-
Notifications
You must be signed in to change notification settings - Fork 4
/
xfilesys.c
1866 lines (1447 loc) · 36.2 KB
/
xfilesys.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
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Teradesk. Copyright (c) 1993 - 2002 W. Klaren,
* 2002 - 2003 H. Robbers,
* 2003 - 2013 Dj. Vukovic
*
* This file is part of Teradesk.
*
* Teradesk is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Teradesk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Teradesk; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA
*/
#include <library.h>
#include <xdialog.h>
#include <mint/cookie.h>
#include "resource.h"
#include "desk.h"
#include "error.h"
#include "xfilesys.h"
#include "file.h"
#include "config.h"
#include "prgtype.h"
#define XBUFSIZE 2048L /* size of a buffer used in file reading/writing */
/*
* If _CHECK_RWMODE is set to 0, there will be no checks whether xfile->mode
* is exactly O_RDONLY or O_WRONLY;
* if it is not O_WRONLY, O_RDONLY will be assumed
*/
#define _CHECK_RWMODE 0
static bool flock;
/*
* Aux. function for size optimization when returning results
* of some GEMDOS operations.
*/
static long x_retresult(long result)
{
return (result < 0) ? (long) xerror((_WORD) result) : result;
}
/*
* Check if a filename or path + name is valid in this OS.
* Also check if it fits into buffers.
* Return 0 if OK.
* 'path' must exist even if empty; 'name' can be NULL or empty.
*/
_WORD x_checkname(const char *path, const char *name)
{
long nl = 0;
long mp = sizeof(VLNAME);
if (!x_netob(path)) /* only if this is not a network object... */
{
if (*path) /* and a path is given */
{
if (!isdisk(path)) /* if it is not on a disk, return error */
return ENOTDIR;
mp = x_pathconf(path, DP_PATHMAX); /* maximum possible length */
if (mp < 0)
return xerror((_WORD) mp);
}
nl = (long) strlen((name) ? name : fn_get_name(path)); /* name length */
/* Avoid needless interrogation of drive if no name given */
if ((*path && nl && nl > x_pathconf(path, DP_NAMEMAX)) || nl >= (long) sizeof(LNAME))
return EFNTL;
}
if ((long) (strlen(path) + nl + 2L) > lmin(mp, (long) sizeof(VLNAME)))
return ENAMETOOLONG;
return 0;
}
/*
* Create a path+filename string from path "path" and filename "name".
* Return a pointer to the created string (being allocated in this routine)
*/
char *x_makepath(const char *path, const char *name, _WORD *error)
{
char *p;
if ((p = malloc(strlen(path) + strlen(name) + 2)) != NULL)
{
*error = make_path(p, path, name);
if (*error != 0)
{
free(p);
p = NULL;
}
} else
{
*error = ENOMEM;
}
return p;
}
/*
* Check if a file or folder or link exists. Return true if it exists.
* If EX_LINK is set in flags, check for the link itself;
* otherwise follow the link and check for target existence.
*/
bool x_exist(const char *file, _WORD flags)
{
XATTR attr;
unsigned short itype;
_WORD theflag;
#if _MINT_
if (x_attr((flags & EX_LINK) ? 1 : 0, FS_INQ, file, &attr) < 0)
#else
if (x_attr(1, FS_INQ, file, &attr) < 0)
#endif
{
return FALSE; /* x_attr can't find target */
} else
{
itype = attr.st_mode & S_IFMT;
switch (itype)
{
case S_IFDIR:
theflag = EX_DIR;
break;
#if _MINT_
case S_IFLNK:
theflag = EX_LINK;
break;
#endif
default:
theflag = EX_FILE;
break;
}
if ((flags & theflag) == 0)
return FALSE;
return TRUE;
}
}
/*
* Check if a name points to a network object, to be accessed
* as http:, https:, ftp:, mailto: or telnet: target. Return TRUE if it is.
* Comparison is case insensitive. If a new network object type is added,
* take care to change loop exit count below.
*/
bool x_netob(const char *name)
{
_WORD i;
static const char *pfx[] = { "http:", "https:", "ftp:", "mailto:", "telnet:" };
if (*name && name[1] != ':') /* don't check further if not necessary */
{
for (i = 0; i < 5; i++)
{
if (strnicmp(name, pfx[i], strlen(pfx[i])) == 0)
{
return TRUE;
}
}
}
return FALSE;
}
/*
* Set a directory path. This works on current drive only, and
* 'path' hould bagin with a backslash, not wioth a drive letter
*/
_WORD x_setpath(const char *path)
{
return xerror(Dsetpath(path));
}
/*
* Get current default path on the specified drive, return pointer to
* this new-allocated string. If drive is specified as 0, also get
* default drive. The resulting path will not be longer than VLNAME.
* Drive 1 = A: 2 = B: 3 = C: , etc. Beware: for x_getdrv() 0=A: 1=B; 2=C: ...
*/
char *x_getpath(_WORD drive, _WORD *error)
{
VLNAME tmp;
char *buffer = NULL;
char *t = tmp;
long e;
/* Put drive id at the beginning of the temporary buffer */
*t++ = (char) (((drive == 0) ? x_getdrv() : (drive - 1)) + 'A');
*t++ = ':';
*t = 0; /* t is now tmp + 2 */
#if _MINT_
if (mint)
{
/* Use Dgetcwd so that length can be limited */
e = Dgetcwd(t, drive, (_WORD) sizeof(VLNAME) - 2);
if (e == EBADARG)
e = ENAMETOOLONG;
} else
#endif
{
/* In single-TOS this should be safe */
e = Dgetpath(t, drive);
}
*error = xerror((_WORD) e);
/* Create output buffer only if there are no errors */
if (*error == 0)
buffer = strdup(tmp);
return buffer;
}
/*
* Create a directory
*/
_WORD x_mkdir(const char *path)
{
return xerror(Dcreate(path));
}
/*
* Remove a directory
*/
_WORD x_rmdir(const char *path)
{
return xerror(Ddelete(path));
}
/*
* Modify a name string so that it represents a full path + name.
* The returned string can be longer than the initial one, so take
* care to have a sufficient buffer.
* The resulting name will never be longer than VLNAME.
*/
static _WORD _fullname(char *buffer)
{
_WORD error = 0, drive = 0;
bool d = isdisk(buffer);
if (!d || strlen(buffer) < 3)
{
/* No drive name contained in the name, or no complete path */
char *def;
char *save;
char *n = buffer;
/* Save the name so that it can be copied back */
if (d)
{
drive = *buffer - 'A' + 1;
n += 2; /* here begins the name (after the ':') */
}
save = strdup(n); /* save name only */
def = x_getpath(drive, &error); /* get default path incl. drive name */
/* Compose fullname */
if (def && save && !error)
make_path(buffer, def, save);
free(save);
free(def);
}
return error;
}
/*
* Create a new name string with maybe a path prepended to it so that
* it represents a full name
*/
char *x_fullname(const char *file, _WORD *error)
{
char *buffer;
if ((buffer = malloc(sizeof(VLNAME))) == NULL)
{
*error = ENOMEM;
} else
{
strsncpy(buffer, file, sizeof(VLNAME));
if ((*error = _fullname(buffer)) != 0)
{
free(buffer);
buffer = NULL;
}
}
return buffer;
}
#if _MINT_
/*
* Create a symbolic link. "linkname" will point to a real object "refname"
*/
_WORD x_mklink(const char *linkname, const char *refname)
{
if (x_exist(linkname, EX_LINK))
return EACCES;
return xerror((_WORD) Fsymlink(refname, linkname));
}
/*
* Read target name of a symbolic link.
* Any '/' characters are converted to '\', otherwise other routines
* may not find this target.
* Do not make this conversion for network objects.
*/
_WORD x_rdlink(size_t tgtsize, char *tgt, const char *linkname)
{
char *slash;
_WORD err = EACCES;
if (!x_netob(linkname))
err = xerror((_WORD) Freadlink((_WORD) tgtsize, tgt, linkname));
if (err == 0 && !x_netob(tgt))
{
while ((slash = strchr(tgt, '/')) != NULL)
*slash = '\\';
}
return err;
}
/*
* Prepend path of the link 'linkname' to a link target definition 'tgtname',
* if it is not given. Return a path + name string (memory allocated here).
* Perform similar tasks for the ".\" and "..\" paths.
* Do not add anything for a network object or id a path is explicitely
* given.
*/
char *x_pathlink(char *tgtname, const char *linkname)
{
char *target = NULL;
char *lpath; /* path of the link */
char *lppath; /* parent path of the link */
char *b; /* position of the first backslash, or after it */
char *p = tgtname; /* pointer to the backslash */
_WORD error;
/* beware: comparison below depends on the order of execution */
if (!x_netob(tgtname) && (((b = strchr(tgtname, '\\')) == NULL) || /* no '\' in the path */
((*p++ == '.') && /* first is '.' */
((*p == '\\') || /* second is '\' or... */
(*p++ == '.' && *p == '\\') /* second is '.' and third is '\\' */
))))
{
if ((lpath = fn_get_path(linkname)) != NULL)
{
if (b == NULL) /* object path does not contain '\' */
{
b = tgtname;
} else /* first character after the '\' */
{
b = p + 1;
}
if (p == tgtname + 2) /* it is a "..\" */
{
lppath = fn_get_path(lpath);
free(lpath);
lpath = lppath;
}
/*
* referenced name does not contain an explicit path,
* use that of the link, or link parent path
*/
target = x_makepath(lpath, b, &error);
free(lpath);
}
} else
{
target = strdup(tgtname);
}
return target;
}
#endif
/*
* Obtain the name of the object referenced by a link (link target);
* if "linkname" is not the name of a link, or, if some other error happens,
* just copy the name. This routine allocates space for the output of real
* object name. If the name of the target does not contain a path, prepend
* the path of the link.
*/
char *x_fllink(const char *linkname)
{
char *tmp = NULL;
char *target = NULL;
if (linkname)
{
#if _MINT_
_WORD error = EACCES;
if (mint)
{
if ((tmp = malloc_chk(sizeof(VLNAME))) != NULL)
{
error = x_rdlink(sizeof(VLNAME), tmp, linkname);
/* If the name of the referenced item has been obtained... */
if (error)
{
/* this is not a link, just copy the name */
target = strdup(linkname);
} else
{
/* this is a link */
target = x_pathlink(tmp, linkname);
}
}
}
if (tmp == NULL)
#endif
target = strdup(linkname);
free(tmp);
}
return target;
}
/*
* Get information about free space on a disk volume.
* this information is returned in *diskinfo as:
* - number of flree clusters
* - total number of clusters
* - sector size in bytes
* number of sectors in a cluster
*/
_WORD x_dfree(_DISKINFO *diskinfo, _WORD drive)
{
return xerror(Dfree(diskinfo, drive));
}
/*
* Get the id of the current default drive
* 0=A: 1=B: 2=C: 3=D: ...
*/
_WORD x_getdrv(void)
{
return Dgetdrv();
}
/*
* Set new default drive
* 0=A: 1=B: 2=C: ...
*/
long x_setdrv(_WORD drive)
{
return Dsetdrv(drive);
}
/*
* Get information about a disk-volume label
* note: drive 0 = A:\, 1 = B:\, etc.
* It seems that in other than FAT fs labels can be longer than 11 (8+3)
* characters. Maximum intermediate label length is here limited to
* 39 characters, but output label name always cramped to 12 characters.
*/
#define LBLMAX 40 /* maximum permitted intermediate label length + 1 */
_WORD x_getlabel(_WORD drive, char *label)
{
_DTA *olddta, dta;
_WORD error;
char path[8];
char lblbuf[LBLMAX];
strcpy(path, adrive);
strcat(path, "*.*");
*path += (char) drive;
#if _MINT_
if (mint)
{
path[3] = 0;
error = (_WORD) x_retresult(Dreadlabel(path, lblbuf, LBLMAX));
} else
#endif
{
olddta = Fgetdta();
Fsetdta(&dta);
if ((error = Fsfirst(path, FA_LABEL)) == 0)
strsncpy(lblbuf, dta.dta_name, (size_t) LBLMAX);
else
error = ENOENT;
Fsetdta(olddta);
}
if (error == 0)
cramped_name(lblbuf, label, sizeof(INAME));
else
*label = 0;
return error == ENMFILES || error == ENOENT ? 0 : error;
}
#if _EDITLABELS
/*
* Create a volume label (for the time being, mint or magic only).
* In single TOS, does not do anything, but does not return error.
* Currently, this routine is not used anywhere in TeraDesk
*/
_WORD x_putlabel(_WORD drive, char *label)
{
char path[4];
strcpy(path, adrive);
*path += (char) drive;
#if _MINT_
if (mint)
return x_retresult(Dwritelabel(path, label));
else
#endif
return 0;
}
#endif
/* File functions */
/*
* Rename a file from "oldn" to "newn";
* note unusual (for C) order of arguments: (source, destination)
*/
_WORD x_rename(const char *oldn, const char *newn)
{
return xerror(Frename(0, oldn, newn));
}
/*
* "Unlink" a file (i.e. delete it) .
* When operated on a symblic link, it deletes the link, not the file
*/
_WORD x_unlink(const char *file)
{
return xerror(Fdelete(file));
}
/*
* Set GEMDOS file attributes and access rights.
* Note: Applying Fattrib() to folders in Mint will fail
* on -some- FAT partitions (why?).
*/
_WORD x_fattrib(const char *file, /* file name */
XATTR * attr /* extended attributes */
)
{
#if _MINT_
_WORD mode;
bool hasuid; /* true if access rights are settable */
#endif
_WORD mask; /* mask for changeable ms-dos attributes */
_WORD error; /* error code */
/*
* The following change is of V4.01. If file access rights
* are available, do not fail if it is impossible set MS-DOS
* file attributes - user acces rights are probaly the only
* relevant protection. Previous version failed when attempting
* to access files on a network file system because Fattrib
* did not work.
*/
#if _MINT_
hasuid = (x_inq_xfs(file) & FS_UID) != 0;
#endif
mask = FA_RDONLY | FA_SYSTEM | FA_HIDDEN | FA_CHANGED;
if ((attr->st_mode & S_IFMT) == S_IFDIR)
mask |= FA_DIR;
error = xerror((_WORD) Fattrib(file, 1, (attr->st_attr & mask)));
#if _MINT_
if (hasuid)
error = 0;
if (mint)
{
mode = attr->st_mode & (DEFAULT_DIRMODE | S_ISUID | S_ISGID | S_ISVTX);
/* Quietly fail on folders if necessary in Mint (why?) */
if (!magx && (attr->st_mode & S_IFMT) == S_IFDIR && error == ENOENT)
error = 0;
/* Set access rights and owner IDs if possible */
if (error >= 0 && hasuid)
{
/* Don't use Fchmod() on links; target will be modified! */
if ((attr->st_mode & S_IFLNK) != S_IFLNK)
error = xerror((_WORD) Fchmod(file, mode));
/*
* This (and above) may cause a problem with network file systems.
* on accessing -some- remote systems, Fchown and/or Fchmod
* may fail, depending on the settings of user-id-mapping.
* Therefore, such errors are quietly ignored.
*/
if (error >= 0)
error = xerror((_WORD) Fchown(file, attr->st_uid, attr->st_gid));
if (error == EACCES)
{
char b[8];
const char *c = "U:\\NFS\\";
strsncpy(b, file, 8);
strupr(b);
if (strcmp(b, c) == 0)
error = 0;
}
}
}
#endif
return error;
}
/*
* Get or set file date & time. A handle to the file must exist first
*/
_WORD x_datime(_DOSTIME *time, _WORD handle, _WORD wflag)
{
return xerror(Fdatime(time, handle, wflag));
}
/*
* Open a file
*/
_WORD x_open(const char *file, _WORD mode)
{
if (!flock)
mode &= O_ACCMODE;
return (_WORD) x_retresult(Fopen(file, mode));
}
/*
* Create a new file with specified attributes and access rights
*/
_WORD x_create(const char *file, XATTR *attr)
{
_WORD error = (_WORD) x_retresult(Fcreate(file, (attr) ? attr->st_attr : 0));
#if _MINT_
if (mint && (error >= 0) && attr)
{
_WORD handle = error;
error = x_fattrib(file, attr);
if (error >= 0)
error = handle;
}
#endif
return error;
}
/*
* Close an open file
*/
_WORD x_close(_WORD handle)
{
return xerror(Fclose(handle));
}
/*
* Read 'count' bytes from a file into 'buf'
*/
long x_read(_WORD handle, long count, char *buf)
{
return x_retresult(Fread(handle, count, buf));
}
/*
* Write 'count' bytes to a file from 'buf'
*/
long x_write(_WORD handle, long count, char *buf)
{
return x_retresult(Fwrite(handle, count, buf));
}
/*
* Position the file pointer at some offset from file beginning
*/
long x_seek(long offset, _WORD handle, _WORD seekmode)
{
return x_retresult(Fseek(offset, handle, seekmode));
}
/* Funkties voor het lezen van een directory */
/*
* Convert a DTA structure to a XATTR structure. The index, dev,
* rdev, blksize and nblocks fields in attrib are not set. They
* are not necessary anyway on TOS.
* Access rights are read and write for everybody, unless an item
* is set as readonly.
* For directories, execute rights are added.
* Note: perhaps the default rights should not be rwxrwxrwx but rwxr-x--- ?
*/
static void dta_to_xattr(_DTA *dta, XATTR *attrib)
{
attrib->st_mode = S_IRUSR | S_IRGRP | S_IROTH; /* everything is readonly */
if ((dta->dta_attribute & FA_RDONLY) == 0) /* can write as well */
attrib->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
if (dta->dta_attribute & FA_DIR)
attrib->st_mode |= S_IFDIR | EXEC_MODE;
else if (!(dta->dta_attribute & FA_LABEL))
attrib->st_mode |= S_IFREG;
attrib->st_size = dta->dta_size;
#if _MINT_
attrib->st_uid = 0;
attrib->st_gid = 0;
#endif
dos_mtime(attrib) = dos_atime(attrib) = dos_ctime(attrib) = dta->dta_time;
dos_mdate(attrib) = dos_adate(attrib) = dos_cdate(attrib) = dta->dta_date;
attrib->st_attr = dta->dta_attribute & 0xFF;
}
/*
* Inquire about details of filesystem in which 'path' item resides.
* HR 151102: courtesy XaAES & EXPLODE; now it also works with MagiC
* Dj.V. Modified here to return integer code identifying file system type.
* Return code contains bitflags describing the filesystem:
* 0x0000: FS_TOS- standard TOS FAT filesystem
* 0x0001: FS_LFN- long file names are possible
* 0x0002: FS_LNK- symbolic links are possible
* 0x0004: FS_UID- access rights and user/group IDs are possible.
* 0x0008: FS_CSE- case-sensitive names are possible
* If neither mint or magic are present, always return 0.
* If the inquiry is about the contents of a folder specified
* then 'path' should be terminated by a '\'
*/
_WORD x_inq_xfs(const char *path)
{
_WORD retcode = 0;
#if _MINT_
if (mint)
{
long n;
long t;
long c;
long m;
long x;
/* Inquire about filesystem details */
n = Dpathconf(path, DP_NAMEMAX); /* 3: maximum name length */
t = Dpathconf(path, DP_TRUNC); /* 5: name truncation */
c = Dpathconf(path, DP_CASE); /* 6: case-sensitive names? */
m = Dpathconf(path, DP_MODEATTR); /* 7: valid mode bits */
x = Dpathconf(path, DP_XATTRFIELDS); /* 8: valid XATTR fields */
/*
* If information can not be returned, results will be < 0, then
* treat as if there are no fields set.
*/
if (m < 0)
m = 0;
if (x < 0)
x = 0;
if (c < 0)
c = DP_CASEINSENS;
if (t < 0)
t = DP_NOTRUNC;
if (n < 0)
n = 12;
/*
* If (m & 0x1FF00), nine access rights bits are valid mode fields
* If (x & 0x0030), user and group ids are valid XATTR fields
*/
if ((m & 0x0001FF00L) != 0 && (x & 0x00000030L) != 0)
retcode |= FS_UID;
/*
* DP_NOSENSITIVE = 1 = not sensitive, converted to uppercase
* DP_DOSTRUNC = 2 = file names truncated to 8+3
*/
if (c != DP_CASEINSENS)
{
retcode |= FS_CSE;
}
if (t != DP_DOSTRUNC && n > 12)
retcode |= FS_LFN;
/* Are link itemtypes valid ? */
if ((m & DP_FT_LNK) != 0)
retcode |= FS_LNK;
}
#else
(void) path;
#endif
return retcode;
}
/*
* Open a directory
*/
XDIR *x_opendir(const char *path, _WORD *error)
{
XDIR *dir;
VLNAME p;
if ((dir = malloc(sizeof(XDIR))) == NULL)
{
*error = ENOMEM;
} else
{
dir->path = path;
strsncpy(p, path, sizeof(VLNAME) - 1);
if (*(p + strlen(p) - 1) != '\\')
strcat(p, bslash);
#if _MINT_
dir->type = x_inq_xfs(p);
if (dir->type != 0)
{
/* File system with long filenames or other extensions */
if (((dir->data.handle = Dopendir(path, 0)) & 0xFF000000L) == 0xFF000000L)
{
*error = xerror((_WORD) dir->data.handle);
free(dir);
dir = NULL;
}
} else
#endif
{
/* FAT file system */
dir->data.gdata.first = 1;
dir->data.gdata.old_dta = Fgetdta();
Fsetdta(&dir->data.gdata.dta);
*error = 0;
}
}
return dir;
}
/*
* Read a directory entry.
* Note: In order to increase speed, only the pointer is passed,
* and the name is no more copied to output location (in all uses of this
* routine in TeraDesk, obtained name is immediately copied elsewhere).
* **buffer should probably be considered as readonly,
* not to be written to or used for permanent storage
*/
long x_xreaddir(XDIR *dir, char **buffer, size_t len, XATTR *attrib)
{
long result;
static char fspec[sizeof(VLNAME) + 4];