--- uae/src/filesys.c 2018/04/24 17:05:49 1.1.1.15 +++ uae/src/filesys.c 2018/04/24 17:16:47 1.1.1.21 @@ -27,7 +27,6 @@ #include "sysconfig.h" #include "sysdeps.h" -#include "config.h" #include "threaddep/thread.h" #include "options.h" #include "uae.h" @@ -37,14 +36,13 @@ #include "newcpu.h" #include "filesys.h" #include "autoconf.h" -#include "compiler.h" #include "fsusage.h" #include "native2amiga.h" #include "scsidev.h" #include "fsdb.h" -/* #define TRACING_ENABLED */ -#ifdef TRACING_ENABLED +#define TRACING_ENABLED 0 +#if TRACING_ENABLED #define TRACE(x) do { write_log x; } while(0) #define DUMPLOCK(u,x) dumplock(u,x) #else @@ -120,7 +118,7 @@ typedef struct { char *rootdir; /* root unix directory */ int readonly; /* disallow write access? */ int devno; - + struct hardfiledata hf; /* Threading stuff */ @@ -184,7 +182,7 @@ char *get_filesys_unit (struct uaedev_mo 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; @@ -354,7 +352,8 @@ void write_filesys_config (struct uaedev } else { fprintf (f, "hardfile=%s,%d,%d,%d,%d,%s\n", uip[i].readonly ? "ro" : "rw", uip[i].hf.secspertrack, - uip[i].hf.surfaces, uip[i].hf.reservedblocks, 512, str); + uip[i].hf.surfaces, uip[i].hf.reservedblocks, + uip[i].hf.blocksize, str); } free (str); } @@ -601,7 +600,7 @@ find_unit (uaecptr port) return u; } - + static void prepare_for_open (char *name) { #if 0 @@ -659,27 +658,41 @@ static void recycle_aino (Unit *unit, a_ /* Reap a few. */ int i = 0; while (i < 50) { + a_inode *parent = unit->rootnode.prev->parent; a_inode **aip; - aip = &unit->rootnode.prev->parent->child; - for (;;) { - a_inode *aino = *aip; - if (aino == 0) - break; - - /* Not recyclable if next == 0 (i.e., not chained into - recyclable list), or if parent directory is being - ExNext()ed. */ - if (aino->next == 0 || aino->parent->locked_children) - aip = &aino->sibling; - else { - if (aino->shlock > 0 || aino->elock) - write_log ("panic: freeing locked a_inode!\n"); - - de_recycle_aino (unit, aino); - dispose_aino (unit, aip, aino); - i++; + aip = &parent->child; + + if (! parent->locked_children) { + for (;;) { + a_inode *aino = *aip; + if (aino == 0) + break; + + /* Not recyclable if next == 0 (i.e., not chained into + recyclable list), or if parent directory is being + ExNext()ed. */ + if (aino->next == 0) { + aip = &aino->sibling; + } else { + if (aino->shlock > 0 || aino->elock) + write_log ("panic: freeing locked a_inode!\n"); + + de_recycle_aino (unit, aino); + dispose_aino (unit, aip, aino); + i++; + } } } + /* In the previous loop, we went through all children of one + parent. Re-arrange the recycled list so that we'll find a + different parent the next time around. */ + do { + unit->rootnode.next->prev = unit->rootnode.prev; + unit->rootnode.prev->next = unit->rootnode.next; + unit->rootnode.next = unit->rootnode.prev; + unit->rootnode.prev = unit->rootnode.prev->prev; + unit->rootnode.prev->next = unit->rootnode.next->prev = &unit->rootnode; + } while (unit->rootnode.prev->parent == parent); } #if 0 { @@ -706,7 +719,7 @@ static void update_child_names (Unit *un char *name_start; char *new_name; char dirsep[2] = { FSDB_DIR_SEPARATOR, '\0' }; - + a->parent = parent; name_start = strrchr (a->nname, FSDB_DIR_SEPARATOR); if (name_start == 0) { @@ -735,7 +748,6 @@ static void move_aino_children (Unit *un static void delete_aino (Unit *unit, a_inode *aino) { a_inode **aip; - int hash; TRACE(("deleting aino %x\n", aino->uniq)); @@ -746,13 +758,17 @@ static void delete_aino (Unit *unit, a_i /* If any ExKeys are currently pointing at us, advance them. */ if (aino->parent->exnext_count > 0) { int i; + TRACE(("entering exkey validation\n")); for (i = 0; i < EXKEYS; i++) { ExamineKey *k = unit->examine_keys + i; if (k->uniq == 0) continue; if (k->aino == aino->parent) { - if (k->curr_file == aino) + TRACE(("Same parent found for %d\n", i)); + if (k->curr_file == aino) { k->curr_file = aino->sibling; + TRACE(("Advancing curr_file\n")); + } } } } @@ -790,9 +806,14 @@ static a_inode *lookup_sub (a_inode *dir } cp = &c->sibling; } - *cp = c->sibling; - c->sibling = dir->child; - dir->child = c; + if (! dir->locked_children) { + /* Move to the front to speed up repeated lookups. Don't do this if + an ExNext is going on in this directory, or we'll terminally + confuse it. */ + *cp = c->sibling; + c->sibling = dir->child; + dir->child = c; + } return retval; } @@ -841,7 +862,7 @@ static char *get_nname (Unit *unit, a_in char *p = 0; *modified_rel = 0; - + /* If we have a mapping of some other aname to "rel", we must pretend * it does not exist. * This can happen for example if an Amiga program creates a @@ -874,7 +895,7 @@ static char *create_nname (Unit *unit, a char *p; /* We are trying to create a file called REL. */ - + /* If the name is used otherwise in the directory (or globally), we * need a new unique nname. */ if (fsdb_name_invalid (rel) || fsdb_used_as_nname (base, rel)) { @@ -967,7 +988,7 @@ static a_inode *new_child_aino (Unit *un init_child_aino (unit, base, aino); recycle_aino (unit, aino); - TRACE(("created aino %x, lookup\n", aino->uniq)); + TRACE(("created aino %x, lookup, amigaos_mode %d\n", aino->uniq, aino->amigaos_mode)); return aino; } @@ -1245,7 +1266,7 @@ static void do_info (Unit *unit, dpacket packet, uaecptr info) { 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 ()); @@ -1681,7 +1702,10 @@ get_fileinfo (Unit *unit, dpacket packet else { TRACE(("comment=\"%s\"\n", aino->comment)); i = 144; - n = strlen (x = aino->comment); + x = aino->comment; + if (! x) + x = ""; + n = strlen (x); if (n > 78) n = 78; put_byte (info + i, n); i++; @@ -1730,6 +1754,8 @@ static void populate_directory (Unit *un base->locked_children++; unit->total_locked_ainos++; } + TRACE(("Populating directory, child %p, locked_children %d\n", + base->child, base->locked_children)); for (;;) { struct dirent de_space; struct dirent *de; @@ -1751,13 +1777,13 @@ static void populate_directory (Unit *un static void do_examine (Unit *unit, dpacket packet, ExamineKey *ek, uaecptr info) { - a_inode *aino; - if (ek->curr_file == 0) goto no_more_entries; get_fileinfo (unit, packet, info, ek->curr_file); ek->curr_file = ek->curr_file->sibling; + TRACE (("curr_file set to %p %s\n", ek->curr_file, + ek->curr_file ? ek->curr_file->aname : "NULL")); return; no_more_entries: @@ -1790,14 +1816,19 @@ static void action_examine_next (Unit *u } else if (uniq == 0xFFFFFFFE) goto no_more_entries; else if (uniq == 0xFFFFFFFF) { + TRACE(("Creating new ExKey\n")); ek = new_exkey (unit, aino); if (ek) { if (aino->exnext_count++ == 0) populate_directory (unit, aino); } ek->curr_file = aino->child; - } else + TRACE(("Initial curr_file: %p %s\n", ek->curr_file, + ek->curr_file ? ek->curr_file->aname : "NULL")); + } else { + TRACE(("Looking up ExKey\n")); ek = lookup_exkey (unit, get_long (info)); + } if (ek == 0) { write_log ("Couldn't find a matching ExKey. Prepare for trouble.\n"); goto no_more_entries; @@ -1948,9 +1979,9 @@ action_fh_from_lock (Unit *unit, dpacket mode = aino->amigaos_mode; /* Use same mode for opened filehandle as existing Lock() */ prepare_for_open (aino->nname); - - openmode = (((mode & A_FIBF_READ) == 0 ? O_WRONLY - : (mode & A_FIBF_WRITE) == 0 ? O_RDONLY + TRACE ((" mode is %d\n", mode)); + openmode = (((mode & A_FIBF_READ) ? O_WRONLY + : (mode & A_FIBF_WRITE) ? O_RDONLY : O_RDWR)); /* the files on CD really can have the write-bit set. */ @@ -2158,6 +2189,22 @@ action_seek (Unit *unit, dpacket packet) TRACE(("ACTION_SEEK(%s,%d,%d)\n", k->aino->nname, pos, mode)); old = lseek (k->fd, 0, SEEK_CUR); + { + uae_s32 temppos; + long filesize = lseek (k->fd, 0, SEEK_END); + lseek (k->fd, old, SEEK_SET); + + if (whence == SEEK_CUR) temppos = old + pos; + if (whence == SEEK_SET) temppos = pos; + if (whence == SEEK_END) temppos = filesize + pos; + if (filesize < temppos) { + res = -1; + PUT_PCK_RES1 (packet,res); + PUT_PCK_RES2 (packet, ERROR_SEEK_ERROR); + return; + } + } + res = lseek (k->fd, pos, whence); if (-1 == res) { @@ -2267,7 +2314,7 @@ action_change_mode (Unit *unit, dpacket /* will be CHANGE_FH or CHANGE_LOCK value */ long type = GET_PCK_ARG1 (packet); /* either a file-handle or lock */ - uaecptr object = GET_PCK_ARG2 (packet) << 2; + uaecptr object = GET_PCK_ARG2 (packet) << 2; /* will be EXCLUSIVE_LOCK/SHARED_LOCK if CHANGE_LOCK, * or MODE_OLDFILE/MODE_NEWFILE/MODE_READWRITE if CHANGE_FH */ long mode = GET_PCK_ARG3 (packet); @@ -3004,6 +3051,14 @@ static int get_new_device (char **devnam return result; } +static void init_filesys_diagentry (void) +{ + 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), current_mountinfo->num_units); +} + void filesys_start_threads (void) { UnitInfo *uip; @@ -3012,7 +3067,7 @@ void filesys_start_threads (void) 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; @@ -3050,6 +3105,16 @@ void filesys_reset (void) current_mountinfo = 0; } +static void free_all_ainos (Unit *u, a_inode *parent) +{ + a_inode *a; + while (a = parent->child) { + free_all_ainos (u, a); + dispose_aino (u, &parent->child, a); + } +} + + void filesys_prepare_reset (void) { UnitInfo *uip = current_mountinfo->ui; @@ -3071,13 +3136,9 @@ void filesys_prepare_reset (void) #endif u = units; while (u != 0) { - while (u->rootnode.next != &u->rootnode) { - a_inode *b; - a_inode *a = u->rootnode.next; - u->rootnode.next = a->next; - de_recycle_aino (u, a); - dispose_aino (u, &b, a); - } + free_all_ainos (u, &u->rootnode); + u->rootnode.next = u->rootnode.prev = &u->rootnode; + u->aino_cache_size = 0; u = u->next; } } @@ -3092,10 +3153,7 @@ static uae_u32 filesys_diagentry (void) 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), current_mountinfo->num_units); + init_filesys_diagentry (); uae_sem_init (&singlethread_int_sem, 0, 1); if (ROM_hardfile_resid != 0) { @@ -3112,7 +3170,7 @@ static uae_u32 filesys_diagentry (void) } resaddr += 0x1A; tmp = resaddr; - + /* 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.