2 Copyright © 2011, The AROS Development Team. All rights reserved.
5 Desc: Low-level filesystem access functions, packet version
9 #include <aros/debug.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
);
23 BSTR bstrname
= C2BSTR(name
);
26 return ERROR_NO_FREE_STORE
;
33 parent
= dvp
->dvp_Lock
;
36 *ret
= (BPTR
)dopacket3(DOSBase
, &error
, port
, ACTION_LOCATE_OBJECT
, parent
, bstrname
, accessMode
);
42 LONG
fs_Open(struct FileHandle
*handle
, UBYTE refType
, BPTR lock
, LONG mode
, CONST_STRPTR name
, struct DosLibrary
*DOSBase
)
46 struct MsgPort
*port
= NULL
;
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
;
64 bug("unknown access mode %x\n", mode
);
65 return ERROR_ACTION_NOT_KNOWN
;
71 /* 'lock' parameter is actually a parent's BPTR lock */
72 port
= ((struct FileLock
*)BADDR(lock
))->fl_Task
;
76 port
= ((struct DevProc
*)BADDR(lock
))->dvp_Port
;
77 lock
= ((struct DevProc
*)BADDR(lock
))->dvp_Lock
;
81 me
= (struct Process
*)FindTask(NULL
);
82 port
= me
->pr_ConsoleTask
;
83 /* console handler ACTION_FIND* ignores lock */
89 /* handler pointer not set, return NIL: handle */
91 handle
->fh_Type
= BNULL
;
92 /* NIL: is considered interactive */
93 handle
->fh_Interactive
= DOSTRUE
;
97 bstrname
= C2BSTR(name
);
99 return ERROR_NO_FREE_STORE
;
101 dopacket3(DOSBase
, &error
, port
, action
, MKBADDR(handle
), lock
, bstrname
);
102 FREEC2BSTR(bstrname
);
104 handle
->fh_Type
= port
;
108 LONG
fs_ReadLink(BPTR parent
, struct DevProc
*dvp
, CONST_STRPTR path
, STRPTR buffer
, ULONG size
, struct DosLibrary
*DOSBase
)
110 struct MsgPort
*port
;
114 struct FileLock
*fl
= BADDR(parent
);
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
)
130 struct FileHandle
*fh
= BADDR(handle
);
132 dopacket3(DOSBase
, &error
, fh
->fh_Type
, ACTION_CHANGE_SIGNAL
, fh
->fh_Arg1
, (IPTR
)task
, (SIPTR
)NULL
);
137 LONG
fs_AddNotify(struct NotifyRequest
*notify
, struct DevProc
*dvp
, BPTR lock
, struct DosLibrary
*DOSBase
)
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
)
149 struct FileHandle
*h
;
153 return Open("NIL:", mode
);
154 old
= SetConsoleTask(h
->fh_Type
);
155 nfh
= Open("*", mode
);