-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdirectory.c
4518 lines (3929 loc) · 113 KB
/
directory.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
/* $Id: directory.c 15.21 1999/09/11 17:05:14 Michiel Exp Michiel $ */
/* $Log: directory.c $
* Revision 15.21 1999/09/11 17:05:14 Michiel
* bugfix version 18.4
*
* Revision 15.20 1999/05/14 11:31:34 Michiel
* Long filename support implemented; bugfixes
*
* Revision 15.19 1999/05/10 23:53:29 Michiel
* hardlink bug (ST_LINKFILE/ST_LINKDIR) fixed
*
* Revision 15.18 1999/04/25 21:48:19 Michiel
* bug 00141 fixed: hardlink overwrite problem in NewFile()
*
* Revision 15.17 1999/04/23 11:12:39 Michiel
* optimisation: delfile is deleted when detected to be empty (during dirscan)
*
* Revision 15.16 1999/03/23 06:00:19 Michiel
* More informative error messages in setdeldir
* Maxdeldir bug in setdeldir fixed
*
* Revision 15.15 1999/03/09 10:34:02 Michiel
* typo in mufs code
*
* Revision 15.14 1999/02/22 16:31:55 Michiel
* Changes for increasing deldir capacity
* Fixed link problems; new function MoveLink
*
* Revision 15.13 1998/09/27 11:26:37 Michiel
* ErrorMsg param
*
* Revision 15.12 1998/09/03 07:12:14 Michiel
* versie 17.4
* bugfixes 118, 121, 123 and superindexblocks and td64 support
*
* Revision 15.11 1997/03/03 22:04:04 Michiel
* Release 16.21
*
* Revision 15.10 1996/04/22 22:12:41 Michiel
* NewFile overwrite bug fix
* SetDate deldirfile bug fix
*
* Revision 15.9 1996/03/14 19:30:52 Michiel
* The connect anode for directory anode allocation now is the second anode,
* not the head anode --> better large directory performance
* NewFile does not call SearchInDir anymore --> better (large) dir perf.
* (see log 15.3.96)
*
* Revision 15.8 1996/03/07 10:09:09 Michiel
* rename bug fixed (wt)
*
* Revision 15.7 1996/01/30 12:47:46 Michiel
* --- working tree overlap ---
* Softlink bug fixes
* Notify-update changes
*
* Revision 15.6 1995/12/29 11:02:43 Michiel
* SetRollover extended
*
* Revision 15.4 1995/12/21 12:00:51 Michiel
* bugfix: newfile didn't clear extrafields/filetype
* Now using FreeBlockAC directly instead of buggy FreeAnodeBlocksAC
*
* Revision 15.3 1995/12/20 11:54:19 Michiel
* indented
*
* Revision 15.2 1995/12/07 15:25:38 Michiel
* rollover support and bugfixes
*
* Revision 15.1 1995/11/15 15:41:17 Michiel
* Postponed operation support:
* AllocDeldirSlot, AddToDeldir, FreeAnodeBlocks, NewFile, DeleteObject, FreeAnodesInChain
* Rootblock extension: dates in Touch, Examine
*
* Revision 14.12 1995/11/07 14:54:13 Michiel
* Checks for ReservedAreaLock where needed
*
* Revision 14.11 1995/10/20 10:08:37 Michiel
* Anode reserved area adaptions (16.3)
*
* Revision 14.10 1995/10/04 08:58:17 Michiel
* FreeAnodeBlocks nu met anodechains geimplementeerd (FAB kan nu falen!).
*
* Revision 14.9 1995/10/03 10:59:37 Michiel
* merged
*
* Revision 14.8 1995/09/28 12:18:25 Michiel
* soft/hardlink namelength check added
* Deldir now frees oldblocknr of dirty member blocks
*
* Revision 14.7 1995/08/24 13:01:27 Michiel
* Touch now doesn't touch rootblock because that gives
* disk recognition problems when changing disks
*
* Revision 14.6 1995/08/21 04:18:49 Michiel
* RenameAndMove didn't check if source was deldir
*
* Revision 14.5 1995/08/16 14:31:34 Michiel
* added KillEmpty
* added forced_RemoveDirEntry
*
* Revision 14.4 1995/08/04 04:17:09 Michiel
* SetProtection on deldir now allowed (using masks).
* SetOwner on deldir now allowed
* Touching deldir when file added to deldir
* Now using protection field of deldir for all deldirentries
*
* Revision 14.3 1995/08/02 16:09:39 Michiel
* Filename size limitation (31 characters)
* Empty filenames not accepted
*
* Revision 14.2 1995/07/28 07:58:01 Michiel
* Deldirentry valid check added
*
* Revision 14.1 1995/07/21 06:43:33 Michiel
* DELDIR implemented
* fixed ExNext problem (?)
* NewDir now does a diskwp. check
* Touch() now updates rootdir too
*
* Revision 13.11 1995/07/11 17:29:31 Michiel
* ErrorMsg () calls use messages.c variables now.
*
* Revision 13.10 1995/07/11 09:23:36 Michiel
* DELDIR stuff
*
* Revision 13.9 1995/07/07 14:41:21 Michiel
* no fib->fib_Reserved stuff
* ProtectFile fix
*
* Revision 13.8 1995/06/23 17:26:57 Michiel
* MakeDirEntry now also sets protection to default and owner to current (multiuser)
*
* Revision 13.7 1995/06/21 08:13:18 Michiel
* CheckVolume() calls removed (moved to dostohandlerinterface.c)
*
* Revision 13.6 1995/06/20 18:55:00 Michiel
* fixed a bug in FreeAnodeBlocks
* Examine checks softprotect
*
* Revision 13.5 1995/06/15 18:55:28 Michiel
* pooled mem
*
* Revision 13.4 1995/06/08 11:12:32 Michiel
* Now GetFullPath checks if path is directory.
*
* Revision 13.3 1995/06/04 07:43:54 Michiel
* Longword protection implemented
*
* Revision 13.2 1995/05/03 19:14:13 Michiel
* LOCK added to create soft & hardlink
*
* Revision 13.1 1995/04/23 09:06:53 Michiel
* Rewritten direntry change routines,
* solving directory-order problem
*
* Revision 12.9 1995/04/18 17:08:16 Michiel
* CopyMem() to memcpy() and some cosmetic changes
*
* Revision 12.8 1995/04/14 10:03:53 Michiel
* 'Out of buffers' problem fixed.
*
* Revision 12.7 1995/04/05 12:24:43 Michiel
* Bugfix in ExamineAll
* Don't allow hardlinks when no dirextension
*
* Revision 12.6 1995/03/30 11:53:46 Michiel
* Rename now does a notify to sourcedir if rename across dirs
*
* Revision 12.5 1995/03/30 10:50:37 Michiel
* some notify stuff added
*
* Revision 12.4 1995/03/24 16:29:57 Michiel
* Softlink support added
* Hardlink bugs fixed
*
* Revision 12.3 1995/02/28 18:20:49 Michiel
* Link handling functions added: DeleteLink(), RemapLinks(), UpdateLinks(),
* FetchObject(), UpdateLinkDir().
* NewFile() takes over old direntry now, instead of delete/create.
* GetDir() resolves links.
*
* Revision 12.2 1995/02/24 07:12:41 Michiel
* CreateLink added, MakeDirEntry changed
*
* Revision 12.1 1995/02/23 06:57:01 Michiel
* Directory extension implemented
*
* Revision 11.5 1995/02/15 16:43:39 Michiel
* Release version
* Using new headers (struct.h & blocks.h)
*
* Revision 11.4 1995/01/29 07:34:57 Michiel
* Bug in FreeAnodeBlocks fixed
*
* Revision 11.3 1995/01/24 09:49:51 Michiel
* Cache hashing added
*
* Revision 11.2 1995/01/18 04:29:34 Michiel
* Bugfixes. Now ready for beta release.
*
* Revision 11.1 1995/01/08 16:16:29 Michiel
* Compiled
*
* Revision 10.4 1994/11/15 17:52:30 Michiel
* GuruBook update
*
* Revision 10.3 1994/10/28 06:06:40 Michiel
* uses new listentry field anodenr
*
* Revision 10.2 1994/10/27 11:29:33 Michiel
* *** empty log message ***
*
* Revision 10.1 1994/10/24 11:16:28 Michiel
* first RCS revision
* */
// anodenr in cdirblock !!! @->bugnr @@->currently wrong
//#define DEBUG 1
#define __USE_SYSBASE
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <dos/exall.h>
#include <dos/filehandler.h>
#include <proto/intuition.h>
#include <proto/utility.h>
#if MULTIUSER
#include <proto/multiuser.h>
#endif
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
// own includes
#include "debug.h"
#include "blocks.h"
#include "struct.h"
#include "directory_protos.h"
#include "allocation_protos.h"
#include "volume_protos.h"
#include "lock_protos.h"
#include "disk_protos.h"
#include "anodes_protos.h"
#include "update_protos.h"
#include "lru_protos.h"
#include "ass_protos.h"
#include "support.c"
#include "kswrapper.h"
void PFSDoNotify(struct fileinfo *object, BOOL checkparent, globaldata * g);
void PFSUpdateNotify(ULONG dirnode, DSTR filename, ULONG anodenr, globaldata * g);
/**********************************************************************/
/* DEBUG */
/**********************************************************************/
#ifdef DEBUG
extern BOOL debug;
static UBYTE debugbuf[120];
#define DebugOn debug++
#define DebugOff debug=0
#define DebugMsg(msg) if(debug) {NormalErrorMsg(msg, NULL);debug=0;}
#define DebugMsgNum(msg, num) sprintf(debugbuf, "%s 0x%08lx.", msg, num); \
if(debug) {NormalErrorMsg(debugbuf, NULL);debug=0;}
#define DebugMsgName(msg, name) sprintf(debugbuf, "%s >%s<.", msg, name); \
if(debug) {NormalErrorMsg(debugbuf, NULL);debug=0;}
#else
#define DebugOn
#define DebugOff
#define DebugMsg(m)
#define DebugMsgNum(msg,num)
#define DebugMsgName(msg, name)
#endif
/*
* Contents
*/
static BOOL GetParentOf(union objectinfo *path, SIPTR *error, globaldata *);
static BOOL GetDir(STRPTR dirname, union objectinfo *path, SIPTR *error, globaldata *);
static BOOL GetObject(STRPTR objectname, union objectinfo *path, SIPTR *error, globaldata *);
static BOOL SearchInDir(ULONG dirnodenr, STRPTR objectname, union objectinfo *info, globaldata * g);
static void FillFib(struct direntry *direntry, struct FileInfoBlock *fib, globaldata * g);
#if DELDIR
static struct deldirentry *SearchInDeldir(STRPTR delname, union objectinfo *result, globaldata *g);
static BOOL IsDelfileValid(struct deldirentry *dde, struct cdeldirblock *ddblk, globaldata *g);
static BOOL BlockTaken(struct canode *anode, globaldata *g);
static void FillDelfileFib(struct deldirentry *dde, ULONG slotnr, struct FileInfoBlock *fib, globaldata *g);
static struct deldirentry *GetDeldirEntry(IPTR *nr, globaldata *g);
static ULONG FillInDDEData(struct ExAllData *buffer, LONG type, struct deldirentry *dde, ULONG ddenr, ULONG spaceleft, globaldata *g);
static struct cdeldirblock *GetDeldirBlock(UWORD seqnr, globaldata *g);
#endif
static void GetFirstEntry(lockentry_t *, globaldata *);
static ULONG GetFirstNonEmptyDE(ULONG anodenr, struct fileinfo *, globaldata *);
static void RemakeNextEntry(lockentry_t *, struct FileInfoBlock *, globaldata *);
static ULONG FillInData(struct ExAllData *, LONG, struct direntry *, ULONG, globaldata *);
static BOOL DeleteDir(union objectinfo *, SIPTR *, globaldata *);
static BOOL DirIsEmpty(ULONG, globaldata *);
static BOOL MakeDirEntry(BYTE type, UBYTE *name, UBYTE *entrybuffer, globaldata * g);
static BOOL IsChildOf(union objectinfo child, union objectinfo parent, globaldata * g);
static BOOL DeleteLink(struct fileinfo *link, SIPTR *, globaldata * g);
static BOOL RemapLinks(struct fileinfo *object, globaldata * g);
static void UpdateLinkDir(struct direntry *object, ULONG newdiran, globaldata * g);
static void MoveLink(struct direntry *object, ULONG newdiran, globaldata *g);
static void RenameAcrossDirs(struct fileinfo from, struct direntry *to, union objectinfo *destdir, struct fileinfo *result, globaldata * g);
static void RenameWithinDir(struct fileinfo from, struct direntry *to, struct fileinfo *newinfo, globaldata * g);
static void RenameInPlace(struct fileinfo from, struct direntry *to, struct fileinfo *result, globaldata * g);
static struct direntry *CheckFit(struct cdirblock *blok, int needed, globaldata * g);
static BOOL MoveToPrevious(struct fileinfo de, struct direntry *to, struct fileinfo *result, globaldata * g);
static void RemoveDirEntry(struct fileinfo info, globaldata * g);
static BOOL AddDirectoryEntry(union objectinfo *dir, struct direntry *newentry, struct fileinfo *newinfo, globaldata * g);
static void UpdateChangedRef(struct fileinfo from, struct fileinfo *to, int diff, globaldata * g);
#if VERSION23
static int AllocDeldirSlot(globaldata * g);
static void AddToDeldir(union objectinfo *info, int ddnr, globaldata * g);
#else
static void AddToDeldir(union objectinfo *info, globaldata * g);
static BOOL FreeAnodeBlocks(ULONG anodenr, enum freeblocktype freenodes, globaldata * g);
#endif
/**********************************************************************/
/* SEARCH IN DIRECTORY */
/* SEARCH IN DIRECTORY */
/* SEARCH IN DIRECTORY */
/**********************************************************************/
/* GetFullPath converts a relative path to an absolute path.
* The fileinfo of the new path is returned in [result].
* The return value is the filename without path.
* Error: return 0
*
* Parsing Syntax:
* : after '/' or at the beginning ==> root
* : after [name] ==> volume [name]
* / after / or ':' or at the beginning ==> parent
* / after dir ==> get dir
* / after file ==> error (ALWAYS) (AMIGADOS ok if LAST file)
*
* IN basispath, filename, g
* OUT fullpath, error
*
* If only a partial path is found, a pointer to the unparsed part
* will be stored in g->unparsed.
*/
UBYTE *GetFullPath(union objectinfo *basispath, STRPTR filename,
union objectinfo *fullpath, SIPTR *error, globaldata * g)
{
UBYTE *pathpart, parttype;
COUNT index;
BOOL eop = FALSE, success = TRUE;
struct volumedata *volume;
// VVV Init:getrootvolume
ENTER("GetFullPath");
g->unparsed = NULL;
/* Set base path */
if (basispath)
*fullpath = *basispath;
else
GetRoot(fullpath, g);
/* The basispath should not be a file
* BTW: softlink is illegal too, but not possible
*/
if (IsFile(*fullpath) || IsDelFile(*fullpath))
{
*error = ERROR_OBJECT_WRONG_TYPE;
return NULL;
}
/* check if device present */
if (IsVolume(*fullpath) || IsDelDir(*fullpath))
volume = fullpath->volume.volume;
else
volume = fullpath->file.dirblock->volume;
if (!CheckVolume(volume, 0, error, g))
return (0);
/* extend base-path using filename and
* continue until path complete (eop = end of path)
*/
while (!eop)
{
pathpart = filename;
index = strcspn(filename, "/:");
parttype = filename[index];
filename[index] = 0x0;
switch (parttype)
{
case ':':
success = FALSE;
break;
case '/':
if (*pathpart == 0x0)
{
// if already at root, fail with an error
if (IsVolume(*fullpath))
{
*error = ERROR_OBJECT_NOT_FOUND;
success = FALSE;
break;
}
success = GetParentOf(fullpath, error, g);
}
else
success = GetDir(pathpart, fullpath, error, g);
break;
default:
eop = TRUE;
}
filename[index] = parttype;
if (!success)
{
/* return pathrest for readlink() */
if (*error == ERROR_IS_SOFT_LINK)
g->unparsed = filename + index;
else if (*error == ERROR_OBJECT_NOT_FOUND)
g->unparsed = filename;
return NULL;
}
if (!eop)
filename += index + 1;
}
return filename;
}
BOOL GetRoot(union objectinfo * path, globaldata * g)
{
UpdateCurrentDisk(g);
path->volume.root = 0;
path->volume.volume = g->currentvolume;
return DOSTRUE;
}
/* pre: - path <> 0 and volume or directory
* result back in path
*/
static BOOL GetParentOf(union objectinfo *path, SIPTR *error, globaldata * g)
{
BOOL ok;
union objectinfo info;
info = *path;
ok = GetParent(&info, path, error, g);
return ok;
}
/* pre: - path <> 0 and volume of directory
* - dirname without path; strlen(dirname) > 0
* result back in path
*/
static BOOL GetDir(STRPTR dirname, union objectinfo *path, SIPTR *error, globaldata * g)
{
BOOL found;
found = GetObject(dirname, path, error, g);
#if DELDIR
if (g->deldirenabled && IsDelDir(*path))
return DOSTRUE;
#endif
/* check if found directory */
#if DELDIR
if (!found || IsFile(*path) || IsDelFile(*path))
#else
if (!found || IsFile(*path))
#endif
{
*error = ERROR_OBJECT_NOT_FOUND; // DOPUS doesn't like DIR_NOT_FOUND
return DOSFALSE;
}
/* check if softlink */
if (IsSoftLink(*path))
{
*error = ERROR_IS_SOFT_LINK;
return DOSFALSE;
}
/* resolve links */
if (path->file.direntry->type == ST_LINKDIR)
{
struct extrafields extrafields;
struct canode linknode;
GetExtraFields(path->file.direntry, &extrafields);
GetAnode(&linknode, path->file.direntry->anode, g);
if (!FetchObject(linknode.clustersize, extrafields.link, path, g))
return DOSFALSE;
}
return DOSTRUE;
}
/* pre: - path<>0 and volume of directory
* - objectname without path; strlen(objectname) > 0
* result back in path
*/
static BOOL GetObject(STRPTR objectname, union objectinfo *path, SIPTR *error, globaldata *g)
{
ULONG anodenr;
BOOL found;
#if DELDIR
if (IsDelDir(*path))
{
found = (SearchInDeldir(objectname, path, g) != NULL);
goto go_error;
}
#endif
if (IsVolume(*path))
anodenr = ANODE_ROOTDIR;
else
anodenr = path->file.direntry->anode;
DB(Trace(1, "GetObject", "parent anodenr %lx\n", anodenr));
found = SearchInDir(anodenr, objectname, path, g);
go_error:
if (!found)
{
#if DELDIR
if (g->deldirenabled && IsVolume(*path))
{
if (stricmp(deldirname+1, objectname) == 0)
{
path->deldir.special = SPECIAL_DELDIR;
path->deldir.volume = g->currentvolume;
return DOSTRUE;
}
}
#endif
*error = ERROR_OBJECT_NOT_FOUND;
return DOSFALSE;
}
return DOSTRUE;
}
/* <FindObject>
*
* FindObject searches the object 'fname' in directory 'directory'.
* FindObject zoekt het object 'fname' in directory 'directory'.
* Interpret empty filename as parent and ":" as root.
* Does not use multiple-assign-list
*
* input : - [directory]: the 'root' directory of the search
* - [objectname]: file to be found, including path
*
* output: - [object]: If file found : fileinfo of object
* If path found : fileinfo of directory
* - [error]: Errornumber as result = DOSFALSE; otherwise 0
*
* result: DOSTRUE (-1) = file found (->in fileinfo)
* DOSFALSE (0) = error
*
* If only a partial path is found, a pointer to the unparsed part
* will be stored in g->unparsed.
*/
BOOL FindObject(union objectinfo *directory, STRPTR objectname,
union objectinfo *object, SIPTR *error, globaldata *g)
{
UBYTE *filename;
BOOL ok;
*error = 0;
filename = GetFullPath(directory, objectname, object, error, g);
if (!filename)
{
DB(Trace(2, "FindObject !filename %s\n", objectname));
return DOSFALSE;
}
/* path only (dir or volume) */
if (!*filename)
return DOSTRUE;
/* there is a filepart (file or dir) */
ok = GetObject(filename, object, error, g);
if (!ok && (*error == ERROR_OBJECT_NOT_FOUND))
g->unparsed = filename;
return ok;
}
/* GetParent
*
* childanodenr = anodenr of start directory (the child)
* parentanodenr = anodenr of directory containing childanodenr (the parent)
* childfi == parentfi can be dangerous
* in:childfi; out:parentfi, error
*/
BOOL GetParent(union objectinfo *childfi, union objectinfo *parentfi, SIPTR *error, globaldata *g)
{
struct canode anode;
struct cdirblock *dirblock;
struct direntry *de;
ULONG anodeoffset = 0;
ULONG childanodenr, parentanodenr;
BOOL eod = FALSE, eob = FALSE, found = FALSE;
// -I- Find anode of parent
if (!childfi || IsVolume(*childfi)) // child is rootdir
{
*error = 0x0; /* No error; just return NULL */
return 0;
}
#if DELDIR
if (g->deldirenabled)
{
if (IsDelDir(*childfi))
return GetRoot(parentfi, g);
if (IsDelFile(*childfi))
{
parentfi->deldir.special = SPECIAL_DELDIR;
parentfi->deldir.volume = g->currentvolume;
return TRUE;
}
}
#endif
childanodenr = childfi->file.dirblock->blk.anodenr; /* the directory 'child' is in */
parentanodenr = childfi->file.dirblock->blk.parent; /* the directory 'childanodenr' is in */
// -II- check if in root
if (parentanodenr == 0) /* child is in rootdir */
{
parentfi->volume.root = 0;
parentfi->volume.volume = childfi->file.dirblock->volume;
return TRUE;
}
// -III- get parentdirectory and find direntry
GetAnode(&anode, parentanodenr, g);
while (!found && !eod)
{
dirblock = LoadDirBlock(anode.blocknr + anodeoffset, g);
if (dirblock)
{
de = FIRSTENTRY(dirblock);
eob = 0;
while (!found && !eob)
{
found = (de->anode == childanodenr);
eob = (de->next == 0);
if (!found && !eob)
de = NEXTENTRY(de);
}
if (!found)
eod = !NextBlock(&anode, &anodeoffset, g);
}
else
{
break;
}
}
if (!found)
{
DB(Trace(1, "GetParent", "DiskNotValidated %ld\n", childanodenr));
*error = ERROR_DISK_NOT_VALIDATED;
return FALSE;
}
parentfi->file.direntry = de;
parentfi->file.dirblock = dirblock;
LOCK(dirblock);
return TRUE;
}
/* SearchInDir
*
* Search an object in a directory and return the fileinfo
*
* input : - dirnodenr: anodenr of directory to search in
* - objectname: found object (without path)
*
* output: - info: objectinfo of found object
*
* result: success
*/
static BOOL SearchInDir(ULONG dirnodenr, STRPTR objectname, union objectinfo *info, globaldata * g)
{
struct canode anode;
struct cdirblock *dirblock;
struct direntry *entry = NULL;
BOOL found = FALSE, eod = FALSE;
ULONG anodeoffset;
UBYTE intl_name[PATHSIZE];
ENTER("SearchInDir");
ctodstr(objectname, intl_name);
/* truncate */
if (intl_name[0] > FILENAMESIZE - 1)
intl_name[0] = FILENAMESIZE - 1;
intltoupper(intl_name); /* international uppercase objectname */
GetAnode(&anode, dirnodenr, g);
anodeoffset = 0;
dirblock = LoadDirBlock(anode.blocknr, g);
while (dirblock && !found && !eod) /* eod stands for end-of-dir */
{
entry = (struct direntry *)(&dirblock->blk.entries);
/* scan block */
while (entry->next)
{
found = intlcmp(intl_name, DIRENTRYNAME(entry));
if (found)
break;
entry = NEXTENTRY(entry);
}
/* load next block */
if (!found)
{
if (NextBlock(&anode, &anodeoffset, g))
dirblock = LoadDirBlock(anode.blocknr + anodeoffset, g);
else
eod = TRUE;
}
}
/* make fileinfo */
if (!dirblock)
{
return FALSE;
}
else if (found)
{
info->file.direntry = entry;
info->file.dirblock = dirblock;
LOCK(dirblock);
return TRUE;
}
else
return FALSE;
}
/*
* Search object by anodenr in directory
* in: diranodenr, target: anodenr of target and the anodenr of the directory to search in
* out: result: an objectinfo to the object, if found
* returns: success
*/
BOOL FetchObject(ULONG diranodenr, ULONG target, union objectinfo * result, globaldata * g)
{
struct canode anode;
struct cdirblock *dirblock;
struct direntry *de;
ULONG anodeoffset = 0;
BOOL eod = FALSE, found = FALSE;
/* Get directory and find object */
GetAnode(&anode, diranodenr, g);
while (!found && !eod)
{
dirblock = LoadDirBlock(anode.blocknr + anodeoffset, g);
if (dirblock)
{
de = FIRSTENTRY(dirblock);
while (de->next)
{
if (!(found = (de->anode == target)))
de = NEXTENTRY(de);
else
break;
}
if (!found)
eod = !NextBlock(&anode, &anodeoffset, g);
}
else
break;
}
if (!found)
return FALSE;
result->file.dirblock = dirblock;
result->file.direntry = de;
LOCK(dirblock);
return TRUE;
}
/**********************************************************************/
/* GET DIRECTORY CONTENTS */
/* GET DIRECTORY CONTENTS */
/* GET DIRECTORY CONTENTS */
/**********************************************************************/
/* ExamineFile
*
* Specification:
*
* - fill in fileinfoblock
* - prepares for ExamineNextFile
* - result: success
* *error: error if failure; else undefined
*
* - fib_DirEntryType must be equal to fib_EntryType
*/
BOOL ExamineFile(listentry_t *file, struct FileInfoBlock * fib, SIPTR *error, globaldata * g)
{
struct volumedata *volume;
#if DELDIR
struct crootblockextension *rext;
union objectinfo *info;
#endif
/* volume must be or become currentvolume */
if (!file)
volume = g->currentvolume;
else
volume = file->volume;
/* fill in fib */
fib->fib_DiskKey = (IPTR)file; // I use it as dir-block-number for ExNext
if (!file || IsVolumeEntry(file))
{
fib->fib_DirEntryType = \
fib->fib_EntryType = ST_USERDIR;
fib->fib_Protection = (g->diskstate == ID_WRITE_PROTECTED) || g->softprotect;
fib->fib_Size = 0;
fib->fib_NumBlocks = 0;
if (volume->rblkextension)
{
fib->fib_Date.ds_Days = (ULONG)volume->rblkextension->blk.root_date[0];
fib->fib_Date.ds_Minute = (ULONG)volume->rblkextension->blk.root_date[1];
fib->fib_Date.ds_Tick = (ULONG)volume->rblkextension->blk.root_date[2];
}
else
{
fib->fib_Date.ds_Days = (ULONG)volume->rootblk->creationday;
fib->fib_Date.ds_Minute = (ULONG)volume->rootblk->creationminute;
fib->fib_Date.ds_Tick = (ULONG)volume->rootblk->creationtick;
}
strncpy(fib->fib_FileName, volume->rootblk->diskname, volume->rootblk->diskname[0] + 1);
fib->fib_Comment[0] = 0x0;
//fib->fib_Reserved[0] = 0x0;
}
else
#if DELDIR
{
info = &file->info;
if (IsDelDir(*info))
{
rext = volume->rblkextension;
fib->fib_DiskKey = 0;
fib->fib_DirEntryType = \
fib->fib_EntryType = ST_USERDIR;
fib->fib_Protection = (ULONG)rext->blk.dd_protection;
fib->fib_Size = 0;
fib->fib_NumBlocks = 0;
fib->fib_Date.ds_Days = (ULONG)rext->blk.dd_creationday;
fib->fib_Date.ds_Minute = (ULONG)rext->blk.dd_creationminute;
fib->fib_Date.ds_Tick = (ULONG)rext->blk.dd_creationtick;
strcpy(fib->fib_FileName, deldirname);
fib->fib_Comment[0] = 0x0;
fib->fib_OwnerUID = (ULONG)rext->blk.dd_uid;
fib->fib_OwnerGID = (ULONG)rext->blk.dd_gid;
/* prepare ExNext() */
((lockentry_t *)file)->nextanode = 0;
return DOSTRUE;
}
else if (IsDelFile(*info))
{
FillDelfileFib(NULL, info->delfile.slotnr, fib, g);
return DOSTRUE;
}
else
#endif
{
FillFib(file->info.file.direntry, fib, g);
}
#if DELDIR
}
#endif
/* prepare examinenext */
if (!file || file->type.flags.dir)
GetFirstEntry((lockentry_t *)file, g);
return DOSTRUE;
}
/* ExamineNextFile
*
* Specification:
*
* - used to obtain info on all directory entries
* - fill in fileinfoblock
*
* Quirks:
*
* - fib_DirEntryType must be equal to fib_EntryType
* - it is allowed to stop invoking before end of dir
* - for old compatibility: only DiskKey and FileName guaranteed to be the same
* on subsequent calls
* - it is possible to receive other packets between ExNext's -> special cases
* - the lock is passed is not always the same, but it is a lock to the same object
*
* Implementation:
*
* - fib_DiskKey contains address of lock; different->problems
*
* lock->nextentry contains pointer to be fetched entry. End of dir <=>
* lock->nextentry == {NULL, NULL}
*
*/
BOOL ExamineNextFile(lockentry_t *file, struct FileInfoBlock * fib,
SIPTR *error, globaldata * g)
{
struct direntry *direntry;
*error = 0;
/* file must be lock on dir; NULL lock not allowed */
if (!file || !file->le.type.flags.dir)
{
*error = ERROR_OBJECT_WRONG_TYPE;
return DOSFALSE;
}
#if DELDIR
if (IsDelDir(file->le.info))
{
struct deldirentry *dde;
dde = GetDeldirEntry(&fib->fib_DiskKey, g);
if (dde)
{
FillDelfileFib(dde, fib->fib_DiskKey, fib, g);
fib->fib_DiskKey++;
return DOSTRUE;
}
else
{
*error = ERROR_NO_MORE_ENTRIES;
return DOSFALSE;
}
}
#endif
/* check if same lock used */
if ((IPTR)file != (IPTR)fib->fib_DiskKey)
{
DB(Trace(1, "ExamineNextFile", "Other lock!!\n"));
RemakeNextEntry(file, fib, g);
}
/* Check if end of dir */
if (file->nextentry.dirblock == NULL)
{
*error = ERROR_NO_MORE_ENTRIES;
return DOSFALSE;
}
/* Fill infoblock */
direntry = file->nextentry.direntry;
if (direntry->next)
{
fib->fib_DiskKey = (IPTR)file; // I use it as dir-block-number
FillFib(direntry, fib, g);
}
else