Annotation of uae/src/filesys.c, revision 1.1.1.9

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.