FILE_OBJECT

https://msdn.microsoft.com/en-us/library/windows/hardware/ff545834(v=vs.85).aspx

The FILE_OBJECT structure is used by the system to represent a file object. To user-mode protected subsystems, a file object represents an open instance of a file, device, directory, or volume. To device and intermediate drivers, a file object usually represents a device object. To drivers in the file system stack, a file object usually represents a directory or file.

A file object is partially opaque. Certain types of drivers, such as file system drivers and network transport drivers, use some of the fields of file objects.

 1 typedef struct _FILE_OBJECT {
 2   CSHORT                            Type;
 3   CSHORT                            Size;
 4   PDEVICE_OBJECT                    DeviceObject;
 5   PVPB                              Vpb;
 6   PVOID                             FsContext;
 7   PVOID                             FsContext2;
 8   PSECTION_OBJECT_POINTERS          SectionObjectPointer;
 9   PVOID                             PrivateCacheMap;
10   NTSTATUS                          FinalStatus;
11   struct _FILE_OBJECT  *RelatedFileObject;
12   BOOLEAN                           LockOperation;
13   BOOLEAN                           DeletePending;
14   BOOLEAN                           ReadAccess;
15   BOOLEAN                           WriteAccess;
16   BOOLEAN                           DeleteAccess;
17   BOOLEAN                           SharedRead;
18   BOOLEAN                           SharedWrite;
19   BOOLEAN                           SharedDelete;
20   ULONG                             Flags;
21   UNICODE_STRING                    FileName;
22   LARGE_INTEGER                     CurrentByteOffset;
23   __volatile ULONG                  Waiters;
24   __volatile ULONG                  Busy;
25   PVOID                             LastLock;
26   KEVENT                            Lock;
27   KEVENT                            Event;
28   __volatile PIO_COMPLETION_CONTEXT CompletionContext;
29   KSPIN_LOCK                        IrpListLock;
30   LIST_ENTRY                        IrpList;
31   __volatile PVOID                  FileObjectExtension;
32 } FILE_OBJECT, *PFILE_OBJECT;

Members

Type

A read-only member used by the system to indicate that the object is a file object. If the object is a file object, the value of this member is 5.

Size

A read-only member that specifies the size, in bytes, of the file object. This size does not include the file object extension, if one is present.

DeviceObject

A pointer to the device object on which the file is opened.

Vpb

A pointer to the volume parameter block associated with the file object.

Note that if the Vpb member is non-NULL, the file resides on a mounted volume.

FsContext

A pointer to whatever optional state a driver maintains about the file object; otherwise, NULL. For file system drivers, this member must point to aFSRTL_ADVANCED_FCB_HEADER header structure that is contained within a file-system-specific structure; otherwise system instability can result. Usually, this header structure is embedded in a file control block (FCB). However, on some file systems that support multiple data streams, such as NTFS, this header structure is a stream control block (SCB).

Note  In a WDM device stack, only the functional device object (FDO) can use the two context pointers. File system drivers share this member across multiple opens to the same data stream.

FsContext2

A pointer to whatever additional state a driver maintains about the file object; otherwise, NULL.

Note  This member is opaque for drivers in the file system stack because the underlying file system utilizes this member.

SectionObjectPointer

A pointer to the file object‘s read-only section object. This member is set only by file systems and used for Cache Manager interaction.

PrivateCacheMap

An opaque member, set only by file systems, that points to handle-specific information and that is used for Cache Manager interaction.

FinalStatus

A read-only member that is used, in certain synchronous cases, to indicate the final status of the file object‘s I/O request.

RelatedFileObject

A pointer to a FILE_OBJECT structure used to indicate that the current file object has been opened relative to an already open file object. The file object pointed to by this member is usually a directory (meaning the current file has been opened relative to this directory). However, a file can be reopened relative to itself, and alternate data streams for a file can be opened relative to an already open primary data stream for that same file. The RelatedFileObject member is only valid during the processing of the IRP_MJ_CREATE requests.

LockOperation

A read-only member. If FALSE, a lock operation (NtLockFile) has never been performed on the file object. If TRUE, at least one lock operation has been performed on the file object. Once set to TRUE, this member always remains TRUE (for example, releasing file locks on the file object does not reset this member to FALSE).

DeletePending

A read-only member. If TRUE, a delete operation for the file associated with the file object exists. If FALSE, there currently is no pending delete operation for the file object.

ReadAccess

A read-only member. If TRUE, the file associated with the file object has been opened for read access. If FALSE, the file has been opened without read access. This information is used when checking and/or setting the share access of the file.

WriteAccess

A read-only member. If TRUE, the file associated with the file object has been opened for write access. If FALSE, the file has been opened without write access. This information is used when checking and/or setting the share access of the file.

DeleteAccess

A read-only member. If TRUE, the file associated with the file object has been opened for delete access. If FALSE, the file has been opened without delete access. This information is used when checking and/or setting the share access of the file.

SharedRead

A read-only member. If TRUE, the file associated with the file object has been opened for read sharing access. If FALSE, the file has been opened without read sharing access. This information is used when checking and/or setting the share access of the file.

SharedWrite

A read-only member. If TRUE, the file associated with the file object has been opened for write sharing access. If FALSE, the file has been opened without write sharing access. This information is used when checking and/or setting the share access of the file.

SharedDelete

A read-only member. If TRUE, the file associated with the file object has been opened for delete sharing access. If FALSE, the file has been opened without delete sharing access. This information is used when checking and/or setting the share access of the file.

Flags

A read-only member used by the system to hold one or more (a bitwise inclusive OR combination) of the following private flag values.

Flag Meaning

FO_FILE_OPEN


Deprecated.


FO_SYNCHRONOUS_IO


The file object is opened for synchronous I/O.


FO_ALERTABLE_IO


Any wait in the I/O manager, as a result of a request made to this file object, is alertable.


FO_NO_INTERMEDIATE_BUFFERING


The file associated with the file object cannot be cached or buffered in a driver‘s internal buffers.


FO_WRITE_THROUGH


System services, file system drivers, and drivers that write data to the file must transfer the data into the file before any requested write operation is considered complete.


FO_SEQUENTIAL_ONLY


The file associated with the file object was opened for sequential I/O operations only.


FO_CACHE_SUPPORTED


The file associated with the file object is cacheable. This flag should be set only by a file system driver, and only if theFsContext member points to a valid FSRTL_ADVANCED_FCB_HEADER structure.


FO_NAMED_PIPE


The file object represents a named pipe.


FO_STREAM_FILE


The file object represents a file stream.


FO_MAILSLOT


The file object represents a mailslot.


FO_GENERATE_AUDIT_ON_CLOSE


Deprecated.


FO_QUEUE_IRP_TO_THREAD


IRPs will not be queued to this file object.


FO_DIRECT_DEVICE_OPEN


The device targeted by this file object was opened directly.


FO_FILE_MODIFIED


The file associated with the file object has been modified.


FO_FILE_SIZE_CHANGED


The file associated with the file object has changed in size.


FO_CLEANUP_COMPLETE


The file system has completed its cleanup for this file object.


FO_TEMPORARY_FILE


The file associated with the file object is a temporary file.


FO_DELETE_ON_CLOSE


The file associated with the file object will be deleted by the file system upon close.


FO_OPENED_CASE_SENSITIVE


The file name case of the file associated with the file object is respected.


FO_HANDLE_CREATED


A file handle was created for file object.


FO_FILE_FAST_IO_READ


A fast I/O read was performed on this file object.


FO_RANDOM_ACCESS


The file associated with the file object was opened for random access.


FO_FILE_OPEN_CANCELLED


The create request for this file object was canceled before completing.


FO_VOLUME_OPEN


The file object represents a volume open request.


FO_REMOTE_ORIGIN


The create request for the file associated with the file object originated on a remote machine.


FO_SKIP_COMPLETION_PORT


For a file object associated with a port, determines if the system should skip queuing to the completion port when the IRP is completed synchronously with a non-error status return value.


FO_SKIP_SET_EVENT


Skip setting the event for the file object upon IRP completion.


FO_SKIP_SET_FAST_IO


Skip setting an event supplied to a system service when the fast I/O path is successful.

FileName

UNICODE_STRING structure whose Buffer member points to a read-only Unicode string that holds the name of the file opened on the volume. If the volume is being opened, the Length member of the UNICODE_STRING structure will be zero. Note that the file name in this string is valid only during the initial processing of an IRP_MJ_CREATE request. This file name should not be considered valid after the file system starts to process the IRP_MJ_CREATE request. The storage for the string pointed to by the Buffer member of the UNICODE_STRING structure is allocated in paged system memory. For more information about obtaining a file name, see FltGetFileNameInformation.

CurrentByteOffset

A read-only member that specifies the file offset, in bytes, associated with the file object.

Waiters

A read-only member used by the system to count the number of outstanding waiters on a file object opened for synchronous access.

Busy

A read-only member used by the system to indicate whether a file object opened for synchronous access is currently busy.

LastLock

An opaque pointer to the last lock applied to the file object.

Lock

An opaque member used by the system to hold a file object event lock. The event lock is used to control synchronous access to the file object. Applicable only to file objects that are opened for synchronous access.

Event

An opaque member used by the system to hold an event object for the file object. The event object is used to signal the completion of an I/O request on the file object if no user event was supplied or a synchronous API was called.

CompletionContext

An opaque pointer to completion port information (port pointer and key) associated with the file object, if any.

IrpListLock

An opaque pointer to a KSPIN_LOCK structure that serves as the spin lock used to synchronize access to the file object‘s IRP list.

IrpList

An opaque pointer to the head of the IRP list associated with the file object.

FileObjectExtension

An opaque pointer to the file object‘s file object extension (FOBX) structure. The FOBX structure contains various opaque contexts used internally as well as the per-file object contexts available through FsRtlXxx routines.

Remarks

Drivers can use the FsContext and FsContext2 members to maintain driver-determined state about an open file object. A driver cannot use these members unless the file object is accessible in the driver‘s I/O stack location of an IRP.

All remaining members in a file object are either opaque or read-only:

  • Opaque members within a file object should be considered inaccessible. Drivers with dependencies on object field locations or access to opaque members might not remain portable and interoperable with other drivers over time.
  • Drivers can use read-only members to acquire relevant information but must not modify read-only members and, if a pointer, the object that the member points to.

During the processing of an IRP_MJ_CREATE request, a file system driver calls the IoSetShareAccess routine (if the client is the first to open the file) or the IoCheckShareAccess routine (for subsequent clients that want to share the file). IoSetShareAccess and IoCheckShareAccess update theReadAccessWriteAccess, and DeleteAccess members to indicate the access rights that are granted to the client if the client has exclusive access to the file. Additionally, IoCheckShareAccess updates the SharedReadSharedWrite, and SharedDelete members to indicate the access rights that are simultaneously granted to two or more clients that share the file. If the driver for a device other than a file system has to monitor the access rights of clients, this driver typically stores access rights information in context buffers that are pointed to by the FsContext and FsContext2 members.

Note  The type of object (for example, a file, directory, or volume) that a given file object represents cannot be determined by only examining the contents of the file object structure. For information about how to determine the type of object that a file object represents, seeZwQueryInformationFile.

时间: 2024-08-11 03:34:19

FILE_OBJECT的相关文章

Python读写文件

Python读写文件1.open使用open打开文件后一定要记得调用文件对象的close()方法.比如可以用try/finally语句来确保最后能关闭文件. file_object = open('thefile.txt')try:     all_the_text = file_object.read( )finally:     file_object.close( ) 注:不能把open语句放在try块里,因为当打开文件出现异常时,文件对象file_object无法执行close()方法.

python_字符_函数

一.字符集和字符编码 1.定义 计算机中储存的信息都是用二进制数表示的,而我们在屏幕上看到的英文.汉字等字符是二进制数转换之后的结果.通俗的说,按照何种规则将字符存储在计算机中,如'a'用什么表示,称为"编码":反之,将存储在计算机中的二进制数解析显示出来,称为"解码",如同密码学中的加密和解密.在解码过程中,如果使用了错误的解码规则,则导致'a'解析成'b'或者乱码. 字符(Character):是一个信息单位,在计算机里面,一个中文汉字是一个字符,一个英文字母是

Python对文件的操作(转)

一.文件对象 我理解的文件对象就是一个接口,通过这个接口对文件进行相关操作. <Python 核心编程>上说的很晦涩,这里没有深刻理解到,希望有人能解释给我听. >>> f = open('demo.txt','r') >>> f <open file 'demo.txt', mode 'r' at 0x00CCCEC0> >>> type(f) <type 'file'> 二.相关函数 [1].内建函数:open(

python 读取文本文件

Python的文本处理是经常碰到的一个问题,Python的文本文件的内容读取中,有三类方法:read().readline().readlines(),这三种方法各有利弊,下面逐一介绍其使用方法和利弊. read(): read()是最简单的一种方法,一次性读取文件的所有内容放在一个大字符串中,即存在内存中 file_object = open('test.txt') //不要把open放在try中,以防止打开失败,那么就不用关闭了 try: file_context = file_object

Python 基础 - Day 2 Learning Note - File 文件

文件 - 内建函数Open() FILE操作流程: 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 f.close Open()的基本语法: file_object = open(file_name, access_mode='r', buffering=-1) 手动创建yesterday 文件,access mode = reading, 只读,不可写或追加 f = open('yesterday', 'r', encoding='utf-8',) # r表示read

python批量Telnet远程主机

周末被Wanna Cry病毒轰炸的朋友圈,特写了个小脚本,可以批量检测网络内所有主机的445端口是否开启, 针对检测出来445端口开放的ip全部简单记录在txt中,支持协程和单线程2种模式 #!/usr/bin/env python2.7 # encoding:utf-8 import telnetlib import sys from gevent import monkey; reload(sys) sys.setdefaultencoding("utf-8") monkey.pa

第 10 章 文件和异常

至此,我们掌握了编写组织有序而易于使用的程序所需的基本技能,该考虑让程序目标更明确,用途更大了.在本章中,我们将学习处理文件,让程序能够快速地分析大量的数据:我们将学习错误处理,避免程序在面对意外情形时崩溃:我们将学习异常,它们是Python创建的特殊对象,用于管理程序运行时出现的错误:我们还将学习模块json,它让我们能够保存用户数据,以免在程序停止运行后丢失. 学习处理文件和保存数据可以让我们的程序使用起来更容易:用户将能够选择输入什么样的数据,以及在什么时候输入:用户使用我们的程序做一些工

python读取一个文件的每一行判断是否为素数,并把结果写到另一个文件中

刚刚学习python的菜鸟,这道题包括:文件的读写,python的参数调用,异常的使用,函数的使用 创建一个文本文件inti_prime.txt 执行命令:python Prime.py init_prime.txt result_prime.txt 会生成一个result_prime.txt文件 1 #-*- coding:UTF-8 -*- 2 #读取一个文件的每一行,每一行为一个数字 3 #判断数字是不是素数 4 #并打印结果到另外一个文件 5 #输入文件名和输出文件名用参数的形式 6 i

使用余弦定理计算两篇文章的相似性

使用余弦定理计算两篇文章的相似性:(方法论,细致易懂版) http://blog.csdn.net/dearwind153/article/details/52316151 python 实现(代码): http://outofmemory.cn/code-snippet/35172/match-text-release (结巴分词下载及安装:http://www.cnblogs.com/kaituorensheng/p/3595879.html) java 实现(代码+方法描述): https