ReactOS  0.4.15-dev-1377-ga59cecd
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 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   (BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE | BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID)
 
#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

NTSTATUS RtlStringCbVPrintfA (char *pszDest, size_t cbDest, const char *pszFormat, va_list argList)
 
 DEFINE_GUID (BtrfsBusInterface, 0x4d414874, 0x6865, 0x6761, 0x6d, 0x65, 0x83, 0x69, 0x17, 0x9a, 0x7d, 0x1d)
 
static NTSTATUS close_file (_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
 
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable (ULONG Version)
 
bool is_top_level (_In_ PIRP Irp)
 
 _Function_class_ (DRIVER_UNLOAD)
 
static bool get_last_inode (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_opt_ PIRP Irp)
 
 _Success_ (return)
 
 _Dispatch_type_ (IRP_MJ_CLOSE)
 
 _Dispatch_type_ (IRP_MJ_FLUSH_BUFFERS)
 
static void calculate_total_space (_In_ device_extension *Vcb, _Out_ uint64_t *totalsize, _Out_ uint64_t *freespace)
 
static bool lie_about_fs_type ()
 
NTSTATUS utf8_to_utf16 (WCHAR *dest, ULONG dest_max, ULONG *dest_len, char *src, ULONG src_len)
 
NTSTATUS utf16_to_utf8 (char *dest, ULONG dest_max, ULONG *dest_len, WCHAR *src, ULONG src_len)
 
 _Dispatch_type_ (IRP_MJ_QUERY_VOLUME_INFORMATION)
 
 _Function_class_ (IO_COMPLETION_ROUTINE)
 
NTSTATUS create_root (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ uint64_t id, _Out_ root **rootptr, _In_ bool no_tree, _In_ uint64_t offset, _In_opt_ PIRP Irp)
 
static NTSTATUS set_label (_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
 
 _Dispatch_type_ (IRP_MJ_SET_VOLUME_INFORMATION)
 
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)
 
uint64_t chunk_estimate_phys_size (device_extension *Vcb, chunk *c, uint64_t u)
 
NTSTATUS find_chunk_usage (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS load_sys_chunks (_In_ device_extension *Vcb)
 
_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))
 
 if (pnp_name.Buffer) ExFreePool(pnp_name.Buffer)
 
static bool still_has_superblock (_In_ PDEVICE_OBJECT device, _In_ PFILE_OBJECT fileobj)
 
static NTSTATUS mount_vol (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS verify_device (_In_ device_extension *Vcb, _Inout_ device *dev)
 
static NTSTATUS verify_volume (_In_ PDEVICE_OBJECT devobj)
 
 _Dispatch_type_ (IRP_MJ_FILE_SYSTEM_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_LOCK_CONTROL)
 
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)
 
bool is_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
 
bool have_sse2 = false
 
uint64_t num_reads = 0
 
LIST_ENTRY uid_map_list
 
LIST_ENTRY gid_map_list
 
LIST_ENTRY VcbList
 
ERESOURCE global_loading_lock
 
uint32_t debug_log_level = 0
 
uint32_t mount_compress = 0
 
uint32_t mount_compress_force = 0
 
uint32_t mount_compress_type = 0
 
uint32_t mount_zlib_level = 3
 
uint32_t mount_zstd_level = 3
 
uint32_t mount_flush_interval = 30
 
uint32_t mount_max_inline = 2048
 
uint32_t mount_skip_balance = 0
 
uint32_t mount_no_barrier = 0
 
uint32_t mount_no_trim = 0
 
uint32_t mount_clear_cache = 0
 
uint32_t mount_allow_degraded = 0
 
uint32_t mount_readonly = 0
 
uint32_t 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
 
uint64_t boot_subvol
 
_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)
 
UNICODE_STRING pnp_name
 
const GUIDguid
 
 Status = sync_read_phys(DeviceObject, NULL, superblock_addrs[0], to_read, (PUCHAR)sb, true)
 
DeviceObject Flags &pnp_name Buffer = NULL
 
end __pad0__
 

Macro Definition Documentation

◆ COMPAT_RO_SUPPORTED

◆ INCOMPAT_SUPPORTED

#define INCOMPAT_SUPPORTED
Value:
BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO | BTRFS_INCOMPAT_FLAGS_BIG_METADATA | BTRFS_INCOMPAT_FLAGS_RAID56 | \
BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA | BTRFS_INCOMPAT_FLAGS_NO_HOLES | \
BTRFS_INCOMPAT_FLAGS_COMPRESS_ZSTD | BTRFS_INCOMPAT_FLAGS_METADATA_UUID | BTRFS_INCOMPAT_FLAGS_RAID1C34)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:116
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:110
#define BTRFS_INCOMPAT_FLAGS_METADATA_UUID
Definition: btrfs.h:118
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:108
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:113
#define BTRFS_INCOMPAT_FLAGS_NO_HOLES
Definition: btrfs.h:117
#define BTRFS_INCOMPAT_FLAGS_RAID56
Definition: btrfs.h:115
#define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL
Definition: btrfs.h:109
#define BTRFS_INCOMPAT_FLAGS_RAID1C34
Definition: btrfs.h:119

Definition at line 57 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 607 of file btrfs.c.

Function Documentation

◆ _Dispatch_type_() [1/10]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 461 of file btrfs.c.

463  {
466  device_extension* Vcb = DeviceObject->DeviceExtension;
467  bool top_level;
468 
470 
471  TRACE("close\n");
472 
473  top_level = is_top_level(Irp);
474 
475  if (DeviceObject == master_devobj) {
476  TRACE("Closing file system\n");
478  goto end;
479  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
481  goto end;
482  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
484  goto end;
485  }
486 
488 
489  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
490 
492 
493 end:
494  Irp->IoStatus.Status = Status;
495  Irp->IoStatus.Information = 0;
496 
498 
499  if (top_level)
501 
502  TRACE("returning %08lx\n", Status);
503 
505 
506  return Status;
507 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_DISK_INCREMENT
Definition: iotypes.h:583
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:69
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2978
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
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:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
_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:1860
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:95
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ _Dispatch_type_() [2/10]

_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 509 of file btrfs.c.

511  {
515  fcb* fcb = FileObject->FsContext;
516  device_extension* Vcb = DeviceObject->DeviceExtension;
517  bool top_level;
518 
520 
521  TRACE("flush buffers\n");
522 
523  top_level = is_top_level(Irp);
524 
525  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
527  goto end;
528  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
530  goto end;
531  }
532 
533  if (!fcb) {
534  ERR("fcb was NULL\n");
536  goto end;
537  }
538 
539  if (fcb == Vcb->volume_fcb) {
541  goto end;
542  }
543 
545 
546  Irp->IoStatus.Information = 0;
547 
548  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
549 
551  Irp->IoStatus.Status = Status;
552 
553  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
554  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &Irp->IoStatus);
555 
556  if (fcb->Header.PagingIoResource) {
557  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
558  ExReleaseResourceLite(fcb->Header.PagingIoResource);
559  }
560 
561  Status = Irp->IoStatus.Status;
562  }
563 
564 end:
566 
567  TRACE("returning %08lx\n", Status);
568 
569  if (top_level)
571 
573 
574  return Status;
575 }
#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:4232
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:330
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
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:302
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
InsertTailList & Vcb
Definition: btrfs.c:2978
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:294
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1978
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:1690
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
_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:1683
#define IO_NO_INCREMENT
Definition: iotypes.h:581
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:1172
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ _Dispatch_type_() [3/10]

_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 925 of file btrfs.c.

927  {
930  ULONG BytesCopied = 0;
931  device_extension* Vcb = DeviceObject->DeviceExtension;
932  bool top_level;
933 
935 
936  TRACE("query volume information\n");
937  top_level = is_top_level(Irp);
938 
939  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
941  goto end;
942  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
944  goto end;
945  }
946 
948 
950 
951  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
953  {
954  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
955  bool overflow = false;
956 #ifndef __REACTOS__
957  static const WCHAR ntfs[] = L"NTFS";
958 #endif
959  static const WCHAR btrfs[] = L"Btrfs";
960  const WCHAR* fs_name;
961  ULONG fs_name_len, orig_fs_name_len;
962 
963 #ifndef __REACTOS__
964  if (Irp->RequestorMode == UserMode && lie_about_fs_type()) {
965  fs_name = ntfs;
966  orig_fs_name_len = fs_name_len = sizeof(ntfs) - sizeof(WCHAR);
967  } else {
968  fs_name = btrfs;
969  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
970  }
971 #else
972  fs_name = btrfs;
973  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
974 #endif
975 
976  TRACE("FileFsAttributeInformation\n");
977 
978  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
979  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
980  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
981  else
982  fs_name_len = 0;
983 
984  overflow = true;
985  }
986 
987  data->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_CASE_SENSITIVE_SEARCH |
992  if (Vcb->readonly)
993  data->FileSystemAttributes |= FILE_READ_ONLY_VOLUME;
994 
995  // should also be FILE_FILE_COMPRESSION when supported
996  data->MaximumComponentNameLength = 255; // FIXME - check
997  data->FileSystemNameLength = orig_fs_name_len;
998  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
999 
1000  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
1002  break;
1003  }
1004 
1006  {
1007  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
1008 
1009  TRACE("FileFsDeviceInformation\n");
1010 
1011  ffdi->DeviceType = FILE_DEVICE_DISK;
1012 
1013  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1014  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
1015  ExReleaseResourceLite(&Vcb->tree_lock);
1016 
1017  if (Vcb->readonly)
1019  else
1021 
1024 
1025  break;
1026  }
1027 
1029  {
1030  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1031 
1032  TRACE("FileFsFullSizeInformation\n");
1033 
1036  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1037  ffsi->BytesPerSector = 512;
1038 
1041 
1042  break;
1043  }
1044 
1046  {
1047  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
1048 
1049  TRACE("FileFsObjectIdInformation\n");
1050 
1051  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
1052  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
1053 
1056 
1057  break;
1058  }
1059 
1060  case FileFsSizeInformation:
1061  {
1062  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1063 
1064  TRACE("FileFsSizeInformation\n");
1065 
1067  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1068  ffsi->BytesPerSector = 512;
1069 
1072 
1073  break;
1074  }
1075 
1077  {
1078  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1080  bool overflow = false;
1081  ULONG label_len, orig_label_len;
1082 
1083  TRACE("FileFsVolumeInformation\n");
1084  TRACE("max length = %lu\n", IrpSp->Parameters.QueryVolume.Length);
1085 
1086  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1087 
1088  Status = utf8_to_utf16(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1089  if (!NT_SUCCESS(Status)) {
1090  ERR("utf8_to_utf16 returned %08lx\n", Status);
1091  ExReleaseResourceLite(&Vcb->tree_lock);
1092  break;
1093  }
1094 
1095  orig_label_len = label_len;
1096 
1097  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len) {
1098  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR))
1099  label_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_VOLUME_INFORMATION) + sizeof(WCHAR);
1100  else
1101  label_len = 0;
1102 
1103  overflow = true;
1104  }
1105 
1106  TRACE("label_len = %lu\n", label_len);
1107 
1108  ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
1109  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];
1110  ffvi.VolumeLabelLength = orig_label_len;
1111  ffvi.SupportsObjects = false;
1112 
1113  RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
1114 
1115  if (label_len > 0) {
1116  ULONG bytecount;
1117 
1118  Status = utf8_to_utf16(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1120  ERR("utf8_to_utf16 returned %08lx\n", Status);
1121  ExReleaseResourceLite(&Vcb->tree_lock);
1122  break;
1123  }
1124 
1125  TRACE("label = %.*S\n", (int)(label_len / sizeof(WCHAR)), data->VolumeLabel);
1126  }
1127 
1128  ExReleaseResourceLite(&Vcb->tree_lock);
1129 
1130  BytesCopied = sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len;
1132  break;
1133  }
1134 
1135 #ifndef __REACTOS__
1136 #ifdef _MSC_VER // not in mingw yet
1137  case FileFsSectorSizeInformation:
1138  {
1139  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1140 
1141  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
1142  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1143  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
1144  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1145  data->ByteOffsetForSectorAlignment = 0;
1146  data->ByteOffsetForPartitionAlignment = 0;
1147 
1148  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
1149 
1150  if (Vcb->trim && !Vcb->options.no_trim)
1151  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
1152 
1153  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
1155 
1156  break;
1157  }
1158 #endif
1159 #endif /* __REACTOS__ */
1160 
1161  default:
1163  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
1164  break;
1165  }
1166 
1168  Irp->IoStatus.Information = 0;
1169  else
1170  Irp->IoStatus.Information = BytesCopied;
1171 
1172 end:
1173  Irp->IoStatus.Status = Status;
1174 
1176 
1177  if (top_level)
1179 
1180  TRACE("query volume information returning %08lx\n", Status);
1181 
1183 
1184  return Status;
1185 }
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
struct _FILE_FS_FULL_SIZE_INFORMATION FILE_FS_FULL_SIZE_INFORMATION
struct _FILE_FS_OBJECTID_INFORMATION FILE_FS_OBJECTID_INFORMATION
#define FsRtlEnterFileSystem
NTSTATUS vol_query_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:336
#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:4232
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
#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:154
#define IO_DISK_INCREMENT
Definition: iotypes.h:583
_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
static bool lie_about_fs_type()
Definition: btrfs.c:615
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2978
Status
Definition: gdiplustypes.h:24
#define FILE_UNICODE_ON_DISK
Definition: from_kernel.h:235
#define TRACE(s)
Definition: solgame.cpp:4
LARGE_INTEGER VolumeCreationTime
Definition: winioctl.h:408
#define FILE_SUPPORTS_BLOCK_REFCOUNTING
Definition: btrfs_drv.h:150
#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:697
#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:727
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:577
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static const WCHAR L[]
Definition: oid.c:1250
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
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:2789
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
struct _FILE_FS_VOLUME_INFORMATION FILE_FS_VOLUME_INFORMATION
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:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
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 1379 of file btrfs.c.

1381  {
1383  device_extension* Vcb = DeviceObject->DeviceExtension;
1384  NTSTATUS Status;
1385  bool top_level;
1386 
1388 
1389  TRACE("set volume information\n");
1390 
1391  top_level = is_top_level(Irp);
1392 
1393  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1395  goto end;
1396  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1398  goto end;
1399  }
1400 
1402 
1403  if (Vcb->readonly) {
1405  goto end;
1406  }
1407 
1408  if (Vcb->removing || Vcb->locked) {
1410  goto end;
1411  }
1412 
1413  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1415  FIXME("STUB: FileFsControlInformation\n");
1416  break;
1417 
1419  TRACE("FileFsLabelInformation\n");
1420 
1421  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1422  break;
1423 
1425  FIXME("STUB: FileFsObjectIdInformation\n");
1426  break;
1427 
1428  default:
1429  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1430  break;
1431  }
1432 
1433 end:
1434  Irp->IoStatus.Status = Status;
1435  Irp->IoStatus.Information = 0;
1436 
1437  TRACE("returning %08lx\n", Status);
1438 
1440 
1441  if (top_level)
1443 
1445 
1446  return Status;
1447 }
#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:4232
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
_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:2978
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:697
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1324
#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:2789
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
NTSTATUS vol_set_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:342

◆ _Dispatch_type_() [5/10]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2374 of file btrfs.c.

2376  {
2377  NTSTATUS Status;
2380  device_extension* Vcb = DeviceObject->DeviceExtension;
2381  fcb* fcb = FileObject->FsContext;
2382  bool top_level;
2383 
2385 
2386  TRACE("cleanup\n");
2387 
2388  top_level = is_top_level(Irp);
2389 
2390  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2392  goto exit;
2393  } else if (DeviceObject == master_devobj) {
2394  TRACE("closing file system\n");
2396  goto exit;
2397  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2399  goto exit;
2400  }
2401 
2402  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2403  TRACE("FileObject %p already cleaned up\n", FileObject);
2405  goto exit;
2406  }
2407 
2408  if (!fcb) {
2409  ERR("fcb was NULL\n");
2411  goto exit;
2412  }
2413 
2415 
2416  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2417  // messages belonging to other devices.
2418 
2419  if (FileObject && FileObject->FsContext) {
2420  LONG oc;
2421  ccb* ccb;
2422  file_ref* fileref;
2423  bool locked = true;
2424 
2425  ccb = FileObject->FsContext2;
2426  fileref = ccb ? ccb->fileref : NULL;
2427 
2428  TRACE("cleanup called for FileObject %p\n", FileObject);
2429  TRACE("fileref %p, refcount = %li, open_count = %li\n", fileref, fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2430 
2431  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
2432 
2433  ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
2434 
2436 
2438 
2439  if (ccb)
2440  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2441 
2442  if (fileref) {
2443  oc = InterlockedDecrement(&fileref->open_count);
2444 #ifdef DEBUG_FCB_REFCOUNTS
2445  ERR("fileref %p: open_count now %i\n", fileref, oc);
2446 #endif
2447  }
2448 
2449  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2450  fileref->delete_on_close = true;
2451 
2452  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2453  fileref->delete_on_close = false;
2454 
2455  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2456  TRACE("unlocking volume\n");
2459  }
2460 
2461  if (ccb && ccb->reserving) {
2462  fcb->subvol->reserved = NULL;
2463  ccb->reserving = false;
2464  // FIXME - flush all of subvol's fcbs
2465  }
2466 
2467  if (fileref && (oc == 0 || (fileref->delete_on_close && fileref->posix_delete))) {
2468  if (!fcb->Vcb->removing) {
2469  if (oc == 0 && fileref->fcb->inode_item.st_nlink == 0 && fileref != fcb->Vcb->root_fileref &&
2470  fcb != fcb->Vcb->volume_fcb && !fcb->ads) { // last handle closed on POSIX-deleted file
2472 
2474 
2476  if (!NT_SUCCESS(Status)) {
2477  ERR("delete_fileref_fcb returned %08lx\n", Status);
2479  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2480  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2481  goto exit;
2482  }
2483 
2485 
2486  mark_fcb_dirty(fileref->fcb);
2487  } else if (fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2489 
2491 
2492  if (!fileref->fcb->ads || fileref->dc) {
2493  if (fileref->fcb->ads) {
2495  FILE_ACTION_REMOVED, &fileref->dc->name);
2496  } else
2498  }
2499 
2500  ExReleaseResourceLite(fcb->Header.Resource);
2501  locked = false;
2502 
2503  // fileref_lock needs to be acquired before fcb->Header.Resource
2504  ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
2505 
2506  Status = delete_fileref(fileref, FileObject, oc > 0 && fileref->posix_delete, Irp, &rollback);
2507  if (!NT_SUCCESS(Status)) {
2508  ERR("delete_fileref returned %08lx\n", Status);
2510  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2511  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2512  goto exit;
2513  }
2514 
2515  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2516 
2518  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && FileObject->SectionObjectPointer->DataSectionObject) {
2520 
2521  if (locked) {
2522  ExReleaseResourceLite(fcb->Header.Resource);
2523  locked = false;
2524  }
2525 
2526  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2527 
2528  if (!NT_SUCCESS(iosb.Status))
2529  ERR("CcFlushCache returned %08lx\n", iosb.Status);
2530 
2531  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2532  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
2533  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2534  }
2535 
2536  CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, false);
2537 
2538  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2539  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2540  }
2541  }
2542 
2543  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2545  }
2546 
2547  if (locked)
2548  ExReleaseResourceLite(fcb->Header.Resource);
2549 
2550  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2551 
2552  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2553  }
2554 
2556 
2557 exit:
2558  TRACE("returning %08lx\n", Status);
2559 
2560  Irp->IoStatus.Status = Status;
2561  Irp->IoStatus.Information = 0;
2562 
2564 
2565  if (top_level)
2567 
2569 
2570  return Status;
2571 }
struct _file_ref * parent
Definition: btrfs_drv.h:368
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1050
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
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1029
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:390
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:4232
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:367
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
#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:1449
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
bool posix_delete
Definition: btrfs_drv.h:361
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:635
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
_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:285
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:69
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
#define FILE_ACTION_REMOVED
void mark_fcb_dirty(_In_ fcb *fcb)
Definition: btrfs.c:1625
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:302
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
LONG refcount
Definition: btrfs_drv.h:366
FILE_LOCK lock
Definition: btrfs_drv.h:305
InsertTailList & Vcb
Definition: btrfs.c:2978
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:294
Status
Definition: gdiplustypes.h:24
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
uint64_t st_size
Definition: btrfs.h:282
#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:697
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1978
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1761
dir_child * dc
Definition: btrfs_drv.h:369
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define InterlockedDecrement
Definition: armddk.h:52
NTSTATUS vol_cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:348
fcb * fcb
Definition: btrfs_drv.h:357
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:1026
INODE_ITEM inode_item
Definition: btrfs_drv.h:303
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
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:1770
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:2150
#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:299
#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:1357
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
bool ads
Definition: btrfs_drv.h:341
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1683
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:2206
#define IO_NO_INCREMENT
Definition: iotypes.h:581
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
bool reserving
Definition: btrfs_drv.h:397
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:1172
SHARE_ACCESS share_access
Definition: btrfs_drv.h:309
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:399
return STATUS_SUCCESS
Definition: btrfs.c:3014
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2320
struct _device_extension * Vcb
Definition: btrfs_drv.h:298
UNICODE_STRING name
Definition: btrfs_drv.h:267
bool delete_on_close
Definition: btrfs_drv.h:360

◆ _Dispatch_type_() [6/10]

_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 5191 of file btrfs.c.

5193  {
5195  NTSTATUS Status;
5196  device_extension* Vcb = DeviceObject->DeviceExtension;
5197  bool top_level;
5198 
5200 
5201  TRACE("file system control\n");
5202 
5203  top_level = is_top_level(Irp);
5204 
5205  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5207  goto end;
5208  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
5210  goto end;
5211  }
5212 
5214 
5216 
5217  Irp->IoStatus.Information = 0;
5218 
5219  switch (IrpSp->MinorFunction) {
5220  case IRP_MN_MOUNT_VOLUME:
5221  TRACE("IRP_MN_MOUNT_VOLUME\n");
5222 
5224  break;
5225 
5226  case IRP_MN_KERNEL_CALL:
5227  TRACE("IRP_MN_KERNEL_CALL\n");
5228 
5229  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
5230  break;
5231 
5233  TRACE("IRP_MN_USER_FS_REQUEST\n");
5234 
5235  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
5236  break;
5237 
5238  case IRP_MN_VERIFY_VOLUME:
5239  TRACE("IRP_MN_VERIFY_VOLUME\n");
5240 
5242 
5243  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
5244  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
5245  Vcb->removing = true;
5246  ExReleaseResourceLite(&Vcb->tree_lock);
5247  }
5248 
5249  break;
5250 
5251  default:
5252  break;
5253  }
5254 
5255 end:
5256  TRACE("returning %08lx\n", Status);
5257 
5258  if (Irp) {
5259  Irp->IoStatus.Status = Status;
5260 
5262  }
5263 
5264  if (top_level)
5266 
5268 
5269  return Status;
5270 }
#define FsRtlEnterFileSystem
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, uint32_t type)
Definition: fsctl.c:4968
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
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:4384
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS vol_file_system_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:362
InsertTailList & Vcb
Definition: btrfs.c:2978
Status
Definition: gdiplustypes.h:24
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4383
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4382
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
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:4387
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:696
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:581
static NTSTATUS verify_volume(_In_ PDEVICE_OBJECT devobj)
Definition: btrfs.c:5132
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
#define VPB_MOUNTED
Definition: iotypes.h:1787
static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: btrfs.c:4322

◆ _Dispatch_type_() [7/10]

_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 5272 of file btrfs.c.

5274  {
5275  NTSTATUS Status;
5277  fcb* fcb = IrpSp->FileObject ? IrpSp->FileObject->FsContext : NULL;
5278  device_extension* Vcb = DeviceObject->DeviceExtension;
5279  bool top_level;
5280 
5282 
5283  top_level = is_top_level(Irp);
5284 
5285  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5287 
5288  Irp->IoStatus.Status = Status;
5290 
5291  goto exit;
5292  }
5293 
5294  TRACE("lock control\n");
5295 
5296  if (!fcb) {
5297  ERR("fcb was NULL\n");
5299  goto exit;
5300  }
5301 
5303 
5305 
5306  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
5307 
5308 exit:
5309  TRACE("returning %08lx\n", Status);
5310 
5311  if (top_level)
5313 
5315 
5316  return Status;
5317 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
_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:305
InsertTailList & Vcb
Definition: btrfs.c:2978
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:294
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static __inline FAST_IO_POSSIBLE fast_io_possible(fcb *fcb)
Definition: btrfs_drv.h:1690
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1153
#define ERR(fmt,...)
Definition: debug.h:110
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:3148
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
NTSTATUS vol_lock_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:368
#define NULL
Definition: types.h:112
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1683
#define IO_NO_INCREMENT
Definition: iotypes.h:581
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:1172
void exit(int exitcode)
Definition: _exit.c:33

◆ _Dispatch_type_() [8/10]

_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 5437 of file btrfs.c.

5439  {
5440  NTSTATUS Status;
5441  bool top_level;
5442  device_extension* Vcb = DeviceObject->DeviceExtension;
5443 
5445 
5446  TRACE("shutdown\n");
5447 
5448  top_level = is_top_level(Irp);
5449 
5450  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5452  goto end;
5453  }
5454 
5456 
5457  do_shutdown(Irp);
5458 
5459 end:
5460  Irp->IoStatus.Status = Status;
5461  Irp->IoStatus.Information = 0;
5462 
5464 
5465  if (top_level)
5467 
5469 
5470  return Status;
5471 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
_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:2978
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS vol_shutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:899
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
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:581
return STATUS_SUCCESS
Definition: btrfs.c:3014
void do_shutdown(PIRP Irp)
Definition: btrfs.c:5319

◆ _Dispatch_type_() [9/10]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5581 of file btrfs.c.

5583  {
5584  NTSTATUS Status;
5586  device_extension* Vcb = DeviceObject->DeviceExtension;
5587  bool top_level;
5588 
5589  // no need for FsRtlEnterFileSystem, as this only ever gets called in a system thread
5590 
5591  top_level = is_top_level(Irp);
5592 
5593  Irp->IoStatus.Information = 0;
5594 
5595  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5596  volume_device_extension* vde = DeviceObject->DeviceExtension;
5597 
5599  IrpSp->Parameters.Power.State.SystemState != PowerSystemWorking && vde->mounted_device) {
5601 
5602  /* If power state is about to go to sleep or hibernate, do a flush. We do this on IRP_MJ_QUERY_POWER
5603  * rather than IRP_MJ_SET_POWER because we know that the hard disks are still awake. */
5604 
5605  if (Vcb2) {
5606  ExAcquireResourceExclusiveLite(&Vcb2->tree_lock, true);
5607 
5608  if (Vcb2->need_write && !Vcb2->readonly) {
5609  TRACE("doing protective flush on power state change\n");
5610  Status = do_write(Vcb2, NULL);
5611  } else
5613 
5614  free_trees(Vcb2);
5615 
5616  if (!NT_SUCCESS(Status))
5617  ERR("do_write returned %08lx\n", Status);
5618 
5619  ExReleaseResourceLite(&Vcb2->tree_lock);
5620  }
5621  } else if (IrpSp->MinorFunction == IRP_MN_SET_POWER && IrpSp->Parameters.Power.Type == SystemPowerState &&
5622  IrpSp->Parameters.Power.State.SystemState == PowerSystemWorking && vde->mounted_device) {
5624 
5625  /* If waking up, make sure that the FS hasn't been changed while we've been out (e.g., by dual-boot Linux) */
5626 
5627  if (Vcb2) {
5628  PIO_WORKITEM work_item;
5629 
5630  work_item = IoAllocateWorkItem(DeviceObject);
5631  if (!work_item) {
5632  ERR("out of memory\n");
5633  } else
5634  IoQueueWorkItem(work_item, check_after_wakeup, DelayedWorkQueue, Vcb2);
5635  }
5636  }
5637 
5640  Status = PoCallDriver(vde->attached_device, Irp);
5641 
5642  goto exit;
5643  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5645 
5646  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5647 
5648  goto exit;
5649  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5650  bus_device_extension* bde = DeviceObject->DeviceExtension;
5651 
5654  Status = PoCallDriver(bde->attached_device, Irp);
5655 
5656  goto exit;
5657  }
5658 
5660  Irp->IoStatus.Status = STATUS_SUCCESS;
5661 
5662  Status = Irp->IoStatus.Status;
5663 
5665 
5667 
5668 exit:
5669  if (top_level)
5671 
5672  return Status;
5673 }
#define IRP_MN_QUERY_POWER
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7789
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:699
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
void free_trees(device_extension *Vcb)
Definition: treefuncs.c:794
InsertTailList & Vcb
Definition: btrfs.c:2978
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:697
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:884
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define IRP_MN_SET_POWER
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:888
#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:2789
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:857
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
_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:581
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7498
void exit(int exitcode)
Definition: _exit.c:33
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014

◆ _Dispatch_type_() [10/10]

_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5675 of file btrfs.c.

5677  {
5678  NTSTATUS Status;
5679  device_extension* Vcb = DeviceObject->DeviceExtension;
5680  bool top_level;
5681 
5683 
5684  top_level = is_top_level(Irp);
5685 
5686  Irp->IoStatus.Information = 0;
5687 
5688  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5689  volume_device_extension* vde = DeviceObject->DeviceExtension;
5690 
5692 
5694 
5695  goto exit;
5696  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5698 
5699  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5700 
5701  goto exit;
5702  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5703  bus_device_extension* bde = DeviceObject->DeviceExtension;
5704 
5706 
5708 
5709  goto exit;
5710  }
5711 
5712  Status = Irp->IoStatus.Status;
5714 
5715 exit:
5716  if (top_level)
5718 
5720 
5721  return Status;
5722 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
#define VCB_TYPE_FS
Definition: btrfs_drv.h:695
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:279
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:699
_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:2978
Status
Definition: gdiplustypes.h:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:888
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:857
#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:581
void exit(int exitcode)
Definition: _exit.c:33

◆ _Function_class_() [1/6]

_Function_class_ ( DRIVER_UNLOAD  )

Definition at line 288 of file btrfs.c.

289  {
290  UNICODE_STRING dosdevice_nameW;
291 
292  TRACE("(%p)\n", DriverObject);
293 
294  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
295  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
296 
297  IoDeleteSymbolicLink(&dosdevice_nameW);
298  IoDeleteDevice(DriverObject->DeviceObject);
299 
300  while (!IsListEmpty(&uid_map_list)) {
302  uid_map* um = CONTAINING_RECORD(le, uid_map, listentry);
303 
304  ExFreePool(um->sid);
305 
306  ExFreePool(um);
307  }
308 
309  while (!IsListEmpty(&gid_map_list)) {
311 
312  ExFreePool(gm->sid);
313  ExFreePool(gm);
314  }
315 
316  // FIXME - free volumes and their devpaths
317 
318 #ifdef _DEBUG
319  if (comfo)
320  ObDereferenceObject(comfo);
321 
322  if (log_handle)
323  ZwClose(log_handle);
324 #endif
325 
328 
329  if (log_device.Buffer)
331 
332  if (log_file.Buffer)
334 
335  if (registry_path.Buffer)
337 
338 #ifdef _DEBUG
339  ExDeleteResourceLite(&log_lock);
340 #endif
342 }
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:94
PSID sid
Definition: btrfs_drv.h:918
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UNICODE_STRING registry_path
Definition: btrfs.c:94
PSID sid
Definition: btrfs_drv.h:912
static const WCHAR dosdevice_name[]
Definition: btrfs.c:64
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:74
Definition: typedefs.h:119
ERESOURCE mapping_lock
Definition: btrfs.c:108
ERESOURCE global_loading_lock
Definition: btrfs.c:76
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
UNICODE_STRING log_device
Definition: btrfs.c:94
ERESOURCE pdo_list_lock
Definition: btrfs.c:108
LIST_ENTRY gid_map_list
Definition: btrfs.c:74
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ _Function_class_() [2/6]

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 1187 of file btrfs.c.

1188  {
1189  read_context* context = conptr;
1190 
1192 
1193  context->iosb = Irp->IoStatus;
1194  KeSetEvent(&context->Event, 0, false);
1195 
1197 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
Definition: http.c:7094
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:86

◆ _Function_class_() [3/6]

_Function_class_ ( IO_WORKITEM_ROUTINE  )

Definition at line 1578 of file btrfs.c.

1579  {
1580  notification_fcb* nf = con;
1581 
1583 
1584  ExAcquireResourceSharedLite(&nf->fileref->fcb->Vcb->tree_lock, TRUE); // protect us from fileref being reaped
1585 
1587 
1588  free_fileref(nf->fileref);
1589 
1590  ExReleaseResourceLite(&nf->fileref->fcb->Vcb->tree_lock);
1591 
1593 
1594  ExFreePool(nf);
1595 }
#define TRUE
Definition: types.h:120
PUNICODE_STRING stream
Definition: btrfs.c:1574
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
ULONG filter_match
Definition: btrfs.c:1572
_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:1489
#define UNUSED(x)
Definition: btrfs_drv.h:86
file_ref * fileref
Definition: btrfs.c:1571
PIO_WORKITEM work_item
Definition: btrfs.c:1575
ULONG action
Definition: btrfs.c:1573
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
fcb * fcb
Definition: btrfs_drv.h:357
void free_fileref(_Inout_ file_ref *fr)
Definition: btrfs.c:1786
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
struct _device_extension * Vcb
Definition: btrfs_drv.h:298
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ _Function_class_() [4/6]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 5989 of file btrfs.c.

5990  {
5991  KTIMER timer;
5992  LARGE_INTEGER delay;
5993 
5994  UNUSED(context);
5995 
5996  KeInitializeTimer(&timer);
5997 
5998  delay.QuadPart = -30000000; // wait three seconds
5999  KeSetTimer(&timer, delay, NULL);
6000  KeWaitForSingleObject(&timer, Executive, KernelMode, false, NULL);
6001 
6002  TRACE("timer expired\n");
6003 
6004  degraded_wait = false;
6005 
6008 
6010 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
Definition: http.c:7094
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
HANDLE degraded_wait_handle
Definition: btrfs.c:111
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:86
#define TRACE(s)
Definition: solgame.cpp:4
bool degraded_wait
Definition: btrfs.c:112
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
#define NULL
Definition: types.h:112
return STATUS_SUCCESS
Definition: btrfs.c:3014
LONGLONG QuadPart
Definition: typedefs.h:114

◆ _Function_class_() [5/6]

_Function_class_ ( DRIVER_ADD_DEVICE  )

Definition at line 6012 of file btrfs.c.

6013  {
6014  LIST_ENTRY* le;
6015  NTSTATUS Status;
6016  UNICODE_STRING volname;
6017  ULONG i;
6018  WCHAR* s;
6019  pdo_device_extension* pdode = NULL;
6020  PDEVICE_OBJECT voldev;
6022  UNICODE_STRING arc_name_us;
6023  WCHAR* anp;
6024 
6025  static const WCHAR arc_name_prefix[] = L"\\ArcName\\btrfs(";
6026 
6027  WCHAR arc_name[(sizeof(arc_name_prefix) / sizeof(WCHAR)) - 1 + 37];
6028 
6029  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
6030 
6032 
6033  le = pdo_list.Flink;
6034  while (le != &pdo_list) {
6036 
6037  if (pdode2->pdo == PhysicalDeviceObject) {
6038  pdode = pdode2;
6039  break;
6040  }
6041 
6042  le = le->Flink;
6043  }
6044 
6045  if (!pdode) {
6046  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
6048  goto end;
6049  }
6050 
6052 
6053  if (pdode->vde) { // if already done, return success
6055  goto end2;
6056  }
6057 
6058  volname.Length = volname.MaximumLength = (sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR)) + ((36 + 1) * sizeof(WCHAR));
6059  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
6060 
6061  if (!volname.Buffer) {
6062  ERR("out of memory\n");
6064  goto end2;
6065  }
6066 
6067  RtlCopyMemory(volname.Buffer, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR));
6068  RtlCopyMemory(arc_name, arc_name_prefix, sizeof(arc_name_prefix) - sizeof(WCHAR));
6069 
6070  anp = &arc_name[(sizeof(arc_name_prefix) / sizeof(WCHAR)) - 1];
6071  s = &volname.Buffer[(sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1];
6072 
6073  for (i = 0; i < 16; i++) {
6074  *s = *anp = hex_digit(pdode->uuid.uuid[i] >> 4);
6075  s++;
6076  anp++;
6077 
6078  *s = *anp = hex_digit(pdode->uuid.uuid[i] & 0xf);
6079  s++;
6080  anp++;
6081 
6082  if (i == 3 || i == 5 || i == 7 || i == 9) {
6083  *s = *anp = '-';
6084  s++;
6085  anp++;
6086  }
6087  }
6088 
6089  *s = '}';
6090  *anp = ')';
6091 
6094  if (!NT_SUCCESS(Status)) {
6095  ERR("IoCreateDevice returned %08lx\n", Status);
6096  goto end2;
6097  }
6098 
6099  arc_name_us.Buffer = arc_name;
6100  arc_name_us.Length = arc_name_us.MaximumLength = sizeof(arc_name);
6101 
6102  Status = IoCreateSymbolicLink(&arc_name_us, &volname);
6103  if (!NT_SUCCESS(Status))
6104  WARN("IoCreateSymbolicLink returned %08lx\n", Status);
6105 
6106  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
6107  voldev->Flags |= DO_DIRECT_IO;
6108 
6109  vde = voldev->DeviceExtension;
6110  vde->type = VCB_TYPE_VOLUME;
6111  vde->name = volname;
6112  vde->device = voldev;
6113  vde->mounted_device = NULL;
6114  vde->pdo = PhysicalDeviceObject;
6115  vde->pdode = pdode;
6116  vde->removing = false;
6117  vde->dead = false;
6118  vde->open_count = 0;
6119 
6120  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
6121  if (!NT_SUCCESS(Status))
6122  WARN("IoRegisterDeviceInterface returned %08lx\n", Status);
6123 
6125 
6126  pdode->vde = vde;
6127 
6128  if (pdode->removable)
6129  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
6130 
6131  if (RtlCompareMemory(&boot_uuid, &pdode->uuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
6132  voldev->Flags |= DO_SYSTEM_BOOT_PARTITION;
6134  }
6135 
6136  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
6137 
6138  Status = IoSetDeviceInterfaceState(&vde->bus_name, true);
6139  if (!NT_SUCCESS(Status))
6140  WARN("IoSetDeviceInterfaceState returned %08lx\n", Status);
6141 
6143 
6144 end2:
6146 
6147 end:
6149 
6150  return Status;
6151 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1794
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
return STATUS_NOT_SUPPORTED
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
USHORT MaximumLength
Definition: env_spec_w32.h:370
PDEVICE_OBJECT device
Definition: btrfs_drv.h:883
#define WARN(fmt,...)
Definition: debug.h:112
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:885
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1155
#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:882
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:898
#define ALLOC_TAG
Definition: btrfs_drv.h:91
UNICODE_STRING bus_name
Definition: btrfs_drv.h:887
BTRFS_UUID boot_uuid
Definition: boot.c:33
#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
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:886
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:109
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BTRFS_VOLUME_PREFIX
Definition: btrfs_drv.h:131
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:697
ERESOURCE child_lock
Definition: btrfs_drv.h:904
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:884
GLuint GLuint end
Definition: gl.h:1545
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:68
static const WCHAR L[]
Definition: oid.c:1250
GLdouble s
Definition: gl.h:2039
Definition: typedefs.h:119
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:888
#define ERR(fmt,...)
Definition: debug.h:110
uint8_t uuid[16]
Definition: btrfs.h:133
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:158
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:108
volume_device_extension * vde
Definition: btrfs_drv.h:897
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
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

◆ _Function_class_() [6/6]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 6153 of file btrfs.c.

6154  {
6155  NTSTATUS Status;
6157  UNICODE_STRING device_nameW;
6158  UNICODE_STRING dosdevice_nameW;
6160  bus_device_extension* bde;
6161  HANDLE regh;
6162  OBJECT_ATTRIBUTES oa, system_thread_attributes;
6163  ULONG dispos;
6164 
6167 
6168 #ifdef _DEBUG
6169  ExInitializeResourceLite(&log_lock);
6170 #endif
6172 
6175  log_file.Buffer = NULL;
6177 
6180 
6181  if (!registry_path.Buffer) {
6182  ERR("out of memory\n");
6184  }
6185 
6187 
6188  read_registry(&registry_path, false);
6189 
6190 #ifdef _DEBUG
6191  if (debug_log_level > 0)
6192  init_logging();
6193 
6194  log_started = true;
6195 #endif
6196 
6197  TRACE("DriverEntry\n");
6198 
6199 #if !defined(__REACTOS__) && (defined(_X86_) || defined(_AMD64_))
6200  check_cpu();
6201 #endif
6202 
6205  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
6206 
6207  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
6208  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
6209 
6210  if (fPsIsDiskCountersEnabled) {
6211  diskacc = fPsIsDiskCountersEnabled();
6212 
6213  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
6215 
6216  if (!fPsUpdateDiskCounters)
6217  diskacc = false;
6218 
6219  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
6221  }
6222 
6223  RtlInitUnicodeString(&name, L"CcCopyReadEx");
6225 
6226  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
6228 
6229  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
6231 
6232  RtlInitUnicodeString(&name, L"FsRtlCheckLockForOplockRequest");
6234  } else {
6236  fCcCopyReadEx = NULL;
6237  fCcCopyWriteEx = NULL;
6241  }
6242 
6245 
6246  RtlInitUnicodeString(&name, L"IoUnregisterPlugPlayNotificationEx");
6248 
6249  RtlInitUnicodeString(&name, L"FsRtlAreThereCurrentOrInProgressFileLocks");
6251  } else {
6254  }
6255 
6258 
6259  RtlInitUnicodeString(&name, L"FsRtlGetEcpListFromIrp");
6261 
6262  RtlInitUnicodeString(&name, L"FsRtlGetNextExtraCreateParameter");
6264 
6265  RtlInitUnicodeString(&name, L"FsRtlValidateReparsePointBuffer");
6267  } else {
6271  }
6272 
6273  drvobj = DriverObject;
6274 
6276 
6277  DriverObject->DriverExtension->AddDevice = AddDevice;
6278 
6279  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
6280  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
6281  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
6282  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
6283  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
6284  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
6285  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
6286  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
6287  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
6288  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
6289  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
6290  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
6291  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
6292  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
6293  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
6294  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
6295  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
6296  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
6297  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
6298  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
6299  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
6300  DriverObject->MajorFunction[IRP_MJ_PNP] = drv_pnp;
6301 
6302  init_fast_io_dispatch(&DriverObject->FastIoDispatch);
6303 
6304  device_nameW.Buffer = (WCHAR*)device_name;
6305  device_nameW.Length = device_nameW.MaximumLength = sizeof(device_name) - sizeof(WCHAR);
6306  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
6307  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
6308 
6311  if (!NT_SUCCESS(Status)) {
6312  ERR("IoCreateDevice returned %08lx\n", Status);
6313  return Status;
6314  }
6315 
6318 
6320 
6321  cde->type = VCB_TYPE_CONTROL;
6322 
6324 
6325  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
6326  if (!NT_SUCCESS(Status)) {
6327  ERR("IoCreateSymbolicLink returned %08lx\n", Status);
6328  return Status;
6329  }
6330 
6331  init_cache();
6332 
6336 
6338 
6341  if (!NT_SUCCESS(Status)) {
6342  ERR("ZwCreateKey returned %08lx\n", Status);
6343  return Status;
6344  }
6345 
6346  watch_registry(regh);
6347 
6349  FILE_DEVICE_SECURE_OPEN, false, &busobj);
6350  if (!NT_SUCCESS(Status)) {
6351  ERR("IoCreateDevice returned %08lx\n", Status);
6352  return Status;
6353  }
6354 
6356 
6357  RtlZeroMemory(bde, sizeof(bus_device_extension));
6358 
6359  bde->type = VCB_TYPE_BUS;
6360 
6361  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
6362  NULL, NULL, 0, &bde->buspdo);
6363  if (!NT_SUCCESS(Status)) {
6364  ERR("IoReportDetectedDevice returned %08lx\n", Status);
6365  return Status;
6366  }
6367 
6368  Status = IoRegisterDeviceInterface(bde->buspdo, &BtrfsBusInterface, NULL, &bde->bus_name);
6369  if (!NT_SUCCESS(Status))
6370  WARN("IoRegisterDeviceInterface returned %08lx\n", Status);
6371 
6373 
6375 
6376  Status = IoSetDeviceInterfaceState(&bde->bus_name, true);
6377  if (!NT_SUCCESS(Status))
6378  WARN("IoSetDeviceInterfaceState returned %08lx\n", Status);
6379 
6381 
6382  InitializeObjectAttributes(&system_thread_attributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
6383 
6384  Status = PsCreateSystemThread(&degraded_wait_handle, 0, &system_thread_attributes, NULL, NULL, degraded_wait_thread, NULL);
6385  if (!NT_SUCCESS(Status))
6386  WARN("PsCreateSystemThread returned %08lx\n", Status);
6387 
6389 
6391  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
6392  if (!NT_SUCCESS(Status))
6393  ERR("IoRegisterPlugPlayNotification returned %08lx\n", Status);
6394 
6396  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
6397  if (!NT_SUCCESS(Status))
6398  ERR("IoRegisterPlugPlayNotification returned %08lx\n", Status);
6399 
6401  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
6402  if (!NT_SUCCESS(Status))
6403  ERR("IoRegisterPlugPlayNotification returned %08lx\n", Status);
6404 
6405  finished_probing = true;
6406 
6408 
6409  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, &system_thread_attributes, NULL, NULL, mountmgr_thread, NULL);
6410  if (!NT_SUCCESS(Status))
6411  WARN("PsCreateSystemThread returned %08lx\n", Status);
6412 
6414 
6416 
6417  return STATUS_SUCCESS;
6418 }
VOID(__stdcall * tFsRtlUpdateDiskCounters)(ULONG64 BytesRead, ULONG64 BytesWritten)
Definition: btrfs_drv.h:1901
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
tFsRtlCheckLockForOplockRequest fFsRtlCheckLockForOplockRequest
Definition: btrfs.c:104
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:856
#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:486
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
bool finished_probing
Definition: btrfs.c:110
#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:1907
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IRP_MJ_SHUTDOWN
void * notification_entry3
Definition: btrfs.c:107
DRIVER_ADD_DEVICE AddDevice
Definition: parport.h:72
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:96
HANDLE degraded_wait_handle
Definition: btrfs.c:111
LIST_ENTRY VcbList
Definition: btrfs.c:75
#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:63
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4232
UNICODE_STRING log_file
Definition: btrfs.c:94
tFsRtlValidateReparsePointBuffer fFsRtlValidateReparsePointBuffer
Definition: btrfs.c:103
tFsRtlAreThereCurrentOrInProgressFileLocks fFsRtlAreThereCurrentOrInProgressFileLocks
Definition: btrfs.c:105
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1219
void watch_registry(HANDLE regh)
Definition: registry.c:1028
void * notification_entry2
Definition: btrfs.c:107
bool diskacc
Definition: btrfs.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
uint32_t debug_log_level
Definition: btrfs.c:77
UNICODE_STRING bus_name
Definition: btrfs_drv.h:858
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:699
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:95
#define ALLOC_TAG
Definition: btrfs_drv.h:91
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
UNICODE_STRING registry_path
Definition: btrfs.c:94
NTSTATUS NTAPI IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject, IN INTERFACE_TYPE LegacyBusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PCM_RESOURCE_LIST ResourceList, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL, IN BOOLEAN ResourceAssigned, IN OUT PDEVICE_OBJECT *DeviceObject OPTIONAL)
Definition: pnpreport.c:156
HANDLE mountmgr_thread_handle
Definition: btrfs.c:111
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3432
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:1887
static const WCHAR dosdevice_name[]
Definition: btrfs.c:64
#define IRP_MJ_SET_EA
NTSTATUS(__stdcall * tFsRtlGetEcpListFromIrp)(PIRP Irp, PECP_LIST *EcpList)
Definition: btrfs_drv.h:1905
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:69
PVOID DeviceExtension
Definition: env_spec_w32.h:418
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:99
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
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
tCcCopyWriteEx fCcCopyWriteEx
Definition: btrfs.c:97
void __stdcall check_system_root(PDRIVER_OBJECT DriverObject, PVOID Context, ULONG Count)
Definition: boot.c:470
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:107
BOOLEAN(__stdcall * tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1884
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:109
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define NTDDI_WIN7
Definition: sdkddkver.h:112
BOOLEAN(__stdcall * tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1879
BOOLEAN(__stdcall * tFsRtlAreThereCurrentOrInProgressFileLocks)(PFILE_LOCK FileLock)
Definition: btrfs_drv.h:1914
VOID NTAPI IoRegisterBootDriverReinitialization(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
Definition: driver.c:1736
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:68
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:98
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2268
NTSTATUS(__stdcall * tFsRtlValidateReparsePointBuffer)(ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: btrfs_drv.h:1910
LIST_ENTRY uid_map_list
Definition: btrfs.c:74
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
PDEVICE_OBJECT busobj
Definition: btrfs.c:69
#define IRP_MJ_SYSTEM_CONTROL
tFsRtlGetNextExtraCreateParameter fFsRtlGetNextExtraCreateParameter
Definition: btrfs.c:102
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:696
ERESOURCE mapping_lock
Definition: btrfs.c:108
ERESOURCE global_loading_lock
Definition: btrfs.c:76
#define ERR(fmt,...)
Definition: debug.h:110
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:857
NTSTATUS(__stdcall * tIoUnregisterPlugPlayNotificationEx)(PVOID NotificationEntry)
Definition: btrfs_drv.h:1903
void init_cache()
Definition: cache.c:85
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:2486
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NTDDI_VISTA
Definition: sdkddkver.h:103
tIoUnregisterPlugPlayNotificationEx fIoUnregisterPlugPlayNotificationEx
Definition: btrfs.c:100
BOOLEAN(__stdcall * tFsRtlCheckLockForOplockRequest)(PFILE_LOCK FileLock, PLARGE_INTEGER AllocationSize)
Definition: btrfs_drv.h:1912
KEVENT mountmgr_thread_event
Definition: btrfs.c:113
#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:94
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:139
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
ERESOURCE pdo_list_lock
Definition: btrfs.c:108
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
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:93
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
VOID(__stdcall * tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1899
#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:74
#define NTDDI_WIN8
Definition: sdkddkver.h:113
tFsRtlGetEcpListFromIrp fFsRtlGetEcpListFromIrp
Definition: btrfs.c:101
NTSTATUS __stdcall compat_FsRtlValidateReparsePointBuffer(IN ULONG BufferLength, IN PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: fsrtl.c:32
return STATUS_SUCCESS
Definition: btrfs.c:3014
VOID(__stdcall * tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1881
ERESOURCE boot_lock
Definition: btrfs.c:115
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 385 of file btrfs.c.

386  {
387  DIR_ITEM* xa = (DIR_ITEM*)item;
388  USHORT xasize;
389 
390  while (true) {
391  if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m + xa->n)) {
392  WARN("DIR_ITEM is truncated\n");
393  return false;
394  }
395 
396  if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name, xa->n) == xa->n) {
397  TRACE("found xattr %s\n", name);
398 
399  *datalen = xa->m;
400 
401  if (xa->m > 0) {
403  if (!*data) {
404  ERR("out of memory\n");
405  return false;
406  }
407 
408  RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
409  } else
410  *data = NULL;
411 
412  return true;
413  }
414 
415  xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
416 
417  if (size > xasize) {
418  size -= xasize;
419  xa = (DIR_ITEM*)&xa->name[xa->m + xa->n];
420  } else
421  break;
422  }
423 
424  TRACE("xattr %s not found\n", name);
425 
426  return false;
427 }
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:2932
#define ALLOC_TAG
Definition: btrfs_drv.h:91
uint16_t m
Definition: btrfs.h:268
char name[1]
Definition: btrfs.h:271
#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:269
#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 3212 of file btrfs.c.

3212  {
3213  LIST_ENTRY* le;
3214 
3215  le = Vcb->devices.Flink;
3216 
3217  while (le != &Vcb->devices) {
3218  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3219 
3220  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
3221  InsertHeadList(le->Blink, &dev->list_entry);
3222  return;
3223  }
3224 
3225  le = le->Flink;
3226  }
3227 
3228  InsertTailList(&Vcb->devices, &dev->list_entry);
3229 }
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:2978
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint64_t dev_id
Definition: btrfs.h:171
Definition: typedefs.h:119
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:536
uint64_t dev_id

Referenced by find_device_from_uuid(), and load_chunk_root().

◆ calculate_total_space()

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

Definition at line 577 of file btrfs.c.

577  {
578  uint64_t nfactor, dfactor, sectors_used;
579 
580  if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags & BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
581  nfactor = 1;
582  dfactor = 2;
583  } else if (Vcb->data_flags & BLOCK_FLAG_RAID5) {
584  nfactor = Vcb->superblock.num_devices - 1;
585  dfactor = Vcb->superblock.num_devices;
586  } else if (Vcb->data_flags & BLOCK_FLAG_RAID6) {
587  nfactor = Vcb->superblock.num_devices - 2;
588  dfactor = Vcb->superblock.num_devices;
589  } else if (Vcb->data_flags & BLOCK_FLAG_RAID1C3) {
590  nfactor = 1;
591  dfactor = 3;
592  } else if (Vcb->data_flags & BLOCK_FLAG_RAID1C4) {
593  nfactor = 1;
594  dfactor = 4;
595  } else {
596  nfactor = 1;
597  dfactor = 1;
598  }
599 
600  sectors_used = (Vcb->superblock.bytes_used / Vcb->superblock.sector_size) * nfactor / dfactor;
601 
602  *totalsize = (Vcb->superblock.total_bytes / Vcb->superblock.sector_size) * nfactor / dfactor;
603  *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
604 }
#define freespace(fs, percentreserved)
Definition: fs.h:640
#define BLOCK_FLAG_RAID1C3
Definition: btrfs.h:83
#define BLOCK_FLAG_RAID10
Definition: shellext.h:81
InsertTailList & Vcb
Definition: btrfs.c:2978
#define BLOCK_FLAG_RAID6
Definition: shellext.h:83
#define BLOCK_FLAG_RAID1C4
Definition: btrfs.h:84
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_superblock_checksum()

bool check_superblock_checksum ( superblock sb)

Definition at line 2761 of file btrfs.c.

2761  {
2762  switch (sb->csum_type) {
2763  case CSUM_TYPE_CRC32C: {
2764  uint32_t crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum));
2765 
2766  if (crc32 == *((uint32_t*)sb->checksum))
2767  return true;
2768 
2769  WARN("crc32 was %08x, expected %08x\n", crc32, *((uint32_t*)sb->checksum));
2770 
2771  break;
2772  }
2773 
2774  case CSUM_TYPE_XXHASH: {
2775  uint64_t hash = XXH64(&sb->uuid, sizeof(superblock) - sizeof(sb->checksum), 0);
2776 
2777  if (hash == *((uint64_t*)sb->checksum))
2778  return true;
2779 
2780  WARN("superblock hash was %I64x, expected %I64x\n", hash, *((uint64_t*)sb->checksum));
2781 
2782  break;
2783  }
2784 
2785  case CSUM_TYPE_SHA256: {
2787 
2788  calc_sha256(hash, &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
2789 
2791  return true;
2792 
2793  WARN("superblock hash was invalid\n");
2794 
2795  break;
2796  }
2797 
2798  case CSUM_TYPE_BLAKE2: {
2800 
2801  blake2b(hash, sizeof(hash), &sb->uuid, sizeof(superblock) - sizeof(sb->checksum));
2802 
2804  return true;
2805 
2806  WARN("superblock hash was invalid\n");
2807 
2808  break;
2809  }
2810 
2811  default:
2812  WARN("unrecognized csum type %x\n", sb->csum_type);
2813  }
2814 
2815  return false;
2816 }
superblock * sb
Definition: btrfs.c:4220
#define CSUM_TYPE_BLAKE2
Definition: btrfs.h:128
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:125
void calc_sha256(uint8_t *hash, const void *input, size_t len)
Definition: sha256.c:126
#define SHA256_HASH_SIZE
Definition: btrfs_drv.h:1248
uint16_t csum_type
Definition: btrfs.h:240
uint8_t checksum[32]
Definition: btrfs.h:217
#define CSUM_TYPE_XXHASH
Definition: btrfs.h:126
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:127
UINT64 uint64_t
Definition: types.h:77
BTRFS_UUID uuid
Definition: btrfs.h:218
UINT32 uint32_t
Definition: types.h:75
#define crc32(crc, buf, len)
Definition: inflate.c:1081
#define BLAKE2_HASH_SIZE
Definition: btrfs_drv.h:1252
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_estimate_phys_size()

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

Definition at line 3809 of file btrfs.c.

3809  {
3810  uint64_t nfactor, dfactor;
3811 
3812  if (c->chunk_item->type & BLOCK_FLAG_DUPLICATE || c->chunk_item->type & BLOCK_FLAG_RAID1 || c->chunk_item->type & BLOCK_FLAG_RAID10) {
3813  nfactor = 1;
3814  dfactor = 2;
3815  } else if (c->chunk_item->type & BLOCK_FLAG_RAID5) {
3816  nfactor = Vcb->superblock.num_devices - 1;
3817  dfactor = Vcb->superblock.num_devices;
3818  } else if (c->chunk_item->type & BLOCK_FLAG_RAID6) {
3819  nfactor = Vcb->superblock.num_devices - 2;
3820  dfactor = Vcb->superblock.num_devices;
3821  } else if (c->chunk_item->type & BLOCK_FLAG_RAID1C3) {
3822  nfactor = 1;
3823  dfactor = 3;
3824  } else if (c->chunk_item->type & BLOCK_FLAG_RAID1C4) {
3825  nfactor = 1;
3826  dfactor = 4;
3827  } else {
3828  nfactor = 1;
3829  dfactor = 1;
3830  }
3831 
3832  return u * dfactor / nfactor;
3833 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define BLOCK_FLAG_RAID1C3
Definition: btrfs.h:83
#define BLOCK_FLAG_RAID10
Definition: shellext.h:81
InsertTailList & Vcb
Definition: btrfs.c:2978
const GLubyte * c
Definition: glext.h:8905
#define BLOCK_FLAG_RAID6
Definition: shellext.h:83
#define BLOCK_FLAG_RAID1C4
Definition: btrfs.h:84
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 create_chunk(), drop_chunk(), find_chunk_usage(), and update_chunk_usage().

◆ chunk_lock_range()

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

Definition at line 5747 of file btrfs.c.

5747  {
5748  LIST_ENTRY* le;
5749  bool locked;
5750  range_lock* rl;
5751 
5752  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5753  if (!rl) {
5754  ERR("out of memory\n");
5755  return;
5756  }
5757 
5758  rl->start = start;
5759  rl->length = length;
5760  rl->thread = PsGetCurrentThread();
5761 
5762  while (true) {
5763  locked = false;
5764 
5765  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5766 
5767  le = c->range_locks.Flink;
5768  while (le != &c->range_locks) {
5770 
5771  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5772  locked = true;
5773  break;
5774  }
5775 
5776  le = le->Flink;
5777  }
5778 
5779  if (!locked) {
5780  InsertTailList(&c->range_locks, &rl->list_entry);
5781 
5782  ExReleaseResourceLite(&c->range_locks_lock);
5783  return;
5784  }
5785 
5786  KeClearEvent(&c->range_locks_event);
5787 
5788  ExReleaseResourceLite(&c->range_locks_lock);
5789 
5790  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, false, NULL);
5791  }
5792 }
uint64_t start
Definition: btrfs_drv.h:555
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
uint64_t length
Definition: btrfs_drv.h:556
#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:558
InsertTailList & Vcb
Definition: btrfs.c:2978
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:557
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(), scrub_chunk_raid56_stripe_run(), and write_data_complete().

◆ chunk_unlock_range()

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

Definition at line 5794 of file btrfs.c.

5794  {
5795  LIST_ENTRY* le;
5796 
5797  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5798 
5799  le = c->range_locks.Flink;
5800  while (le != &c->range_locks) {
5802 
5803  if (rl->start == start && rl->length == length) {
5805  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5806  break;
5807  }
5808 
5809  le = le->Flink;
5810  }
5811 
5812  KeSetEvent(&c->range_locks_event, 0, false);
5813 
5814  ExReleaseResourceLite(&c->range_locks_lock);
5815 }
uint64_t start
Definition: btrfs_drv.h:555
uint64_t length
Definition: btrfs_drv.h:556
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:558
InsertTailList & Vcb
Definition: btrfs.c:2978
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(), scrub_chunk_raid56_stripe_run(), and write_data_complete().

◆ close_file()

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

Definition at line 1860 of file btrfs.c.

1860  {
1861  fcb* fcb;
1862  ccb* ccb;
1863  file_ref* fileref = NULL;
1864  LONG open_files;
1865 
1866  UNUSED(Irp);
1867 
1868  TRACE("FileObject = %p\n", FileObject);
1869 
1870  fcb = FileObject->FsContext;
1871  if (!fcb) {
1872  TRACE("FCB was NULL, returning success\n");
1873  return STATUS_SUCCESS;
1874  }
1875 
1876  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1877 
1878  ccb = FileObject->FsContext2;
1879 
1880  TRACE("close called for fcb %p)\n", fcb);
1881 
1882  // FIXME - make sure notification gets sent if file is being deleted
1883 
1884  if (ccb) {
1885  if (ccb->query_string.Buffer)
1887 
1888  if (ccb->filename.Buffer)
1890 
1891  // FIXME - use refcounts for fileref
1892  fileref = ccb->fileref;
1893 
1894  if (fcb->Vcb->running_sends > 0) {
1895  bool send_cancelled = false;
1896 
1897  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
1898 
1899  if (ccb->send) {
1900  ccb->send->cancelling = true;
1901  send_cancelled = true;
1902  KeSetEvent(&ccb->send->cleared_event, 0, false);
1903  }
1904 
1905  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1906 
1907  if (send_cancelled) {
1908  while (ccb->send) {
1909  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
1910  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1911  }
1912  }
1913  }
1914 
1915  ExFreePool(ccb);
1916  }
1917 
1919 
1920  if (open_files == 0 && fcb->Vcb->removing) {
1921  uninit(fcb->Vcb);
1922  return STATUS_SUCCESS;
1923  }
1924 
1925  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1926  return STATUS_SUCCESS;
1927 
1928  if (fileref)
1929  free_fileref(fileref);
1930  else
1931  free_fcb(fcb);
1932 
1933  return STATUS_SUCCESS;
1934 }
void free_fcb(_Inout_ fcb *fcb)
Definition: btrfs.c:1664
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1936
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UNICODE_STRING filename
Definition: btrfs_drv.h:400
UNICODE_STRING query_string
Definition: btrfs_drv.h:392
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:86
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define TRACE(s)
Definition: solgame.cpp:4
struct _fcb fcb
Definition: btrfs_drv.h:1357
KEVENT cleared_event
Definition: btrfs_drv.h:381
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:1786
bool cancelling
Definition: btrfs_drv.h:382
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:399
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define VPB_MOUNTED
Definition: iotypes.h:1787
struct _device_extension * Vcb
Definition: btrfs_drv.h:298
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
send_info * send
Definition: btrfs_drv.h:408

Referenced by _Dispatch_type_().

◆ create_calc_threads()

static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 4053 of file btrfs.c.

4053  {
4054  device_extension* Vcb = DeviceObject->DeviceExtension;
4055  OBJECT_ATTRIBUTES oa;
4056  ULONG i;
4057 
4058  Vcb->calcthreads.num_threads = get_num_of_processors();
4059 
4060  Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
4061  if (!Vcb->calcthreads.threads) {
4062  ERR("out of memory\n");
4064  }
4065 
4066  InitializeListHead(&Vcb->calcthreads.job_list);
4067  KeInitializeSpinLock(&Vcb->calcthreads.spinlock);
4068  KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, false);
4069 
4070  RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads);
4071 
4073 
4074  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
4075  NTSTATUS Status;
4076 
4077  Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
4078  Vcb->calcthreads.threads[i].number = i;
4079  KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, false);
4080 
4081  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, &oa, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
4082  if (!NT_SUCCESS(Status)) {
4083  ULONG j;
4084 
4085  ERR("PsCreateSystemThread returned %08lx\n", Status);
4086 
4087  for (j = 0; j < i; j++) {
4088  Vcb->calcthreads.threads[i].quit = true;
4089  }
4090 
4091  KeSetEvent(&Vcb->calcthreads.event, 0, false);
4092 
4093  return Status;
4094  }
4095  }
4096 
4097  return STATUS_SUCCESS;
4098 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4232
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:91
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
uint32_t get_num_of_processors()
Definition: btrfs.c:4039
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:2978
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:3014

Referenced by mount_vol().

◆ create_root()

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

Definition at line 1199 of file btrfs.c.

1200  {
1201  NTSTATUS Status;
1202  root* r;
1203  tree* t = NULL;
1204  ROOT_ITEM* ri;
1205  traverse_ptr tp;
1206 
1208  if (!r) {
1209  ERR("out of memory\n");
1211  }
1212 
1214  if (!r->nonpaged) {
1215  ERR("out of memory\n");
1216  ExFreePool(r);
1218  }
1219 
1220  if (!no_tree) {
1222  if (!t) {
1223  ERR("out of memory\n");
1224  ExFreePool(r->nonpaged);
1225  ExFreePool(r);
1226  return