ReactOS  0.4.14-dev-114-gc8cbd56
btrfs.c File Reference
#include "btrfs_drv.h"
#include <cpuid.h>
#include <ntddscsi.h>
#include "btrfs.h"
#include <ata.h>
#include <initguid.h>
#include <ntddstor.h>
#include <ntdddisk.h>
#include <ntddvol.h>
Include dependency graph for btrfs.c:

Go to the source code of this file.

Classes

struct  read_context
 

Macros

#define INCOMPAT_SUPPORTED
 
#define COMPAT_RO_SUPPORTED   (BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE | BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID)
 

Functions

NTSTATUS RtlStringCbVPrintfA (char *pszDest, size_t cbDest, const char *pszFormat, va_list argList)
 
 DEFINE_GUID (BtrfsBusInterface, 0x4d414874, 0x6865, 0x6761, 0x6d, 0x65, 0x83, 0x69, 0x17, 0x9a, 0x7d, 0x1d)
 
static NTSTATUS close_file (_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
 
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable (ULONG Version)
 
bool is_top_level (_In_ PIRP Irp)
 
 _Function_class_ (DRIVER_UNLOAD)
 
static bool get_last_inode (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_opt_ PIRP Irp)
 
 _Success_ (return)
 
 _Dispatch_type_ (IRP_MJ_CLOSE)
 
 _Dispatch_type_ (IRP_MJ_FLUSH_BUFFERS)
 
static void calculate_total_space (_In_ device_extension *Vcb, _Out_ uint64_t *totalsize, _Out_ uint64_t *freespace)
 
static bool lie_about_fs_type ()
 
NTSTATUS utf8_to_utf16 (WCHAR *dest, ULONG dest_max, ULONG *dest_len, char *src, ULONG src_len)
 
NTSTATUS utf16_to_utf8 (char *dest, ULONG dest_max, ULONG *dest_len, WCHAR *src, ULONG src_len)
 
 _Dispatch_type_ (IRP_MJ_QUERY_VOLUME_INFORMATION)
 
 _Function_class_ (IO_COMPLETION_ROUTINE)
 
NTSTATUS create_root (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ uint64_t id, _Out_ root **rootptr, _In_ bool no_tree, _In_ uint64_t offset, _In_opt_ PIRP Irp)
 
static NTSTATUS set_label (_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
 
 _Dispatch_type_ (IRP_MJ_SET_VOLUME_INFORMATION)
 
static WCHARfile_desc_fcb (_In_ fcb *fcb)
 
WCHARfile_desc_fileref (_In_ file_ref *fileref)
 
_Ret_z_ WCHARfile_desc (_In_ PFILE_OBJECT FileObject)
 
void send_notification_fileref (_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
 
void send_notification_fcb (_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
 
void mark_fcb_dirty (_In_ fcb *fcb)
 
void mark_fileref_dirty (_In_ file_ref *fileref)
 
void free_fcb (_Inout_ fcb *fcb)
 
void reap_fcb (fcb *fcb)
 
void reap_fcbs (device_extension *Vcb)
 
void free_fileref (_Inout_ file_ref *fr)
 
void reap_fileref (device_extension *Vcb, file_ref *fr)
 
void reap_filerefs (device_extension *Vcb, file_ref *fr)
 
void uninit (_In_ device_extension *Vcb)
 
static NTSTATUS delete_fileref_fcb (_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
 
NTSTATUS delete_fileref (_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_ bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
 
 _Dispatch_type_ (IRP_MJ_CLEANUP)
 
ULONG get_file_attributes (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ uint64_t inode, _In_ uint8_t type, _In_ bool dotfile, _In_ bool ignore_xa, _In_opt_ PIRP Irp)
 
NTSTATUS sync_read_phys (_In_ PDEVICE_OBJECT DeviceObject, _In_ PFILE_OBJECT FileObject, _In_ uint64_t StartingOffset, _In_ ULONG Length, _Out_writes_bytes_(Length) PUCHAR Buffer, _In_ bool override)
 
static NTSTATUS read_superblock (_In_ device_extension *Vcb, _In_ PDEVICE_OBJECT device, _In_ PFILE_OBJECT fileobj, _In_ uint64_t length)
 
NTSTATUS dev_ioctl (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize, _Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _In_ bool Override, _Out_opt_ IO_STATUS_BLOCK *iosb)
 
 _Requires_exclusive_lock_held_ (Vcb->tree_lock) static NTSTATUS add_root(_Inout_ device_extension *Vcb
 
 if (!r)
 
 RtlZeroMemory (r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
 
 if (!r->nonpaged)
 
 if (tp)
 
else RtlZeroMemoryr (ROOT_ITEM)
 
 if (!Vcb->readonly &&(r->id==BTRFS_ROOT_ROOT||r->id==BTRFS_ROOT_FSTREE||(r->id >=0x100 &&!(r->id &0xf000000000000000))))
 
 switch (r->id)
 
static NTSTATUS look_for_roots (_Requires_exclusive_lock_held_(_Curr_->tree_lock) _In_ device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS find_disk_holes (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ device *dev, _In_opt_ PIRP Irp)
 
static void add_device_to_list (_In_ device_extension *Vcb, _In_ device *dev)
 
_Ret_maybenull_ devicefind_device_from_uuid (_In_ device_extension *Vcb, _In_ BTRFS_UUID *uuid)
 
static bool is_device_removable (_In_ PDEVICE_OBJECT devobj)
 
static ULONG get_device_change_count (_In_ PDEVICE_OBJECT devobj)
 
void init_device (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ bool get_nums)
 
static NTSTATUS load_chunk_root (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
void protect_superblocks (_Inout_ chunk *c)
 
uint64_t chunk_estimate_phys_size (device_extension *Vcb, chunk *c, uint64_t u)
 
NTSTATUS find_chunk_usage (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS load_sys_chunks (_In_ device_extension *Vcb)
 
static _Ret_maybenull_ rootfind_default_subvol (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
void init_file_cache (_In_ PFILE_OBJECT FileObject, _In_ CC_FILE_SIZES *ccfs)
 
uint32_t get_num_of_processors ()
 
static NTSTATUS create_calc_threads (_In_ PDEVICE_OBJECT DeviceObject)
 
static bool is_btrfs_volume (_In_ PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS get_device_pnp_name_guid (_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _In_ const GUID *guid)
 
NTSTATUS get_device_pnp_name (_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _Out_ const GUID **guid)
 
 _Success_ (return >=0) static NTSTATUS check_mount_device(_In_ PDEVICE_OBJECT DeviceObject
 
 if (!NT_SUCCESS(Status))
 
 if (sb->magic !=BTRFS_MAGIC)
 
 if (crc32 != *((uint32_t *) sb->checksum))
 
 if (pnp_name.Length==0) *pno_pnp
 
 volume_arrival (drvobj, &pnp_name)
 
static bool still_has_superblock (_In_ PDEVICE_OBJECT device, _In_ PFILE_OBJECT fileobj)
 
static NTSTATUS mount_vol (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS verify_device (_In_ device_extension *Vcb, _Inout_ device *dev)
 
static NTSTATUS verify_volume (_In_ PDEVICE_OBJECT devobj)
 
 _Dispatch_type_ (IRP_MJ_FILE_SYSTEM_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_LOCK_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_SHUTDOWN)
 
 _Dispatch_type_ (IRP_MJ_POWER)
 
 _Dispatch_type_ (IRP_MJ_SYSTEM_CONTROL)
 
bool is_file_name_valid (_In_ PUNICODE_STRING us, _In_ bool posix)
 
void chunk_lock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ uint64_t start, _In_ uint64_t length)
 
void chunk_unlock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ uint64_t start, _In_ uint64_t length)
 
void log_device_error (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ int error)
 
static void check_cpu ()
 
 _Function_class_ (KSTART_ROUTINE)
 
 _Function_class_ (DRIVER_ADD_DEVICE)
 
 _Function_class_ (DRIVER_INITIALIZE)
 

Variables

static const WCHAR device_name [] = {'\\','B','t','r','f','s',0}
 
static const WCHAR dosdevice_name [] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','B','t','r','f','s',0}
 
PDRIVER_OBJECT drvobj
 
PDEVICE_OBJECT master_devobj
 
PDEVICE_OBJECT busobj
 
bool have_sse42 = false
 
bool have_sse2 = false
 
uint64_t num_reads = 0
 
LIST_ENTRY uid_map_list
 
LIST_ENTRY gid_map_list
 
LIST_ENTRY VcbList
 
ERESOURCE global_loading_lock
 
uint32_t debug_log_level = 0
 
uint32_t mount_compress = 0
 
uint32_t mount_compress_force = 0
 
uint32_t mount_compress_type = 0
 
uint32_t mount_zlib_level = 3
 
uint32_t mount_zstd_level = 3
 
uint32_t mount_flush_interval = 30
 
uint32_t mount_max_inline = 2048
 
uint32_t mount_skip_balance = 0
 
uint32_t mount_no_barrier = 0
 
uint32_t mount_no_trim = 0
 
uint32_t mount_clear_cache = 0
 
uint32_t mount_allow_degraded = 0
 
uint32_t mount_readonly = 0
 
uint32_t no_pnp = 0
 
bool log_started = false
 
UNICODE_STRING log_device
 
UNICODE_STRING log_file
 
UNICODE_STRING registry_path
 
tPsUpdateDiskCounters fPsUpdateDiskCounters
 
tCcCopyReadEx fCcCopyReadEx
 
tCcCopyWriteEx fCcCopyWriteEx
 
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
 
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
 
tIoUnregisterPlugPlayNotificationEx fIoUnregisterPlugPlayNotificationEx
 
tFsRtlGetEcpListFromIrp fFsRtlGetEcpListFromIrp
 
tFsRtlGetNextExtraCreateParameter fFsRtlGetNextExtraCreateParameter
 
tFsRtlValidateReparsePointBuffer fFsRtlValidateReparsePointBuffer
 
bool diskacc = false
 
voidnotification_entry = NULL
 
voidnotification_entry2 = NULL
 
voidnotification_entry3 = NULL
 
ERESOURCE pdo_list_lock
 
ERESOURCE mapping_lock
 
LIST_ENTRY pdo_list
 
bool finished_probing = false
 
HANDLE degraded_wait_handle = NULL
 
HANDLE mountmgr_thread_handle = NULL
 
bool degraded_wait = true
 
KEVENT mountmgr_thread_event
 
bool shutting_down = false
 
_In_ uint64_t id = id
 
_In_ uint64_t _In_ uint64_t addr
 
_In_ uint64_t _In_ uint64_t _In_ uint64_t generation = generation
 
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptrtp
 
r dirty = false
 
r received = false
 
r reserved = NULL
 
r treeholder address = addr
 
r treeholder tree = NULL
 
r parent = 0
 
r send_ops = 0
 
r fcbs_version = 0
 
r checked_for_orphans = false
 
InitializeListHeadr
 
r nonpaged = ExAllocatePoolWithTag(NonPagedPool, sizeof(root_nonpaged), ALLOC_TAG)
 
r lastinode = 0
 
InsertTailListVcb
 
return STATUS_SUCCESS
 
_Out_ boolpno_pnp
 
ULONG to_read = DeviceObject->SectorSize == 0 ? sizeof(superblock) : (ULONG)sector_align(sizeof(superblock), DeviceObject->SectorSize)
 
superblocksb = ExAllocatePoolWithTag(NonPagedPool, to_read, ALLOC_TAG)
 
uint32_t crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum))
 
UNICODE_STRING pnp_name
 
const GUIDguid
 
 Status = sync_read_phys(DeviceObject, NULL, superblock_addrs[0], to_read, (PUCHAR)sb, true)
 
DeviceObject Flags &pnp_name Buffer = NULL
 
 else
 
end __pad0__
 

Macro Definition Documentation

◆ COMPAT_RO_SUPPORTED

◆ INCOMPAT_SUPPORTED

#define INCOMPAT_SUPPORTED
Value:
BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO | BTRFS_INCOMPAT_FLAGS_BIG_METADATA | BTRFS_INCOMPAT_FLAGS_RAID56 | \
BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA | BTRFS_INCOMPAT_FLAGS_NO_HOLES | \
BTRFS_INCOMPAT_FLAGS_COMPRESS_ZSTD)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:113
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:107
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:105
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:110
#define BTRFS_INCOMPAT_FLAGS_NO_HOLES
Definition: btrfs.h:114
#define BTRFS_INCOMPAT_FLAGS_RAID56
Definition: btrfs.h:112
#define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL
Definition: btrfs.h:106

Definition at line 55 of file btrfs.c.

Function Documentation

◆ _Dispatch_type_() [1/10]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 479 of file btrfs.c.

481  {
485  bool top_level;
486 
488 
489  TRACE("close\n");
490 
491  top_level = is_top_level(Irp);
492 
493  if (DeviceObject == master_devobj) {
494  TRACE("Closing file system\n");
496  goto end;
497  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
499  goto end;
500  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
502  goto end;
503  }
504 
506 
507  // FIXME - unmount if called for volume
508  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
509 
511 
512 end:
513  Irp->IoStatus.Status = Status;
514  Irp->IoStatus.Information = 0;
515 
517 
518  if (top_level)
520 
521  TRACE("returning %08x\n", Status);
522 
524 
525  return Status;
526 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2930
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1894
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:49
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Dispatch_type_() [2/10]

_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 528 of file btrfs.c.

530  {
534  fcb* fcb = FileObject->FsContext;
536  bool top_level;
537 
539 
540  TRACE("flush buffers\n");
541 
542  top_level = is_top_level(Irp);
543 
544  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
546  goto end;
547  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
549  goto end;
550  }
551 
552  if (!fcb) {
553  ERR("fcb was NULL\n");
555  goto end;
556  }
557 
558  if (fcb == Vcb->volume_fcb) {
560  goto end;
561  }
562 
563  Irp->IoStatus.Information = 0;
564 
565  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
566 
568  Irp->IoStatus.Status = Status;
569 
570  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
571  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &Irp->IoStatus);
572 
573  if (fcb->Header.PagingIoResource) {
574  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
575  ExReleaseResourceLite(fcb->Header.PagingIoResource);
576  }
577 
578  Status = Irp->IoStatus.Status;
579  }
580 
581 end:
583 
584  TRACE("returning %08x\n", Status);
585 
586  if (top_level)
588 
590 
591  return Status;
592 }
#define FsRtlEnterFileSystem
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:309
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:81
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:280
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
InsertTailList & Vcb
Definition: btrfs.c:2930
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:272
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1575
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Dispatch_type_() [3/10]

_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 932 of file btrfs.c.

934  {
937  ULONG BytesCopied = 0;
939  bool top_level;
940 
942 
943  TRACE("query volume information\n");
944  top_level = is_top_level(Irp);
945 
946  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
948  goto end;
949  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
951  goto end;
952  }
953 
955 
957 
958  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
960  {
961  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
962  bool overflow = false;
963 #ifndef __REACTOS__
964  static const WCHAR ntfs[] = L"NTFS";
965 #endif
966  static const WCHAR btrfs[] = L"Btrfs";
967  const WCHAR* fs_name;
968  ULONG fs_name_len, orig_fs_name_len;
969 
970 #ifndef __REACTOS__
971  if (Irp->RequestorMode == UserMode && lie_about_fs_type()) {
972  fs_name = ntfs;
973  orig_fs_name_len = fs_name_len = sizeof(ntfs) - sizeof(WCHAR);
974  } else {
975  fs_name = btrfs;
976  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
977  }
978 #else
979  fs_name = btrfs;
980  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
981 #endif
982 
983  TRACE("FileFsAttributeInformation\n");
984 
985  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
986  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
987  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
988  else
989  fs_name_len = 0;
990 
991  overflow = true;
992  }
993 
994  data->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_CASE_SENSITIVE_SEARCH |
999  if (Vcb->readonly)
1000  data->FileSystemAttributes |= FILE_READ_ONLY_VOLUME;
1001 
1002  // should also be FILE_FILE_COMPRESSION when supported
1003  data->MaximumComponentNameLength = 255; // FIXME - check
1004  data->FileSystemNameLength = orig_fs_name_len;
1005  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
1006 
1007  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
1009  break;
1010  }
1011 
1013  {
1014  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
1015 
1016  TRACE("FileFsDeviceInformation\n");
1017 
1018  ffdi->DeviceType = FILE_DEVICE_DISK;
1019 
1020  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1021  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
1022  ExReleaseResourceLite(&Vcb->tree_lock);
1023 
1024  if (Vcb->readonly)
1026  else
1028 
1031 
1032  break;
1033  }
1034 
1036  {
1037  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1038 
1039  TRACE("FileFsFullSizeInformation\n");
1040 
1043  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1044  ffsi->BytesPerSector = 512;
1045 
1048 
1049  break;
1050  }
1051 
1053  {
1054  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
1055 
1056  TRACE("FileFsObjectIdInformation\n");
1057 
1058  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
1059  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
1060 
1063 
1064  break;
1065  }
1066 
1067  case FileFsSizeInformation:
1068  {
1069  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1070 
1071  TRACE("FileFsSizeInformation\n");
1072 
1074  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1075  ffsi->BytesPerSector = 512;
1076 
1079 
1080  break;
1081  }
1082 
1084  {
1085  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1087  bool overflow = false;
1088  ULONG label_len, orig_label_len;
1089 
1090  TRACE("FileFsVolumeInformation\n");
1091  TRACE("max length = %u\n", IrpSp->Parameters.QueryVolume.Length);
1092 
1093  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1094 
1095  Status = utf8_to_utf16(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1096  if (!NT_SUCCESS(Status)) {
1097  ERR("utf8_to_utf16 returned %08x\n", Status);
1098  ExReleaseResourceLite(&Vcb->tree_lock);
1099  break;
1100  }
1101 
1102  orig_label_len = label_len;
1103 
1104  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len) {
1105  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR))
1106  label_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_VOLUME_INFORMATION) + sizeof(WCHAR);
1107  else
1108  label_len = 0;
1109 
1110  overflow = true;
1111  }
1112 
1113  TRACE("label_len = %u\n", label_len);
1114 
1115  ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
1116  ffvi.VolumeSerialNumber = Vcb->superblock.uuid.uuid[12] << 24 | Vcb->superblock.uuid.uuid[13] << 16 | Vcb->superblock.uuid.uuid[14] << 8 | Vcb->superblock.uuid.uuid[15];
1117  ffvi.VolumeLabelLength = orig_label_len;
1118  ffvi.SupportsObjects = false;
1119 
1120  RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
1121 
1122  if (label_len > 0) {
1123  ULONG bytecount;
1124 
1125  Status = utf8_to_utf16(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1127  ERR("utf8_to_utf16 returned %08x\n", Status);
1128  ExReleaseResourceLite(&Vcb->tree_lock);
1129  break;
1130  }
1131 
1132  TRACE("label = %.*S\n", label_len / sizeof(WCHAR), data->VolumeLabel);
1133  }
1134 
1135  ExReleaseResourceLite(&Vcb->tree_lock);
1136 
1137  BytesCopied = sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len;
1139  break;
1140  }
1141 
1142 #ifndef __REACTOS__
1143 #ifdef _MSC_VER // not in mingw yet
1144  case FileFsSectorSizeInformation:
1145  {
1146  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1147 
1148  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
1149  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1150  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
1151  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1152  data->ByteOffsetForSectorAlignment = 0;
1153  data->ByteOffsetForPartitionAlignment = 0;
1154 
1155  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
1156 
1157  if (Vcb->trim && !Vcb->options.no_trim)
1158  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
1159 
1160  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
1161 
1162  break;
1163  }
1164 #endif
1165 #endif /* __REACTOS__ */
1166 
1167  default:
1169  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
1170  break;
1171  }
1172 
1174  Irp->IoStatus.Information = 0;
1175  else
1176  Irp->IoStatus.Information = BytesCopied;
1177 
1178 end:
1179  Irp->IoStatus.Status = Status;
1180 
1182 
1183  if (top_level)
1185 
1186  TRACE("query volume information returning %08x\n", Status);
1187 
1189 
1190  return Status;
1191 }
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
struct _FILE_FS_FULL_SIZE_INFORMATION FILE_FS_FULL_SIZE_INFORMATION
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _FILE_FS_OBJECTID_INFORMATION FILE_FS_OBJECTID_INFORMATION
#define FsRtlEnterFileSystem
NTSTATUS vol_query_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:315
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_SUPPORTS_OBJECT_IDS
Definition: from_kernel.h:243
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WARN(fmt,...)
Definition: debug.h:111
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
#define FILE_SUPPORTS_POSIX_UNLINK_RENAME
Definition: btrfs_drv.h:144
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
static bool lie_about_fs_type()
Definition: btrfs.c:624
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2930
#define FILE_UNICODE_ON_DISK
Definition: from_kernel.h:235
#define TRACE(s)
Definition: solgame.cpp:4
LARGE_INTEGER VolumeCreationTime
Definition: winioctl.h:408
#define FILE_SUPPORTS_BLOCK_REFCOUNTING
Definition: btrfs_drv.h:140
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
#define FILE_CASE_SENSITIVE_SEARCH
Definition: from_kernel.h:233
NTSTATUS utf8_to_utf16(WCHAR *dest, ULONG dest_max, ULONG *dest_len, char *src, ULONG src_len)
Definition: btrfs.c:734
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define FILE_NAMED_STREAMS
Definition: from_kernel.h:245
#define FILE_SUPPORTS_OPEN_BY_FILE_ID
Definition: from_kernel.h:251
unsigned char UCHAR
Definition: xmlstorage.h:181
static void calculate_total_space(_In_ device_extension *Vcb, _Out_ uint64_t *totalsize, _Out_ uint64_t *freespace)
Definition: btrfs.c:594
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static const WCHAR L[]
Definition: oid.c:1250
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
Status
Definition: gdiplustypes.h:24
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
UINT64 uint64_t
Definition: types.h:77
#define FILE_SUPPORTS_SPARSE_FILES
Definition: from_kernel.h:239
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
#define min(a, b)
Definition: monoChain.cc:55
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES
Definition: from_kernel.h:250
struct _FILE_FS_VOLUME_INFORMATION FILE_FS_VOLUME_INFORMATION
unsigned int ULONG
Definition: retypes.h:1
#define FILE_PERSISTENT_ACLS
Definition: from_kernel.h:236
#define FILE_READ_ONLY_VOLUME
Definition: from_kernel.h:246
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
LARGE_INTEGER CallerAvailableAllocationUnits
Definition: from_kernel.h:271
#define FILE_READ_ONLY_DEVICE
Definition: nt_native.h:808
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:270
LONGLONG QuadPart
Definition: typedefs.h:112

◆ _Dispatch_type_() [4/10]

_Dispatch_type_ ( IRP_MJ_SET_VOLUME_INFORMATION  )

Definition at line 1384 of file btrfs.c.

1386  {
1389  NTSTATUS Status;
1390  bool top_level;
1391 
1393 
1394  TRACE("set volume information\n");
1395 
1396  top_level = is_top_level(Irp);
1397 
1398  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1400  goto end;
1401  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1403  goto end;
1404  }
1405 
1407 
1408  if (Vcb->readonly) {
1410  goto end;
1411  }
1412 
1413  if (Vcb->removing || Vcb->locked) {
1415  goto end;
1416  }
1417 
1418  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1420  FIXME("STUB: FileFsControlInformation\n");
1421  break;
1422 
1424  TRACE("FileFsLabelInformation\n");
1425 
1426  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1427  break;
1428 
1430  FIXME("STUB: FileFsObjectIdInformation\n");
1431  break;
1432 
1433  default:
1434  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1435  break;
1436  }
1437 
1438 end:
1439  Irp->IoStatus.Status = Status;
1440  Irp->IoStatus.Information = 0;
1441 
1442  TRACE("returning %08x\n", Status);
1443 
1445 
1446  if (top_level)
1448 
1450 
1451  return Status;
1452 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define FIXME(fmt,...)
Definition: debug.h:110
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
InsertTailList & Vcb
Definition: btrfs.c:2930
#define TRACE(s)
Definition: solgame.cpp:4
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1329
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS vol_set_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:321

◆ _Dispatch_type_() [5/10]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2385 of file btrfs.c.

2387  {
2388  NTSTATUS Status;
2392  fcb* fcb = FileObject->FsContext;
2393  bool top_level;
2394 
2396 
2397  TRACE("cleanup\n");
2398 
2399  top_level = is_top_level(Irp);
2400 
2401  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2403  goto exit;
2404  } else if (DeviceObject == master_devobj) {
2405  TRACE("closing file system\n");
2407  goto exit;
2408  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2410  goto exit;
2411  }
2412 
2413  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2414  TRACE("FileObject %p already cleaned up\n", FileObject);
2416  goto exit;
2417  }
2418 
2419  if (!fcb) {
2420  ERR("fcb was NULL\n");
2422  goto exit;
2423  }
2424 
2425  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2426  // messages belonging to other devices.
2427 
2428  if (FileObject && FileObject->FsContext) {
2429  LONG oc;
2430  ccb* ccb;
2431  file_ref* fileref;
2432  bool locked = true;
2433 
2434  ccb = FileObject->FsContext2;
2435  fileref = ccb ? ccb->fileref : NULL;
2436 
2437  TRACE("cleanup called for FileObject %p\n", FileObject);
2438  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2439 
2440  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
2441 
2442  ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
2443 
2445 
2447 
2448  if (ccb)
2449  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2450 
2451  if (fileref) {
2452  oc = InterlockedDecrement(&fileref->open_count);
2453 #ifdef DEBUG_FCB_REFCOUNTS
2454  ERR("fileref %p: open_count now %i\n", fileref, oc);
2455 #endif
2456  }
2457 
2458  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2459  fileref->delete_on_close = true;
2460 
2461  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2462  fileref->delete_on_close = false;
2463 
2464  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2465  TRACE("unlocking volume\n");
2468  }
2469 
2470  if (ccb && ccb->reserving) {
2471  fcb->subvol->reserved = NULL;
2472  ccb->reserving = false;
2473  // FIXME - flush all of subvol's fcbs
2474  }
2475 
2476  if (fileref && (oc == 0 || (fileref->delete_on_close && fileref->posix_delete))) {
2477  if (!fcb->Vcb->removing) {
2478  if (oc == 0 && fileref->fcb->inode_item.st_nlink == 0 && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) { // last handle closed on POSIX-deleted file
2480 
2482 
2484  if (!NT_SUCCESS(Status)) {
2485  ERR("delete_fileref_fcb returned %08x\n", Status);
2487  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2488  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2489  goto exit;
2490  }
2491 
2493 
2494  mark_fcb_dirty(fileref->fcb);
2495  } else if (fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2497 
2499 
2500  if (!fileref->fcb->ads || fileref->dc) {
2501  if (fileref->fcb->ads) {
2503  FILE_ACTION_REMOVED, &fileref->dc->name);
2504  } else
2506  }
2507 
2508  ExReleaseResourceLite(fcb->Header.Resource);
2509  locked = false;
2510 
2511  // fileref_lock needs to be acquired before fcb->Header.Resource
2512  ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
2513 
2514  Status = delete_fileref(fileref, FileObject, oc > 0 && fileref->posix_delete, Irp, &rollback);
2515  if (!NT_SUCCESS(Status)) {
2516  ERR("delete_fileref returned %08x\n", Status);
2518  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2519  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2520  goto exit;
2521  }
2522 
2523  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2524 
2526  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && FileObject->SectionObjectPointer->DataSectionObject) {
2528  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2529 
2530  if (!NT_SUCCESS(iosb.Status)) {
2531  ERR("CcFlushCache returned %08x\n", iosb.Status);
2532  }
2533 
2534  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2535  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
2536  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2537  }
2538 
2539  CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, false);
2540 
2541  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2542  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2543  }
2544  }
2545 
2546  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2548  }
2549 
2550  if (locked)
2551  ExReleaseResourceLite(fcb->Header.Resource);
2552 
2553  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2554 
2555  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2556  }
2557 
2559 
2560 exit:
2561  TRACE("returning %08x\n", Status);
2562 
2563  Irp->IoStatus.Status = Status;
2564  Irp->IoStatus.Information = 0;
2565 
2567 
2568  if (top_level)
2570 
2572 
2573  return Status;
2574 }
struct _file_ref * parent
Definition: btrfs_drv.h:346
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1049
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1028
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:369
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
Status
Definition: btrfs.c:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:345
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define FILE_NOTIFY_CHANGE_DIR_NAME
void send_notification_fileref(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1543
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
bool posix_delete
Definition: btrfs_drv.h:339
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:635
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
long LONG
Definition: pedump.c:60
uint32_t st_nlink
Definition: btrfs.h:274
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:81
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
void mark_fcb_dirty(_In_ fcb *fcb)
Definition: btrfs.c:1664
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:280
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG refcount
Definition: btrfs_drv.h:344
FILE_LOCK lock
Definition: btrfs_drv.h:283
InsertTailList & Vcb
Definition: btrfs.c:2930
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:272
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
uint64_t st_size
Definition: btrfs.h:271
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1738
dir_child * dc
Definition: btrfs_drv.h:348
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define InterlockedDecrement
Definition: armddk.h:52
NTSTATUS vol_cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:327
fcb * fcb
Definition: btrfs_drv.h:335
Definition: typedefs.h:117
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1026
INODE_ITEM inode_item
Definition: btrfs_drv.h:281
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1747
static NTSTATUS delete_fileref_fcb(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2161
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _root * subvol
Definition: btrfs_drv.h:277
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1301
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
bool ads
Definition: btrfs_drv.h:319
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_ bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2217
#define IO_NO_INCREMENT
Definition: iotypes.h:566
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
bool reserving
Definition: btrfs_drv.h:376
SHARE_ACCESS share_access
Definition: btrfs_drv.h:287
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:378
return STATUS_SUCCESS
Definition: btrfs.c:2966
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2318
struct _device_extension * Vcb
Definition: btrfs_drv.h:276
UNICODE_STRING name
Definition: btrfs_drv.h:246
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1529
bool delete_on_close
Definition: btrfs_drv.h:338

◆ _Dispatch_type_() [6/10]

_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 5083 of file btrfs.c.

5085  {
5087  NTSTATUS Status;
5089  bool top_level;
5090 
5092 
5093  TRACE("file system control\n");
5094 
5095  top_level = is_top_level(Irp);
5096 
5097  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5099  goto end;
5100  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
5102  goto end;
5103  }
5104 
5106 
5108 
5109  Irp->IoStatus.Information = 0;
5110 
5111  switch (IrpSp->MinorFunction) {
5112  case IRP_MN_MOUNT_VOLUME:
5113  TRACE("IRP_MN_MOUNT_VOLUME\n");
5114 
5116  break;
5117 
5118  case IRP_MN_KERNEL_CALL:
5119  TRACE("IRP_MN_KERNEL_CALL\n");
5120 
5121  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
5122  break;
5123 
5125  TRACE("IRP_MN_USER_FS_REQUEST\n");
5126 
5127  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
5128  break;
5129 
5130  case IRP_MN_VERIFY_VOLUME:
5131  TRACE("IRP_MN_VERIFY_VOLUME\n");
5132 
5134 
5135  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
5136  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
5137  Vcb->removing = true;
5138  ExReleaseResourceLite(&Vcb->tree_lock);
5139  }
5140 
5141  break;
5142 
5143  default:
5144  break;
5145  }
5146 
5147 end:
5148  TRACE("returning %08x\n", Status);
5149 
5150  if (Irp) {
5151  Irp->IoStatus.Status = Status;
5152 
5154  }
5155 
5156  if (top_level)
5158 
5160 
5161  return Status;
5162 }
#define FsRtlEnterFileSystem
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, uint32_t type)
Definition: fsctl.c:4838
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4049
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS vol_file_system_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:341
InsertTailList & Vcb
Definition: btrfs.c:2930
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4048
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4047
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4052
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:658
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IO_NO_INCREMENT
Definition: iotypes.h:566
static NTSTATUS verify_volume(_In_ PDEVICE_OBJECT devobj)
Definition: btrfs.c:5024
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define VPB_MOUNTED
Definition: iotypes.h:1764
static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: btrfs.c:4271

◆ _Dispatch_type_() [7/10]

_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 5164 of file btrfs.c.

5166  {
5167  NTSTATUS Status;
5169  fcb* fcb = IrpSp->FileObject->FsContext;
5171  bool top_level;
5172 
5174 
5175  top_level = is_top_level(Irp);
5176 
5177  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5179 
5180  Irp->IoStatus.Status = Status;
5182 
5183  goto exit;
5184  }
5185 
5186  TRACE("lock control\n");
5187 
5189 
5190  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
5191 
5192 exit:
5193  TRACE("returning %08x\n", Status);
5194 
5195  if (top_level)
5197 
5199 
5200  return Status;
5201 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FILE_LOCK lock
Definition: btrfs_drv.h:283
InsertTailList & Vcb
Definition: btrfs.c:2930
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:272
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1153
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS vol_lock_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:347
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1575
void exit(int exitcode)
Definition: _exit.c:33

◆ _Dispatch_type_() [8/10]

_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 5203 of file btrfs.c.

5205  {
5206  NTSTATUS Status;
5207  bool top_level;
5209  LIST_ENTRY* le;
5210 
5212 
5213  TRACE("shutdown\n");
5214 
5215  top_level = is_top_level(Irp);
5216 
5217  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5219  goto end;
5220  }
5221 
5223 
5224  shutting_down = true;
5225  KeSetEvent(&mountmgr_thread_event, 0, false);
5226 
5227  le = VcbList.Flink;
5228  while (le != &VcbList) {
5229  bool open_files;
5230  LIST_ENTRY* le2 = le->Flink;
5231 
5233 
5234  TRACE("shutting down Vcb %p\n", Vcb);
5235 
5236  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
5237  Vcb->removing = true;
5238  open_files = Vcb->open_files > 0;
5239 
5240  if (Vcb->need_write && !Vcb->readonly) {
5241  Status = do_write(Vcb, Irp);
5242  if (!NT_SUCCESS(Status))
5243  ERR("do_write returned %08x\n", Status);
5244  }
5245 
5246  free_trees(Vcb);
5247 
5248  ExReleaseResourceLite(&Vcb->tree_lock);
5249 
5250  if (!open_files)
5251  uninit(Vcb);
5252 
5253  le = le2;
5254  }
5255 
5256 #ifdef _DEBUG
5257  if (comfo) {
5258  ObDereferenceObject(comfo);
5259  comdo = NULL;
5260  comfo = NULL;
5261  }
5262 #endif
5263 
5264 end:
5265  Irp->IoStatus.Status = Status;
5266  Irp->IoStatus.Information = 0;
5267 
5269 
5270  if (top_level)
5272 
5274 
5275  return Status;
5276 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LIST_ENTRY VcbList
Definition: btrfs.c:73
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7652
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
GLuint GLuint end
Definition: gl.h:1545
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1970
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void free_trees(device_extension *Vcb)
Definition: treefuncs.c:793
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
bool shutting_down
Definition: btrfs.c:109
InsertTailList & Vcb
Definition: btrfs.c:2930
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS vol_shutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:863
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
KEVENT mountmgr_thread_event
Definition: btrfs.c:108
Definition: list.h:27
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Dispatch_type_() [9/10]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5278 of file btrfs.c.

5280  {
5281  NTSTATUS Status;
5284  bool top_level;
5285 
5287 
5288  top_level = is_top_level(Irp);
5289 
5290  Irp->IoStatus.Information = 0;
5291 
5292  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5294 
5298 
5299  goto exit;
5300  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5302 
5303  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5304 
5305  goto exit;
5306  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5308 
5312 
5313  goto exit;
5314  }
5315 
5317  Irp->IoStatus.Status = STATUS_SUCCESS;
5318 
5319  Status = Irp->IoStatus.Status;
5320 
5322 
5324 
5325 exit:
5326  if (top_level)
5328 
5330 
5331  return Status;
5332 }
#define FsRtlEnterFileSystem
#define IRP_MN_QUERY_POWER
#define FsRtlExitFileSystem
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:661
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2930
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define IRP_MN_SET_POWER
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:847
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:817
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:566
void exit(int exitcode)
Definition: _exit.c:33
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Dispatch_type_() [10/10]

_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5334 of file btrfs.c.

5336  {
5337  NTSTATUS Status;
5339  bool top_level;
5340 
5342 
5343  top_level = is_top_level(Irp);
5344 
5345  Irp->IoStatus.Information = 0;
5346 
5347  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5349 
5351 
5353 
5354  goto exit;
5355  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5357 
5358  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5359 
5360  goto exit;
5361  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5363 
5365 
5367 
5368  goto exit;
5369  }
5370 
5371  Status = Irp->IoStatus.Status;
5373 
5374 exit:
5375  if (top_level)
5377 
5379 
5380  return Status;
5381 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:661
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2930
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:847
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:817
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:566
void exit(int exitcode)
Definition: _exit.c:33

◆ _Function_class_() [1/5]

_Function_class_ ( DRIVER_UNLOAD  )

Definition at line 281 of file btrfs.c.

282  {
283  UNICODE_STRING dosdevice_nameW;
284 
285  TRACE("(%p)\n", DriverObject);
286 
287  free_cache();
288 
290 
291  if (notification_entry2) {
294  else
296  }
297 
298  if (notification_entry3) {
301  else
303  }
304 
305  if (notification_entry) {
308  else
310  }
311 
312  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
313  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
314 
315  IoDeleteSymbolicLink(&dosdevice_nameW);
317 
318  while (!IsListEmpty(&uid_map_list)) {
320  uid_map* um = CONTAINING_RECORD(le, uid_map, listentry);
321 
322  ExFreePool(um->sid);
323 
324  ExFreePool(um);
325  }
326 
327  while (!IsListEmpty(&gid_map_list)) {
329 
330  ExFreePool(gm->sid);
331  ExFreePool(gm);
332  }
333 
334  // FIXME - free volumes and their devpaths
335 
336 #ifdef _DEBUG
337  if (comfo)
338  ObDereferenceObject(comfo);
339 
340  if (log_handle)
341  ZwClose(log_handle);
342 #endif
343 
346 
347  if (log_device.Buffer)
349 
350  if (log_file.Buffer)
352 
353  if (registry_path.Buffer)
355 
356 #ifdef _DEBUG
357  ExDeleteResourceLite(&log_lock);
358 #endif
360 }
NTSTATUS NTAPI IoUnregisterPlugPlayNotification(IN PVOID NotificationEntry)
Definition: pnpnotify.c:371
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
void * notification_entry3
Definition: btrfs.c:102
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1061
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
UNICODE_STRING log_file
Definition: btrfs.c:91
void free_cache()
Definition: cache.c:100
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
void * notification_entry2
Definition: btrfs.c:102
PSID sid
Definition: btrfs_drv.h:875
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UNICODE_STRING registry_path
Definition: btrfs.c:91
PSID sid
Definition: btrfs_drv.h:869
static const WCHAR dosdevice_name[]
Definition: btrfs.c:62
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
void * notification_entry
Definition: btrfs.c:102
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LIST_ENTRY uid_map_list
Definition: btrfs.c:72
Definition: typedefs.h:117
ERESOURCE mapping_lock
Definition: btrfs.c:103
ERESOURCE global_loading_lock
Definition: btrfs.c:74
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
tIoUnregisterPlugPlayNotificationEx fIoUnregisterPlugPlayNotificationEx
Definition: btrfs.c:97
UNICODE_STRING log_device
Definition: btrfs.c:91
ERESOURCE pdo_list_lock
Definition: btrfs.c:103
LIST_ENTRY gid_map_list
Definition: btrfs.c:72
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2169

◆ _Function_class_() [2/5]

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 1193 of file btrfs.c.

1194  {
1195  read_context* context = conptr;
1196 
1198 
1199  context->iosb = Irp->IoStatus;
1200  KeSetEvent(&context->Event, 0, false);
1201 
1203 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
Definition: http.c:6587
_In_ PIRP Irp
Definition: csq.h:116
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define UNUSED(x)
Definition: btrfs_drv.h:86
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

◆ _Function_class_() [3/5]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 5640 of file btrfs.c.

5641  {
5642  KTIMER timer;
5644 
5645  UNUSED(context);
5646 
5647  KeInitializeTimer(&timer);
5648 
5649  delay.QuadPart = -30000000; // wait three seconds
5650  KeSetTimer(&timer, delay, NULL);
5651  KeWaitForSingleObject(&timer, Executive, KernelMode, false, NULL);
5652 
5653  TRACE("timer expired\n");
5654 
5655  degraded_wait = false;
5656 
5659 
5661 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
Definition: http.c:6587
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
HANDLE degraded_wait_handle
Definition: btrfs.c:106
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define UNUSED(x)
Definition: btrfs_drv.h:86
#define TRACE(s)
Definition: solgame.cpp:4
void delay(unsigned msec)
Definition: i386rtl.c:32
bool degraded_wait
Definition: btrfs.c:107
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Function_class_() [4/5]

_Function_class_ ( DRIVER_ADD_DEVICE  )

Definition at line 5663 of file btrfs.c.

5664  {
5665  LIST_ENTRY* le;
5666  NTSTATUS Status;
5667  UNICODE_STRING volname;
5668  ULONG i, j;
5669  pdo_device_extension* pdode = NULL;
5670  PDEVICE_OBJECT voldev;
5672 
5673  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
5674 
5676 
5677  le = pdo_list.Flink;
5678  while (le != &pdo_list) {
5680 
5681  if (pdode2->pdo == PhysicalDeviceObject) {
5682  pdode = pdode2;
5683  break;
5684  }
5685 
5686  le = le->Flink;
5687  }
5688 
5689  if (!pdode) {
5690  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
5692  goto end;
5693  }
5694 
5695  ExAcquireResourceSharedLite(&pdode->child_lock, true);
5696 
5697  volname.Length = volname.MaximumLength = (sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR)) + ((36 + 1) * sizeof(WCHAR));
5698  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
5699 
5700  if (!volname.Buffer) {
5701  ERR("out of memory\n");
5703  goto end2;
5704  }
5705 
5706  RtlCopyMemory(volname.Buffer, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR));
5707 
5708  j = (sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1;
5709  for (i = 0; i < 16; i++) {
5710  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] >> 4); j++;
5711  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] & 0xf); j++;
5712 
5713  if (i == 3 || i == 5 || i == 7 || i == 9) {
5714  volname.Buffer[j] = '-';
5715  j++;
5716  }
5717  }
5718 
5719  volname.Buffer[j] = '}';
5720 
5723  if (!NT_SUCCESS(Status)) {
5724  ERR("IoCreateDevice returned %08x\n", Status);
5725  goto end2;
5726  }
5727 
5728  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
5729  voldev->Flags |= DO_DIRECT_IO;
5730 
5731  vde = voldev->DeviceExtension;
5732  vde->type = VCB_TYPE_VOLUME;
5733  vde->name = volname;
5734  vde->device = voldev;
5735  vde->mounted_device = NULL;
5736  vde->pdo = PhysicalDeviceObject;
5737  vde->pdode = pdode;
5738  vde->removing = false;
5739  vde->open_count = 0;
5740 
5741  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
5742  if (!NT_SUCCESS(Status))
5743  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5744 
5746 
5747  pdode->vde = vde;
5748 
5749  if (pdode->removable)
5750  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
5751 
5752  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
5753 
5754  Status = IoSetDeviceInterfaceState(&vde->bus_name, true);
5755  if (!NT_SUCCESS(Status))
5756  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5757 
5759 
5760 end2:
5762 
5763 end:
5765 
5766  return Status;
5767 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1656
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
USHORT MaximumLength
Definition: env_spec_w32.h:370
PDEVICE_OBJECT device
Definition: btrfs_drv.h:842
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4175
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:844
GLuint GLuint end
Definition: gl.h:1545
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1114
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
UNICODE_STRING name
Definition: btrfs_drv.h:841
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:856
#define ALLOC_TAG
Definition: btrfs_drv.h:91
UNICODE_STRING bus_name
Definition: btrfs_drv.h:846
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:845
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:104
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BTRFS_VOLUME_PREFIX
Definition: btrfs_drv.h:127
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
ERESOURCE child_lock
Definition: btrfs_drv.h:861
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:843
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:66
Definition: typedefs.h:117
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:847
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
uint8_t uuid[16]
Definition: btrfs.h:123
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
Definition: btrfs_drv.h:148
Definition: list.h:27
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
ERESOURCE pdo_list_lock
Definition: btrfs.c:103
volume_device_extension * vde
Definition: btrfs_drv.h:855
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Function_class_() [5/5]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 5769 of file btrfs.c.

5770  {
5771  NTSTATUS Status;
5773  UNICODE_STRING device_nameW;
5774  UNICODE_STRING dosdevice_nameW;
5776  bus_device_extension* bde;
5777  HANDLE regh;
5778  OBJECT_ATTRIBUTES oa;
5779  ULONG dispos;
5780 
5783 
5784 #ifdef _DEBUG
5785  ExInitializeResourceLite(&log_lock);
5786 #endif
5788 
5791  log_file.Buffer = NULL;
5793 
5796 
5797  if (!registry_path.Buffer) {
5798  ERR("out of memory\n");
5800  }
5801 
5803 
5804  read_registry(&registry_path, false);
5805 
5806 #ifdef _DEBUG
5807  if (debug_log_level > 0)
5808  init_logging();
5809 
5810  log_started = true;
5811 #endif
5812 
5813  TRACE("DriverEntry\n");
5814 
5815 #ifndef __REACTOS__
5816  check_cpu();
5817 #endif
5818 
5821  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
5822 
5823  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
5824  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
5825 
5826  if (fPsIsDiskCountersEnabled) {
5827  diskacc = fPsIsDiskCountersEnabled();
5828 
5829  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
5831 
5832  if (!fPsUpdateDiskCounters)
5833  diskacc = false;
5834 
5835  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
5837  }
5838 
5839  RtlInitUnicodeString(&name, L"CcCopyReadEx");
5841 
5842  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
5844 
5845  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
5847  } else {
5849  fCcCopyReadEx = NULL;
5850  fCcCopyWriteEx = NULL;
5853  }
5854 
5857 
5858  RtlInitUnicodeString(&name, L"IoUnregisterPlugPlayNotificationEx");
5860  } else
5862 
5865 
5866  RtlInitUnicodeString(&name, L"FsRtlGetEcpListFromIrp");
5868 
5869  RtlInitUnicodeString(&name, L"FsRtlGetNextExtraCreateParameter");
5871 
5872  RtlInitUnicodeString(&name, L"FsRtlValidateReparsePointBuffer");
5874  } else {
5878  }
5879 
5880  drvobj = DriverObject;
5881 
5883 
5885 
5886  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
5887  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
5888  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
5889  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
5890  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
5891  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
5892  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
5893  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
5894  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
5895  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
5896  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
5897  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
5898  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
5899  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
5900  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
5901  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
5902  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
5903  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
5904  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
5905  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
5906  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
5908 
5910 
5911  device_nameW.Buffer = (WCHAR*)device_name;
5912  device_nameW.Length = device_nameW.MaximumLength = sizeof(device_name) - sizeof(WCHAR);
5913  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
5914  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
5915 
5918  if (!NT_SUCCESS(Status)) {
5919  ERR("IoCreateDevice returned %08x\n", Status);
5920  return Status;
5921  }
5922 
5925 
5927 
5928  cde->type = VCB_TYPE_CONTROL;
5929 
5931 
5932  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
5933  if (!NT_SUCCESS(Status)) {
5934  ERR("IoCreateSymbolicLink returned %08x\n", Status);
5935  return Status;
5936  }
5937 
5938  Status = init_cache();
5939  if (!NT_SUCCESS(Status)) {
5940  ERR("init_cache returned %08x\n", Status);
5941  return Status;
5942  }
5943 
5947 
5949 
5952  if (!NT_SUCCESS(Status)) {
5953  ERR("ZwCreateKey returned %08x\n", Status);
5954  return Status;
5955  }
5956 
5957  watch_registry(regh);
5958 
5960  FILE_DEVICE_SECURE_OPEN, false, &busobj);
5961  if (!NT_SUCCESS(Status)) {
5962  ERR("IoCreateDevice returned %08x\n", Status);
5963  return Status;
5964  }
5965 
5967 
5968  RtlZeroMemory(bde, sizeof(bus_device_extension));
5969 
5970  bde->type = VCB_TYPE_BUS;
5971 
5972  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
5973  NULL, NULL, 0, &bde->buspdo);
5974  if (!NT_SUCCESS(Status)) {
5975  ERR("IoReportDetectedDevice returned %08x\n", Status);
5976  return Status;
5977  }
5978 
5979  Status = IoRegisterDeviceInterface(bde->buspdo, &BtrfsBusInterface, NULL, &bde->bus_name);
5980  if (!NT_SUCCESS(Status))
5981  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5982 
5984 
5986 
5987  Status = IoSetDeviceInterfaceState(&bde->bus_name, true);
5988  if (!NT_SUCCESS(Status))
5989  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5990 
5992 
5993  Status = PsCreateSystemThread(&degraded_wait_handle, 0, NULL, NULL, NULL, degraded_wait_thread, NULL);
5994  if (!NT_SUCCESS(Status))
5995  WARN("PsCreateSystemThread returned %08x\n", Status);
5996 
5998  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
5999  if (!NT_SUCCESS(Status))
6000  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
6001 
6003  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
6004  if (!NT_SUCCESS(Status))
6005  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
6006 
6008  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
6009  if (!NT_SUCCESS(Status))
6010  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
6011 
6012  finished_probing = true;
6013 
6015 
6016  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, NULL, NULL, NULL, mountmgr_thread, NULL);
6017  if (!NT_SUCCESS(Status))
6018  WARN("PsCreateSystemThread returned %08x\n", Status);
6019 
6021 
6023 
6024  return STATUS_SUCCESS;
6025 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
NTSTATUS(* tIoUnregisterPlugPlayNotificationEx)(PVOID NotificationEntry)
Definition: btrfs_drv.h:1765
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:816
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
void init_fast_io_dispatch(FAST_IO_DISPATCH **fiod)
Definition: fastio.c:468
NTSTATUS init_cache()
Definition: cache.c:85
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
bool finished_probing
Definition: btrfs.c:105
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_FLUSH_BUFFERS
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IRP_MJ_SHUTDOWN
void * notification_entry3
Definition: btrfs.c:102
DRIVER_ADD_DEVICE AddDevice
Definition: parport.h:72
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:93
NTSTATUS compat_FsRtlValidateReparsePointBuffer(IN ULONG BufferLength, IN PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: fsrtl.c:32
HANDLE degraded_wait_handle
Definition: btrfs.c:106
LIST_ENTRY VcbList
Definition: btrfs.c:73
#define IRP_MJ_SET_SECURITY
static void check_cpu()
Definition: btrfs.c:5532
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define WARN(fmt,...)
Definition: debug.h:111
NTSTATUS(* tFsRtlValidateReparsePointBuffer)(ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: btrfs_drv.h:1772
LONG NTSTATUS
Definition: precomp.h:26
VOID(* tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1761
static const WCHAR device_name[]
Definition: btrfs.c:61
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4175
UNICODE_STRING log_file
Definition: btrfs.c:91
tFsRtlValidateReparsePointBuffer fFsRtlValidateReparsePointBuffer
Definition: btrfs.c:100
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
void watch_registry(HANDLE regh)
Definition: registry.c:1020
void * notification_entry2
Definition: btrfs.c:102
bool diskacc
Definition: btrfs.c:101
BOOLEAN(* tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1749
uint32_t debug_log_level
Definition: btrfs.c:75
UNICODE_STRING bus_name
Definition: btrfs_drv.h:818
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:661
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:92
#define ALLOC_TAG
Definition: btrfs_drv.h:91
UNICODE_STRING registry_path
Definition: btrfs.c:91
NTSTATUS NTAPI IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject, IN INTERFACE_TYPE LegacyBusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PCM_RESOURCE_LIST ResourceList, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL, IN BOOLEAN ResourceAssigned, IN OUT PDEVICE_OBJECT *DeviceObject OPTIONAL)
Definition: pnpreport.c:162
HANDLE mountmgr_thread_handle
Definition: btrfs.c:106
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3417
BOOLEAN(* tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1741
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
static const WCHAR dosdevice_name[]
Definition: btrfs.c:62
#define IRP_MJ_SET_EA
VOID(* tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1743
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS(* tFsRtlGetEcpListFromIrp)(PIRP Irp, PECP_LIST *EcpList)
Definition: btrfs_drv.h:1767
smooth NULL
Definition: ftsmooth.c:416
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:96
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS(* tFsRtlGetNextExtraCreateParameter)(PECP_LIST EcpList, PVOID CurrentEcpContext, LPGUID NextEcpType, PVOID *NextEcpContext, ULONG *NextEcpContextSize)
Definition: btrfs_drv.h:1769
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
tCcCopyWriteEx fCcCopyWriteEx
Definition: btrfs.c:94
void __stdcall check_system_root(PDRIVER_OBJECT DriverObject, PVOID Context, ULONG Count)
Definition: boot.c:204
#define IRP_MJ_QUERY_EA
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
void * notification_entry
Definition: btrfs.c:102
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:104
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define NTDDI_WIN7
Definition: sdkddkver.h:112
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
VOID NTAPI IoRegisterBootDriverReinitialization(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
Definition: driver.c:1706
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:66
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:95
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
LIST_ENTRY uid_map_list
Definition: btrfs.c:72
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
PDEVICE_OBJECT busobj
Definition: btrfs.c:67
#define IRP_MJ_SYSTEM_CONTROL
tFsRtlGetNextExtraCreateParameter fFsRtlGetNextExtraCreateParameter
Definition: btrfs.c:99
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:658
Status
Definition: gdiplustypes.h:24
ERESOURCE mapping_lock
Definition: btrfs.c:103
ERESOURCE global_loading_lock
Definition: btrfs.c:74
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:817
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5108
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NTDDI_VISTA
Definition: sdkddkver.h:103
tIoUnregisterPlugPlayNotificationEx fIoUnregisterPlugPlayNotificationEx
Definition: btrfs.c:97
KEVENT mountmgr_thread_event
Definition: btrfs.c:108
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_NOTIFY
Definition: nt_native.h:1020
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static DRIVER_UNLOAD DriverUnload
Definition: kbdclass.c:17
UNICODE_STRING log_device
Definition: btrfs.c:91
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
VOID(* tFsRtlUpdateDiskCounters)(ULONG64 BytesRead, ULONG64 BytesWritten)
Definition: btrfs_drv.h:1763
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
ERESOURCE pdo_list_lock
Definition: btrfs.c:103
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:992
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2177
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG const UNICODE_STRING ULONG PULONG dispos
Definition: reg.c:130
#define IRP_MJ_CLEANUP
Definition: name.c:36
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
bool log_started
Definition: btrfs.c:90
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
LIST_ENTRY gid_map_list
Definition: btrfs.c:72
BOOLEAN(* tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1746
#define NTDDI_WIN8
Definition: sdkddkver.h:113
tFsRtlGetEcpListFromIrp fFsRtlGetEcpListFromIrp
Definition: btrfs.c:98
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
void read_registry(PUNICODE_STRING regpath, bool refresh)
Definition: registry.c:763
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
GLuint const GLchar * name
Definition: glext.h:6031

◆ _Requires_exclusive_lock_held_()

_Requires_exclusive_lock_held_ ( Vcb->  tree_lock)

◆ _Success_() [1/2]

_Success_ ( return  = = 0)

Definition at line 403 of file btrfs.c.

404  {
405  DIR_ITEM* xa = (DIR_ITEM*)item;
406  USHORT xasize;
407 
408  while (true) {
409  if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m + xa->n)) {
410  WARN("DIR_ITEM is truncated\n");
411  return false;
412  }
413 
414  if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name, xa->n) == xa->n) {
415  TRACE("found xattr %s\n", name);
416 
417  *datalen = xa->m;
418 
419  if (xa->m > 0) {
421  if (!*data) {
422  ERR("out of memory\n");
423  return false;
424  }
425 
426  RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
427  } else
428  *data = NULL;
429 
430  return true;
431  }
432 
433  xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
434 
435  if (size > xasize) {
436  size -= xasize;
437  xa = (DIR_ITEM*)&xa->name[xa->m + xa->n];
438  } else
439  break;
440  }
441 
442  TRACE("xattr %s not found\n", name);
443 
444  return false;
445 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define WARN(fmt,...)
Definition: debug.h:111
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1027
if(!r)
Definition: btrfs.c:2885
#define ALLOC_TAG
Definition: btrfs_drv.h:91
uint16_t m
Definition: btrfs.h:257
char name[1]
Definition: btrfs.h:260
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
static ATOM item
Definition: dde.c:856
unsigned short USHORT
Definition: pedump.c:61
Definition: name.c:36
uint16_t n
Definition: btrfs.h:258
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

◆ _Success_() [2/2]

_Success_ ( return >=  0)

◆ add_device_to_list()

static void add_device_to_list ( _In_ device_extension Vcb,
_In_ device dev 
)
static

Definition at line 3164 of file btrfs.c.

3164  {
3165  LIST_ENTRY* le;
3166 
3167  le = Vcb->devices.Flink;
3168 
3169  while (le != &Vcb->devices) {
3170  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3171 
3172  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
3173  InsertHeadList(le->Blink, &dev->list_entry);
3174  return;
3175  }
3176 
3177  le = le->Flink;
3178  }
3179 
3180  InsertTailList(&Vcb->devices, &dev->list_entry);
3181 }
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define InsertTailList(ListHead, Entry)
Definition: devices.h:37
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
InsertTailList & Vcb
Definition: btrfs.c:2930
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
uint64_t dev_id
Definition: btrfs.h:161
Definition: typedefs.h:117
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:514
uint64_t dev_id

Referenced by find_device_from_uuid(), and load_chunk_root().

◆ calculate_total_space()

static void calculate_total_space ( _In_ device_extension Vcb,
_Out_ uint64_t totalsize,
_Out_ uint64_t freespace 
)
static

Definition at line 594 of file btrfs.c.

594  {
595  uint64_t nfactor, dfactor, sectors_used;
596 
597  if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags & BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
598  nfactor = 1;
599  dfactor = 2;
600  } else if (Vcb->data_flags & BLOCK_FLAG_RAID5) {
601  nfactor = Vcb->superblock.num_devices - 1;
602  dfactor = Vcb->superblock.num_devices;
603  } else if (Vcb->data_flags & BLOCK_FLAG_RAID6) {
604  nfactor = Vcb->superblock.num_devices - 2;
605  dfactor = Vcb->superblock.num_devices;
606  } else {
607  nfactor = 1;
608  dfactor = 1;
609  }
610 
611  sectors_used = Vcb->superblock.bytes_used / Vcb->superblock.sector_size;
612 
613  *totalsize = (Vcb->superblock.total_bytes / Vcb->superblock.sector_size) * nfactor / dfactor;
614  *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
615 }
#define freespace(fs, percentreserved)
Definition: fs.h:640
#define BLOCK_FLAG_RAID10
Definition: shellext.h:76
InsertTailList & Vcb
Definition: btrfs.c:2930
#define BLOCK_FLAG_RAID6
Definition: shellext.h:78
UINT64 uint64_t
Definition: types.h:77
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint GLenum GLenum dfactor
Definition: glfuncs.h:252
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:75
#define BLOCK_FLAG_RAID5
Definition: shellext.h:77
#define BLOCK_FLAG_RAID1
Definition: shellext.h:74

Referenced by _Dispatch_type_().

◆ check_cpu()

static void check_cpu ( )
static

Definition at line 5532 of file btrfs.c.

5532  {
5533  unsigned int cpuInfo[4];
5534 #ifndef _MSC_VER
5535  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
5536  have_sse42 = cpuInfo[2] & bit_SSE4_2;
5537  have_sse2 = cpuInfo[3] & bit_SSE2;
5538 #else
5539  __cpuid(cpuInfo, 1);
5540  have_sse42 = cpuInfo[2] & (1 << 20);
5541  have_sse2 = cpuInfo[3] & (1 << 26);
5542 #endif
5543 
5544  if (have_sse42)
5545  TRACE("SSE4.2 is supported\n");
5546  else
5547  TRACE("SSE4.2 not supported\n");
5548 
5549  if (have_sse2)
5550  TRACE("SSE2 is supported\n");
5551  else
5552  TRACE("SSE2 is not supported\n");
5553 }
bool have_sse2
Definition: btrfs.c:69
#define TRACE(s)
Definition: solgame.cpp:4
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
bool have_sse42
Definition: btrfs.c:69

Referenced by _Function_class_().

◆ chunk_estimate_phys_size()

uint64_t chunk_estimate_phys_size ( device_extension Vcb,
chunk c,
uint64_t  u 
)

Definition at line 3761 of file btrfs.c.

3761  {
3762  uint64_t nfactor, dfactor;
3763 
3764  if (c->chunk_item->type & BLOCK_FLAG_DUPLICATE || c->chunk_item->type & BLOCK_FLAG_RAID1 || c->chunk_item->type & BLOCK_FLAG_RAID10) {
3765  nfactor = 1;
3766  dfactor = 2;
3767  } else if (c->chunk_item->type & BLOCK_FLAG_RAID5) {
3768  nfactor = Vcb->superblock.num_devices - 1;
3769  dfactor = Vcb->superblock.num_devices;
3770  } else if (c->chunk_item->type & BLOCK_FLAG_RAID6) {
3771  nfactor = Vcb->superblock.num_devices - 2;
3772  dfactor = Vcb->superblock.num_devices;
3773  } else {
3774  nfactor = 1;
3775  dfactor = 1;
3776  }
3777 
3778  return u * dfactor / nfactor;
3779 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define BLOCK_FLAG_RAID10
Definition: shellext.h:76
InsertTailList & Vcb
Definition: btrfs.c:2930
const GLubyte * c
Definition: glext.h:8905
#define BLOCK_FLAG_RAID6
Definition: shellext.h:78
UINT64 uint64_t
Definition: types.h:77
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint GLenum GLenum dfactor
Definition: glfuncs.h:252
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:75
#define BLOCK_FLAG_RAID5
Definition: shellext.h:77
#define BLOCK_FLAG_RAID1
Definition: shellext.h:74

Referenced by create_chunk(), drop_chunk(), find_chunk_usage(), and update_chunk_usage().

◆ chunk_lock_range()

void chunk_lock_range ( _In_ device_extension Vcb,
_In_ chunk c,
_In_ uint64_t  start,
_In_ uint64_t  length 
)

Definition at line 5405 of file btrfs.c.

5405  {
5406  LIST_ENTRY* le;
5407  bool locked;
5408  range_lock* rl;
5409 
5410  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5411  if (!rl) {
5412  ERR("out of memory\n");
5413  return;
5414  }
5415 
5416  rl->start = start;
5417  rl->length = length;
5418  rl->thread = PsGetCurrentThread();
5419 
5420  while (true) {
5421  locked = false;
5422 
5423  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5424 
5425  le = c->range_locks.Flink;
5426  while (le != &c->range_locks) {
5428 
5429  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5430  locked = true;
5431  break;
5432  }
5433 
5434  le = le->Flink;
5435  }
5436 
5437  if (!locked) {
5438  InsertTailList(&c->range_locks, &rl->list_entry);
5439 
5440  ExReleaseResourceLite(&c->range_locks_lock);
5441  return;
5442  }
5443 
5444  KeClearEvent(&c->range_locks_event);
5445 
5446  ExReleaseResourceLite(&c->range_locks_lock);
5447 
5448  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, false, NULL);
5449  }
5450 }
uint64_t start
Definition: btrfs_drv.h:533
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
uint64_t length
Definition: btrfs_drv.h:534
#define InsertTailList(ListHead, Entry)
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY list_entry
Definition: btrfs_drv.h:536
InsertTailList & Vcb
Definition: btrfs.c:2930
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:535
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
GLuint start
Definition: gl.h:1545
Definition: list.h:27
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

Referenced by read_data(), scrub_chunk_raid56_stripe_run(), and write_data_complete().

◆ chunk_unlock_range()

void chunk_unlock_range ( _In_ device_extension Vcb,
_In_ chunk c,
_In_ uint64_t  start,
_In_ uint64_t  length 
)

Definition at line 5452 of file btrfs.c.

5452  {
5453  LIST_ENTRY* le;
5454 
5455  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5456 
5457  le = c->range_locks.Flink;
5458  while (le != &c->range_locks) {
5460 
5461  if (rl->start == start && rl->length == length) {
5463  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5464  break;
5465  }
5466 
5467  le = le->Flink;
5468  }
5469 
5470  KeSetEvent(&c->range_locks_event, 0, false);
5471 
5472  ExReleaseResourceLite(&c->range_locks_lock);
5473 }
uint64_t start
Definition: btrfs_drv.h:533
uint64_t length
Definition: btrfs_drv.h:534
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY list_entry
Definition: btrfs_drv.h:536
InsertTailList & Vcb
Definition: btrfs.c:2930
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Definition: typedefs.h:117
GLuint start
Definition: gl.h:1545
Definition: list.h:27

Referenced by read_data(), scrub_chunk_raid56_stripe_run(), and write_data_complete().

◆ close_file()

static NTSTATUS close_file ( _In_ PFILE_OBJECT  FileObject,
_In_ PIRP  Irp 
)
static

Definition at line 1894 of file btrfs.c.

1894  {
1895  fcb* fcb;
1896  ccb* ccb;
1897  file_ref* fileref = NULL;
1898  LONG open_files;
1899 
1900  UNUSED(Irp);
1901 
1902  TRACE("FileObject = %p\n", FileObject);
1903 
1904  fcb = FileObject->FsContext;
1905  if (!fcb) {
1906  TRACE("FCB was NULL, returning success\n");
1907  return STATUS_SUCCESS;
1908  }
1909 
1910  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1911 
1912  ccb = FileObject->FsContext2;
1913 
1914  TRACE("close called for %S (fcb == %p)\n", file_desc(FileObject), fcb);
1915 
1916  // FIXME - make sure notification gets sent if file is being deleted
1917 
1918  if (ccb) {
1919  if (ccb->query_string.Buffer)
1921 
1922  if (ccb->filename.Buffer)
1924 
1925  // FIXME - use refcounts for fileref
1926  fileref = ccb->fileref;
1927 
1928  if (fcb->Vcb->running_sends > 0) {
1929  bool send_cancelled = false;
1930 
1931  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
1932 
1933  if (ccb->send) {
1934  ccb->send->cancelling = true;
1935  send_cancelled = true;
1936  KeSetEvent(&ccb->send->cleared_event, 0, false);
1937  }
1938 
1939  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1940 
1941  if (send_cancelled) {
1942  while (ccb->send) {
1943  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
1944  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1945  }
1946  }
1947  }
1948 
1949  ExFreePool(ccb);
1950  }
1951 
1953 
1954  if (open_files == 0 && fcb->Vcb->removing) {
1955  uninit(fcb->Vcb);
1956  return STATUS_SUCCESS;
1957  }
1958 
1959  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1960  return STATUS_SUCCESS;
1961 
1962  if (fileref)
1963  free_fileref(fileref);
1964  else
1965  free_fcb(fcb);
1966 
1967  return STATUS_SUCCESS;
1968 }
void free_fcb(_Inout_ fcb *fcb)
Definition: btrfs.c:1703
_In_ PIRP Irp
Definition: csq.h:116
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1970
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UNICODE_STRING filename
Definition: btrfs_drv.h:379
UNICODE_STRING query_string
Definition: btrfs_drv.h:371
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define UNUSED(x)
Definition: btrfs_drv.h:86
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TRACE(s)
Definition: solgame.cpp:4
struct _fcb fcb
Definition: btrfs_drv.h:1301
KEVENT cleared_event
Definition: btrfs_drv.h:360
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define InterlockedDecrement
Definition: armddk.h:52
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
void free_fileref(_Inout_ file_ref *fr)
Definition: btrfs.c:1820
bool cancelling
Definition: btrfs_drv.h:361
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:378
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define VPB_MOUNTED
Definition: iotypes.h:1764
struct _device_extension * Vcb
Definition: btrfs_drv.h:276
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1529
send_info * send
Definition: btrfs_drv.h:387

Referenced by _Dispatch_type_().

◆ create_calc_threads()

static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 3999 of file btrfs.c.

3999  {
4001  ULONG i;
4002 
4003  Vcb->calcthreads.num_threads = get_num_of_processors();
4004 
4005  Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
4006  if (!Vcb->calcthreads.threads) {
4007  ERR("out of memory\n");
4009  }
4010 
4011  InitializeListHead(&Vcb->calcthreads.job_list);
4012  ExInitializeResourceLite(&Vcb->calcthreads.lock);
4013  KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, false);
4014 
4015  RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads);
4016 
4017  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
4018  NTSTATUS Status;
4019 
4020  Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
4021  KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, false);
4022 
4023  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, NULL, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
4024  if (!NT_SUCCESS(Status)) {
4025  ULONG j;
4026 
4027  ERR("PsCreateSystemThread returned %08x\n", Status);
4028 
4029  for (j = 0; j < i; j++) {
4030  Vcb->calcthreads.threads[i].quit = true;
4031  }
4032 
4033  KeSetEvent(&Vcb->calcthreads.event, 0, false);
4034 
4035  return Status;
4036  }
4037  }
4038 
4039  return STATUS_SUCCESS;
4040 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4175
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ALLOC_TAG
Definition: btrfs_drv.h:91
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PVOID DeviceExtension
Definition: env_spec_w32.h:418
uint32_t get_num_of_processors()
Definition: btrfs.c:3985
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
InsertTailList & Vcb
Definition: btrfs.c:2930
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by mount_vol().

◆ create_root()

NTSTATUS create_root ( _In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension Vcb,
_In_ uint64_t  id,
_Out_ root **  rootptr,
_In_ bool  no_tree,
_In_ uint64_t  offset,
_In_opt_ PIRP  Irp 
)

Definition at line 1205 of file btrfs.c.

1206  {
1207  NTSTATUS Status;
1208  root* r;
1209  tree* t = NULL;
1210  ROOT_ITEM* ri;
1211  traverse_ptr tp;
1212 
1214  if (!r) {
1215  ERR("out of memory\n");
1217  }
1218 
1220  if (!r->nonpaged) {
1221  ERR("out of memory\n");
1222  ExFreePool(r);
1224  }
1225 
1226  if (!no_tree) {
1228  if (!t) {
1229  ERR("out of memory\n");
1230  ExFreePool(r->nonpaged);
1231  ExFreePool(r);
1233  }
1234 
1235  t->nonpaged = NULL;
1236 
1237  t->is_unique = true;
1238  t->uniqueness_determined = true;
1239  t->buf = NULL;
1240  }
1241 
1243  if (!ri) {
1244  ERR("out of memory\n");
1245 
1246  if (t)
1247  ExFreePool(t);
1248 
1249  ExFreePool(r->nonpaged);
1250  ExFreePool(r);
1252  }
1253 
1254  r->id = id;
1255  r->treeholder.address = 0;
1256  r->treeholder.generation = Vcb->superblock.generation;
1257  r->treeholder.tree = t;
1258  r->lastinode = 0;
1259  r->dirty = false;
1260  r->received = false;
1261  r->reserved = NULL;
1262  r->parent = 0;
1263  r->send_ops = 0;
1264  RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
1265  r->root_item.num_references = 1;
1266  r->fcbs_version = 0;
1267  r->checked_for_orphans = true;
1268  InitializeListHead(&r->fcbs);
1269  RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY*) * 256);
1270 
1271  RtlCopyMemory(ri, &r->root_item, sizeof(ROOT_ITEM));
1272 
1273  // We ask here for a traverse_ptr to the item we're inserting, so we can
1274  // copy some of the tree's variables
1275 
1276  Status = insert_tree_item(Vcb, Vcb->root_root, id, TYPE_ROOT_ITEM, offset, ri, sizeof(ROOT_ITEM), &tp, Irp);
1277  if (!NT_SUCCESS(Status)) {
1278  ERR("insert_tree_item returned %08x\n", Status);
1279  ExFreePool(ri);
1280 
1281  if (t)
1282  ExFreePool(t);
1283 
1284  ExFreePool(r->nonpaged);
1285  ExFreePool(r);
1286  return Status;
1287  }
1288 
1289  ExInitializeResourceLite(&r->nonpaged->load_tree_lock);
1290 
1291  InsertTailList(&Vcb->roots, &r->list_entry);
1292 
1293  if (!no_tree) {
1294  RtlZeroMemory(&t->header, sizeof(tree_header));
1295  t->header.fs_uuid = tp.tree->header.fs_uuid;
1296  t->header.address = 0;
1297  t->header.flags = HEADER_FLAG_MIXED_BACKREF | 1; // 1 == "written"? Why does the Linux driver record this?
1298  t->header.chunk_tree_uuid = tp.tree->header.chunk_tree_uuid;
1299  t->header.generation = Vcb->superblock.generation;
1300  t->header.tree_id = id;
1301  t->header.num_items = 0;
1302  t->header.level = 0;
1303 
1304  t->has_address = false;
1305  t->size = 0;
1306  t->Vcb = Vcb;
1307  t->parent = NULL;
1308  t->paritem = NULL;
1309  t->root = r;
1310 
1311  InitializeListHead(&t->itemlist);
1312 
1313  t->new_address = 0;
1314  t->has_new_address = false;
1315  t->updated_extents = false;
1316 
1317  InsertTailList(&Vcb->trees, &t->list_entry);
1318  t->list_entry_hash.Flink = NULL;
1319 
1320  t->write = true;
1321  Vcb->need_write = true;
1322  }
1323 
1324  *rootptr = r;
1325 
1326  return STATUS_SUCCESS;
1327 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
InitializeListHead & r
Definition: btrfs.c:2901
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
GLdouble GLdouble t
Definition: gl.h:2047
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4175
#define InsertTailList(ListHead, Entry)
#define HEADER_FLAG_MIXED_BACKREF
Definition: btrfs.h:134
#define ALLOC_TAG
Definition: btrfs_drv.h:91
tree * tree
Definition: btrfs_drv.h:495
smooth NULL
Definition: ftsmooth.c:416
_In_ uint64_t id
Definition: btrfs.c:2882
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2883
InsertTailList & Vcb
Definition: btrfs.c:2930
BTRFS_UUID chunk_tree_uuid
Definition: btrfs.h:141
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS insert_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ uint64_t obj_id, _In_ uint8_t obj_type, _In_ uint64_t offset, _In_reads_bytes_opt_(size) _When_(return >=0, __drv_aliasesMem) void *data, _In_ uint16_t size, _Out_opt_ traverse_ptr *ptp, _In_opt_ PIRP Irp)
Definition: treefuncs.c:857
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
tree_header header
Definition: btrfs_drv.h:421
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
BTRFS_UUID fs_uuid
Definition: btrfs.h:138
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define TYPE_ROOT_ITEM
Definition: btrfs.h:28
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by create_subvol(), do_create_snapshot(), flush_subvol(), and look_for_roots().

◆ DEFINE_GUID()

DEFINE_GUID ( BtrfsBusInterface  ,
0x4d414874  ,
0x6865  ,
0x6761  ,
0x6d  ,
0x65  ,
0x83  ,
0x69  ,
0x17  ,
0x9a  ,
0x7d  ,
0x1d   
)

◆ delete_fileref()

NTSTATUS delete_fileref ( _In_ file_ref fileref,
_In_opt_ PFILE_OBJECT  FileObject,
_In_ bool  make_orphan,
_In_opt_ PIRP  Irp,
_In_ LIST_ENTRY rollback 
)

Definition at line 2217 of file btrfs.c.

2217  {
2218  LARGE_INTEGER newlength, time;
2219  BTRFS_TIME now;
2220  NTSTATUS Status;
2221  ULONG utf8len = 0;
2222 
2225 
2226  ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, true);
2227 
2228  if (fileref->deleted) {
2229  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2230  return STATUS_SUCCESS;
2231  }
2232 
2233  if (fileref->fcb->subvol->send_ops > 0) {
2234  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2235  return STATUS_ACCESS_DENIED;
2236  }
2237 
2238  fileref->deleted = true;
2239  mark_fileref_dirty(fileref);
2240 
2241  // delete INODE_ITEM (0x1)
2242 
2243  TRACE("nlink = %u\n", fileref->fcb->inode_item.st_nlink);
2244 
2245  if (!fileref->fcb->ads) {
2246  if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
2247  LIST_ENTRY* le;
2248 
2249  mark_fcb_dirty(fileref->fcb);
2250 
2251  fileref->fcb->inode_item_changed = true;
2252 
2253  if (fileref->fcb->inode_item.st_nlink > 1 || make_orphan) {
2254  fileref->fcb->inode_item.st_nlink--;
2255  fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2256  fileref->fcb->inode_item.sequence++;
2257  fileref->fcb->inode_item.st_ctime = now;
2258  } else {
2260  if (!NT_SUCCESS(Status)) {
2261  ERR("delete_fileref_fcb returned %08x\n", Status);
2262  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2263  return Status;
2264  }
2265  }
2266 
2267  if (fileref->dc) {
2268  le = fileref->fcb->hardlinks.Flink;
2269  while (le != &fileref->fcb->hardlinks) {
2271 
2272  if (hl->parent == fileref->parent->fcb->inode && hl->index == fileref->dc->index) {
2274 
2275  if (hl->name.Buffer)
2276  ExFreePool(hl->name.Buffer);
2277 
2278  if (hl->