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

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

unix.superglobalmegacorp.com

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