ReactOS  0.4.15-dev-4872-g8a3db97
btrfs.c File Reference
#include "btrfs_drv.h"
#include "xxhash.h"
#include "crc32c.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 <ntstrsafe.h>
Include dependency graph for btrfs.c:

Go to the source code of this file.

Classes

struct  read_context
 
struct  notification_fcb
 

Macros

#define INCOMPAT_SUPPORTED
 
#define COMPAT_RO_SUPPORTED
 
#define INIT_UNICODE_STRING(var, val)   UNICODE_STRING us##var; us##var.Buffer = (WCHAR*)val; us##var.Length = us##var.MaximumLength = sizeof(val) - sizeof(WCHAR);
 

Functions

 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)
 
static void __stdcall do_xor_basic (uint8_t *buf1, uint8_t *buf2, uint32_t len)
 
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)
 
void send_notification_fileref (_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
 
static void send_notification_fcb (_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
 
 _Function_class_ (IO_WORKITEM_ROUTINE)
 
void queue_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)
 
bool check_superblock_checksum (superblock *sb)
 
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)
 
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)
 
_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 (!check_superblock_checksum(sb))
 
static bool still_has_superblock (_In_ PDEVICE_OBJECT device, _In_ PFILE_OBJECT fileobj)
 
static void calculate_sector_shift (device_extension *Vcb)
 
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)
 
void do_shutdown (PIRP Irp)
 
 _Dispatch_type_ (IRP_MJ_SHUTDOWN)
 
static bool device_still_valid (device *dev, uint64_t expected_generation)
 
 _Dispatch_type_ (IRP_MJ_POWER)
 
 _Dispatch_type_ (IRP_MJ_SYSTEM_CONTROL)
 
NTSTATUS check_file_name_valid (_In_ PUNICODE_STRING us, _In_ bool posix, _In_ bool stream)
 
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)
 
 _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
 
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 mount_no_root_dir = 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
 
tFsRtlCheckLockForOplockRequest fFsRtlCheckLockForOplockRequest
 
tFsRtlAreThereCurrentOrInProgressFileLocks fFsRtlAreThereCurrentOrInProgressFileLocks
 
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
 
ERESOURCE boot_lock
 
bool is_windows_8
 
uint64_t boot_subvol
 
xor_func do_xor = do_xor_basic
 
_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
 
r dropped = 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)
 
 Status = sync_read_phys(DeviceObject, NULL, superblock_addrs[0], to_read, (PUCHAR)sb, true)
 
end __pad0__
 

Macro Definition Documentation

◆ COMPAT_RO_SUPPORTED

#define COMPAT_RO_SUPPORTED
Value:
BTRFS_COMPAT_RO_FLAGS_VERITY)
#define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID
Definition: btrfs.h:112
#define BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE
Definition: btrfs.h:111

Definition at line 57 of file btrfs.c.

◆ 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 | BTRFS_INCOMPAT_FLAGS_METADATA_UUID | BTRFS_INCOMPAT_FLAGS_RAID1C34)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:123
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:117
#define BTRFS_INCOMPAT_FLAGS_METADATA_UUID
Definition: btrfs.h:125
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:115
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:120
#define BTRFS_INCOMPAT_FLAGS_NO_HOLES
Definition: btrfs.h:124
#define BTRFS_INCOMPAT_FLAGS_RAID56
Definition: btrfs.h:122
#define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL
Definition: btrfs.h:116
#define BTRFS_INCOMPAT_FLAGS_RAID1C34
Definition: btrfs.h:126

Definition at line 53 of file btrfs.c.

◆ INIT_UNICODE_STRING

#define INIT_UNICODE_STRING (   var,
  val 
)    UNICODE_STRING us##var; us##var.Buffer = (WCHAR*)val; us##var.Length = us##var.MaximumLength = sizeof(val) - sizeof(WCHAR);

Definition at line 648 of file btrfs.c.

Function Documentation

◆ _Dispatch_type_() [1/10]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 502 of file btrfs.c.

504  {
507  device_extension* Vcb = DeviceObject->DeviceExtension;
508  bool top_level;
509 
511 
512  TRACE("close\n");
513 
514  top_level = is_top_level(Irp);
515 
516  if (DeviceObject == master_devobj) {
517  TRACE("Closing file system\n");
519  goto end;
520  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
522  goto end;
523  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
525  goto end;
526  }
527 
529 
530  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
531 
533 
534 end:
535  Irp->IoStatus.Status = Status;
536  Irp->IoStatus.Information = 0;
537 
539 
540  if (top_level)
542 
543  TRACE("returning %08lx\n", Status);
544 
546 
547  return Status;
548 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_DISK_INCREMENT
Definition: iotypes.h:600
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:66
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
GLuint GLuint end
Definition: gl.h:1545
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
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:95
return STATUS_SUCCESS
Definition: btrfs.c:3049

◆ _Dispatch_type_() [2/10]

_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 550 of file btrfs.c.

552  {
556  fcb* fcb = FileObject->FsContext;
557  device_extension* Vcb = DeviceObject->DeviceExtension;
558  bool top_level;
559 
561 
562  TRACE("flush buffers\n");
563 
564  top_level = is_top_level(Irp);
565 
566  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
568  goto end;
569  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
571  goto end;
572  }
573 
574  if (!fcb) {
575  ERR("fcb was NULL\n");
577  goto end;
578  }
579 
580  if (fcb == Vcb->volume_fcb) {
582  goto end;
583  }
584 
586 
587  Irp->IoStatus.Information = 0;
588 
589  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
590 
592  Irp->IoStatus.Status = Status;
593 
594  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
595  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &Irp->IoStatus);
596 
597  if (fcb->Header.PagingIoResource) {
598  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
599  ExReleaseResourceLite(fcb->Header.PagingIoResource);
600  }
601 
602  Status = Irp->IoStatus.Status;
603  }
604 
605 end:
607 
608  TRACE("returning %08lx\n", Status);
609 
610  if (top_level)
612 
614 
615  return Status;
616 }
#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
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:291
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
InsertTailList & Vcb
Definition: btrfs.c:3013
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:283
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1998
GLuint GLuint end
Definition: gl.h:1545
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static __inline FAST_IO_POSSIBLE fast_io_possible(fcb *fcb)
Definition: btrfs_drv.h:1677
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1670
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1170
return STATUS_SUCCESS
Definition: btrfs.c:3049

◆ _Dispatch_type_() [3/10]

_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 966 of file btrfs.c.

968  {
971  ULONG BytesCopied = 0;
972  device_extension* Vcb = DeviceObject->DeviceExtension;
973  bool top_level;
974 
976 
977  TRACE("query volume information\n");
978  top_level = is_top_level(Irp);
979 
980  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
982  goto end;
983  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
985  goto end;
986  }
987 
989 
991 
992  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
994  {
995  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
996  bool overflow = false;
997 #ifndef __REACTOS__
998  static const WCHAR ntfs[] = L"NTFS";
999 #endif
1000  static const WCHAR btrfs[] = L"Btrfs";
1001  const WCHAR* fs_name;
1002  ULONG fs_name_len, orig_fs_name_len;
1003 
1004 #ifndef __REACTOS__
1005  if (Irp->RequestorMode == UserMode && lie_about_fs_type()) {
1006  fs_name = ntfs;
1007  orig_fs_name_len = fs_name_len = sizeof(ntfs) - sizeof(WCHAR);
1008  } else {
1009  fs_name = btrfs;
1010  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
1011  }
1012 #else
1013  fs_name = btrfs;
1014  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
1015 #endif
1016 
1017  TRACE("FileFsAttributeInformation\n");
1018 
1019  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
1020  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
1021  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
1022  else
1023  fs_name_len = 0;
1024 
1025  overflow = true;
1026  }
1027 
1028  data->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_CASE_SENSITIVE_SEARCH |
1033  if (Vcb->readonly)
1034  data->FileSystemAttributes |= FILE_READ_ONLY_VOLUME;
1035 
1036  // should also be FILE_FILE_COMPRESSION when supported
1037  data->MaximumComponentNameLength = 255; // FIXME - check
1038  data->FileSystemNameLength = orig_fs_name_len;
1039  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
1040 
1041  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
1043  break;
1044  }
1045 
1047  {
1048  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
1049 
1050  TRACE("FileFsDeviceInformation\n");
1051 
1052  ffdi->DeviceType = FILE_DEVICE_DISK;
1053 
1054  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1055  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
1056  ExReleaseResourceLite(&Vcb->tree_lock);
1057 
1058  if (Vcb->readonly)
1060  else
1062 
1065 
1066  break;
1067  }
1068 
1070  {
1071  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1072 
1073  TRACE("FileFsFullSizeInformation\n");
1074 
1077  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1078  ffsi->BytesPerSector = 512;
1079 
1082 
1083  break;
1084  }
1085 
1087  {
1088  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
1089 
1090  TRACE("FileFsObjectIdInformation\n");
1091 
1092  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
1093  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
1094 
1097 
1098  break;
1099  }
1100 
1101  case FileFsSizeInformation:
1102  {
1103  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1104 
1105  TRACE("FileFsSizeInformation\n");
1106 
1108  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1109  ffsi->BytesPerSector = 512;
1110 
1113 
1114  break;
1115  }
1116 
1118  {
1119  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1121  bool overflow = false;
1122  ULONG label_len, orig_label_len;
1123 
1124  TRACE("FileFsVolumeInformation\n");
1125  TRACE("max length = %lu\n", IrpSp->Parameters.QueryVolume.Length);
1126 
1127  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1128 
1129  Status = utf8_to_utf16(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1130  if (!NT_SUCCESS(Status)) {
1131  ERR("utf8_to_utf16 returned %08lx\n", Status);
1132  ExReleaseResourceLite(&Vcb->tree_lock);
1133  break;
1134  }
1135 
1136  orig_label_len = label_len;
1137 
1138  if (IrpSp->Parameters.QueryVolume.Length < offsetof(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + label_len) {
1139  if (IrpSp->Parameters.QueryVolume.Length > offsetof(FILE_FS_VOLUME_INFORMATION, VolumeLabel))
1140  label_len = IrpSp->Parameters.QueryVolume.Length - offsetof(FILE_FS_VOLUME_INFORMATION, VolumeLabel);
1141  else
1142  label_len = 0;
1143 
1144  overflow = true;
1145  }
1146 
1147  TRACE("label_len = %lu\n", label_len);
1148 
1149  RtlZeroMemory(&ffvi, offsetof(FILE_FS_VOLUME_INFORMATION, VolumeLabel));
1150 
1151  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];
1152  ffvi.VolumeLabelLength = orig_label_len;
1153 
1154  RtlCopyMemory(data, &ffvi, min(offsetof(FILE_FS_VOLUME_INFORMATION, VolumeLabel), IrpSp->Parameters.QueryVolume.Length));
1155 
1156  if (label_len > 0) {
1157  ULONG bytecount;
1158 
1159  Status = utf8_to_utf16(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1161  ERR("utf8_to_utf16 returned %08lx\n", Status);
1162  ExReleaseResourceLite(&Vcb->tree_lock);
1163  break;
1164  }
1165 
1166  TRACE("label = %.*S\n", (int)(label_len / sizeof(WCHAR)), data->VolumeLabel);
1167  }
1168 
1169  ExReleaseResourceLite(&Vcb->tree_lock);
1170 
1171  BytesCopied = offsetof(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + label_len;
1173  break;
1174  }
1175 
1176 #ifndef __REACTOS__
1177 #ifdef _MSC_VER // not in mingw yet
1178  case FileFsSectorSizeInformation:
1179  {
1180  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1181 
1182  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
1183  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1184  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
1185  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1186  data->ByteOffsetForSectorAlignment = 0;
1187  data->ByteOffsetForPartitionAlignment = 0;
1188 
1189  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
1190 
1191  if (Vcb->trim && !Vcb->options.no_trim)
1192  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
1193 
1194  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
1196 
1197  break;
1198  }
1199 #endif
1200 #endif /* __REACTOS__ */
1201 
1202  default:
1204  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
1205  break;
1206  }
1207 
1209  Irp->IoStatus.Information = 0;
1210  else
1211  Irp->IoStatus.Information = BytesCopied;
1212 
1213 end:
1214  Irp->IoStatus.Status = Status;
1215 
1217 
1218  if (top_level)
1220 
1221  TRACE("query volume information returning %08lx\n", Status);
1222 
1224 
1225  return Status;
1226 }
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
struct _FILE_FS_FULL_SIZE_INFORMATION FILE_FS_FULL_SIZE_INFORMATION
struct _FILE_FS_OBJECTID_INFORMATION FILE_FS_OBJECTID_INFORMATION
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#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:112
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
#define FILE_SUPPORTS_POSIX_UNLINK_RENAME
Definition: btrfs_drv.h:152
#define L(x)
Definition: ntvdm.h:50
#define IO_DISK_INCREMENT
Definition: iotypes.h:600
_In_ PIRP Irp
Definition: csq.h:116
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
#define offsetof(TYPE, MEMBER)
static bool lie_about_fs_type()
Definition: btrfs.c:656
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define FILE_UNICODE_ON_DISK
Definition: from_kernel.h:235
#define TRACE(s)
Definition: solgame.cpp:4
#define FILE_SUPPORTS_BLOCK_REFCOUNTING
Definition: btrfs_drv.h:148
#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:681
#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:780
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
GLuint GLuint end
Definition: gl.h:1545
#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:618
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
UINT64 uint64_t
Definition: types.h:77
#define FILE_SUPPORTS_SPARSE_FILES
Definition: from_kernel.h:239
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES
Definition: from_kernel.h:250
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#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:3128
return STATUS_SUCCESS
Definition: btrfs.c:3049
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:114

◆ _Dispatch_type_() [4/10]

_Dispatch_type_ ( IRP_MJ_SET_VOLUME_INFORMATION  )

Definition at line 1416 of file btrfs.c.

1418  {
1420  device_extension* Vcb = DeviceObject->DeviceExtension;
1421  NTSTATUS Status;
1422  bool top_level;
1423 
1425 
1426  TRACE("set volume information\n");
1427 
1428  top_level = is_top_level(Irp);
1429 
1430  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1432  goto end;
1433  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1435  goto end;
1436  }
1437 
1439 
1440  if (Vcb->readonly) {
1442  goto end;
1443  }
1444 
1445  if (Vcb->removing || Vcb->locked) {
1447  goto end;
1448  }
1449 
1450  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1452  FIXME("STUB: FileFsControlInformation\n");
1453  break;
1454 
1456  TRACE("FileFsLabelInformation\n");
1457 
1458  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1459  break;
1460 
1462  FIXME("STUB: FileFsObjectIdInformation\n");
1463  break;
1464 
1465  default:
1466  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1467  break;
1468  }
1469 
1470 end:
1471  Irp->IoStatus.Status = Status;
1472  Irp->IoStatus.Information = 0;
1473 
1474  TRACE("returning %08lx\n", Status);
1475 
1477 
1478  if (top_level)
1480 
1482 
1483  return Status;
1484 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WARN(fmt,...)
Definition: debug.h:112
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
_In_ PIRP Irp
Definition: csq.h:116
#define FIXME(fmt,...)
Definition: debug.h:111
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1361
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
GLuint GLuint end
Definition: gl.h:1545
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:598
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128

◆ _Dispatch_type_() [5/10]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2407 of file btrfs.c.

2409  {
2410  NTSTATUS Status;
2413  device_extension* Vcb = DeviceObject->DeviceExtension;
2414  fcb* fcb = FileObject->FsContext;
2415  bool top_level;
2416 
2418 
2419  TRACE("cleanup\n");
2420 
2421  top_level = is_top_level(Irp);
2422 
2423  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2424  Irp->IoStatus.Information = 0;
2426  goto exit;
2427  } else if (DeviceObject == master_devobj) {
2428  TRACE("closing file system\n");
2430  goto exit;
2431  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2433  goto exit;
2434  }
2435 
2436  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2437  TRACE("FileObject %p already cleaned up\n", FileObject);
2439  goto exit;
2440  }
2441 
2442  if (!fcb) {
2443  ERR("fcb was NULL\n");
2445  goto exit;
2446  }
2447 
2449 
2450  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2451  // messages belonging to other devices.
2452 
2453  if (FileObject && FileObject->FsContext) {
2454  ccb* ccb;
2455  file_ref* fileref;
2456  bool locked = true;
2457 
2458  ccb = FileObject->FsContext2;
2459  fileref = ccb ? ccb->fileref : NULL;
2460 
2461  TRACE("cleanup called for FileObject %p\n", FileObject);
2462  TRACE("fileref %p, refcount = %li, open_count = %li\n", fileref, fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2463 
2464  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
2465 
2466  ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
2467 
2469 
2471 
2472  if (ccb)
2473  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2474 
2475  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2476  fileref->delete_on_close = true;
2477 
2478  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2479  fileref->delete_on_close = false;
2480 
2481  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2482  TRACE("unlocking volume\n");
2485  }
2486 
2487  if (ccb && ccb->reserving) {
2488  fcb->subvol->reserved = NULL;
2489  ccb->reserving = false;
2490  // FIXME - flush all of subvol's fcbs
2491  }
2492 
2493  if (fileref) {
2494  LONG oc = InterlockedDecrement(&fileref->open_count);
2495 #ifdef DEBUG_FCB_REFCOUNTS
2496  ERR("fileref %p: open_count now %i\n", fileref, oc);
2497 #endif
2498 
2499  if (oc == 0 || (fileref->delete_on_close && fileref->posix_delete)) {
2500  if (!fcb->Vcb->removing) {
2501  if (oc == 0 && fileref->fcb->inode_item.st_nlink == 0 && fileref != fcb->Vcb->root_fileref &&
2502  fcb != fcb->Vcb->volume_fcb && !fcb->ads) { // last handle closed on POSIX-deleted file
2504 
2506 
2508  if (!NT_SUCCESS(Status)) {
2509  ERR("delete_fileref_fcb returned %08lx\n", Status);
2511  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2512  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2513  goto exit;
2514  }
2515 
2517 
2518  mark_fcb_dirty(fileref->fcb);
2519  } else if (fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2521 
2523 
2524  if (!fileref->fcb->ads || fileref->dc) {
2525  if (fileref->fcb->ads) {
2527  FILE_ACTION_REMOVED, &fileref->dc->name);
2528  } else
2530  }
2531 
2532  ExReleaseResourceLite(fcb->Header.Resource);
2533  locked = false;
2534 
2535  // fileref_lock needs to be acquired before fcb->Header.Resource
2536  ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
2537 
2538  Status = delete_fileref(fileref, FileObject, oc > 0 && fileref->posix_delete, Irp, &rollback);
2539  if (!NT_SUCCESS(Status)) {
2540  ERR("delete_fileref returned %08lx\n", Status);
2542  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2543  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2544  goto exit;
2545  }
2546 
2547  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2548 
2550  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && FileObject->SectionObjectPointer->DataSectionObject) {
2552 
2553  if (locked) {
2554  ExReleaseResourceLite(fcb->Header.Resource);
2555  locked = false;
2556  }
2557 
2558  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2559 
2560  if (!NT_SUCCESS(iosb.Status))
2561  ERR("CcFlushCache returned %08lx\n", iosb.Status);
2562 
2563  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2564  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
2565  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2566  }
2567 
2568  CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, false);
2569 
2570  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2571  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2572  }
2573  }
2574 
2575  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2577  }
2578  }
2579 
2580  if (locked)
2581  ExReleaseResourceLite(fcb->Header.Resource);
2582 
2583  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2584 
2585  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2586  }
2587 
2589 
2590 exit:
2591  TRACE("returning %08lx\n", Status);
2592 
2593  Irp->IoStatus.Status = Status;
2594  Irp->IoStatus.Information = 0;
2595 
2597 
2598  if (top_level)
2600 
2602 
2603  return Status;
2604 }
struct _file_ref * parent
Definition: btrfs_drv.h:352
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
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:386
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:374
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
#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:4242
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:351
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
#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:1486
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
bool posix_delete
Definition: btrfs_drv.h:346
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:659
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
long LONG
Definition: pedump.c:60
uint32_t st_nlink
Definition: btrfs.h:292
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:66
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
#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:291
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
LONG refcount
Definition: btrfs_drv.h:350
FILE_LOCK lock
Definition: btrfs_drv.h:294
InsertTailList & Vcb
Definition: btrfs.c:3013
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:283
Status
Definition: gdiplustypes.h:24
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
uint64_t st_size
Definition: btrfs.h:289
#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:681
NTSTATUS NTSTATUS void clear_rollback(LIST_ENTRY *rollback) __attribute__((nonnull(1)))
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1998
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1781
dir_child * dc
Definition: btrfs_drv.h:353
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define InterlockedDecrement
Definition: armddk.h:52
fcb * fcb
Definition: btrfs_drv.h:342
Definition: typedefs.h:119
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1025
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback) __attribute__((nonnull(1
INODE_ITEM inode_item
Definition: btrfs_drv.h:292
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1790
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:2183
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
struct _root * subvol
Definition: btrfs_drv.h:288
#define NULL
Definition: types.h:112
_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:1355
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
bool ads
Definition: btrfs_drv.h:330
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1670
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:2239
#define IO_NO_INCREMENT
Definition: iotypes.h:598
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
bool reserving
Definition: btrfs_drv.h:381
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1170
SHARE_ACCESS share_access
Definition: btrfs_drv.h:298
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:383
return STATUS_SUCCESS
Definition: btrfs.c:3049
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2322
struct _device_extension * Vcb
Definition: btrfs_drv.h:287
UNICODE_STRING name
Definition: btrfs_drv.h:256
bool delete_on_close
Definition: btrfs_drv.h:345

◆ _Dispatch_type_() [6/10]

_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 5233 of file btrfs.c.

5235  {
5237  NTSTATUS Status;
5238  device_extension* Vcb = DeviceObject->DeviceExtension;
5239  bool top_level;
5240 
5242 
5243  TRACE("file system control\n");
5244 
5245  top_level = is_top_level(Irp);
5246 
5247  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5249  goto end;
5250  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
5252  goto end;
5253  }
5254 
5256 
5258 
5259  Irp->IoStatus.Information = 0;
5260 
5261  switch (IrpSp->MinorFunction) {
5262  case IRP_MN_MOUNT_VOLUME:
5263  TRACE("IRP_MN_MOUNT_VOLUME\n");
5264 
5266  break;
5267 
5268  case IRP_MN_KERNEL_CALL:
5269  TRACE("IRP_MN_KERNEL_CALL\n");
5270 
5271  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
5272  break;
5273 
5275  TRACE("IRP_MN_USER_FS_REQUEST\n");
5276 
5277  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
5278  break;
5279 
5280  case IRP_MN_VERIFY_VOLUME:
5281  TRACE("IRP_MN_VERIFY_VOLUME\n");
5282 
5284 
5285  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
5286  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
5287  Vcb->removing = true;
5288  ExReleaseResourceLite(&Vcb->tree_lock);
5289  }
5290 
5291  break;
5292 
5293  default:
5294  break;
5295  }
5296 
5297 end:
5298  TRACE("returning %08lx\n", Status);
5299 
5300  if (Irp) {
5301  Irp->IoStatus.Status = Status;
5302 
5304  }
5305 
5306  if (top_level)
5308 
5310 
5311  return Status;
5312 }
#define FsRtlEnterFileSystem
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, uint32_t type)
Definition: fsctl.c:5341
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4405
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4403
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLuint GLuint end
Definition: gl.h:1545
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4408
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:680
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:598
static NTSTATUS verify_volume(_In_ PDEVICE_OBJECT devobj)
Definition: btrfs.c:5172
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
#define VPB_MOUNTED
Definition: iotypes.h:1807
static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: btrfs.c:4344

◆ _Dispatch_type_() [7/10]

_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 5314 of file btrfs.c.

5316  {
5317  NTSTATUS Status;
5319  fcb* fcb = IrpSp->FileObject ? IrpSp->FileObject->FsContext : NULL;
5320  device_extension* Vcb = DeviceObject->DeviceExtension;
5321  bool top_level;
5322 
5324 
5325  top_level = is_top_level(Irp);
5326 
5327  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5329 
5330  Irp->IoStatus.Status = Status;
5332 
5333  goto exit;
5334  }
5335 
5336  TRACE("lock control\n");
5337 
5338  if (!fcb) {
5339  ERR("fcb was NULL\n");
5341  goto exit;
5342  }
5343 
5345 
5347 
5348  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
5349 
5350 exit:
5351  TRACE("returning %08lx\n", Status);
5352 
5353  if (top_level)
5355 
5357 
5358  return Status;
5359 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
FILE_LOCK lock
Definition: btrfs_drv.h:294
InsertTailList & Vcb
Definition: btrfs.c:3013
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:283
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static __inline FAST_IO_POSSIBLE fast_io_possible(fcb *fcb)
Definition: btrfs_drv.h:1677
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1152
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1670
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1170
void exit(int exitcode)
Definition: _exit.c:33

◆ _Dispatch_type_() [8/10]

_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 5479 of file btrfs.c.

5481  {
5482  NTSTATUS Status;
5483  bool top_level;
5484  device_extension* Vcb = DeviceObject->DeviceExtension;
5485 
5487 
5488  TRACE("shutdown\n");
5489 
5490  top_level = is_top_level(Irp);
5491 
5492  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5494  goto end;
5495  }
5496 
5498 
5499  do_shutdown(Irp);
5500 
5501 end:
5502  Irp->IoStatus.Status = Status;
5503  Irp->IoStatus.Information = 0;
5504 
5506 
5507  if (top_level)
5509 
5511 
5512  return Status;
5513 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
GLuint GLuint end
Definition: gl.h:1545
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:598
return STATUS_SUCCESS
Definition: btrfs.c:3049
void do_shutdown(PIRP Irp)
Definition: btrfs.c:5361

◆ _Dispatch_type_() [9/10]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5623 of file btrfs.c.

5625  {
5626  NTSTATUS Status;
5628  device_extension* Vcb = DeviceObject->DeviceExtension;
5629  bool top_level;
5630 
5631  // no need for FsRtlEnterFileSystem, as this only ever gets called in a system thread
5632 
5633  top_level = is_top_level(Irp);
5634 
5635  Irp->IoStatus.Information = 0;
5636 
5637  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5638  volume_device_extension* vde = DeviceObject->DeviceExtension;
5639 
5641  IrpSp->Parameters.Power.State.SystemState != PowerSystemWorking && vde->mounted_device) {
5643 
5644  /* If power state is about to go to sleep or hibernate, do a flush. We do this on IRP_MJ_QUERY_POWER
5645  * rather than IRP_MJ_SET_POWER because we know that the hard disks are still awake. */
5646 
5647  if (Vcb2) {
5648  ExAcquireResourceExclusiveLite(&Vcb2->tree_lock, true);
5649 
5650  if (Vcb2->need_write && !Vcb2->readonly) {
5651  TRACE("doing protective flush on power state change\n");
5652  Status = do_write(Vcb2, NULL);
5653  } else
5655 
5656  free_trees(Vcb2);
5657 
5658  if (!NT_SUCCESS(Status))
5659  ERR("do_write returned %08lx\n", Status);
5660 
5661  ExReleaseResourceLite(&Vcb2->tree_lock);
5662  }
5663  } else if (IrpSp->MinorFunction == IRP_MN_SET_POWER && IrpSp->Parameters.Power.Type == SystemPowerState &&
5664  IrpSp->Parameters.Power.State.SystemState == PowerSystemWorking && vde->mounted_device) {
5666 
5667  /* If waking up, make sure that the FS hasn't been changed while we've been out (e.g., by dual-boot Linux) */
5668 
5669  if (Vcb2) {
5670  PIO_WORKITEM work_item;
5671 
5672  work_item = IoAllocateWorkItem(DeviceObject);
5673  if (!work_item) {
5674  ERR("out of memory\n");
5675  } else
5676  IoQueueWorkItem(work_item, check_after_wakeup, DelayedWorkQueue, Vcb2);
5677  }
5678  }
5679 
5682  Status = PoCallDriver(vde->attached_device, Irp);
5683 
5684  goto exit;
5685  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5687 
5688  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5689 
5690  goto exit;
5691  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5692  bus_device_extension* bde = DeviceObject->DeviceExtension;
5693 
5696  Status = PoCallDriver(bde->attached_device, Irp);
5697 
5698  goto exit;
5699  }
5700 
5702  Irp->IoStatus.Status = STATUS_SUCCESS;
5703 
5704  Status = Irp->IoStatus.Status;
5705 
5707 
5709 
5710 exit:
5711  if (top_level)
5713 
5714  return Status;
5715 }
#define IRP_MN_QUERY_POWER
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7759
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:683
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:868
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define IRP_MN_SET_POWER
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:872
NTSTATUS NTSTATUS bool bool void free_trees(device_extension *Vcb) __attribute__((nonnull(1)))
#define ERR(fmt,...)
Definition: debug.h:110
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:841
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:746
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
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:598
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7519
void exit(int exitcode)
Definition: _exit.c:33
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
return STATUS_SUCCESS
Definition: btrfs.c:3049

◆ _Dispatch_type_() [10/10]

_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5717 of file btrfs.c.

5719  {
5720  NTSTATUS Status;
5721  device_extension* Vcb = DeviceObject->DeviceExtension;
5722  bool top_level;
5723 
5725 
5726  top_level = is_top_level(Irp);
5727 
5728  Irp->IoStatus.Information = 0;
5729 
5730  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5731  volume_device_extension* vde = DeviceObject->DeviceExtension;
5732 
5734 
5736 
5737  goto exit;
5738  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5740 
5741  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5742 
5743  goto exit;
5744  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5745  bus_device_extension* bde = DeviceObject->DeviceExtension;
5746 
5748 
5750 
5751  goto exit;
5752  }
5753 
5754  Status = Irp->IoStatus.Status;
5756 
5757 exit:
5758  if (top_level)
5760 
5762 
5763  return Status;
5764 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
#define VCB_TYPE_FS
Definition: btrfs_drv.h:679
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:277
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:683
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:3013
Status
Definition: gdiplustypes.h:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:681
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:872
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:841
#define NULL
Definition: types.h:112
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:598
void exit(int exitcode)
Definition: _exit.c:33

◆ _Function_class_() [1/6]

_Function_class_ ( DRIVER_UNLOAD  )

Definition at line 329 of file btrfs.c.

330  {
331  UNICODE_STRING dosdevice_nameW;
332 
333  TRACE("(%p)\n", DriverObject);
334 
335  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
336  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
337 
338  IoDeleteSymbolicLink(&dosdevice_nameW);
339  IoDeleteDevice(DriverObject->DeviceObject);
340 
341  while (!IsListEmpty(&uid_map_list)) {
343  uid_map* um = CONTAINING_RECORD(le, uid_map, listentry);
344 
345  ExFreePool(um->sid);
346 
347  ExFreePool(um);
348  }
349 
350  while (!IsListEmpty(&gid_map_list)) {
352 
353  ExFreePool(gm->sid);
354  ExFreePool(gm);
355  }
356 
357  // FIXME - free volumes and their devpaths
358 
359 #ifdef _DEBUG
360  if (comfo)
361  ObDereferenceObject(comfo);
362 
363  if (log_handle)
364  ZwClose(log_handle);
365 #endif
366 
369 
370  if (log_device.Buffer)
372 
373  if (log_file.Buffer)
375 
376  if (registry_path.Buffer)
378 
379 #ifdef _DEBUG
380  ExDeleteResourceLite(&log_lock);
381 #endif
383 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
UNICODE_STRING log_file
Definition: btrfs.c:88
PSID sid
Definition: btrfs_drv.h:902
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UNICODE_STRING registry_path
Definition: btrfs.c:88
PSID sid
Definition: btrfs_drv.h:896
static const WCHAR dosdevice_name[]
Definition: btrfs.c:61
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
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ObDereferenceObject
Definition: obfuncs.h:203
LIST_ENTRY uid_map_list
Definition: btrfs.c:68
Definition: typedefs.h:119
ERESOURCE mapping_lock
Definition: btrfs.c:102
ERESOURCE global_loading_lock
Definition: btrfs.c:70
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
UNICODE_STRING log_device
Definition: btrfs.c:88
ERESOURCE pdo_list_lock
Definition: btrfs.c:102
LIST_ENTRY gid_map_list
Definition: btrfs.c:68
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ _Function_class_() [2/6]

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 1228 of file btrfs.c.

1229  {
1230  read_context* context = conptr;
1231 
1233 
1234  context->iosb = Irp->IoStatus;
1235  KeSetEvent(&context->Event, 0, false);
1236 
1238 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
Definition: http.c:7251
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define UNUSED(x)
Definition: btrfs_drv.h:82

◆ _Function_class_() [3/6]

_Function_class_ ( IO_WORKITEM_ROUTINE  )

Definition at line 1617 of file btrfs.c.

1618  {
1619  notification_fcb* nf = con;
1620 
1622 
1623  ExAcquireResourceSharedLite(&nf->fileref->fcb->Vcb->tree_lock, TRUE); // protect us from fileref being reaped
1624 
1626 
1627  free_fileref(nf->fileref);
1628 
1629  ExReleaseResourceLite(&nf->fileref->fcb->Vcb->tree_lock);
1630 
1632 
1633  ExFreePool(nf);
1634 }
#define TRUE
Definition: types.h:120
PUNICODE_STRING stream
Definition: btrfs.c:1613
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
ULONG filter_match
Definition: btrfs.c:1611
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
static void send_notification_fcb(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1526
#define UNUSED(x)
Definition: btrfs_drv.h:82
file_ref * fileref
Definition: btrfs.c:1610
PIO_WORKITEM work_item
Definition: btrfs.c:1614
ULONG action
Definition: btrfs.c:1612
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
fcb * fcb
Definition: btrfs_drv.h:342
void free_fileref(_Inout_ file_ref *fr)
Definition: btrfs.c:1825
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
struct _device_extension * Vcb
Definition: btrfs_drv.h:287
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ _Function_class_() [4/6]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 6106 of file btrfs.c.

6107  {
6108  KTIMER timer;
6109  LARGE_INTEGER delay;
6110 
6111  UNUSED(context);
6112 
6113  KeInitializeTimer(&timer);
6114 
6115  delay.QuadPart = -30000000; // wait three seconds
6116  KeSetTimer(&timer, delay, NULL);
6117  KeWaitForSingleObject(&timer, Executive, KernelMode, false, NULL);
6118 
6119  TRACE("timer expired\n");
6120 
6121  degraded_wait = false;
6122 
6125 
6127 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
Definition: http.c:7251
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
HANDLE degraded_wait_handle
Definition: btrfs.c:105
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
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define UNUSED(x)
Definition: btrfs_drv.h:82
#define TRACE(s)
Definition: solgame.cpp:4
bool degraded_wait
Definition: btrfs.c:106
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1148
#define NULL
Definition: types.h:112
return STATUS_SUCCESS
Definition: btrfs.c:3049
LONGLONG QuadPart
Definition: typedefs.h:114

◆ _Function_class_() [5/6]

_Function_class_ ( DRIVER_ADD_DEVICE  )

Definition at line 6129 of file btrfs.c.

6130  {
6131  LIST_ENTRY* le;
6132  NTSTATUS Status;
6133  UNICODE_STRING volname;
6134  ULONG i;
6135  WCHAR* s;
6136  pdo_device_extension* pdode = NULL;
6137  PDEVICE_OBJECT voldev;
6139  UNICODE_STRING arc_name_us;
6140  WCHAR* anp;
6141 
6142  static const WCHAR arc_name_prefix[] = L"\\ArcName\\btrfs(";
6143 
6144  WCHAR arc_name[(sizeof(arc_name_prefix) / sizeof(WCHAR)) - 1 + 37];
6145 
6146  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
6147 
6149 
6151 
6152  le = pdo_list.Flink;
6153  while (le != &pdo_list) {
6155 
6156  if (pdode2->pdo == PhysicalDeviceObject) {
6157  pdode = pdode2;
6158  break;
6159  }
6160 
6161  le = le->Flink;
6162  }
6163 
6164  if (!pdode) {
6165  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
6167  goto end;
6168  }
6169 
6171 
6172  if (pdode->vde) { // if already done, return success
6174  goto end2;
6175  }
6176 
6177  volname.Length = volname.MaximumLength = (sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR)) + ((36 + 1) * sizeof(WCHAR));
6178  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
6179 
6180  if (!volname.Buffer) {
6181  ERR("out of memory\n");
6183  goto end2;
6184  }
6185 
6186  RtlCopyMemory(volname.Buffer, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR));
6187  RtlCopyMemory(arc_name, arc_name_prefix, sizeof(arc_name_prefix) - sizeof(WCHAR));
6188 
6189  anp = &arc_name[(sizeof(arc_name_prefix) / sizeof(WCHAR)) - 1];
6190  s = &volname.Buffer[(sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1];
6191 
6192  for (i = 0; i < 16; i++) {
6193  *s = *anp = hex_digit(pdode->uuid.uuid[i] >> 4);
6194  s++;
6195  anp++;
6196 
6197  *s = *anp = hex_digit(pdode->uuid.uuid[i] & 0xf);
6198  s++;
6199  anp++;
6200 
6201  if (i == 3 || i == 5 || i == 7 || i == 9) {
6202  *s = *anp = '-';
6203  s++;
6204  anp++;
6205  }
6206  }
6207 
6208  *s = '}';
6209  *anp = ')';
6210 
6213  if (!NT_SUCCESS(Status)) {
6214  ERR("IoCreateDevice returned %08lx\n", Status);
6215  goto end2;
6216  }
6217 
6218  arc_name_us.Buffer = arc_name;
6219  arc_name_us.Length = arc_name_us.MaximumLength = sizeof(arc_name);
6220 
6221  Status = IoCreateSymbolicLink(&arc_name_us, &volname);
6222  if (!NT_SUCCESS(Status))
6223  WARN("IoCreateSymbolicLink returned %08lx\n", Status);
6224 
6225  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
6226  voldev->Flags |= DO_DIRECT_IO;
6227 
6228  vde = voldev->DeviceExtension;
6229  vde->type = VCB_TYPE_VOLUME;
6230  vde->name = volname;
6231  vde->device = voldev;
6232  vde->mounted_device = NULL;
6233  vde->pdo = PhysicalDeviceObject;
6234  vde->pdode = pdode;
6235  vde->removing = false;
6236  vde->dead = false;
6237  vde->open_count = 0;
6238 
6239  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
6240  if (!NT_SUCCESS(Status))
6241  WARN("IoRegisterDeviceInterface returned %08lx\n", Status);
6242 
6244 
6245  pdode->vde = vde;
6246 
6247  if (pdode->removable)
6248  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
6249 
6250  if (RtlCompareMemory(&boot_uuid, &pdode->uuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
6251  voldev->Flags |= DO_SYSTEM_BOOT_PARTITION;
6253  }
6254 
6255  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
6256 
6257  Status = IoSetDeviceInterfaceState(&vde->bus_name, true);
6258  if (!NT_SUCCESS(Status))
6259  WARN("IoSetDeviceInterfaceState returned %08lx\n", Status);
6260 
6262 
6263 end2:
6265 
6266 end:
6268 
6269  return Status;
6270 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1738
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
return STATUS_NOT_SUPPORTED
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
PDEVICE_OBJECT device
Definition: btrfs_drv.h:867
#define WARN(fmt,...)
Definition: debug.h:112
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:869
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1149
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
UNICODE_STRING name
Definition: btrfs_drv.h:866
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:882
#define ALLOC_TAG
Definition: btrfs_drv.h:87
UNICODE_STRING bus_name
Definition: btrfs_drv.h:871
BTRFS_UUID boot_uuid
Definition: boot.c:33
#define L(x)
Definition: ntvdm.h:50
bool is_windows_8
Definition: btrfs.c:110
#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
#define DO_SYSTEM_BOOT_PARTITION
Definition: env_spec_w32.h:400
#define UNUSED(x)
Definition: btrfs_drv.h:82
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:870
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
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:103
__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:681
ERESOURCE child_lock
Definition: btrfs_drv.h:888
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:868
GLuint GLuint end
Definition: gl.h:1545
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:65
GLdouble s
Definition: gl.h:2039
Definition: typedefs.h:119
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:872
#define ERR(fmt,...)
Definition: debug.h:110
uint8_t uuid[16]
Definition: btrfs.h:140
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
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_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
Definition: btrfs_drv.h:156
Definition: list.h:27
#define NULL
Definition: types.h:112
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
ERESOURCE pdo_list_lock
Definition: btrfs.c:102
volume_device_extension * vde
Definition: btrfs_drv.h:881
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 RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
return STATUS_SUCCESS
Definition: btrfs.c:3049
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

◆ _Function_class_() [6/6]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 6272 of file btrfs.c.

6273  {
6274  NTSTATUS Status;
6276  UNICODE_STRING device_nameW;
6277  UNICODE_STRING dosdevice_nameW;
6279  bus_device_extension* bde;
6280  HANDLE regh;
6281  OBJECT_ATTRIBUTES oa, system_thread_attributes;
6282  ULONG dispos;
6283  RTL_OSVERSIONINFOW ver;
6284 
6286 
6287  Status = RtlGetVersion(&ver);
6288  if (!NT_SUCCESS(Status)) {
6289  ERR("RtlGetVersion returned %08lx\n", Status);
6290  return Status;
6291  }
6292 
6293  is_windows_8 = ver.dwMajorVersion > 6 || (ver.dwMajorVersion == 6 && ver.dwMinorVersion >= 2);
6294 
6296 
6299 
6300 #ifdef _DEBUG
6301  ExInitializeResourceLite(&log_lock);
6302 #endif
6304 
6307  log_file.Buffer = NULL;
6309 
6312 
6313  if (!registry_path.Buffer) {
6314  ERR("out of memory\n");
6316  }
6317 
6319 
6320  read_registry(&registry_path, false);
6321 
6322 #ifdef _DEBUG
6323  if (debug_log_level > 0)
6324  init_logging();
6325 
6326  log_started = true;
6327 #endif
6328 
6329  TRACE("DriverEntry\n");
6330 
6331 #if !defined(__REACTOS__) && (defined(_X86_) || defined(_AMD64_))
6332  check_cpu();
6333 #endif
6334 
6335  if (ver.dwMajorVersion > 6 || (ver.dwMajorVersion == 6 && ver.dwMinorVersion >= 2)) { // Windows 8 or above
6337  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
6338 
6339  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
6340  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
6341 
6342  if (fPsIsDiskCountersEnabled) {
6343  diskacc = fPsIsDiskCountersEnabled();
6344 
6345  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
6347 
6348  if (!fPsUpdateDiskCounters)
6349  diskacc = false;
6350 
6351  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
6353  }
6354 
6355  RtlInitUnicodeString(&name, L"CcCopyReadEx");
6357 
6358  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
6360 
6361  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
6363 
6364  RtlInitUnicodeString(&name, L"FsRtlCheckLockForOplockRequest");
6366  } else {
6368  fCcCopyReadEx = NULL;
6369  fCcCopyWriteEx = NULL;
6373  }
6374 
6375  if (ver.dwMajorVersion > 6 || (ver.dwMajorVersion == 6 && ver.dwMinorVersion >= 1)) { // Windows 7 or above
6377 
6378  RtlInitUnicodeString(&name, L"IoUnregisterPlugPlayNotificationEx");
6380 
6381  RtlInitUnicodeString(&name, L"FsRtlAreThereCurrentOrInProgressFileLocks");
6383  } else {
6386  }
6387 
6388  if (ver.dwMajorVersion >= 6) { // Windows Vista or above
6390 
6391  RtlInitUnicodeString(&name, L"FsRtlGetEcpListFromIrp");
6393 
6394  RtlInitUnicodeString(&name, L"FsRtlGetNextExtraCreateParameter");
6396 
6397  RtlInitUnicodeString(&name, L"FsRtlValidateReparsePointBuffer");
6399  } else {
6403  }
6404 
6405  drvobj = DriverObject;
6406 
6408 
6409  DriverObject->DriverExtension->AddDevice = AddDevice;
6410 
6411  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
6412  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
6413  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
6414  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
6415  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
6416  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
6417  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
6418  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
6419  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
6420  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
6421  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
6422  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
6423  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
6424  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
6425  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
6426  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
6427  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
6428  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
6429  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
6430  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
6431  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
6432  DriverObject->MajorFunction[IRP_MJ_PNP] = drv_pnp;
6433 
6434  init_fast_io_dispatch(&DriverObject->FastIoDispatch);
6435 
6436  device_nameW.Buffer = (WCHAR*)device_name;
6437  device_nameW.Length = device_nameW.MaximumLength = sizeof(device_name) - sizeof(WCHAR);
6438  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
6439  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
6440 
6443  if (!NT_SUCCESS(Status)) {
6444  ERR("IoCreateDevice returned %08lx\n", Status);
6445  return Status;
6446  }
6447 
6450 
6452 
6453  cde->type = VCB_TYPE_CONTROL;
6454 
6456 
6457  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
6458  if (!NT_SUCCESS(Status)) {
6459  ERR("IoCreateSymbolicLink returned %08lx\n", Status);
6460  return Status;
6461  }
6462 
6463  init_cache();
6464 
6468 
6470 
6473  if (!NT_SUCCESS(Status)) {
6474  ERR("ZwCreateKey returned %08lx\n", Status);
6475  return Status;
6476  }
6477 
6478  watch_registry(regh);
6479 
6481  FILE_DEVICE_SECURE_OPEN, false, &busobj);
6482  if (!NT_SUCCESS(Status)) {
6483  ERR("IoCreateDevice returned %08lx\n", Status);
6484  return Status;
6485  }
6486 
6488 
6489  RtlZeroMemory(bde, sizeof(bus_device_extension));
6490 
6491  bde->type = VCB_TYPE_BUS;
6492 
6493  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
6494  NULL, NULL, 0, &bde->buspdo);
6495  if (!NT_SUCCESS(Status)) {
6496  ERR("IoReportDetectedDevice returned %08lx\n", Status);
6497  return Status;
6498  }
6499 
6500  Status = IoRegisterDeviceInterface(bde->buspdo, &BtrfsBusInterface, NULL, &bde->bus_name);
6501  if (!NT_SUCCESS(Status))
6502  WARN("IoRegisterDeviceInterface returned %08lx\n", Status);
6503 
6505 
6507 
6508  Status = IoSetDeviceInterfaceState(&bde->bus_name, true);
6509  if (!NT_SUCCESS(Status))
6510  WARN("IoSetDeviceInterfaceState returned %08lx\n", Status);
6511 
6513 
6514  InitializeObjectAttributes(&system_thread_attributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
6515 
6516  Status = PsCreateSystemThread(&degraded_wait_handle, 0, &system_thread_attributes, NULL, NULL, degraded_wait_thread, NULL);
6517  if (!NT_SUCCESS(Status))
6518  WARN("PsCreateSystemThread returned %08lx\n", Status);
6519 
6521 
6523  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, NULL, &notification_entry2);
6524  if (!NT_SUCCESS(Status))
6525  ERR("IoRegisterPlugPlayNotification returned %08lx\n", Status);
6526 
6528  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, NULL, &notification_entry3);
6529  if (!NT_SUCCESS(Status))
6530  ERR("IoRegisterPlugPlayNotification returned %08lx\n", Status);
6531 
6533  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
6534  if (!NT_SUCCESS(Status))
6535  ERR("IoRegisterPlugPlayNotification returned %08lx\n", Status);
6536 
6537  finished_probing = true;
6538 
6540 
6541  // Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, &system_thread_attributes, NULL, NULL, mountmgr_thread, NULL);
6542  // if (!NT_SUCCESS(Status))
6543  // WARN("PsCreateSystemThread returned %08lx\n", Status);
6544 
6546 
6548 
6549  return STATUS_SUCCESS;
6550 }
VOID(__stdcall * tFsRtlUpdateDiskCounters)(ULONG64 BytesRead, ULONG64 BytesWritten)
Definition: btrfs_drv.h:1845
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
tFsRtlCheckLockForOplockRequest fFsRtlCheckLockForOplockRequest
Definition: btrfs.c:98
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:840
#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:535
NTSTATUS NTAPI RtlGetVersion(IN OUT PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: version.c:158
bool finished_probing
Definition: btrfs.c:104
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_FLUSH_BUFFERS
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSTATUS(__stdcall * tFsRtlGetNextExtraCreateParameter)(PECP_LIST EcpList, PVOID CurrentEcpContext, LPGUID NextEcpType, PVOID *NextEcpContext, ULONG *NextEcpContextSize)
Definition: btrfs_drv.h:1851
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IRP_MJ_SHUTDOWN
void * notification_entry3
Definition: btrfs.c:101
DRIVER_ADD_DEVICE AddDevice
Definition: parport.h:72
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:90
HANDLE degraded_wait_handle
Definition: btrfs.c:105
LIST_ENTRY VcbList
Definition: btrfs.c:69
#define IRP_MJ_SET_SECURITY
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define WARN(fmt,...)
Definition: debug.h:112
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
static const WCHAR device_name[]
Definition: btrfs.c:60
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4242
UNICODE_STRING log_file
Definition: btrfs.c:88
tFsRtlValidateReparsePointBuffer fFsRtlValidateReparsePointBuffer
Definition: btrfs.c:97
tFsRtlAreThereCurrentOrInProgressFileLocks fFsRtlAreThereCurrentOrInProgressFileLocks
Definition: btrfs.c:99
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1239
void watch_registry(HANDLE regh)
Definition: registry.c:1028
void * notification_entry2
Definition: btrfs.c:101
bool diskacc
Definition: btrfs.c:100
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
uint32_t debug_log_level
Definition: btrfs.c:71
KSPIN_LOCK fve_data_lock
Definition: search.c:63
UNICODE_STRING bus_name
Definition: btrfs_drv.h:842
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:683
void check_system_root()
Definition: boot.c:336
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:89
#define ALLOC_TAG
Definition: btrfs_drv.h:87
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
UNICODE_STRING registry_path
Definition: btrfs.c:88
#define L(x)
Definition: ntvdm.h:50
bool is_windows_8
Definition: btrfs.c:110
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3514
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
BOOLEAN(__stdcall * tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1831
static const WCHAR dosdevice_name[]
Definition: btrfs.c:61
#define IRP_MJ_SET_EA
NTSTATUS(__stdcall * tFsRtlGetEcpListFromIrp)(PIRP Irp, PECP_LIST *EcpList)
Definition: btrfs_drv.h:1849
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:66
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:240
PVOID DeviceExtension
Definition: env_spec_w32.h:418
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:93
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
struct _OSVERSIONINFOW RTL_OSVERSIONINFOW
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:114
tCcCopyWriteEx fCcCopyWriteEx
Definition: btrfs.c:91
Status
Definition: gdiplustypes.h:24
#define IRP_MJ_QUERY_EA
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
void * notification_entry
Definition: btrfs.c:101
BOOLEAN(__stdcall * tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1828
#define TRACE(s)
Definition: solgame.cpp:4
ULONG dwMajorVersion
Definition: rtltypes.h:247
LIST_ENTRY pdo_list
Definition: btrfs.c:103
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:246
BOOLEAN(__stdcall * tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1823
BOOLEAN(__stdcall * tFsRtlAreThereCurrentOrInProgressFileLocks)(PFILE_LOCK FileLock)
Definition: btrfs_drv.h:1858
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:65
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:92
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2288
NTSTATUS(__stdcall * tFsRtlValidateReparsePointBuffer)(ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: btrfs_drv.h:1854
LIST_ENTRY uid_map_list
Definition: btrfs.c:68
PDEVICE_OBJECT busobj
Definition: btrfs.c:66
#define IRP_MJ_SYSTEM_CONTROL
tFsRtlGetNextExtraCreateParameter fFsRtlGetNextExtraCreateParameter
Definition: btrfs.c:96
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:680
NTSTATUS NTAPI IoReportDetectedDevice(_In_ PDRIVER_OBJECT DriverObject, _In_ INTERFACE_TYPE LegacyBusType, _In_ ULONG BusNumber, _In_ ULONG SlotNumber, _In_opt_ PCM_RESOURCE_LIST ResourceList, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements, _In_ BOOLEAN ResourceAssigned, _Inout_ PDEVICE_OBJECT *DeviceObject)
Definition: pnpreport.c:148
ERESOURCE mapping_lock
Definition: btrfs.c:102
ERESOURCE global_loading_lock
Definition: btrfs.c:70
#define ERR(fmt,...)
Definition: debug.h:110
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:841
NTSTATUS(__stdcall * tIoUnregisterPlugPlayNotificationEx)(PVOID NotificationEntry)
Definition: btrfs_drv.h:1847
void init_cache()
Definition: cache.c:85
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:2342
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
tIoUnregisterPlugPlayNotificationEx fIoUnregisterPlugPlayNotificationEx
Definition: btrfs.c:94
BOOLEAN(__stdcall * tFsRtlCheckLockForOplockRequest)(PFILE_LOCK FileLock, PLARGE_INTEGER AllocationSize)
Definition: btrfs_drv.h:1856
KEVENT mountmgr_thread_event
Definition: btrfs.c:107
#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:88
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)
#define NULL
Definition: types.h:112
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
ERESOURCE pdo_list_lock
Definition: btrfs.c:102
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
ULONG dwMinorVersion
Definition: rtltypes.h:248
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG const UNICODE_STRING ULONG PULONG dispos
Definition: reg.c:130
#define IRP_MJ_CLEANUP
Definition: name.c:38
#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:87
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSTATUS NTAPI IoRegisterPlugPlayNotification(_In_ IO_NOTIFICATION_EVENT_CATEGORY EventCategory, _In_ ULONG EventCategoryFlags, _In_opt_ PVOID EventCategoryData, _In_ PDRIVER_OBJECT DriverObject, _In_ PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, _Inout_opt_ PVOID Context, _Out_ PVOID *NotificationEntry)
Definition: pnpnotify.c:345
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID(__stdcall * tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1843
#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:68
tFsRtlGetEcpListFromIrp fFsRtlGetEcpListFromIrp
Definition: btrfs.c:95
NTSTATUS __stdcall compat_FsRtlValidateReparsePointBuffer(IN ULONG BufferLength, IN PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: fsrtl.c:32
return STATUS_SUCCESS
Definition: btrfs.c:3049
VOID(__stdcall * tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1825
ERESOURCE boot_lock
Definition: btrfs.c:109
void read_registry(PUNICODE_STRING regpath, bool refresh)
Definition: registry.c:770
#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 426 of file btrfs.c.

427  {
428  DIR_ITEM* xa = (DIR_ITEM*)item;
429  USHORT xasize;
430 
431  while (true) {
432  if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m + xa->n)) {
433  WARN("DIR_ITEM is truncated\n");
434  return false;
435  }
436 
437  if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name, xa->n) == xa->n) {
438  TRACE("found xattr %s\n", name);
439 
440  *datalen = xa->m;
441 
442  if (xa->m > 0) {
444  if (!*data) {
445  ERR("out of memory\n");
446  return false;
447  }
448 
449  RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
450  } else
451  *data = NULL;
452 
453  return true;
454  }
455 
456  xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
457 
458  if (size > xasize) {
459  size -= xasize;
460  xa = (DIR_ITEM*)&xa->name[xa->m + xa->n];
461  } else
462  break;
463  }
464 
465  TRACE("xattr %s not found\n", name);
466 
467  return false;
468 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define WARN(fmt,...)
Definition: debug.h:112
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1030
if(!r)
Definition: btrfs.c:2967
#define ALLOC_TAG
Definition: btrfs_drv.h:87
uint16_t m
Definition: btrfs.h:275
char name[1]
Definition: btrfs.h:278
#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:110
static ATOM item
Definition: dde.c:856
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
Definition: name.c:38
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint16_t n
Definition: btrfs.h:276
#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 3248 of file btrfs.c.

3248  {
3249  LIST_ENTRY* le;
3250 
3251  le = Vcb->devices.Flink;
3252 
3253  while (le != &Vcb->devices) {
3254  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3255 
3256  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
3257  InsertHeadList(le->Blink, &dev->list_entry);
3258  return;
3259  }
3260 
3261  le = le->Flink;
3262  }
3263 
3264  InsertTailList(&Vcb->devices, &dev->list_entry);
3265 }
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
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:3013
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint64_t dev_id
Definition: btrfs.h:178
Definition: typedefs.h:119
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:520
uint64_t dev_id

Referenced by find_device_from_uuid(), and load_chunk_root().

◆ calculate_sector_shift()

static void calculate_sector_shift ( device_extension Vcb)
static

Definition at line 4333 of file btrfs.c.

4333  {
4334  uint32_t ss = Vcb->superblock.sector_size;
4335 
4336  Vcb->sector_shift = 0;
4337 
4338  while (!(ss & 1)) {
4339  Vcb->sector_shift++;
4340  ss >>= 1;
4341  }
4342 }
InsertTailList & Vcb
Definition: btrfs.c:3013
UINT32 uint32_t
Definition: types.h:75
#define ss
Definition: i386-dis.c:434

Referenced by mount_vol().

◆ calculate_total_space()

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

Definition at line 618 of file btrfs.c.

618  {
619  uint64_t nfactor, dfactor, sectors_used;
620 
621  if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags & BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
622  nfactor = 1;
623  dfactor = 2;
624  } else if (Vcb->data_flags & BLOCK_FLAG_RAID5) {
625  nfactor = Vcb->superblock.num_devices - 1;
626  dfactor = Vcb->superblock.num_devices;
627  } else if (Vcb->data_flags & BLOCK_FLAG_RAID6) {
628  nfactor = Vcb->superblock.num_devices - 2;
629  dfactor = Vcb->superblock.num_devices;
630  } else if (Vcb->data_flags & BLOCK_FLAG_RAID1C3) {
631  nfactor = 1;
632  dfactor = 3;
633  } else if (Vcb->data_flags & BLOCK_FLAG_RAID1C4) {
634  nfactor = 1;
635  dfactor = 4;
636  } else {
637  nfactor = 1;
638  dfactor = 1;
639  }
640 
641  sectors_used = (Vcb->superblock.bytes_used >> Vcb->sector_shift) * nfactor / dfactor;
642 
643  *totalsize = (Vcb->superblock.total_bytes >> Vcb->sector_shift) * nfactor / dfactor;
644  *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
645 }
#define BLOCK_FLAG_RAID1C3
Definition: btrfs.h:87
#define BLOCK_FLAG_RAID10
Definition: shellext.h:81
InsertTailList & Vcb
Definition: btrfs.c:3013
#define BLOCK_FLAG_RAID6
Definition: shellext.h:83
#define BLOCK_FLAG_RAID1C4
Definition: btrfs.h:88
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:80
#define BLOCK_FLAG_RAID5
Definition: shellext.h:82
#define BLOCK_FLAG_RAID1
Definition: shellext.h:79

Referenced by _Dispatch_type_().

◆ check_file_name_valid()

NTSTATUS check_file_name_valid ( _In_ PUNICODE_STRING  us,
_In_ bool  posix,
_In_ bool  stream 
)

Definition at line 5766 of file btrfs.c.

5766  {
5767  ULONG i;
5768 
5769  if (us->Length < sizeof(WCHAR))
5771 
5772  if (us->Length > 255 * sizeof(WCHAR))
5774 
5775  for (i = 0; i < us->Length / sizeof(WCHAR); i++) {
5776  if (us->Buffer[i] == '/' || us->Buffer[i] == 0 ||
5777  (!posix && (us->Buffer[i] == '/' || us->Buffer[i] == ':')) ||
5778  (!posix && !stream && (us->Buffer[i] == '<' || us->Buffer[i] == '>' || us->Buffer[i] == '"' ||
5779  us->Buffer[i] == '|' || us->Buffer[i] == '?' || us->Buffer[i] == '*' || (us->Buffer[i] >= 1 && us->Buffer[i] <= 31))))
5781 
5782  /* Don't allow unpaired surrogates ("WTF-16") */
5783 
5784  if ((us->Buffer[i] & 0xfc00) == 0xdc00 && (i == 0 || ((us->Buffer[i-1] & 0xfc00) != 0xd800)))
5786 
5787  if ((us->Buffer[i] & 0xfc00) == 0xd800 && (i == (us->Length / sizeof(WCHAR)) - 1 || ((us->Buffer[i+1] & 0xfc00) != 0xdc00)))
5789  }
5790 
5791  if (us->Buffer[0] == '.' && (us->Length == sizeof(WCHAR) || (us->Length == 2 * sizeof(WCHAR) && us->Buffer[1] == '.')))
5793 
5794  /* The Linux driver expects filenames with a maximum length of 255 bytes - make sure
5795  * that our UTF-8 length won't be longer than that. */
5796  if (us->Length >= 85 * sizeof(WCHAR)) {
5797  NTSTATUS Status;
5798  ULONG utf8len;
5799 
5800  Status = utf16_to_utf8(NULL, 0, &utf8len, us->Buffer, us->Length);
5801  if (!NT_SUCCESS(Status))
5802  return Status;
5803 
5804  if (utf8len > 255)
5806  else if (stream && utf8len > 250) // minus five bytes for "user."
5808  }
5809 
5810  return STATUS_SUCCESS;
5811 }
static const BYTE us[]
Definition: encode.c:689
NTSTATUS utf16_to_utf8(char *dest, ULONG dest_max, ULONG *dest_len, WCHAR *src, ULONG src_len)
Definition: btrfs.c:863
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
Status
Definition: gdiplustypes.h:24
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Definition: parse.h:22
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 STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3049

Referenced by create_snapshot(), create_stream(), create_subvol(), file_create(), find_file_in_dir(), rename_file_to_stream(), rename_stream(), set_link_information(), and set_rename_information().

◆ check_superblock_checksum()

bool check_superblock_checksum ( superblock sb)

Definition at line 2794 of file btrfs.c.

2794  {
2795  switch (sb->csum_type) {
2796  case CSUM_TYPE_CRC32C: {
2797  uint32_t crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
2798 
2799  if (crc32 == *((uint32_t*)sb->checksum))
2800  return true;
2801 
2802  WARN("crc32 was %08x, expected %08x\n", crc32, *((uint32_t*)sb->checksum));
2803 
2804  break;
2805  }
2806 
2807  case CSUM_TYPE_XXHASH: {
2808  uint64_t hash = XXH64(&sb->uuid, sizeof(superblock) - sizeof(sb->checksum), 0);
2809 
2810  if (hash == *((uint64_t*)sb->checksum))
2811  return true;
2812 
2813  WARN("superblock hash was %I64x, expected %I64x\n", hash, *((uint64_t*)sb->checksum));
2814 
2815  break;
2816  }
2817 
2818  case CSUM_TYPE_SHA256: {
2820 
2821  calc_sha256(hash, &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
2822 
2824  return true;
2825 
2826  WARN("superblock hash was invalid\n");
2827 
2828  break;
2829  }
2830 
2831  case CSUM_TYPE_BLAKE2: {
2833 
2834  blake2b(hash, sizeof(hash), &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
2835 
2837  return true;
2838 
2839  WARN("superblock hash was invalid\n");
2840 
2841  break;
2842  }
2843 
2844  default:
2845  WARN("unrecognized csum type %x\n", sb->csum_type);
2846  }
2847 
2848  return false;
2849 }
superblock * sb
Definition: btrfs.c:4230
#define CSUM_TYPE_BLAKE2
Definition: btrfs.h:135
void blake2b(void *out, size_t outlen, const void *in, size_t inlen)
Definition: blake2b-ref.c:237
#define WARN(fmt,...)
Definition: debug.h:112
#define CSUM_TYPE_CRC32C
Definition: btrfs.h:132
void calc_sha256(uint8_t *hash, const void *input, size_t len)
Definition: sha256.c:126
#define SHA256_HASH_SIZE
Definition: btrfs_drv.h:1239
uint16_t csum_type
Definition: btrfs.h:247
uint8_t checksum[32]
Definition: btrfs.h:224
#define CSUM_TYPE_XXHASH
Definition: btrfs.h:133
crc_func calc_crc32c
Definition: crc32c.c:23
BYTE uint8_t
Definition: msvideo1.c:66
XXH_PUBLIC_API unsigned long long XXH64(const void *input, size_t len, unsigned long long seed)
Definition: xxhash.c:555
#define CSUM_TYPE_SHA256
Definition: btrfs.h:134
UINT64 uint64_t
Definition: types.h:77
BTRFS_UUID uuid
Definition: btrfs.h:225
UINT32 uint32_t
Definition: types.h:75
#define crc32(crc, buf, len)
Definition: inflate.c:1081
#define BLAKE2_HASH_SIZE
Definition: btrfs_drv.h:1243
unsigned int ULONG
Definition: retypes.h:1
Definition: _hash_fun.h:40
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by device_still_valid(), is_device_part_of_mounted_btrfs_raid(), read_superblock(), still_has_superblock(), test_vol(), and verify_device().

◆ 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 5813 of file btrfs.c.

5813  {
5814  LIST_ENTRY* le;
5815  bool locked;
5816  range_lock* rl;
5817 
5818  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5819  if (!rl) {
5820  ERR("out of memory\n");
5821  return;
5822  }
5823 
5824  rl->start = start;
5825  rl->length = length;
5826  rl->thread = PsGetCurrentThread();
5827 
5828  while (true) {
5829  locked = false;
5830 
5831  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5832 
5833  le = c->range_locks.Flink;
5834  while (le != &c->range_locks) {
5836 
5837  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5838  locked = true;
5839  break;
5840  }
5841 
5842  le = le->Flink;
5843  }
5844 
5845  if (!locked) {
5846  InsertTailList(&c->range_locks, &rl->list_entry);
5847 
5848  ExReleaseResourceLite(&c->range_locks_lock);
5849  return;
5850  }
5851 
5852  KeClearEvent(&c->range_locks_event);
5853 
5854  ExReleaseResourceLite(&c->range_locks_lock);
5855 
5856  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, false, NULL);
5857  }
5858 }
uint64_t start
Definition: btrfs_drv.h:539
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
uint64_t length
Definition: btrfs_drv.h:540
#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
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
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:542
InsertTailList & Vcb
Definition: btrfs.c:3013
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:541
Definition: typedefs.h:119
#define ERR(fmt,...)
Definition: debug.h:110
GLuint start
Definition: gl.h:1545
Definition: list.h:27
#define NULL
Definition: types.h:112
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

Referenced by read_data(), and scrub_chunk_raid56_stripe_run().

◆ 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 5860 of file btrfs.c.

5860  {
5861  LIST_ENTRY* le;
5862 
5863  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5864 
5865  le = c->range_locks.Flink;
5866  while (le != &c->range_locks) {
5868 
5869  if (rl->start == start && rl->length == length) {
5871  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5872  break;
5873  }
5874 
5875  le = le->Flink;
5876  }
5877 
5878  KeSetEvent(&c->range_locks_event, 0, false);
5879 
5880  ExReleaseResourceLite(&c->range_locks_lock);
5881 }
uint64_t start
Definition: btrfs_drv.h:539
uint64_t length
Definition: btrfs_drv.h:540
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
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
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:542
InsertTailList & Vcb
Definition: btrfs.c:3013
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Definition: typedefs.h:119
GLuint start
Definition: gl.h:1545
Definition: list.h:27

Referenced by read_data(), and scrub_chunk_raid56_stripe_run().

◆ 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 fcb %p)\n", 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
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:384
UNICODE_STRING query_string
Definition: btrfs_drv.h:376
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_In_ PIRP Irp
Definition: csq.h:116
long LONG
Definition: pedump.c:60
#define UNUSED(x)
Definition: btrfs_drv.h:82
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define TRACE(s)
Definition: solgame.cpp:4
struct _fcb fcb
Definition: btrfs_drv.h:1355
KEVENT cleared_event
Definition: btrfs_drv.h:365
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:286
#define NULL
Definition: types.h:112
void free_fileref(_Inout_ file_ref *fr)
Definition: btrfs.c:1825
bool cancelling
Definition: btrfs_drv.h:366
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:383
return STATUS_SUCCESS
Definition: btrfs.c:3049
#define VPB_MOUNTED
Definition: iotypes.h:1807
struct _device_extension * Vcb
Definition: btrfs_drv.h:287
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
send_info * send
Definition: btrfs_drv.h:392

Referenced by _Dispatch_type_().

◆ create_calc_threads()

static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 4063 of file btrfs.c.

4063  {
4064  device_extension* Vcb = DeviceObject->DeviceExtension;
4065  OBJECT_ATTRIBUTES oa;
4066  ULONG i;
4067 
4068  Vcb->calcthreads.num_threads = get_num_of_processors();
4069 
4070  Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
4071  if (!Vcb->calcthreads.threads) {
4072  ERR("out of memory\n");
4074  }
4075 
4076  InitializeListHead(&Vcb->calcthreads.job_list);
4077  KeInitializeSpinLock(&Vcb->calcthreads.spinlock);
4078  KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, false);
4079 
4080  RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads);
4081 
4083 
4084  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
4085  NTSTATUS Status;
4086 
4087  Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
4088  Vcb->calcthreads.threads[i].number = i;
4089  KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, false);
4090 
4091  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, &oa, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
4092  if (!NT_SUCCESS(Status)) {
4093  ULONG j;
4094 
4095  ERR("PsCreateSystemThread returned %08lx\n", Status);
4096 
4097  for (j = 0; j < i; j++) {
4098  Vcb->calcthreads.threads[i].quit = true;
4099  }
4100 
4101  KeSetEvent(&Vcb->calcthreads.event, 0, false);
4102 
4103  return Status;
4104  }
4105  }
4106 
4107  return STATUS_SUCCESS;
4108 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4242
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define ALLOC_TAG
Definition: btrfs_drv.h:87
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:240
uint32_t get_num_of_processors()
Definition: btrfs.c:4049
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:3013
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:110
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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 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)
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:3049

Referenced by