-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdd_support.c
541 lines (461 loc) · 14.4 KB
/
dd_support.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
/* $Id: dd_support.c 1.9 1999/02/22 16:33:43 Michiel Exp Michiel $ */
/* $Log: dd_support.c $
* Revision 1.9 1999/02/22 16:33:43 Michiel
* Changes for increasing deldir capacity
*
* Revision 1.8 1998/09/27 11:26:37 Michiel
* ErrorMsg param
*
* Revision 1.7 1997/03/03 22:04:04 Michiel
* Release 16.21
*
* Revision 1.6 1996/03/29 17:02:54 Michiel
* update sleeproutines
*
* Revision 1.5 1996/01/30 12:49:23 Michiel
* --- working tree overlap ---
* new notify routines
* */
#include "kswrapper.h"
/**********************
* function prototypes
*/
static BOOL RenameDisk(UBYTE *, globaldata *);
static void NotifyUser(struct NotifyRequest *nr, globaldata *g);
static struct notifyobject *CheckNotify(ULONG parentanodenr, DSTR objectname,
struct notifyobject *no, BOOL checkparent, globaldata *);
void PFSDoNotify(struct fileinfo *object, BOOL checkparent, globaldata *g);
void PFSUpdateNotify(ULONG dirnode, DSTR filename, ULONG anodenr, globaldata *g);
/* AFS extensions */
#if EXTRAPACKETS
static void Sleep (globaldata *g);
static void Awake (globaldata *g);
static void Alarm (globaldata *g);
static LONG UpdateAnode (ULONG old, ULONG new, globaldata *g);
void HandleSleepMsg (globaldata *g);
#endif
/**********************
* macros
*/
#define SkipColon(filename,pathname) \
do { \
if ((filename = strchr ((pathname), ':'))) \
filename++; \
else \
filename=(pathname); \
} while (0)
#define LocateFile(parentfi,filename,objectfi,error) \
do { \
if (!FindObject (parentfi, filename, &(objectfi), error, g)) \
return DOSFALSE; \
\
if (IsVolume(objectfi)) \
{ \
*error = ERROR_OBJECT_WRONG_TYPE; \
return DOSFALSE; \
} \
} while (0)
#if MULTIUSER
#define muGetRelationship(extrafields) \
((g->muFS_ready) ? \
(muGetRelationshipA (g->user, ((extrafields).uid << 16) + (extrafields).gid, NULL)) : \
((((extrafields).uid == muNOBODY_UID) << muRelB_NO_OWNER) | muRelF_NOBODY))
#if DELDIR
#define CheckPropertyAccess(objectfi,extrafields,flags, error) \
do { \
GetExtraFieldsOI (&(objectfi), &(extrafields), g); \
if (g->muFS_ready) \
flags = muGetRelationshipA (g->user, ((extrafields).uid << 16) + (extrafields).gid, NULL); \
else \
flags = (((extrafields).uid == muNOBODY_UID) << muRelB_NO_OWNER) | muRelF_NOBODY; \
\
if (!(flags & muRel_PROPERTY_ACCESS)) \
{ \
*error = ERROR_WRITE_PROTECTED; \
return DOSFALSE; \
} \
} while (0)
#else /* DELDIR */
#define CheckPropertyAccess(objectfi,extrafields,flags, error) \
do { \
GetExtraFields ((objectfi).file.direntry, &(extrafields)); \
if (g->muFS_ready) \
flags = muGetRelationshipA (g->user, ((extrafields).uid << 16) + (extrafields).gid, NULL); \
else \
flags = (((extrafields).uid == muNOBODY_UID) << muRelB_NO_OWNER) | muRelF_NOBODY; \
\
if (!(flags & muRel_PROPERTY_ACCESS)) \
{ \
*error = ERROR_WRITE_PROTECTED; \
return DOSFALSE; \
} \
} while (0)
#endif /* DELDIR */
#else /* MULTIUSER */
#define muGetRelationship(extrafields)
#define CheckPropertyAccess(objectfi,extrafields,flags,error)
#endif /* MULTIUSER */
/*
* BPTR, BOOL, listentry_t *, union objectinfo *
*/
#define GetFileInfoFromLock(argument, access, fe, fi) \
do { \
if ((fe = LockEntryFromLock (argument))) \
{ \
if (!CheckVolume ((fe)->le.volume, access, error, g)) \
return DOSFALSE; \
UpdateLE ((listentry_t *)(fe), g); \
fi = &(fe)->le.info; \
} \
else \
{ \
if (!g->currentvolume) \
{ \
*error = ERROR_NO_DISK; \
return DOSFALSE; \
} \
fi = NULL; \
} \
} while (0)
/**********************
* rename disk
*/
static BOOL RenameDisk (UBYTE *newname, globaldata *g) //%4.5
{
UBYTE *diskname;
struct volumedata *volume = g->currentvolume;
ENTER("RenameDisk");
if (g->currentvolume && (strlen(newname) < DNSIZE))
{
/* Write changes directly to disk to prevent disk recognition problems.
* (So DON'T use updatedisk)
*/
diskname = volume->rootblk->diskname;
*diskname = strlen(newname);
CopyMem (newname, diskname+1, strlen(newname));
RawWrite ((UBYTE *)volume->rootblk, 1, ROOTBLOCK, g); /* %7.2 */
UpdateAndMotorOff(g);
volume->rootblockchangeflag = FALSE;
return DOSTRUE;
}
else
{
return DOSFALSE;
}
}
/**********************
* notify stuff
*/
static void NotifyUser (struct NotifyRequest *nr, globaldata *g)
{
struct NotifyMessage *msg;
if (nr->nr_MsgCount && (nr->nr_Flags & NRF_WAIT_REPLY))
{
nr->nr_Flags |= NRF_MAGIC;
return;
}
if (nr->nr_Flags & NRF_SEND_MESSAGE)
{
if (!(msg = AllocMemP (sizeof(struct NotifyMessage), g)))
return;
msg->nm_ExecMessage.mn_ReplyPort = g->notifyport;
msg->nm_ExecMessage.mn_Length = sizeof(struct NotifyMessage);
msg->nm_Class = NOTIFY_CLASS;
msg->nm_Code = NOTIFY_CODE;
msg->nm_NReq = nr;
PutMsg (nr->nr_stuff.nr_Msg.nr_Port, &msg->nm_ExecMessage);
nr->nr_MsgCount++;
}
else if (nr->nr_Flags & NRF_SEND_SIGNAL)
{
Signal (nr->nr_stuff.nr_Signal.nr_Task, 1<<nr->nr_stuff.nr_Signal.nr_SignalNum);
}
}
/*
* Checks if there is a notify for the object identified by anodenr
*/
static struct notifyobject *
CheckNotify (ULONG parentanodenr, DSTR objectname, struct notifyobject *no,
BOOL checkparent, globaldata *g)
{
if (!no)
no = HeadOf(&g->currentvolume->notifylist);
else
no = no->next;
for ( ; no->next; no=no->next)
{
/* file match */
if (no->parentanodenr == parentanodenr)
{
if (intlcmp(no->objectname, objectname))
return no;
}
/* parent match */
if (checkparent && no->anodenr == parentanodenr)
return no;
}
return NULL;
}
/*
* Notifies change of object & dir object is in
*/
void PFSDoNotify (struct fileinfo *object, BOOL checkparent, globaldata *g)
{
struct notifyobject *no = NULL;
#if DELDIR
if ((IPTR)object->direntry <= SPECIAL_DELFILE)
return;
#endif
while ((no = CheckNotify (object->dirblock->blk.anodenr,
(DSTR)&object->direntry->nlength, no, checkparent, g)))
NotifyUser(no->req, g);
}
/*
* To be called when a object named filename is created in dir
* dirnode. This routine checks if there is a partially parsed
* notify request in that directory that matches the newly
* created object. If so, the parsing of the notify request
* can continue.
*/
void PFSUpdateNotify (ULONG dirnode, DSTR filename, ULONG anodenr, globaldata *g)
{
struct notifyobject *no = NULL;
UBYTE *temp;
for (no = HeadOf(&g->currentvolume->notifylist); no->next; no=no->next)
{
/* check for parsed path match */
if (no->parentanodenr == dirnode)
{
if (no->unparsed)
{
/* check if we can continue parsing */
temp = strchr(no->unparsed, '/');
if (temp)
*temp = 0;
if (intlcdcmp(no->unparsed, filename))
{
if (temp)
no->unparsed = *(temp+1) ? (temp+1) : NULL;
else
no->unparsed = NULL;
no->parentanodenr = anodenr;
}
if (temp)
*temp = '/';
}
else
{
/* check if new object is a notify object */
if (intlcmp(no->objectname, filename))
{
no->anodenr = anodenr;
}
}
}
}
}
/**********************
* AFS extension
*/
#if EXTRAPACKETS
/*
* Enter MODE_SLEEP
*
* All direct directory block references are replaced by an
* anode reference. The reference can later be restored by
* searching the object in the directory identified by the
* diranodenr.
*
* Examine chains have to be broken since sleepwalkers are
* allowed to change directory order
*/
static void Sleep (globaldata *g)
{
listentry_t *le;
struct volumedata *volume = g->currentvolume;
if (volume)
{
/* first update disk */
UpdateDisk (g);
/* flush references */
for (le=HeadOf (&volume->fileentries); le->next; le=le->next)
{
if (!IsVolumeEntry(le))
{
/* load flushed references */
if (le->dirblocknr)
LoadDirBlock (le->dirblocknr, g);
le->diranodenr = le->info.file.dirblock->blk.anodenr;
}
if (IsFileEntry(le))
{
fileentry_t *fe = (fileentry_t *)le;
if (fe->anodechain)
DetachAnodeChain (fe->anodechain, g);
fe->currnode = NULL;
}
}
/* now kill all flushed references (they are now replaced
* by anode references in le->diranodenr)
*/
for (le=HeadOf (&volume->fileentries); le->next; le=le->next)
{
le->dirblocknr = 0;
/* terminate examine chains */
if (le->type.flags.dir && !IsDelDir(le->info))
{
((lockentry_t *)le)->nextentry.direntry = NULL;
((lockentry_t *)le)->nextentry.dirblock = NULL;
((lockentry_t *)le)->nextdirblocknr = 0;
((lockentry_t *)le)->nextdirblockoffset = 0;
}
}
/* flush cache. Watch it: FreeUnusedResources also calls
* the conventional FlushBlock!
*/
FreeUnusedResources (volume, g);
}
/* set sleepmode */
g->sleepmode = TRUE;
/* enter sleepmode */
g->DoCommand = SleepCommands;
}
/*
* Leave MODE_SLEEP
*
* Reload all essential blocks. References are restored by searching
* by anodenr in the directory identified by diranodenr (using FetchObject)
*/
static void Awake (globaldata *g)
{
listentry_t *le;
struct volumedata *volume = g->currentvolume;
struct rootblock *rootblock;
SIPTR error;
if (volume)
{
/* reload current rootblock */
rootblock = volume->rootblk;
RawRead((UBYTE *)rootblock, rootblock->rblkcluster, ROOTBLOCK, g);
/* reload rootblock extension */
if (rootblock->extension && (rootblock->options & MODE_EXTENSION))
RawRead((UBYTE *)&volume->rblkextension->blk, volume->rescluster,
rootblock->extension, g);
/* reload deldir */
// if (rootblock->deldir && (rootblock->options & MODE_DELDIR))
// RawRead((UBYTE *)&volume->deldir->blk, volume->rescluster,
// rootblock->deldir, g);
/* reconfigure modules */
InitModules (volume, FALSE, g);
/* restore references */
for (le=HeadOf (&volume->fileentries); le->next; le=le->next)
{
if (!IsVolumeEntry(le))
{
if (!FetchObject(le->diranodenr, le->anodenr, &le->info, g))
ErrorMsg(AFS_ERROR_UNSLEEP, NULL, g); /* -> kill, invalidate lock <- */
if (IsFileEntry(le))
{
ULONG offset;
fileentry_t *fe = (fileentry_t *)le;
/* restore anodechain and fe->currnode */
if (!(fe->anodechain = GetAnodeChain(fe->le.anodenr, g)))
; /* kill, invalidate */
offset = fe->offset;
fe->currnode = &fe->anodechain->head;
fe->offset = fe->blockoffset = fe->anodeoffset = 0;
if (SeekInObject(fe, offset, OFFSET_BEGINNING, &error, g) == -1)
ErrorMsg(AFS_ERROR_UNSLEEP, NULL, g); /* -> kill, invalidate */
}
}
}
}
// --> prevent 'normal' reference-restore on loading
// directory blocks
/* unset sleepmode */
g->sleepmode = FALSE;
/* awake */
g->DoCommand = NormalCommands;
}
/*
* Disk accessing packets are pending --> wake up!
* Handshaking sleeptask <-> AFS
*/
static void Alarm (globaldata *g)
{
ULONG sleepmask = 1<<g->alarmsignal;
/* signal task that we want to wake up */
Signal (g->sleeptask, sleepmask);
while (g->sleepmode)
{
WaitPort (g->sleepport);
HandleSleepMsg (g);
}
}
/*
* Reflect changed anode in locklist references
* returns number of references updated
* (MODE_SLEEP only)
*/
static LONG UpdateAnode (ULONG old, ULONG new, globaldata *g)
{
listentry_t *le;
struct notifyobject *no;
LONG i=0;
struct volumedata *volume = g->currentvolume;
/*
* Update fileentry list
*/
for (le=(listentry_t *)HeadOf(&volume->fileentries); le->next; le=le->next)
{
if (!IsVolumeEntry(le))
{
if (le->anodenr == old)
{
i++;
if (!new)
; /* invalidate le */
le->anodenr = new;
}
if (le->diranodenr == old)
{
i++;
le->diranodenr = new;
}
}
}
/*
* Update notify list
*/
for (no=HeadOf(&g->currentvolume->notifylist); no->next; no=no->next)
{
if (no->anodenr == old)
{
i++;
no->anodenr = new;
}
}
return i;
}
/*
* Message handler for messages on the sleepport
*/
void HandleSleepMsg (globaldata *g)
{
struct Message *msg;
while ((msg = GetMsg (g->sleepport)))
{
if (g->sleepmode)
{
g->action = (struct DosPacket *)msg->mn_Node.ln_Name;
(g->DoCommand)(g->action, g);
}
else
{
g->action->dp_Res1 = DOSFALSE;
g->action->dp_Res2 = ERROR_ACTION_NOT_KNOWN;
}
ReturnPacket (g->action, g->sleepport, g);
}
}
#endif