dos.library: Use fh_Interactive instead of fh_Port alias, for code clarity
[AROS.git] / rom / dos / fs_driver.c
blobfa34d5e0a643615685787b2bc52c49b028001be8
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Low-level filesystem access functions, packet version
6 Lang: English
7 */
9 #include <aros/debug.h>
10 #include <dos/dos.h>
11 #include <dos/filesystem.h>
12 #include <proto/dos.h>
13 #include <proto/exec.h>
15 #include "dos_intern.h"
16 #include "fs_driver.h"
18 LONG fs_LocateObject(BPTR *ret, BPTR parent, struct DevProc *dvp, CONST_STRPTR name, LONG accessMode, struct DosLibrary *DOSBase)
20 struct FileLock *fl = BADDR(parent);
21 struct MsgPort *port;
22 SIPTR error = 0;
23 BSTR bstrname = C2BSTR(name);
25 if (!bstrname)
26 return ERROR_NO_FREE_STORE;
28 if (fl)
29 port = fl->fl_Task;
30 else
32 port = dvp->dvp_Port;
33 parent = dvp->dvp_Lock;
36 *ret = (BPTR)dopacket3(DOSBase, &error, port, ACTION_LOCATE_OBJECT, parent, bstrname, accessMode);
37 FREEC2BSTR(bstrname);
39 return error;
42 LONG fs_Open(struct FileHandle *handle, UBYTE refType, BPTR lock, LONG mode, CONST_STRPTR name, struct DosLibrary *DOSBase)
44 ULONG action;
45 BSTR bstrname;
46 struct MsgPort *port = NULL;
47 struct Process *me;
48 SIPTR error = 0;
50 if (mode == MODE_READWRITE)
51 action = ACTION_FINDUPDATE;
52 else if (mode == MODE_NEWFILE)
53 action = ACTION_FINDOUTPUT;
54 else if (mode == MODE_OLDFILE)
55 action = ACTION_FINDINPUT;
56 else if (mode & FMF_CREATE)
57 action = ACTION_FINDOUTPUT;
58 else if (mode & FMF_CLEAR)
59 action = ACTION_FINDOUTPUT;
60 else if (mode & (FMF_READ | FMF_WRITE))
61 action = ACTION_FINDINPUT;
62 else
64 bug("unknown access mode %x\n", mode);
65 return ERROR_ACTION_NOT_KNOWN;
68 switch (refType)
70 case REF_LOCK:
71 /* 'lock' parameter is actually a parent's BPTR lock */
72 port = ((struct FileLock *)BADDR(lock))->fl_Task;
73 break;
75 case REF_DEVICE:
76 port = ((struct DevProc *)BADDR(lock))->dvp_Port;
77 lock = ((struct DevProc *)BADDR(lock))->dvp_Lock;
78 break;
80 case REF_CONSOLE:
81 me = (struct Process *)FindTask(NULL);
82 port = me->pr_ConsoleTask;
83 /* console handler ACTION_FIND* ignores lock */
84 break;
87 if (!port)
89 /* handler pointer not set, return NIL: handle */
90 SetIoErr(0);
91 handle->fh_Type = BNULL;
92 /* NIL: is considered interactive */
93 handle->fh_Interactive = DOSTRUE;
94 return 0;
97 bstrname = C2BSTR(name);
98 if (!bstrname)
99 return ERROR_NO_FREE_STORE;
101 dopacket3(DOSBase, &error, port, action, MKBADDR(handle), lock, bstrname);
102 FREEC2BSTR(bstrname);
104 handle->fh_Type = port;
105 return error;
108 LONG fs_ReadLink(BPTR parent, struct DevProc *dvp, CONST_STRPTR path, STRPTR buffer, ULONG size, struct DosLibrary *DOSBase)
110 struct MsgPort *port;
112 if (parent)
114 struct FileLock *fl = BADDR(parent);
116 port = fl->fl_Task;
118 else
120 port = dvp->dvp_Port;
121 parent = dvp->dvp_Lock;
124 return ReadLink(port, parent, path, buffer, size);
127 LONG fs_ChangeSignal(BPTR handle, struct Process *task, struct DosLibrary *DOSBase)
129 SIPTR error = 0;
130 struct FileHandle *fh = BADDR(handle);
132 dopacket3(DOSBase, &error, fh->fh_Type, ACTION_CHANGE_SIGNAL, fh->fh_Arg1, (IPTR)task, (SIPTR)NULL);
134 return error;
137 LONG fs_AddNotify(struct NotifyRequest *notify, struct DevProc *dvp, BPTR lock, struct DosLibrary *DOSBase)
139 SIPTR err = 0;
140 LONG status = dopacket1(DOSBase, &err, notify->nr_Handler, ACTION_ADD_NOTIFY, (SIPTR)notify);
142 return status ? 0 : err;
145 BPTR DupFH(BPTR fh, LONG mode, struct DosLibrary *DOSBase)
147 BPTR nfh;
148 struct MsgPort *old;
149 struct FileHandle *h;
151 h = BADDR(fh);
152 if (!h->fh_Type)
153 return Open("NIL:", mode);
154 old = SetConsoleTask(h->fh_Type);
155 nfh = Open("*", mode);
156 SetConsoleTask(old);
157 return nfh;