-
Notifications
You must be signed in to change notification settings - Fork 2
/
FileSystem.c
796 lines (621 loc) · 18.1 KB
/
FileSystem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
#include "FileSystem.h"
#include "Errors.h"
#include "Users.h"
#include <glob.h>
//#include <sys/ioctl.h>
//#include <sys/resource.h>
#include <sys/mount.h>
#include <utime.h>
#include <time.h>
#ifdef HAVE_XATTR
#include <sys/xattr.h>
#endif
#ifdef USE_FANOTIFY
#include <sys/fanotify.h>
#endif
#ifdef USE_FSFLAGS
#include <linux/fs.h>
#endif
#ifndef HAVE_GET_CURR_DIR
char *get_current_dir_name()
{
char *path;
path=(char *) calloc(1, PATH_MAX+1);
getcwd(path, PATH_MAX+1);
return(path);
}
#endif
const char *GetBasename(const char *Path)
{
const char *ptr;
int len;
len=StrLen(Path);
if (len==0) return("");
if (len==1) return(Path);
ptr=Path+len-1;
while (ptr > Path)
{
if ((*ptr=='/') && (*(ptr+1) != '\0')) break;
ptr--;
}
if ((*ptr=='/') && (*(ptr+1) != '\0')) ptr++;
return(ptr);
}
char *SlashTerminateDirectoryPath(char *DirPath)
{
char *ptr, *RetStr=NULL;
if (! StrValid(DirPath)) return(CopyStr(DirPath,"/"));
RetStr=DirPath;
ptr=RetStr+StrLen(RetStr)-1;
if (*ptr != '/') RetStr=AddCharToStr(RetStr,'/');
return(RetStr);
}
char *StripDirectorySlash(char *DirPath)
{
char *ptr;
//don't strip '/' (root dir)
if (! StrValid(DirPath)) return(DirPath);
if (strcmp(DirPath,"/")==0) return(DirPath);
ptr=DirPath+StrLen(DirPath)-1;
if (*ptr == '/') *ptr='\0';
return(DirPath);
}
int MakeDirPath(const char *Path, int DirMask)
{
const char *ptr;
char *Tempstr=NULL;
int result=-1;
ptr=Path;
if (*ptr=='/') ptr++;
ptr=strchr(ptr, '/');
while (ptr)
{
Tempstr=CopyStrLen(Tempstr,Path,ptr-Path);
result=mkdir(Tempstr, DirMask);
if ((result==-1) && (errno != EEXIST))
{
RaiseError(ERRFLAG_ERRNO, "MakeDirPath", "cannot mkdir '%s'",Tempstr);
break;
}
ptr=strchr(++ptr, '/');
}
DestroyString(Tempstr);
if (result==0) return(TRUE);
return(FALSE);
}
int FileChangeExtension(const char *FilePath, const char *NewExt)
{
char *ptr;
char *Tempstr=NULL;
int result;
Tempstr=CopyStr(Tempstr,FilePath);
ptr=strrchr(Tempstr,'/');
if (!ptr) ptr=Tempstr;
ptr=strrchr(ptr,'.');
if (! ptr) ptr=Tempstr+StrLen(Tempstr);
StrTrunc(Tempstr, ptr-Tempstr);
if (*NewExt=='.') Tempstr=CatStr(Tempstr,NewExt);
else Tempstr=MCatStr(Tempstr,".",NewExt,NULL);
result=rename(FilePath,Tempstr);
if (result !=0) RaiseError(ERRFLAG_ERRNO, "FileChangeExtension", "cannot rename '%s' to '%s'",FilePath, Tempstr);
DestroyString(Tempstr);
if (result==0) return(TRUE);
else return(FALSE);
}
int FileMoveToDir(const char *FilePath, const char *Dir)
{
char *Tempstr=NULL;
struct stat Stat;
int result, size;
int RetVal=FALSE;
Tempstr=MCopyStr(Tempstr, Dir, "/", GetBasename(FilePath), NULL);
MakeDirPath(Tempstr, 0700);
if (rename(FilePath,Tempstr) != 0)
{
RaiseError(ERRFLAG_DEBUG | ERRFLAG_ERRNO, "FileMoveToDir", "cannot rename '%s' to '%s', attempting copy",FilePath, Tempstr);
stat(FilePath, &Stat);
size=FileCopy(FilePath, Tempstr);
if (size==Stat.st_size)
{
unlink(FilePath);
RetVal=TRUE;
}
else RaiseError(ERRFLAG_ERRNO, "FileMoveToDir", "cannot rename nor copy '%s' to '%s'",FilePath, Tempstr);
}
else RetVal=TRUE;
DestroyString(Tempstr);
return(RetVal);
}
int FindFilesInPath(const char *File, const char *Path, ListNode *Files)
{
char *Tempstr=NULL, *CurrPath=NULL;
const char *ptr;
int i;
glob_t Glob;
if (*File=='/')
{
CurrPath=CopyStr(CurrPath,"");
ptr=""; //so we execute once below
}
else ptr=GetToken(Path,":",&CurrPath,0);
while (ptr)
{
CurrPath=SlashTerminateDirectoryPath(CurrPath);
Tempstr=MCopyStr(Tempstr,CurrPath,File,NULL);
glob(Tempstr,0,0,&Glob);
for (i=0; i < Glob.gl_pathc; i++) ListAddItem(Files,CopyStr(NULL,Glob.gl_pathv[i]));
globfree(&Glob);
ptr=GetToken(ptr,":",&CurrPath,0);
}
DestroyString(Tempstr);
DestroyString(CurrPath);
return(ListSize(Files));
}
char *FindFileInPath(char *InBuff, const char *File, const char *Path)
{
char *Tempstr=NULL, *CurrPath=NULL, *RetStr=NULL, *Link=NULL;
struct stat Stat;
const char *ptr;
RetStr=CopyStr(InBuff,"");
if (*File=='/')
{
CurrPath=CopyStr(CurrPath,"");
ptr=""; //so we execute once below
}
else ptr=GetToken(Path,":",&CurrPath,0);
while (ptr)
{
CurrPath=SlashTerminateDirectoryPath(CurrPath);
Tempstr=MCopyStr(Tempstr,CurrPath,File,NULL);
if (lstat(Tempstr, &Stat)==0)
{
//if we find an symlink, then remember it, but don't return it,
//in the hope that we will find a better match
if (S_ISLNK(Stat.st_mode))
{
if (! StrValid(Link)) Link=CopyStr(Link, Tempstr);
}
else
{
RetStr=CopyStr(RetStr,Tempstr);
break;
}
}
ptr=GetToken(ptr,":",&CurrPath,0);
}
//if we didn't find an actual file, but found a link with the name
//then return that link
if (! StrValid(RetStr)) RetStr=CopyStr(RetStr, Link);
DestroyString(Tempstr);
DestroyString(CurrPath);
DestroyString(Link);
return(RetStr);
}
/* This checks if a certain file exists (not if we can open it etc, just if */
/* we can stat it, this is useful for checking pid files etc). */
int FileExists(const char *FileName)
{
struct stat StatData;
if (stat(FileName,&StatData) == 0) return(1);
else return(0);
}
int FileChOwner(const char *FileName, const char *Owner)
{
int uid, result;
uid=LookupUID(Owner);
if (uid > -1)
{
result=chown(FileName, uid, -1);
if (result==0) return(TRUE);
}
RaiseError(ERRFLAG_ERRNO, "FileChOwner", "failed to change owner to user=%s uid=%d",Owner,uid);
return(FALSE);
}
int FileChGroup(const char *FileName, const char *Group)
{
int gid, result;
gid=LookupGID(Group);
if (gid > -1)
{
result=chown(FileName, -1, gid);
if (result==0) return(TRUE);
}
RaiseError(ERRFLAG_ERRNO, "FileChGroup", "failed to change group to group=%s gid=%d",Group,gid);
return(FALSE);
}
int FileChMod(const char *Path, const char *Mode)
{
int perms;
perms=FileSystemParsePermissions(Mode);
if (chmod(Path, perms) ==0) return(TRUE);
return(FALSE);
}
int FileTouch(const char *Path)
{
struct utimbuf times;
times.actime=time(NULL);
times.modtime=time(NULL);
if (utime(Path, ×)==0) return(TRUE);
RaiseError(ERRFLAG_ERRNO, "FileTouch", "failed to update file mtime");
return(FALSE);
}
unsigned long FileCopyWithProgress(const char *SrcPath, const char *DestPath, DATA_PROGRESS_CALLBACK Callback)
{
STREAM *Src;
unsigned long result;
struct stat FStat;
Src=STREAMOpen(SrcPath,"r");
if (! Src) return(0);
if (Callback) STREAMAddProgressCallback(Src,Callback);
result=STREAMCopy(Src, DestPath);
STREAMClose(Src);
if (stat(SrcPath, &FStat)==0) chmod(DestPath, FStat.st_mode);
return(result);
}
int FileGetBinaryXAttr(char **RetStr, const char *Path, const char *Name)
{
int len=0;
*RetStr=CopyStr(*RetStr, "");
#ifdef HAVE_XATTR
#ifdef __APPLE__ //'cos some idiot's always got to 'think different'
len=getxattr(Path, Name, NULL, 0, 0, 0);
#else
len=getxattr(Path, Name, NULL, 0);
#endif
if (len > 0)
{
*RetStr=SetStrLen(*RetStr,len);
#ifdef __APPLE__
getxattr(Path, Name, *RetStr, len, 0, 0);
#else
getxattr(Path, Name, *RetStr, len);
#endif
}
#else
RaiseError(0, "FileGetXAttr", "xattr support not compiled in");
#endif
return(len);
}
char *FileGetXAttr(char *RetStr, const char *Path, const char *Name)
{
int len;
len=FileGetBinaryXAttr(&RetStr, Path, Name);
if (len > 0) RetStr[len]=0;
return(RetStr);
}
int FileSetBinaryXAttr(const char *Path, const char *Name, const char *Value, int Len)
{
#ifdef HAVE_XATTR
#ifdef __APPLE__
return(setxattr(Path, Name, Value, Len, 0, 0));
#else
return(setxattr(Path, Name, Value, Len, 0));
#endif
#else
RaiseError(0, "FileSetXAttr", "xattr support not compiled in");
#endif
return(-1);
}
int FileSetXAttr(const char *Path, const char *Name, const char *Value)
{
return(FileSetBinaryXAttr(Path, Name, Value, StrLen(Value)));
}
int FileSystemMount(const char *Dev, const char *MountPoint, const char *Type, const char *Args)
{
const char *ptr, *p_Type, *p_MountPoint;
char *Token=NULL;
int Flags=0, result, Perms=700;
p_Type=Type;
if (! StrValid(MountPoint))
{
p_MountPoint=Dev;
if (*p_MountPoint) p_MountPoint++;
}
else p_MountPoint=MountPoint;
if (! StrValid(p_MountPoint)) return(FALSE);
if (strcmp(Type,"bind")==0)
{
#ifdef MS_BIND
p_Type="";
Flags=MS_BIND;
#else
RaiseError(0, "FileSystemMount", "Bind mounts not supported on this system.");
return(FALSE);
#endif
}
ptr=GetToken(Args, " |,", &Token, GETTOKEN_MULTI_SEP);
while (ptr)
{
#ifdef MS_RDONLY
if (strcmp(Token,"ro")==0) Flags |= MS_RDONLY;
#endif
#ifdef MS_NOATIME
if (strcmp(Token,"noatime")==0) Flags |= MS_NOATIME;
#endif
#ifdef MS_NOATIME
if (strcmp(Token,"nodiratime")==0) Flags |= MS_NODIRATIME;
#endif
#ifdef MS_NOEXEC
if (strcmp(Token,"noexec")==0) Flags |= MS_NOEXEC;
#endif
#ifdef MS_NOSUID
if (strcmp(Token,"nosuid")==0) Flags |= MS_NOSUID;
#endif
#ifdef MS_NODEV
if (strcmp(Token,"nodev")==0) Flags |= MS_NODEV;
#endif
#ifdef MS_REMOUNT
if (strcmp(Token,"remount")==0) Flags |= MS_REMOUNT;
#endif
if (strncmp(Token,"perms=",6)==0) Perms=strtol(Token+6,NULL,8);
ptr=GetToken(ptr, " |,", &Token, GETTOKEN_MULTI_SEP);
}
Token=MCopyStr(Token,p_MountPoint,"/",NULL);
MakeDirPath(Token,Perms);
//must do a little dance for readonly bind mounts. We must first mount, then remount readonly
#ifdef MS_BIND
if ((Flags & MS_BIND) && (Flags & MS_RDONLY))
{
mount(Dev,p_MountPoint,"",MS_BIND,NULL);
Flags |= MS_REMOUNT;
}
#endif
#ifdef linux
result=mount(Dev,p_MountPoint,p_Type,Flags,NULL);
#else
//assume BSD if not linux
result=mount(p_Type,p_MountPoint,Flags,(void *) Dev);
#endif
if (result !=0) RaiseError(ERRFLAG_ERRNO, "FileSystemMount", "failed to mount %s:%s on %s", p_Type,Dev,p_MountPoint);
DestroyString(Token);
if (result==0) return(TRUE);
return(FALSE);
}
//if the system doesn't have these flags then define empty values for them
#ifndef UMOUNT_NOFOLLOW
#define UMOUNT_NOFOLLOW 0
#endif
#ifndef MNT_DETACH
#define MNT_DETACH 0
#endif
#define UMOUNT_RECURSE 1
#define UMOUNT_SUBDIRS 2
#define UMOUNT_RMDIR 4
#define UMOUNT_RMFILE 8
int FileSystemUnMountFlagsDepth(const char *MountPoint, int UnmountFlags, int ExtraFlags, int Depth, int MaxDepth)
{
int result, i;
char *Path=NULL;
struct stat FStat;
glob_t Glob;
if (strcmp(MountPoint,"/proc")==0) MaxDepth=10;
if (strcmp(MountPoint,"/sys")==0) MaxDepth=10;
if (strcmp(MountPoint,"/dev")==0) MaxDepth=10;
if (ExtraFlags & UMOUNT_RECURSE)
{
if ((MaxDepth ==0) || (Depth <= MaxDepth))
{
Path=MCopyStr(Path,MountPoint,"/*",NULL);
glob(Path, 0, 0, &Glob);
for (i=0; i < Glob.gl_pathc; i++)
{
if (lstat(Glob.gl_pathv[i],&FStat)==0)
{
if (S_ISDIR(FStat.st_mode))
{
FileSystemUnMountFlagsDepth(Glob.gl_pathv[i], UnmountFlags, ExtraFlags & ~UMOUNT_SUBDIRS, Depth+1, MaxDepth);
}
else if (ExtraFlags & UMOUNT_RMFILE) unlink(Glob.gl_pathv[i]);
}
}
globfree(&Glob);
}
}
if (ExtraFlags & UMOUNT_SUBDIRS) return(0);
result=0;
while (result > -1)
{
#ifdef HAVE_UMOUNT2
result=umount2(MountPoint, UnmountFlags);
#elif HAVE_UMOUNT
result=umount(MountPoint);
#elif HAVE_UNMOUNT
result=unmount(MountPoint,0);
#else
result=-1;
#endif
}
if (ExtraFlags & UMOUNT_RMDIR) rmdir(MountPoint);
Destroy(Path);
return(result);
}
int FileSystemUnMountFlags(const char *MountPoint, int UnmountFlags, int ExtraFlags)
{
return(FileSystemUnMountFlagsDepth(MountPoint, UnmountFlags, ExtraFlags, 0, 0));
}
int FileSystemUnMount(const char *MountPoint, const char *Args)
{
int Flags=UMOUNT_NOFOLLOW;
int ExtraFlags=0;
char *Token=NULL;
const char *ptr;
int result;
ptr=GetToken(Args, " |,", &Token, GETTOKEN_MULTI_SEP);
while (ptr)
{
if (strcmp(Token,"follow")==0) Flags &= ~UMOUNT_NOFOLLOW;
if (strcmp(Token,"lazy")==0) Flags |= MNT_DETACH;
if (strcmp(Token,"detach")==0) Flags |= MNT_DETACH;
if (strcmp(Token,"recurse")==0) ExtraFlags |= UMOUNT_RECURSE;
if (strcmp(Token,"subdirs")==0) ExtraFlags |= UMOUNT_SUBDIRS | UMOUNT_RECURSE;
if (strcmp(Token,"rmdir")==0) ExtraFlags |= UMOUNT_RMDIR;
ptr=GetToken(ptr, " |,", &Token, GETTOKEN_MULTI_SEP);
}
result=FileSystemUnMountFlags(MountPoint, Flags, ExtraFlags);
DestroyString(Token);
return(result);
}
int FileSystemRmDir(const char *Dir)
{
return(FileSystemUnMountFlagsDepth(Dir, 0, UMOUNT_RECURSE | UMOUNT_RMDIR | UMOUNT_RMFILE, 0, 0));
}
int FileSystemCopyDir(const char *Src, const char *Dest)
{
glob_t Glob;
const char *ptr;
struct stat Stat;
char *Tempstr=NULL, *Path=NULL;
int i, result, RetVal=FALSE;
Tempstr=MCopyStr(Tempstr, Dest, "/", NULL);
MakeDirPath(Tempstr, 0777);
Tempstr=MCopyStr(Tempstr, Src, "/*", NULL);
glob(Tempstr, 0, 0, &Glob);
Tempstr=MCopyStr(Tempstr, Src, "/.*", NULL);
glob(Tempstr, GLOB_APPEND, NULL, &Glob);
for (i=0; i < Glob.gl_pathc; i++)
{
ptr=GetBasename(Glob.gl_pathv[i]);
if ((strcmp(ptr,".") !=0) && (strcmp(ptr, "..") !=0) )
{
ptr=Glob.gl_pathv[i];
if (lstat(ptr, &Stat) == 0)
{
RetVal=TRUE;
Path=MCopyStr(Path, Dest, "/", GetBasename(ptr), NULL);
if (S_ISLNK(Stat.st_mode))
{
Tempstr=SetStrLen(Tempstr, PATH_MAX);
result=readlink(ptr, Tempstr, PATH_MAX);
StrTrunc(Tempstr, result);
result=symlink(Path, Tempstr);
}
else if (S_ISDIR(Stat.st_mode))
{
FileSystemCopyDir(ptr, Path);
}
else if (S_ISREG(Stat.st_mode))
{
FileCopy(ptr, Path);
}
else
{
RaiseError(0, "FileSystemCopyDir", "WARNING: not copying %s. Files of this type aren't yet supported for copy", Src);
}
}
}
}
globfree(&Glob);
Destroy(Tempstr);
Destroy(Path);
return(RetVal);
}
static int FileSystemParsePermissionsTri(const char **ptr, int ReadPerm, int WritePerm, int ExecPerm)
{
int Perms=0;
if (**ptr=='+') ptr++;
if (**ptr=='=') ptr++;
if (**ptr=='r') Perms |= ReadPerm;
if (ptr_incr(ptr, 1) ==0) return(Perms);
if (**ptr=='w') Perms |= WritePerm;
if (ptr_incr(ptr, 1) ==0) return(Perms);
if (**ptr=='x') Perms |= ExecPerm;
if (ptr_incr(ptr, 1) ==0) return(Perms);
return(Perms);
}
int FileSystemParsePermissions(const char *PermsStr)
{
int Perms=0;
const char *ptr;
if (! StrValid(PermsStr)) return(0);
ptr=PermsStr;
switch(*ptr)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
return(strtol(PermsStr,NULL,8));
break;
case 'a':
Perms |= FileSystemParsePermissionsTri(&ptr, S_IRUSR|S_IRGRP|S_IROTH, S_IWUSR|S_IWGRP|S_IWOTH, S_IXUSR|S_IXGRP|S_IXOTH);
break;
case 'u':
Perms |= FileSystemParsePermissionsTri(&ptr, S_IRUSR, S_IWUSR, S_IXUSR);
break;
case 'g':
Perms |= FileSystemParsePermissionsTri(&ptr, S_IRGRP, S_IWGRP, S_IXGRP);
break;
case 'o':
Perms |= FileSystemParsePermissionsTri(&ptr, S_IROTH, S_IWOTH, S_IXOTH);
break;
default:
Perms |= FileSystemParsePermissionsTri(&ptr, S_IRUSR, S_IWUSR, S_IXUSR);
Perms |= FileSystemParsePermissionsTri(&ptr, S_IRGRP, S_IWGRP, S_IXGRP);
Perms |= FileSystemParsePermissionsTri(&ptr, S_IROTH, S_IWOTH, S_IXOTH);
break;
}
return(Perms);
}
int FDSetFlags(int fd, int Set, int UnSet)
{
#ifdef USE_FSFLAGS
int attr;
if (fd > -1)
{
if (ioctl(fd, FS_IOC_GETFLAGS, &attr) >= 0)
{
attr |= Set;
attr &= ~UnSet;
if (ioctl(fd, FS_IOC_SETFLAGS, &attr) >=0) return(TRUE);
}
}
#else
RaiseError(0, "FDSetFlags", "Support for append-only/immutable filesystem flags not compiled into libUseful");
#endif
return(FALSE);
}
int FileSetFlags(const char *Path, int Set, int Unset)
{
int fd;
int RetVal=FALSE;
#ifdef FS_IOC_GETFLAGS
fd=open(Path, O_RDONLY);
if (fd > -1)
{
RetVal=FDSetFlags(fd, Set, Unset);
close(fd);
}
#endif
return(RetVal);
}
int FileSystemSetSTREAMFlags(int fd, int Set, int UnSet)
{
int toset=0, tounset=0;
#ifdef FS_IMMUTABLE_FL
if (Set & STREAM_IMMUTABLE) toset |= FS_IMMUTABLE_FL;
else if (UnSet & STREAM_IMMUTABLE) tounset |= FS_IMMUTABLE_FL;
#endif
#ifdef FS_APPEND_FL
if (Set & STREAM_APPENDONLY) toset |= FS_APPEND_FL;
else if (UnSet & STREAM_APPENDONLY) tounset |= FS_APPEND_FL;
#endif
return(FDSetFlags(fd, toset, tounset));
}
int FileSetSTREAMFlags(const char *Path, int Set, int Unset)
{
int fd;
int RetVal=FALSE;
#ifdef FS_IOC_GETFLAGS
fd=open(Path, O_RDONLY);
if (fd > -1)
{
RetVal=FileSystemSetSTREAMFlags(fd, Set, Unset);
close(fd);
}
#endif
return(RetVal);
}