Codebase list golang-golang-x-sys / a8b976e
windows: add Find*ChangeNotification APIs for file and directory monitoring https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationw https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findnextchangenotification https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findclosechangenotification Change-Id: If7abfd63cd7a60e7f95ffad9aca2b7b7b74c94f0 Reviewed-on: https://go-review.googlesource.com/c/sys/+/285713 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Jason A. Donenfeld 3 years ago
3 changed file(s) with 45 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
263263 //sys VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) = kernel32.VirtualProtect
264264 //sys TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) = mswsock.TransmitFile
265265 //sys ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) = kernel32.ReadDirectoryChangesW
266 //sys FindFirstChangeNotification(path string, watchSubtree bool, notifyFilter uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.FindFirstChangeNotificationW
267 //sys FindNextChangeNotification(handle Handle) (err error)
268 //sys FindCloseChangeNotification(handle Handle) (err error)
266269 //sys CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) = crypt32.CertOpenSystemStoreW
267270 //sys CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) = crypt32.CertOpenStore
268271 //sys CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) [failretval==nil] = crypt32.CertEnumCertificatesInStore
226226 )
227227
228228 const (
229 // filters for ReadDirectoryChangesW
229 // filters for ReadDirectoryChangesW and FindFirstChangeNotificationW
230230 FILE_NOTIFY_CHANGE_FILE_NAME = 0x001
231231 FILE_NOTIFY_CHANGE_DIR_NAME = 0x002
232232 FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x004
182182 procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
183183 procExitProcess = modkernel32.NewProc("ExitProcess")
184184 procFindClose = modkernel32.NewProc("FindClose")
185 procFindCloseChangeNotification = modkernel32.NewProc("FindCloseChangeNotification")
186 procFindFirstChangeNotificationW = modkernel32.NewProc("FindFirstChangeNotificationW")
185187 procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
186188 procFindFirstVolumeMountPointW = modkernel32.NewProc("FindFirstVolumeMountPointW")
187189 procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW")
190 procFindNextChangeNotification = modkernel32.NewProc("FindNextChangeNotification")
188191 procFindNextFileW = modkernel32.NewProc("FindNextFileW")
189192 procFindNextVolumeMountPointW = modkernel32.NewProc("FindNextVolumeMountPointW")
190193 procFindNextVolumeW = modkernel32.NewProc("FindNextVolumeW")
15241527 return
15251528 }
15261529
1530 func FindCloseChangeNotification(handle Handle) (err error) {
1531 r1, _, e1 := syscall.Syscall(procFindCloseChangeNotification.Addr(), 1, uintptr(handle), 0, 0)
1532 if r1 == 0 {
1533 err = errnoErr(e1)
1534 }
1535 return
1536 }
1537
1538 func FindFirstChangeNotification(path string, watchSubtree bool, notifyFilter uint32) (handle Handle, err error) {
1539 var _p0 *uint16
1540 _p0, err = syscall.UTF16PtrFromString(path)
1541 if err != nil {
1542 return
1543 }
1544 return _FindFirstChangeNotification(_p0, watchSubtree, notifyFilter)
1545 }
1546
1547 func _FindFirstChangeNotification(path *uint16, watchSubtree bool, notifyFilter uint32) (handle Handle, err error) {
1548 var _p1 uint32
1549 if watchSubtree {
1550 _p1 = 1
1551 }
1552 r0, _, e1 := syscall.Syscall(procFindFirstChangeNotificationW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(_p1), uintptr(notifyFilter))
1553 handle = Handle(r0)
1554 if handle == InvalidHandle {
1555 err = errnoErr(e1)
1556 }
1557 return
1558 }
1559
15271560 func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
15281561 r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
15291562 handle = Handle(r0)
15461579 r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0)
15471580 handle = Handle(r0)
15481581 if handle == InvalidHandle {
1582 err = errnoErr(e1)
1583 }
1584 return
1585 }
1586
1587 func FindNextChangeNotification(handle Handle) (err error) {
1588 r1, _, e1 := syscall.Syscall(procFindNextChangeNotification.Addr(), 1, uintptr(handle), 0, 0)
1589 if r1 == 0 {
15491590 err = errnoErr(e1)
15501591 }
15511592 return