--- uae/src/filesys.c 2018/04/24 16:40:09 1.1.1.3 +++ uae/src/filesys.c 2018/04/24 16:42:15 1.1.1.4 @@ -37,12 +37,12 @@ #include "filesys.h" #include "autoconf.h" #include "compiler.h" -#include "zfile.h" +#include "fsusage.h" #include "threaddep/penguin.h" /* #define TRACING_ENABLED */ #ifdef TRACING_ENABLED -#define TRACE(x) do { sprintf x; write_log(warning_buffer); } while(0) +#define TRACE(x) do { write_log x; } while(0) #define DUMPLOCK(u,x) dumplock(u,x) #else #define TRACE(x) @@ -76,7 +76,7 @@ static long dos_errno(void) { int e = errno; - switch(e) { + switch (e) { case ENOMEM: return ERROR_NO_FREE_STORE; case EEXIST: return ERROR_OBJECT_EXISTS; case EACCES: return ERROR_WRITE_PROTECTED; @@ -98,7 +98,7 @@ static long dos_errno(void) #endif default: - TRACE((warning_buffer, "Unimplemented error %s\n", strerror(e))); + TRACE(("Unimplemented error %s\n", strerror(e))); return ERROR_NOT_IMPLEMENTED; } } @@ -107,7 +107,9 @@ static long dos_errno(void) /* * This _should_ be no issue for us, but let's rather use a guaranteed * thread safe function if we have one. - * Well, let's use it once it works. + * This used to be broken in glibc versions <= 2.0.1 (I think). I hope + * no one is using this these days. + * Michael Krause says it's also broken in libc5. ARRRGHHHHHH!!!! */ #if 0 && defined HAVE_READDIR_R @@ -125,6 +127,9 @@ static struct dirent *my_readdir (DIR *d #define my_readdir(dirstream, space) readdir(dirstream) #endif +uaecptr filesys_initcode; +static uae_u32 fsdevname, filesys_configdev; + #define FS_STARTUP 0 #define FS_GO_DOWN 1 @@ -157,109 +162,262 @@ typedef struct { smp_comm_pipe *unit_pipe, *back_pipe; penguin_id tid; struct _unit *volatile self; + /* Reset handling */ + uae_sem_t reset_sync_sem; + int reset_state; } UnitInfo; #define MAX_UNITS 20 -static int num_units = 0, num_filesys_units = 0; -static UnitInfo ui[MAX_UNITS]; -uaecptr filesys_initcode; -static uae_u32 fsdevname, hardfileseglist, filesys_configdev; -static uaecptr filesys_parampacket; -char * add_filesys_unit(char *volname, char *rootdir, int readonly, +struct uaedev_mount_info { + int num_units; + UnitInfo ui[MAX_UNITS]; +}; + +static struct uaedev_mount_info *current_mountinfo; + +int nr_units (struct uaedev_mount_info *mountinfo) +{ + return mountinfo->num_units; +} + +int is_hardfile (struct uaedev_mount_info *mountinfo, int unit_no) +{ + return mountinfo->ui[unit_no].volname == 0; +} + +static void close_filesys_unit (struct uaedev_mount_info *mountinfo, int nr) +{ + UnitInfo *uip = mountinfo->ui + nr; + + if (uip->hf.fd != 0) + fclose (uip->hf.fd); + if (uip->volname != 0) + free (uip->volname); + if (uip->devname != 0) + free (uip->devname); + if (uip->rootdir != 0) + free (uip->rootdir); + if (uip->unit_pipe) + free (uip->unit_pipe); + if (uip->back_pipe) + free (uip->back_pipe); + + uip->unit_pipe = 0; + uip->back_pipe = 0; + + uip->hf.fd = 0; + uip->volname = 0; + uip->devname = 0; + uip->rootdir = 0; +} + +char *get_filesys_unit (struct uaedev_mount_info *mountinfo, int nr, + char **volname, char **rootdir, int *readonly, + int *secspertrack, int *surfaces, int *reserved, + int *cylinders, int *size) +{ + UnitInfo *uip = mountinfo->ui + nr; + + if (nr >= mountinfo->num_units) + return "No slot allocated for this unit"; + + *volname = uip->volname ? my_strdup (uip->volname) : 0; + *rootdir = uip->rootdir ? my_strdup (uip->rootdir) : 0; + *readonly = uip->readonly; + *secspertrack = uip->hf.secspertrack; + *surfaces = uip->hf.surfaces; + *reserved = uip->hf.reservedblocks; + *size = uip->hf.size; + *cylinders = uip->hf.nrcyls; + return 0; +} + +char *set_filesys_unit (struct uaedev_mount_info *mountinfo, int nr, + char *volname, char *rootdir, int readonly, int secspertrack, int surfaces, int reserved) { - UnitInfo *uip; - if (num_units >= MAX_UNITS) { - return "Maximum number of file systems mounted"; - } + UnitInfo tmpui; + + if (nr >= mountinfo->num_units) + return "No slot allocated for this unit"; - uip = ui + num_units; if (volname != 0) { - num_filesys_units++; - uip->volname = my_strdup(volname); - uip->hf.fd = 0; + tmpui.volname = my_strdup (volname); + tmpui.hf.fd = 0; } else { - FILE *hf; - - uip->volname = 0; - uip->hf.fd = zfile_open (rootdir, "r+b"); - if (uip->hf.fd == 0) { + tmpui.volname = 0; + tmpui.hf.fd = fopen (rootdir, "r+b"); + if (tmpui.hf.fd == 0) { readonly = 1; - uip->hf.fd = zfile_open (rootdir, "rb"); + tmpui.hf.fd = fopen (rootdir, "rb"); } - if (uip->hf.fd == 0) { + if (tmpui.hf.fd == 0) return "Hardfile not found"; - } + if (secspertrack < 1 || secspertrack > 32767 || surfaces < 1 || surfaces > 1023 - || reserved < 0 || reserved > 1023) { + || reserved < 0 || reserved > 1023) + { return "Bad hardfile geometry"; } - fseek (uip->hf.fd, 0, SEEK_END); - uip->hf.size = ftell (uip->hf.fd); - uip->hf.secspertrack = secspertrack; - uip->hf.surfaces = surfaces; - uip->hf.reservedblocks = reserved; - uip->hf.nrcyls = (uip->hf.size >> 9) / (secspertrack * surfaces); - } - uip->rootdir = my_strdup (rootdir); - uip->readonly = readonly; + fseek (tmpui.hf.fd, 0, SEEK_END); + tmpui.hf.size = ftell (tmpui.hf.fd); + tmpui.hf.secspertrack = secspertrack; + tmpui.hf.surfaces = surfaces; + tmpui.hf.reservedblocks = reserved; + tmpui.hf.nrcyls = (tmpui.hf.size >> 9) / (secspertrack * surfaces); + } + tmpui.self = 0; + tmpui.reset_state = FS_STARTUP; + tmpui.rootdir = my_strdup (rootdir); + tmpui.readonly = readonly; + + close_filesys_unit (mountinfo, nr); + mountinfo->ui[nr] = tmpui; - num_units++; return 0; } + +char *add_filesys_unit (struct uaedev_mount_info *mountinfo, + char *volname, char *rootdir, int readonly, + int secspertrack, int surfaces, int reserved) +{ + char *retval; + int nr = mountinfo->num_units; + UnitInfo *uip = mountinfo->ui + nr; -int kill_filesys_unit (int nr) + if (nr >= MAX_UNITS) + return "Maximum number of file systems mounted"; + + uip->hf.fd = 0; + uip->devname = 0; + uip->volname = 0; + uip->rootdir = 0; + uip->unit_pipe = 0; + uip->back_pipe = 0; + + mountinfo->num_units++; + retval = set_filesys_unit (mountinfo, nr, volname, rootdir, readonly, + secspertrack, surfaces, reserved); + if (retval) + mountinfo->num_units--; + return retval; +} + +int kill_filesys_unit (struct uaedev_mount_info *mountinfo, int nr) { - if (nr > num_units || nr < 0) + UnitInfo *uip = mountinfo->ui; + if (nr >= mountinfo->num_units || nr < 0) return -1; - if (ui[nr].hf.fd != 0) - fclose (ui[nr].hf.fd); - num_units--; - for (; nr < num_units; nr++) { - ui[nr] = ui[nr+1]; + close_filesys_unit (mountinfo, nr); + + mountinfo->num_units--; + for (; nr < mountinfo->num_units; nr++) { + uip[nr] = uip[nr+1]; } return 0; } -struct hardfiledata *get_hardfile_data (int nr) +int move_filesys_unit (struct uaedev_mount_info *mountinfo, int nr, int to) { - if (nr < 0 || nr >= num_units || ui[nr].volname != 0) - return 0; - return &ui[nr].hf; + UnitInfo tmpui; + UnitInfo *uip = mountinfo->ui; + + if (nr >= mountinfo->num_units || nr < 0 + || to >= mountinfo->num_units || to < 0 + || to == nr) + return -1; + tmpui = uip[nr]; + if (to > nr) { + int i; + for (i = nr; i < to; i++) + uip[i] = uip[i + 1]; + } else { + int i; + for (i = nr; i > to; i--) + uip[i] = uip[i - 1]; + } + uip[to] = tmpui; + return 0; } -int sprintf_filesys_unit(char *buffer, int num) +int sprintf_filesys_unit (struct uaedev_mount_info *mountinfo, char *buffer, int num) { - if (num >= num_units) + UnitInfo *uip = mountinfo->ui; + if (num >= mountinfo->num_units) return -1; - - if (ui[num].volname != 0) - sprintf (buffer, "(UAE%d:) Filesystem, %s: %s %s", num, ui[num].volname, - ui[num].rootdir, ui[num].readonly ? "ro" : ""); + + if (uip[num].volname != 0) + sprintf (buffer, "(UAE%d:) Filesystem, %s: %s %s", num, uip[num].volname, + uip[num].rootdir, uip[num].readonly ? "ro" : ""); else sprintf (buffer, "(UAE%d:) Hardfile, \"%s\", size %d bytes", num, - ui[num].rootdir, ui[num].hf.size); + uip[num].rootdir, uip[num].hf.size); return 0; } -void write_filesys_config(FILE *f) +void write_filesys_config (struct uaedev_mount_info *mountinfo, FILE *f) { + UnitInfo *uip = mountinfo->ui; int i; - for (i = 0; i < num_units; i++) { - if (ui[i].volname != 0) { - fprintf(f, "-%c %s:%s\n", ui[i].readonly ? 'M' : 'm', - ui[i].volname, ui[i].rootdir); + + for (i = 0; i < mountinfo->num_units; i++) { + if (uip[i].volname != 0) { + fprintf (f, "-%c %s:%s\n", uip[i].readonly ? 'M' : 'm', + uip[i].volname, uip[i].rootdir); } else { - fprintf(f, "-W %d:%d:%d:%s\n", ui[i].hf.secspertrack, - ui[i].hf.surfaces, ui[i].hf.reservedblocks, - ui[i].rootdir); + fprintf (f, "-W %d:%d:%d:%s\n", uip[i].hf.secspertrack, + uip[i].hf.surfaces, uip[i].hf.reservedblocks, + uip[i].rootdir); } } } +struct uaedev_mount_info *alloc_mountinfo (void) +{ + struct uaedev_mount_info *info; + info = (struct uaedev_mount_info *)malloc (sizeof *info); + info->num_units = 0; + return info; +} + +struct uaedev_mount_info *dup_mountinfo (struct uaedev_mount_info *mip) +{ + int i; + struct uaedev_mount_info *i2 = alloc_mountinfo (); + + memcpy (i2, mip, sizeof *i2); + + for (i = 0; i < i2->num_units; i++) { + UnitInfo *uip = i2->ui + i; + if (uip->volname) + uip->volname = my_strdup (uip->volname); + if (uip->rootdir) + uip->rootdir = my_strdup (uip->rootdir); + if (uip->hf.fd) + uip->hf.fd = fdopen (fileno (uip->hf.fd), uip->readonly ? "rb" : "r+b"); + } + return i2; +} + +void free_mountinfo (struct uaedev_mount_info *mip) +{ + int i; + for (i = 0; i < mip->num_units; i++) + close_filesys_unit (mip, i); + free (mip); +} + +struct hardfiledata *get_hardfile_data (int nr) +{ + UnitInfo *uip = current_mountinfo->ui; + if (nr < 0 || nr >= current_mountinfo->num_units || uip[nr].volname != 0) + return 0; + return &uip[nr].hf; +} + /* minimal AmigaDOS definitions */ /* field offsets in DosPacket */ @@ -350,40 +508,36 @@ typedef struct _unit { struct _unit *next; /* Amiga stuff */ - uaecptr dosbase; - uaecptr volume; - uaecptr port; /* Our port */ - uaecptr locklist; + uaecptr dosbase; + uaecptr volume; + uaecptr port; /* Our port */ + uaecptr locklist; /* Native stuff */ - uae_s32 unit; /* unit number */ - UnitInfo ui; /* unit startup info */ - char tmpbuf3[256]; + uae_s32 unit; /* unit number */ + UnitInfo ui; /* unit startup info */ + char tmpbuf3[256]; /* Dummy message processing */ - uaecptr dummy_message; + uaecptr dummy_message; volatile unsigned int cmds_sent; volatile unsigned int cmds_complete; volatile unsigned int cmds_acked; /* ExKeys */ ExamineKey examine_keys[EXKEYS]; - int next_exkey; + int next_exkey; /* Keys */ - struct key* keys; - uae_u32 key_uniq; - uae_u32 a_uniq; + struct key *keys; + uae_u32 key_uniq; + uae_u32 a_uniq; struct a_inode rootnode; unsigned long aino_cache_size; struct a_inode *aino_hash[MAX_AINO_HASH]; unsigned long nr_cache_hits; unsigned long nr_cache_lookups; - - /* Reset handling */ - uae_sem_t reset_sync_sem; - int reset_state; } Unit; typedef uae_u8 *dpacket; @@ -404,7 +558,7 @@ static char *bstr1 (uaecptr addr) int n = get_byte(addr); addr++; - for(i = 0; i < n; i++, addr++) + for (i = 0; i < n; i++, addr++) buf[i] = get_byte(addr); buf[i] = 0; return buf; @@ -416,7 +570,7 @@ static char *bstr (Unit *unit, uaecptr a int n = get_byte(addr); addr++; - for(i = 0; i < n; i++, addr++) + for (i = 0; i < n; i++, addr++) unit->tmpbuf3[i] = get_byte(addr); unit->tmpbuf3[i] = 0; return unit->tmpbuf3; @@ -429,7 +583,7 @@ static char *bstr_cut (Unit *unit, uaecp int n = get_byte (addr); addr++; - for(i = 0; i < n; i++, addr++) { + for (i = 0; i < n; i++, addr++) { uae_u8 c = get_byte(addr); unit->tmpbuf3[i] = c; if (c == '/' || (c == ':' && colon_seen++ == 0)) @@ -443,11 +597,11 @@ static Unit *units = 0; static int unit_num = 0; static Unit* -find_unit(uaecptr port) +find_unit (uaecptr port) { Unit* u; - for(u = units; u; u = u->next) - if(u->port == port) + for (u = units; u; u = u->next) + if (u->port == port) break; return u; @@ -460,7 +614,7 @@ static int get_file_attrs (struct a_inod return dos_errno (); aino->dir = S_ISDIR (statbuf.st_mode) ? 1 : 0; aino->amigaos_mode = -#ifndef __DOS__ +#if !defined __DOS__ && !defined _WIN32 (S_IXUSR & statbuf.st_mode ? 0 : A_FIBF_EXECUTE) | #endif (S_IWUSR & statbuf.st_mode ? 0 : A_FIBF_WRITE) | @@ -629,7 +783,7 @@ static void delete_aino (Unit *unit, str struct a_inode **aip; int hash; - TRACE((warning_buffer, "deleting aino %x\n", aino->uniq)); + TRACE(("deleting aino %x\n", aino->uniq)); de_recycle_aino (unit, aino); aip = &aino->parent->child; @@ -699,14 +853,21 @@ static struct a_inode *lookup_aino (Unit static char *get_nname (Unit *unit, struct a_inode *base, char *rel) { DIR* dir; - struct dirent* de; + struct dirent *de; char *p = 0; - dir = opendir(base->nname); + /* Don't allow Unix "." and "..", which confuse AmigaOS and let us + * escape out of the mount point. */ + if (rel[0] == '.' + && (rel[1] == '\0' + || (rel[1] == '.' && rel[2] == '\0'))) + return 0; + + dir = opendir (base->nname); if (dir) { struct dirent de_space; - while((de = my_readdir (dir, &de_space))) { - if (strcasecmp(de->d_name, rel) == 0) + while ((de = my_readdir (dir, &de_space))) { + if (strcasecmp (de->d_name, rel) == 0) break; } if (de) { @@ -715,7 +876,7 @@ static char *get_nname (Unit *unit, stru strcat (p, "/"); strcat (p, de->d_name); } - closedir(dir); + closedir (dir); } return p; } @@ -745,7 +906,6 @@ static char *get_aname (Unit *unit, stru static struct a_inode *new_child_aino (Unit *unit, struct a_inode *base, char *rel, int force) { - struct stat statbuf; char *nn; struct a_inode *aino; @@ -791,14 +951,13 @@ static struct a_inode *new_child_aino (U get_file_attrs (aino); } recycle_aino (unit, aino); - TRACE((warning_buffer, "created aino %x, normal\n", aino->uniq)); + TRACE(("created aino %x, normal\n", aino->uniq)); return aino; } static struct a_inode *lookup_child_aino (Unit *unit, struct a_inode *base, char *rel, uae_u32 *err) { struct a_inode *c = base->child; - char *p, *p2; int l0 = strlen (rel); if (base->dir == 0) { @@ -825,7 +984,6 @@ static struct a_inode *lookup_child_aino static struct a_inode *lookup_child_aino_for_exnext (Unit *unit, struct a_inode *base, char *rel, uae_u32 *err) { struct a_inode *c = base->child; - char *p, *p2; int l0 = strlen (rel); *err = 0; @@ -863,24 +1021,23 @@ static struct a_inode *lookup_child_aino get_file_attrs (c); recycle_aino (unit, c); - TRACE((warning_buffer, "created aino %x, exnext\n", c->uniq)); + TRACE(("created aino %x, exnext\n", c->uniq)); } return c; } -static struct a_inode *get_aino(Unit* unit, struct a_inode *base, const char *rel, uae_u32 *err) +static struct a_inode *get_aino (Unit *unit, struct a_inode *base, const char *rel, uae_u32 *err) { char *tmp; char *p; - char *r; struct a_inode *curr; int i; *err = 0; - TRACE((warning_buffer, "get_path(%s,%s)\n", base->aname, rel)); + TRACE(("get_path(%s,%s)\n", base->aname, rel)); /* root-relative path? */ - for(i = 0; rel[i] && rel[i] != '/' && rel[i] != ':'; i++) + for (i = 0; rel[i] && rel[i] != '/' && rel[i] != ':'; i++) ; if (':' == rel[i]) rel += i+1; @@ -934,31 +1091,32 @@ static uae_u32 startup_handler (void) int i, namelen; char* devname = bstr1 (get_long (pkt + dp_Arg1) << 2); char* s; - Unit* unit; + Unit *unit; UnitInfo *uinfo; /* find UnitInfo with correct device name */ - s = strchr(devname, ':'); - if(s) + s = strchr (devname, ':'); + if (s) *s = '\0'; - for(i = 0; i < num_units; i++) { + for (i = 0; i < current_mountinfo->num_units; i++) { /* Hardfile volume name? */ - if (ui[i].volname == 0) + if (current_mountinfo->ui[i].volname == 0) continue; - if (ui[i].startup == arg2) + if (current_mountinfo->ui[i].startup == arg2) break; } - if(i == num_units || 0 != access(ui[i].rootdir, R_OK)) { - sprintf(warning_buffer, "Failed attempt to mount device\n", devname); - write_log (warning_buffer); + if (i == current_mountinfo->num_units + || access (current_mountinfo->ui[i].rootdir, R_OK) != 0) + { + write_log ("Failed attempt to mount device\n", devname); put_long (pkt + dp_Res1, DOS_FALSE); put_long (pkt + dp_Res2, ERROR_DEVICE_NOT_MOUNTED); return 1; } - uinfo = ui + i; + uinfo = current_mountinfo->ui + i; unit = (Unit *) xmalloc (sizeof (Unit)); unit->next = units; @@ -966,7 +1124,6 @@ static uae_u32 startup_handler (void) uinfo->self = unit; unit->volume = 0; - unit->reset_state = FS_STARTUP; unit->port = m68k_areg(regs, 5); unit->unit = unit_num++; @@ -1005,7 +1162,7 @@ static uae_u32 startup_handler (void) /* write_comm_pipe_int (unit->ui.unit_pipe, -1, 1);*/ - TRACE((warning_buffer, "**** STARTUP volume %s\n", unit->ui.volname)); + TRACE(("**** STARTUP volume %s\n", unit->ui.volname)); /* fill in our process in the device node */ put_long ((get_long (pkt + dp_Arg3) << 2) + 8, unit->port); @@ -1031,7 +1188,7 @@ static uae_u32 startup_handler (void) put_long (unit->volume + 40, (unit->volume + 44) >> 2); /* Name */ namelen = strlen (unit->ui.volname); put_byte (unit->volume + 44, namelen); - for(i = 0; i < namelen; i++) + for (i = 0; i < namelen; i++) put_byte (unit->volume + 45 + i, unit->ui.volname[i]); /* link into DOS list */ @@ -1045,70 +1202,52 @@ static uae_u32 startup_handler (void) return 0; } -#ifdef HAVE_STATFS static void -do_info(Unit* unit, dpacket packet, uaecptr info) +do_info (Unit *unit, dpacket packet, uaecptr info) { - struct statfs statbuf; -#if STATFS_NO_ARGS == 2 - if(-1 == statfs(unit->ui.rootdir, &statbuf)) -#else - if(-1 == statfs(unit->ui.rootdir, &statbuf, sizeof(struct statfs), 0)) -#endif - { + struct fs_usage fsu; + + if (get_fs_usage (unit->ui.rootdir, 0, &fsu) != 0) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, dos_errno ()); + return; } + fsu.fsu_blocks >>= 1; + fsu.fsu_bavail >>= 1; put_long(info, 0); /* errors */ put_long(info + 4, unit->unit); /* unit number */ put_long(info + 8, unit->ui.readonly ? 80 : 82); /* state */ - put_long(info + 12, statbuf.f_blocks); /* numblocks */ - put_long(info + 16, statbuf.f_blocks - statbuf.STATBUF_BAVAIL); /* inuse */ - put_long(info + 20, statbuf.f_bsize); /* bytesperblock */ + put_long(info + 12, fsu.fsu_blocks ); /* numblocks */ + put_long(info + 16, fsu.fsu_blocks - fsu.fsu_bavail); /* inuse */ + put_long(info + 20, 1024); /* bytesperblock */ put_long(info + 24, DISK_TYPE); /* disk type */ put_long(info + 28, unit->volume >> 2); /* volume node */ put_long(info + 32, 0); /* inuse */ PUT_PCK_RES1 (packet, DOS_TRUE); } -#else -static void -do_info(Unit* unit, dpacket packet, uaecptr info) -{ - put_long(info, 0); /* errors */ - put_long(info + 4, unit->unit); /* unit number */ - put_long(info + 8, unit->ui.readonly ? 80 : 82); /* state */ - put_long(info + 12, 256); /* numblocks */ - put_long(info + 16, 128); /* inuse */ - put_long(info + 20, 512); /* bytesperblock */ - put_long(info + 24, DISK_TYPE); /* disk type */ - put_long(info + 28, unit->volume >> 2); /* volume node */ - put_long(info + 32, 0); /* inuse */ - PUT_PCK_RES1 (packet, DOS_TRUE); -} -#endif static void -action_disk_info(Unit* unit, dpacket packet) +action_disk_info (Unit *unit, dpacket packet) { - TRACE((warning_buffer, "ACTION_DISK_INFO\n")); + TRACE(("ACTION_DISK_INFO\n")); do_info(unit, packet, GET_PCK_ARG1 (packet) << 2); } static void -action_info(Unit* unit, dpacket packet) +action_info (Unit *unit, dpacket packet) { - TRACE((warning_buffer, "ACTION_INFO\n")); + TRACE(("ACTION_INFO\n")); do_info(unit, packet, GET_PCK_ARG2 (packet) << 2); } -static void free_key (Unit *unit, Key*k) +static void free_key (Unit *unit, Key *k) { Key *k1; Key *prev = 0; for (k1 = unit->keys; k1; k1 = k1->next) { if (k == k1) { - if(prev) + if (prev) prev->next = k->next; else unit->keys = k->next; @@ -1123,12 +1262,12 @@ static void free_key (Unit *unit, Key*k) free(k); } -static Key *lookup_key(Unit *unit, uae_u32 uniq) +static Key *lookup_key (Unit *unit, uae_u32 uniq) { Key *k; /* It's hardly worthwhile to optimize this - most of the time there are * only one or zero keys. */ - for(k = unit->keys; k; k = k->next) { + for (k = unit->keys; k; k = k->next) { if (uniq == k->uniq) return k; } @@ -1143,9 +1282,9 @@ static Key *lookup_key(Unit *unit, uae_u return 0; } -static Key *new_key(Unit *unit) +static Key *new_key (Unit *unit) { - Key *k = (Key*) xmalloc(sizeof(Key)); + Key *k = (Key *) xmalloc(sizeof(Key)); k->uniq = ++unit->key_uniq; k->fd = -1; k->file_pos = 0; @@ -1156,28 +1295,28 @@ static Key *new_key(Unit *unit) } static void -dumplock(Unit *unit, uaecptr lock) +dumplock (Unit *unit, uaecptr lock) { struct a_inode *a; - TRACE((warning_buffer, "LOCK: 0x%lx", lock)); - if(!lock) { - TRACE((warning_buffer, "\n")); + TRACE(("LOCK: 0x%lx", lock)); + if (!lock) { + TRACE(("\n")); return; } - TRACE((warning_buffer, "{ next=0x%lx, mode=%ld, handler=0x%lx, volume=0x%lx, aino %lx ", + TRACE(("{ next=0x%lx, mode=%ld, handler=0x%lx, volume=0x%lx, aino %lx ", get_long(lock) << 2, get_long(lock+8), get_long(lock+12), get_long(lock+16), get_long(lock + 4))); a = lookup_aino (unit, get_long (lock + 4)); if (a == 0) { - TRACE((warning_buffer, "not found!")); + TRACE(("not found!")); } else { - TRACE((warning_buffer, "%s", a->nname)); + TRACE(("%s", a->nname)); } - TRACE((warning_buffer, " }\n")); + TRACE((" }\n")); } -static struct a_inode *find_aino(Unit* unit, uaecptr lock, const char *name, uae_u32 *err) +static struct a_inode *find_aino (Unit *unit, uaecptr lock, const char *name, uae_u32 *err) { struct a_inode *a; @@ -1187,20 +1326,20 @@ static struct a_inode *find_aino(Unit* u /* That's the best we can hope to do. */ a = get_aino (unit, &unit->rootnode, name, err); } else { - TRACE((warning_buffer, "aino: 0x%08lx", (unsigned long int)olda->uniq)); - TRACE((warning_buffer, " \"%s\"\n", olda->nname)); + TRACE(("aino: 0x%08lx", (unsigned long int)olda->uniq)); + TRACE((" \"%s\"\n", olda->nname)); a = get_aino (unit, olda, name, err); } } else { a = get_aino (unit, &unit->rootnode, name, err); } if (a) { - TRACE((warning_buffer, "aino=\"%s\"\n", a->nname)); + TRACE(("aino=\"%s\"\n", a->nname)); } return a; } -static uaecptr make_lock (Unit* unit, uae_u32 uniq, long mode) +static uaecptr make_lock (Unit *unit, uae_u32 uniq, long mode) { /* allocate lock from the list kept by the assembly code */ uaecptr lock; @@ -1222,10 +1361,9 @@ static uaecptr make_lock (Unit* unit, ua return lock; } -static void free_lock (Unit* unit, uaecptr lock) +static void free_lock (Unit *unit, uaecptr lock) { - Key *k; - if(!lock) + if (! lock) return; if (lock == get_long(unit->volume + 28) << 2) { @@ -1233,9 +1371,9 @@ static void free_lock (Unit* unit, uaecp } else { uaecptr current = get_long(unit->volume + 28); uaecptr next = 0; - while(current) { + while (current) { next = get_long(current << 2); - if(lock == next << 2) + if (lock == next << 2) break; current = next; } @@ -1247,7 +1385,7 @@ static void free_lock (Unit* unit, uaecp } static void -action_lock(Unit* unit, dpacket packet) +action_lock (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; uaecptr name = GET_PCK_ARG2 (packet) << 2; @@ -1256,11 +1394,11 @@ action_lock(Unit* unit, dpacket packet) uae_u32 err; if (mode != -2 && mode != -1) { - TRACE((warning_buffer, "Bad mode.\n")); + TRACE(("Bad mode.\n")); mode = -2; } - TRACE((warning_buffer, "ACTION_LOCK(0x%lx, \"%s\", %d)\n", lock, bstr (unit, name), mode)); + TRACE(("ACTION_LOCK(0x%lx, \"%s\", %d)\n", lock, bstr (unit, name), mode)); DUMPLOCK(unit, lock); a = find_aino (unit, lock, bstr (unit, name), &err); @@ -1281,11 +1419,11 @@ action_lock(Unit* unit, dpacket packet) PUT_PCK_RES1 (packet, make_lock (unit, a->uniq, mode) >> 2); } -static void action_free_lock (Unit* unit, dpacket packet) +static void action_free_lock (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; struct a_inode *a; - TRACE((warning_buffer, "ACTION_FREE_LOCK(0x%lx)\n", lock)); + TRACE(("ACTION_FREE_LOCK(0x%lx)\n", lock)); DUMPLOCK(unit, lock); a = lookup_aino (unit, get_long (lock + 4)); @@ -1305,14 +1443,14 @@ static void action_free_lock (Unit* unit } static void -action_dup_lock(Unit* unit, dpacket packet) +action_dup_lock (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; struct a_inode *a; - TRACE((warning_buffer, "ACTION_DUP_LOCK(0x%lx)\n", lock)); + TRACE(("ACTION_DUP_LOCK(0x%lx)\n", lock)); DUMPLOCK(unit, lock); - if(!lock) { + if (!lock) { PUT_PCK_RES1 (packet, 0); return; } @@ -1340,7 +1478,7 @@ const int secs_per_day = 24 * 60 * 60; const int diff = (8 * 365 + 2) * (24 * 60 * 60); static void -get_time(time_t t, long* days, long* mins, long* ticks) +get_time (time_t t, long* days, long* mins, long* ticks) { /* time_t is secs since 1-1-1970 */ /* days since 1-1-1978 */ @@ -1356,7 +1494,7 @@ get_time(time_t t, long* days, long* min } static time_t -put_time(long days, long mins, long ticks) +put_time (long days, long mins, long ticks) { time_t t; t = ticks / 50; @@ -1367,7 +1505,7 @@ put_time(long days, long mins, long tick return t; } -static void free_exkey(ExamineKey* ek) +static void free_exkey (ExamineKey *ek) { ek->aino = 0; ek->uniq = 0; @@ -1376,7 +1514,7 @@ static void free_exkey(ExamineKey* ek) } /* This is so sick... who invented ACTION_EXAMINE_NEXT? What did he THINK??? */ -static ExamineKey *new_exkey(Unit *unit, struct a_inode *aino) +static ExamineKey *new_exkey (Unit *unit, struct a_inode *aino) { uae_u32 uniq; uae_u32 oldest = 0xFFFFFFFF; @@ -1416,7 +1554,7 @@ static ExamineKey *new_exkey(Unit *unit, return ek; } -static ExamineKey *lookup_exkey(Unit *unit, uae_u32 uniq) +static ExamineKey *lookup_exkey (Unit *unit, uae_u32 uniq) { ExamineKey *ek; int i; @@ -1432,13 +1570,12 @@ static ExamineKey *lookup_exkey(Unit *un } static void -get_fileinfo(Unit *unit, dpacket packet, uaecptr info, struct a_inode *aino) +get_fileinfo (Unit *unit, dpacket packet, uaecptr info, struct a_inode *aino) { struct stat statbuf; long days, mins, ticks; int i, n; char *x; - uae_u32 err; /* No error checks - this had better work. */ stat (aino->nname, &statbuf); @@ -1457,7 +1594,7 @@ get_fileinfo(Unit *unit, dpacket packet, else x = aino->aname; } - TRACE((warning_buffer, "name=\"%s\"\n", x)); + TRACE(("name=\"%s\"\n", x)); n = strlen(x); if (n > 106) n = 106; @@ -1483,7 +1620,7 @@ get_fileinfo(Unit *unit, dpacket packet, PUT_PCK_RES1 (packet, DOS_TRUE); } -static void do_examine(Unit *unit, dpacket packet, ExamineKey* ek, uaecptr info) +static void do_examine (Unit *unit, dpacket packet, ExamineKey *ek, uaecptr info) { struct dirent de_space; struct dirent* de; @@ -1503,20 +1640,20 @@ static void do_examine(Unit *unit, dpack de = my_readdir (ek->dir, &de_space); while (de && (0 == strcmp(".", de->d_name) - || 0 == strcmp("..", de->d_name))) + || 0 == strcmp("..", de->d_name))) { de = my_readdir (ek->dir, &de_space); } if (!de) { - TRACE((warning_buffer, "no more entries\n")); + TRACE(("no more entries\n")); free_exkey (ek); PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, ERROR_NO_MORE_ENTRIES); return; } - TRACE((warning_buffer, "entry=\"%s\"\n", de->d_name)); + TRACE(("entry=\"%s\"\n", de->d_name)); aino = lookup_child_aino_for_exnext (unit, ek->aino, de->d_name, &err); if (err != 0) { write_log ("Severe problem in ExNext.\n"); @@ -1528,14 +1665,13 @@ static void do_examine(Unit *unit, dpack get_fileinfo (unit, packet, info, aino); } -static void action_examine_object (Unit* unit, dpacket packet) +static void action_examine_object (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; uaecptr info = GET_PCK_ARG2 (packet) << 2; - ExamineKey* ek; struct a_inode *aino = 0; - TRACE((warning_buffer, "ACTION_EXAMINE_OBJECT(0x%lx,0x%lx)\n", lock, info)); + TRACE(("ACTION_EXAMINE_OBJECT(0x%lx,0x%lx)\n", lock, info)); DUMPLOCK(unit, lock); if (lock != 0) @@ -1550,7 +1686,7 @@ static void action_examine_object (Unit* put_long(info, 0); } -static void action_examine_next(Unit* unit, dpacket packet) +static void action_examine_next (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; uaecptr info = GET_PCK_ARG2 (packet) << 2; @@ -1558,7 +1694,7 @@ static void action_examine_next(Unit* un ExamineKey *ek; uae_u32 uniq; - TRACE((warning_buffer, "ACTION_EXAMINE_NEXT(0x%lx,0x%lx)\n", lock, info)); + TRACE(("ACTION_EXAMINE_NEXT(0x%lx,0x%lx)\n", lock, info)); DUMPLOCK(unit, lock); if (lock != 0) @@ -1586,21 +1722,19 @@ static void action_examine_next(Unit* un do_examine(unit, packet, ek, info); } -static void do_find (Unit* unit, dpacket packet, int mode, int create, int fallback) +static void do_find (Unit *unit, dpacket packet, int mode, int create, int fallback) { uaecptr fh = GET_PCK_ARG1 (packet) << 2; uaecptr lock = GET_PCK_ARG2 (packet) << 2; uaecptr name = GET_PCK_ARG3 (packet) << 2; struct a_inode *aino; Key *k; - struct stat st; int fd; - int doserr; uae_u32 err; mode_t openmode; int aino_created = 0; - TRACE((warning_buffer, "ACTION_FIND_*(0x%lx,0x%lx,\"%s\",%d)\n", fh, lock, bstr (unit, name), mode)); + TRACE(("ACTION_FIND_*(0x%lx,0x%lx,\"%s\",%d)\n", fh, lock, bstr (unit, name), mode)); DUMPLOCK(unit, lock); aino = find_aino (unit, lock, bstr (unit, name), &err); @@ -1700,13 +1834,13 @@ static void do_find (Unit* unit, dpacket } static void -action_find_input(Unit* unit, dpacket packet) +action_find_input (Unit *unit, dpacket packet) { do_find(unit, packet, A_FIBF_READ|A_FIBF_WRITE, 0, 1); } static void -action_find_output(Unit* unit, dpacket packet) +action_find_output (Unit *unit, dpacket packet) { if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); @@ -1717,7 +1851,7 @@ action_find_output(Unit* unit, dpacket p } static void -action_find_write(Unit* unit, dpacket packet) +action_find_write (Unit *unit, dpacket packet) { if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); @@ -1728,10 +1862,10 @@ action_find_write(Unit* unit, dpacket pa } static void -action_end(Unit* unit, dpacket packet) +action_end (Unit *unit, dpacket packet) { Key *k; - TRACE((warning_buffer, "ACTION_END(0x%lx)\n", GET_PCK_ARG1 (packet))); + TRACE(("ACTION_END(0x%lx)\n", GET_PCK_ARG1 (packet))); k = lookup_key (unit, GET_PCK_ARG1 (packet)); if (k != 0) { @@ -1747,7 +1881,7 @@ action_end(Unit* unit, dpacket packet) } static void -action_read(Unit* unit, dpacket packet) +action_read (Unit *unit, dpacket packet) { Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); uaecptr addr = GET_PCK_ARG2 (packet); @@ -1759,7 +1893,7 @@ action_read(Unit* unit, dpacket packet) /* PUT_PCK_RES2 (packet, EINVAL); */ return; } - TRACE((warning_buffer, "ACTION_READ(%s,0x%lx,%ld)\n",k->aino->nname,addr,size)); + TRACE(("ACTION_READ(%s,0x%lx,%ld)\n",k->aino->nname,addr,size)); #ifdef RELY_ON_LOADSEG_DETECTION /* HACK HACK HACK HACK * Try to detect a LoadSeg() */ @@ -1789,11 +1923,10 @@ action_read(Unit* unit, dpacket packet) } } else { char *buf; - sprintf (warning_buffer, "unixfs warning: Bad pointer passed for read: %08x\n", addr); - write_log (warning_buffer); + write_log ("unixfs warning: Bad pointer passed for read: %08x\n", addr); /* ugh this is inefficient but easy */ buf = (char *)malloc(size); - if(!buf) { + if (!buf) { PUT_PCK_RES1 (packet, -1); PUT_PCK_RES2 (packet, ERROR_NO_FREE_STORE); return; @@ -1806,16 +1939,16 @@ action_read(Unit* unit, dpacket packet) } else { int i; PUT_PCK_RES1 (packet, actual); - for(i = 0; i < actual; i++) + for (i = 0; i < actual; i++) put_byte(addr + i, buf[i]); k->file_pos += actual; } - free(buf); + free (buf); } } static void -action_write(Unit* unit, dpacket packet) +action_write (Unit *unit, dpacket packet) { Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); uaecptr addr = GET_PCK_ARG2 (packet); @@ -1829,7 +1962,7 @@ action_write(Unit* unit, dpacket packet) return; } - TRACE((warning_buffer, "ACTION_WRITE(%s,0x%lx,%ld)\n",k->aino->nname,addr,size)); + TRACE(("ACTION_WRITE(%s,0x%lx,%ld)\n",k->aino->nname,addr,size)); if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); @@ -1854,13 +1987,13 @@ action_write(Unit* unit, dpacket packet) if (GET_PCK_RES1 (packet) >= 0) k->file_pos += GET_PCK_RES1 (packet); - free(buf); + free (buf); } static void -action_seek(Unit* unit, dpacket packet) +action_seek (Unit *unit, dpacket packet) { - Key* k = lookup_key (unit, GET_PCK_ARG1 (packet)); + Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); long pos = (uae_s32)GET_PCK_ARG2 (packet); long mode = (uae_s32)GET_PCK_ARG3 (packet); off_t res; @@ -1876,7 +2009,7 @@ action_seek(Unit* unit, dpacket packet) if (mode > 0) whence = SEEK_END; if (mode < 0) whence = SEEK_SET; - TRACE((warning_buffer, "ACTION_SEEK(%s,%d,%d)\n", k->aino->nname, pos, mode)); + TRACE(("ACTION_SEEK(%s,%d,%d)\n", k->aino->nname, pos, mode)); old = lseek (k->fd, 0, SEEK_CUR); res = lseek (k->fd, pos, whence); @@ -1890,16 +2023,15 @@ action_seek(Unit* unit, dpacket packet) } static void -action_set_protect(Unit* unit, dpacket packet) +action_set_protect (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG2 (packet) << 2; uaecptr name = GET_PCK_ARG3 (packet) << 2; uae_u32 mask = GET_PCK_ARG4 (packet); - mode_t mode; struct a_inode *a; uae_u32 err; - TRACE((warning_buffer, "ACTION_SET_PROTECT(0x%lx,\"%s\",0x%lx)\n", lock, bstr (unit, name), mask)); + TRACE(("ACTION_SET_PROTECT(0x%lx,\"%s\",0x%lx)\n", lock, bstr (unit, name), mask)); if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); @@ -1924,12 +2056,12 @@ action_set_protect(Unit* unit, dpacket p } static void -action_same_lock(Unit* unit, dpacket packet) +action_same_lock (Unit *unit, dpacket packet) { uaecptr lock1 = GET_PCK_ARG1 (packet) << 2; uaecptr lock2 = GET_PCK_ARG2 (packet) << 2; - TRACE((warning_buffer, "ACTION_SAME_LOCK(0x%lx,0x%lx)\n",lock1,lock2)); + TRACE(("ACTION_SAME_LOCK(0x%lx,0x%lx)\n",lock1,lock2)); DUMPLOCK(unit, lock1); DUMPLOCK(unit, lock2); if (!lock1 || !lock2) { @@ -1940,12 +2072,12 @@ action_same_lock(Unit* unit, dpacket pac } static void -action_parent(Unit* unit, dpacket packet) +action_parent (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; - struct a_inode *a, *olda; + struct a_inode *olda; - TRACE((warning_buffer, "ACTION_PARENT(0x%lx)\n",lock)); + TRACE(("ACTION_PARENT(0x%lx)\n",lock)); if (!lock) { PUT_PCK_RES1 (packet, 0); @@ -1976,14 +2108,14 @@ action_parent(Unit* unit, dpacket packet } static void -action_create_dir(Unit* unit, dpacket packet) +action_create_dir (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; uaecptr name = GET_PCK_ARG2 (packet) << 2; struct a_inode *aino; uae_u32 err; - TRACE((warning_buffer, "ACTION_CREATE_DIR(0x%lx,\"%s\")\n", lock, bstr (unit, name))); + TRACE(("ACTION_CREATE_DIR(0x%lx,\"%s\")\n", lock, bstr (unit, name))); if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); @@ -2022,14 +2154,13 @@ action_create_dir(Unit* unit, dpacket pa } static void -action_examine_fh(Unit* unit, dpacket packet) +action_examine_fh (Unit *unit, dpacket packet) { Key *k; - ExamineKey* ek; struct a_inode *aino = 0; uaecptr info = GET_PCK_ARG2 (packet) << 2; - TRACE((warning_buffer, "ACTION_EXAMINE_FH(0x%lx,0x%lx)\n", GET_PCK_ARG1 (packet), GET_PCK_ARG2 (packet) )); + TRACE(("ACTION_EXAMINE_FH(0x%lx,0x%lx)\n", GET_PCK_ARG1 (packet), GET_PCK_ARG2 (packet) )); k = lookup_key (unit, GET_PCK_ARG1 (packet)); if (k != 0) @@ -2049,10 +2180,8 @@ action_examine_fh(Unit* unit, dpacket pa * This implementation tries to mimic the behaviour of the Kick 3.1 ramdisk * (which seems to match the Autodoc description). */ static void -action_set_file_size(Unit* unit, dpacket packet) +action_set_file_size (Unit *unit, dpacket packet) { - int error = 0; - char chunk = 0; Key *k, *k1; off_t offset = GET_PCK_ARG2 (packet); long mode = (uae_s32)GET_PCK_ARG3 (packet); @@ -2061,7 +2190,7 @@ action_set_file_size(Unit* unit, dpacket if (mode > 0) whence = SEEK_END; if (mode < 0) whence = SEEK_SET; - TRACE((warning_buffer, "ACTION_SET_FILE_SIZE(0x%lx, %d, 0x%x)\n", GET_PCK_ARG1 (packet), offset, mode)); + TRACE(("ACTION_SET_FILE_SIZE(0x%lx, %d, 0x%x)\n", GET_PCK_ARG1 (packet), offset, mode)); k = lookup_key (unit, GET_PCK_ARG1 (packet)); if (k == 0) { @@ -2097,14 +2226,14 @@ action_set_file_size(Unit* unit, dpacket } static void -action_delete_object(Unit* unit, dpacket packet) +action_delete_object (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG1 (packet) << 2; uaecptr name = GET_PCK_ARG2 (packet) << 2; struct a_inode *a; uae_u32 err; - TRACE((warning_buffer, "ACTION_DELETE_OBJECT(0x%lx,\"%s\")\n", lock, bstr (unit, name))); + TRACE(("ACTION_DELETE_OBJECT(0x%lx,\"%s\")\n", lock, bstr (unit, name))); if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); @@ -2146,7 +2275,7 @@ action_delete_object(Unit* unit, dpacket } static void -action_set_date(Unit* unit, dpacket packet) +action_set_date (Unit *unit, dpacket packet) { uaecptr lock = GET_PCK_ARG2 (packet) << 2; uaecptr name = GET_PCK_ARG3 (packet) << 2; @@ -2155,9 +2284,9 @@ action_set_date(Unit* unit, dpacket pack struct utimbuf ut; uae_u32 err; - TRACE((warning_buffer, "ACTION_SET_DATE(0x%lx,\"%s\")\n", lock, bstr (unit, name))); + TRACE(("ACTION_SET_DATE(0x%lx,\"%s\")\n", lock, bstr (unit, name))); - if(unit->ui.readonly) { + if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); return; @@ -2175,7 +2304,7 @@ action_set_date(Unit* unit, dpacket pack } static void -action_rename_object(Unit* unit, dpacket packet) +action_rename_object (Unit *unit, dpacket packet) { uaecptr lock1 = GET_PCK_ARG1 (packet) << 2; uaecptr name1 = GET_PCK_ARG2 (packet) << 2; @@ -2184,10 +2313,10 @@ action_rename_object(Unit* unit, dpacket struct a_inode *a1, *a2; uae_u32 err1, err2; - TRACE((warning_buffer, "ACTION_RENAME_OBJECT(0x%lx,\"%s\",", lock1, bstr (unit, name1))); - TRACE((warning_buffer, "0x%lx,\"%s\")\n", lock2, bstr (unit, name2))); + TRACE(("ACTION_RENAME_OBJECT(0x%lx,\"%s\",", lock1, bstr (unit, name1))); + TRACE(("0x%lx,\"%s\")\n", lock2, bstr (unit, name2))); - if(unit->ui.readonly) { + if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); return; @@ -2214,7 +2343,7 @@ action_rename_object(Unit* unit, dpacket } /* @@@ what should we do if there are locks on a1? */ - if(-1 == rename(a1->nname, a2->nname)) { + if (-1 == rename(a1->nname, a2->nname)) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, dos_errno()); return; @@ -2225,21 +2354,21 @@ action_rename_object(Unit* unit, dpacket } static void -action_current_volume(Unit* unit, dpacket packet) +action_current_volume (Unit *unit, dpacket packet) { PUT_PCK_RES1 (packet, unit->volume >> 2); } static void -action_rename_disk(Unit* unit, dpacket packet) +action_rename_disk (Unit *unit, dpacket packet) { uaecptr name = GET_PCK_ARG1 (packet) << 2; int i; int namelen; - TRACE((warning_buffer, "ACTION_RENAME_DISK(\"%s\")\n", bstr (unit, name))); + TRACE(("ACTION_RENAME_DISK(\"%s\")\n", bstr (unit, name))); - if(unit->ui.readonly) { + if (unit->ui.readonly) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, ERROR_DISK_WRITE_PROTECTED); return; @@ -2249,25 +2378,25 @@ action_rename_disk(Unit* unit, dpacket p namelen = get_byte (name); name++; free (unit->ui.volname); unit->ui.volname = (char *) xmalloc (namelen + 1); - for(i = 0; i < namelen; i++, name++) + for (i = 0; i < namelen; i++, name++) unit->ui.volname[i] = get_byte (name); unit->ui.volname[i] = 0; put_byte (unit->volume + 44, namelen); - for(i = 0; i < namelen; i++) + for (i = 0; i < namelen; i++) put_byte (unit->volume + 45 + i, unit->ui.volname[i]); PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_is_filesystem(Unit* unit, dpacket packet) +action_is_filesystem (Unit *unit, dpacket packet) { PUT_PCK_RES1 (packet, DOS_TRUE); } static void -action_flush(Unit* unit, dpacket packet) +action_flush (Unit *unit, dpacket packet) { /* sync(); */ /* pretty drastic, eh */ PUT_PCK_RES1 (packet, DOS_TRUE); @@ -2279,6 +2408,7 @@ static uae_sem_t singlethread_int_sem; static uae_u32 exter_int_helper (void) { + UnitInfo *uip = current_mountinfo->ui; static int unit_no; switch (m68k_dreg (regs, 0)) { @@ -2324,16 +2454,16 @@ static uae_u32 exter_int_helper (void) * Take care not to dereference self for units that didn't have their * startup packet sent. */ for (;;) { - if (unit_no >= num_units) + if (unit_no >= current_mountinfo->num_units) return 0; - if (ui[unit_no].self != 0 - && ui[unit_no].self->cmds_acked == ui[unit_no].self->cmds_complete - && ui[unit_no].self->cmds_acked != ui[unit_no].self->cmds_sent) + if (uip[unit_no].self != 0 + && uip[unit_no].self->cmds_acked == uip[unit_no].self->cmds_complete + && uip[unit_no].self->cmds_acked != uip[unit_no].self->cmds_sent) break; unit_no++; } - ui[unit_no].self->cmds_acked = ui[unit_no].self->cmds_sent; - return ui[unit_no++].self->port; + uip[unit_no].self->cmds_acked = uip[unit_no].self->cmds_sent; + return uip[unit_no++].self->port; case 3: /* Look up a message for a port. */ @@ -2359,35 +2489,35 @@ static int handle_packet (Unit *unit, dp uae_s32 type = GET_PCK_TYPE (pck); PUT_PCK_RES2 (pck, 0); switch (type) { - case ACTION_LOCATE_OBJECT: action_lock(unit, pck); break; - case ACTION_FREE_LOCK: action_free_lock(unit, pck); break; - case ACTION_COPY_DIR: action_dup_lock(unit, pck); break; - case ACTION_DISK_INFO: action_disk_info(unit, pck); break; - case ACTION_INFO: action_info(unit, pck); break; - case ACTION_EXAMINE_OBJECT: action_examine_object(unit, pck); break; - case ACTION_EXAMINE_NEXT: action_examine_next(unit, pck); break; - case ACTION_FIND_INPUT: action_find_input(unit, pck); break; - case ACTION_FIND_WRITE: action_find_write(unit, pck); break; - case ACTION_FIND_OUTPUT: action_find_output(unit, pck); break; - case ACTION_END: action_end(unit, pck); break; - case ACTION_READ: action_read(unit, pck); break; - case ACTION_WRITE: action_write(unit, pck); break; - case ACTION_SEEK: action_seek(unit, pck); break; - case ACTION_SET_PROTECT: action_set_protect(unit, pck); break; - case ACTION_SAME_LOCK: action_same_lock(unit, pck); break; - case ACTION_PARENT: action_parent(unit, pck); break; - case ACTION_CREATE_DIR: action_create_dir(unit, pck); break; - case ACTION_DELETE_OBJECT: action_delete_object(unit, pck); break; - case ACTION_RENAME_OBJECT: action_rename_object(unit, pck); break; - case ACTION_SET_DATE: action_set_date(unit, pck); break; - case ACTION_CURRENT_VOLUME: action_current_volume(unit, pck); break; - case ACTION_RENAME_DISK: action_rename_disk(unit, pck); break; - case ACTION_IS_FILESYSTEM: action_is_filesystem(unit, pck); break; - case ACTION_FLUSH: action_flush(unit, pck); break; + case ACTION_LOCATE_OBJECT: action_lock (unit, pck); break; + case ACTION_FREE_LOCK: action_free_lock (unit, pck); break; + case ACTION_COPY_DIR: action_dup_lock (unit, pck); break; + case ACTION_DISK_INFO: action_disk_info (unit, pck); break; + case ACTION_INFO: action_info (unit, pck); break; + case ACTION_EXAMINE_OBJECT: action_examine_object (unit, pck); break; + case ACTION_EXAMINE_NEXT: action_examine_next (unit, pck); break; + case ACTION_FIND_INPUT: action_find_input (unit, pck); break; + case ACTION_FIND_WRITE: action_find_write (unit, pck); break; + case ACTION_FIND_OUTPUT: action_find_output (unit, pck); break; + case ACTION_END: action_end (unit, pck); break; + case ACTION_READ: action_read (unit, pck); break; + case ACTION_WRITE: action_write (unit, pck); break; + case ACTION_SEEK: action_seek (unit, pck); break; + case ACTION_SET_PROTECT: action_set_protect (unit, pck); break; + case ACTION_SAME_LOCK: action_same_lock (unit, pck); break; + case ACTION_PARENT: action_parent (unit, pck); break; + case ACTION_CREATE_DIR: action_create_dir (unit, pck); break; + case ACTION_DELETE_OBJECT: action_delete_object (unit, pck); break; + case ACTION_RENAME_OBJECT: action_rename_object (unit, pck); break; + case ACTION_SET_DATE: action_set_date (unit, pck); break; + case ACTION_CURRENT_VOLUME: action_current_volume (unit, pck); break; + case ACTION_RENAME_DISK: action_rename_disk (unit, pck); break; + case ACTION_IS_FILESYSTEM: action_is_filesystem (unit, pck); break; + case ACTION_FLUSH: action_flush (unit, pck); break; /* 2.0+ packet types */ - case ACTION_SET_FILE_SIZE: action_set_file_size(unit, pck); break; - case ACTION_EXAMINE_FH: action_examine_fh(unit, pck); break; + case ACTION_SET_FILE_SIZE: action_set_file_size (unit, pck); break; + case ACTION_EXAMINE_FH: action_examine_fh (unit, pck); break; /* unsupported packets */ case ACTION_LOCK_RECORD: @@ -2403,7 +2533,7 @@ static int handle_packet (Unit *unit, dp case ACTION_ADD_NOTIFY: case ACTION_REMOVE_NOTIFY: default: - TRACE((warning_buffer, "*** UNSUPPORTED PACKET %ld\n", type)); + TRACE(("*** UNSUPPORTED PACKET %ld\n", type)); return 0; } return 1; @@ -2423,13 +2553,13 @@ static void *filesys_penguin (void *unit msg = (uae_u8 *)read_comm_pipe_pvoid_blocking (ui->unit_pipe); morelocks = (uae_u32)read_comm_pipe_int_blocking (ui->unit_pipe); - if (ui->self->reset_state == FS_GO_DOWN) { + if (ui->reset_state == FS_GO_DOWN) { if (pck != 0) continue; /* Death message received. */ - uae_sem_post (&ui->self->reset_sync_sem); - /* No more messages should arrive until we restart. */ - continue; + uae_sem_post (&ui->reset_sync_sem); + /* Die. */ + return 0; } put_long (get_long (morelocks), get_long (ui->self->locklist)); @@ -2456,7 +2586,7 @@ static void *filesys_penguin (void *unit #endif /* Talk about spaghetti code... */ -static uae_u32 filesys_handler(void) +static uae_u32 filesys_handler (void) { Unit *unit = find_unit (m68k_areg (regs, 5)); uaecptr packet_addr = m68k_dreg (regs, 3); @@ -2470,9 +2600,11 @@ static uae_u32 filesys_handler(void) pck = get_real_address (packet_addr); msg = get_real_address (message_addr); +#if 0 if (unit->reset_state == FS_GO_DOWN) /* You might as well queue it, if you live long enough */ return 1; +#endif do_put_mem_long ((uae_u32 *)(msg + 4), -1); if (!unit || !unit->volume) { @@ -2502,45 +2634,76 @@ static uae_u32 filesys_handler(void) PUT_PCK_RES1 (pck, DOS_FALSE); PUT_PCK_RES2 (pck, ERROR_ACTION_NOT_KNOWN); } - TRACE((warning_buffer, "reply: %8lx, %ld\n", GET_PCK_RES1 (pck), GET_PCK_RES2 (pck))); + TRACE(("reply: %8lx, %ld\n", GET_PCK_RES1 (pck), GET_PCK_RES2 (pck))); error2: return 0; } +void filesys_start_threads (void) +{ + UnitInfo *uip; + int i; + + current_mountinfo = dup_mountinfo (currprefs.mountinfo); + + reset_uaedevices (); + + uip = current_mountinfo->ui; + for (i = 0; i < current_mountinfo->num_units; i++) { + uip[i].unit_pipe = 0; + uip[i].devno = get_new_device (&uip[i].devname, &uip[i].devname_amiga); + +#ifdef UAE_FILESYS_THREADS + if (! is_hardfile (current_mountinfo, i)) { + uip[i].unit_pipe = (smp_comm_pipe *)xmalloc (sizeof (smp_comm_pipe)); + uip[i].back_pipe = (smp_comm_pipe *)xmalloc (sizeof (smp_comm_pipe)); + init_comm_pipe (uip[i].unit_pipe, 50, 3); + init_comm_pipe (uip[i].back_pipe, 50, 1); + start_penguin (filesys_penguin, (void *)(uip + i), &uip[i].tid); + } +#endif + } +} + void filesys_reset (void) { Unit *u, *u1; int i; - for (i = 0; i < num_units; i++) { - ui[i].self = 0; - } + /* We get called once from customreset at the beginning of the program + * before filesys_start_threads has been called. Survive that. */ + if (current_mountinfo == 0) + return; - for(u = units; u; u = u1) { + for (u = units; u; u = u1) { u1 = u->next; free (u); } unit_num = 0; units = 0; + + free_mountinfo (current_mountinfo); + current_mountinfo = 0; } void filesys_prepare_reset (void) { - Unit *u, *u1; + UnitInfo *uip = current_mountinfo->ui; + Unit *u; int i; #ifdef UAE_FILESYS_THREADS - for (i = 0; i < num_units; i++) { - if (ui[i].self != 0) { - uae_sem_init (&ui[i].self->reset_sync_sem, 0, 0); - ui[i].self->reset_state = FS_GO_DOWN; + for (i = 0; i < current_mountinfo->num_units; i++) { + if (uip[i].unit_pipe != 0) { + uae_sem_init (&uip[i].reset_sync_sem, 0, 0); + uip[i].reset_state = FS_GO_DOWN; /* send death message */ - write_comm_pipe_int (ui[i].unit_pipe, 0, 0); - write_comm_pipe_int (ui[i].unit_pipe, 0, 0); - write_comm_pipe_int (ui[i].unit_pipe, 0, 1); - uae_sem_wait (&ui[i].self->reset_sync_sem); + write_comm_pipe_int (uip[i].unit_pipe, 0, 0); + write_comm_pipe_int (uip[i].unit_pipe, 0, 0); + write_comm_pipe_int (uip[i].unit_pipe, 0, 1); + uae_sem_wait (&uip[i].reset_sync_sem); } } #endif @@ -2557,18 +2720,18 @@ void filesys_prepare_reset (void) } } -static uae_u32 filesys_diagentry(void) +static uae_u32 filesys_diagentry (void) { uaecptr resaddr = m68k_areg(regs, 2) + 0x10; - TRACE ((warning_buffer, "filesystem: diagentry called\n")); + TRACE (("filesystem: diagentry called\n")); filesys_configdev = m68k_areg(regs, 3); do_put_mem_long ((uae_u32 *)(filesysory + 0x2100), EXPANSION_explibname); do_put_mem_long ((uae_u32 *)(filesysory + 0x2104), filesys_configdev); do_put_mem_long ((uae_u32 *)(filesysory + 0x2108), EXPANSION_doslibname); - do_put_mem_long ((uae_u32 *)(filesysory + 0x210c), num_units); + do_put_mem_long ((uae_u32 *)(filesysory + 0x210c), current_mountinfo->num_units); uae_sem_init (&singlethread_int_sem, 0, 1); if (ROM_hardfile_resid != 0) { @@ -2585,7 +2748,6 @@ static uae_u32 filesys_diagentry(void) } resaddr += 0x1A; - filesys_reset (); /* The good thing about this function is that it always gets called * when we boot. So we could put all sorts of stuff that wants to be done * here. */ @@ -2595,37 +2757,37 @@ static uae_u32 filesys_diagentry(void) /* Remember a pointer AmigaOS gave us so we can later use it to identify * which unit a given startup message belongs to. */ -static uae_u32 filesys_dev_remember(void) +static uae_u32 filesys_dev_remember (void) { int unit_no = m68k_dreg (regs, 6); uaecptr devicenode = m68k_areg (regs, 3); - ui[unit_no].startup = get_long (devicenode + 28); + current_mountinfo->ui[unit_no].startup = get_long (devicenode + 28); return devicenode; } /* Fill in per-unit fields of a parampacket */ -static uae_u32 filesys_dev_storeinfo(void) +static uae_u32 filesys_dev_storeinfo (void) { + UnitInfo *uip = current_mountinfo->ui; int unit_no = m68k_dreg (regs, 6); uaecptr parmpacket = m68k_areg (regs, 0); - int is_hardfile = ui[unit_no].volname == 0; - put_long (parmpacket, ui[unit_no].devname_amiga); - put_long (parmpacket + 4, is_hardfile ? ROM_hardfile_resname : fsdevname); - put_long (parmpacket + 8, ui[unit_no].devno); + put_long (parmpacket, current_mountinfo->ui[unit_no].devname_amiga); + put_long (parmpacket + 4, is_hardfile (current_mountinfo, unit_no) ? ROM_hardfile_resname : fsdevname); + put_long (parmpacket + 8, uip[unit_no].devno); put_long (parmpacket + 12, 0); /* Device flags */ put_long (parmpacket + 16, 16); /* Env. size */ put_long (parmpacket + 20, 128); /* 512 bytes per block */ put_long (parmpacket + 24, 0); /* unused */ - put_long (parmpacket + 28, ui[unit_no].hf.surfaces); /* heads */ + put_long (parmpacket + 28, uip[unit_no].hf.surfaces); /* heads */ put_long (parmpacket + 32, 0); /* unused */ - put_long (parmpacket + 36, ui[unit_no].hf.secspertrack); /* sectors per track */ - put_long (parmpacket + 40, ui[unit_no].hf.reservedblocks); /* reserved blocks */ + put_long (parmpacket + 36, uip[unit_no].hf.secspertrack); /* sectors per track */ + put_long (parmpacket + 40, uip[unit_no].hf.reservedblocks); /* reserved blocks */ put_long (parmpacket + 44, 0); /* unused */ put_long (parmpacket + 48, 0); /* interleave */ put_long (parmpacket + 52, 0); /* lowCyl */ - put_long (parmpacket + 56, ui[unit_no].hf.nrcyls - 1); /* hiCyl */ + put_long (parmpacket + 56, uip[unit_no].hf.nrcyls - 1); /* hiCyl */ put_long (parmpacket + 60, 0); /* Number of buffers */ put_long (parmpacket + 64, 0); /* Buffer mem type */ put_long (parmpacket + 68, 0x7FFFFFFF); /* largest transfer */ @@ -2634,27 +2796,7 @@ static uae_u32 filesys_dev_storeinfo(voi put_long (parmpacket + 80, 0x444f5300); /* DOS\0 */ put_long (parmpacket + 84, 0); /* pad */ - return is_hardfile; -} - -/* Called exactly once, at the time we know that we are actually going - * to run the emulator. */ -void filesys_start_threads (void) -{ - int i; - for (i = 0; i < num_units; i++) { - int is_hardfile = ui[i].volname == 0; - ui[i].unit_pipe = 0; -#ifdef UAE_FILESYS_THREADS - if (!is_hardfile) { - ui[i].unit_pipe = (smp_comm_pipe *)xmalloc (sizeof (smp_comm_pipe)); - ui[i].back_pipe = (smp_comm_pipe *)xmalloc (sizeof (smp_comm_pipe)); - init_comm_pipe (ui[i].unit_pipe, 50, 3); - init_comm_pipe (ui[i].back_pipe, 50, 1); - start_penguin (filesys_penguin, (void *)(ui + i), &ui[i].tid); - } -#endif - } + return is_hardfile (current_mountinfo, unit_no); } void filesys_install (void) @@ -2662,45 +2804,41 @@ void filesys_install (void) int i; uaecptr loop; - TRACE ((warning_buffer, "Installing filesystem\n")); + TRACE (("Installing filesystem\n")); ROM_filesys_resname = ds("UAEunixfs.resource"); ROM_filesys_resid = ds("UAE unixfs 0.4"); - fsdevname = ds("uae.device"); /* does not really exist */ - - for(i = 0; i < num_units; i++) { - ui[i].devno = get_new_device(&ui[i].devname, &ui[i].devname_amiga); - } + fsdevname = ds ("uae.device"); /* does not really exist */ ROM_filesys_diagentry = here(); calltrap (deftrap(filesys_diagentry)); dw(RTS); loop = here (); /* Special trap for the assembly make_dev routine */ - org(0xF0FF20); + org (0xF0FF20); calltrap (deftrap (filesys_dev_remember)); - dw(RTS); + dw (RTS); - org(0xF0FF28); + org (0xF0FF28); calltrap (deftrap (filesys_dev_storeinfo)); - dw(RTS); + dw (RTS); - org(0xF0FF30); + org (0xF0FF30); calltrap (deftrap (filesys_handler)); - dw(RTS); + dw (RTS); - org(0xF0FF40); + org (0xF0FF40); calltrap (deftrap (startup_handler)); - dw(RTS); + dw (RTS); - org(0xF0FF50); + org (0xF0FF50); calltrap (deftrap (exter_int_helper)); - dw(RTS); + dw (RTS); - org(0xF0FF70); + org (0xF0FF70); calltrap (deftrap (mousehack_helper)); - dw(RTS); + dw (RTS); org (loop); }