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

Go to the source code of this file.

Classes

struct  read_context
 
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)
 
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 (crc32 != *((uint32_t *) sb->checksum))
 
 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)
 
 _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)
 
static void check_cpu ()
 
 _Function_class_ (KSTART_ROUTINE)
 
 _Function_class_ (DRIVER_ADD_DEVICE)
 
 _Function_class_ (DRIVER_INITIALIZE)
 

Variables

static const WCHAR device_name [] = {'\\','B','t','r','f','s',0}
 
static const WCHAR dosdevice_name [] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','B','t','r','f','s',0}
 
PDRIVER_OBJECT drvobj
 
PDEVICE_OBJECT master_devobj
 
PDEVICE_OBJECT busobj
 
bool have_sse42 = false
 
bool have_sse2 = false
 
uint64_t num_reads = 0
 
LIST_ENTRY uid_map_list
 
LIST_ENTRY gid_map_list
 
LIST_ENTRY VcbList
 
ERESOURCE global_loading_lock
 
uint32_t debug_log_level = 0
 
uint32_t mount_compress = 0
 
uint32_t mount_compress_force = 0
 
uint32_t mount_compress_type = 0
 
uint32_t mount_zlib_level = 3
 
uint32_t mount_zstd_level = 3
 
uint32_t mount_flush_interval = 30
 
uint32_t mount_max_inline = 2048
 
uint32_t mount_skip_balance = 0
 
uint32_t mount_no_barrier = 0
 
uint32_t mount_no_trim = 0
 
uint32_t mount_clear_cache = 0
 
uint32_t mount_allow_degraded = 0
 
uint32_t mount_readonly = 0
 
uint32_t 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
 
_In_ uint64_t id = id
 
_In_ uint64_t _In_ uint64_t addr
 
_In_ uint64_t _In_ uint64_t _In_ uint64_t generation = generation
 
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptrtp
 
r dirty = false
 
r received = false
 
r reserved = NULL
 
r treeholder address = addr
 
r treeholder tree = NULL
 
r parent = 0
 
r send_ops = 0
 
r fcbs_version = 0
 
r checked_for_orphans = false
 
InitializeListHeadr
 
r nonpaged = ExAllocatePoolWithTag(NonPagedPool, sizeof(root_nonpaged), ALLOC_TAG)
 
r lastinode = 0
 
InsertTailListVcb
 
return STATUS_SUCCESS
 
_Out_ boolpno_pnp
 
ULONG to_read = DeviceObject->SectorSize == 0 ? sizeof(superblock) : (ULONG)sector_align(sizeof(superblock), DeviceObject->SectorSize)
 
superblocksb = ExAllocatePoolWithTag(NonPagedPool, to_read, ALLOC_TAG)
 
uint32_t crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum))
 
UNICODE_STRING pnp_name
 
const GUIDguid
 
 Status = sync_read_phys(DeviceObject, NULL, superblock_addrs[0], to_read, (PUCHAR)sb, true)
 
DeviceObject Flags &pnp_name Buffer = NULL
 
end __pad0__
 

Macro Definition Documentation

◆ COMPAT_RO_SUPPORTED

◆ INCOMPAT_SUPPORTED

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

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

Function Documentation

◆ _Dispatch_type_() [1/10]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 458 of file btrfs.c.

460  {
464  bool top_level;
465 
467 
468  TRACE("close\n");
469 
470  top_level = is_top_level(Irp);
471 
472  if (DeviceObject == master_devobj) {
473  TRACE("Closing file system\n");
475  goto end;
476  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
478  goto end;
479  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
481  goto end;
482  }
483 
485 
486  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
487 
489 
490 end:
491  Irp->IoStatus.Status = Status;
492  Irp->IoStatus.Information = 0;
493 
495 
496  if (top_level)
498 
499  TRACE("returning %08x\n", Status);
500 
502 
503  return Status;
504 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2902
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1842
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:95
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ _Dispatch_type_() [2/10]

_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 506 of file btrfs.c.

508  {
512  fcb* fcb = FileObject->FsContext;
514  bool top_level;
515 
517 
518  TRACE("flush buffers\n");
519 
520  top_level = is_top_level(Irp);
521 
522  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
524  goto end;
525  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
527  goto end;
528  }
529 
530  if (!fcb) {
531  ERR("fcb was NULL\n");
533  goto end;
534  }
535 
536  if (fcb == Vcb->volume_fcb) {
538  goto end;
539  }
540 
542 
543  Irp->IoStatus.Information = 0;
544 
545  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
546 
548  Irp->IoStatus.Status = Status;
549 
550  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
551  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &Irp->IoStatus);
552 
553  if (fcb->Header.PagingIoResource) {
554  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
555  ExReleaseResourceLite(fcb->Header.PagingIoResource);
556  }
557 
558  Status = Irp->IoStatus.Status;
559  }
560 
561 end:
563 
564  TRACE("returning %08x\n", Status);
565 
566  if (top_level)
568 
570 
571  return Status;
572 }
#define FsRtlEnterFileSystem
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:330
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:287
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
InsertTailList & Vcb
Definition: btrfs.c:2902
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:279
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static __inline FAST_IO_POSSIBLE fast_io_possible(fcb *fcb)
Definition: btrfs_drv.h:1636
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1629
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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:2938

◆ _Dispatch_type_() [3/10]

_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 916 of file btrfs.c.

918  {
921  ULONG BytesCopied = 0;
923  bool top_level;
924 
926 
927  TRACE("query volume information\n");
928  top_level = is_top_level(Irp);
929 
930  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
932  goto end;
933  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
935  goto end;
936  }
937 
939 
941 
942  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
944  {
945  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
946  bool overflow = false;
947 #ifndef __REACTOS__
948  static const WCHAR ntfs[] = L"NTFS";
949 #endif
950  static const WCHAR btrfs[] = L"Btrfs";
951  const WCHAR* fs_name;
952  ULONG fs_name_len, orig_fs_name_len;
953 
954 #ifndef __REACTOS__
955  if (Irp->RequestorMode == UserMode && lie_about_fs_type()) {
956  fs_name = ntfs;
957  orig_fs_name_len = fs_name_len = sizeof(ntfs) - sizeof(WCHAR);
958  } else {
959  fs_name = btrfs;
960  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
961  }
962 #else
963  fs_name = btrfs;
964  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
965 #endif
966 
967  TRACE("FileFsAttributeInformation\n");
968 
969  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
970  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
971  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
972  else
973  fs_name_len = 0;
974 
975  overflow = true;
976  }
977 
978  data->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_CASE_SENSITIVE_SEARCH |
983  if (Vcb->readonly)
984  data->FileSystemAttributes |= FILE_READ_ONLY_VOLUME;
985 
986  // should also be FILE_FILE_COMPRESSION when supported
987  data->MaximumComponentNameLength = 255; // FIXME - check
988  data->FileSystemNameLength = orig_fs_name_len;
989  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
990 
991  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
993  break;
994  }
995 
997  {
998  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
999 
1000  TRACE("FileFsDeviceInformation\n");
1001 
1002  ffdi->DeviceType = FILE_DEVICE_DISK;
1003 
1004  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1005  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
1006  ExReleaseResourceLite(&Vcb->tree_lock);
1007 
1008  if (Vcb->readonly)
1010  else
1012 
1015 
1016  break;
1017  }
1018 
1020  {
1021  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1022 
1023  TRACE("FileFsFullSizeInformation\n");
1024 
1027  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1028  ffsi->BytesPerSector = 512;
1029 
1032 
1033  break;
1034  }
1035 
1037  {
1038  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
1039 
1040  TRACE("FileFsObjectIdInformation\n");
1041 
1042  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
1043  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
1044 
1047 
1048  break;
1049  }
1050 
1051  case FileFsSizeInformation:
1052  {
1053  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
1054 
1055  TRACE("FileFsSizeInformation\n");
1056 
1058  ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
1059  ffsi->BytesPerSector = 512;
1060 
1063 
1064  break;
1065  }
1066 
1068  {
1069  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1071  bool overflow = false;
1072  ULONG label_len, orig_label_len;
1073 
1074  TRACE("FileFsVolumeInformation\n");
1075  TRACE("max length = %u\n", IrpSp->Parameters.QueryVolume.Length);
1076 
1077  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
1078 
1079  Status = utf8_to_utf16(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1080  if (!NT_SUCCESS(Status)) {
1081  ERR("utf8_to_utf16 returned %08x\n", Status);
1082  ExReleaseResourceLite(&Vcb->tree_lock);
1083  break;
1084  }
1085 
1086  orig_label_len = label_len;
1087 
1088  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len) {
1089  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR))
1090  label_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_VOLUME_INFORMATION) + sizeof(WCHAR);
1091  else
1092  label_len = 0;
1093 
1094  overflow = true;
1095  }
1096 
1097  TRACE("label_len = %u\n", label_len);
1098 
1099  ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
1100  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];
1101  ffvi.VolumeLabelLength = orig_label_len;
1102  ffvi.SupportsObjects = false;
1103 
1104  RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
1105 
1106  if (label_len > 0) {
1107  ULONG bytecount;
1108 
1109  Status = utf8_to_utf16(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
1111  ERR("utf8_to_utf16 returned %08x\n", Status);
1112  ExReleaseResourceLite(&Vcb->tree_lock);
1113  break;
1114  }
1115 
1116  TRACE("label = %.*S\n", label_len / sizeof(WCHAR), data->VolumeLabel);
1117  }
1118 
1119  ExReleaseResourceLite(&Vcb->tree_lock);
1120 
1121  BytesCopied = sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len;
1123  break;
1124  }
1125 
1126 #ifndef __REACTOS__
1127 #ifdef _MSC_VER // not in mingw yet
1128  case FileFsSectorSizeInformation:
1129  {
1130  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
1131 
1132  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
1133  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1134  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
1135  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
1136  data->ByteOffsetForSectorAlignment = 0;
1137  data->ByteOffsetForPartitionAlignment = 0;
1138 
1139  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
1140 
1141  if (Vcb->trim && !Vcb->options.no_trim)
1142  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
1143 
1144  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
1145 
1146  break;
1147  }
1148 #endif
1149 #endif /* __REACTOS__ */
1150 
1151  default:
1153  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
1154  break;
1155  }
1156 
1158  Irp->IoStatus.Information = 0;
1159  else
1160  Irp->IoStatus.Information = BytesCopied;
1161 
1162 end:
1163  Irp->IoStatus.Status = Status;
1164 
1166 
1167  if (top_level)
1169 
1170  TRACE("query volume information returning %08x\n", Status);
1171 
1173 
1174  return Status;
1175 }
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:263
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
struct _FILE_FS_FULL_SIZE_INFORMATION FILE_FS_FULL_SIZE_INFORMATION
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _FILE_FS_OBJECTID_INFORMATION FILE_FS_OBJECTID_INFORMATION
#define FsRtlEnterFileSystem
NTSTATUS vol_query_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:336
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_SUPPORTS_OBJECT_IDS
Definition: from_kernel.h:243
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WARN(fmt,...)
Definition: debug.h:111
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
GLuint GLuint end
Definition: gl.h:1545
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
#define FILE_SUPPORTS_POSIX_UNLINK_RENAME
Definition: btrfs_drv.h:150
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
static bool lie_about_fs_type()
Definition: btrfs.c:606
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2902
#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:146
#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:666
#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:718
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define FILE_NAMED_STREAMS
Definition: from_kernel.h:245
#define FILE_SUPPORTS_OPEN_BY_FILE_ID
Definition: from_kernel.h:251
unsigned char UCHAR
Definition: xmlstorage.h:181
static void calculate_total_space(_In_ device_extension *Vcb, _Out_ uint64_t *totalsize, _Out_ uint64_t *freespace)
Definition: btrfs.c:574
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static const WCHAR L[]
Definition: oid.c:1250
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
Status
Definition: gdiplustypes.h:24
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
UINT64 uint64_t
Definition: types.h:77
#define FILE_SUPPORTS_SPARSE_FILES
Definition: from_kernel.h:239
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
#define min(a, b)
Definition: monoChain.cc:55
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES
Definition: from_kernel.h:250
struct _FILE_FS_VOLUME_INFORMATION FILE_FS_VOLUME_INFORMATION
unsigned int ULONG
Definition: retypes.h:1
#define FILE_PERSISTENT_ACLS
Definition: from_kernel.h:236
#define FILE_READ_ONLY_VOLUME
Definition: from_kernel.h:246
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
LARGE_INTEGER CallerAvailableAllocationUnits
Definition: from_kernel.h:271
#define FILE_READ_ONLY_DEVICE
Definition: nt_native.h:808
LARGE_INTEGER TotalAllocationUnits
Definition: from_kernel.h:270
LONGLONG QuadPart
Definition: typedefs.h:112

◆ _Dispatch_type_() [4/10]

_Dispatch_type_ ( IRP_MJ_SET_VOLUME_INFORMATION  )

Definition at line 1368 of file btrfs.c.

1370  {
1373  NTSTATUS Status;
1374  bool top_level;
1375 
1377 
1378  TRACE("set volume information\n");
1379 
1380  top_level = is_top_level(Irp);
1381 
1382  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1384  goto end;
1385  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1387  goto end;
1388  }
1389 
1391 
1392  if (Vcb->readonly) {
1394  goto end;
1395  }
1396 
1397  if (Vcb->removing || Vcb->locked) {
1399  goto end;
1400  }
1401 
1402  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1404  FIXME("STUB: FileFsControlInformation\n");
1405  break;
1406 
1408  TRACE("FileFsLabelInformation\n");
1409 
1410  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1411  break;
1412 
1414  FIXME("STUB: FileFsObjectIdInformation\n");
1415  break;
1416 
1417  default:
1418  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1419  break;
1420  }
1421 
1422 end:
1423  Irp->IoStatus.Status = Status;
1424  Irp->IoStatus.Information = 0;
1425 
1426  TRACE("returning %08x\n", Status);
1427 
1429 
1430  if (top_level)
1432 
1434 
1435  return Status;
1436 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
#define FIXME(fmt,...)
Definition: debug.h:110
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
InsertTailList & Vcb
Definition: btrfs.c:2902
#define TRACE(s)
Definition: solgame.cpp:4
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1313
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
NTSTATUS vol_set_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:342

◆ _Dispatch_type_() [5/10]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2355 of file btrfs.c.

2357  {
2358  NTSTATUS Status;
2362  fcb* fcb = FileObject->FsContext;
2363  bool top_level;
2364 
2366 
2367  TRACE("cleanup\n");
2368 
2369  top_level = is_top_level(Irp);
2370 
2371  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2373  goto exit;
2374  } else if (DeviceObject == master_devobj) {
2375  TRACE("closing file system\n");
2377  goto exit;
2378  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2380  goto exit;
2381  }
2382 
2383  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2384  TRACE("FileObject %p already cleaned up\n", FileObject);
2386  goto exit;
2387  }
2388 
2389  if (!fcb) {
2390  ERR("fcb was NULL\n");
2392  goto exit;
2393  }
2394 
2396 
2397  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2398  // messages belonging to other devices.
2399 
2400  if (FileObject && FileObject->FsContext) {
2401  LONG oc;
2402  ccb* ccb;
2403  file_ref* fileref;
2404  bool locked = true;
2405 
2406  ccb = FileObject->FsContext2;
2407  fileref = ccb ? ccb->fileref : NULL;
2408 
2409  TRACE("cleanup called for FileObject %p\n", FileObject);
2410  TRACE("fileref %p, refcount = %u, open_count = %u\n", fileref, fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2411 
2412  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
2413 
2414  ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
2415 
2417 
2419 
2420  if (ccb)
2421  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2422 
2423  if (fileref) {
2424  oc = InterlockedDecrement(&fileref->open_count);
2425 #ifdef DEBUG_FCB_REFCOUNTS
2426  ERR("fileref %p: open_count now %i\n", fileref, oc);
2427 #endif
2428  }
2429 
2430  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2431  fileref->delete_on_close = true;
2432 
2433  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2434  fileref->delete_on_close = false;
2435 
2436  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2437  TRACE("unlocking volume\n");
2440  }
2441 
2442  if (ccb && ccb->reserving) {
2443  fcb->subvol->reserved = NULL;
2444  ccb->reserving = false;
2445  // FIXME - flush all of subvol's fcbs
2446  }
2447 
2448  if (fileref && (oc == 0 || (fileref->delete_on_close && fileref->posix_delete))) {
2449  if (!fcb->Vcb->removing) {
2450  if (oc == 0 && fileref->fcb->inode_item.st_nlink == 0 && fileref != fcb->Vcb->root_fileref &&
2451  fcb != fcb->Vcb->volume_fcb && !fcb->ads) { // last handle closed on POSIX-deleted file
2453 
2455 
2457  if (!NT_SUCCESS(Status)) {
2458  ERR("delete_fileref_fcb returned %08x\n", Status);
2460  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2461  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2462  goto exit;
2463  }
2464 
2466 
2467  mark_fcb_dirty(fileref->fcb);
2468  } else if (fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2470 
2472 
2473  if (!fileref->fcb->ads || fileref->dc) {
2474  if (fileref->fcb->ads) {
2476  FILE_ACTION_REMOVED, &fileref->dc->name);
2477  } else
2479  }
2480 
2481  ExReleaseResourceLite(fcb->Header.Resource);
2482  locked = false;
2483 
2484  // fileref_lock needs to be acquired before fcb->Header.Resource
2485  ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
2486 
2487  Status = delete_fileref(fileref, FileObject, oc > 0 && fileref->posix_delete, Irp, &rollback);
2488  if (!NT_SUCCESS(Status)) {
2489  ERR("delete_fileref returned %08x\n", Status);
2491  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2492  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2493  goto exit;
2494  }
2495 
2496  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2497 
2499  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && FileObject->SectionObjectPointer->DataSectionObject) {
2501  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2502 
2503  if (!NT_SUCCESS(iosb.Status)) {
2504  ERR("CcFlushCache returned %08x\n", iosb.Status);
2505  }
2506 
2507  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2508  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
2509  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2510  }
2511 
2512  CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, false);
2513 
2514  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2515  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2516  }
2517  }
2518 
2519  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2521  }
2522 
2523  if (locked)
2524  ExReleaseResourceLite(fcb->Header.Resource);
2525 
2526  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2527 
2528  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2529  }
2530 
2532 
2533 exit:
2534  TRACE("returning %08x\n", Status);
2535 
2536  Irp->IoStatus.Status = Status;
2537  Irp->IoStatus.Information = 0;
2538 
2540 
2541  if (top_level)
2543 
2545 
2546  return Status;
2547 }
struct _file_ref * parent
Definition: btrfs_drv.h:353
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1049
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1028
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:375
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
Status
Definition: btrfs.c:4150
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:352
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
#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:1438
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
bool posix_delete
Definition: btrfs_drv.h:346
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:635
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
long LONG
Definition: pedump.c:60
uint32_t st_nlink
Definition: btrfs.h:275
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
void mark_fcb_dirty(_In_ fcb *fcb)
Definition: btrfs.c:1614
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:287
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG refcount
Definition: btrfs_drv.h:351
FILE_LOCK lock
Definition: btrfs_drv.h:290
InsertTailList & Vcb
Definition: btrfs.c:2902
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:279
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
uint64_t st_size
Definition: btrfs.h:272
#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:666
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1738
dir_child * dc
Definition: btrfs_drv.h:354
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:342
Definition: typedefs.h:117
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1026
INODE_ITEM inode_item
Definition: btrfs_drv.h:288
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1747
static NTSTATUS delete_fileref_fcb(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2131
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _root * subvol
Definition: btrfs_drv.h:284
_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:1314
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
bool ads
Definition: btrfs_drv.h:326
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1629
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:2187
#define IO_NO_INCREMENT
Definition: iotypes.h:566
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
bool reserving
Definition: btrfs_drv.h:382
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:294
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:384
return STATUS_SUCCESS
Definition: btrfs.c:2938
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2320
struct _device_extension * Vcb
Definition: btrfs_drv.h:283
UNICODE_STRING name
Definition: btrfs_drv.h:252
bool delete_on_close
Definition: btrfs_drv.h:345

◆ _Dispatch_type_() [6/10]

_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 5084 of file btrfs.c.

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

◆ _Dispatch_type_() [7/10]

_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 5165 of file btrfs.c.

5167  {
5168  NTSTATUS Status;
5170  fcb* fcb = IrpSp->FileObject ? IrpSp->FileObject->FsContext : NULL;
5172  bool top_level;
5173 
5175 
5176  top_level = is_top_level(Irp);
5177 
5178  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5180 
5181  Irp->IoStatus.Status = Status;
5183 
5184  goto exit;
5185  }
5186 
5187  TRACE("lock control\n");
5188 
5189  if (!fcb) {
5190  ERR("fcb was NULL\n");
5192  goto exit;
5193  }
5194 
5196 
5198 
5199  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
5200 
5201 exit:
5202  TRACE("returning %08x\n", Status);
5203 
5204  if (top_level)
5206 
5208 
5209  return Status;
5210 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FILE_LOCK lock
Definition: btrfs_drv.h:290
InsertTailList & Vcb
Definition: btrfs.c:2902
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:279
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static __inline FAST_IO_POSSIBLE fast_io_possible(fcb *fcb)
Definition: btrfs_drv.h:1636
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1153
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS vol_lock_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:368
static __inline POPLOCK fcb_oplock(fcb *fcb)
Definition: btrfs_drv.h:1629
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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 5309 of file btrfs.c.

5311  {
5312  NTSTATUS Status;
5313  bool top_level;
5315 
5317 
5318  TRACE("shutdown\n");
5319 
5320  top_level = is_top_level(Irp);
5321 
5322  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5324  goto end;
5325  }
5326 
5328 
5329  do_shutdown(Irp);
5330 
5331 end:
5332  Irp->IoStatus.Status = Status;
5333  Irp->IoStatus.Information = 0;
5334 
5336 
5337  if (top_level)
5339 
5341 
5342  return Status;
5343 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2902
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS vol_shutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:886
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938
void do_shutdown(PIRP Irp)
Definition: btrfs.c:5212

◆ _Dispatch_type_() [9/10]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5345 of file btrfs.c.

5347  {
5348  NTSTATUS Status;
5351  bool top_level;
5352 
5354 
5355  top_level = is_top_level(Irp);
5356 
5357  Irp->IoStatus.Information = 0;
5358 
5359  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5361 
5365 
5366  goto exit;
5367  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5369 
5370  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5371 
5372  goto exit;
5373  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5375 
5379 
5380  goto exit;
5381  }
5382 
5384  Irp->IoStatus.Status = STATUS_SUCCESS;
5385 
5386  Status = Irp->IoStatus.Status;
5387 
5389 
5391 
5392 exit:
5393  if (top_level)
5395 
5397 
5398  return Status;
5399 }
#define FsRtlEnterFileSystem
#define IRP_MN_QUERY_POWER
#define FsRtlExitFileSystem
NTSTATUS NTAPI PoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: power.c:485
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:668
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2902
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define IRP_MN_SET_POWER
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:855
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:825
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:626
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:566
void exit(int exitcode)
Definition: _exit.c:33
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ _Dispatch_type_() [10/10]

_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5401 of file btrfs.c.

5403  {
5404  NTSTATUS Status;
5406  bool top_level;
5407 
5409 
5410  top_level = is_top_level(Irp);
5411 
5412  Irp->IoStatus.Information = 0;
5413 
5414  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5416 
5418 
5420 
5421  goto exit;
5422  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5424 
5425  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5426 
5427  goto exit;
5428  } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5430 
5432 
5434 
5435  goto exit;
5436  }
5437 
5438  Status = Irp->IoStatus.Status;
5440 
5441 exit:
5442  if (top_level)
5444 
5446 
5447  return Status;
5448 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
#define VCB_TYPE_FS
Definition: btrfs_drv.h:664
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:276
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:668
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2902
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:855
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:825
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:566
void exit(int exitcode)
Definition: _exit.c:33

◆ _Function_class_() [1/6]

_Function_class_ ( DRIVER_UNLOAD  )

Definition at line 285 of file btrfs.c.

286  {
287  UNICODE_STRING dosdevice_nameW;
288 
289  TRACE("(%p)\n", DriverObject);
290 
291  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
292  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
293 
294  IoDeleteSymbolicLink(&dosdevice_nameW);
296 
297  while (!IsListEmpty(&uid_map_list)) {
299  uid_map* um = CONTAINING_RECORD(le, uid_map, listentry);
300 
301  ExFreePool(um->sid);
302 
303  ExFreePool(um);
304  }
305 
306  while (!IsListEmpty(&gid_map_list)) {
308 
309  ExFreePool(gm->sid);
310  ExFreePool(gm);
311  }
312 
313  // FIXME - free volumes and their devpaths
314 
315 #ifdef _DEBUG
316  if (comfo)
317  ObDereferenceObject(comfo);
318 
319  if (log_handle)
320  ZwClose(log_handle);
321 #endif
322 
325 
326  if (log_device.Buffer)
328 
329  if (log_file.Buffer)
331 
332  if (registry_path.Buffer)
334 
335 #ifdef _DEBUG
336  ExDeleteResourceLite(&log_lock);
337 #endif
339 }
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:92
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
PSID sid
Definition: btrfs_drv.h:885
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UNICODE_STRING registry_path
Definition: btrfs.c:92
PSID sid
Definition: btrfs_drv.h:879
static const WCHAR dosdevice_name[]
Definition: btrfs.c:62
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LIST_ENTRY uid_map_list
Definition: btrfs.c:72
Definition: typedefs.h:117
ERESOURCE mapping_lock
Definition: btrfs.c:106
ERESOURCE global_loading_lock
Definition: btrfs.c:74
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
UNICODE_STRING log_device
Definition: btrfs.c:92
ERESOURCE pdo_list_lock
Definition: btrfs.c:106
LIST_ENTRY gid_map_list
Definition: btrfs.c:72
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2169

◆ _Function_class_() [2/6]

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 1177 of file btrfs.c.

1178  {
1179  read_context* context = conptr;
1180 
1182 
1183  context->iosb = Irp->IoStatus;
1184  KeSetEvent(&context->Event, 0, false);
1185 
1187 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
Definition: http.c:7098
_In_ PIRP Irp
Definition: csq.h:116
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define UNUSED(x)
Definition: btrfs_drv.h:86
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

◆ _Function_class_() [3/6]

_Function_class_ ( IO_WORKITEM_ROUTINE  )

Definition at line 1567 of file btrfs.c.

1568  {
1569  notification_fcb* nf = con;
1570 
1572 
1573  ExAcquireResourceSharedLite(&nf->fileref->fcb->Vcb->tree_lock, TRUE); // protect us from fileref being reaped
1574 
1576 
1577  free_fileref(nf->fileref);
1578 
1579  ExReleaseResourceLite(&nf->fileref->fcb->Vcb->tree_lock);
1580 
1582 
1583  ExFreePool(nf);
1584 }
#define TRUE
Definition: types.h:120
PUNICODE_STRING stream
Definition: btrfs.c:1563
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
ULONG filter_match
Definition: btrfs.c:1561
static void send_notification_fcb(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1478
#define UNUSED(x)
Definition: btrfs_drv.h:86
file_ref * fileref
Definition: btrfs.c:1560
PIO_WORKITEM work_item
Definition: btrfs.c:1564
ULONG action
Definition: btrfs.c:1562
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
fcb * fcb
Definition: btrfs_drv.h:342
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
void free_fileref(_Inout_ file_ref *fr)
Definition: btrfs.c:1768
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
struct _device_extension * Vcb
Definition: btrfs_drv.h:283
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ _Function_class_() [4/6]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 5712 of file btrfs.c.

5713  {
5714  KTIMER timer;
5716 
5717  UNUSED(context);
5718 
5719  KeInitializeTimer(&timer);
5720 
5721  delay.QuadPart = -30000000; // wait three seconds
5722  KeSetTimer(&timer, delay, NULL);
5723  KeWaitForSingleObject(&timer, Executive, KernelMode, false, NULL);
5724 
5725  TRACE("timer expired\n");
5726 
5727  degraded_wait = false;
5728 
5731 
5733 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
Definition: http.c:7098
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
HANDLE degraded_wait_handle
Definition: btrfs.c:109
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define UNUSED(x)
Definition: btrfs_drv.h:86
#define TRACE(s)
Definition: solgame.cpp:4
void delay(unsigned msec)
Definition: i386rtl.c:32
bool degraded_wait
Definition: btrfs.c:110
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ _Function_class_() [5/6]

_Function_class_ ( DRIVER_ADD_DEVICE  )

Definition at line 5735 of file btrfs.c.

5736  {
5737  LIST_ENTRY* le;
5738  NTSTATUS Status;
5739  UNICODE_STRING volname;
5740  ULONG i, j;
5741  pdo_device_extension* pdode = NULL;
5742  PDEVICE_OBJECT voldev;
5744 
5745  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
5746 
5748 
5749  le = pdo_list.Flink;
5750  while (le != &pdo_list) {
5752 
5753  if (pdode2->pdo == PhysicalDeviceObject) {
5754  pdode = pdode2;
5755  break;
5756  }
5757 
5758  le = le->Flink;
5759  }
5760 
5761  if (!pdode) {
5762  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
5764  goto end;
5765  }
5766 
5768 
5769  if (pdode->vde) { // if already done, return success
5771  goto end2;
5772  }
5773 
5774  volname.Length = volname.MaximumLength = (sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR)) + ((36 + 1) * sizeof(WCHAR));
5775  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
5776 
5777  if (!volname.Buffer) {
5778  ERR("out of memory\n");
5780  goto end2;
5781  }
5782 
5783  RtlCopyMemory(volname.Buffer, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR));
5784 
5785  j = (sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1;
5786  for (i = 0; i < 16; i++) {
5787  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] >> 4); j++;
5788  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] & 0xf); j++;
5789 
5790  if (i == 3 || i == 5 || i == 7 || i == 9) {
5791  volname.Buffer[j] = '-';
5792  j++;
5793  }
5794  }
5795 
5796  volname.Buffer[j] = '}';
5797 
5800  if (!NT_SUCCESS(Status)) {
5801  ERR("IoCreateDevice returned %08x\n", Status);
5802  goto end2;
5803  }
5804 
5805  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
5806  voldev->Flags |= DO_DIRECT_IO;
5807 
5808  vde = voldev->DeviceExtension;
5809  vde->type = VCB_TYPE_VOLUME;
5810  vde->name = volname;
5811  vde->device = voldev;
5812  vde->mounted_device = NULL;
5813  vde->pdo = PhysicalDeviceObject;
5814  vde->pdode = pdode;
5815  vde->removing = false;
5816  vde->dead = false;
5817  vde->open_count = 0;
5818 
5819  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
5820  if (!NT_SUCCESS(Status))
5821  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5822 
5824 
5825  pdode->vde = vde;
5826 
5827  if (pdode->removable)
5828  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
5829 
5830  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
5831 
5832  Status = IoSetDeviceInterfaceState(&vde->bus_name, true);
5833  if (!NT_SUCCESS(Status))
5834  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5835 
5837 
5838 end2:
5840 
5841 end:
5843 
5844  return Status;
5845 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1725
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
USHORT MaximumLength
Definition: env_spec_w32.h:370
PDEVICE_OBJECT device
Definition: btrfs_drv.h:850
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:4150
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:852
GLuint GLuint end
Definition: gl.h:1545
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1122
#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:849
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:865
#define ALLOC_TAG
Definition: btrfs_drv.h:91
UNICODE_STRING bus_name
Definition: btrfs_drv.h:854
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:853
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:107
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BTRFS_VOLUME_PREFIX
Definition: btrfs_drv.h:127
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:666
ERESOURCE child_lock
Definition: btrfs_drv.h:871
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:851
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:66
Definition: typedefs.h:117
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:855
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
uint8_t uuid[16]
Definition: btrfs.h:124
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:955
#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
Definition: btrfs_drv.h:154
Definition: list.h:27
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
ERESOURCE pdo_list_lock
Definition: btrfs.c:106
volume_device_extension * vde
Definition: btrfs_drv.h:864
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ _Function_class_() [6/6]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 5847 of file btrfs.c.

5848  {
5849  NTSTATUS Status;
5852  UNICODE_STRING dosdevice_nameW;
5854  bus_device_extension* bde;
5855  HANDLE regh;
5856  OBJECT_ATTRIBUTES oa, system_thread_attributes;
5857  ULONG dispos;
5858 
5861 
5862 #ifdef _DEBUG
5863  ExInitializeResourceLite(&log_lock);
5864 #endif
5866 
5869  log_file.Buffer = NULL;
5871 
5874 
5875  if (!registry_path.Buffer) {
5876  ERR("out of memory\n");
5878  }
5879 
5881 
5882  read_registry(&registry_path, false);
5883 
5884 #ifdef _DEBUG
5885  if (debug_log_level > 0)
5886  init_logging();
5887 
5888  log_started = true;
5889 #endif
5890 
5891  TRACE("DriverEntry\n");
5892 
5893 #ifndef __REACTOS__
5894  check_cpu();
5895 #endif
5896 
5899  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
5900 
5901  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
5902  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
5903 
5904  if (fPsIsDiskCountersEnabled) {
5905  diskacc = fPsIsDiskCountersEnabled();
5906 
5907  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
5909 
5910  if (!fPsUpdateDiskCounters)
5911  diskacc = false;
5912 
5913  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
5915  }
5916 
5917  RtlInitUnicodeString(&name, L"CcCopyReadEx");
5919 
5920  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
5922 
5923  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
5925 
5926  RtlInitUnicodeString(&name, L"FsRtlCheckLockForOplockRequest");
5928  } else {
5930  fCcCopyReadEx = NULL;
5931  fCcCopyWriteEx = NULL;
5935  }
5936 
5939 
5940  RtlInitUnicodeString(&name, L"IoUnregisterPlugPlayNotificationEx");
5942 
5943  RtlInitUnicodeString(&name, L"FsRtlAreThereCurrentOrInProgressFileLocks");
5945  } else {
5948  }
5949 
5952 
5953  RtlInitUnicodeString(&name, L"FsRtlGetEcpListFromIrp");
5955 
5956  RtlInitUnicodeString(&name, L"FsRtlGetNextExtraCreateParameter");
5958 
5959  RtlInitUnicodeString(&name, L"FsRtlValidateReparsePointBuffer");
5961  } else {
5965  }
5966 
5967  drvobj = DriverObject;
5968 
5970 
5972 
5973  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
5974  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
5975  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
5976  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
5977  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
5978  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
5979  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
5980  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
5981  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
5982  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
5983  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
5984  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
5985  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
5986  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
5987  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
5988  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
5989  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
5990  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
5991  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
5992  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
5993  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
5995 
5997 
5998  device_nameW.Buffer = (WCHAR*)device_name;
5999  device_nameW.Length = device_nameW.MaximumLength = sizeof(device_name) - sizeof(WCHAR);
6000  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
6001  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
6002 
6005  if (!NT_SUCCESS(Status)) {
6006  ERR("IoCreateDevice returned %08x\n", Status);
6007  return Status;
6008  }
6009 
6012 
6014 
6015  cde->type = VCB_TYPE_CONTROL;
6016 
6018 
6019  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
6020  if (!NT_SUCCESS(Status)) {
6021  ERR("IoCreateSymbolicLink returned %08x\n", Status);
6022  return Status;
6023  }
6024 
6025  init_cache();
6026 
6030 
6032 
6035  if (!NT_SUCCESS(Status)) {
6036  ERR("ZwCreateKey returned %08x\n", Status);
6037  return Status;
6038  }
6039 
6040  watch_registry(regh);
6041 
6043  FILE_DEVICE_SECURE_OPEN, false, &busobj);
6044  if (!NT_SUCCESS(Status)) {
6045  ERR("IoCreateDevice returned %08x\n", Status);
6046  return Status;
6047  }
6048 
6050 
6051  RtlZeroMemory(bde, sizeof(bus_device_extension));
6052 
6053  bde->type = VCB_TYPE_BUS;
6054 
6055  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
6056  NULL, NULL, 0, &bde->buspdo);
6057  if (!NT_SUCCESS(Status)) {
6058  ERR("IoReportDetectedDevice returned %08x\n", Status);
6059  return Status;
6060  }
6061 
6062  Status = IoRegisterDeviceInterface(bde->buspdo, &BtrfsBusInterface, NULL, &bde->bus_name);
6063  if (!NT_SUCCESS(Status))
6064  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
6065 
6067 
6069 
6070  Status = IoSetDeviceInterfaceState(&bde->bus_name, true);
6071  if (!NT_SUCCESS(Status))
6072  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
6073 
6075 
6076  InitializeObjectAttributes(&system_thread_attributes, NULL, OBJ_KERNEL_HANDLE, NULL, NULL);
6077 
6078  Status = PsCreateSystemThread(&degraded_wait_handle, 0, &system_thread_attributes, NULL, NULL, degraded_wait_thread, NULL);
6079  if (!NT_SUCCESS(Status))
6080  WARN("PsCreateSystemThread returned %08x\n", Status);
6081 
6083 
6085  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
6086  if (!NT_SUCCESS(Status))
6087  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
6088 
6090  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
6091  if (!NT_SUCCESS(Status))
6092  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
6093 
6095  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
6096  if (!NT_SUCCESS(Status))
6097  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
6098 
6099  finished_probing = true;
6100 
6102 
6103  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, &system_thread_attributes, NULL, NULL, mountmgr_thread, NULL);
6104  if (!NT_SUCCESS(Status))
6105  WARN("PsCreateSystemThread returned %08x\n", Status);
6106 
6108 
6110 
6111  return STATUS_SUCCESS;
6112 }
VOID(__stdcall * tFsRtlUpdateDiskCounters)(ULONG64 BytesRead, ULONG64 BytesWritten)
Definition: btrfs_drv.h:1832
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
tFsRtlCheckLockForOplockRequest fFsRtlCheckLockForOplockRequest
Definition: btrfs.c:102
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:824
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
void init_fast_io_dispatch(FAST_IO_DISPATCH **fiod)
Definition: fastio.c:486
BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version)
bool finished_probing
Definition: btrfs.c:108
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_FLUSH_BUFFERS
NTSTATUS(__stdcall * tFsRtlGetNextExtraCreateParameter)(PECP_LIST EcpList, PVOID CurrentEcpContext, LPGUID NextEcpType, PVOID *NextEcpContext, ULONG *NextEcpContextSize)
Definition: btrfs_drv.h:1838
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IRP_MJ_SHUTDOWN
void * notification_entry3
Definition: btrfs.c:105
DRIVER_ADD_DEVICE AddDevice
Definition: parport.h:72
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:94
HANDLE degraded_wait_handle
Definition: btrfs.c:109
LIST_ENTRY VcbList
Definition: btrfs.c:73
#define IRP_MJ_SET_SECURITY
static void check_cpu()
Definition: btrfs.c:5604
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR device_name[]
Definition: btrfs.c:61
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4150
UNICODE_STRING log_file
Definition: btrfs.c:92
tFsRtlValidateReparsePointBuffer fFsRtlValidateReparsePointBuffer
Definition: btrfs.c:101
tFsRtlAreThereCurrentOrInProgressFileLocks fFsRtlAreThereCurrentOrInProgressFileLocks
Definition: btrfs.c:103
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1196
void watch_registry(HANDLE regh)
Definition: registry.c:1027
void * notification_entry2
Definition: btrfs.c:105
bool diskacc
Definition: btrfs.c:104
uint32_t debug_log_level
Definition: btrfs.c:75
UNICODE_STRING bus_name
Definition: btrfs_drv.h:826
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:668
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:93
#define ALLOC_TAG
Definition: btrfs_drv.h:91
UNICODE_STRING registry_path
Definition: btrfs.c:92
NTSTATUS NTAPI IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject, IN INTERFACE_TYPE LegacyBusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PCM_RESOURCE_LIST ResourceList, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL, IN BOOLEAN ResourceAssigned, IN OUT PDEVICE_OBJECT *DeviceObject OPTIONAL)
Definition: pnpreport.c:162
HANDLE mountmgr_thread_handle
Definition: btrfs.c:109
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3417
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
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:1818
static const WCHAR dosdevice_name[]
Definition: btrfs.c:62
#define IRP_MJ_SET_EA
NTSTATUS(__stdcall * tFsRtlGetEcpListFromIrp)(PIRP Irp, PECP_LIST *EcpList)
Definition: btrfs_drv.h:1836
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:97
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1311
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
tCcCopyWriteEx fCcCopyWriteEx
Definition: btrfs.c:95
void __stdcall check_system_root(PDRIVER_OBJECT DriverObject, PVOID Context, ULONG Count)
Definition: boot.c:278
#define IRP_MJ_QUERY_EA
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
void * notification_entry
Definition: btrfs.c:105
BOOLEAN(__stdcall * tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1815
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:107
__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:1810
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
BOOLEAN(__stdcall * tFsRtlAreThereCurrentOrInProgressFileLocks)(PFILE_LOCK FileLock)
Definition: btrfs_drv.h:1845
VOID NTAPI IoRegisterBootDriverReinitialization(IN PDRIVER_OBJECT DriverObject, IN PDRIVER_REINITIALIZE ReinitRoutine, IN PVOID Context)
Definition: driver.c:1706
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:66
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:96
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
NTSTATUS(__stdcall * tFsRtlValidateReparsePointBuffer)(ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: btrfs_drv.h:1841
LIST_ENTRY uid_map_list
Definition: btrfs.c:72
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:249
PDEVICE_OBJECT busobj
Definition: btrfs.c:67
static const WCHAR device_nameW[]
Definition: httpapi_main.c:33
#define IRP_MJ_SYSTEM_CONTROL
tFsRtlGetNextExtraCreateParameter fFsRtlGetNextExtraCreateParameter
Definition: btrfs.c:100
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:665
Status
Definition: gdiplustypes.h:24
ERESOURCE mapping_lock
Definition: btrfs.c:106
ERESOURCE global_loading_lock
Definition: btrfs.c:74
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:825
NTSTATUS(__stdcall * tIoUnregisterPlugPlayNotificationEx)(PVOID NotificationEntry)
Definition: btrfs_drv.h:1834
void init_cache()
Definition: cache.c:85
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5111
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:98
BOOLEAN(__stdcall * tFsRtlCheckLockForOplockRequest)(PFILE_LOCK FileLock, PLARGE_INTEGER AllocationSize)
Definition: btrfs_drv.h:1843
KEVENT mountmgr_thread_event
Definition: btrfs.c:111
#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:92
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 FILE_DEVICE_UNKNOWN
Definition: winioctl.h:139
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
ERESOURCE pdo_list_lock
Definition: btrfs.c:106
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:992
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2177
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG const UNICODE_STRING ULONG PULONG dispos
Definition: reg.c:130
#define IRP_MJ_CLEANUP
Definition: name.c:38
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
bool log_started
Definition: btrfs.c:91
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
VOID(__stdcall * tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1830
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
LIST_ENTRY gid_map_list
Definition: btrfs.c:72
#define NTDDI_WIN8
Definition: sdkddkver.h:113
tFsRtlGetEcpListFromIrp fFsRtlGetEcpListFromIrp
Definition: btrfs.c:99
NTSTATUS __stdcall compat_FsRtlValidateReparsePointBuffer(IN ULONG BufferLength, IN PREPARSE_DATA_BUFFER ReparseBuffer)
Definition: fsrtl.c:32
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
VOID(__stdcall * tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1812
ERESOURCE boot_lock
Definition: btrfs.c:113
void read_registry(PUNICODE_STRING regpath, bool refresh)
Definition: registry.c:769
#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 382 of file btrfs.c.

383  {
384  DIR_ITEM* xa = (DIR_ITEM*)item;
385  USHORT xasize;
386 
387  while (true) {
388  if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m + xa->n)) {
389  WARN("DIR_ITEM is truncated\n");
390  return false;
391  }
392 
393  if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name, xa->n) == xa->n) {
394  TRACE("found xattr %s\n", name);
395 
396  *datalen = xa->m;
397 
398  if (xa->m > 0) {
400  if (!*data) {
401  ERR("out of memory\n");
402  return false;
403  }
404 
405  RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
406  } else
407  *data = NULL;
408 
409  return true;
410  }
411 
412  xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
413 
414  if (size > xasize) {
415  size -= xasize;
416  xa = (DIR_ITEM*)&xa->name[xa->m + xa->n];
417  } else
418  break;
419  }
420 
421  TRACE("xattr %s not found\n", name);
422 
423  return false;
424 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define WARN(fmt,...)
Definition: debug.h:111
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1027
if(!r)
Definition: btrfs.c:2857
#define ALLOC_TAG
Definition: btrfs_drv.h:91
uint16_t m
Definition: btrfs.h:258
char name[1]
Definition: btrfs.h:261
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
static ATOM item
Definition: dde.c:856
unsigned short USHORT
Definition: pedump.c:61
Definition: name.c:38
uint16_t n
Definition: btrfs.h:259
#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 3136 of file btrfs.c.

3136  {
3137  LIST_ENTRY* le;
3138 
3139  le = Vcb->devices.Flink;
3140 
3141  while (le != &Vcb->devices) {
3142  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3143 
3144  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
3145  InsertHeadList(le->Blink, &dev->list_entry);
3146  return;
3147  }
3148 
3149  le = le->Flink;
3150  }
3151 
3152  InsertTailList(&Vcb->devices, &dev->list_entry);
3153 }
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define InsertTailList(ListHead, Entry)
Definition: devices.h:37
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
InsertTailList & Vcb
Definition: btrfs.c:2902
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
uint64_t dev_id
Definition: btrfs.h:162
Definition: typedefs.h:117
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:520
uint64_t dev_id

Referenced by find_device_from_uuid(), and load_chunk_root().

◆ calculate_total_space()

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

Definition at line 574 of file btrfs.c.

574  {
575  uint64_t nfactor, dfactor, sectors_used;
576 
577  if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags & BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
578  nfactor = 1;
579  dfactor = 2;
580  } else if (Vcb->data_flags & BLOCK_FLAG_RAID5) {
581  nfactor = Vcb->superblock.num_devices - 1;
582  dfactor = Vcb->superblock.num_devices;
583  } else if (Vcb->data_flags & BLOCK_FLAG_RAID6) {
584  nfactor = Vcb->superblock.num_devices - 2;
585  dfactor = Vcb->superblock.num_devices;
586  } else {
587  nfactor = 1;
588  dfactor = 1;
589  }
590 
591  sectors_used = Vcb->superblock.bytes_used / Vcb->superblock.sector_size;
592 
593  *totalsize = (Vcb->superblock.total_bytes / Vcb->superblock.sector_size) * nfactor / dfactor;
594  *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
595 }
#define freespace(fs, percentreserved)
Definition: fs.h:640
#define BLOCK_FLAG_RAID10
Definition: shellext.h:81
InsertTailList & Vcb
Definition: btrfs.c:2902
#define BLOCK_FLAG_RAID6
Definition: shellext.h:83
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_cpu()

static void check_cpu ( )
static

Definition at line 5604 of file btrfs.c.

5604  {
5605  unsigned int cpuInfo[4];
5606 #ifndef _MSC_VER
5607  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
5608  have_sse42 = cpuInfo[2] & bit_SSE4_2;
5609  have_sse2 = cpuInfo[3] & bit_SSE2;
5610 #else
5611  __cpuid(cpuInfo, 1);
5612  have_sse42 = cpuInfo[2] & (1 << 20);
5613  have_sse2 = cpuInfo[3] & (1 << 26);
5614 #endif
5615 
5616  if (have_sse42)
5617  TRACE("SSE4.2 is supported\n");
5618  else
5619  TRACE("SSE4.2 not supported\n");
5620 
5621  if (have_sse2)
5622  TRACE("SSE2 is supported\n");
5623  else
5624  TRACE("SSE2 is not supported\n");
5625 }
bool have_sse2
Definition: btrfs.c:69
#define TRACE(s)
Definition: solgame.cpp:4
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
bool have_sse42
Definition: btrfs.c:69

Referenced by _Function_class_().

◆ chunk_estimate_phys_size()

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

Definition at line 3733 of file btrfs.c.

3733  {
3734  uint64_t nfactor, dfactor;
3735 
3736  if (c->chunk_item->type & BLOCK_FLAG_DUPLICATE || c->chunk_item->type & BLOCK_FLAG_RAID1 || c->chunk_item->type & BLOCK_FLAG_RAID10) {
3737  nfactor = 1;
3738  dfactor = 2;
3739  } else if (c->chunk_item->type & BLOCK_FLAG_RAID5) {
3740  nfactor = Vcb->superblock.num_devices - 1;
3741  dfactor = Vcb->superblock.num_devices;
3742  } else if (c->chunk_item->type & BLOCK_FLAG_RAID6) {
3743  nfactor = Vcb->superblock.num_devices - 2;
3744  dfactor = Vcb->superblock.num_devices;
3745  } else {
3746  nfactor = 1;
3747  dfactor = 1;
3748  }
3749 
3750  return u * dfactor / nfactor;
3751 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define BLOCK_FLAG_RAID10
Definition: shellext.h:81
InsertTailList & Vcb
Definition: btrfs.c:2902
const GLubyte * c
Definition: glext.h:8905
#define BLOCK_FLAG_RAID6
Definition: shellext.h:83
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 5473 of file btrfs.c.

5473  {
5474  LIST_ENTRY* le;
5475  bool locked;
5476  range_lock* rl;
5477 
5478  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5479  if (!rl) {
5480  ERR("out of memory\n");
5481  return;
5482  }
5483 
5484  rl->start = start;
5485  rl->length = length;
5486  rl->thread = PsGetCurrentThread();
5487 
5488  while (true) {
5489  locked = false;
5490 
5491  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5492 
5493  le = c->range_locks.Flink;
5494  while (le != &c->range_locks) {
5496 
5497  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5498  locked = true;
5499  break;
5500  }
5501 
5502  le = le->Flink;
5503  }
5504 
5505  if (!locked) {
5506  InsertTailList(&c->range_locks, &rl->list_entry);
5507 
5508  ExReleaseResourceLite(&c->range_locks_lock);
5509  return;
5510  }
5511 
5512  KeClearEvent(&c->range_locks_event);
5513 
5514  ExReleaseResourceLite(&c->range_locks_lock);
5515 
5516  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, false, NULL);
5517  }
5518 }
uint64_t start
Definition: btrfs_drv.h:539
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
uint64_t length
Definition: btrfs_drv.h:540
#define InsertTailList(ListHead, Entry)
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY list_entry
Definition: btrfs_drv.h:542
InsertTailList & Vcb
Definition: btrfs.c:2902
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:541
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
GLuint start
Definition: gl.h:1545
Definition: list.h:27
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

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

◆ chunk_unlock_range()

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

Definition at line 5520 of file btrfs.c.

5520  {
5521  LIST_ENTRY* le;
5522 
5523  ExAcquireResourceExclusiveLite(&c->range_locks_lock, true);
5524 
5525  le = c->range_locks.Flink;
5526  while (le != &c->range_locks) {
5528 
5529  if (rl->start == start && rl->length == length) {
5531  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5532  break;
5533  }
5534 
5535  le = le->Flink;
5536  }
5537 
5538  KeSetEvent(&c->range_locks_event, 0, false);
5539 
5540  ExReleaseResourceLite(&c->range_locks_lock);
5541 }
uint64_t start
Definition: btrfs_drv.h:539
uint64_t length
Definition: btrfs_drv.h:540
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY list_entry
Definition: btrfs_drv.h:542
InsertTailList & Vcb
Definition: btrfs.c:2902
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
Definition: typedefs.h:117
GLuint start
Definition: gl.h:1545
Definition: list.h:27

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

◆ close_file()

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

Definition at line 1842 of file btrfs.c.

1842  {
1843  fcb* fcb;
1844  ccb* ccb;
1845  file_ref* fileref = NULL;
1846  LONG open_files;
1847 
1848  UNUSED(Irp);
1849 
1850  TRACE("FileObject = %p\n", FileObject);
1851 
1852  fcb = FileObject->FsContext;
1853  if (!fcb) {
1854  TRACE("FCB was NULL, returning success\n");
1855  return STATUS_SUCCESS;
1856  }
1857 
1858  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1859 
1860  ccb = FileObject->FsContext2;
1861 
1862  TRACE("close called for fcb %p)\n", fcb);
1863 
1864  // FIXME - make sure notification gets sent if file is being deleted
1865 
1866  if (ccb) {
1867  if (ccb->query_string.Buffer)
1869 
1870  if (ccb->filename.Buffer)
1872 
1873  // FIXME - use refcounts for fileref
1874  fileref = ccb->fileref;
1875 
1876  if (fcb->Vcb->running_sends > 0) {
1877  bool send_cancelled = false;
1878 
1879  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
1880 
1881  if (ccb->send) {
1882  ccb->send->cancelling = true;
1883  send_cancelled = true;
1884  KeSetEvent(&ccb->send->cleared_event, 0, false);
1885  }
1886 
1887  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1888 
1889  if (send_cancelled) {
1890  while (ccb->send) {
1891  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
1892  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1893  }
1894  }
1895  }
1896 
1897  ExFreePool(ccb);
1898  }
1899 
1901 
1902  if (open_files == 0 && fcb->Vcb->removing) {
1903  uninit(fcb->Vcb);
1904  return STATUS_SUCCESS;
1905  }
1906 
1907  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1908  return STATUS_SUCCESS;
1909 
1910  if (fileref)
1911  free_fileref(fileref);
1912  else
1913  free_fcb(fcb);
1914 
1915  return STATUS_SUCCESS;
1916 }
void free_fcb(_Inout_ fcb *fcb)
Definition: btrfs.c:1653
_In_ PIRP Irp
Definition: csq.h:116
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1918
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UNICODE_STRING filename
Definition: btrfs_drv.h:385
UNICODE_STRING query_string
Definition: btrfs_drv.h:377
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define UNUSED(x)
Definition: btrfs_drv.h:86
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TRACE(s)
Definition: solgame.cpp:4
struct _fcb fcb
Definition: btrfs_drv.h:1314
KEVENT cleared_event
Definition: btrfs_drv.h:366
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define InterlockedDecrement
Definition: armddk.h:52
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
void free_fileref(_Inout_ file_ref *fr)
Definition: btrfs.c:1768
bool cancelling
Definition: btrfs_drv.h:367
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:384
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define VPB_MOUNTED
Definition: iotypes.h:1764
struct _device_extension * Vcb
Definition: btrfs_drv.h:283
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
send_info * send
Definition: btrfs_drv.h:393

Referenced by _Dispatch_type_().

◆ create_calc_threads()

static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 3971 of file btrfs.c.

3971  {
3973  OBJECT_ATTRIBUTES oa;
3974  ULONG i;
3975 
3976  Vcb->calcthreads.num_threads = get_num_of_processors();
3977 
3978  Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
3979  if (!Vcb->calcthreads.threads) {
3980  ERR("out of memory\n");
3982  }
3983 
3984  InitializeListHead(&Vcb->calcthreads.job_list);
3985  ExInitializeResourceLite(&Vcb->calcthreads.lock);
3986  KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, false);
3987 
3988  RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads);
3989 
3991 
3992  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
3993  NTSTATUS Status;
3994 
3995  Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
3996  KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, false);
3997 
3998  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, &oa, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
3999  if (!NT_SUCCESS(Status)) {
4000  ULONG j;
4001 
4002  ERR("PsCreateSystemThread returned %08x\n", Status);
4003 
4004  for (j = 0; j < i; j++) {
4005  Vcb->calcthreads.threads[i].quit = true;
4006  }
4007 
4008  KeSetEvent(&Vcb->calcthreads.event, 0, false);
4009 
4010  return Status;
4011  }
4012  }
4013 
4014  return STATUS_SUCCESS;
4015 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:4150
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ALLOC_TAG
Definition: btrfs_drv.h:91
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
PVOID DeviceExtension
Definition: env_spec_w32.h:418
uint32_t get_num_of_processors()
Definition: btrfs.c:3957
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
InsertTailList & Vcb
Definition: btrfs.c:2902
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
unsigned int ULONG
Definition: retypes.h:1
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231

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

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

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

◆ DEFINE_GUID()

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

◆ delete_fileref()

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

Definition at line 2187 of file btrfs.c.

2187  {
2188  LARGE_INTEGER newlength, time;
2189  BTRFS_TIME now;