--- uae/src/filesys.c 2018/04/24 16:48:50 1.1.1.8 +++ uae/src/filesys.c 2018/04/24 17:00:19 1.1.1.12 @@ -33,7 +33,6 @@ #include "uae.h" #include "memory.h" #include "custom.h" -#include "readcpu.h" #include "newcpu.h" #include "filesys.h" #include "autoconf.h" @@ -60,7 +59,7 @@ static long dos_errno(void) case ENOMEM: return ERROR_NO_FREE_STORE; case EEXIST: return ERROR_OBJECT_EXISTS; case EACCES: return ERROR_WRITE_PROTECTED; - case ENOENT: return ERROR_OBJECT_NOT_FOUND; + case ENOENT: return ERROR_OBJECT_NOT_AROUND; case ENOTDIR: return ERROR_OBJECT_WRONG_TYPE; case ENOSPC: return ERROR_DISK_IS_FULL; case EBUSY: return ERROR_OBJECT_IN_USE; @@ -352,7 +351,8 @@ void write_filesys_config (struct uaedev fprintf (f, "filesystem=%s,%s:%s\n", uip[i].readonly ? "ro" : "rw", uip[i].volname, str); } else { - fprintf (f, "hardfile=%s,%d,%d,%d,%d,%s\n", uip[i].hf.secspertrack, + 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); } free (str); @@ -636,18 +636,13 @@ static void dispose_aino (Unit *unit, a_ free (aino); } -static void recycle_aino (Unit *unit, a_inode *aino) +static void recycle_aino (Unit *unit, a_inode *new_aino) { - if (aino->dir || aino->shlock > 0 || aino->elock || aino == &unit->rootnode) + if (new_aino->dir || new_aino->shlock > 0 + || new_aino->elock || new_aino == &unit->rootnode) /* Still in use */ return; - /* Chain it into circular list. */ - aino->next = unit->rootnode.next; - aino->prev = &unit->rootnode; - aino->prev->next = aino; - aino->next->prev = aino; - unit->aino_cache_size++; if (unit->aino_cache_size > 500) { /* Reap a few. */ int i = 0; @@ -655,7 +650,7 @@ static void recycle_aino (Unit *unit, a_ a_inode **aip; aip = &unit->rootnode.prev->parent->child; for (;;) { - aino = *aip; + a_inode *aino = *aip; if (aino == 0) break; @@ -679,6 +674,13 @@ static void recycle_aino (Unit *unit, a_ } #endif } + + /* Chain it into circular list. */ + new_aino->next = unit->rootnode.next; + new_aino->prev = &unit->rootnode; + new_aino->prev->next = new_aino; + new_aino->next->prev = new_aino; + unit->aino_cache_size++; } static void update_child_names (Unit *unit, a_inode *a, a_inode *parent) @@ -910,7 +912,7 @@ static a_inode *new_child_aino (Unit *un if (nn == 0) return 0; - aino = (a_inode *) xmalloc (sizeof (a_inode)); + aino = (a_inode *) xcalloc (sizeof (a_inode), 1); if (aino == 0) return 0; aino->aname = modified_rel ? modified_rel : my_strdup (rel); @@ -932,7 +934,7 @@ static a_inode *new_child_aino (Unit *un static a_inode *create_child_aino (Unit *unit, a_inode *base, char *rel, int isdir) { - a_inode *aino = (a_inode *) xmalloc (sizeof (a_inode)); + a_inode *aino = (a_inode *) xcalloc (sizeof (a_inode), 1); if (aino == 0) return 0; @@ -973,7 +975,7 @@ static a_inode *lookup_child_aino (Unit return c; c = new_child_aino (unit, base, rel); if (c == 0) - *err = ERROR_OBJECT_NOT_FOUND; + *err = ERROR_OBJECT_NOT_AROUND; return c; } @@ -1054,7 +1056,7 @@ static a_inode *get_aino (Unit *unit, a_ next = lookup_child_aino (unit, curr, p, err); if (next == 0) { /* if only last component not found, return parent dir. */ - if (*err != ERROR_OBJECT_NOT_FOUND || component_end != 0) + if (*err != ERROR_OBJECT_NOT_AROUND || component_end != 0) curr = 0; /* ? what error is appropriate? */ break; @@ -1110,7 +1112,7 @@ static uae_u32 startup_handler (void) } uinfo = current_mountinfo->ui + i; - unit = (Unit *) xmalloc (sizeof (Unit)); + unit = (Unit *) xcalloc (sizeof (Unit), 1); unit->next = units; units = unit; uinfo->self = unit; @@ -1148,6 +1150,8 @@ static uae_u32 startup_handler (void) unit->rootnode.amigaos_mode = 0; unit->rootnode.shlock = 0; unit->rootnode.elock = 0; + unit->rootnode.comment = 0; + unit->rootnode.has_dbentry = 0; unit->aino_cache_size = 0; for (i = 0; i < MAX_AINO_HASH; i++) unit->aino_hash[i] = 0; @@ -1424,7 +1428,7 @@ static void action_free_lock (Unit *unit a = lookup_aino (unit, get_long (lock + 4)); if (a == 0) { PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_FOUND); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); return; } if (a->elock) @@ -1452,7 +1456,7 @@ action_dup_lock (Unit *unit, dpacket pac a = lookup_aino (unit, get_long (lock + 4)); if (a == 0) { PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_FOUND); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); return; } /* DupLock()ing exclusive locks isn't possible, says the Autodoc, but @@ -1739,7 +1743,7 @@ static void do_find (Unit *unit, dpacket aino = find_aino (unit, lock, bstr (unit, name), &err); - if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_FOUND)) { + if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) { /* Whatever it is, we can't handle it. */ PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, err); @@ -2206,7 +2210,7 @@ action_change_mode (Unit *unit, dpacket Key *k = lookup_key (unit, object); if (!k) { PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_FOUND); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); return; } uniq = k->aino->uniq; @@ -2270,7 +2274,7 @@ action_parent_fh (Unit *unit, dpacket pa Key *k = lookup_key (unit, GET_PCK_ARG1 (packet)); if (!k) { PUT_PCK_RES1 (packet, DOS_FALSE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_FOUND); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); return; } action_parent_common (unit, packet, k->aino->uniq); @@ -2308,7 +2312,7 @@ action_create_dir (Unit *unit, dpacket p } aino = find_aino (unit, lock, bstr (unit, name), &err); - if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_FOUND)) { + if (aino == 0 || (err != 0 && err != ERROR_OBJECT_NOT_AROUND)) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, err); return; @@ -2380,7 +2384,7 @@ action_set_file_size (Unit *unit, dpacke k = lookup_key (unit, GET_PCK_ARG1 (packet)); if (k == 0) { PUT_PCK_RES1 (packet, DOS_TRUE); - PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_FOUND); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_AROUND); return; } @@ -2448,6 +2452,8 @@ action_delete_object (Unit *unit, dpacke return; } if (a->dir) { + /* This should take care of removing the fsdb if no files remain. */ + fsdb_dir_writeback (a); if (rmdir (a->nname) == -1) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, dos_errno()); @@ -2533,7 +2539,7 @@ action_rename_object (Unit *unit, dpacke return; } a2 = a2->parent; - } else if (a2 == 0 || err2 != ERROR_OBJECT_NOT_FOUND) { + } else if (a2 == 0 || err2 != ERROR_OBJECT_NOT_AROUND) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, err2 == 0 ? ERROR_OBJECT_EXISTS : err2); return; @@ -2885,6 +2891,23 @@ static uae_u32 filesys_handler (void) return 0; } +static int current_deviceno = 0; + +static void reset_uaedevices (void) +{ + current_deviceno = 0; +} + +static int get_new_device (char **devname, uaecptr *devname_amiga, int cdrom) +{ + char buffer[80]; + + sprintf (buffer, cdrom ? "CD%d" : "DH%d", current_deviceno); + + *devname_amiga = ds (*devname = my_strdup (buffer)); + return current_deviceno++; +} + void filesys_start_threads (void) { UnitInfo *uip; @@ -2897,7 +2920,7 @@ void filesys_start_threads (void) 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); + uip[i].devno = get_new_device (&uip[i].devname, &uip[i].devname_amiga, 0); #ifdef UAE_FILESYS_THREADS if (! is_hardfile (current_mountinfo, i)) {