|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * Unix file system handler for AmigaDOS
5: *
1.1.1.3 root 6: * Copyright 1996 Ed Hanway
7: * Copyright 1996, 1997 Bernd Schmidt
1.1 root 8: *
1.1.1.3 root 9: * Version 0.4: 970308
1.1 root 10: *
11: * Based on example code (c) 1988 The Software Distillery
12: * and published in Transactor for the Amiga, Volume 2, Issues 2-5.
13: * (May - August 1989)
14: *
15: * Known limitations:
16: * Does not support ACTION_INHIBIT (big deal).
1.1.1.6 root 17: * Does not support several 2.0+ packet types.
1.1 root 18: * Does not support removable volumes.
19: * May not return the correct error code in some cases.
20: * Does not check for sane values passed by AmigaDOS. May crash the emulation
21: * if passed garbage values.
1.1.1.3 root 22: * Could do tighter checks on malloc return values.
23: * Will probably fail spectacularly in some cases if the filesystem is
24: * modified at the same time by another process while UAE is running.
1.1 root 25: */
26:
27: #include "sysconfig.h"
28: #include "sysdeps.h"
29:
30: #include "config.h"
1.1.1.13 root 31: #include "threaddep/thread.h"
1.1 root 32: #include "options.h"
1.1.1.3 root 33: #include "uae.h"
1.1 root 34: #include "memory.h"
35: #include "custom.h"
1.1.1.13 root 36: #include "events.h"
1.1 root 37: #include "newcpu.h"
1.1.1.3 root 38: #include "filesys.h"
1.1 root 39: #include "autoconf.h"
1.1.1.4 root 40: #include "fsusage.h"
1.1.1.7 root 41: #include "native2amiga.h"
42: #include "scsidev.h"
43: #include "fsdb.h"
1.1 root 44:
1.1.1.17 root 45: #define TRACING_ENABLED 0
46: #if TRACING_ENABLED
1.1.1.4 root 47: #define TRACE(x) do { write_log x; } while(0)
1.1.1.3 root 48: #define DUMPLOCK(u,x) dumplock(u,x)
49: #else
50: #define TRACE(x)
51: #define DUMPLOCK(u,x)
52: #endif
53:
54: static long dos_errno(void)
1.1 root 55: {
1.1.1.3 root 56: int e = errno;
1.1 root 57:
1.1.1.4 root 58: switch (e) {
1.1.1.3 root 59: case ENOMEM: return ERROR_NO_FREE_STORE;
60: case EEXIST: return ERROR_OBJECT_EXISTS;
61: case EACCES: return ERROR_WRITE_PROTECTED;
1.1.1.11 root 62: case ENOENT: return ERROR_OBJECT_NOT_AROUND;
1.1.1.3 root 63: case ENOTDIR: return ERROR_OBJECT_WRONG_TYPE;
1.1.1.6 root 64: case ENOSPC: return ERROR_DISK_IS_FULL;
1.1.1.3 root 65: case EBUSY: return ERROR_OBJECT_IN_USE;
66: case EISDIR: return ERROR_OBJECT_WRONG_TYPE;
67: #if defined(ETXTBSY)
68: case ETXTBSY: return ERROR_OBJECT_IN_USE;
69: #endif
70: #if defined(EROFS)
71: case EROFS: return ERROR_DISK_WRITE_PROTECTED;
72: #endif
73: #if defined(ENOTEMPTY)
74: #if ENOTEMPTY != EEXIST
75: case ENOTEMPTY: return ERROR_DIRECTORY_NOT_EMPTY;
76: #endif
77: #endif
78:
79: default:
1.1.1.4 root 80: TRACE(("Unimplemented error %s\n", strerror(e)));
1.1.1.3 root 81: return ERROR_NOT_IMPLEMENTED;
82: }
1.1 root 83: }
84:
1.1.1.3 root 85: /*
86: * This _should_ be no issue for us, but let's rather use a guaranteed
87: * thread safe function if we have one.
1.1.1.4 root 88: * This used to be broken in glibc versions <= 2.0.1 (I think). I hope
89: * no one is using this these days.
90: * Michael Krause says it's also broken in libc5. ARRRGHHHHHH!!!!
1.1.1.3 root 91: */
92: #if 0 && defined HAVE_READDIR_R
93:
94: static struct dirent *my_readdir (DIR *dirstream, struct dirent *space)
95: {
96: struct dirent *loc;
97: if (readdir_r (dirstream, space, &loc) == 0) {
98: /* Success */
99: return loc;
100: }
101: return 0;
102: }
103:
104: #else
105: #define my_readdir(dirstream, space) readdir(dirstream)
106: #endif
107:
1.1.1.4 root 108: uaecptr filesys_initcode;
109: static uae_u32 fsdevname, filesys_configdev;
110:
1.1.1.3 root 111: #define FS_STARTUP 0
112: #define FS_GO_DOWN 1
113:
1.1 root 114: typedef struct {
115: char *devname; /* device name, e.g. UAE0: */
1.1.1.3 root 116: uaecptr devname_amiga;
117: uaecptr startup;
1.1 root 118: char *volname; /* volume name, e.g. CDROM, WORK, etc. */
119: char *rootdir; /* root unix directory */
120: int readonly; /* disallow write access? */
121: int devno;
1.1.1.3 root 122:
123: struct hardfiledata hf;
124:
125: /* Threading stuff */
126: smp_comm_pipe *unit_pipe, *back_pipe;
1.1.1.13 root 127: uae_thread_id tid;
1.1.1.3 root 128: struct _unit *volatile self;
1.1.1.4 root 129: /* Reset handling */
130: uae_sem_t reset_sync_sem;
131: int reset_state;
1.1 root 132: } UnitInfo;
133:
134: #define MAX_UNITS 20
135:
1.1.1.4 root 136: struct uaedev_mount_info {
137: int num_units;
138: UnitInfo ui[MAX_UNITS];
139: };
140:
141: static struct uaedev_mount_info *current_mountinfo;
142:
143: int nr_units (struct uaedev_mount_info *mountinfo)
144: {
145: return mountinfo->num_units;
146: }
147:
148: int is_hardfile (struct uaedev_mount_info *mountinfo, int unit_no)
149: {
150: return mountinfo->ui[unit_no].volname == 0;
151: }
152:
1.1.1.6 root 153: static void close_filesys_unit (UnitInfo *uip)
1.1.1.4 root 154: {
155: if (uip->hf.fd != 0)
156: fclose (uip->hf.fd);
157: if (uip->volname != 0)
158: free (uip->volname);
159: if (uip->devname != 0)
160: free (uip->devname);
161: if (uip->rootdir != 0)
162: free (uip->rootdir);
163: if (uip->unit_pipe)
164: free (uip->unit_pipe);
165: if (uip->back_pipe)
166: free (uip->back_pipe);
167:
168: uip->unit_pipe = 0;
169: uip->back_pipe = 0;
170:
171: uip->hf.fd = 0;
172: uip->volname = 0;
173: uip->devname = 0;
174: uip->rootdir = 0;
175: }
176:
177: char *get_filesys_unit (struct uaedev_mount_info *mountinfo, int nr,
178: char **volname, char **rootdir, int *readonly,
179: int *secspertrack, int *surfaces, int *reserved,
1.1.1.6 root 180: int *cylinders, int *size, int *blocksize)
1.1.1.4 root 181: {
182: UnitInfo *uip = mountinfo->ui + nr;
183:
184: if (nr >= mountinfo->num_units)
185: return "No slot allocated for this unit";
186:
187: *volname = uip->volname ? my_strdup (uip->volname) : 0;
188: *rootdir = uip->rootdir ? my_strdup (uip->rootdir) : 0;
189: *readonly = uip->readonly;
190: *secspertrack = uip->hf.secspertrack;
191: *surfaces = uip->hf.surfaces;
192: *reserved = uip->hf.reservedblocks;
193: *size = uip->hf.size;
194: *cylinders = uip->hf.nrcyls;
1.1.1.6 root 195: *blocksize = uip->hf.blocksize;
1.1.1.4 root 196: return 0;
197: }
198:
1.1.1.6 root 199: static char *set_filesys_unit_1 (struct uaedev_mount_info *mountinfo, int nr,
200: char *volname, char *rootdir, int readonly,
201: int secspertrack, int surfaces, int reserved,
202: int blocksize)
1.1 root 203: {
1.1.1.6 root 204: UnitInfo *ui = mountinfo->ui + nr;
1.1.1.4 root 205:
206: if (nr >= mountinfo->num_units)
207: return "No slot allocated for this unit";
1.1 root 208:
1.1.1.6 root 209: ui->hf.fd = 0;
210: ui->devname = 0;
211: ui->volname = 0;
212: ui->rootdir = 0;
213: ui->unit_pipe = 0;
214: ui->back_pipe = 0;
1.1.1.5 root 215:
1.1.1.3 root 216: if (volname != 0) {
1.1.1.6 root 217: ui->volname = my_strdup (volname);
218: ui->hf.fd = 0;
1.1.1.3 root 219: } else {
1.1.1.6 root 220: ui->volname = 0;
221: ui->hf.fd = fopen (rootdir, "r+b");
222: if (ui->hf.fd == 0) {
1.1.1.3 root 223: readonly = 1;
1.1.1.6 root 224: ui->hf.fd = fopen (rootdir, "rb");
1.1.1.3 root 225: }
1.1.1.6 root 226: if (ui->hf.fd == 0)
1.1.1.3 root 227: return "Hardfile not found";
1.1.1.4 root 228:
1.1.1.3 root 229: if (secspertrack < 1 || secspertrack > 32767
230: || surfaces < 1 || surfaces > 1023
1.1.1.6 root 231: || reserved < 0 || reserved > 1023
232: || (blocksize & (blocksize - 1)) != 0)
1.1.1.4 root 233: {
1.1.1.3 root 234: return "Bad hardfile geometry";
235: }
1.1.1.6 root 236: fseek (ui->hf.fd, 0, SEEK_END);
237: ui->hf.size = ftell (ui->hf.fd);
238: ui->hf.secspertrack = secspertrack;
239: ui->hf.surfaces = surfaces;
240: ui->hf.reservedblocks = reserved;
241: ui->hf.nrcyls = (ui->hf.size / blocksize) / (secspertrack * surfaces);
242: ui->hf.blocksize = blocksize;
243: }
244: ui->self = 0;
245: ui->reset_state = FS_STARTUP;
246: ui->rootdir = my_strdup (rootdir);
247: ui->readonly = readonly;
1.1 root 248:
1.1.1.3 root 249: return 0;
1.1 root 250: }
1.1.1.6 root 251:
252: char *set_filesys_unit (struct uaedev_mount_info *mountinfo, int nr,
253: char *volname, char *rootdir, int readonly,
254: int secspertrack, int surfaces, int reserved,
255: int blocksize)
256: {
257: UnitInfo ui = mountinfo->ui[nr];
258: char *result = set_filesys_unit_1 (mountinfo, nr, volname, rootdir, readonly,
259: secspertrack, surfaces, reserved, blocksize);
260: if (result)
261: mountinfo->ui[nr] = ui;
262: else
263: close_filesys_unit (&ui);
264:
265: return result;
266: }
267:
1.1.1.4 root 268: char *add_filesys_unit (struct uaedev_mount_info *mountinfo,
269: char *volname, char *rootdir, int readonly,
1.1.1.6 root 270: int secspertrack, int surfaces, int reserved,
271: int blocksize)
1.1.1.4 root 272: {
273: char *retval;
274: int nr = mountinfo->num_units;
275: UnitInfo *uip = mountinfo->ui + nr;
1.1 root 276:
1.1.1.4 root 277: if (nr >= MAX_UNITS)
278: return "Maximum number of file systems mounted";
279:
280: mountinfo->num_units++;
1.1.1.6 root 281: retval = set_filesys_unit_1 (mountinfo, nr, volname, rootdir, readonly,
282: secspertrack, surfaces, reserved, blocksize);
1.1.1.4 root 283: if (retval)
284: mountinfo->num_units--;
285: return retval;
286: }
287:
288: int kill_filesys_unit (struct uaedev_mount_info *mountinfo, int nr)
1.1.1.2 root 289: {
1.1.1.4 root 290: UnitInfo *uip = mountinfo->ui;
291: if (nr >= mountinfo->num_units || nr < 0)
1.1.1.2 root 292: return -1;
293:
1.1.1.6 root 294: close_filesys_unit (mountinfo->ui + nr);
1.1.1.4 root 295:
296: mountinfo->num_units--;
297: for (; nr < mountinfo->num_units; nr++) {
298: uip[nr] = uip[nr+1];
1.1.1.2 root 299: }
300: return 0;
301: }
302:
1.1.1.4 root 303: int move_filesys_unit (struct uaedev_mount_info *mountinfo, int nr, int to)
1.1.1.3 root 304: {
1.1.1.4 root 305: UnitInfo tmpui;
306: UnitInfo *uip = mountinfo->ui;
307:
308: if (nr >= mountinfo->num_units || nr < 0
309: || to >= mountinfo->num_units || to < 0
310: || to == nr)
311: return -1;
312: tmpui = uip[nr];
313: if (to > nr) {
314: int i;
315: for (i = nr; i < to; i++)
316: uip[i] = uip[i + 1];
317: } else {
318: int i;
319: for (i = nr; i > to; i--)
320: uip[i] = uip[i - 1];
321: }
322: uip[to] = tmpui;
323: return 0;
1.1.1.3 root 324: }
325:
1.1.1.4 root 326: int sprintf_filesys_unit (struct uaedev_mount_info *mountinfo, char *buffer, int num)
1.1.1.2 root 327: {
1.1.1.4 root 328: UnitInfo *uip = mountinfo->ui;
329: if (num >= mountinfo->num_units)
1.1.1.2 root 330: return -1;
1.1.1.4 root 331:
332: if (uip[num].volname != 0)
1.1.1.6 root 333: sprintf (buffer, "(DH%d:) Filesystem, %s: %s %s", num, uip[num].volname,
1.1.1.4 root 334: uip[num].rootdir, uip[num].readonly ? "ro" : "");
1.1.1.2 root 335: else
1.1.1.6 root 336: sprintf (buffer, "(DH%d:) Hardfile, \"%s\", size %d bytes", num,
1.1.1.4 root 337: uip[num].rootdir, uip[num].hf.size);
1.1.1.2 root 338: return 0;
339: }
340:
1.1.1.6 root 341: void write_filesys_config (struct uaedev_mount_info *mountinfo,
342: const char *unexpanded, const char *default_path, FILE *f)
1.1 root 343: {
1.1.1.4 root 344: UnitInfo *uip = mountinfo->ui;
1.1 root 345: int i;
1.1.1.4 root 346:
347: for (i = 0; i < mountinfo->num_units; i++) {
1.1.1.6 root 348: char *str;
349: str = cfgfile_subst_path (default_path, unexpanded, uip[i].rootdir);
1.1.1.4 root 350: if (uip[i].volname != 0) {
1.1.1.7 root 351: fprintf (f, "filesystem=%s,%s:%s\n", uip[i].readonly ? "ro" : "rw",
1.1.1.6 root 352: uip[i].volname, str);
1.1.1.3 root 353: } else {
1.1.1.12 root 354: fprintf (f, "hardfile=%s,%d,%d,%d,%d,%s\n",
355: uip[i].readonly ? "ro" : "rw", uip[i].hf.secspertrack,
1.1.1.17 root 356: uip[i].hf.surfaces, uip[i].hf.reservedblocks,
357: uip[i].hf.blocksize, str);
1.1 root 358: }
1.1.1.6 root 359: free (str);
1.1 root 360: }
361: }
362:
1.1.1.4 root 363: struct uaedev_mount_info *alloc_mountinfo (void)
364: {
365: struct uaedev_mount_info *info;
366: info = (struct uaedev_mount_info *)malloc (sizeof *info);
1.1.1.6 root 367: /* memset (info, 0xaa, sizeof *info);*/
1.1.1.4 root 368: info->num_units = 0;
369: return info;
370: }
371:
372: struct uaedev_mount_info *dup_mountinfo (struct uaedev_mount_info *mip)
373: {
374: int i;
375: struct uaedev_mount_info *i2 = alloc_mountinfo ();
376:
377: memcpy (i2, mip, sizeof *i2);
378:
379: for (i = 0; i < i2->num_units; i++) {
380: UnitInfo *uip = i2->ui + i;
381: if (uip->volname)
382: uip->volname = my_strdup (uip->volname);
383: if (uip->rootdir)
384: uip->rootdir = my_strdup (uip->rootdir);
385: if (uip->hf.fd)
1.1.1.7 root 386: uip->hf.fd = fdopen ( dup (fileno (uip->hf.fd)), uip->readonly ? "rb" : "r+b");
1.1.1.4 root 387: }
388: return i2;
389: }
390:
391: void free_mountinfo (struct uaedev_mount_info *mip)
392: {
393: int i;
394: for (i = 0; i < mip->num_units; i++)
1.1.1.6 root 395: close_filesys_unit (mip->ui + i);
1.1.1.4 root 396: free (mip);
397: }
398:
399: struct hardfiledata *get_hardfile_data (int nr)
400: {
401: UnitInfo *uip = current_mountinfo->ui;
402: if (nr < 0 || nr >= current_mountinfo->num_units || uip[nr].volname != 0)
403: return 0;
404: return &uip[nr].hf;
405: }
406:
1.1 root 407: /* minimal AmigaDOS definitions */
408:
409: /* field offsets in DosPacket */
1.1.1.3 root 410: #define dp_Type 8
411: #define dp_Res1 12
412: #define dp_Res2 16
413: #define dp_Arg1 20
414: #define dp_Arg2 24
415: #define dp_Arg3 28
416: #define dp_Arg4 32
1.1 root 417:
418: /* result codes */
1.1.1.3 root 419: #define DOS_TRUE ((unsigned long)-1L)
1.1 root 420: #define DOS_FALSE (0L)
421:
1.1.1.13 root 422: /* Passed as type to Lock() */
423: #define SHARED_LOCK -2 /* File is readable by others */
424: #define ACCESS_READ -2 /* Synonym */
425: #define EXCLUSIVE_LOCK -1 /* No other access allowed */
426: #define ACCESS_WRITE -1 /* Synonym */
427:
1.1 root 428: /* packet types */
429: #define ACTION_CURRENT_VOLUME 7
430: #define ACTION_LOCATE_OBJECT 8
431: #define ACTION_RENAME_DISK 9
432: #define ACTION_FREE_LOCK 15
433: #define ACTION_DELETE_OBJECT 16
434: #define ACTION_RENAME_OBJECT 17
435: #define ACTION_COPY_DIR 19
436: #define ACTION_SET_PROTECT 21
437: #define ACTION_CREATE_DIR 22
438: #define ACTION_EXAMINE_OBJECT 23
439: #define ACTION_EXAMINE_NEXT 24
440: #define ACTION_DISK_INFO 25
441: #define ACTION_INFO 26
442: #define ACTION_FLUSH 27
443: #define ACTION_SET_COMMENT 28
444: #define ACTION_PARENT 29
445: #define ACTION_SET_DATE 34
446: #define ACTION_FIND_WRITE 1004
447: #define ACTION_FIND_INPUT 1005
448: #define ACTION_FIND_OUTPUT 1006
449: #define ACTION_END 1007
450: #define ACTION_SEEK 1008
451: #define ACTION_IS_FILESYSTEM 1027
452: #define ACTION_READ 'R'
453: #define ACTION_WRITE 'W'
454:
1.1.1.3 root 455: /* 2.0+ packet types */
456: #define ACTION_INHIBIT 31
457: #define ACTION_SET_FILE_SIZE 1022
458: #define ACTION_LOCK_RECORD 2008
459: #define ACTION_FREE_RECORD 2009
460: #define ACTION_SAME_LOCK 40
461: #define ACTION_CHANGE_MODE 1028
462: #define ACTION_FH_FROM_LOCK 1026
463: #define ACTION_COPY_DIR_FH 1030
464: #define ACTION_PARENT_FH 1031
465: #define ACTION_EXAMINE_FH 1034
466: #define ACTION_EXAMINE_ALL 1033
467: #define ACTION_MAKE_LINK 1021
468: #define ACTION_READ_LINK 1024
469: #define ACTION_FORMAT 1020
470: #define ACTION_IS_FILESYSTEM 1027
471: #define ACTION_ADD_NOTIFY 4097
472: #define ACTION_REMOVE_NOTIFY 4098
1.1 root 473:
1.1.1.3 root 474: #define DISK_TYPE 0x444f5301 /* DOS\1 */
1.1 root 475:
1.1.1.3 root 476: typedef struct {
477: uae_u32 uniq;
1.1.1.14 root 478: /* The directory we're going through. */
1.1.1.7 root 479: a_inode *aino;
1.1.1.14 root 480: /* The file we're going to look up next. */
481: a_inode *curr_file;
1.1.1.3 root 482: } ExamineKey;
1.1 root 483:
1.1.1.3 root 484: typedef struct key {
485: struct key *next;
1.1.1.7 root 486: a_inode *aino;
1.1.1.3 root 487: uae_u32 uniq;
488: int fd;
489: off_t file_pos;
490: } Key;
1.1 root 491:
1.1.1.3 root 492: /* Since ACTION_EXAMINE_NEXT is so braindamaged, we have to keep
493: * some of these around
494: */
495:
496: #define EXKEYS 100
497: #define MAX_AINO_HASH 128
1.1 root 498:
499: /* handler state info */
500:
501: typedef struct _unit {
502: struct _unit *next;
503:
504: /* Amiga stuff */
1.1.1.4 root 505: uaecptr dosbase;
506: uaecptr volume;
507: uaecptr port; /* Our port */
508: uaecptr locklist;
1.1 root 509:
510: /* Native stuff */
1.1.1.4 root 511: uae_s32 unit; /* unit number */
512: UnitInfo ui; /* unit startup info */
513: char tmpbuf3[256];
1.1.1.3 root 514:
515: /* Dummy message processing */
1.1.1.4 root 516: uaecptr dummy_message;
1.1.1.3 root 517: volatile unsigned int cmds_sent;
518: volatile unsigned int cmds_complete;
519: volatile unsigned int cmds_acked;
520:
521: /* ExKeys */
1.1.1.14 root 522: ExamineKey examine_keys[EXKEYS];
1.1.1.4 root 523: int next_exkey;
1.1.1.14 root 524: unsigned long total_locked_ainos;
1.1.1.3 root 525:
526: /* Keys */
1.1.1.4 root 527: struct key *keys;
528: uae_u32 key_uniq;
529: uae_u32 a_uniq;
1.1.1.3 root 530:
1.1.1.7 root 531: a_inode rootnode;
1.1.1.3 root 532: unsigned long aino_cache_size;
1.1.1.7 root 533: a_inode *aino_hash[MAX_AINO_HASH];
1.1.1.3 root 534: unsigned long nr_cache_hits;
535: unsigned long nr_cache_lookups;
1.1 root 536: } Unit;
537:
1.1.1.3 root 538: typedef uae_u8 *dpacket;
539: #define PUT_PCK_RES1(p,v) do { do_put_mem_long ((uae_u32 *)((p) + dp_Res1), (v)); } while (0)
540: #define PUT_PCK_RES2(p,v) do { do_put_mem_long ((uae_u32 *)((p) + dp_Res2), (v)); } while (0)
541: #define GET_PCK_TYPE(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Type))))
542: #define GET_PCK_RES1(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Res1))))
543: #define GET_PCK_RES2(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Res2))))
544: #define GET_PCK_ARG1(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Arg1))))
545: #define GET_PCK_ARG2(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Arg2))))
546: #define GET_PCK_ARG3(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Arg3))))
547: #define GET_PCK_ARG4(p) ((uae_s32)(do_get_mem_long ((uae_u32 *)((p) + dp_Arg4))))
1.1 root 548:
1.1.1.3 root 549: static char *bstr1 (uaecptr addr)
1.1 root 550: {
551: static char buf[256];
552: int i;
1.1.1.3 root 553: int n = get_byte(addr);
554: addr++;
555:
1.1.1.4 root 556: for (i = 0; i < n; i++, addr++)
1.1.1.3 root 557: buf[i] = get_byte(addr);
1.1 root 558: buf[i] = 0;
559: return buf;
560: }
561:
1.1.1.3 root 562: static char *bstr (Unit *unit, uaecptr addr)
563: {
564: int i;
565: int n = get_byte(addr);
566:
567: addr++;
1.1.1.4 root 568: for (i = 0; i < n; i++, addr++)
1.1.1.3 root 569: unit->tmpbuf3[i] = get_byte(addr);
570: unit->tmpbuf3[i] = 0;
571: return unit->tmpbuf3;
572: }
573:
574: static char *bstr_cut (Unit *unit, uaecptr addr)
575: {
576: char *p = unit->tmpbuf3;
577: int i, colon_seen = 0;
578: int n = get_byte (addr);
579:
580: addr++;
1.1.1.4 root 581: for (i = 0; i < n; i++, addr++) {
1.1.1.3 root 582: uae_u8 c = get_byte(addr);
583: unit->tmpbuf3[i] = c;
584: if (c == '/' || (c == ':' && colon_seen++ == 0))
585: p = unit->tmpbuf3 + i + 1;
586: }
587: unit->tmpbuf3[i] = 0;
588: return p;
589: }
590:
591: static Unit *units = 0;
1.1 root 592: static int unit_num = 0;
593:
594: static Unit*
1.1.1.4 root 595: find_unit (uaecptr port)
1.1 root 596: {
597: Unit* u;
1.1.1.4 root 598: for (u = units; u; u = u->next)
599: if (u->port == port)
1.1 root 600: break;
601:
602: return u;
603: }
1.1.1.7 root 604:
1.1.1.3 root 605: static void prepare_for_open (char *name)
606: {
607: #if 0
608: struct stat statbuf;
609: int mode;
610:
611: if (-1 == stat (name, &statbuf))
612: return;
613:
614: mode = statbuf.st_mode;
615: mode |= S_IRUSR;
616: mode |= S_IWUSR;
617: mode |= S_IXUSR;
618: chmod (name, mode);
619: #endif
620: }
621:
1.1.1.7 root 622: static void de_recycle_aino (Unit *unit, a_inode *aino)
1.1 root 623: {
1.1.1.3 root 624: if (aino->next == 0 || aino == &unit->rootnode)
625: return;
626: aino->next->prev = aino->prev;
627: aino->prev->next = aino->next;
628: aino->next = aino->prev = 0;
629: unit->aino_cache_size--;
630: }
631:
1.1.1.7 root 632: static void dispose_aino (Unit *unit, a_inode **aip, a_inode *aino)
633: {
634: int hash = aino->uniq % MAX_AINO_HASH;
635: if (unit->aino_hash[hash] == aino)
636: unit->aino_hash[hash] = 0;
637:
638: if (aino->dirty && aino->parent)
639: fsdb_dir_writeback (aino->parent);
640:
641: *aip = aino->sibling;
642: if (aino->comment)
643: free (aino->comment);
644: free (aino->nname);
645: free (aino->aname);
646: free (aino);
647: }
648:
1.1.1.9 root 649: static void recycle_aino (Unit *unit, a_inode *new_aino)
1.1.1.3 root 650: {
1.1.1.9 root 651: if (new_aino->dir || new_aino->shlock > 0
652: || new_aino->elock || new_aino == &unit->rootnode)
1.1.1.3 root 653: /* Still in use */
654: return;
655:
1.1.1.14 root 656: TRACE (("Recycling; cache size %d, total_locked %d\n",
657: unit->aino_cache_size, unit->total_locked_ainos));
658: if (unit->aino_cache_size > 500 + unit->total_locked_ainos) {
1.1.1.3 root 659: /* Reap a few. */
660: int i = 0;
661: while (i < 50) {
1.1.1.16 root 662: a_inode *parent = unit->rootnode.prev->parent;
1.1.1.7 root 663: a_inode **aip;
1.1.1.16 root 664: aip = &parent->child;
665:
666: if (! parent->locked_children)
667: for (;;) {
668: a_inode *aino = *aip;
669: if (aino == 0)
670: break;
671:
672: /* Not recyclable if next == 0 (i.e., not chained into
673: recyclable list), or if parent directory is being
674: ExNext()ed. */
675: if (aino->next == 0)
676: aip = &aino->sibling;
677: else {
678: if (aino->shlock > 0 || aino->elock)
679: write_log ("panic: freeing locked a_inode!\n");
680:
681: de_recycle_aino (unit, aino);
682: dispose_aino (unit, aip, aino);
683: i++;
684: }
1.1.1.3 root 685: }
1.1.1.16 root 686: /* In the previous loop, we went through all children of one
687: parent. Re-arrange the recycled list so that we'll find a
688: different parent the next time around. */
689: do {
690: unit->rootnode.next->prev = unit->rootnode.prev;
691: unit->rootnode.prev->next = unit->rootnode.next;
692: unit->rootnode.next = unit->rootnode.prev;
693: unit->rootnode.prev = unit->rootnode.prev->prev;
694: unit->rootnode.prev->next = unit->rootnode.next->prev = &unit->rootnode;
695: } while (unit->rootnode.prev->parent == parent);
1.1.1.3 root 696: }
697: #if 0
698: {
699: char buffer[40];
700: sprintf (buffer, "%d ainos reaped.\n", i);
1.1.1.14 root 701: TRACE ((buffer));
1.1.1.3 root 702: }
703: #endif
704: }
1.1.1.9 root 705:
706: /* Chain it into circular list. */
707: new_aino->next = unit->rootnode.next;
708: new_aino->prev = &unit->rootnode;
709: new_aino->prev->next = new_aino;
710: new_aino->next->prev = new_aino;
711: unit->aino_cache_size++;
1.1.1.3 root 712: }
1.1 root 713:
1.1.1.7 root 714: static void update_child_names (Unit *unit, a_inode *a, a_inode *parent)
1.1.1.3 root 715: {
716: int l0 = strlen (parent->nname) + 2;
1.1 root 717:
1.1.1.3 root 718: while (a != 0) {
719: char *name_start;
720: char *new_name;
1.1.1.13 root 721: char dirsep[2] = { FSDB_DIR_SEPARATOR, '\0' };
722:
1.1.1.3 root 723: a->parent = parent;
1.1.1.13 root 724: name_start = strrchr (a->nname, FSDB_DIR_SEPARATOR);
1.1.1.3 root 725: if (name_start == 0) {
726: write_log ("malformed file name");
727: }
728: name_start++;
729: new_name = (char *)xmalloc (strlen (name_start) + l0);
730: strcpy (new_name, parent->nname);
1.1.1.13 root 731: strcat (new_name, dirsep);
1.1.1.3 root 732: strcat (new_name, name_start);
733: free (a->nname);
734: a->nname = new_name;
735: if (a->child)
736: update_child_names (unit, a->child, a);
737: a = a->sibling;
1.1 root 738: }
1.1.1.3 root 739: }
1.1 root 740:
1.1.1.7 root 741: static void move_aino_children (Unit *unit, a_inode *from, a_inode *to)
1.1.1.3 root 742: {
743: to->child = from->child;
744: from->child = 0;
745: update_child_names (unit, to->child, to);
1.1 root 746: }
747:
1.1.1.7 root 748: static void delete_aino (Unit *unit, a_inode *aino)
1.1 root 749: {
1.1.1.7 root 750: a_inode **aip;
1.1.1.3 root 751: int hash;
752:
1.1.1.4 root 753: TRACE(("deleting aino %x\n", aino->uniq));
1.1.1.3 root 754:
1.1.1.7 root 755: aino->dirty = 1;
756: aino->deleted = 1;
1.1.1.3 root 757: de_recycle_aino (unit, aino);
1.1.1.14 root 758:
759: /* If any ExKeys are currently pointing at us, advance them. */
760: if (aino->parent->exnext_count > 0) {
761: int i;
1.1.1.17 root 762: TRACE(("entering exkey validation\n"));
1.1.1.14 root 763: for (i = 0; i < EXKEYS; i++) {
764: ExamineKey *k = unit->examine_keys + i;
765: if (k->uniq == 0)
766: continue;
767: if (k->aino == aino->parent) {
1.1.1.17 root 768: TRACE(("Same parent found for %d\n", i));
769: if (k->curr_file == aino) {
1.1.1.14 root 770: k->curr_file = aino->sibling;
1.1.1.17 root 771: TRACE(("Advancing curr_file\n"));
772: }
1.1.1.14 root 773: }
774: }
775: }
776:
1.1.1.3 root 777: aip = &aino->parent->child;
778: while (*aip != aino && *aip != 0)
779: aip = &(*aip)->sibling;
780: if (*aip != aino) {
781: write_log ("Couldn't delete aino.\n");
782: return;
783: }
1.1.1.7 root 784: dispose_aino (unit, aip, aino);
1.1 root 785: }
786:
1.1.1.7 root 787: static a_inode *lookup_sub (a_inode *dir, uae_u32 uniq)
1.1.1.3 root 788: {
1.1.1.7 root 789: a_inode **cp = &dir->child;
790: a_inode *c, *retval;
1.1.1.3 root 791:
792: for (;;) {
793: c = *cp;
794: if (c == 0)
795: return 0;
796:
797: if (c->uniq == uniq) {
798: retval = c;
799: break;
800: }
801: if (c->dir) {
1.1.1.7 root 802: a_inode *a = lookup_sub (c, uniq);
1.1.1.3 root 803: if (a != 0) {
804: retval = a;
805: break;
806: }
807: }
808: cp = &c->sibling;
809: }
1.1.1.17 root 810: if (! dir->locked_children) {
811: /* Move to the front to speed up repeated lookups. Don't do this if
812: an ExNext is going on in this directory, or we'll terminally
813: confuse it. */
814: *cp = c->sibling;
815: c->sibling = dir->child;
816: dir->child = c;
817: }
1.1.1.3 root 818: return retval;
819: }
820:
1.1.1.7 root 821: static a_inode *lookup_aino (Unit *unit, uae_u32 uniq)
1.1 root 822: {
1.1.1.7 root 823: a_inode *a;
1.1.1.3 root 824: int hash = uniq % MAX_AINO_HASH;
825:
826: if (uniq == 0)
827: return &unit->rootnode;
828: a = unit->aino_hash[hash];
829: if (a == 0 || a->uniq != uniq)
830: a = lookup_sub (&unit->rootnode, uniq);
831: else
832: unit->nr_cache_hits++;
833: unit->nr_cache_lookups++;
834: unit->aino_hash[hash] = a;
835: return a;
836: }
837:
1.1.1.7 root 838: char *build_nname (const char *d, const char *n)
839: {
840: char dsep[2] = { FSDB_DIR_SEPARATOR, '\0' };
841: char *p = (char *) xmalloc (strlen (d) + strlen (n) + 2);
842: strcpy (p, d);
843: strcat (p, dsep);
844: strcat (p, n);
845: return p;
846: }
847:
848: char *build_aname (const char *d, const char *n)
849: {
850: char *p = (char *) xmalloc (strlen (d) + strlen (n) + 2);
851: strcpy (p, d);
852: strcat (p, "/");
853: strcat (p, n);
854: return p;
855: }
856:
1.1.1.3 root 857: /* This gets called to translate an Amiga name that some program used to
1.1.1.7 root 858: * a name that we can use on the native filesystem. */
859: static char *get_nname (Unit *unit, a_inode *base, char *rel,
860: char **modified_rel)
1.1.1.3 root 861: {
1.1.1.7 root 862: char *found;
1.1.1.3 root 863: char *p = 0;
864:
1.1.1.7 root 865: *modified_rel = 0;
866:
867: /* If we have a mapping of some other aname to "rel", we must pretend
868: * it does not exist.
869: * This can happen for example if an Amiga program creates a
870: * file called ".". We can't represent this in our filesystem,
871: * so we create a special file "uae_xxx" and record the mapping
872: * aname "." -> nname "uae_xxx" in the database. Then, the Amiga
873: * program looks up "uae_xxx" (yes, it's contrived). The filesystem
874: * should not make the uae_xxx file visible to the Amiga side. */
875: if (fsdb_used_as_nname (base, rel))
876: return 0;
877: /* A file called "." (or whatever else is invalid on this filesystem)
878: * does not exist, as far as the Amiga side is concerned. */
879: if (fsdb_name_invalid (rel))
1.1.1.4 root 880: return 0;
881:
1.1.1.7 root 882: /* See if we have a file that has the same name as the aname we are
883: * looking for. */
884: found = fsdb_search_dir (base->nname, rel);
885: if (found == 0)
886: return found;
887: if (found == rel)
888: return build_nname (base->nname, rel);
889:
890: *modified_rel = found;
891: return build_nname (base->nname, found);
892: }
893:
894: static char *create_nname (Unit *unit, a_inode *base, char *rel)
895: {
896: char *p;
897:
898: /* We are trying to create a file called REL. */
899:
900: /* If the name is used otherwise in the directory (or globally), we
901: * need a new unique nname. */
902: if (fsdb_name_invalid (rel) || fsdb_used_as_nname (base, rel)) {
903: oh_dear:
904: p = fsdb_create_unique_nname (base, rel);
905: return p;
906: }
907: p = build_nname (base->nname, rel);
908:
909: /* Delete this code once we know everything works. */
910: if (access (p, R_OK) >= 0 || errno != ENOENT) {
911: write_log ("Filesystem in trouble... please report.\n");
912: free (p);
913: goto oh_dear;
1.1.1.3 root 914: }
915: return p;
916: }
917:
918: /*
919: * This gets called if an ACTION_EXAMINE_NEXT happens and we hit an object
920: * for which we know the name on the native filesystem, but no corresponding
921: * Amiga filesystem name.
922: * @@@ For DOS filesystems, it might make sense to declare the new name
923: * "weak", so that it can get overriden by a subsequent call to get_nname().
924: * That way, if someone does "dir :" and there is a file "foobar.inf", and
925: * someone else tries to open "foobar.info", get_nname() could maybe made to
926: * figure out that this is supposed to be the file "foobar.inf".
927: * DOS sucks...
928: */
1.1.1.7 root 929: static char *get_aname (Unit *unit, a_inode *base, char *rel)
1.1.1.3 root 930: {
1.1.1.7 root 931: return my_strdup (rel);
1.1.1.3 root 932: }
933:
1.1.1.7 root 934: static void init_child_aino (Unit *unit, a_inode *base, a_inode *aino)
1.1.1.3 root 935: {
936: aino->uniq = ++unit->a_uniq;
937: if (unit->a_uniq == 0xFFFFFFFF) {
938: write_log ("Running out of a_inodes (prepare for big trouble)!\n");
939: }
940: aino->shlock = 0;
941: aino->elock = 0;
942:
1.1.1.7 root 943: aino->dirty = 0;
944: aino->deleted = 0;
945:
1.1.1.14 root 946: /* For directories - this one isn't being ExNext()ed yet. */
947: aino->locked_children = 0;
948: aino->exnext_count = 0;
949: /* But the parent might be. */
950: if (base->exnext_count) {
951: unit->total_locked_ainos++;
952: base->locked_children++;
953: }
1.1.1.3 root 954: /* Update tree structure */
955: aino->parent = base;
956: aino->child = 0;
957: aino->sibling = base->child;
958: base->child = aino;
959: aino->next = aino->prev = 0;
1.1.1.7 root 960: }
1.1.1.3 root 961:
1.1.1.7 root 962: static a_inode *new_child_aino (Unit *unit, a_inode *base, char *rel)
963: {
964: char *modified_rel;
965: char *nn;
966: a_inode *aino;
967:
968: TRACE(("new_child_aino %s, %s\n", base->aname, rel));
969:
970: aino = fsdb_lookup_aino_aname (base, rel);
971: if (aino == 0) {
972: nn = get_nname (unit, base, rel, &modified_rel);
973: if (nn == 0)
974: return 0;
975:
1.1.1.11 root 976: aino = (a_inode *) xcalloc (sizeof (a_inode), 1);
1.1.1.7 root 977: if (aino == 0)
978: return 0;
979: aino->aname = modified_rel ? modified_rel : my_strdup (rel);
980: aino->nname = nn;
981:
982: aino->comment = 0;
983: aino->has_dbentry = 0;
984:
985: fsdb_fill_file_attrs (aino);
986: if (aino->dir)
987: fsdb_clean_dir (aino);
1.1.1.3 root 988: }
1.1.1.7 root 989: init_child_aino (unit, base, aino);
990:
991: recycle_aino (unit, aino);
1.1.1.17 root 992: TRACE(("created aino %x, lookup, amigaos_mode %d\n", aino->uniq, aino->amigaos_mode));
1.1.1.7 root 993: return aino;
994: }
995:
996: static a_inode *create_child_aino (Unit *unit, a_inode *base, char *rel, int isdir)
997: {
1.1.1.11 root 998: a_inode *aino = (a_inode *) xcalloc (sizeof (a_inode), 1);
1.1.1.7 root 999: if (aino == 0)
1000: return 0;
1001:
1002: aino->aname = my_strdup (rel);
1003: aino->nname = create_nname (unit, base, rel);
1004:
1005: init_child_aino (unit, base, aino);
1006: aino->amigaos_mode = 0;
1007: aino->dir = isdir;
1008:
1009: aino->comment = 0;
1010: aino->has_dbentry = 0;
1011: aino->dirty = 1;
1.1.1.5 root 1012:
1.1.1.3 root 1013: recycle_aino (unit, aino);
1.1.1.7 root 1014: TRACE(("created aino %x, create\n", aino->uniq));
1.1.1.3 root 1015: return aino;
1016: }
1017:
1.1.1.7 root 1018: static a_inode *lookup_child_aino (Unit *unit, a_inode *base, char *rel, uae_u32 *err)
1.1.1.3 root 1019: {
1.1.1.7 root 1020: a_inode *c = base->child;
1.1.1.3 root 1021: int l0 = strlen (rel);
1022:
1023: if (base->dir == 0) {
1024: *err = ERROR_OBJECT_WRONG_TYPE;
1025: return 0;
1026: }
1027:
1028: while (c != 0) {
1029: int l1 = strlen (c->aname);
1.1.1.7 root 1030: if (l0 <= l1 && same_aname (rel, c->aname + l1 - l0)
1.1.1.3 root 1031: && (l0 == l1 || c->aname[l1-l0-1] == '/'))
1032: break;
1033: c = c->sibling;
1034: }
1035: if (c != 0)
1036: return c;
1.1.1.7 root 1037: c = new_child_aino (unit, base, rel);
1.1.1.3 root 1038: if (c == 0)
1.1.1.11 root 1039: *err = ERROR_OBJECT_NOT_AROUND;
1.1.1.3 root 1040: return c;
1041: }
1042:
1.1.1.7 root 1043: /* Different version because for this one, REL is an nname. */
1044: static a_inode *lookup_child_aino_for_exnext (Unit *unit, a_inode *base, char *rel, uae_u32 *err)
1.1.1.3 root 1045: {
1.1.1.7 root 1046: a_inode *c = base->child;
1.1.1.3 root 1047: int l0 = strlen (rel);
1048:
1049: *err = 0;
1050: while (c != 0) {
1051: int l1 = strlen (c->nname);
1.1.1.7 root 1052: /* Note: using strcmp here. */
1053: if (l0 <= l1 && strcmp (rel, c->nname + l1 - l0) == 0
1054: && (l0 == l1 || c->nname[l1-l0-1] == FSDB_DIR_SEPARATOR))
1.1.1.3 root 1055: break;
1056: c = c->sibling;
1057: }
1058: if (c != 0)
1059: return c;
1.1.1.7 root 1060: c = fsdb_lookup_aino_nname (base, rel);
1061: if (c == 0) {
1062: c = (a_inode *)malloc (sizeof (a_inode));
1063: if (c == 0) {
1064: *err = ERROR_NO_FREE_STORE;
1065: return 0;
1066: }
1067:
1068: c->nname = build_nname (base->nname, rel);
1.1.1.3 root 1069: c->aname = get_aname (unit, base, rel);
1.1.1.7 root 1070: c->comment = 0;
1071: c->has_dbentry = 0;
1072: fsdb_fill_file_attrs (c);
1073: if (c->dir)
1074: fsdb_clean_dir (c);
1.1.1.3 root 1075: }
1.1.1.7 root 1076: init_child_aino (unit, base, c);
1077:
1078: recycle_aino (unit, c);
1079: TRACE(("created aino %x, exnext\n", c->uniq));
1080:
1.1.1.3 root 1081: return c;
1082: }
1083:
1.1.1.7 root 1084: static a_inode *get_aino (Unit *unit, a_inode *base, const char *rel, uae_u32 *err)
1.1.1.3 root 1085: {
1086: char *tmp;
1087: char *p;
1.1.1.7 root 1088: a_inode *curr;
1.1.1.3 root 1089: int i;
1090:
1091: *err = 0;
1.1.1.4 root 1092: TRACE(("get_path(%s,%s)\n", base->aname, rel));
1.1.1.3 root 1093:
1094: /* root-relative path? */
1.1.1.4 root 1095: for (i = 0; rel[i] && rel[i] != '/' && rel[i] != ':'; i++)
1.1.1.3 root 1096: ;
1097: if (':' == rel[i])
1098: rel += i+1;
1099:
1100: tmp = my_strdup (rel);
1101: p = tmp;
1102: curr = base;
1103:
1.1.1.7 root 1104: while (*p) {
1.1.1.3 root 1105: /* start with a slash? go up a level. */
1106: if (*p == '/') {
1107: if (curr->parent != 0)
1108: curr = curr->parent;
1109: p++;
1110: } else {
1.1.1.7 root 1111: a_inode *next;
1.1.1.3 root 1112:
1113: char *component_end;
1114: component_end = strchr (p, '/');
1115: if (component_end != 0)
1116: *component_end = '\0';
1117: next = lookup_child_aino (unit, curr, p, err);
1118: if (next == 0) {
1119: /* if only last component not found, return parent dir. */
1.1.1.11 root 1120: if (*err != ERROR_OBJECT_NOT_AROUND || component_end != 0)
1.1.1.3 root 1121: curr = 0;
1122: /* ? what error is appropriate? */
1123: break;
1124: }
1125: curr = next;
1126: if (component_end)
1127: p = component_end+1;
1128: else
1129: break;
1130:
1131: }
1132: }
1133: free (tmp);
1134: return curr;
1135: }
1136:
1137: static uae_u32 startup_handler (void)
1138: {
1139: /* Just got the startup packet. It's in A4. DosBase is in A2,
1140: * our allocated volume structure is in D6, A5 is a pointer to
1141: * our port. */
1.1.1.7 root 1142: uaecptr rootnode = get_long (m68k_areg (regs, 2) + 34);
1143: uaecptr dos_info = get_long (rootnode + 24) << 2;
1.1.1.3 root 1144: uaecptr pkt = m68k_dreg (regs, 3);
1145: uaecptr arg2 = get_long (pkt + dp_Arg2);
1.1 root 1146: int i, namelen;
1.1.1.3 root 1147: char* devname = bstr1 (get_long (pkt + dp_Arg1) << 2);
1.1 root 1148: char* s;
1.1.1.4 root 1149: Unit *unit;
1.1.1.3 root 1150: UnitInfo *uinfo;
1.1 root 1151:
1152: /* find UnitInfo with correct device name */
1.1.1.4 root 1153: s = strchr (devname, ':');
1154: if (s)
1.1.1.3 root 1155: *s = '\0';
1.1 root 1156:
1.1.1.4 root 1157: for (i = 0; i < current_mountinfo->num_units; i++) {
1.1 root 1158: /* Hardfile volume name? */
1.1.1.4 root 1159: if (current_mountinfo->ui[i].volname == 0)
1.1 root 1160: continue;
1.1.1.3 root 1161:
1.1.1.4 root 1162: if (current_mountinfo->ui[i].startup == arg2)
1.1.1.3 root 1163: break;
1.1 root 1164: }
1.1.1.3 root 1165:
1.1.1.4 root 1166: if (i == current_mountinfo->num_units
1167: || access (current_mountinfo->ui[i].rootdir, R_OK) != 0)
1168: {
1169: write_log ("Failed attempt to mount device\n", devname);
1.1.1.3 root 1170: put_long (pkt + dp_Res1, DOS_FALSE);
1171: put_long (pkt + dp_Res2, ERROR_DEVICE_NOT_MOUNTED);
1172: return 1;
1.1 root 1173: }
1.1.1.4 root 1174: uinfo = current_mountinfo->ui + i;
1.1 root 1175:
1.1.1.11 root 1176: unit = (Unit *) xcalloc (sizeof (Unit), 1);
1.1 root 1177: unit->next = units;
1178: units = unit;
1.1.1.3 root 1179: uinfo->self = unit;
1.1 root 1180:
1181: unit->volume = 0;
1.1.1.7 root 1182: unit->port = m68k_areg (regs, 5);
1.1 root 1183: unit->unit = unit_num++;
1184:
1.1.1.3 root 1185: unit->ui.devname = uinfo->devname;
1186: unit->ui.volname = my_strdup (uinfo->volname); /* might free later for rename */
1187: unit->ui.rootdir = uinfo->rootdir;
1188: unit->ui.readonly = uinfo->readonly;
1189: unit->ui.unit_pipe = uinfo->unit_pipe;
1190: unit->ui.back_pipe = uinfo->back_pipe;
1191: unit->cmds_complete = 0;
1192: unit->cmds_sent = 0;
1193: unit->cmds_acked = 0;
1194: for (i = 0; i < EXKEYS; i++) {
1195: unit->examine_keys[i].aino = 0;
1.1.1.14 root 1196: unit->examine_keys[i].curr_file = 0;
1.1.1.3 root 1197: unit->examine_keys[i].uniq = 0;
1198: }
1.1.1.14 root 1199: unit->total_locked_ainos = 0;
1.1.1.3 root 1200: unit->next_exkey = 1;
1201: unit->keys = 0;
1202: unit->a_uniq = unit->key_uniq = 0;
1203:
1204: unit->rootnode.aname = uinfo->volname;
1205: unit->rootnode.nname = uinfo->rootdir;
1206: unit->rootnode.sibling = 0;
1207: unit->rootnode.next = unit->rootnode.prev = &unit->rootnode;
1208: unit->rootnode.uniq = 0;
1209: unit->rootnode.parent = 0;
1210: unit->rootnode.child = 0;
1211: unit->rootnode.dir = 1;
1212: unit->rootnode.amigaos_mode = 0;
1213: unit->rootnode.shlock = 0;
1214: unit->rootnode.elock = 0;
1.1.1.11 root 1215: unit->rootnode.comment = 0;
1216: unit->rootnode.has_dbentry = 0;
1.1.1.3 root 1217: unit->aino_cache_size = 0;
1218: for (i = 0; i < MAX_AINO_HASH; i++)
1219: unit->aino_hash[i] = 0;
1220:
1221: /* write_comm_pipe_int (unit->ui.unit_pipe, -1, 1);*/
1.1 root 1222:
1.1.1.4 root 1223: TRACE(("**** STARTUP volume %s\n", unit->ui.volname));
1.1 root 1224:
1225: /* fill in our process in the device node */
1.1.1.3 root 1226: put_long ((get_long (pkt + dp_Arg3) << 2) + 8, unit->port);
1.1.1.7 root 1227: unit->dosbase = m68k_areg (regs, 2);
1.1 root 1228:
1.1.1.3 root 1229: /* make new volume */
1230: unit->volume = m68k_areg (regs, 3) + 32;
1231: #ifdef UAE_FILESYS_THREADS
1232: unit->locklist = m68k_areg (regs, 3) + 8;
1233: #else
1234: unit->locklist = m68k_areg (regs, 3);
1235: #endif
1236: unit->dummy_message = m68k_areg (regs, 3) + 12;
1.1 root 1237:
1.1.1.3 root 1238: put_long (unit->dummy_message + 10, 0);
1239:
1240: put_long (unit->volume + 4, 2); /* Type = dt_volume */
1241: put_long (unit->volume + 12, 0); /* Lock */
1242: put_long (unit->volume + 16, 3800); /* Creation Date */
1243: put_long (unit->volume + 20, 0);
1244: put_long (unit->volume + 24, 0);
1245: put_long (unit->volume + 28, 0); /* lock list */
1246: put_long (unit->volume + 40, (unit->volume + 44) >> 2); /* Name */
1247: namelen = strlen (unit->ui.volname);
1248: put_byte (unit->volume + 44, namelen);
1.1.1.4 root 1249: for (i = 0; i < namelen; i++)
1.1.1.3 root 1250: put_byte (unit->volume + 45 + i, unit->ui.volname[i]);
1251:
1252: /* link into DOS list */
1.1.1.7 root 1253: put_long (unit->volume, get_long (dos_info + 4));
1.1.1.3 root 1254: put_long (dos_info + 4, unit->volume >> 2);
1255:
1256: put_long (unit->volume + 8, unit->port);
1257: put_long (unit->volume + 32, DISK_TYPE);
1.1 root 1258:
1.1.1.3 root 1259: put_long (pkt + dp_Res1, DOS_TRUE);
1.1.1.7 root 1260:
1261: fsdb_clean_dir (&unit->rootnode);
1262:
1.1.1.3 root 1263: return 0;
1.1 root 1264: }
1265:
1266: static void
1.1.1.4 root 1267: do_info (Unit *unit, dpacket packet, uaecptr info)
1.1 root 1268: {
1.1.1.4 root 1269: struct fs_usage fsu;
1270:
1271: if (get_fs_usage (unit->ui.rootdir, 0, &fsu) != 0) {
1.1.1.3 root 1272: PUT_PCK_RES1 (packet, DOS_FALSE);
1273: PUT_PCK_RES2 (packet, dos_errno ());
1.1.1.4 root 1274: return;
1.1 root 1275: }
1276:
1.1.1.4 root 1277: fsu.fsu_blocks >>= 1;
1278: fsu.fsu_bavail >>= 1;
1.1.1.7 root 1279: put_long (info, 0); /* errors */
1280: put_long (info + 4, unit->unit); /* unit number */
1281: put_long (info + 8, unit->ui.readonly ? 80 : 82); /* state */
1282: put_long (info + 12, fsu.fsu_blocks ); /* numblocks */
1283: put_long (info + 16, fsu.fsu_blocks - fsu.fsu_bavail); /* inuse */
1284: put_long (info + 20, 1024); /* bytesperblock */
1285: put_long (info + 24, DISK_TYPE); /* disk type */
1286: put_long (info + 28, unit->volume >> 2); /* volume node */
1287: put_long (info + 32, 0); /* inuse */
1.1.1.3 root 1288: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 1289: }
1290:
1291: static void
1.1.1.4 root 1292: action_disk_info (Unit *unit, dpacket packet)
1.1 root 1293: {
1.1.1.4 root 1294: TRACE(("ACTION_DISK_INFO\n"));
1.1.1.3 root 1295: do_info(unit, packet, GET_PCK_ARG1 (packet) << 2);
1.1 root 1296: }
1297:
1298: static void
1.1.1.4 root 1299: action_info (Unit *unit, dpacket packet)
1.1 root 1300: {
1.1.1.4 root 1301: TRACE(("ACTION_INFO\n"));
1.1.1.3 root 1302: do_info(unit, packet, GET_PCK_ARG2 (packet) << 2);
1.1 root 1303: }
1304:
1.1.1.4 root 1305: static void free_key (Unit *unit, Key *k)
1.1 root 1306: {
1307: Key *k1;
1.1.1.3 root 1308: Key *prev = 0;
1309: for (k1 = unit->keys; k1; k1 = k1->next) {
1310: if (k == k1) {
1.1.1.4 root 1311: if (prev)
1.1.1.3 root 1312: prev->next = k->next;
1313: else
1314: unit->keys = k->next;
1315: break;
1316: }
1317: prev = k1;
1.1 root 1318: }
1319:
1320: if (k->fd >= 0)
1.1.1.13 root 1321: close (k->fd);
1.1.1.3 root 1322:
1.1 root 1323: free(k);
1324: }
1325:
1.1.1.4 root 1326: static Key *lookup_key (Unit *unit, uae_u32 uniq)
1.1 root 1327: {
1328: Key *k;
1.1.1.3 root 1329: /* It's hardly worthwhile to optimize this - most of the time there are
1330: * only one or zero keys. */
1.1.1.4 root 1331: for (k = unit->keys; k; k = k->next) {
1.1.1.3 root 1332: if (uniq == k->uniq)
1333: return k;
1.1 root 1334: }
1.1.1.3 root 1335: write_log ("Error: couldn't find key!\n");
1336: #if 0
1.1 root 1337: exit(1);
1338: /* NOTREACHED */
1.1.1.3 root 1339: #endif
1340: /* There isn't much hope we will recover. Unix would kill the process,
1341: * AmigaOS gets killed by it. */
1342: write_log ("Better reset that Amiga - the system is messed up.\n");
1343: return 0;
1.1 root 1344: }
1345:
1.1.1.4 root 1346: static Key *new_key (Unit *unit)
1.1 root 1347: {
1.1.1.4 root 1348: Key *k = (Key *) xmalloc(sizeof(Key));
1.1.1.3 root 1349: k->uniq = ++unit->key_uniq;
1.1 root 1350: k->fd = -1;
1351: k->file_pos = 0;
1.1.1.3 root 1352: k->next = unit->keys;
1353: unit->keys = k;
1.1 root 1354:
1355: return k;
1356: }
1357:
1358: static void
1.1.1.4 root 1359: dumplock (Unit *unit, uaecptr lock)
1.1 root 1360: {
1.1.1.7 root 1361: a_inode *a;
1.1.1.4 root 1362: TRACE(("LOCK: 0x%lx", lock));
1363: if (!lock) {
1364: TRACE(("\n"));
1.1 root 1365: return;
1366: }
1.1.1.4 root 1367: TRACE(("{ next=0x%lx, mode=%ld, handler=0x%lx, volume=0x%lx, aino %lx ",
1.1.1.7 root 1368: get_long (lock) << 2, get_long (lock+8),
1369: get_long (lock+12), get_long (lock+16),
1370: get_long (lock + 4)));
1.1.1.3 root 1371: a = lookup_aino (unit, get_long (lock + 4));
1372: if (a == 0) {
1.1.1.4 root 1373: TRACE(("not found!"));
1.1.1.3 root 1374: } else {
1.1.1.4 root 1375: TRACE(("%s", a->nname));
1.1.1.3 root 1376: }
1.1.1.4 root 1377: TRACE((" }\n"));
1.1 root 1378: }
1379:
1.1.1.7 root 1380: static a_inode *find_aino (Unit *unit, uaecptr lock, const char *name, uae_u32 *err)
1.1 root 1381: {
1.1.1.7 root 1382: a_inode *a;
1.1 root 1383:
1.1.1.3 root 1384: if (lock) {
1.1.1.7 root 1385: a_inode *olda = lookup_aino (unit, get_long (lock + 4));
1.1.1.3 root 1386: if (olda == 0) {
1387: /* That's the best we can hope to do. */
1388: a = get_aino (unit, &unit->rootnode, name, err);
1.1 root 1389: } else {
1.1.1.4 root 1390: TRACE(("aino: 0x%08lx", (unsigned long int)olda->uniq));
1391: TRACE((" \"%s\"\n", olda->nname));
1.1.1.3 root 1392: a = get_aino (unit, olda, name, err);
1.1 root 1393: }
1394: } else {
1.1.1.3 root 1395: a = get_aino (unit, &unit->rootnode, name, err);
1.1 root 1396: }
1.1.1.3 root 1397: if (a) {
1.1.1.4 root 1398: TRACE(("aino=\"%s\"\n", a->nname));
1.1.1.3 root 1399: }
1400: return a;
1.1 root 1401: }
1402:
1.1.1.4 root 1403: static uaecptr make_lock (Unit *unit, uae_u32 uniq, long mode)
1.1 root 1404: {
1.1.1.3 root 1405: /* allocate lock from the list kept by the assembly code */
1406: uaecptr lock;
1.1 root 1407:
1.1.1.3 root 1408: lock = get_long (unit->locklist);
1409: put_long (unit->locklist, get_long (lock));
1410: lock += 4;
1.1 root 1411:
1.1.1.7 root 1412: put_long (lock + 4, uniq);
1413: put_long (lock + 8, mode);
1414: put_long (lock + 12, unit->port);
1415: put_long (lock + 16, unit->volume >> 2);
1.1 root 1416:
1417: /* prepend to lock chain */
1.1.1.7 root 1418: put_long (lock, get_long (unit->volume + 28));
1419: put_long (unit->volume + 28, lock >> 2);
1.1 root 1420:
1.1.1.3 root 1421: DUMPLOCK(unit, lock);
1.1 root 1422: return lock;
1423: }
1424:
1.1.1.4 root 1425: static void free_lock (Unit *unit, uaecptr lock)
1.1 root 1426: {
1.1.1.4 root 1427: if (! lock)
1.1 root 1428: return;
1429:
1.1.1.7 root 1430: if (lock == get_long (unit->volume + 28) << 2) {
1431: put_long (unit->volume + 28, get_long (lock));
1.1 root 1432: } else {
1.1.1.7 root 1433: uaecptr current = get_long (unit->volume + 28);
1.1.1.3 root 1434: uaecptr next = 0;
1.1.1.4 root 1435: while (current) {
1.1.1.7 root 1436: next = get_long (current << 2);
1.1.1.4 root 1437: if (lock == next << 2)
1.1 root 1438: break;
1439: current = next;
1440: }
1.1.1.7 root 1441: put_long (current << 2, get_long (lock));
1.1 root 1442: }
1.1.1.3 root 1443: lock -= 4;
1444: put_long (lock, get_long (unit->locklist));
1445: put_long (unit->locklist, lock);
1.1 root 1446: }
1447:
1448: static void
1.1.1.4 root 1449: action_lock (Unit *unit, dpacket packet)
1.1 root 1450: {
1.1.1.3 root 1451: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
1452: uaecptr name = GET_PCK_ARG2 (packet) << 2;
1453: long mode = GET_PCK_ARG3 (packet);
1.1.1.7 root 1454: a_inode *a;
1.1.1.3 root 1455: uae_u32 err;
1.1 root 1456:
1.1.1.13 root 1457: if (mode != SHARED_LOCK && mode != EXCLUSIVE_LOCK) {
1.1.1.4 root 1458: TRACE(("Bad mode.\n"));
1.1.1.13 root 1459: mode = SHARED_LOCK;
1.1.1.3 root 1460: }
1.1 root 1461:
1.1.1.4 root 1462: TRACE(("ACTION_LOCK(0x%lx, \"%s\", %d)\n", lock, bstr (unit, name), mode));
1.1.1.3 root 1463: DUMPLOCK(unit, lock);
1.1 root 1464:
1.1.1.3 root 1465: a = find_aino (unit, lock, bstr (unit, name), &err);
1.1.1.13 root 1466: if (err == 0 && (a->elock || (mode != SHARED_LOCK && a->shlock > 0))) {
1.1.1.3 root 1467: err = ERROR_OBJECT_IN_USE;
1.1 root 1468: }
1.1.1.3 root 1469: /* Lock() doesn't do access checks. */
1470: if (err != 0) {
1471: PUT_PCK_RES1 (packet, DOS_FALSE);
1472: PUT_PCK_RES2 (packet, err);
1473: return;
1474: }
1.1.1.13 root 1475: if (mode == SHARED_LOCK)
1.1.1.3 root 1476: a->shlock++;
1477: else
1478: a->elock = 1;
1479: de_recycle_aino (unit, a);
1480: PUT_PCK_RES1 (packet, make_lock (unit, a->uniq, mode) >> 2);
1.1 root 1481: }
1482:
1.1.1.4 root 1483: static void action_free_lock (Unit *unit, dpacket packet)
1.1 root 1484: {
1.1.1.3 root 1485: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
1.1.1.7 root 1486: a_inode *a;
1.1.1.4 root 1487: TRACE(("ACTION_FREE_LOCK(0x%lx)\n", lock));
1.1.1.3 root 1488: DUMPLOCK(unit, lock);
1.1 root 1489:
1.1.1.3 root 1490: a = lookup_aino (unit, get_long (lock + 4));
1491: if (a == 0) {
1492: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.11 root 1493: PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND);
1.1.1.3 root 1494: return;
1495: }
1496: if (a->elock)
1497: a->elock = 0;
1498: else
1499: a->shlock--;
1500: recycle_aino (unit, a);
1.1 root 1501: free_lock(unit, lock);
1502:
1.1.1.3 root 1503: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 1504: }
1505:
1506: static void
1.1.1.4 root 1507: action_dup_lock (Unit *unit, dpacket packet)
1.1 root 1508: {
1.1.1.3 root 1509: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
1.1.1.7 root 1510: a_inode *a;
1.1.1.4 root 1511: TRACE(("ACTION_DUP_LOCK(0x%lx)\n", lock));
1.1.1.3 root 1512: DUMPLOCK(unit, lock);
1.1 root 1513:
1.1.1.4 root 1514: if (!lock) {
1.1.1.3 root 1515: PUT_PCK_RES1 (packet, 0);
1.1 root 1516: return;
1517: }
1.1.1.3 root 1518: a = lookup_aino (unit, get_long (lock + 4));
1519: if (a == 0) {
1520: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.11 root 1521: PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND);
1.1.1.3 root 1522: return;
1.1 root 1523: }
1.1.1.3 root 1524: /* DupLock()ing exclusive locks isn't possible, says the Autodoc, but
1525: * at least the RAM-Handler seems to allow it. Let's see what happens
1526: * if we don't. */
1527: if (a->elock) {
1528: PUT_PCK_RES1 (packet, DOS_FALSE);
1529: PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE);
1530: return;
1531: }
1532: a->shlock++;
1533: de_recycle_aino (unit, a);
1534: PUT_PCK_RES1 (packet, make_lock (unit, a->uniq, -2) >> 2);
1.1 root 1535: }
1536:
1537: /* convert time_t to/from AmigaDOS time */
1538: const int secs_per_day = 24 * 60 * 60;
1539: const int diff = (8 * 365 + 2) * (24 * 60 * 60);
1540:
1541: static void
1.1.1.4 root 1542: get_time (time_t t, long* days, long* mins, long* ticks)
1.1 root 1543: {
1544: /* time_t is secs since 1-1-1970 */
1545: /* days since 1-1-1978 */
1546: /* mins since midnight */
1547: /* ticks past minute @ 50Hz */
1548:
1549: t -= diff;
1550: *days = t / secs_per_day;
1551: t -= *days * secs_per_day;
1552: *mins = t / 60;
1553: t -= *mins * 60;
1554: *ticks = t * 50;
1555: }
1556:
1557: static time_t
1.1.1.4 root 1558: put_time (long days, long mins, long ticks)
1.1 root 1559: {
1560: time_t t;
1561: t = ticks / 50;
1562: t += mins * 60;
1563: t += days * secs_per_day;
1564: t += diff;
1565:
1566: return t;
1567: }
1568:
1.1.1.14 root 1569: static void free_exkey (Unit *unit, ExamineKey *ek)
1.1 root 1570: {
1.1.1.14 root 1571: if (--ek->aino->exnext_count == 0) {
1572: TRACE (("Freeing ExKey and reducing total_locked from %d by %d\n",
1573: unit->total_locked_ainos, ek->aino->locked_children));
1574: unit->total_locked_ainos -= ek->aino->locked_children;
1575: ek->aino->locked_children = 0;
1576: }
1.1.1.3 root 1577: ek->aino = 0;
1578: ek->uniq = 0;
1.1 root 1579: }
1580:
1.1.1.13 root 1581: static ExamineKey *lookup_exkey (Unit *unit, uae_u32 uniq)
1582: {
1583: ExamineKey *ek;
1584: int i;
1585:
1586: ek = unit->examine_keys;
1587: for (i = 0; i < EXKEYS; i++, ek++) {
1588: /* Did we find a free one? */
1589: if (ek->uniq == uniq)
1590: return ek;
1591: }
1592: write_log ("Houston, we have a BIG problem.\n");
1593: return 0;
1594: }
1595:
1.1.1.3 root 1596: /* This is so sick... who invented ACTION_EXAMINE_NEXT? What did he THINK??? */
1.1.1.7 root 1597: static ExamineKey *new_exkey (Unit *unit, a_inode *aino)
1.1 root 1598: {
1.1.1.3 root 1599: uae_u32 uniq;
1.1.1.14 root 1600: uae_u32 oldest = 0xFFFFFFFE;
1.1.1.3 root 1601: ExamineKey *ek, *oldest_ek = 0;
1602: int i;
1603:
1604: ek = unit->examine_keys;
1605: for (i = 0; i < EXKEYS; i++, ek++) {
1606: /* Did we find a free one? */
1607: if (ek->aino == 0)
1608: continue;
1609: if (ek->uniq < oldest)
1610: oldest = (oldest_ek = ek)->uniq;
1611: }
1612: ek = unit->examine_keys;
1613: for (i = 0; i < EXKEYS; i++, ek++) {
1614: /* Did we find a free one? */
1615: if (ek->aino == 0)
1616: goto found;
1617: }
1618: /* This message should usually be harmless. */
1619: write_log ("Houston, we have a problem.\n");
1.1.1.14 root 1620: free_exkey (unit, oldest_ek);
1.1.1.3 root 1621: ek = oldest_ek;
1622: found:
1623:
1624: uniq = unit->next_exkey;
1.1.1.14 root 1625: if (uniq >= 0xFFFFFFFE) {
1.1.1.3 root 1626: /* Things will probably go wrong, but most likely the Amiga will crash
1627: * before this happens because of something else. */
1628: uniq = 1;
1.1 root 1629: }
1.1.1.3 root 1630: unit->next_exkey = uniq+1;
1631: ek->aino = aino;
1.1.1.14 root 1632: ek->curr_file = 0;
1.1 root 1633: ek->uniq = uniq;
1634: return ek;
1635: }
1636:
1.1.1.14 root 1637: static void move_exkeys (Unit *unit, a_inode *from, a_inode *to)
1638: {
1639: int i;
1640: unsigned long tmp = 0;
1641: for (i = 0; i < EXKEYS; i++) {
1642: ExamineKey *k = unit->examine_keys + i;
1643: if (k->uniq == 0)
1644: continue;
1645: if (k->aino == from) {
1646: k->aino = to;
1647: tmp++;
1648: }
1649: }
1650: if (tmp != from->exnext_count)
1651: write_log ("filesys.c: Bug in ExNext bookkeeping. BAD.\n");
1652: to->exnext_count = from->exnext_count;
1653: to->locked_children = from->locked_children;
1654: from->exnext_count = 0;
1655: from->locked_children = 0;
1656: }
1657:
1.1 root 1658: static void
1.1.1.7 root 1659: get_fileinfo (Unit *unit, dpacket packet, uaecptr info, a_inode *aino)
1.1 root 1660: {
1661: struct stat statbuf;
1662: long days, mins, ticks;
1.1.1.3 root 1663: int i, n;
1664: char *x;
1665:
1666: /* No error checks - this had better work. */
1667: stat (aino->nname, &statbuf);
1668:
1669: if (aino->parent == 0) {
1670: x = unit->ui.volname;
1671: put_long (info + 4, 1);
1672: put_long (info + 120, 1);
1.1 root 1673: } else {
1.1.1.3 root 1674: /* AmigaOS docs say these have to contain the same value. */
1.1.1.7 root 1675: put_long (info + 4, aino->dir ? 2 : -3);
1676: put_long (info + 120, aino->dir ? 2 : -3);
1677: x = aino->aname;
1.1.1.3 root 1678: }
1.1.1.4 root 1679: TRACE(("name=\"%s\"\n", x));
1.1.1.7 root 1680: n = strlen (x);
1.1.1.3 root 1681: if (n > 106)
1682: n = 106;
1683: i = 8;
1.1.1.7 root 1684: put_byte (info + i, n); i++;
1685: while (n--)
1686: put_byte (info + i, *x), i++, x++;
1687: while (i < 108)
1688: put_byte (info + i, 0), i++;
1.1.1.3 root 1689:
1690: put_long (info + 116, aino->amigaos_mode);
1.1.1.7 root 1691: put_long (info + 124, statbuf.st_size);
1.1 root 1692: #ifdef HAVE_ST_BLOCKS
1.1.1.7 root 1693: put_long (info + 128, statbuf.st_blocks);
1.1 root 1694: #else
1.1.1.7 root 1695: put_long (info + 128, statbuf.st_size / 512 + 1);
1.1 root 1696: #endif
1.1.1.7 root 1697: get_time (statbuf.st_mtime, &days, &mins, &ticks);
1698: put_long (info + 132, days);
1699: put_long (info + 136, mins);
1700: put_long (info + 140, ticks);
1701: if (aino->comment == 0)
1702: put_long (info + 144, 0);
1703: else {
1704: TRACE(("comment=\"%s\"\n", aino->comment));
1705: i = 144;
1.1.1.16 root 1706: x = aino->comment;
1707: if (! x)
1708: x = "";
1709: n = strlen (x);
1.1.1.7 root 1710: if (n > 78)
1711: n = 78;
1712: put_byte (info + i, n); i++;
1713: while (n--)
1714: put_byte (info + i, *x), i++, x++;
1715: while (i < 224)
1716: put_byte (info + i, 0), i++;
1717: }
1.1.1.3 root 1718: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 1719: }
1720:
1.1.1.4 root 1721: static void action_examine_object (Unit *unit, dpacket packet)
1.1 root 1722: {
1.1.1.3 root 1723: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
1724: uaecptr info = GET_PCK_ARG2 (packet) << 2;
1.1.1.7 root 1725: a_inode *aino = 0;
1.1 root 1726:
1.1.1.4 root 1727: TRACE(("ACTION_EXAMINE_OBJECT(0x%lx,0x%lx)\n", lock, info));
1.1.1.3 root 1728: DUMPLOCK(unit, lock);
1.1 root 1729:
1.1.1.3 root 1730: if (lock != 0)
1.1.1.7 root 1731: aino = lookup_aino (unit, get_long (lock + 4));
1.1.1.3 root 1732: if (aino == 0)
1733: aino = &unit->rootnode;
1734:
1735: get_fileinfo (unit, packet, info, aino);
1736: if (aino->dir) {
1.1.1.7 root 1737: put_long (info, 0xFFFFFFFF);
1.1.1.3 root 1738: } else
1.1.1.7 root 1739: put_long (info, 0);
1.1 root 1740: }
1741:
1.1.1.14 root 1742: /* Read a directory's contents, create a_inodes for each file, and
1743: mark them as locked in memory so that recycle_aino will not reap
1744: them.
1745: We do this to avoid problems with the host OS: we don't want to
1746: leave the directory open on the host side until all ExNext()s have
1747: finished - they may never finish! */
1748:
1749: static void populate_directory (Unit *unit, a_inode *base)
1750: {
1751: DIR *d = opendir (base->nname);
1752: a_inode *aino;
1753:
1754: for (aino = base->child; aino; aino = aino->sibling) {
1755: base->locked_children++;
1756: unit->total_locked_ainos++;
1757: }
1.1.1.17 root 1758: TRACE(("Populating directory, child %p, locked_children %d\n",
1759: base->child, base->locked_children));
1.1.1.14 root 1760: for (;;) {
1761: struct dirent de_space;
1762: struct dirent *de;
1763: uae_u32 err;
1764:
1765: /* Find next file that belongs to the Amiga fs (skipping things
1766: like "..", "." etc. */
1767: do {
1768: de = my_readdir (d, &de_space);
1769: } while (de && fsdb_name_invalid (de->d_name));
1770: if (! de)
1771: break;
1772: /* This calls init_child_aino, which will notice that the parent is
1773: being ExNext()ed, and it will increment the locked counts. */
1774: aino = lookup_child_aino_for_exnext (unit, base, de->d_name, &err);
1775: }
1776: closedir (d);
1777: }
1778:
1779: static void do_examine (Unit *unit, dpacket packet, ExamineKey *ek, uaecptr info)
1780: {
1781: a_inode *aino;
1782:
1783: if (ek->curr_file == 0)
1784: goto no_more_entries;
1785:
1786: get_fileinfo (unit, packet, info, ek->curr_file);
1787: ek->curr_file = ek->curr_file->sibling;
1.1.1.17 root 1788: TRACE (("curr_file set to %p %s\n", ek->curr_file,
1789: ek->curr_file ? ek->curr_file->aname : "NULL"));
1.1.1.14 root 1790: return;
1791:
1792: no_more_entries:
1793: TRACE(("no more entries\n"));
1794: free_exkey (unit, ek);
1795: PUT_PCK_RES1 (packet, DOS_FALSE);
1796: PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES);
1797: }
1798:
1.1.1.4 root 1799: static void action_examine_next (Unit *unit, dpacket packet)
1.1 root 1800: {
1.1.1.3 root 1801: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
1802: uaecptr info = GET_PCK_ARG2 (packet) << 2;
1.1.1.7 root 1803: a_inode *aino = 0;
1.1.1.3 root 1804: ExamineKey *ek;
1805: uae_u32 uniq;
1.1 root 1806:
1.1.1.4 root 1807: TRACE(("ACTION_EXAMINE_NEXT(0x%lx,0x%lx)\n", lock, info));
1.1.1.3 root 1808: DUMPLOCK(unit, lock);
1.1 root 1809:
1.1.1.3 root 1810: if (lock != 0)
1.1.1.7 root 1811: aino = lookup_aino (unit, get_long (lock + 4));
1.1.1.3 root 1812: if (aino == 0)
1813: aino = &unit->rootnode;
1814:
1815: uniq = get_long (info);
1816: if (uniq == 0) {
1817: write_log ("ExNext called for a file! (Houston?)\n");
1.1.1.14 root 1818: goto no_more_entries;
1819: } else if (uniq == 0xFFFFFFFE)
1820: goto no_more_entries;
1821: else if (uniq == 0xFFFFFFFF) {
1.1.1.17 root 1822: TRACE(("Creating new ExKey\n"));
1.1.1.14 root 1823: ek = new_exkey (unit, aino);
1824: if (ek) {
1825: if (aino->exnext_count++ == 0)
1826: populate_directory (unit, aino);
1827: }
1828: ek->curr_file = aino->child;
1.1.1.17 root 1829: TRACE(("Initial curr_file: %p %s\n", ek->curr_file,
1830: ek->curr_file ? ek->curr_file->aname : "NULL"));
1831: } else {
1832: TRACE(("Looking up ExKey\n"));
1.1.1.7 root 1833: ek = lookup_exkey (unit, get_long (info));
1.1.1.17 root 1834: }
1.1.1.3 root 1835: if (ek == 0) {
1836: write_log ("Couldn't find a matching ExKey. Prepare for trouble.\n");
1.1.1.14 root 1837: goto no_more_entries;
1.1.1.3 root 1838: }
1.1.1.7 root 1839: put_long (info, ek->uniq);
1840: do_examine (unit, packet, ek, info);
1.1.1.14 root 1841: return;
1842:
1843: no_more_entries:
1844: PUT_PCK_RES1 (packet, DOS_FALSE);
1845: PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES);
1.1 root 1846: }
1847:
1.1.1.4 root 1848: static void do_find (Unit *unit, dpacket packet, int mode, int create, int fallback)
1.1 root 1849: {
1.1.1.3 root 1850: uaecptr fh = GET_PCK_ARG1 (packet) << 2;
1851: uaecptr lock = GET_PCK_ARG2 (packet) << 2;
1852: uaecptr name = GET_PCK_ARG3 (packet) << 2;
1.1.1.7 root 1853: a_inode *aino;
1.1 root 1854: Key *k;
1.1.1.3 root 1855: int fd;
1856: uae_u32 err;
1857: mode_t openmode;
1858: int aino_created = 0;
1859:
1.1.1.4 root 1860: TRACE(("ACTION_FIND_*(0x%lx,0x%lx,\"%s\",%d)\n", fh, lock, bstr (unit, name), mode));
1.1.1.3 root 1861: DUMPLOCK(unit, lock);
1862:
1863: aino = find_aino (unit, lock, bstr (unit, name), &err);
1864:
1.1.1.11 root 1865: if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) {
1.1.1.3 root 1866: /* Whatever it is, we can't handle it. */
1867: PUT_PCK_RES1 (packet, DOS_FALSE);
1868: PUT_PCK_RES2 (packet, err);
1869: return;
1870: }
1871: if (err == 0) {
1872: /* Object exists. */
1873: if (aino->dir) {
1874: PUT_PCK_RES1 (packet, DOS_FALSE);
1875: PUT_PCK_RES2 (packet, ERROR_OBJECT_WRONG_TYPE);
1876: return;
1877: }
1878: if (aino->elock || (create == 2 && aino->shlock > 0)) {
1879: PUT_PCK_RES1 (packet, DOS_FALSE);
1880: PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE);
1881: return;
1882: }
1883: if (create == 2 && (aino->amigaos_mode & A_FIBF_DELETE) != 0) {
1884: PUT_PCK_RES1 (packet, DOS_FALSE);
1885: PUT_PCK_RES2 (packet, ERROR_DELETE_PROTECTED);
1886: return;
1887: }
1888: if (create != 2) {
1889: if ((((mode & aino->amigaos_mode) & A_FIBF_WRITE) != 0 || unit->ui.readonly)
1890: && fallback)
1891: {
1892: mode &= ~A_FIBF_WRITE;
1893: }
1894: /* Kick 1.3 doesn't check read and write access bits - maybe it would be
1895: * simpler just not to do that either. */
1896: if ((mode & A_FIBF_WRITE) != 0 && unit->ui.readonly) {
1897: PUT_PCK_RES1 (packet, DOS_FALSE);
1898: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1899: return;
1900: }
1901: if (((mode & aino->amigaos_mode) & A_FIBF_WRITE) != 0
1902: || mode == 0)
1903: {
1904: PUT_PCK_RES1 (packet, DOS_FALSE);
1905: PUT_PCK_RES2 (packet, ERROR_WRITE_PROTECTED);
1906: return;
1907: }
1908: if (((mode & aino->amigaos_mode) & A_FIBF_READ) != 0) {
1909: PUT_PCK_RES1 (packet, DOS_FALSE);
1910: PUT_PCK_RES2 (packet, ERROR_READ_PROTECTED);
1911: return;
1912: }
1913: }
1914: } else if (create == 0) {
1915: PUT_PCK_RES1 (packet, DOS_FALSE);
1916: PUT_PCK_RES2 (packet, err);
1.1 root 1917: return;
1.1.1.3 root 1918: } else {
1919: /* Object does not exist. aino points to containing directory. */
1.1.1.7 root 1920: aino = create_child_aino (unit, aino, my_strdup (bstr_cut (unit, name)), 0);
1.1.1.3 root 1921: if (aino == 0) {
1922: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.6 root 1923: PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */
1.1 root 1924: return;
1925: }
1.1.1.3 root 1926: aino_created = 1;
1.1 root 1927: }
1928:
1.1.1.3 root 1929: prepare_for_open (aino->nname);
1.1 root 1930:
1.1.1.3 root 1931: openmode = (((mode & A_FIBF_READ) == 0 ? O_WRONLY
1932: : (mode & A_FIBF_WRITE) == 0 ? O_RDONLY
1933: : O_RDWR)
1934: | (create ? O_CREAT : 0)
1935: | (create == 2 ? O_TRUNC : 0));
1936:
1937: fd = open (aino->nname, openmode | O_BINARY, 0777);
1938:
1939: if (fd < 0) {
1940: if (aino_created)
1941: delete_aino (unit, aino);
1942: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.7 root 1943: PUT_PCK_RES2 (packet, dos_errno ());
1.1 root 1944: return;
1945: }
1.1.1.3 root 1946: k = new_key (unit);
1947: k->fd = fd;
1948: k->aino = aino;
1.1 root 1949:
1.1.1.3 root 1950: put_long (fh+36, k->uniq);
1951: if (create == 2)
1952: aino->elock = 1;
1953: else
1954: aino->shlock++;
1955: de_recycle_aino (unit, aino);
1956: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 1957: }
1958:
1959: static void
1.1.1.6 root 1960: action_fh_from_lock (Unit *unit, dpacket packet)
1961: {
1962: uaecptr fh = GET_PCK_ARG1 (packet) << 2;
1963: uaecptr lock = GET_PCK_ARG2 (packet) << 2;
1.1.1.7 root 1964: a_inode *aino;
1.1.1.6 root 1965: Key *k;
1966: int fd;
1967: mode_t openmode;
1968: int mode;
1969:
1970: TRACE(("ACTION_FH_FROM_LOCK(0x%lx,0x%lx)\n",fh,lock));
1971: DUMPLOCK(unit,lock);
1972:
1973: if (!lock) {
1.1.1.7 root 1974: PUT_PCK_RES1 (packet, DOS_FALSE);
1975: PUT_PCK_RES2 (packet, 0);
1976: return;
1.1.1.6 root 1977: }
1978:
1979: aino = lookup_aino (unit, get_long (lock + 4));
1980: if (aino == 0)
1.1.1.7 root 1981: aino = &unit->rootnode;
1.1.1.6 root 1982: mode = aino->amigaos_mode; /* Use same mode for opened filehandle as existing Lock() */
1983:
1984: prepare_for_open (aino->nname);
1.1.1.17 root 1985: TRACE ((" mode is %d\n", mode));
1986: openmode = (((mode & A_FIBF_READ) ? O_WRONLY
1987: : (mode & A_FIBF_WRITE) ? O_RDONLY
1.1.1.6 root 1988: : O_RDWR));
1989:
1.1.1.8 root 1990: /* the files on CD really can have the write-bit set. */
1991: if (unit->ui.readonly)
1992: openmode = O_RDONLY;
1993:
1.1.1.6 root 1994: fd = open (aino->nname, openmode | O_BINARY, 0777);
1995:
1996: if (fd < 0) {
1997: PUT_PCK_RES1 (packet, DOS_FALSE);
1998: PUT_PCK_RES2 (packet, dos_errno());
1999: return;
2000: }
2001: k = new_key (unit);
2002: k->fd = fd;
2003: k->aino = aino;
2004:
2005: put_long (fh+36, k->uniq);
2006: /* I don't think I need to play with shlock count here, because I'm
2007: opening from an existing lock ??? */
2008:
2009: /* Is this right? I don't completely understand how this works. Do I
2010: also need to free_lock() my lock, since nobody else is going to? */
2011: de_recycle_aino (unit, aino);
2012: PUT_PCK_RES1 (packet, DOS_TRUE);
2013: /* PUT_PCK_RES2 (packet, k->uniq); - this shouldn't be necessary, try without it */
2014: }
2015:
2016: static void
1.1.1.4 root 2017: action_find_input (Unit *unit, dpacket packet)
1.1 root 2018: {
1.1.1.3 root 2019: do_find(unit, packet, A_FIBF_READ|A_FIBF_WRITE, 0, 1);
1.1 root 2020: }
2021:
2022: static void
1.1.1.4 root 2023: action_find_output (Unit *unit, dpacket packet)
1.1 root 2024: {
1.1.1.3 root 2025: if (unit->ui.readonly) {
2026: PUT_PCK_RES1 (packet, DOS_FALSE);
2027: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2028: return;
2029: }
1.1.1.3 root 2030: do_find(unit, packet, A_FIBF_READ|A_FIBF_WRITE, 2, 0);
1.1 root 2031: }
2032:
2033: static void
1.1.1.4 root 2034: action_find_write (Unit *unit, dpacket packet)
1.1 root 2035: {
1.1.1.3 root 2036: if (unit->ui.readonly) {
2037: PUT_PCK_RES1 (packet, DOS_FALSE);
2038: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2039: return;
2040: }
1.1.1.3 root 2041: do_find(unit, packet, A_FIBF_READ|A_FIBF_WRITE, 1, 0);
1.1 root 2042: }
2043:
2044: static void
1.1.1.4 root 2045: action_end (Unit *unit, dpacket packet)
1.1 root 2046: {
2047: Key *k;
1.1.1.4 root 2048: TRACE(("ACTION_END(0x%lx)\n", GET_PCK_ARG1 (packet)));
1.1 root 2049:
1.1.1.3 root 2050: k = lookup_key (unit, GET_PCK_ARG1 (packet));
2051: if (k != 0) {
2052: if (k->aino->elock)
2053: k->aino->elock = 0;
2054: else
2055: k->aino->shlock--;
2056: recycle_aino (unit, k->aino);
2057: free_key (unit, k);
2058: }
2059: PUT_PCK_RES1 (packet, DOS_TRUE);
2060: PUT_PCK_RES2 (packet, 0);
1.1 root 2061: }
2062:
2063: static void
1.1.1.4 root 2064: action_read (Unit *unit, dpacket packet)
1.1 root 2065: {
1.1.1.3 root 2066: Key *k = lookup_key (unit, GET_PCK_ARG1 (packet));
2067: uaecptr addr = GET_PCK_ARG2 (packet);
2068: long size = (uae_s32)GET_PCK_ARG3 (packet);
1.1 root 2069: int actual;
2070:
1.1.1.3 root 2071: if (k == 0) {
2072: PUT_PCK_RES1 (packet, DOS_FALSE);
2073: /* PUT_PCK_RES2 (packet, EINVAL); */
2074: return;
2075: }
1.1.1.4 root 2076: TRACE(("ACTION_READ(%s,0x%lx,%ld)\n",k->aino->nname,addr,size));
1.1 root 2077: #ifdef RELY_ON_LOADSEG_DETECTION
1.1.1.3 root 2078: /* HACK HACK HACK HACK
1.1 root 2079: * Try to detect a LoadSeg() */
2080: if (k->file_pos == 0 && size >= 4) {
2081: unsigned char buf[4];
2082: off_t currpos = lseek(k->fd, 0, SEEK_CUR);
2083: read(k->fd, buf, 4);
2084: lseek(k->fd, currpos, SEEK_SET);
2085: if (buf[0] == 0 && buf[1] == 0 && buf[2] == 3 && buf[3] == 0xF3)
2086: possible_loadseg();
2087: }
2088: #endif
2089: if (valid_address (addr, size)) {
1.1.1.3 root 2090: uae_u8 *realpt;
1.1 root 2091: realpt = get_real_address (addr);
2092: actual = read(k->fd, realpt, size);
2093:
1.1.1.2 root 2094: if (actual == 0) {
1.1.1.3 root 2095: PUT_PCK_RES1 (packet, 0);
2096: PUT_PCK_RES2 (packet, 0);
1.1.1.2 root 2097: } else if (actual < 0) {
1.1.1.3 root 2098: PUT_PCK_RES1 (packet, 0);
2099: PUT_PCK_RES2 (packet, dos_errno());
1.1 root 2100: } else {
1.1.1.3 root 2101: PUT_PCK_RES1 (packet, actual);
1.1 root 2102: k->file_pos += actual;
2103: }
2104: } else {
2105: char *buf;
1.1.1.4 root 2106: write_log ("unixfs warning: Bad pointer passed for read: %08x\n", addr);
1.1 root 2107: /* ugh this is inefficient but easy */
2108: buf = (char *)malloc(size);
1.1.1.4 root 2109: if (!buf) {
1.1.1.3 root 2110: PUT_PCK_RES1 (packet, -1);
2111: PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE);
1.1 root 2112: return;
2113: }
2114: actual = read(k->fd, buf, size);
2115:
1.1.1.2 root 2116: if (actual < 0) {
1.1.1.3 root 2117: PUT_PCK_RES1 (packet, 0);
2118: PUT_PCK_RES2 (packet, dos_errno());
1.1 root 2119: } else {
2120: int i;
1.1.1.3 root 2121: PUT_PCK_RES1 (packet, actual);
1.1.1.4 root 2122: for (i = 0; i < actual; i++)
1.1 root 2123: put_byte(addr + i, buf[i]);
2124: k->file_pos += actual;
2125: }
1.1.1.4 root 2126: free (buf);
1.1 root 2127: }
2128: }
2129:
2130: static void
1.1.1.4 root 2131: action_write (Unit *unit, dpacket packet)
1.1 root 2132: {
1.1.1.3 root 2133: Key *k = lookup_key (unit, GET_PCK_ARG1 (packet));
2134: uaecptr addr = GET_PCK_ARG2 (packet);
2135: long size = GET_PCK_ARG3 (packet);
1.1 root 2136: char *buf;
2137: int i;
2138:
1.1.1.3 root 2139: if (k == 0) {
2140: PUT_PCK_RES1 (packet, DOS_FALSE);
2141: /* PUT_PCK_RES2 (packet, EINVAL); */
2142: return;
2143: }
1.1 root 2144:
1.1.1.4 root 2145: TRACE(("ACTION_WRITE(%s,0x%lx,%ld)\n",k->aino->nname,addr,size));
1.1.1.3 root 2146:
2147: if (unit->ui.readonly) {
2148: PUT_PCK_RES1 (packet, DOS_FALSE);
2149: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2150: return;
2151: }
2152:
2153: /* ugh this is inefficient but easy */
2154: buf = (char *)malloc(size);
1.1.1.3 root 2155: if (!buf) {
2156: PUT_PCK_RES1 (packet, -1);
2157: PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE);
1.1 root 2158: return;
2159: }
2160:
1.1.1.3 root 2161: for (i = 0; i < size; i++)
1.1 root 2162: buf[i] = get_byte(addr + i);
2163:
1.1.1.3 root 2164: PUT_PCK_RES1 (packet, write(k->fd, buf, size));
2165: if (GET_PCK_RES1 (packet) != size)
2166: PUT_PCK_RES2 (packet, dos_errno ());
2167: if (GET_PCK_RES1 (packet) >= 0)
2168: k->file_pos += GET_PCK_RES1 (packet);
1.1 root 2169:
1.1.1.4 root 2170: free (buf);
1.1 root 2171: }
2172:
2173: static void
1.1.1.4 root 2174: action_seek (Unit *unit, dpacket packet)
1.1 root 2175: {
1.1.1.4 root 2176: Key *k = lookup_key (unit, GET_PCK_ARG1 (packet));
1.1.1.3 root 2177: long pos = (uae_s32)GET_PCK_ARG2 (packet);
2178: long mode = (uae_s32)GET_PCK_ARG3 (packet);
1.1 root 2179: off_t res;
2180: long old;
2181: int whence = SEEK_CUR;
2182:
1.1.1.3 root 2183: if (k == 0) {
2184: PUT_PCK_RES1 (packet, -1);
2185: PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK);
2186: return;
2187: }
1.1 root 2188:
1.1.1.3 root 2189: if (mode > 0) whence = SEEK_END;
2190: if (mode < 0) whence = SEEK_SET;
1.1 root 2191:
1.1.1.4 root 2192: TRACE(("ACTION_SEEK(%s,%d,%d)\n", k->aino->nname, pos, mode));
1.1.1.3 root 2193:
2194: old = lseek (k->fd, 0, SEEK_CUR);
1.1.1.17 root 2195: {
2196: uae_s32 temppos;
2197: long filesize = lseek (k->fd, 0, SEEK_END);
2198: lseek (k->fd, old, SEEK_SET);
2199:
2200: if (whence == SEEK_CUR) temppos = old + pos;
2201: if (whence == SEEK_SET) temppos = pos;
2202: if (whence == SEEK_END) temppos = filesize + pos;
2203: if (filesize < temppos) {
2204: res = -1;
2205: PUT_PCK_RES1 (packet,res);
2206: PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR);
2207: return;
2208: }
2209: }
2210:
1.1.1.3 root 2211: res = lseek (k->fd, pos, whence);
2212:
2213: if (-1 == res) {
2214: PUT_PCK_RES1 (packet, res);
2215: PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR);
2216: } else
2217: PUT_PCK_RES1 (packet, old);
1.1 root 2218: k->file_pos = res;
2219: }
2220:
2221: static void
1.1.1.4 root 2222: action_set_protect (Unit *unit, dpacket packet)
1.1 root 2223: {
1.1.1.3 root 2224: uaecptr lock = GET_PCK_ARG2 (packet) << 2;
2225: uaecptr name = GET_PCK_ARG3 (packet) << 2;
2226: uae_u32 mask = GET_PCK_ARG4 (packet);
1.1.1.7 root 2227: a_inode *a;
1.1.1.3 root 2228: uae_u32 err;
1.1 root 2229:
1.1.1.4 root 2230: TRACE(("ACTION_SET_PROTECT(0x%lx,\"%s\",0x%lx)\n", lock, bstr (unit, name), mask));
1.1 root 2231:
1.1.1.3 root 2232: if (unit->ui.readonly) {
2233: PUT_PCK_RES1 (packet, DOS_FALSE);
2234: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2235: return;
2236: }
2237:
1.1.1.3 root 2238: a = find_aino (unit, lock, bstr (unit, name), &err);
2239: if (err != 0) {
2240: PUT_PCK_RES1 (packet, DOS_FALSE);
2241: PUT_PCK_RES2 (packet, err);
1.1 root 2242: return;
2243: }
2244:
1.1.1.7 root 2245: err = fsdb_set_file_attrs (a, mask);
1.1.1.3 root 2246: if (err != 0) {
2247: PUT_PCK_RES1 (packet, DOS_FALSE);
2248: PUT_PCK_RES2 (packet, err);
2249: } else {
2250: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1.1.2 root 2251: }
1.1.1.3 root 2252: }
1.1 root 2253:
1.1.1.7 root 2254: static void action_set_comment (Unit * unit, dpacket packet)
2255: {
2256: uaecptr lock = GET_PCK_ARG2 (packet) << 2;
2257: uaecptr name = GET_PCK_ARG3 (packet) << 2;
2258: uaecptr comment = GET_PCK_ARG4 (packet) << 2;
2259: char *commented;
2260: a_inode *a;
2261: uae_u32 err;
2262: long res1, res2;
2263:
2264: if (unit->ui.readonly) {
2265: PUT_PCK_RES1 (packet, DOS_FALSE);
2266: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
2267: return;
2268: }
2269:
2270: commented = bstr (unit, comment);
2271: commented = strlen (commented) > 0 ? my_strdup (commented) : 0;
2272: TRACE (("ACTION_SET_COMMENT(0x%lx,\"%s\")\n", lock, commented));
2273:
2274: a = find_aino (unit, lock, bstr (unit, name), &err);
2275: if (err != 0) {
2276: PUT_PCK_RES1 (packet, DOS_FALSE);
2277: PUT_PCK_RES2 (packet, err);
2278:
2279: maybe_free_and_out:
2280: if (commented)
2281: free (commented);
2282: return;
2283: }
2284: PUT_PCK_RES1 (packet, DOS_TRUE);
2285: PUT_PCK_RES2 (packet, 0);
2286: if (a->comment == 0 && commented == 0)
2287: goto maybe_free_and_out;
2288: if (a->comment != 0 && commented != 0 && strcmp (a->comment, commented) == 0)
2289: goto maybe_free_and_out;
2290: if (a->comment)
2291: free (a->comment);
2292: a->comment = commented;
2293: a->dirty = 1;
2294: }
2295:
1.1.1.3 root 2296: static void
1.1.1.4 root 2297: action_same_lock (Unit *unit, dpacket packet)
1.1.1.3 root 2298: {
2299: uaecptr lock1 = GET_PCK_ARG1 (packet) << 2;
2300: uaecptr lock2 = GET_PCK_ARG2 (packet) << 2;
1.1 root 2301:
1.1.1.4 root 2302: TRACE(("ACTION_SAME_LOCK(0x%lx,0x%lx)\n",lock1,lock2));
1.1.1.3 root 2303: DUMPLOCK(unit, lock1); DUMPLOCK(unit, lock2);
1.1 root 2304:
1.1.1.3 root 2305: if (!lock1 || !lock2) {
2306: PUT_PCK_RES1 (packet, lock1 == lock2 ? DOS_TRUE : DOS_FALSE);
1.1 root 2307: } else {
1.1.1.3 root 2308: PUT_PCK_RES1 (packet, get_long (lock1 + 4) == get_long (lock2 + 4) ? DOS_TRUE : DOS_FALSE);
1.1 root 2309: }
2310: }
2311:
2312: static void
1.1.1.6 root 2313: action_change_mode (Unit *unit, dpacket packet)
1.1 root 2314: {
1.1.1.6 root 2315: #define CHANGE_LOCK 0
2316: #define CHANGE_FH 1
2317: /* will be CHANGE_FH or CHANGE_LOCK value */
2318: long type = GET_PCK_ARG1 (packet);
2319: /* either a file-handle or lock */
2320: uaecptr object = GET_PCK_ARG2 (packet) << 2;
2321: /* will be EXCLUSIVE_LOCK/SHARED_LOCK if CHANGE_LOCK,
2322: * or MODE_OLDFILE/MODE_NEWFILE/MODE_READWRITE if CHANGE_FH */
2323: long mode = GET_PCK_ARG3 (packet);
1.1.1.8 root 2324: unsigned long uniq;
1.1.1.7 root 2325: a_inode *a = NULL, *olda = NULL;
1.1.1.6 root 2326: uae_u32 err = 0;
2327: TRACE(("ACTION_CHANGE_MODE(0x%lx,%d,%d)\n",object,type,mode));
1.1.1.13 root 2328:
1.1.1.6 root 2329: if (! object
2330: || (type != CHANGE_FH && type != CHANGE_LOCK))
2331: {
1.1.1.7 root 2332: PUT_PCK_RES1 (packet, DOS_FALSE);
2333: PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK);
2334: return;
1.1.1.6 root 2335: }
1.1 root 2336:
1.1.1.6 root 2337: /* @@@ Brian: shouldn't this be good enough to support
2338: CHANGE_FH? */
2339: if (type == CHANGE_FH)
2340: mode = (mode == 1006 ? -1 : -2);
1.1.1.8 root 2341:
2342: if (type == CHANGE_LOCK)
1.1.1.13 root 2343: uniq = get_long (object + 4);
1.1.1.8 root 2344: else {
2345: Key *k = lookup_key (unit, object);
2346: if (!k) {
2347: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.11 root 2348: PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND);
1.1.1.8 root 2349: return;
2350: }
1.1.1.13 root 2351: uniq = k->aino->uniq;
1.1.1.8 root 2352: }
2353: a = lookup_aino (unit, uniq);
2354:
1.1.1.6 root 2355: if (! a)
2356: err = ERROR_INVALID_LOCK;
2357: else {
2358: if (mode == -1) {
2359: if (a->shlock > 1)
2360: err = ERROR_OBJECT_IN_USE;
2361: else {
2362: a->shlock = 0;
2363: a->elock = 1;
2364: }
2365: } else { /* Must be SHARED_LOCK == -2 */
2366: a->elock = 0;
2367: a->shlock++;
2368: }
1.1.1.13 root 2369: }
1.1.1.6 root 2370:
2371: if (err) {
1.1.1.7 root 2372: PUT_PCK_RES1 (packet, DOS_FALSE);
2373: PUT_PCK_RES2 (packet, err);
2374: return;
1.1.1.6 root 2375: } else {
1.1.1.7 root 2376: de_recycle_aino (unit, a);
2377: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1.1.3 root 2378: }
1.1.1.6 root 2379: }
1.1.1.3 root 2380:
1.1.1.6 root 2381: static void
1.1.1.8 root 2382: action_parent_common (Unit *unit, dpacket packet, unsigned long uniq)
1.1.1.6 root 2383: {
1.1.1.8 root 2384: a_inode *olda = lookup_aino (unit, uniq);
1.1.1.3 root 2385: if (olda == 0) {
2386: PUT_PCK_RES1 (packet, DOS_FALSE);
2387: PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK);
2388: return;
2389: }
2390:
2391: if (olda->parent == 0) {
2392: PUT_PCK_RES1 (packet, 0);
2393: PUT_PCK_RES2 (packet, 0);
2394: return;
1.1 root 2395: }
1.1.1.3 root 2396: if (olda->parent->elock) {
2397: PUT_PCK_RES1 (packet, DOS_FALSE);
2398: PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE);
2399: return;
2400: }
2401: olda->parent->shlock++;
2402: de_recycle_aino (unit, olda->parent);
2403: PUT_PCK_RES1 (packet, make_lock (unit, olda->parent->uniq, -2) >> 2);
1.1 root 2404: }
2405:
2406: static void
1.1.1.6 root 2407: action_parent_fh (Unit *unit, dpacket packet)
2408: {
1.1.1.8 root 2409: Key *k = lookup_key (unit, GET_PCK_ARG1 (packet));
2410: if (!k) {
1.1.1.7 root 2411: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.11 root 2412: PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND);
1.1.1.7 root 2413: return;
1.1.1.6 root 2414: }
1.1.1.8 root 2415: action_parent_common (unit, packet, k->aino->uniq);
1.1.1.6 root 2416: }
2417:
2418: static void
2419: action_parent (Unit *unit, dpacket packet)
2420: {
2421: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
2422:
2423: TRACE(("ACTION_PARENT(0x%lx)\n",lock));
2424:
2425: if (!lock) {
2426: PUT_PCK_RES1 (packet, 0);
2427: PUT_PCK_RES2 (packet, 0);
2428: return;
2429: }
2430: action_parent_common (unit, packet, get_long (lock + 4));
2431: }
2432:
2433: static void
1.1.1.4 root 2434: action_create_dir (Unit *unit, dpacket packet)
1.1 root 2435: {
1.1.1.3 root 2436: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
2437: uaecptr name = GET_PCK_ARG2 (packet) << 2;
1.1.1.7 root 2438: a_inode *aino;
1.1.1.3 root 2439: uae_u32 err;
1.1 root 2440:
1.1.1.4 root 2441: TRACE(("ACTION_CREATE_DIR(0x%lx,\"%s\")\n", lock, bstr (unit, name)));
1.1 root 2442:
1.1.1.3 root 2443: if (unit->ui.readonly) {
2444: PUT_PCK_RES1 (packet, DOS_FALSE);
2445: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2446: return;
2447: }
2448:
1.1.1.3 root 2449: aino = find_aino (unit, lock, bstr (unit, name), &err);
1.1.1.11 root 2450: if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) {
1.1.1.3 root 2451: PUT_PCK_RES1 (packet, DOS_FALSE);
2452: PUT_PCK_RES2 (packet, err);
1.1 root 2453: return;
2454: }
1.1.1.3 root 2455: if (err == 0) {
2456: /* Object exists. */
2457: PUT_PCK_RES1 (packet, DOS_FALSE);
2458: PUT_PCK_RES2 (packet, ERROR_OBJECT_EXISTS);
2459: return;
1.1 root 2460: }
1.1.1.3 root 2461: /* Object does not exist. aino points to containing directory. */
1.1.1.7 root 2462: aino = create_child_aino (unit, aino, my_strdup (bstr_cut (unit, name)), 1);
1.1.1.3 root 2463: if (aino == 0) {
2464: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.6 root 2465: PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */
1.1.1.3 root 2466: return;
2467: }
2468:
2469: if (mkdir (aino->nname, 0777) == -1) {
2470: PUT_PCK_RES1 (packet, DOS_FALSE);
2471: PUT_PCK_RES2 (packet, dos_errno());
2472: return;
2473: }
2474: aino->shlock = 1;
2475: de_recycle_aino (unit, aino);
2476: PUT_PCK_RES1 (packet, make_lock (unit, aino->uniq, -2) >> 2);
1.1 root 2477: }
2478:
2479: static void
1.1.1.4 root 2480: action_examine_fh (Unit *unit, dpacket packet)
1.1 root 2481: {
1.1.1.3 root 2482: Key *k;
1.1.1.7 root 2483: a_inode *aino = 0;
1.1.1.3 root 2484: uaecptr info = GET_PCK_ARG2 (packet) << 2;
1.1 root 2485:
1.1.1.6 root 2486: TRACE(("ACTION_EXAMINE_FH(0x%lx,0x%lx)\n",
2487: GET_PCK_ARG1 (packet), GET_PCK_ARG2 (packet) ));
1.1 root 2488:
1.1.1.3 root 2489: k = lookup_key (unit, GET_PCK_ARG1 (packet));
2490: if (k != 0)
2491: aino = k->aino;
2492: if (aino == 0)
2493: aino = &unit->rootnode;
2494:
2495: get_fileinfo (unit, packet, info, aino);
2496: if (aino->dir)
1.1.1.6 root 2497: put_long (info, 0xFFFFFFFF);
1.1.1.3 root 2498: else
1.1.1.6 root 2499: put_long (info, 0);
1.1.1.3 root 2500: }
2501:
2502: /* For a nice example of just how contradictory documentation can be, see the
2503: * Autodoc for DOS:SetFileSize and the Packets.txt description of this packet...
2504: * This implementation tries to mimic the behaviour of the Kick 3.1 ramdisk
2505: * (which seems to match the Autodoc description). */
2506: static void
1.1.1.4 root 2507: action_set_file_size (Unit *unit, dpacket packet)
1.1.1.3 root 2508: {
2509: Key *k, *k1;
2510: off_t offset = GET_PCK_ARG2 (packet);
2511: long mode = (uae_s32)GET_PCK_ARG3 (packet);
2512: int whence = SEEK_CUR;
1.1.1.13 root 2513:
1.1.1.3 root 2514: if (mode > 0) whence = SEEK_END;
2515: if (mode < 0) whence = SEEK_SET;
1.1 root 2516:
1.1.1.4 root 2517: TRACE(("ACTION_SET_FILE_SIZE(0x%lx, %d, 0x%x)\n", GET_PCK_ARG1 (packet), offset, mode));
1.1 root 2518:
1.1.1.3 root 2519: k = lookup_key (unit, GET_PCK_ARG1 (packet));
2520: if (k == 0) {
2521: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1.1.11 root 2522: PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND);
1.1 root 2523: return;
2524: }
1.1.1.3 root 2525:
2526: /* If any open files have file pointers beyond this size, truncate only
2527: * so far that these pointers do not become invalid. */
2528: for (k1 = unit->keys; k1; k1 = k1->next) {
2529: if (k != k1 && k->aino == k1->aino) {
2530: if (k1->file_pos > offset)
2531: offset = k1->file_pos;
2532: }
2533: }
2534:
2535: /* Write one then truncate: that should give the right size in all cases. */
2536: offset = lseek (k->fd, offset, whence);
2537: write (k->fd, /* whatever */(char *)&k1, 1);
2538: if (k->file_pos > offset)
2539: k->file_pos = offset;
2540: lseek (k->fd, k->file_pos, SEEK_SET);
2541:
1.1.1.6 root 2542: /* Brian: no bug here; the file _must_ be one byte too large after writing
2543: The write is supposed to guarantee that the file can't be smaller than
2544: the requested size, the truncate guarantees that it can't be larger.
2545: If we were to write one byte earlier we'd clobber file data. */
2546: if (truncate (k->aino->nname, offset) == -1) {
1.1.1.3 root 2547: PUT_PCK_RES1 (packet, DOS_FALSE);
2548: PUT_PCK_RES2 (packet, dos_errno ());
1.1 root 2549: return;
2550: }
1.1.1.3 root 2551:
2552: PUT_PCK_RES1 (packet, offset);
2553: PUT_PCK_RES2 (packet, 0);
1.1 root 2554: }
2555:
2556: static void
1.1.1.4 root 2557: action_delete_object (Unit *unit, dpacket packet)
1.1 root 2558: {
1.1.1.3 root 2559: uaecptr lock = GET_PCK_ARG1 (packet) << 2;
2560: uaecptr name = GET_PCK_ARG2 (packet) << 2;
1.1.1.7 root 2561: a_inode *a;
1.1.1.3 root 2562: uae_u32 err;
1.1 root 2563:
1.1.1.4 root 2564: TRACE(("ACTION_DELETE_OBJECT(0x%lx,\"%s\")\n", lock, bstr (unit, name)));
1.1 root 2565:
1.1.1.3 root 2566: if (unit->ui.readonly) {
2567: PUT_PCK_RES1 (packet, DOS_FALSE);
2568: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2569: return;
2570: }
2571:
1.1.1.3 root 2572: a = find_aino (unit, lock, bstr (unit, name), &err);
1.1 root 2573:
1.1.1.3 root 2574: if (err != 0) {
2575: PUT_PCK_RES1 (packet, DOS_FALSE);
2576: PUT_PCK_RES2 (packet, err);
1.1 root 2577: return;
2578: }
1.1.1.7 root 2579: if (a->amigaos_mode & A_FIBF_DELETE) {
2580: PUT_PCK_RES1 (packet, DOS_FALSE);
2581: PUT_PCK_RES2 (packet, ERROR_DELETE_PROTECTED);
2582: return;
2583: }
1.1.1.3 root 2584: if (a->shlock > 0 || a->elock) {
2585: PUT_PCK_RES1 (packet, DOS_FALSE);
2586: PUT_PCK_RES2 (packet, ERROR_OBJECT_IN_USE);
1.1 root 2587: return;
2588: }
1.1.1.3 root 2589: if (a->dir) {
1.1.1.11 root 2590: /* This should take care of removing the fsdb if no files remain. */
2591: fsdb_dir_writeback (a);
1.1.1.3 root 2592: if (rmdir (a->nname) == -1) {
2593: PUT_PCK_RES1 (packet, DOS_FALSE);
2594: PUT_PCK_RES2 (packet, dos_errno());
1.1 root 2595: return;
2596: }
2597: } else {
1.1.1.3 root 2598: if (unlink (a->nname) == -1) {
2599: PUT_PCK_RES1 (packet, DOS_FALSE);
2600: PUT_PCK_RES2 (packet, dos_errno());
1.1 root 2601: return;
2602: }
2603: }
1.1.1.3 root 2604: if (a->child != 0) {
2605: write_log ("Serious error in action_delete_object.\n");
2606: } else {
2607: delete_aino (unit, a);
2608: }
2609: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 2610: }
2611:
2612: static void
1.1.1.4 root 2613: action_set_date (Unit *unit, dpacket packet)
1.1 root 2614: {
1.1.1.3 root 2615: uaecptr lock = GET_PCK_ARG2 (packet) << 2;
2616: uaecptr name = GET_PCK_ARG3 (packet) << 2;
2617: uaecptr date = GET_PCK_ARG4 (packet);
1.1.1.7 root 2618: a_inode *a;
1.1 root 2619: struct utimbuf ut;
1.1.1.3 root 2620: uae_u32 err;
1.1 root 2621:
1.1.1.4 root 2622: TRACE(("ACTION_SET_DATE(0x%lx,\"%s\")\n", lock, bstr (unit, name)));
1.1 root 2623:
1.1.1.4 root 2624: if (unit->ui.readonly) {
1.1.1.3 root 2625: PUT_PCK_RES1 (packet, DOS_FALSE);
2626: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2627: return;
2628: }
2629:
1.1.1.6 root 2630: ut.actime = ut.modtime = put_time(get_long (date), get_long (date + 4),
2631: get_long (date + 8));
1.1.1.3 root 2632: a = find_aino (unit, lock, bstr (unit, name), &err);
2633: if (err == 0 && utime (a->nname, &ut) == -1)
2634: err = dos_errno ();
2635: if (err != 0) {
2636: PUT_PCK_RES1 (packet, DOS_FALSE);
2637: PUT_PCK_RES2 (packet, err);
2638: } else
2639: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 2640: }
2641:
2642: static void
1.1.1.4 root 2643: action_rename_object (Unit *unit, dpacket packet)
1.1 root 2644: {
1.1.1.3 root 2645: uaecptr lock1 = GET_PCK_ARG1 (packet) << 2;
2646: uaecptr name1 = GET_PCK_ARG2 (packet) << 2;
2647: uaecptr lock2 = GET_PCK_ARG3 (packet) << 2;
2648: uaecptr name2 = GET_PCK_ARG4 (packet) << 2;
1.1.1.7 root 2649: a_inode *a1, *a2;
1.1.1.3 root 2650: uae_u32 err1, err2;
1.1 root 2651:
1.1.1.4 root 2652: TRACE(("ACTION_RENAME_OBJECT(0x%lx,\"%s\",", lock1, bstr (unit, name1)));
2653: TRACE(("0x%lx,\"%s\")\n", lock2, bstr (unit, name2)));
1.1 root 2654:
1.1.1.4 root 2655: if (unit->ui.readonly) {
1.1.1.3 root 2656: PUT_PCK_RES1 (packet, DOS_FALSE);
2657: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2658: return;
2659: }
2660:
1.1.1.3 root 2661: a1 = find_aino (unit, lock1, bstr (unit, name1), &err1);
2662: if (err1 != 0) {
2663: PUT_PCK_RES1 (packet, DOS_FALSE);
2664: PUT_PCK_RES2 (packet, err1);
2665: return;
2666: }
1.1.1.7 root 2667: /* See whether the other name already exists in the filesystem. */
1.1.1.3 root 2668: a2 = find_aino (unit, lock2, bstr (unit, name2), &err2);
1.1.1.7 root 2669: if (a2 == a1) {
2670: /* Renaming to the same name, but possibly different case. */
2671: if (strcmp (a1->aname, bstr_cut (unit, name2)) == 0) {
2672: /* Exact match -> do nothing. */
2673: PUT_PCK_RES1 (packet, DOS_TRUE);
2674: return;
2675: }
2676: a2 = a2->parent;
1.1.1.11 root 2677: } else if (a2 == 0 || err2 != ERROR_OBJECT_NOT_AROUND) {
1.1.1.3 root 2678: PUT_PCK_RES1 (packet, DOS_FALSE);
2679: PUT_PCK_RES2 (packet, err2 == 0 ? ERROR_OBJECT_EXISTS : err2);
1.1 root 2680: return;
2681: }
1.1.1.7 root 2682:
2683: a2 = create_child_aino (unit, a2, bstr_cut (unit, name2), a1->dir);
1.1.1.3 root 2684: if (a2 == 0) {
2685: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.6 root 2686: PUT_PCK_RES2 (packet, ERROR_DISK_IS_FULL); /* best we can do */
1.1 root 2687: return;
2688: }
2689:
1.1.1.3 root 2690: /* @@@ what should we do if there are locks on a1? */
1.1.1.5 root 2691: if (-1 == rename (a1->nname, a2->nname)) {
1.1.1.3 root 2692: PUT_PCK_RES1 (packet, DOS_FALSE);
1.1.1.5 root 2693: PUT_PCK_RES2 (packet, dos_errno ());
1.1 root 2694: return;
2695: }
1.1.1.7 root 2696: a2->comment = a1->comment;
2697: a1->comment = 0;
2698: a2->amigaos_mode = a1->amigaos_mode;
1.1.1.14 root 2699: a2->uniq = a1->uniq;
2700: move_exkeys (unit, a1, a2);
1.1.1.3 root 2701: move_aino_children (unit, a1, a2);
2702: delete_aino (unit, a1);
2703: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 2704: }
2705:
2706: static void
1.1.1.4 root 2707: action_current_volume (Unit *unit, dpacket packet)
1.1 root 2708: {
1.1.1.3 root 2709: PUT_PCK_RES1 (packet, unit->volume >> 2);
1.1 root 2710: }
2711:
2712: static void
1.1.1.4 root 2713: action_rename_disk (Unit *unit, dpacket packet)
1.1 root 2714: {
1.1.1.3 root 2715: uaecptr name = GET_PCK_ARG1 (packet) << 2;
1.1 root 2716: int i;
2717: int namelen;
2718:
1.1.1.4 root 2719: TRACE(("ACTION_RENAME_DISK(\"%s\")\n", bstr (unit, name)));
1.1 root 2720:
1.1.1.4 root 2721: if (unit->ui.readonly) {
1.1.1.3 root 2722: PUT_PCK_RES1 (packet, DOS_FALSE);
2723: PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED);
1.1 root 2724: return;
2725: }
2726:
2727: /* get volume name */
1.1.1.3 root 2728: namelen = get_byte (name); name++;
2729: free (unit->ui.volname);
2730: unit->ui.volname = (char *) xmalloc (namelen + 1);
1.1.1.4 root 2731: for (i = 0; i < namelen; i++, name++)
1.1.1.3 root 2732: unit->ui.volname[i] = get_byte (name);
1.1 root 2733: unit->ui.volname[i] = 0;
2734:
1.1.1.3 root 2735: put_byte (unit->volume + 44, namelen);
1.1.1.4 root 2736: for (i = 0; i < namelen; i++)
1.1.1.3 root 2737: put_byte (unit->volume + 45 + i, unit->ui.volname[i]);
1.1 root 2738:
1.1.1.3 root 2739: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 2740: }
2741:
2742: static void
1.1.1.4 root 2743: action_is_filesystem (Unit *unit, dpacket packet)
1.1 root 2744: {
1.1.1.3 root 2745: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 2746: }
2747:
2748: static void
1.1.1.4 root 2749: action_flush (Unit *unit, dpacket packet)
1.1 root 2750: {
2751: /* sync(); */ /* pretty drastic, eh */
1.1.1.3 root 2752: PUT_PCK_RES1 (packet, DOS_TRUE);
1.1 root 2753: }
2754:
1.1.1.3 root 2755: /* We don't want multiple interrupts to be active at the same time. I don't
2756: * know whether AmigaOS takes care of that, but this does. */
2757: static uae_sem_t singlethread_int_sem;
2758:
2759: static uae_u32 exter_int_helper (void)
2760: {
1.1.1.4 root 2761: UnitInfo *uip = current_mountinfo->ui;
1.1.1.7 root 2762: uaecptr port;
1.1.1.3 root 2763: static int unit_no;
2764:
2765: switch (m68k_dreg (regs, 0)) {
2766: case 0:
2767: /* Determine whether a given EXTER interrupt is for us. */
2768: if (uae_int_requested) {
2769: if (uae_sem_trywait (&singlethread_int_sem) != 0)
2770: /* Pretend it isn't for us. We might get it again later. */
2771: return 0;
2772: /* Clear the interrupt flag _before_ we do any processing.
2773: * That way, we can get too many interrupts, but never not
2774: * enough. */
2775: uae_int_requested = 0;
2776: unit_no = 0;
2777: return 1;
2778: }
1.1 root 2779: return 0;
1.1.1.3 root 2780: case 1:
2781: /* Release a message_lock. This is called as soon as the message is
2782: * received by the assembly code. We use the opportunity to check
2783: * whether we have some locks that we can give back to the assembler
2784: * code.
2785: * Note that this is called from the main loop, unlike the other cases
2786: * in this switch statement which are called from the interrupt handler.
2787: */
1.1.1.7 root 2788: #ifdef UAE_FILESYS_THREADS
1.1.1.3 root 2789: {
2790: Unit *unit = find_unit (m68k_areg (regs, 5));
2791: unit->cmds_complete = unit->cmds_acked;
2792: while (comm_pipe_has_data (unit->ui.back_pipe)) {
2793: uaecptr locks, lockend;
2794: locks = read_comm_pipe_int_blocking (unit->ui.back_pipe);
2795: lockend = locks;
2796: while (get_long (lockend) != 0)
2797: lockend = get_long (lockend);
2798: put_long (lockend, get_long (m68k_areg (regs, 3)));
2799: put_long (m68k_areg (regs, 3), locks);
2800: }
2801: }
1.1.1.7 root 2802: #else
2803: write_log ("exter_int_helper should not be called with arg 1!\n");
2804: #endif
1.1 root 2805: break;
1.1.1.3 root 2806: case 2:
1.1.1.7 root 2807: /* Find work that needs to be done:
2808: * return d0 = 0: none
2809: * d0 = 1: PutMsg(), port in a0, message in a1
2810: * d0 = 2: Signal(), task in a1, signal set in d1
2811: * d0 = 3: ReplyMsg(), message in a1 */
2812:
2813: #ifdef SUPPORT_THREADS
2814: /* First, check signals/messages */
2815: while (comm_pipe_has_data (&native2amiga_pending)) {
2816: switch (read_comm_pipe_int_blocking (&native2amiga_pending)) {
2817: case 0: /* Signal() */
2818: m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
2819: m68k_dreg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
2820: return 2;
2821:
2822: case 1: /* PutMsg() */
2823: m68k_areg (regs, 0) = read_comm_pipe_u32_blocking (&native2amiga_pending);
2824: m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
2825: return 1;
2826:
2827: case 2: /* ReplyMsg() */
2828: m68k_areg (regs, 1) = read_comm_pipe_u32_blocking (&native2amiga_pending);
2829: return 3;
2830:
2831: default:
2832: write_log ("exter_int_helper: unknown native action\n");
2833: break;
2834: }
2835: }
2836: #endif
2837:
1.1.1.3 root 2838: /* Find some unit that needs a message sent, and return its port,
2839: * or zero if all are done.
2840: * Take care not to dereference self for units that didn't have their
2841: * startup packet sent. */
2842: for (;;) {
1.1.1.4 root 2843: if (unit_no >= current_mountinfo->num_units)
1.1.1.3 root 2844: return 0;
1.1.1.7 root 2845:
1.1.1.4 root 2846: if (uip[unit_no].self != 0
2847: && uip[unit_no].self->cmds_acked == uip[unit_no].self->cmds_complete
2848: && uip[unit_no].self->cmds_acked != uip[unit_no].self->cmds_sent)
1.1.1.3 root 2849: break;
2850: unit_no++;
2851: }
1.1.1.4 root 2852: uip[unit_no].self->cmds_acked = uip[unit_no].self->cmds_sent;
1.1.1.7 root 2853: port = uip[unit_no].self->port;
2854: if (port) {
2855: m68k_areg (regs, 0) = port;
2856: m68k_areg (regs, 1) = find_unit (port)->dummy_message;
2857: unit_no++;
2858: return 1;
1.1.1.3 root 2859: }
1.1 root 2860: break;
1.1.1.3 root 2861: case 4:
2862: /* Exit the interrupt, and release the single-threading lock. */
2863: uae_sem_post (&singlethread_int_sem);
1.1 root 2864: break;
2865:
1.1.1.3 root 2866: default:
2867: write_log ("Shouldn't happen in exter_int_helper.\n");
1.1 root 2868: break;
1.1.1.3 root 2869: }
2870: return 0;
2871: }
1.1 root 2872:
1.1.1.3 root 2873: static int handle_packet (Unit *unit, dpacket pck)
2874: {
2875: uae_s32 type = GET_PCK_TYPE (pck);
2876: PUT_PCK_RES2 (pck, 0);
2877: switch (type) {
1.1.1.4 root 2878: case ACTION_LOCATE_OBJECT: action_lock (unit, pck); break;
2879: case ACTION_FREE_LOCK: action_free_lock (unit, pck); break;
2880: case ACTION_COPY_DIR: action_dup_lock (unit, pck); break;
2881: case ACTION_DISK_INFO: action_disk_info (unit, pck); break;
2882: case ACTION_INFO: action_info (unit, pck); break;
2883: case ACTION_EXAMINE_OBJECT: action_examine_object (unit, pck); break;
2884: case ACTION_EXAMINE_NEXT: action_examine_next (unit, pck); break;
2885: case ACTION_FIND_INPUT: action_find_input (unit, pck); break;
2886: case ACTION_FIND_WRITE: action_find_write (unit, pck); break;
2887: case ACTION_FIND_OUTPUT: action_find_output (unit, pck); break;
2888: case ACTION_END: action_end (unit, pck); break;
2889: case ACTION_READ: action_read (unit, pck); break;
2890: case ACTION_WRITE: action_write (unit, pck); break;
2891: case ACTION_SEEK: action_seek (unit, pck); break;
2892: case ACTION_SET_PROTECT: action_set_protect (unit, pck); break;
1.1.1.7 root 2893: case ACTION_SET_COMMENT: action_set_comment (unit, pck); break;
1.1.1.4 root 2894: case ACTION_SAME_LOCK: action_same_lock (unit, pck); break;
2895: case ACTION_PARENT: action_parent (unit, pck); break;
2896: case ACTION_CREATE_DIR: action_create_dir (unit, pck); break;
2897: case ACTION_DELETE_OBJECT: action_delete_object (unit, pck); break;
2898: case ACTION_RENAME_OBJECT: action_rename_object (unit, pck); break;
2899: case ACTION_SET_DATE: action_set_date (unit, pck); break;
2900: case ACTION_CURRENT_VOLUME: action_current_volume (unit, pck); break;
2901: case ACTION_RENAME_DISK: action_rename_disk (unit, pck); break;
2902: case ACTION_IS_FILESYSTEM: action_is_filesystem (unit, pck); break;
2903: case ACTION_FLUSH: action_flush (unit, pck); break;
1.1.1.3 root 2904:
2905: /* 2.0+ packet types */
1.1.1.4 root 2906: case ACTION_SET_FILE_SIZE: action_set_file_size (unit, pck); break;
2907: case ACTION_EXAMINE_FH: action_examine_fh (unit, pck); break;
1.1.1.6 root 2908: case ACTION_FH_FROM_LOCK: action_fh_from_lock (unit, pck); break;
2909: case ACTION_CHANGE_MODE: action_change_mode (unit, pck); break;
2910: case ACTION_PARENT_FH: action_parent_fh (unit, pck); break;
1.1.1.3 root 2911:
2912: /* unsupported packets */
2913: case ACTION_LOCK_RECORD:
2914: case ACTION_FREE_RECORD:
2915: case ACTION_COPY_DIR_FH:
2916: case ACTION_EXAMINE_ALL:
2917: case ACTION_MAKE_LINK:
2918: case ACTION_READ_LINK:
2919: case ACTION_FORMAT:
2920: case ACTION_ADD_NOTIFY:
2921: case ACTION_REMOVE_NOTIFY:
2922: default:
1.1.1.4 root 2923: TRACE(("*** UNSUPPORTED PACKET %ld\n", type));
1.1.1.3 root 2924: return 0;
2925: }
2926: return 1;
2927: }
1.1 root 2928:
1.1.1.3 root 2929: #ifdef UAE_FILESYS_THREADS
1.1.1.13 root 2930: static void *filesys_thread (void *unit_v)
1.1.1.3 root 2931: {
2932: UnitInfo *ui = (UnitInfo *)unit_v;
2933: for (;;) {
2934: uae_u8 *pck;
2935: uae_u8 *msg;
2936: uae_u32 morelocks;
2937: int i;
2938:
2939: pck = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe);
2940: msg = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe);
2941: morelocks = (uae_u32)read_comm_pipe_int_blocking (ui->unit_pipe);
2942:
1.1.1.4 root 2943: if (ui->reset_state == FS_GO_DOWN) {
1.1.1.3 root 2944: if (pck != 0)
2945: continue;
2946: /* Death message received. */
1.1.1.4 root 2947: uae_sem_post (&ui->reset_sync_sem);
2948: /* Die. */
2949: return 0;
1.1.1.3 root 2950: }
1.1 root 2951:
1.1.1.3 root 2952: put_long (get_long (morelocks), get_long (ui->self->locklist));
2953: put_long (ui->self->locklist, morelocks);
2954: if (! handle_packet (ui->self, pck)) {
2955: PUT_PCK_RES1 (pck, DOS_FALSE);
2956: PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN);
2957: }
2958: /* Mark the packet as processed for the list scan in the assembly code. */
2959: do_put_mem_long ((uae_u32 *)(msg + 4), -1);
2960: /* Acquire the message lock, so that we know we can safely send the
2961: * message. */
2962: ui->self->cmds_sent++;
2963: /* The message is sent by our interrupt handler, so make sure an interrupt
2964: * happens. */
2965: uae_int_requested = 1;
2966: /* Send back the locks. */
2967: if (get_long (ui->self->locklist) != 0)
1.1.1.7 root 2968: write_comm_pipe_int (ui->back_pipe, (int)(get_long (ui->self->locklist)), 0);
1.1.1.3 root 2969: put_long (ui->self->locklist, 0);
2970: }
2971: return 0;
2972: }
2973: #endif
1.1 root 2974:
1.1.1.3 root 2975: /* Talk about spaghetti code... */
1.1.1.4 root 2976: static uae_u32 filesys_handler (void)
1.1.1.3 root 2977: {
2978: Unit *unit = find_unit (m68k_areg (regs, 5));
2979: uaecptr packet_addr = m68k_dreg (regs, 3);
2980: uaecptr message_addr = m68k_areg (regs, 4);
2981: uae_u8 *pck;
2982: uae_u8 *msg;
2983: if (! valid_address (packet_addr, 36) || ! valid_address (message_addr, 14)) {
2984: write_log ("Bad address passed for packet.\n");
2985: goto error2;
2986: }
2987: pck = get_real_address (packet_addr);
2988: msg = get_real_address (message_addr);
2989:
1.1.1.4 root 2990: #if 0
1.1.1.3 root 2991: if (unit->reset_state == FS_GO_DOWN)
2992: /* You might as well queue it, if you live long enough */
2993: return 1;
1.1.1.4 root 2994: #endif
1.1.1.3 root 2995:
2996: do_put_mem_long ((uae_u32 *)(msg + 4), -1);
2997: if (!unit || !unit->volume) {
2998: write_log ("Filesystem was not initialized.\n");
2999: goto error;
3000: }
3001: #ifdef UAE_FILESYS_THREADS
3002: {
3003: /* Get two more locks and hand them over to the other thread. */
3004: uae_u32 morelocks;
3005: morelocks = get_long (m68k_areg (regs, 3));
3006: put_long (m68k_areg (regs, 3), get_long (get_long (morelocks)));
3007: put_long (get_long (morelocks), 0);
3008:
3009: /* The packet wasn't processed yet. */
3010: do_put_mem_long ((uae_u32 *)(msg + 4), 0);
3011: write_comm_pipe_pvoid (unit->ui.unit_pipe, (void *)pck, 0);
3012: write_comm_pipe_pvoid (unit->ui.unit_pipe, (void *)msg, 0);
3013: write_comm_pipe_int (unit->ui.unit_pipe, (int)morelocks, 1);
3014: /* Don't reply yet. */
3015: return 1;
3016: }
3017: #endif
1.1 root 3018:
1.1.1.3 root 3019: if (! handle_packet (unit, pck)) {
3020: error:
3021: PUT_PCK_RES1 (pck, DOS_FALSE);
3022: PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN);
3023: }
1.1.1.4 root 3024: TRACE(("reply: %8lx, %ld\n", GET_PCK_RES1 (pck), GET_PCK_RES2 (pck)));
1.1 root 3025:
1.1.1.3 root 3026: error2:
1.1 root 3027:
1.1.1.3 root 3028: return 0;
3029: }
1.1 root 3030:
1.1.1.11 root 3031: static int current_deviceno = 0;
1.1.1.13 root 3032: static int current_cdrom = 0;
1.1.1.11 root 3033:
3034: static void reset_uaedevices (void)
3035: {
3036: current_deviceno = 0;
1.1.1.13 root 3037: current_cdrom = 0;
1.1.1.11 root 3038: }
3039:
3040: static int get_new_device (char **devname, uaecptr *devname_amiga, int cdrom)
3041: {
1.1.1.13 root 3042: int result;
1.1.1.11 root 3043: char buffer[80];
3044:
1.1.1.13 root 3045: if (cdrom) {
3046: sprintf (buffer, "CD%d", current_cdrom);
3047: result = current_cdrom++;
3048: } else {
3049: sprintf (buffer, "DH%d", current_deviceno);
3050: result = current_deviceno++;
3051: }
1.1.1.11 root 3052:
3053: *devname_amiga = ds (*devname = my_strdup (buffer));
1.1.1.13 root 3054: return result;
1.1.1.11 root 3055: }
3056:
1.1.1.4 root 3057: void filesys_start_threads (void)
3058: {
3059: UnitInfo *uip;
3060: int i;
3061:
3062: current_mountinfo = dup_mountinfo (currprefs.mountinfo);
3063:
3064: reset_uaedevices ();
3065:
3066: uip = current_mountinfo->ui;
3067: for (i = 0; i < current_mountinfo->num_units; i++) {
3068: uip[i].unit_pipe = 0;
1.1.1.11 root 3069: uip[i].devno = get_new_device (&uip[i].devname, &uip[i].devname_amiga, 0);
1.1.1.4 root 3070:
3071: #ifdef UAE_FILESYS_THREADS
3072: if (! is_hardfile (current_mountinfo, i)) {
3073: uip[i].unit_pipe = (smp_comm_pipe *)xmalloc (sizeof (smp_comm_pipe));
3074: uip[i].back_pipe = (smp_comm_pipe *)xmalloc (sizeof (smp_comm_pipe));
3075: init_comm_pipe (uip[i].unit_pipe, 50, 3);
3076: init_comm_pipe (uip[i].back_pipe, 50, 1);
1.1.1.13 root 3077: uae_start_thread (filesys_thread, (void *)(uip + i), &uip[i].tid);
1.1.1.4 root 3078: }
3079: #endif
3080: }
3081: }
3082:
1.1.1.3 root 3083: void filesys_reset (void)
3084: {
3085: Unit *u, *u1;
1.1 root 3086:
1.1.1.4 root 3087: /* We get called once from customreset at the beginning of the program
3088: * before filesys_start_threads has been called. Survive that. */
3089: if (current_mountinfo == 0)
3090: return;
1.1 root 3091:
1.1.1.4 root 3092: for (u = units; u; u = u1) {
1.1.1.3 root 3093: u1 = u->next;
3094: free (u);
1.1 root 3095: }
1.1.1.3 root 3096: unit_num = 0;
3097: units = 0;
1.1.1.4 root 3098:
3099: free_mountinfo (current_mountinfo);
3100: current_mountinfo = 0;
1.1.1.3 root 3101: }
1.1 root 3102:
1.1.1.16 root 3103: static void free_all_ainos (Unit *u, a_inode *parent)
3104: {
3105: a_inode *a;
3106: while (a = parent->child)
3107: {
3108: free_all_ainos (u, a);
3109: dispose_aino (u, &parent->child, a);
3110: }
3111: }
3112:
3113:
1.1.1.3 root 3114: void filesys_prepare_reset (void)
3115: {
1.1.1.4 root 3116: UnitInfo *uip = current_mountinfo->ui;
3117: Unit *u;
1.1.1.3 root 3118: int i;
1.1 root 3119:
1.1.1.3 root 3120: #ifdef UAE_FILESYS_THREADS
1.1.1.4 root 3121: for (i = 0; i < current_mountinfo->num_units; i++) {
3122: if (uip[i].unit_pipe != 0) {
3123: uae_sem_init (&uip[i].reset_sync_sem, 0, 0);
3124: uip[i].reset_state = FS_GO_DOWN;
1.1.1.3 root 3125: /* send death message */
1.1.1.4 root 3126: write_comm_pipe_int (uip[i].unit_pipe, 0, 0);
3127: write_comm_pipe_int (uip[i].unit_pipe, 0, 0);
3128: write_comm_pipe_int (uip[i].unit_pipe, 0, 1);
3129: uae_sem_wait (&uip[i].reset_sync_sem);
1.1.1.3 root 3130: }
3131: }
3132: #endif
3133: u = units;
3134: while (u != 0) {
1.1.1.16 root 3135: free_all_ainos (u, &u->rootnode);
3136: u->rootnode.next = u->rootnode.prev = &u->rootnode;
3137: u->aino_cache_size = 0;
1.1.1.3 root 3138: u = u->next;
3139: }
1.1 root 3140: }
3141:
1.1.1.4 root 3142: static uae_u32 filesys_diagentry (void)
1.1 root 3143: {
1.1.1.7 root 3144: uaecptr resaddr = m68k_areg (regs, 2) + 0x10;
3145: uaecptr start = resaddr;
3146: uaecptr residents, tmp;
1.1.1.3 root 3147:
1.1.1.4 root 3148: TRACE (("filesystem: diagentry called\n"));
1.1.1.3 root 3149:
1.1.1.7 root 3150: filesys_configdev = m68k_areg (regs, 3);
1.1.1.3 root 3151:
3152: do_put_mem_long ((uae_u32 *)(filesysory + 0x2100), EXPANSION_explibname);
3153: do_put_mem_long ((uae_u32 *)(filesysory + 0x2104), filesys_configdev);
3154: do_put_mem_long ((uae_u32 *)(filesysory + 0x2108), EXPANSION_doslibname);
1.1.1.4 root 3155: do_put_mem_long ((uae_u32 *)(filesysory + 0x210c), current_mountinfo->num_units);
1.1.1.3 root 3156:
3157: uae_sem_init (&singlethread_int_sem, 0, 1);
1.1 root 3158: if (ROM_hardfile_resid != 0) {
3159: /* Build a struct Resident. This will set up and initialize
3160: * the uae.device */
1.1.1.7 root 3161: put_word (resaddr + 0x0, 0x4AFC);
3162: put_long (resaddr + 0x2, resaddr);
3163: put_long (resaddr + 0x6, resaddr + 0x1A); /* Continue scan here */
3164: put_word (resaddr + 0xA, 0x8101); /* RTF_AUTOINIT|RTF_COLDSTART; Version 1 */
3165: put_word (resaddr + 0xC, 0x0305); /* NT_DEVICE; pri 05 */
3166: put_long (resaddr + 0xE, ROM_hardfile_resname);
3167: put_long (resaddr + 0x12, ROM_hardfile_resid);
3168: put_long (resaddr + 0x16, ROM_hardfile_init); /* calls filesys_init */
1.1 root 3169: }
3170: resaddr += 0x1A;
1.1.1.7 root 3171: tmp = resaddr;
3172:
1.1.1.2 root 3173: /* The good thing about this function is that it always gets called
3174: * when we boot. So we could put all sorts of stuff that wants to be done
1.1.1.7 root 3175: * here.
3176: * We can simply add more Resident structures here. Although the Amiga OS
3177: * only knows about the one at address DiagArea + 0x10, we scan for other
3178: * Resident structures and call InitResident() for them at the end of the
3179: * diag entry. */
3180:
3181: resaddr = scsidev_startup(resaddr);
3182: native2amiga_startup();
3183:
3184: /* scan for Residents and return pointer to array of them */
3185: residents = resaddr;
3186: while (tmp < residents && tmp > start) {
3187: if (get_word (tmp) == 0x4AFC &&
3188: get_long (tmp + 0x2) == tmp) {
3189: put_word (resaddr, 0x227C); /* movea.l #tmp,a1 */
3190: put_long (resaddr + 2, tmp);
3191: put_word (resaddr + 6, 0x7200); /* moveq.l #0,d1 */
3192: put_long (resaddr + 8, 0x4EAEFF9A); /* jsr -$66(a6) ; InitResident */
3193: resaddr += 12;
3194: tmp = get_long (tmp + 0x6);
3195: } else {
3196: tmp++;
3197: }
3198: }
1.1.1.15 root 3199: /* call setup_exter */
3200: put_word (resaddr + 0, 0x2079);
3201: put_long (resaddr + 2, RTAREA_BASE + 28 + 4); /* move.l RTAREA_BASE+32,a0 */
3202: put_word (resaddr + 6, 0xd1fc);
3203: put_long (resaddr + 8, RTAREA_BASE + 8 + 4); /* add.l #RTAREA_BASE+12,a0 */
3204: put_word (resaddr + 12, 0x4e90); /* jsr (a0) */
3205:
3206: put_word (resaddr + 14, 0x7001); /* moveq.l #1,d0 */
3207: put_word (resaddr + 16, RTS);
1.1 root 3208:
1.1.1.7 root 3209: m68k_areg (regs, 0) = residents;
1.1.1.3 root 3210: return 1;
1.1 root 3211: }
3212:
1.1.1.3 root 3213: /* Remember a pointer AmigaOS gave us so we can later use it to identify
3214: * which unit a given startup message belongs to. */
1.1.1.4 root 3215: static uae_u32 filesys_dev_remember (void)
1.1.1.3 root 3216: {
3217: int unit_no = m68k_dreg (regs, 6);
3218: uaecptr devicenode = m68k_areg (regs, 3);
3219:
1.1.1.4 root 3220: current_mountinfo->ui[unit_no].startup = get_long (devicenode + 28);
1.1.1.3 root 3221: return devicenode;
3222: }
3223:
3224: /* Fill in per-unit fields of a parampacket */
1.1.1.4 root 3225: static uae_u32 filesys_dev_storeinfo (void)
1.1.1.3 root 3226: {
1.1.1.4 root 3227: UnitInfo *uip = current_mountinfo->ui;
1.1.1.3 root 3228: int unit_no = m68k_dreg (regs, 6);
3229: uaecptr parmpacket = m68k_areg (regs, 0);
3230:
1.1.1.4 root 3231: put_long (parmpacket, current_mountinfo->ui[unit_no].devname_amiga);
3232: put_long (parmpacket + 4, is_hardfile (current_mountinfo, unit_no) ? ROM_hardfile_resname : fsdevname);
3233: put_long (parmpacket + 8, uip[unit_no].devno);
1.1.1.3 root 3234: put_long (parmpacket + 12, 0); /* Device flags */
3235: put_long (parmpacket + 16, 16); /* Env. size */
1.1.1.6 root 3236: put_long (parmpacket + 20, uip[unit_no].hf.blocksize >> 2); /* longwords per block */
1.1.1.3 root 3237: put_long (parmpacket + 24, 0); /* unused */
1.1.1.4 root 3238: put_long (parmpacket + 28, uip[unit_no].hf.surfaces); /* heads */
1.1.1.3 root 3239: put_long (parmpacket + 32, 0); /* unused */
1.1.1.4 root 3240: put_long (parmpacket + 36, uip[unit_no].hf.secspertrack); /* sectors per track */
3241: put_long (parmpacket + 40, uip[unit_no].hf.reservedblocks); /* reserved blocks */
1.1.1.3 root 3242: put_long (parmpacket + 44, 0); /* unused */
3243: put_long (parmpacket + 48, 0); /* interleave */
3244: put_long (parmpacket + 52, 0); /* lowCyl */
1.1.1.4 root 3245: put_long (parmpacket + 56, uip[unit_no].hf.nrcyls - 1); /* hiCyl */
1.1.1.6 root 3246: put_long (parmpacket + 60, 50); /* Number of buffers */
1.1.1.3 root 3247: put_long (parmpacket + 64, 0); /* Buffer mem type */
3248: put_long (parmpacket + 68, 0x7FFFFFFF); /* largest transfer */
3249: put_long (parmpacket + 72, ~1); /* addMask (?) */
3250: put_long (parmpacket + 76, (uae_u32)-1); /* bootPri */
3251: put_long (parmpacket + 80, 0x444f5300); /* DOS\0 */
3252: put_long (parmpacket + 84, 0); /* pad */
3253:
1.1.1.4 root 3254: return is_hardfile (current_mountinfo, unit_no);
1.1 root 3255: }
3256:
1.1.1.3 root 3257: void filesys_install (void)
1.1 root 3258: {
3259: int i;
1.1.1.3 root 3260: uaecptr loop;
3261:
1.1.1.4 root 3262: TRACE (("Installing filesystem\n"));
1.1 root 3263:
3264: ROM_filesys_resname = ds("UAEunixfs.resource");
1.1.1.3 root 3265: ROM_filesys_resid = ds("UAE unixfs 0.4");
1.1 root 3266:
1.1.1.4 root 3267: fsdevname = ds ("uae.device"); /* does not really exist */
1.1 root 3268:
3269: ROM_filesys_diagentry = here();
1.1.1.7 root 3270: calltrap (deftrap(filesys_diagentry));
3271: dw(0x4ED0); /* JMP (a0) - jump to code that inits Residents */
1.1.1.3 root 3272:
3273: loop = here ();
3274: /* Special trap for the assembly make_dev routine */
1.1.1.15 root 3275: org (RTAREA_BASE + 0xFF20);
1.1.1.3 root 3276: calltrap (deftrap (filesys_dev_remember));
1.1.1.4 root 3277: dw (RTS);
1.1.1.3 root 3278:
1.1.1.15 root 3279: org (RTAREA_BASE + 0xFF28);
1.1.1.3 root 3280: calltrap (deftrap (filesys_dev_storeinfo));
1.1.1.4 root 3281: dw (RTS);
1.1.1.3 root 3282:
1.1.1.15 root 3283: org (RTAREA_BASE + 0xFF30);
1.1.1.3 root 3284: calltrap (deftrap (filesys_handler));
1.1.1.4 root 3285: dw (RTS);
1.1.1.3 root 3286:
1.1.1.15 root 3287: org (RTAREA_BASE + 0xFF40);
1.1.1.3 root 3288: calltrap (deftrap (startup_handler));
1.1.1.4 root 3289: dw (RTS);
1.1.1.3 root 3290:
1.1.1.15 root 3291: org (RTAREA_BASE + 0xFF50);
1.1.1.3 root 3292: calltrap (deftrap (exter_int_helper));
1.1.1.4 root 3293: dw (RTS);
1.1.1.3 root 3294:
3295: org (loop);
3296: }
3297:
3298: void filesys_install_code (void)
3299: {
1.1 root 3300: align(4);
3301:
1.1.1.3 root 3302: /* The last offset comes from the code itself, look for it near the top. */
1.1.1.15 root 3303: EXPANSION_bootcode = here () + 8 + 0x14 + 4;
1.1.1.3 root 3304: /* Ouch. Make sure this is _always_ a multiple of two bytes. */
1.1.1.15 root 3305: filesys_initcode = here() + 8 + 0x28 + 4;
3306:
1.1.1.3 root 3307: db(0x00); db(0x00); db(0x00); db(0x10); db(0x00); db(0x00); db(0x00); db(0x00);
1.1.1.15 root 3308: db(0x60); db(0x00); db(0x02); db(0x34); db(0x00); db(0x00); db(0x01); db(0x8c);
3309: db(0x00); db(0x00); db(0x00); db(0x2c); db(0x00); db(0x00); db(0x00); db(0xc4);
3310: db(0x00); db(0x00); db(0x00); db(0x18); db(0x00); db(0x00); db(0x01); db(0x54);
3311: db(0x43); db(0xfa); db(0x03); db(0x89); db(0x4e); db(0xae); db(0xff); db(0xa0);
3312: db(0x20); db(0x40); db(0x20); db(0x28); db(0x00); db(0x16); db(0x20); db(0x40);
3313: db(0x4e); db(0x90); db(0x4e); db(0x75); db(0x48); db(0xe7); db(0xff); db(0xfe);
3314: db(0x2c); db(0x78); db(0x00); db(0x04); db(0x30); db(0x3c); db(0xff); db(0xfc);
3315: db(0x61); db(0x00); db(0x03); db(0x4c); db(0x2a); db(0x50); db(0x43); db(0xfa);
3316: db(0x03); db(0x6f); db(0x70); db(0x24); db(0x7a); db(0x00); db(0x4e); db(0xae);
1.1.1.7 root 3317: db(0xfd); db(0xd8); db(0x4a); db(0x80); db(0x66); db(0x0c); db(0x43); db(0xfa);
1.1.1.15 root 3318: db(0x03); db(0x5f); db(0x70); db(0x00); db(0x7a); db(0x01); db(0x4e); db(0xae);
1.1.1.7 root 3319: db(0xfd); db(0xd8); db(0x28); db(0x40); db(0x70); db(0x58); db(0x72); db(0x01);
3320: db(0x4e); db(0xae); db(0xff); db(0x3a); db(0x26); db(0x40); db(0x7e); db(0x54);
3321: db(0x27); db(0xb5); db(0x78); db(0x00); db(0x78); db(0x00); db(0x59); db(0x87);
3322: db(0x64); db(0xf6); db(0x7c); db(0x00); db(0xbc); db(0xad); db(0x01); db(0x0c);
1.1.1.15 root 3323: db(0x64); db(0x18); db(0x20); db(0x4b); db(0x48); db(0xe7); db(0x02); db(0x10);
3324: db(0x2e); db(0x3c); db(0x00); db(0x00); db(0x00); db(0x01); db(0x61); db(0x00);
3325: db(0x01); db(0x04); db(0x4c); db(0xdf); db(0x08); db(0x40); db(0x52); db(0x86);
3326: db(0x60); db(0xe2); db(0x2c); db(0x78); db(0x00); db(0x04); db(0x22); db(0x4c);
3327: db(0x4e); db(0xae); db(0xfe); db(0x62); db(0x30); db(0x3c); db(0xff); db(0x80);
3328: db(0x61); db(0x00); db(0x02); db(0xe4); db(0x4e); db(0x90); db(0x72); db(0x03);
1.1.1.3 root 3329: db(0x74); db(0xf6); db(0x20); db(0x7c); db(0x00); db(0x20); db(0x00); db(0x00);
3330: db(0x90); db(0x88); db(0x65); db(0x0a); db(0x67); db(0x08); db(0x78); db(0x00);
3331: db(0x22); db(0x44); db(0x4e); db(0xae); db(0xfd); db(0x96); db(0x4c); db(0xdf);
1.1.1.7 root 3332: db(0x7f); db(0xff); db(0x4e); db(0x75); db(0x48); db(0xe7); db(0x00); db(0x20);
1.1.1.15 root 3333: db(0x30); db(0x3c); db(0xff); db(0x50); db(0x61); db(0x00); db(0x02); db(0xb8);
3334: db(0x70); db(0x00); db(0x4e); db(0x90); db(0x4a); db(0x80); db(0x67); db(0x76);
3335: db(0x2c); db(0x78); db(0x00); db(0x04); db(0x30); db(0x3c); db(0xff); db(0x50);
3336: db(0x61); db(0x00); db(0x02); db(0xa4); db(0x70); db(0x02); db(0x4e); db(0x90);
3337: db(0x0c); db(0x80); db(0x00); db(0x00); db(0x00); db(0x01); db(0x6d); db(0x50);
3338: db(0x6e); db(0x06); db(0x4e); db(0xae); db(0xfe); db(0x92); db(0x60); db(0xe4);
1.1.1.7 root 3339: db(0x0c); db(0x80); db(0x00); db(0x00); db(0x00); db(0x02); db(0x6e); db(0x08);
1.1.1.15 root 3340: db(0x20); db(0x01); db(0x4e); db(0xae); db(0xfe); db(0xbc); db(0x60); db(0xd4);
3341: db(0x0c); db(0x80); db(0x00); db(0x00); db(0x00); db(0x03); db(0x6e); db(0x06);
3342: db(0x4e); db(0xae); db(0xfe); db(0x86); db(0x60); db(0xc6); db(0x0c); db(0x80);
3343: db(0x00); db(0x00); db(0x00); db(0x04); db(0x6e); db(0x06); db(0x4e); db(0xae);
3344: db(0xff); db(0x4c); db(0x60); db(0xb8); db(0x48); db(0xe7); db(0x00); db(0x24);
3345: db(0x24); db(0x49); db(0x22); db(0x6a); db(0x00); db(0x14); db(0x2a); db(0x6a);
3346: db(0x00); db(0x18); db(0x2f); db(0x0a); db(0x4e); db(0x95); db(0x24); db(0x1f);
3347: db(0x42); db(0xaa); db(0x00); db(0x18); db(0x4c); db(0xdf); db(0x24); db(0x00);
3348: db(0x30); db(0x3c); db(0xff); db(0x50); db(0x61); db(0x00); db(0x02); db(0x40);
3349: db(0x70); db(0x04); db(0x4e); db(0x90); db(0x70); db(0x01); db(0x4c); db(0xdf);
3350: db(0x04); db(0x00); db(0x4e); db(0x75); db(0x70); db(0x1a); db(0x22); db(0x3c);
3351: db(0x00); db(0x01); db(0x00); db(0x01); db(0x4e); db(0xae); db(0xff); db(0x3a);
3352: db(0x22); db(0x40); db(0x41); db(0xfa); db(0x02); db(0x30); db(0x23); db(0x48);
3353: db(0x00); db(0x0a); db(0x41); db(0xfa); db(0xff); db(0x58); db(0x23); db(0x48);
3354: db(0x00); db(0x0e); db(0x41); db(0xfa); db(0xff); db(0x50); db(0x23); db(0x48);
3355: db(0x00); db(0x12); db(0x13); db(0x7c); db(0x00); db(0xc8); db(0x00); db(0x09);
3356: db(0x13); db(0x7c); db(0x00); db(0x02); db(0x00); db(0x08); db(0x70); db(0x0d);
3357: db(0x4e); db(0xee); db(0xff); db(0x58); db(0x2f); db(0x08); db(0x30); db(0x3c);
3358: db(0xff); db(0xfc); db(0x61); db(0x00); db(0x01); db(0xf2); db(0x2a); db(0x50);
3359: db(0x30); db(0x3c); db(0xff); db(0x28); db(0x61); db(0x00); db(0x01); db(0xe8);
3360: db(0x22); db(0x48); db(0x20); db(0x5f); db(0x4e); db(0x91); db(0x26); db(0x00);
3361: db(0xc0); db(0x85); db(0x66); db(0x00); db(0xff); db(0x16); db(0x2c); db(0x4c);
3362: db(0x4e); db(0xae); db(0xff); db(0x70); db(0x26); db(0x40); db(0x30); db(0x3c);
3363: db(0xff); db(0x20); db(0x61); db(0x00); db(0x01); db(0xca); db(0x4e); db(0x90);
1.1.1.7 root 3364: db(0x70); db(0x00); db(0x27); db(0x40); db(0x00); db(0x08); db(0x27); db(0x40);
3365: db(0x00); db(0x10); db(0x27); db(0x40); db(0x00); db(0x20); db(0x4a); db(0x83);
3366: db(0x66); db(0x1c); db(0x27); db(0x7c); db(0x00); db(0x00); db(0x0f); db(0xa0);
1.1.1.15 root 3367: db(0x00); db(0x14); db(0x43); db(0xfa); db(0xfe); db(0x20); db(0x20); db(0x09);
1.1.1.7 root 3368: db(0xe4); db(0x88); db(0x27); db(0x40); db(0x00); db(0x20); db(0x27); db(0x7c);
3369: db(0xff); db(0xff); db(0xff); db(0xff); db(0x00); db(0x24); db(0x4a); db(0x87);
3370: db(0x67); db(0x36); db(0x2c); db(0x78); db(0x00); db(0x04); db(0x70); db(0x14);
3371: db(0x72); db(0x00); db(0x4e); db(0xae); db(0xff); db(0x3a); db(0x22); db(0x40);
3372: db(0x70); db(0x00); db(0x22); db(0x80); db(0x23); db(0x40); db(0x00); db(0x04);
3373: db(0x33); db(0x40); db(0x00); db(0x0e); db(0x30); db(0x3c); db(0x10); db(0xff);
3374: db(0x90); db(0x06); db(0x33); db(0x40); db(0x00); db(0x08); db(0x23); db(0x6d);
3375: db(0x01); db(0x04); db(0x00); db(0x0a); db(0x23); db(0x4b); db(0x00); db(0x10);
3376: db(0x41); db(0xec); db(0x00); db(0x4a); db(0x4e); db(0xee); db(0xfe); db(0xf2);
3377: db(0x20); db(0x4b); db(0x72); db(0x00); db(0x22); db(0x41); db(0x70); db(0xff);
3378: db(0x2c); db(0x4c); db(0x4e); db(0xee); db(0xff); db(0x6a); db(0x2c); db(0x78);
3379: db(0x00); db(0x04); db(0x70); db(0x00); db(0x22); db(0x40); db(0x4e); db(0xae);
3380: db(0xfe); db(0xda); db(0x20); db(0x40); db(0x4b); db(0xe8); db(0x00); db(0x5c);
1.1.1.15 root 3381: db(0x43); db(0xfa); db(0x01); db(0x59); db(0x70); db(0x00); db(0x4e); db(0xae);
1.1.1.7 root 3382: db(0xfd); db(0xd8); db(0x24); db(0x40); db(0x20); db(0x3c); db(0x00); db(0x00);
3383: db(0x00); db(0x9d); db(0x22); db(0x3c); db(0x00); db(0x01); db(0x00); db(0x01);
3384: db(0x4e); db(0xae); db(0xff); db(0x3a); db(0x26); db(0x40); db(0x7c); db(0x00);
3385: db(0x26); db(0x86); db(0x27); db(0x46); db(0x00); db(0x04); db(0x27); db(0x46);
3386: db(0x00); db(0x08); db(0x7a); db(0x00); db(0x20); db(0x4d); db(0x4e); db(0xae);
3387: db(0xfe); db(0x80); db(0x20); db(0x4d); db(0x4e); db(0xae); db(0xfe); db(0x8c);
1.1.1.15 root 3388: db(0x28); db(0x40); db(0x26); db(0x2c); db(0x00); db(0x0a); db(0x30); db(0x3c);
3389: db(0xff); db(0x40); db(0x61); db(0x00); db(0x00); db(0xfa); db(0x70); db(0x00);
3390: db(0x4e); db(0x90); db(0x60); db(0x7e); db(0x20); db(0x4d); db(0x4e); db(0xae);
3391: db(0xfe); db(0x80); db(0x20); db(0x4d); db(0x4e); db(0xae); db(0xfe); db(0x8c);
3392: db(0x28); db(0x40); db(0x26); db(0x2c); db(0x00); db(0x0a); db(0x66); db(0x3c);
3393: db(0x30); db(0x3c); db(0xff); db(0x50); db(0x61); db(0x00); db(0x00); db(0xd8);
3394: db(0x70); db(0x01); db(0x4e); db(0x90); db(0x45); db(0xeb); db(0x00); db(0x04);
3395: db(0x20); db(0x52); db(0x20); db(0x08); db(0x67); db(0xd6); db(0x22); db(0x50);
1.1.1.7 root 3396: db(0x20); db(0x40); db(0x20); db(0x28); db(0x00); db(0x04); db(0x6a); db(0x16);
3397: db(0x48); db(0xe7); db(0x00); db(0xc0); db(0x28); db(0x68); db(0x00); db(0x0a);
1.1.1.15 root 3398: db(0x61); db(0x48); db(0x53); db(0x85); db(0x4c); db(0xdf); db(0x03); db(0x00);
1.1.1.7 root 3399: db(0x24); db(0x89); db(0x20); db(0x49); db(0x60); db(0xdc); db(0x24); db(0x48);
3400: db(0x20); db(0x49); db(0x60); db(0xd6); db(0x0c); db(0x85); db(0x00); db(0x00);
3401: db(0x00); db(0x14); db(0x65); db(0x00); db(0x00); db(0x0a); db(0x70); db(0x01);
1.1.1.15 root 3402: db(0x29); db(0x40); db(0x00); db(0x04); db(0x60); db(0x12); db(0x61); db(0x30);
3403: db(0x30); db(0x3c); db(0xff); db(0x30); db(0x61); db(0x00); db(0x00); db(0x88);
3404: db(0x4e); db(0x90); db(0x4a); db(0x80); db(0x67); db(0x0c); db(0x52); db(0x85);
3405: db(0x28); db(0xab); db(0x00); db(0x04); db(0x27); db(0x4c); db(0x00); db(0x04);
3406: db(0x60); db(0x82); db(0x28); db(0x43); db(0x61); db(0x04); db(0x60); db(0x00);
3407: db(0xff); db(0x7c); db(0x22); db(0x54); db(0x20); db(0x6c); db(0x00); db(0x04);
3408: db(0x29); db(0x4d); db(0x00); db(0x04); db(0x4e); db(0xee); db(0xfe); db(0x92);
3409: db(0x2f); db(0x05); db(0x7a); db(0xfc); db(0x24); db(0x53); db(0x2e); db(0x0a);
3410: db(0x22); db(0x0a); db(0x67); db(0x00); db(0x00); db(0x0c); db(0x52); db(0x85);
3411: db(0x67); db(0x1e); db(0x22); db(0x4a); db(0x24); db(0x52); db(0x60); db(0xf0);
3412: db(0x52); db(0x85); db(0x67); db(0x3c); db(0x24); db(0x47); db(0x70); db(0x18);
3413: db(0x72); db(0x01); db(0x4e); db(0xae); db(0xff); db(0x3a); db(0x52); db(0x46);
3414: db(0x24); db(0x40); db(0x24); db(0x87); db(0x2e); db(0x0a); db(0x60); db(0xe8);
3415: db(0x20); db(0x12); db(0x67); db(0x24); db(0x20); db(0x40); db(0x20); db(0x10);
3416: db(0x67); db(0x1e); db(0x20); db(0x40); db(0x20); db(0x10); db(0x67); db(0x18);
3417: db(0x70); db(0x00); db(0x22); db(0x80); db(0x22); db(0x4a); db(0x24); db(0x51);
3418: db(0x70); db(0x18); db(0x4e); db(0xae); db(0xff); db(0x2e); db(0x06); db(0x86);
3419: db(0x00); db(0x01); db(0x00); db(0x00); db(0x20); db(0x0a); db(0x66); db(0xec);
3420: db(0x26); db(0x87); db(0x2a); db(0x1f); db(0x4e); db(0x75); db(0x41); db(0xfa);
3421: db(0xfc); db(0x6c); db(0x02); db(0x80); db(0x00); db(0x00); db(0xff); db(0xff);
3422: db(0xd1); db(0xc0); db(0x4e); db(0x75); db(0x55); db(0x41); db(0x45); db(0x20);
3423: db(0x66); db(0x69); db(0x6c); db(0x65); db(0x73); db(0x79); db(0x73); db(0x74);
3424: db(0x65); db(0x6d); db(0x00); db(0x64); db(0x6f); db(0x73); db(0x2e); db(0x6c);
3425: db(0x69); db(0x62); db(0x72); db(0x61); db(0x72); db(0x79); db(0x00); db(0x65);
3426: db(0x78); db(0x70); db(0x61); db(0x6e); db(0x73); db(0x69); db(0x6f); db(0x6e);
3427: db(0x2e); db(0x6c); db(0x69); db(0x62); db(0x72); db(0x61); db(0x72); db(0x79);
3428: db(0x00); db(0x00); db(0x00); db(0x00); db(0x00); db(0x00); db(0x03); db(0xf2);
3429:
1.1 root 3430: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.