From bad284ff47868ef44469504e165862a5ee447cdd Mon Sep 17 00:00:00 2001 From: deadwood Date: Sat, 19 Apr 2014 09:33:59 +0000 Subject: [PATCH] dos.library: move special handling of NIL: to one function This cleans up special cases in each of the generic functions. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@48951 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- rom/dos/createnewproc.c | 4 +--- rom/dos/dopkt.c | 10 +--------- rom/dos/dos_intern.h | 1 + rom/dos/duplockfromfh.c | 6 ------ rom/dos/fs_driver.c | 10 ---------- rom/dos/info.c | 8 +------- rom/dos/mmakefile.src | 2 +- rom/dos/nil.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ rom/dos/open.c | 29 ++++++----------------------- rom/dos/openfromlock.c | 10 +--------- rom/dos/unlock.c | 8 -------- rom/dos/write.c | 2 -- test/dos/nil.c | 10 ++++++++-- 13 files changed, 67 insertions(+), 80 deletions(-) create mode 100644 rom/dos/nil.c diff --git a/rom/dos/createnewproc.c b/rom/dos/createnewproc.c index 5ae19803a4..788e66efbb 100644 --- a/rom/dos/createnewproc.c +++ b/rom/dos/createnewproc.c @@ -894,9 +894,7 @@ static BPTR OpenNIL(struct DosLibrary *DOSBase) struct FileHandle *fh; if ((fh = (struct FileHandle *)AllocDosObject(DOS_FILEHANDLE,NULL))) { - fh->fh_Type = BNULL; - fh->fh_Interactive = DOSFALSE; - return MKBADDR(fh); + return (BPTR)handleNIL(ACTION_FINDINPUT, (SIPTR)MKBADDR(fh), (SIPTR)NULL, (SIPTR)NULL); } return BNULL; diff --git a/rom/dos/dopkt.c b/rom/dos/dopkt.c index 1504e7bff8..5d49e94388 100644 --- a/rom/dos/dopkt.c +++ b/rom/dos/dopkt.c @@ -59,14 +59,6 @@ AROS_LIBFUNC_EXIT } -static SIPTR handleNIL(LONG action) -{ - switch(action) - { - case(ACTION_PARENT_FH): return (SIPTR)BNULL; - default: return TRUE; - } -} /* * All Amiga kickstart versions accept most dos packet dos calls without dosbase in A6. * So we have this internal routine here for compatibility purposes. @@ -84,7 +76,7 @@ SIPTR dopacket(SIPTR *res2, struct MsgPort *port, LONG action, SIPTR arg1, SIPTR { /* NIL: */ D(bug("NULL port => handling NIL:\n")); - return handleNIL(action); + return handleNIL(action, arg1, arg2, arg3); } /* First I create a regular dos packet */ diff --git a/rom/dos/dos_intern.h b/rom/dos/dos_intern.h index b51c90ea25..84a1536811 100644 --- a/rom/dos/dos_intern.h +++ b/rom/dos/dos_intern.h @@ -105,6 +105,7 @@ SIPTR dopacket(SIPTR *res2, struct MsgPort *port, LONG action, SIPTR arg1, SIPTR void internal_SendPkt(struct DosPacket *dp, struct MsgPort *port, struct MsgPort *replyport); struct DosPacket *internal_WaitPkt(struct MsgPort *msgPort); void internal_ReplyPkt(struct DosPacket *dp, struct MsgPort *replyPort, SIPTR res1, LONG res2); +SIPTR handleNIL(LONG action, SIPTR arg1, SIPTR arg2, SIPTR arg3); #define dopacket5(base, res2, port, action, arg1, arg2, arg3, arg4, arg5) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), (SIPTR)(arg3), (SIPTR)(arg4), (SIPTR)(arg5), 0, 0) #define dopacket4(base, res2, port, action, arg1, arg2, arg3, arg4) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), (SIPTR)(arg3), (SIPTR)(arg4), 0, 0, 0) diff --git a/rom/dos/duplockfromfh.c b/rom/dos/duplockfromfh.c index 544d4db569..03aed66ceb 100644 --- a/rom/dos/duplockfromfh.c +++ b/rom/dos/duplockfromfh.c @@ -54,12 +54,6 @@ if (handle == BNULL) return BNULL; - /* Special case for NIL: */ - if (fh->fh_Type == BNULL) { - struct FileLock *fl = AllocMem(sizeof(struct FileLock), MEMF_PUBLIC | MEMF_CLEAR); - return MKBADDR(fl); - } - ret = (BPTR)dopacket1(DOSBase, NULL, fh->fh_Type, ACTION_COPY_DIR_FH, fh->fh_Arg1); D(bug("[DupLockFromFH] %x -> %x\n", fh, BADDR(ret))); return ret; diff --git a/rom/dos/fs_driver.c b/rom/dos/fs_driver.c index b33d6a1f61..922744307b 100644 --- a/rom/dos/fs_driver.c +++ b/rom/dos/fs_driver.c @@ -52,16 +52,6 @@ LONG fs_Open(struct FileHandle *handle, struct MsgPort *port, BPTR lock, LONG mo else return ERROR_NOT_IMPLEMENTED; - if (!port) - { - /* handler pointer not set, return NIL: handle */ - SetIoErr(0); - handle->fh_Type = BNULL; - /* NIL: is not considered interactive */ - handle->fh_Interactive = DOSFALSE; - return 0; - } - bstrname = C2BSTR(name); if (!bstrname) return ERROR_NO_FREE_STORE; diff --git a/rom/dos/info.c b/rom/dos/info.c index d16f67b086..51696a93af 100644 --- a/rom/dos/info.c +++ b/rom/dos/info.c @@ -57,13 +57,7 @@ struct FileLock *fl = (struct FileLock *)BADDR(lock); LONG status; - if (fl && fl->fl_Task == NULL) - { - /* Special case for NIL: */ - status = 0; - } - else - status = dopacket2(DOSBase, NULL, fl ? fl->fl_Task : GetFileSysTask(), ACTION_INFO, lock, MKBADDR(parameterBlock)); + status = dopacket2(DOSBase, NULL, fl ? fl->fl_Task : GetFileSysTask(), ACTION_INFO, lock, MKBADDR(parameterBlock)); return status; AROS_LIBFUNC_EXIT diff --git a/rom/dos/mmakefile.src b/rom/dos/mmakefile.src index 058c70086e..ef1ef28f6e 100644 --- a/rom/dos/mmakefile.src +++ b/rom/dos/mmakefile.src @@ -34,7 +34,7 @@ FUNCTIONS := abortpkt addbuffers adddosentry addpart addsegment \ internalunloadseg ioerr isfilesystem \ isinteractive loadseg lock lockdoslist lockrecord lockrecords \ makedosentry makelink matchend matchfirst matchnext matchpattern \ - matchpatternnocase maxcli namefromfh namefromlock newloadseg nextdosentry \ + matchpatternnocase maxcli namefromfh namefromlock newloadseg nextdosentry nil \ open openfromlock output parentdir parentoffh parsepattern \ parsepatternnocase pathpart printfault putstr read readargs \ readitem relabel readlink remassignlist remdosentry remsegment rename \ diff --git a/rom/dos/nil.c b/rom/dos/nil.c new file mode 100644 index 0000000000..98c6f99a0d --- /dev/null +++ b/rom/dos/nil.c @@ -0,0 +1,47 @@ +/* + Copyright © 2014, The AROS Development Team. All rights reserved. + $Id$ + + Desc: Special handling for NIL: locks and file handles + Lang: English +*/ + +#include "dos_intern.h" + +SIPTR handleNIL(LONG action, SIPTR arg1, SIPTR arg2, SIPTR arg3) +{ + switch(action) + { + case(ACTION_FINDUPDATE): + case(ACTION_FINDINPUT): + case(ACTION_FINDOUTPUT): + { + struct FileHandle * fh = BADDR(arg1); + fh->fh_Type = BNULL; + fh->fh_Interactive = DOSFALSE;/* NIL: is not considered interactive */ + return (SIPTR)MKBADDR(fh); + } + case(ACTION_INFO): return (SIPTR)0; + case(ACTION_FREE_LOCK): + { + FreeMem((APTR)arg1, sizeof(struct FileLock)); + return (SIPTR)0; + } + case(ACTION_COPY_DIR_FH): + { + struct FileLock *fl = AllocMem(sizeof(struct FileLock), MEMF_PUBLIC | MEMF_CLEAR); + fl->fl_Access = SHARED_LOCK; + return (SIPTR)MKBADDR(fl); + } + case(ACTION_FH_FROM_LOCK): + { + struct FileHandle * fh = BADDR(arg2); + fh->fh_Interactive = DOSFALSE; + FreeMem((APTR)arg3, sizeof(struct FileLock)); + return (SIPTR)DOSTRUE; + } + case(ACTION_WRITE): return (SIPTR)arg3; + case(ACTION_PARENT_FH): return (SIPTR)BNULL; + default: return TRUE; + } +} diff --git a/rom/dos/open.c b/rom/dos/open.c index 061d217cac..380d27fe06 100644 --- a/rom/dos/open.c +++ b/rom/dos/open.c @@ -107,18 +107,10 @@ static LONG dupHandle(struct FileHandle *fh, BPTR lock, struct DosLibrary *DOSBa if (lock == BNULL) return DOSFALSE; - /* NIL: ? */ - fl = BADDR(lock); port = fl->fl_Task; - if (port) { - err = dopacket2(DOSBase, NULL, port, ACTION_FH_FROM_LOCK, MKBADDR(fh), lock); - } else { - /* NIL: device */ - fh->fh_Interactive = DOSFALSE; - err = DOSTRUE; - } + err = dopacket2(DOSBase, NULL, port, ACTION_FH_FROM_LOCK, MKBADDR(fh), lock); if (err != DOSFALSE) { fh->fh_Type = port; @@ -163,20 +155,6 @@ static LONG InternalOpen(CONST_STRPTR name, LONG accessMode, return dupHandle(handle, ast, DOSBase); } - /* - * Special case for NIL:, since it has no - * device task attached to it. - */ - if (!Stricmp(name, "NIL:")) - { - SetIoErr(0); - - handle->fh_Type = BNULL; - /* NIL: is not considered interactive */ - handle->fh_Interactive = DOSFALSE; - return DOSTRUE; - } - switch(accessMode) { case MODE_NEWFILE: @@ -199,6 +177,11 @@ static LONG InternalOpen(CONST_STRPTR name, LONG accessMode, error = fs_Open(handle, me->pr_ConsoleTask, con, accessMode, name, DOSBase); else if (!Stricmp(name, "*")) error = fs_Open(handle, me->pr_ConsoleTask, ast, accessMode, name, DOSBase); + else if (!Stricmp(name, "NIL:")) + { + error = fs_Open(handle, NULL, NULL, accessMode, name, DOSBase); + SetIoErr(0); + } else { BPTR cur = BNULL; diff --git a/rom/dos/openfromlock.c b/rom/dos/openfromlock.c index f7f3bcc7e0..c1ff43a741 100644 --- a/rom/dos/openfromlock.c +++ b/rom/dos/openfromlock.c @@ -61,15 +61,7 @@ if (fh) { struct MsgPort *port = fl->fl_Task; - if (port == BNULL) { - /* Special case for NIL: */ - fh->fh_Interactive = DOSFALSE; - FreeMem(fl, sizeof(*fl)); - err = DOSTRUE; - } else { - /* Normal case */ - err = dopacket2(DOSBase, NULL, port, ACTION_FH_FROM_LOCK, MKBADDR(fh), lock); - } + err = dopacket2(DOSBase, NULL, port, ACTION_FH_FROM_LOCK, MKBADDR(fh), lock); if (err == DOSFALSE) { FreeDosObject(DOS_FILEHANDLE, fh); diff --git a/rom/dos/unlock.c b/rom/dos/unlock.c index 19357fa264..5fb068d9c3 100644 --- a/rom/dos/unlock.c +++ b/rom/dos/unlock.c @@ -52,14 +52,6 @@ struct FileLock *fl = BADDR(lock); ASSERT_VALID_PTR_OR_NULL(fl); - - /* Special case for NIL: */ - if (fl && fl->fl_Task == NULL) - { - FreeMem(fl, sizeof(struct FileLock)); - return 0; - } - ASSERT_VALID_FILELOCK(lock); D(bug("UnLock(%x)\n", fl)); diff --git a/rom/dos/write.c b/rom/dos/write.c index de47a4b105..1ffc1cfc31 100644 --- a/rom/dos/write.c +++ b/rom/dos/write.c @@ -68,8 +68,6 @@ D(bug("[Write] %x %x %d\n", fh, buffer, length)); if (fh == NULL) SetIoErr(ERROR_INVALID_LOCK); - else if (fh->fh_Type == BNULL) /* NIL: */ - ret = length; else ret = dopacket3(DOSBase, NULL, fh->fh_Type, ACTION_WRITE, fh->fh_Arg1, (SIPTR)buffer, length); D(bug("[Write]=%d\n", ret)); diff --git a/test/dos/nil.c b/test/dos/nil.c index 4325573828..aa9f595506 100644 --- a/test/dos/nil.c +++ b/test/dos/nil.c @@ -17,6 +17,7 @@ int main() { TEXT buffer[20]; LONG result = 0; + BPTR bresult = BNULL; /* Open */ nilfh = Open("NIL:", MODE_OLDFILE); @@ -50,8 +51,7 @@ int main() /* OpenFromLock */ nilfh = OpenFromLock(nillock); -// UnLock(nillock); /* TODO: causes memory freed twice. Invastigate! */ - nillock = BNULL; + nillock = BNULL; /* Lock was consumed when opening */ TEST((nilfh != BNULL)); closehandles(); @@ -68,6 +68,12 @@ int main() TEST((result == 0)); closehandles(); + /* ParentOfFH */ + nilfh = Open("NIL:", MODE_OLDFILE); + bresult = ParentOfFH(nilfh); + TEST((bresult == BNULL)); + closehandles(); + cleanup(); return OK; -- 2.11.4.GIT