2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
9 #include <dos/notify.h>
10 #include <dos/exall.h>
11 #include <proto/dos.h>
12 #include <aros/debug.h>
15 #include "dos_intern.h"
17 /*****************************************************************************
21 AROS_LH1(BOOL
, StartNotify
,
24 AROS_LHA(struct NotifyRequest
*, notify
, D1
),
27 struct DosLibrary
*, DOSBase
, 148, Dos
)
30 Send a notification request to a filesystem. You will then be notified
31 whenever the file (or directory) changes.
34 notify - a notification request for the file or directory to monitor
37 Success/failure indicator.
40 The file or directory connected to a notification request does not
41 have to exist at the time of calling StartNotify(). The NotifyRequest
42 used with this function should not be altered while active.
49 EndNotify(), <dos/notify.h>
53 *****************************************************************************/
59 UBYTE buf
[MAXFILENAMELENGTH
+1], *buf2
, *p
;
63 /* set up some defaults */
64 notify
->nr_MsgCount
= 0;
65 notify
->nr_FullName
= NULL
;
67 D(bug("[StartNotify] Request 0x%p, Name %s\n", notify
, notify
->nr_Name
));
69 /* turn the filename into a device and dir lock */
70 if ((dvp
= GetDeviceProc(notify
->nr_Name
, NULL
)) == NULL
)
73 /* remember the handler for EndNotify() */
74 notify
->nr_Handler
= dvp
->dvp_Port
;
76 /* if no lock is returned by GetDeviceProc() (eg if the path is for a
77 * device or volume root), then get the handler to resolve the name of the
79 if (dvp
->dvp_Lock
== BNULL
)
81 UBYTE name
[MAXFILENAMELENGTH
+1], *src
, *dst
;
82 struct FileInfoBlock
*fib
;
84 src
= notify
->nr_Name
;
93 if ((fib
= AllocDosObject(DOS_FIB
, NULL
)) == NULL
) {
98 if((lock
= Lock(name
, SHARED_LOCK
)) == BNULL
) {
99 FreeDosObject(DOS_FIB
, fib
);
104 if (!Examine(lock
, fib
)) {
105 FreeDosObject(DOS_FIB
, fib
);
110 /* copy it to our processing buffer */
111 src
= fib
->fib_FileName
;
120 FreeDosObject(DOS_FIB
, fib
);
123 /* otherwise we need to expand the name using the lock */
127 if (NameFromLock(dvp
->dvp_Lock
, buf
, sizeof(buf
)) == DOSFALSE
)
136 /* if it's not some absolute base thing, then add a dir seperator for
137 * the concat operation below */
138 if (buf
[len
-1] != ':') {
143 /* look for the ':' following the assign name in the path provided by
146 while (*p
&& *p
!= ':')
149 /* if we found it, move past it */
153 /* hit the end, so the name is a relative path, and we take all of it */
159 if ((buf2
= AllocVec(len
+ len2
+ 1, MEMF_PUBLIC
)) == NULL
)
161 SetIoErr(ERROR_NO_FREE_STORE
);
171 /* concatenate the two bits */
172 CopyMem(buf
, buf2
, len
);
173 CopyMem(p
, buf2
+ len
, len2
+ 1);
175 /* that's our expanded name */
176 notify
->nr_FullName
= buf2
;
178 /* send the request, with error reporting */
181 err
= fs_AddNotify(notify
, dvp
, lock
, DOSBase
);
182 } while (err
!= 0 && ErrorReport(err
, REPORT_LOCK
, 0, notify
->nr_Handler
) == DOSFALSE
);
189 /* something broke, clean up */
192 if (notify
->nr_FullName
!= notify
->nr_Name
)
194 FreeVec(notify
->nr_FullName
);
195 notify
->nr_FullName
= NULL
;
202 D(bug("[StartNotify] nr_Handler 0x%p\n", notify
->nr_Handler
));