2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <dos/notify.h>
10 #include <proto/dos.h>
11 #include "dos_intern.h"
12 #include <aros/debug.h>
15 /*****************************************************************************
19 AROS_LH1(BOOL
, StartNotify
,
22 AROS_LHA(struct NotifyRequest
*, notify
, D1
),
25 struct DosLibrary
*, DOSBase
, 148, Dos
)
29 Send a notification request to a filesystem. You will then be notified
30 whenever the file (or directory) changes.
34 notify -- a notification request for the file or directory to monitor
38 Success/failure indicator.
42 The file or directory connected to a notification request does not have
43 to exist at the time of calling StartNotify().
44 The NotifyRequest used with this function should not be altered while
53 EndNotify(), <dos/notify.h>
57 *****************************************************************************/
61 struct IOFileSys iofs
;
63 UBYTE buf
[MAXFILENAMELENGTH
+1], *buf2
, *p
;
67 /* set up some defaults */
68 notify
->nr_MsgCount
= 0;
69 notify
->nr_FullName
= NULL
;
71 /* turn the filename into a device and dir lock */
72 if ((dvp
= GetDeviceProc(notify
->nr_Name
, NULL
)) == NULL
)
75 /* prepare the notify request */
76 InitIOFS(&iofs
, FSA_ADD_NOTIFY
, DOSBase
);
77 iofs
.io_Union
.io_NOTIFY
.io_NotificationRequest
= notify
;
78 iofs
.IOFS
.io_Device
= (struct Device
*) dvp
->dvp_Port
;
80 /* remember the handler for EndNotify() (but see the comments there about
81 * why we don't really use it */
82 notify
->nr_Handler
= dvp
->dvp_Port
;
84 /* if no lock is returned by GetDeviceProc() (eg if the path is for a
85 * device or volume root), then get the handler to resolve the name of the
87 if (dvp
->dvp_Lock
== NULL
) {
88 UBYTE name
[MAXFILENAMELENGTH
+1], *src
, *dst
;
89 struct FileInfoBlock
*fib
;
91 src
= notify
->nr_Name
;
100 if ((fib
= AllocDosObject(DOS_FIB
, NULL
)) == NULL
) {
105 if((lock
= Lock(name
, SHARED_LOCK
)) == NULL
) {
106 FreeDosObject(DOS_FIB
, fib
);
111 if (!Examine(lock
, fib
)) {
112 FreeDosObject(DOS_FIB
, fib
);
117 /* copy it to our processing buffer */
118 src
= fib
->fib_FileName
;
127 /* use the root lock we just got as the relative lock */
128 iofs
.IOFS
.io_Unit
= ((struct FileHandle
*) BADDR(lock
))->fh_Unit
;
130 FreeDosObject(DOS_FIB
, fib
);
133 /* otherwise we need to expand the name using the lock */
136 if (NameFromLock(dvp
->dvp_Lock
, buf
, sizeof(buf
)) == DOSFALSE
) {
141 /* use the assign base lock as the relative lock */
142 iofs
.IOFS
.io_Unit
= ((struct FileHandle
*) BADDR(dvp
->dvp_Lock
))->fh_Unit
;
147 /* if its not some absolute base thing, then add a dir seperator for
148 * the concat operation below */
149 if (buf
[len
-1] != ':') {
154 /* look for the ':' following the assign name in the path provided by
157 while (*p
&& *p
!= ':')
160 /* if we found it, move past it */
164 /* hit the end, so the name is a relative path, and we take all of it */
170 if ((buf2
= AllocVec(len
+ len2
+ 1, MEMF_PUBLIC
)) == NULL
) {
171 SetIoErr(ERROR_NO_FREE_STORE
);
181 /* concatenate the two bits */
182 CopyMem(buf
, buf2
, len
);
183 CopyMem(p
, buf2
+ len
, len2
+ 1);
185 /* thats our expanded name */
186 notify
->nr_FullName
= buf2
;
188 /* send the request, with error reporting */
191 } while (iofs
.io_DosError
!= 0 && ErrorReport(iofs
.io_DosError
, REPORT_LOCK
, 0, dvp
->dvp_Port
) == DOSFALSE
);
193 SetIoErr(iofs
.io_DosError
);
200 /* something broke, clean up */
201 if (iofs
.io_DosError
!= 0) {
202 if (notify
->nr_FullName
!= notify
->nr_Name
)
203 FreeVec(notify
->nr_FullName
);