--- uae/src/filesys.c 2018/04/24 16:47:32 1.1.1.7 +++ uae/src/filesys.c 2018/04/24 16:53:07 1.1.1.9 @@ -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) @@ -1864,6 +1866,10 @@ action_fh_from_lock (Unit *unit, dpacket : (mode & A_FIBF_WRITE) == 0 ? O_RDONLY : O_RDWR)); + /* the files on CD really can have the write-bit set. */ + if (unit->ui.readonly) + openmode = O_RDONLY; + fd = open (aino->nname, openmode | O_BINARY, 0777); if (fd < 0) { @@ -2178,7 +2184,7 @@ action_change_mode (Unit *unit, dpacket /* 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); - uaecptr fh; + unsigned long uniq; a_inode *a = NULL, *olda = NULL; uae_u32 err = 0; TRACE(("ACTION_CHANGE_MODE(0x%lx,%d,%d)\n",object,type,mode)); @@ -2195,8 +2201,20 @@ action_change_mode (Unit *unit, dpacket CHANGE_FH? */ if (type == CHANGE_FH) mode = (mode == 1006 ? -1 : -2); - fh = (type == CHANGE_LOCK ? get_long (object + 4) : object); - a = lookup_aino (unit, get_long (object + 4)); + + if (type == CHANGE_LOCK) + uniq = get_long (object + 4); + else { + Key *k = lookup_key (unit, object); + if (!k) { + PUT_PCK_RES1 (packet, DOS_FALSE); + PUT_PCK_RES2 (packet, ERROR_OBJECT_NOT_FOUND); + return; + } + uniq = k->aino->uniq; + } + a = lookup_aino (unit, uniq); + if (! a) err = ERROR_INVALID_LOCK; else { @@ -2224,9 +2242,9 @@ action_change_mode (Unit *unit, dpacket } static void -action_parent_common (Unit *unit, dpacket packet, uaecptr fh) +action_parent_common (Unit *unit, dpacket packet, unsigned long uniq) { - a_inode *olda = lookup_aino (unit, fh); + a_inode *olda = lookup_aino (unit, uniq); if (olda == 0) { PUT_PCK_RES1 (packet, DOS_FALSE); PUT_PCK_RES2 (packet, ERROR_INVALID_LOCK); @@ -2251,15 +2269,13 @@ action_parent_common (Unit *unit, dpacke static void action_parent_fh (Unit *unit, dpacket packet) { - uaecptr fh = GET_PCK_ARG1 (packet) << 2; - TRACE(("ACTION_PARENT_FH(0x%lx)\n",fh)); - - if (! fh) { + 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); return; } - action_parent_common (unit, packet, fh); + action_parent_common (unit, packet, k->aino->uniq); } static void