2 Copyright © 1995-2011, 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
)
31 Send a notification request to a filesystem. You will then be notified
32 whenever the file (or directory) changes.
36 notify -- a notification request for the file or directory to monitor
40 Success/failure indicator.
44 The file or directory connected to a notification request does not have
45 to exist at the time of calling StartNotify().
46 The NotifyRequest used with this function should not be altered while
55 EndNotify(), <dos/notify.h>
59 *****************************************************************************/
65 UBYTE buf
[MAXFILENAMELENGTH
+1], *buf2
, *p
;
69 /* set up some defaults */
70 notify
->nr_MsgCount
= 0;
71 notify
->nr_FullName
= NULL
;
73 D(bug("[StartNotify] Request 0x%p, Name %s\n", notify
, notify
->nr_Name
));
75 /* turn the filename into a device and dir lock */
76 if ((dvp
= GetDeviceProc(notify
->nr_Name
, NULL
)) == NULL
)
79 /* remember the handler for EndNotify() */
80 notify
->nr_Handler
= dvp
->dvp_Port
;
82 /* if no lock is returned by GetDeviceProc() (eg if the path is for a
83 * device or volume root), then get the handler to resolve the name of the
85 if (dvp
->dvp_Lock
== BNULL
)
87 UBYTE name
[MAXFILENAMELENGTH
+1], *src
, *dst
;
88 struct FileInfoBlock
*fib
;
90 src
= notify
->nr_Name
;
99 if ((fib
= AllocDosObject(DOS_FIB
, NULL
)) == NULL
) {
104 if((lock
= Lock(name
, SHARED_LOCK
)) == BNULL
) {
105 FreeDosObject(DOS_FIB
, fib
);
110 if (!Examine(lock
, fib
)) {
111 FreeDosObject(DOS_FIB
, fib
);
116 /* copy it to our processing buffer */
117 src
= fib
->fib_FileName
;
126 FreeDosObject(DOS_FIB
, fib
);
129 /* otherwise we need to expand the name using the lock */
133 if (NameFromLock(dvp
->dvp_Lock
, buf
, sizeof(buf
)) == DOSFALSE
)
142 /* if it's not some absolute base thing, then add a dir seperator for
143 * the concat operation below */
144 if (buf
[len
-1] != ':') {
149 /* look for the ':' following the assign name in the path provided by
152 while (*p
&& *p
!= ':')
155 /* if we found it, move past it */
159 /* hit the end, so the name is a relative path, and we take all of it */
165 if ((buf2
= AllocVec(len
+ len2
+ 1, MEMF_PUBLIC
)) == NULL
)
167 SetIoErr(ERROR_NO_FREE_STORE
);
177 /* concatenate the two bits */
178 CopyMem(buf
, buf2
, len
);
179 CopyMem(p
, buf2
+ len
, len2
+ 1);
181 /* that's our expanded name */
182 notify
->nr_FullName
= buf2
;
184 /* send the request, with error reporting */
187 err
= fs_AddNotify(notify
, dvp
, lock
, DOSBase
);
188 } while (err
!= 0 && ErrorReport(err
, REPORT_LOCK
, 0, notify
->nr_Handler
) == DOSFALSE
);
195 /* something broke, clean up */
198 if (notify
->nr_FullName
!= notify
->nr_Name
)
199 FreeVec(notify
->nr_FullName
);
205 D(bug("[StartNotify] nr_Handler 0x%p\n", notify
->nr_Handler
));