监控文件系统用得到的API

 http://msdn.microsoft.com/en-us/library/aa302237.aspx

NT_TRANSACT_NOTIFY_CHANGE

The NT_TRANSACT_NOTIFY_CHANGE command notifies the client when the directory specified by Fid is modified. It also returns the names of any files that changed. Parameters for the command are encoded in NT_TRANSACT command subheader fields as shown.

                    Field name               Displacement        Length
                                                (bytes)         (bytes)
ClientRequestSetupWordsEncoding
                    CompletionFilter               0               4
                    Fid                            4               2
                    WatchTree                      6               1
                    Reserved                       7               1
  ServerResponseParameterEncoding
                    ParameterCount                 0               1
                    FileNotifyInformation          1            Variable
                    NextEntryOffset                *               4
                    Action                         *               4
                    FileNameLength                 *               4
                    FileName                       *            Variable
 
01234567891
0
1234567892
0
1234567893
0
1
  
Fields
ClientRequestSetupWordsEncoding
01234567891
0
1234567892
0
1234567893
0
1
CompletionFilterFidWatchTreeReserved
Encoded in SetupWords[] in the client request.

 

CompletionFilter

Data type: ULONG

Type of operation to monitor. The value is the sum of any of the following flags.
NameValue
FILE_NOTIFY_CHANGE_FILE_NAME0x00000001
FILE_NOTIFY_CHANGE_DIR_NAME0x00000002
FILE_NOTIFY_CHANGE_NAME0x00000003
FILE_NOTIFY_CHANGE_ATTRIBUTES0x00000004
FILE_NOTIFY_CHANGE_SIZE0x00000008
FILE_NOTIFY_CHANGE_LAST_WRITE0x00000010
FILE_NOTIFY_CHANGE_LAST_ACCESS0x00000020
FILE_NOTIFY_CHANGE_CREATION0x00000040
FILE_NOTIFY_CHANGE_EA0x00000080
FILE_NOTIFY_CHANGE_SECURITY0x00000100
FILE_NOTIFY_CHANGE_STREAM_NAME0x00000200
FILE_NOTIFY_CHANGE_STREAM_SIZE0x00000400
FILE_NOTIFY_CHANGE_STREAM_WRITE0x00000800
Fid

Data type: USHORT

File identifier or handle of the directory to monitor.
WatchTree

Data type: BOOLEAN

If TRUE, all subdirectories will be watched; otherwise, FALSE.
Reserved

Data type: UCHAR

Reserved. This value must be 0 (zero).
ServerResponseParameterEncoding
01234567891
0
1234567892
0
1234567893
0
1
ParameterCount
File notification packet.

 

ParameterCount
Number of bytes of change data.
FileNotifyInformation
01234567891
0
1234567892
0
1234567893
0
1
NextEntryOffsetActionFileNameLengthFileName1

Data type: struct

The response contains FILE_NOTIFY_INFORMATION structures, as defined below. The NextEntryOffset field of the structure specifies the offset, in bytes, from the start of the current entry to the next entry in the list. If this is the last entry in the list, this field is zero. Each entry in the list must be longword aligned, so NextEntryOffset must be a multiple of four.

 

NextEntryOffset

Data type: ULONG

Offset, in bytes, from the start of the current entry to the next entry in the list. Each entry in the list must be 4-byte aligned, so  NextEntryOffset must be a multiple of four. If this is the last entry in the list, the value is 0 (zero).
Action

Data type: ULONG

Action taken for the specified file name.
NameValue
FILE_ACTION_ADDED0x00000001
FILE_ACTION_REMOVED0x00000002
FILE_ACTION_MODIFIED0x00000003
FILE_ACTION_RENAMED_OLD_NAME0x00000004
FILE_ACTION_RENAMED_NEW_NAME0x00000005
FILE_ACTION_ADDED_STREAM0x00000006
FILE_ACTION_REMOVED_STREAM0x00000007
FILE_ACTION_MODIFIED_STREAM0x00000008
FileNameLength

Data type: ULONG

File name length of the changed file.
FileName1

Data type: WCHAR

Name of file for which a change is notified.
Remarks

This command notifies the client when the directory specified by Fid is modified. It also returns the name(s) of the file(s) that changed. The command completes once the directory has been modified based on the supplied CompletionFilter. The command is a "single shot" and therefore needs to be reissued to watch for more directory changes.

When a change that is in the CompletionFilter field is made to the directory, the command completes. The names of the files that have changed since the last time the command was issued are returned to the client. The ParameterCount field of the server response indicates the number of bytes that are being returned. If too many files have changed since the last time the command was issued, then zero bytes are returned and an alternate status code is returned in the Status field of the server response header.

A directory file must be opened before this command may be used. After the directory is open, this command may be used to begin watching files and subdirectories in the specified directory for changes. The first time the command is issued, the MaxParameterCount field in the packet header determines the size of the buffer that will be used at the server to buffer directory change information between issuances of the notify change commands.

posted on 2011-11-30 22:55 流沙- 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/darkdance/archive/2011/11/30/2269755.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值