cicada
驱动小牛
驱动小牛
  • 注册日期2003-12-09
  • 最后登录2008-07-11
  • 粉丝1
  • 关注0
  • 积分74分
  • 威望15点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
阅读:1327回复:5

如何得到一个文件的大小?

楼主#
更多 发布于:2005-03-04 22:46
在内核模式的驱动程序中,如何得到一个文件的大小?用什么函数?
bmyyyud
驱动老牛
驱动老牛
  • 注册日期2002-02-22
  • 最后登录2010-01-21
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望130点
  • 贡献值0点
  • 好评度106点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-03-05 09:17
这个
ZwQueryInformationFile
ZwQueryInformationFile returns various kinds of information about a given file object.

NTSTATUS
  ZwQueryInformationFile(
    IN HANDLE  FileHandle,
    OUT PIO_STATUS_BLOCK  IoStatusBlock,
    OUT PVOID  FileInformation,
    IN ULONG  Length,
    IN FILE_INFORMATION_CLASS  FileInformationClass
    );
Parameters
FileHandle
Is the handle returned by a successful call to ZwCreateFile.
IoStatusBlock
Pointer to a variable that receives the final completion status and information about the operation.
FileInformation
Pointer to a caller-allocated buffer or variable that receives the desired information about the file. The contents of FileInformation are defined by the FileInformationClass parameter, described later.
Length
Specifies the size in bytes of FileInformation, which the caller should set according to the given FileInformationClass.
FileInformationClass
Specifies the type of information to be returned about the file, in the buffer specified by FileInformation. Device and intermediate drivers, can specify any of the following. FileInformationClass Value Meaning
FileAlignmentInformation Return a FILE_ALIGNMENT_INFORMATION structure. The caller can query this information as long as the file is open, without any particular requirements for DesiredAccess. This information is useful if the file was opened with the CreateOptions FILE_NO_INTERMEDIATE_BUFFERING flag set.
FileAttributeTagInformation Returns a FILE_ATTRIBUTE_TAG_INFORMATION structure. The caller must have opened the file with the DesiredAccess FILE_READ_ATTRIBUTES flag set.
FileBasicInformation Return a FILE_BASIC_INFORMATION structure. The caller must have opened the file with the DesiredAccess FILE_READ_ATTRIBUTES flag set.
FileNameInformation Return a FILE_NAME_INFORMATION structure. This might include the full file path or only a portion of the path.
See the comments below for details on the file name syntax.
FileNetworkOpenInformation Return a FILE_NETWORK_OPEN_INFORMATION structure. The caller must have opened the file with the DesiredAccess FILE_READ_ATTRIBUTES flag set.
FilePositionInformation Return a FILE_POSITION_INFORMATION structure. The caller must have opened the file with the DesiredAccess FILE_READ_DATA or FILE_WRITE_DATA flag set and with either of the CreateOptions FILE_SYNCHRONOUS_IO_ALERT or FILE_SYNCHRONOUS_IO_NONALERT.
FileStandardInformation Return a FILE_STANDARD_INFORMATION structure. The caller can query this information as long as the file is open, without any particular requirements for DesiredAccess.


Return Value
ZwQueryInformationFile returns STATUS_SUCCESS or an appropriate error status. It also returns the number of bytes actually written to the given FileInformation buffer in the Information member of IoStatusBlock.

Headers
Declared in wdm.h and ntddk.h. Include wdm.h or ntddk.h.

Comments
ZwQueryInformationFile returns information about the given file. Note that it returns zero in any member of a FILE_XXX_INFORMATION structure that is not supported by a particular device or file system.

When FileInformationClass equals FileNameInformation, the file name is returned in the FILE_NAME_INFORMATION structure. The precise syntax of the file name depends on a number of factors:

If the file was opened by submitting a full path and file name to ZwCreateFile, then ZwQueryInformationFile returns that full path and file name.

If the ObjectAttributes->RootDirectory handle was opened by name in a call to ZwCreateFile, and subsequently the file was opened by ZwCreateFile relative to this root directory handle, then the full path and file name are returned.

If the ObjectAttributes->RootDirectory handle was opened by file ID (using the FILE_OPEN_BY_FILE_ID flag) in a call to ZwCreateFile, and subsequently the file was opened by ZwCreateFile relative to this root directory handle, then only the relative path will be returned.

However, if the user has SeChangeNotifyPrivilege (described in Platform SDK documentation), the full path and file name will be returned in all cases.

If only the relative path is returned, the file name string will not begin with a backslash.

If the full path and file name are returned, the string will begin with a single backslash, regardless of its location. Thus the file C:\\dir1\\dir2\\filename.ext will appear as \\dir1\\dir2\\filename.ext, while the file \\\\server\\share\\dir1\\dir2\\filename.ext will appear as \\server\\share\\dir1\\dir2\\filename.ext.

Callers of ZwQueryInformationFile must be running at IRQL = PASSIVE_LEVEL.

滚滚长江东逝水 浪花淘尽英雄 是非成败转头空 青山依旧在 几度夕阳红 白发渔樵江渚上 惯看秋月春风 一壶浊酒喜相逢 古今多少事 尽付笑谈中
cicada
驱动小牛
驱动小牛
  • 注册日期2003-12-09
  • 最后登录2008-07-11
  • 粉丝1
  • 关注0
  • 积分74分
  • 威望15点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-03-07 08:45
FileInformationClass中的哪一个参数是获取文件大小的呢?我怎么没有看到啊!
bmyyyud
驱动老牛
驱动老牛
  • 注册日期2002-02-22
  • 最后登录2010-01-21
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望130点
  • 贡献值0点
  • 好评度106点
  • 原创分0分
  • 专家分0分
地板#
发布于:2005-03-07 09:19
FileInformationClass中的哪一个参数是获取文件大小的呢?我怎么没有看到啊!

FILE_STANDARD_INFORMATION
The FILE_STANDARD_INFORMATION structure is used as an argument to routines that query or set file information.

typedef struct FILE_STANDARD_INFORMATION {
  LARGE_INTEGER  AllocationSize;
  LARGE_INTEGER  EndOfFile;
  ULONG  NumberOfLinks;
  BOOLEAN  DeletePending;
  BOOLEAN  Directory;
} FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
Members
AllocationSize
The file allocation size in bytes. Usually, this value is a multiple of the sector or cluster size of the underlying physical device.
EndOfFile
The end of file location as a byte offset.
NumberOfLinks
The number of hard links to the file.
DeletePending
The delete pending status. TRUE indicates that a file deletion has been requested.
Directory
The file directory status. TRUE indicates the file object represents a directory.
Headers
Defined in wdm.h and ntddk.h. Include wdm.h or ntddk.h.

Comments
EndOfFile specifies the byte offset to the end of the file. Because this value is zero-based, it actually refers to the first free byte in the file; that is, it is the offset to the byte immediately following the last valid byte in the file.

EndOfFile就是啦
滚滚长江东逝水 浪花淘尽英雄 是非成败转头空 青山依旧在 几度夕阳红 白发渔樵江渚上 惯看秋月春风 一壶浊酒喜相逢 古今多少事 尽付笑谈中
xbzjackey
驱动小牛
驱动小牛
  • 注册日期2002-12-27
  • 最后登录2016-01-07
  • 粉丝0
  • 关注0
  • 积分5分
  • 威望34点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2005-03-11 15:58
谢谢bmyyyud,解决了我的问题。

回答好的不要忘了给分哦。。。
cicada
驱动小牛
驱动小牛
  • 注册日期2003-12-09
  • 最后登录2008-07-11
  • 粉丝1
  • 关注0
  • 积分74分
  • 威望15点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-03-13 17:59
那就给分吧!
游客

返回顶部