-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvolume.c
1409 lines (1232 loc) · 34.7 KB
/
volume.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: volume.c 11.34 1999/09/11 17:05:14 Michiel Exp Michiel $ */
/* $Log: volume.c $
* Revision 11.34 1999/09/11 17:05:14 Michiel
* bugfix version 18.4
*
* Revision 11.33 1999/05/14 11:31:34 Michiel
* Long filename support implemented; bugfixes
*
* Revision 11.32 1999/03/23 05:57:39 Michiel
* Autoupgrade bug involving MODE_SUPERDELDIR fixed
*
* Revision 11.31 1999/03/09 10:32:19 Michiel
* 00136: 1024 byte sector support
*
* Revision 11.30 1999/02/22 16:25:30 Michiel
* Changes for increasing deldir capacity
*
* Revision 11.29 1998/09/27 11:26:37 Michiel
* Dynamic rootblock allocation in GetCurrentRoot
* New ErrorMsg function that replaces macro
*
* Revision 11.28 1998/05/30 18:40:14 Michiel
* Title of error requesters was wrong
*
* Revision 11.27 1998/05/27 21:00:08 Michiel
* MODE_DATESTAMP is automatically turned on
*
* Revision 11.26 1998/05/22 22:59:58 Michiel
* Datestamps added
*
* Revision 11.25 1997/03/03 22:04:04 Michiel
* Release 16.21
*
* Revision 11.24 1996/03/29 17:00:11 Michiel
* bugfix: rootblock was freed with FreeVec instead of with FreeBufmem
*
* Revision 11.23 1996/01/30 12:50:39 Michiel
* Diskinsertsequence didn't used old instead of just read rootblock
* --- working tree overlap ---
*
* Revision 11.22 1996/01/03 10:04:35 Michiel
* simple change
*
* Revision 11.21 1995/11/15 16:00:05 Michiel
* Rootblock extension detection, loading and automatic creation
*
* Revision 11.20 1995/11/07 15:07:18 Michiel
* Adapted to new datacache (16.2)
* FreeUnusedResources() checks if volume
*
* Revision 11.19 1995/09/01 11:18:05 Michiel
* CheckCurrentVolumeBack added
* NormalErrorMsg changed. Extra argument that specifies the
* number of targets added.
*
* Revision 11.18 1995/08/21 04:23:11 Michiel
* Create deldir if it isn't there
*
* Revision 11.17 1995/08/04 04:23:01 Michiel
* use of MODE_SIZEFIELD added
*
* Revision 11.16 1995/07/21 06:58:07 Michiel
* DELDIR adaptions: MakeVolumeData, FreeVolumeResources
*
* Revision 11.15 1995/07/11 17:29:31 Michiel
* ErrorMsg () calls use messages.c variables now.
*
* Revision 11.14 1995/07/11 09:23:36 Michiel
* DELDIR stuff
*
* Revision 11.13 1995/07/07 14:38:47 Michiel
* AFSLITE stuff
*
* Revision 11.12 1995/07/07 10:14:12 Michiel
* changed CheckVolume()
*
* Revision 11.11 1995/06/19 09:43:19 Michiel
* softprotect of on diskchange
*
* Revision 11.10 1995/06/16 09:59:37 Michiel
* using Allec & FreeBufMem
*
* Revision 11.9 1995/06/15 18:56:53 Michiel
* pooled mem
*
* Revision 11.8 1995/05/20 12:12:12 Michiel
* Updated messages to reflect Ami-FileLock
* CUTDOWN version
* protection update
*
* Revision 11.7 1995/03/30 18:55:39 Michiel
* Initialization of notifylist added to MakeVolumeData()
*
* Revision 11.6 1995/02/15 16:43:39 Michiel
* Release version
* Using new headers (struct.h & blocks.h)
*
* Revision 11.5 1995/01/29 07:34:57 Michiel
* Raw res read/write and LOCK update
*
* Revision 11.4 1995/01/24 09:54:14 Michiel
* Cache hashing added
*
* Revision 11.3 1995/01/18 04:29:34 Michiel
* Bugfixes. Now ready for beta release.
*
* Revision 11.2 1995/01/15 05:26:44 Michiel
* fixed FreeVolumeResources bug
* inhibited trackdisk specific parts
*
* Revision 11.1 1995/01/08 16:24:01 Michiel
* Compiled (new MODE_BIG version)
*
* Revision 10.4 1994/11/15 17:52:30 Michiel
* GURU book update
*
* Revision 10.3 1994/10/29 08:55:42 Michiel
* changed process references to msgport references
*
* Revision 10.2 1994/10/27 11:38:17 Michiel
* Killed old Update() routines, that now reside in new_Update()
* MakeBlockDirty() now unconditionally sets g->dirty
*
* Revision 10.1 1994/10/24 11:16:28 Michiel
* first RCS revision
* */
//#define DEBUG 1
//#define DEBUGMODE 1
#define __USE_SYSBASE
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/devices.h>
#include <exec/io.h>
#include <exec/interrupts.h>
#include <devices/input.h>
#include <devices/timer.h>
#include <dos/filehandler.h>
#include <intuition/intuition.h>
#include <proto/intuition.h>
#include <clib/alib_protos.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include "debug.h"
// own includes
#include "blocks.h"
#include "struct.h"
#include "directory_protos.h"
#include "volume_protos.h"
#include "disk_protos.h"
#include "allocation_protos.h"
#include "anodes_protos.h"
#include "update_protos.h"
#include "lru_protos.h"
#include "ass_protos.h"
#include "init_protos.h"
#include "format_protos.h"
#include "kswrapper.h"
static VOID CreateInputEvent(BOOL inserted, globaldata *g);
static BOOL GetCurrentRoot(struct rootblock **rootblock, globaldata *g);
/**********************************************************************/
/* DEBUG */
/**********************************************************************/
#ifdef DEBUG
extern BOOL debug;
static UBYTE debugbuf[120];
#define DebugOn debug++
#define DebugOff debug=(debug?debug-1: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
/**********************************************************************/
/* NEWVOLUME */
/* NEWVOLUME */
/* NEWVOLUME */
/**********************************************************************/
/* NewVolume
**
** I Update diskchangenumber
** :nochange->exit (tenzij FORCE = TRUE)
**
** II New state = volume present?
** :get id of new disk (read rootblock)
** New disk = current disk?
** :exit
**
** III Old state = volume present?
** :diskremoved-sequence
**
** IV New state = volume present ?
** :diskinserted-sequence
**-----
** II-III-IV ordering is essential because diskremove-sequence has to be done before
** diskinsert-sequence and diskremove-sequence can only be executed if newvolume <>
** currentvolume
**-----
** DiskRemove-sequence
**
** I Clear globaldata->currentvolume (prevent infinite recursive loop)
**
** II Changed blocks in cache ?
** :request old volume (causes recursive call)
** :update volume
** :exit
**
** III Locks/files open on volume?
** yes: link locks in doslist
** clear volume task field
** no: remove volume from doslist
** free all volume resources
**-----
** DiskInsert-sequence
**
** I Search new disk in volumelist
** found: take over volume and locklist
** ~found: make new volumestructure
** link volume in doslist
**
** II Update globaldata->currentvolume
**----
** use FORCE to force a new volume even if the changecount is equal
*/
static BOOL SameDisk(struct rootblock *, struct rootblock *);
static BOOL SameDiskDL(struct rootblock *, struct DeviceList *);
static void TakeOverLocks(struct FileLock *, globaldata *);
static void DiskInsertSequence(struct rootblock *rootblock, globaldata *g);
static void DiskRemoveSequence(globaldata *g);
void NewVolume (BOOL FORCE, globaldata *g)
{
BOOL oldstate, newstate, changed;
struct rootblock *rootblock;
/* check if something changed */
changed = UpdateChangeCount (g);
if (!FORCE && !changed)
return;
if (!AttemptLockDosList(LDF_VOLUMES | LDF_WRITE))
return;
ENTER("NewVolume");
FlushDataCache (g);
/* newstate <=> there is a PFS disk present */
oldstate = g->currentvolume ? TRUE : FALSE;
newstate = GetCurrentRoot (&rootblock, g);
/* undo error enforced softprotect */
if ((g->softprotect == 1) && g->protectkey == ~0)
g->softprotect = g->protectkey = 0;
if (oldstate && !newstate)
DiskRemoveSequence (g);
if (newstate)
{
if (oldstate && SameDisk (rootblock, g->currentvolume->rootblk))
{
FreeBufmem (rootblock, g); /* @XLVII */
}
else
{
if (oldstate)
DiskRemoveSequence (g);
DiskInsertSequence (rootblock, g);
}
}
else
{
g->currentvolume = NULL; /* @XL */
}
UnLockDosList(LDF_VOLUMES | LDF_WRITE);
UpdateAndMotorOff(g);
EXIT("NewVolume");
}
/* pre:
** globaldata->currentvolume not necessarily present
** post:
** the old currentvolume is updated en als 'removed' currentvolume == 0
** return waarde = currentdisk back in drive?
** used by NewVolume and ACTION_INHIBIT
*/
static void DiskRemoveSequence(globaldata *g)
{
struct volumedata *oldvolume = g->currentvolume;
ENTER("DiskRemoveSequence");
/* -I- update disk
** will ask for old volume if there are unsaved changes
** causes recursive NewVolume call. That's why 'currentvolume'
** has to be cleared first; UpdateDisk won't be called for the
** same disk again
*/
if(oldvolume && g->dirty)
{
RequestCurrentVolumeBack(g);
UpdateDisk(g);
return;
}
/* disk removed */
g->currentvolume = NULL;
FlushDataCache (g);
/* -II- link locks in doslist
** lockentries: link to doslist...
** fileentries: link them too...
*/
if(!IsMinListEmpty(&oldvolume->fileentries))
{
DB(Trace(1, "DiskRemoveSequence", "there are locks\n"));
oldvolume->devlist->dl_LockList = MKBADDR(&(((listentry_t *)(HeadOf(&oldvolume->fileentries)))->lock));
oldvolume->devlist->dl_Task = NULL;
FreeUnusedResources(oldvolume, g);
}
else
{
DB(Trace(1, "DiskRemoveSequence", "removing doslist\n"));
RemDosEntry((struct DosList*)oldvolume->devlist);
FreeDosEntry((struct DosList*)oldvolume->devlist);
MinRemove(oldvolume);
FreeVolumeResources(oldvolume, g);
}
#ifdef TRACKDISK
if(g->trackdisk)
{
g->request->iotd_Req.io_Command = CMD_CLEAR;
DoIO((struct IORequest*)g->request);
}
#endif
CreateInputEvent(FALSE, g);
#if ACCESS_DETECT
g->tdmode = ACCESS_UNDETECTED;
#endif
EXIT("DiskRemoveSequence");
return;
}
BOOL SafeDiskRemoveSequence(globaldata *g)
{
while (g->currentvolume) { /* inefficient.. */
if (AttemptLockDosList(LDF_VOLUMES | LDF_WRITE)) {
DiskRemoveSequence(g);
UnLockDosList(LDF_VOLUMES | LDF_WRITE);
} else {
return FALSE;
}
}
return TRUE;
}
static void DiskInsertSequence(struct rootblock *rootblock, globaldata *g)
{
struct DosList *doslist;
struct DosInfo *di;
struct DeviceList *devlist;
BOOL found = FALSE, added = FALSE;
UBYTE diskname[DNSIZE]; // or should it be a DSTR??
SIPTR locklist;
ENTER("DiskInsertSequence");
/* -I- Search new disk in volumelist */
BCPLtoCString(diskname, rootblock->diskname);
di = BADDR(((struct RootNode *)DOSBase->dl_Root)->rn_Info);
doslist = BADDR(di->di_DevInfo);
for (doslist = BADDR(di->di_DevInfo);doslist;doslist = BADDR(doslist->dol_Next))
{
if (doslist->dol_Type == DLT_VOLUME && SameDiskDL(rootblock, (struct DeviceList *)doslist))
{
found = TRUE;
break;
}
}
// while(!found)
// {
// doslist = NextDosEntry(doslist, LDF_VOLUMES);
//
// if(doslist && (doslist = FindDosEntry(doslist, diskname, LDF_VOLUMES)))
// found = SameDiskDL(rootblock, (struct DeviceList *)doslist);
// else
// break;
// }
if (found)
{
DB(Trace(1, "DiskInsertSequence", "found\n"));
devlist = (struct DeviceList *)doslist;
locklist = (SIPTR)BADDR(devlist->dl_LockList);
/* take over volume
** use LOCKTOFILEENTRY(lock)->volume to get volumepointer
*/
if(locklist)
{
fileentry_t *fe;
/* get volumepointer @XLXV */
fe = LOCKTOFILEENTRY(locklist);
if(fe->le.type.flags.type == ETF_VOLUME)
g->currentvolume = fe->le.info.volume.volume;
else
g->currentvolume = fe->le.volume;
/* update rootblock */
if (g->rootblock) FreeBufmem (g->rootblock, g);
g->rootblock =
g->currentvolume->rootblk = rootblock;
/* take over filelocks
** lockentries: takeover, change taskfield
** fileentries: don't change taskfield
*/
TakeOverLocks((struct FileLock *)locklist, g);
devlist = (struct DeviceList *)doslist;
devlist->dl_LockList = 0;
devlist->dl_Task = g->msgport;
}
else
{
RemDosEntry(doslist); // @@ freeing rootblk etc?
FreeDosEntry(doslist);
found = FALSE; // an empty doslistentry is useless to us
}
}
if(!found)
{
DB(Trace(1, "DiskInsertSequence", "not found %s\n", diskname));
/* make new doslist entry (MOET eerst (zie blz67 schrift) */
devlist = (struct DeviceList *)MakeDosEntry(diskname, DLT_VOLUME);
if(devlist)
{
/* devlist invullen. Diskname NIET @XLIX */
devlist->dl_Task = g->msgport;
devlist->dl_VolumeDate.ds_Days = rootblock->creationday;
devlist->dl_VolumeDate.ds_Minute = rootblock->creationminute;
devlist->dl_VolumeDate.ds_Tick = rootblock->creationtick;
devlist->dl_LockList = 0; // no locks open yet
devlist->dl_DiskType = rootblock->disktype;
added = AddDosEntry((struct DosList *)devlist);
}
/* make new volumestructure for inserted volume */
g->currentvolume = MakeVolumeData(rootblock, g);
MinAddHead(&g->volumes, g->currentvolume);
g->currentvolume->devlist = (struct DeviceList *)devlist;
/* check if things worked out */
if(!devlist || !added) // duplicate disks or out of memory
{
ErrorMsg (AFS_ERROR_DOSLIST_ADD, NULL, g);
if(devlist)
FreeDosEntry((struct DosList *)devlist);
FreeVolumeResources(g->currentvolume, g);
g->currentvolume = NULL;
}
CreateInputEvent(TRUE, g);
}
/* Reconfigure modules to new volume */
InitModules (g->currentvolume, FALSE, g);
/* create rootblockextension if its not there yet */
if (!g->currentvolume->rblkextension &&
g->diskstate != ID_WRITE_PROTECTED)
{
MakeRBlkExtension (g);
}
#if DELDIR
/* upgrade deldir */
if (rootblock->deldir)
{
struct cdeldirblock *ddblk;
int i, nr;
/* kill current deldir */
ddblk = (struct cdeldirblock *)AllocLRU(g);
if (ddblk)
{
if (RawRead ((UBYTE*)&ddblk->blk, RESCLUSTER, rootblock->deldir, g) == 0)
{
if (ddblk->blk.id == DELDIRID)
{
for (i=0; i<31; i++)
{
nr = ddblk->blk.entries[i].anodenr;
if (nr)
FreeAnodesInChain(nr, g);
}
}
}
FreeLRU ((struct cachedblock *)ddblk);
}
/* create new deldir */
SetDeldir(1, g);
ResToBeFreed(rootblock->deldir, g);
rootblock->deldir = 0;
rootblock->options |= MODE_SUPERDELDIR;
}
#endif
/* update datestamp and enable */
rootblock->options |= MODE_DATESTAMP;
rootblock->datestamp++;
g->dirty = TRUE;
EXIT("DiskInsertSequence");
}
/* check if rootblocks are of the same disk */
static BOOL SameDisk(struct rootblock *disk1, struct rootblock *disk2)
{
BOOL result;
result = disk1->creationday == disk2->creationday &&
disk1->creationminute == disk2->creationminute &&
disk1->creationtick == disk2->creationtick &&
ddstricmp(disk1->diskname, disk2->diskname);
return(result);
}
/* checks is devicelist belongs to rootblock */
static BOOL SameDiskDL(struct rootblock *disk1, struct DeviceList *disk2)
{
BOOL result;
result = ddstricmp(disk1->diskname, BADDR(disk2->dl_Name)) &&
disk1->creationday == disk2->dl_VolumeDate.ds_Days &&
disk1->creationminute == disk2->dl_VolumeDate.ds_Minute &&
disk1->creationtick == disk2->dl_VolumeDate.ds_Tick;
return(result);
}
/* make and fill in volume structure
* uses g->geom!
* returns 0 is fails
*/
struct volumedata *MakeVolumeData (struct rootblock *rootblock, globaldata *g)
{
struct volumedata *volume;
struct MinList *list;
ENTER("MakeVolumeData");
volume = AllocMemPR (sizeof(struct volumedata), g);
volume->rootblk = rootblock;
volume->rootblockchangeflag = FALSE;
/* lijsten initieren */
for (list = &volume->fileentries; list <= &volume->notifylist; list++)
NewList((struct List *)list);
/* andere gegevens invullen */
volume->numsofterrors = 0;
volume->diskstate = ID_VALIDATED;
/* these could be put in rootblock @@ see also HD version */
volume->numblocks = g->geom->dg_TotalSectors >> g->blocklogshift;
volume->bytesperblock = BLOCKSIZE;
volume->rescluster = rootblock->reserved_blksize / volume->bytesperblock;
/* Calculate minimum fake block size that keeps total block count less than 16M.
* Workaround for programs (including WB) that calculate free space using
* "in use * 100 / total" formula that overflows if in use is block count is larger
* than 16M blocks with 512 block size. Used only in ACTION_INFO.
*/
g->infoblockshift = 0;
if (g->largeDiskSafeOS) {
UWORD blockshift = 0;
ULONG bpb = volume->bytesperblock;
while (bpb > 512) {
blockshift++;
bpb >>= 1;
}
// Calculate smallest safe fake block size, up to max 32k. (512=0,1024=1,..32768=6)
while ((volume->numblocks >> blockshift) >= 0x02000000 && g->infoblockshift < 6) {
g->infoblockshift++;
blockshift++;
}
}
/* load rootblock extension (if it is present) */
if (rootblock->extension && (rootblock->options & MODE_EXTENSION))
{
struct crootblockextension *rext;
rext = AllocBufmemR (sizeof(struct cachedblock) + rootblock->reserved_blksize, g);
memset (rext, 0, sizeof(struct cachedblock) + rootblock->reserved_blksize);
if (RawRead ((UBYTE *)&rext->blk, volume->rescluster, rootblock->extension, g) != 0)
{
ErrorMsg (AFS_ERROR_READ_EXTENSION, NULL, g);
FreeBufmem (rext, g);
rootblock->options ^= MODE_EXTENSION;
}
else
{
if (rext->blk.id == EXTENSIONID)
{
volume->rblkextension = rext;
rext->volume = volume;
rext->blocknr = rootblock->extension;
}
else
{
ErrorMsg (AFS_ERROR_EXTENSION_INVALID, NULL, g);
FreeBufmem (rext, g);
rootblock->options ^= MODE_EXTENSION;
}
}
}
else
{
volume->rblkextension = NULL;
}
EXIT("MakeVolumeData");
return volume;
}
/* fill in my process at the task fields of the locks */
static void TakeOverLocks (struct FileLock *locklist, globaldata *g)
{
while (locklist)
{
locklist->fl_Task = g->msgport;
locklist = (struct FileLock *)BADDR(locklist->fl_Link);
}
}
/* free all resources (memory) taken by volume accept doslist
** it is assumed all this data can be discarded (not checked here!)
** it is also assumed this volume is no part of any volumelist
*/
void FreeVolumeResources(struct volumedata *volume, globaldata *g)
{
ENTER("Free volume resources");
if (volume)
{
FreeUnusedResources (volume, g);
#if VERSION23
if (volume->rblkextension)
FreeBufmem (volume->rblkextension, g);
#endif
#if DELDIR
// if (g->deldirenabled)
// FreeBufmem (volume->deldir, g);
#endif
FreeBufmem (volume->rootblk, g);
FreeMemP (volume, g);
}
EXIT("FreeVolumeResources");
}
void FreeUnusedResources(struct volumedata *volume, globaldata *g)
{
struct MinList *list;
struct MinNode *node, *next;
ENTER("FreeUnusedResources");
/* check if volume passed */
if (!volume)
return;
/* start with anblks!, fileentries are to be kept! */
for (list = volume->anblks; list<=&volume->bmindexblks; list++)
{
node = (struct MinNode *)HeadOf(list);
while ((next = node->mln_Succ))
{
FlushBlock((struct cachedblock *)node, g);
FreeLRU((struct cachedblock *)node);
node = next;
}
}
}
/* CreateInputEvent
**
** generate a `disk inserted/removed' event, in order to get Workbench to
** rescan the DosList and update the list of volume icons.
**
** function supplied by Nicola Salmoria
*/
static VOID CreateInputEvent(BOOL inserted, globaldata *g)
{
struct MsgPort *port;
port = CreateMsgPort();
if (port)
{
struct IOStdReq *io;
#ifdef __SASC
io = CreateStdIO(port);
#else
io = CreateIORequest(port, sizeof(*io));
#endif
if (io)
{
if (!OpenDevice("input.device",0,(struct IORequest *)io,0))
{
struct InputEvent ie;
memset(&ie,0,sizeof(struct InputEvent));
ie.ie_Class = inserted ? IECLASS_DISKINSERTED : IECLASS_DISKREMOVED;
io->io_Command = IND_WRITEEVENT;
io->io_Data = &ie;
io->io_Length = sizeof(struct InputEvent);
DoIO((struct IORequest *)io);
CloseDevice((struct IORequest *)io);
}
#ifdef __SASC
DeleteStdIO(io);
#else
DeleteIORequest(io);
#endif
}
DeleteMsgPort(port);
}
}
/**********************************************************************/
/* OTHER VOLUMEROUTINES */
/* OTHER VOLUMEROUTINES */
/* OTHER VOLUMEROUTINES */
/**********************************************************************/
/* Update the changecount
** returns TRUE if changecount changed
*/
BOOL UpdateChangeCount(globaldata *g)
{
struct IOExtTD *request = g->request;
ULONG changecount;
BOOL result;
if(g->removable)
{
ENTER("UpdateChangeCount");
request->iotd_Req.io_Command = TD_CHANGENUM;
if(DoIO((struct IORequest *)request) == 0)
changecount = request->iotd_Req.io_Actual;
else
changecount = ~0;
result = (changecount != g->changecount);
g->changecount = changecount;
return(result);
}
else
{
return 0; /* no change */
}
}
/* checks if disk is changed. If so calls NewVolume()
** NB: new volume might be NOVOLUME or NOTAFDSDISK
*/
void UpdateCurrentDisk(globaldata *g)
{
NewVolume(0, g);
}
/* CheckVolume checks if a volume (ve lock) is (still) present.
** If volume==NULL (no disk present) then FALSE is returned (@XLII).
** result: requested volume present/not present TRUE/FALSE
*/
BOOL CheckVolume(struct volumedata *volume, BOOL write, SIPTR *error, globaldata *g)
{
if(!volume || !g->currentvolume)
{
switch(g->disktype)
{
case ID_UNREADABLE_DISK:
case ID_NOT_REALLY_DOS:
*error = ERROR_NOT_A_DOS_DISK;
return(DOSFALSE);
case ID_NO_DISK_PRESENT:
if(!volume && !g->currentvolume)
{
*error = ERROR_NO_DISK;
return(DOSFALSE);
}
default:
*error = ERROR_DEVICE_NOT_MOUNTED;
return(DOSFALSE);
}
}
else if(g->currentvolume == volume)
{
switch(g->diskstate)
{
case ID_WRITE_PROTECTED:
if(write)
{
*error = ERROR_DISK_WRITE_PROTECTED;
return(DOSFALSE);
}
case ID_VALIDATING:
if(write)
{
*error = ERROR_DISK_NOT_VALIDATED;
return(DOSFALSE);
}
case ID_VALIDATED:
if(write && g->softprotect)
{
*error = ERROR_DISK_WRITE_PROTECTED;
return(DOSFALSE);
}
default:
return(DOSTRUE);
}
}
else
{
*error = ERROR_DEVICE_NOT_MOUNTED;
return(DOSFALSE);
}
}
/**********************************************************************/
/* REQUESTERS */
/* REQUESTERS */
/* REQUESTERS */
/**********************************************************************/
/*
* ErrorMsg wrapper function
*/
LONG ErrorMsg(CONST_STRPTR msg, APTR arg, globaldata *g)
{
LONG rv;
char charbuffer[256], *b;
b = stpcpy(charbuffer, "Device ");
strncpy(b, &g->mountname[1], g->mountname[0]);
b += g->mountname[0];
b = stpcpy(b, ":\n");
b = stpcpy(b, msg);
rv = (g->ErrorMsg)(charbuffer,arg,1,g);
if (!g->softprotect) {
g->softprotect = 1;
g->protectkey = ~0;
}
if (g->currentvolume)
g->currentvolume->numsofterrors++;
return rv;
}
/* All possible ErrorMsg routines
**
** Displays easyrequest with error message
** Intuition library has to be opened
*/
static const CONST_STRPTR gadgets[] =
{
"OK", "RETRY|CANCEL"
};
LONG _NormalErrorMsg(CONST_STRPTR melding, APTR arg, ULONG notargets, globaldata *g)
{
struct EasyStruct req;
/*
* Make sure we don't hold the performance semaphore while displaying
* a requester. Note that unlock_device_unit is safe to call multiple
* times, and even when not holding a lock. Unlock also is safe to call
* before init has been called.
*/
unlock_device_unit(g);
req.es_StructSize = sizeof(req);
req.es_Flags = 0;
req.es_Title = "PFS-III Error Requester";
req.es_TextFormat = (STRPTR)melding;
req.es_GadgetFormat = (STRPTR)gadgets[notargets-1];
return EasyRequestArgs(NULL, &req, NULL, arg);
}
/* Don't show up a error requester. Used by GetCurrentRoot */
static LONG NoErrorMsg(CONST_STRPTR melding, APTR arg, ULONG dummy, globaldata *g)
{
return 0;
}
/***********************************************************************/
/* LOWLEVEL */
/* LOWLEVEL */
/* LOWLEVEL */
/***********************************************************************/
/* Load the rootblock of the volume that is currently in the drive.
* Returns FLASE if no disk or no PFS disk and TRU if it is a PFS disk.
* Sets disktype in globaldata->disktype
* Should NOT change globaldata->currentvolume
*
* Allocates space in 'rootblock' which is freed if an error occurs.
*/
#ifdef TRACKDISK
static void UpdateDosEnvec(globaldata *g);
#endif
// if we have original geometry: simply copy it over
static void GetExtBlockGeometry(struct rootblock *rootblock, ULONG rblsize, globaldata *g)
{
struct rootblockextension *rext;
ULONG *env = (ULONG *)g->dosenvec;
if (g->trackdisk || env[DE_LOWCYL] != 0 || !(rootblock->options & MODE_EXTENSION) || !(rootblock->options & MODE_STORED_GEOM))
return;
rext = AllocBufmemR(rblsize << BLOCKSHIFT, g);
if (RawRead((UBYTE *)rext, rblsize, rootblock->extension, g) != 0) {
int minlen = env[0] > rext->dosenvec[0] ? rext->dosenvec[0] : env[0];
if (minlen > 10)
minlen = 10; // de_SizeBlock to de_HighCyl
memcpy(&env[1], &rext->dosenvec[1], minlen * sizeof(ULONG));
GetDriveGeometry(g);
}
FreeBufmem(rext, g);
}
static WORD IsRBBlock(UBYTE *rbpt)
{
struct rootblock *rootblock = (struct rootblock*)rbpt;
if (rootblock->disktype != ID_PFS_DISK && rootblock->disktype != ID_PFS2_DISK)
return 0;
if (rootblock->options == 0 || rootblock->reserved_blksize == 0)
return -1; // boot block
return 1; // root block
}
static BOOL GetCurrentRoot(struct rootblock **rootblock, globaldata *g)
{