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

Go to the source code of this file.

Classes

struct  read_context
 

Macros

#define INCOMPAT_SUPPORTED
 
#define COMPAT_RO_SUPPORTED   (BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE | BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID)
 

Functions

 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)
 
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 *totalsize, _Out_ UINT64 *freespace)
 
static BOOL lie_about_fs_type ()
 
 _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 id, _Out_ root **rootptr, _In_ BOOL no_tree, _In_ UINT64 offset, _In_opt_ PIRP Irp)
 
static NTSTATUS set_label (_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
 
 _Dispatch_type_ (IRP_MJ_SET_VOLUME_INFORMATION)
 
static WCHARfile_desc_fcb (_In_ fcb *fcb)
 
WCHARfile_desc_fileref (_In_ file_ref *fileref)
 
_Ret_z_ WCHARfile_desc (_In_ PFILE_OBJECT FileObject)
 
void send_notification_fileref (_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
 
void send_notification_fcb (_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
 
void mark_fcb_dirty (_In_ fcb *fcb)
 
void mark_fileref_dirty (_In_ file_ref *fileref)
 
void free_fcb (_Inout_ fcb *fcb)
 
void reap_fcb (fcb *fcb)
 
void reap_fcbs (device_extension *Vcb)
 
void free_fileref (_Inout_ file_ref *fr)
 
void reap_fileref (device_extension *Vcb, file_ref *fr)
 
void reap_filerefs (device_extension *Vcb, file_ref *fr)
 
void uninit (_In_ device_extension *Vcb)
 
NTSTATUS delete_fileref (_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _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 inode, _In_ UINT8 type, _In_ BOOL dotfile, _In_ BOOL ignore_xa, _In_opt_ PIRP Irp)
 
NTSTATUS sync_read_phys (_In_ PDEVICE_OBJECT DeviceObject, _In_ UINT64 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_ UINT64 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_ BOOLEAN Override, _Out_opt_ IO_STATUS_BLOCK *iosb)
 
 _Requires_exclusive_lock_held_ (Vcb->tree_lock) static NTSTATUS add_root(_Inout_ device_extension *Vcb
 
 if (!r)
 
 RtlZeroMemory (r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
 
 if (!r->nonpaged)
 
 if (tp)
 
else RtlZeroMemoryr (ROOT_ITEM)
 
 if (!Vcb->readonly &&(r->id==BTRFS_ROOT_ROOT||r->id==BTRFS_ROOT_FSTREE||(r->id >=0x100 &&!(r->id &0xf000000000000000))))
 
 switch (r->id)
 
static NTSTATUS look_for_roots (_Requires_exclusive_lock_held_(_Curr_->tree_lock) _In_ device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS find_disk_holes (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ device *dev, _In_opt_ PIRP Irp)
 
static void add_device_to_list (_In_ device_extension *Vcb, _In_ device *dev)
 
_Ret_maybenull_ devicefind_device_from_uuid (_In_ device_extension *Vcb, _In_ BTRFS_UUID *uuid)
 
static BOOL is_device_removable (_In_ PDEVICE_OBJECT devobj)
 
static ULONG get_device_change_count (_In_ PDEVICE_OBJECT devobj)
 
void init_device (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ BOOL get_nums)
 
static NTSTATUS load_chunk_root (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
void protect_superblocks (_Inout_ chunk *c)
 
NTSTATUS find_chunk_usage (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS load_sys_chunks (_In_ device_extension *Vcb)
 
static _Ret_maybenull_ rootfind_default_subvol (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
void init_file_cache (_In_ PFILE_OBJECT FileObject, _In_ CC_FILE_SIZES *ccfs)
 
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 *) sb->checksum))
 
 if (pnp_name.Length==0) *no_pnp
 
 volume_arrival (drvobj, &pnp_name)
 
static BOOL still_has_superblock (_In_ PDEVICE_OBJECT device)
 
static NTSTATUS mount_vol (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS verify_device (_In_ device_extension *Vcb, _Inout_ device *dev)
 
static NTSTATUS verify_volume (_In_ PDEVICE_OBJECT devobj)
 
 _Dispatch_type_ (IRP_MJ_FILE_SYSTEM_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_LOCK_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_SHUTDOWN)
 
 _Dispatch_type_ (IRP_MJ_POWER)
 
 _Dispatch_type_ (IRP_MJ_SYSTEM_CONTROL)
 
BOOL is_file_name_valid (_In_ PUNICODE_STRING us, _In_ BOOL posix)
 
void chunk_lock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ UINT64 start, _In_ UINT64 length)
 
void chunk_unlock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ UINT64 start, _In_ UINT64 length)
 
void log_device_error (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ int error)
 
static void check_cpu ()
 
 _Function_class_ (KSTART_ROUTINE)
 
NTSTATUS AddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
 
 _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
 
BOOL have_sse42 = FALSE
 
BOOL have_sse2 = FALSE
 
UINT64 num_reads = 0
 
LIST_ENTRY uid_map_list
 
LIST_ENTRY gid_map_list
 
LIST_ENTRY VcbList
 
ERESOURCE global_loading_lock
 
UINT32 debug_log_level = 0
 
UINT32 mount_compress = 0
 
UINT32 mount_compress_force = 0
 
UINT32 mount_compress_type = 0
 
UINT32 mount_zlib_level = 3
 
UINT32 mount_zstd_level = 3
 
UINT32 mount_flush_interval = 30
 
UINT32 mount_max_inline = 2048
 
UINT32 mount_skip_balance = 0
 
UINT32 mount_no_barrier = 0
 
UINT32 mount_no_trim = 0
 
UINT32 mount_clear_cache = 0
 
UINT32 mount_allow_degraded = 0
 
UINT32 mount_readonly = 0
 
UINT32 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
 
BOOL diskacc = FALSE
 
voidnotification_entry = NULL
 
voidnotification_entry2 = NULL
 
voidnotification_entry3 = NULL
 
ERESOURCE pdo_list_lock
 
ERESOURCE mapping_lock
 
LIST_ENTRY pdo_list
 
BOOL finished_probing = FALSE
 
HANDLE degraded_wait_handle = NULL
 
HANDLE mountmgr_thread_handle = NULL
 
BOOL degraded_wait = TRUE
 
KEVENT mountmgr_thread_event
 
BOOL shutting_down = FALSE
 
_In_ UINT64 id = id
 
_In_ UINT64 _In_ UINT64 addr
 
_In_ UINT64 _In_ UINT64 _In_ UINT64 generation = generation
 
_In_ UINT64 _In_ UINT64 _In_ UINT64 _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
 
InitializeListHeadr
 
r nonpaged = ExAllocatePoolWithTag(NonPagedPool, sizeof(root_nonpaged), ALLOC_TAG)
 
r lastinode = 0
 
InsertTailListVcb
 
return STATUS_SUCCESS
 
ULONG to_read = DeviceObject->SectorSize == 0 ? sizeof(superblock) : (ULONG)sector_align(sizeof(superblock), DeviceObject->SectorSize)
 
superblocksb = ExAllocatePoolWithTag(NonPagedPool, to_read, ALLOC_TAG)
 
UINT32 crc32 = ~calc_crc32c(0xffffffff, (UINT8*)&sb->uuid, (ULONG)sizeof(superblock) - sizeof(sb->checksum))
 
UNICODE_STRING pnp_name
 
const GUIDguid
 
 Status = sync_read_phys(DeviceObject, superblock_addrs[0], to_read, (PUCHAR)sb, TRUE)
 
DeviceObject Flags &pnp_name Buffer = NULL
 
 else
 
end __pad0__
 

Macro Definition Documentation

◆ COMPAT_RO_SUPPORTED

◆ INCOMPAT_SUPPORTED

#define INCOMPAT_SUPPORTED
Value:
BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO | BTRFS_INCOMPAT_FLAGS_BIG_METADATA | BTRFS_INCOMPAT_FLAGS_RAID56 | \
BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA | BTRFS_INCOMPAT_FLAGS_NO_HOLES | \
BTRFS_INCOMPAT_FLAGS_COMPRESS_ZSTD)
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:111
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:105
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:103
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:108
#define BTRFS_INCOMPAT_FLAGS_NO_HOLES
Definition: btrfs.h:112
#define BTRFS_INCOMPAT_FLAGS_RAID56
Definition: btrfs.h:110
#define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL
Definition: btrfs.h:104

Definition at line 49 of file btrfs.c.

Function Documentation

◆ _Dispatch_type_() [1/10]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 467 of file btrfs.c.

470  {
471 #else
472 static NTSTATUS drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
473 #endif
477  BOOL top_level;
478 
480 
481  TRACE("close\n");
482 
483  top_level = is_top_level(Irp);
484 
485  if (DeviceObject == master_devobj) {
486  TRACE("Closing file system\n");
488  goto end;
489  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
491  goto end;
492  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
494  goto end;
495  }
496 
498 
499  // FIXME - unmount if called for volume
500  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
501 
503 
504 end:
505  Irp->IoStatus.Status = Status;
506  Irp->IoStatus.Information = 0;
507 
509 
510  if (top_level)
512 
513  TRACE("returning %08x\n", Status);
514 
516 
517  return Status;
518 }
#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:3909
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
GLuint GLuint end
Definition: gl.h:1545
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
unsigned int BOOL
Definition: ntddk_ex.h:94
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:61
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:2709
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
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:2812
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1702
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:48
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ _Dispatch_type_() [2/10]

_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 520 of file btrfs.c.

523  {
524 #else
525 static NTSTATUS drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
526 #endif
530  fcb* fcb = FileObject->FsContext;
532  BOOL top_level;
533 
535 
536  TRACE("flush buffers\n");
537 
538  top_level = is_top_level(Irp);
539 
540  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
542  goto end;
543  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
545  goto end;
546  }
547 
548  if (!fcb) {
549  ERR("fcb was NULL\n");
551  goto end;
552  }
553 
554  if (fcb == Vcb->volume_fcb) {
556  goto end;
557  }
558 
559  Irp->IoStatus.Information = 0;
560 
561  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
562 
564  Irp->IoStatus.Status = Status;
565 
566  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
567  CcFlushCache(&fcb->nonpaged->segment_object, NULL, 0, &Irp->IoStatus);
568 
569  if (fcb->Header.PagingIoResource) {
570  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
571  ExReleaseResourceLite(fcb->Header.PagingIoResource);
572  }
573 
574  Status = Irp->IoStatus.Status;
575  }
576 
577 end:
579 
580  TRACE("returning %08x\n", Status);
581 
582  if (top_level)
584 
586 
587  return Status;
588 }
#define TRUE
Definition: types.h:120
#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
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:310
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
GLuint GLuint end
Definition: gl.h:1545
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
unsigned int BOOL
Definition: ntddk_ex.h:94
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:81
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
InsertTailList & Vcb
Definition: btrfs.c:2709
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:256
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
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:2812
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:257
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
UINT8 type
Definition: btrfs_drv.h:264
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1618
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ _Dispatch_type_() [3/10]

_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 729 of file btrfs.c.

732  {
733 #else
734 static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
735 #endif
738  ULONG BytesCopied = 0;
740  BOOL top_level;
741 
743 
744  TRACE("query volume information\n");
745  top_level = is_top_level(Irp);
746 
747  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
749  goto end;
750  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
752  goto end;
753  }
754 
756 
758 
759  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
761  {
762  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
763  BOOL overflow = FALSE;
764 #ifndef __REACTOS__
765  static const WCHAR ntfs[] = L"NTFS";
766 #endif
767  static const WCHAR btrfs[] = L"Btrfs";
768  const WCHAR* fs_name;
769  ULONG fs_name_len, orig_fs_name_len;
770 
771 #ifndef __REACTOS__
772  if (Irp->RequestorMode == UserMode && lie_about_fs_type()) {
773  fs_name = ntfs;
774  orig_fs_name_len = fs_name_len = sizeof(ntfs) - sizeof(WCHAR);
775  } else {
776  fs_name = btrfs;
777  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
778  }
779 #else
780  fs_name = btrfs;
781  orig_fs_name_len = fs_name_len = sizeof(btrfs) - sizeof(WCHAR);
782 #endif
783 
784  TRACE("FileFsAttributeInformation\n");
785 
786  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
787  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
788  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
789  else
790  fs_name_len = 0;
791 
792  overflow = TRUE;
793  }
794 
795  data->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES | FILE_CASE_SENSITIVE_SEARCH |
799  if (Vcb->readonly)
800  data->FileSystemAttributes |= FILE_READ_ONLY_VOLUME;
801 
802  // should also be FILE_FILE_COMPRESSION when supported
803  data->MaximumComponentNameLength = 255; // FIXME - check
804  data->FileSystemNameLength = orig_fs_name_len;
805  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
806 
807  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
809  break;
810  }
811 
813  {
814  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
815 
816  TRACE("FileFsDeviceInformation\n");
817 
819 
820  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
821  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
822  ExReleaseResourceLite(&Vcb->tree_lock);
823 
824  if (Vcb->readonly)
826  else
828 
831 
832  break;
833  }
834 
836  {
837  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
838 
839  TRACE("FileFsFullSizeInformation\n");
840 
843  ffsi->SectorsPerAllocationUnit = 1;
844  ffsi->BytesPerSector = Vcb->superblock.sector_size;
845 
848 
849  break;
850  }
851 
853  {
854  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
855 
856  TRACE("FileFsObjectIdInformation\n");
857 
858  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
859  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
860 
863 
864  break;
865  }
866 
868  {
869  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
870 
871  TRACE("FileFsSizeInformation\n");
872 
874  ffsi->SectorsPerAllocationUnit = 1;
875  ffsi->BytesPerSector = Vcb->superblock.sector_size;
876 
879 
880  break;
881  }
882 
884  {
885  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
887  BOOL overflow = FALSE;
888  ULONG label_len, orig_label_len;
889 
890  TRACE("FileFsVolumeInformation\n");
891  TRACE("max length = %u\n", IrpSp->Parameters.QueryVolume.Length);
892 
893  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
894 
895  Status = RtlUTF8ToUnicodeN(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
896  if (!NT_SUCCESS(Status)) {
897  ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
898  ExReleaseResourceLite(&Vcb->tree_lock);
899  break;
900  }
901 
902  orig_label_len = label_len;
903 
904  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len) {
905  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR))
906  label_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_VOLUME_INFORMATION) + sizeof(WCHAR);
907  else
908  label_len = 0;
909 
910  overflow = TRUE;
911  }
912 
913  TRACE("label_len = %u\n", label_len);
914 
915  ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
916  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];
917  ffvi.VolumeLabelLength = orig_label_len;
918  ffvi.SupportsObjects = FALSE;
919 
920  RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
921 
922  if (label_len > 0) {
923  ULONG bytecount;
924 
925  Status = RtlUTF8ToUnicodeN(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
927  ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
928  ExReleaseResourceLite(&Vcb->tree_lock);
929  break;
930  }
931 
932  TRACE("label = %.*S\n", label_len / sizeof(WCHAR), data->VolumeLabel);
933  }
934 
935  ExReleaseResourceLite(&Vcb->tree_lock);
936 
937  BytesCopied = sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len;
939  break;
940  }
941 
942 #ifndef __REACTOS__
943 #ifdef _MSC_VER // not in mingw yet
944  case FileFsSectorSizeInformation:
945  {
946  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
947 
948  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
949  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
950  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
951  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
952  data->ByteOffsetForSectorAlignment = 0;
953  data->ByteOffsetForPartitionAlignment = 0;
954 
955  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
956 
957  if (Vcb->trim && !Vcb->options.no_trim)
958  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
959 
960  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
961 
962  break;
963  }
964 #endif
965 #endif /* __REACTOS__ */
966 
967  default:
969  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
970  break;
971  }
972 
974  Irp->IoStatus.Information = 0;
975  else
976  Irp->IoStatus.Information = BytesCopied;
977 
978 end:
979  Irp->IoStatus.Status = Status;
980 
982 
983  if (top_level)
985 
986  TRACE("query volume information returning %08x\n", Status);
987 
989 
990  return Status;
991 }
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
#define TRUE
Definition: types.h:120
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:316
#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:3909
NTSTATUS WINAPI RtlUTF8ToUnicodeN(PWSTR uni_dest, ULONG uni_bytes_max, PULONG uni_bytes_written, PCCH utf8_src, ULONG utf8_bytes)
Definition: reactos.cpp:21
#define FILE_SUPPORTS_REPARSE_POINTS
Definition: from_kernel.h:240
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
GLuint GLuint end
Definition: gl.h:1545
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
unsigned int BOOL
Definition: ntddk_ex.h:94
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
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2709
#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:132
#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:636
#define FILE_CASE_SENSITIVE_SEARCH
Definition: from_kernel.h:233
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
static void calculate_total_space(_In_ device_extension *Vcb, _Out_ UINT64 *totalsize, _Out_ UINT64 *freespace)
Definition: btrfs.c:590
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
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
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define FILE_SUPPORTS_SPARSE_FILES
Definition: from_kernel.h:239
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
#define min(a, b)
Definition: monoChain.cc:55
static BOOL lie_about_fs_type()
Definition: btrfs.c:620
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
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
unsigned long long UINT64
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2745
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 1187 of file btrfs.c.

1190  {
1191 #else
1192 static NTSTATUS drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
1193 #endif
1196  NTSTATUS Status;
1197  BOOL top_level;
1198 
1200 
1201  TRACE("set volume information\n");
1202 
1203  top_level = is_top_level(Irp);
1204 
1205  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1207  goto end;
1208  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1210  goto end;
1211  }
1212 
1214 
1215  if (Vcb->readonly) {
1217  goto end;
1218  }
1219 
1220  if (Vcb->removing || Vcb->locked) {
1222  goto end;
1223  }
1224 
1225  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1227  FIXME("STUB: FileFsControlInformation\n");
1228  break;
1229 
1231  TRACE("FileFsLabelInformation\n");
1232 
1233  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1234  break;
1235 
1237  FIXME("STUB: FileFsObjectIdInformation\n");
1238  break;
1239 
1240  default:
1241  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1242  break;
1243  }
1244 
1245 end:
1246  Irp->IoStatus.Status = Status;
1247  Irp->IoStatus.Information = 0;
1248 
1249  TRACE("returning %08x\n", Status);
1250 
1252 
1253  if (top_level)
1255 
1257 
1258  return Status;
1259 }
#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:3909
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
GLuint GLuint end
Definition: gl.h:1545
unsigned int BOOL
Definition: ntddk_ex.h:94
#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:2709
#define TRACE(s)
Definition: solgame.cpp:4
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1132
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
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
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IO_NO_INCREMENT
Definition: iotypes.h:565
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
NTSTATUS vol_set_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:322

◆ _Dispatch_type_() [5/10]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2181 of file btrfs.c.

2184  {
2185 #else
2186 static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
2187 #endif
2188  NTSTATUS Status;
2192  fcb* fcb = FileObject->FsContext;
2193  BOOL top_level;
2194 
2196 
2197  TRACE("cleanup\n");
2198 
2199  top_level = is_top_level(Irp);
2200 
2201  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2203  goto exit;
2204  } else if (DeviceObject == master_devobj) {
2205  TRACE("closing file system\n");
2207  goto exit;
2208  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2210  goto exit;
2211  }
2212 
2213  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2214  TRACE("FileObject %p already cleaned up\n", FileObject);
2216  goto exit;
2217  }
2218 
2219  if (!fcb) {
2220  ERR("fcb was NULL\n");
2222  goto exit;
2223  }
2224 
2225  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2226  // messages belonging to other devices.
2227 
2228  if (FileObject && FileObject->FsContext) {
2229  LONG oc;
2230  ccb* ccb;
2231  file_ref* fileref;
2232  BOOL locked = TRUE;
2233 
2234  ccb = FileObject->FsContext2;
2235  fileref = ccb ? ccb->fileref : NULL;
2236 
2237  TRACE("cleanup called for FileObject %p\n", FileObject);
2238  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2239 
2240  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
2241 
2243 
2245 
2246  if (ccb)
2247  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2248 
2249  if (fileref) {
2250  oc = InterlockedDecrement(&fileref->open_count);
2251 #ifdef DEBUG_FCB_REFCOUNTS
2252  ERR("fileref %p: open_count now %i\n", fileref, oc);
2253 #endif
2254  }
2255 
2256  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2257  fileref->delete_on_close = TRUE;
2258 
2259  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2260  fileref->delete_on_close = FALSE;
2261 
2262  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2263  TRACE("unlocking volume\n");
2266  }
2267 
2268  if (ccb && ccb->reserving) {
2269  fcb->subvol->reserved = NULL;
2270  ccb->reserving = FALSE;
2271  // FIXME - flush all of subvol's fcbs
2272  }
2273 
2274  if (fileref && oc == 0) {
2275  if (!fcb->Vcb->removing) {
2276  if (fileref && fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2278 
2280 
2281  if (!fileref->fcb->ads || fileref->dc) {
2282  if (fileref->fcb->ads) {
2284  FILE_ACTION_REMOVED, &fileref->dc->name);
2285  } else
2287  }
2288 
2289  ExReleaseResourceLite(fcb->Header.Resource);
2290  locked = FALSE;
2291 
2292  // fileref_lock needs to be acquired before fcb->Header.Resource
2293  ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, TRUE);
2294 
2295  Status = delete_fileref(fileref, FileObject, Irp, &rollback);
2296  if (!NT_SUCCESS(Status)) {
2297  ERR("delete_fileref returned %08x\n", Status);
2299  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2300  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2301  goto exit;
2302  }
2303 
2304  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2305 
2307  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && fcb->nonpaged->segment_object.DataSectionObject) {
2309  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2310 
2311  if (!NT_SUCCESS(iosb.Status)) {
2312  ERR("CcFlushCache returned %08x\n", iosb.Status);
2313  }
2314 
2315  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2316  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
2317  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2318  }
2319 
2320  CcPurgeCacheSection(&fcb->nonpaged->segment_object, NULL, 0, FALSE);
2321 
2322  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %llx, FileSize = %llx, ValidDataLength = %llx)\n",
2323  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2324  }
2325  }
2326 
2327  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2329  }
2330 
2331  if (locked)
2332  ExReleaseResourceLite(fcb->Header.Resource);
2333 
2334  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2335 
2336  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2337  }
2338 
2340 
2341 exit:
2342  TRACE("returning %08x\n", Status);
2343 
2344  Irp->IoStatus.Status = Status;
2345  Irp->IoStatus.Information = 0;
2346 
2348 
2349  if (top_level)
2351 
2353 
2354  return Status;
2355 }
struct _file_ref * parent
Definition: btrfs_drv.h:326
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 TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:349
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:3909
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:325
#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:1347
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
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
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:61
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:81
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG refcount
Definition: btrfs_drv.h:324
InsertTailList & Vcb
Definition: btrfs.c:2709
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:256
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#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:636
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1737
BOOL ads
Definition: btrfs_drv.h:300
dir_child * dc
Definition: btrfs_drv.h:328
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:328
fcb * fcb
Definition: btrfs_drv.h:316
Definition: typedefs.h:117
INODE_ITEM inode_item
Definition: btrfs_drv.h:265
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1334
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
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:2812
UINT64 st_size
Definition: btrfs.h:267
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:257
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:1746
#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:261
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
UINT8 type
Definition: btrfs_drv.h:264
BOOL delete_on_close
Definition: btrfs_drv.h:319
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:1969
#define IO_NO_INCREMENT
Definition: iotypes.h:565
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
BOOL reserving
Definition: btrfs_drv.h:356
SHARE_ACCESS share_access
Definition: btrfs_drv.h:271
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:358
return STATUS_SUCCESS
Definition: btrfs.c:2745
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2292
struct _device_extension * Vcb
Definition: btrfs_drv.h:260
UNICODE_STRING name
Definition: btrfs_drv.h:230
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1336

◆ _Dispatch_type_() [6/10]

_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 4826 of file btrfs.c.

4829  {
4830 #else
4831 static NTSTATUS drv_file_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4832 #endif
4834  NTSTATUS Status;
4836  BOOL top_level;
4837 
4839 
4840  TRACE("file system control\n");
4841 
4842  top_level = is_top_level(Irp);
4843 
4844  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4846  goto end;
4847  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
4849  goto end;
4850  }
4851 
4853 
4855 
4856  Irp->IoStatus.Information = 0;
4857 
4858  switch (IrpSp->MinorFunction) {
4859  case IRP_MN_MOUNT_VOLUME:
4860  TRACE("IRP_MN_MOUNT_VOLUME\n");
4861 
4863  break;
4864 
4865  case IRP_MN_KERNEL_CALL:
4866  TRACE("IRP_MN_KERNEL_CALL\n");
4867 
4868  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4869  break;
4870 
4872  TRACE("IRP_MN_USER_FS_REQUEST\n");
4873 
4874  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4875  break;
4876 
4877  case IRP_MN_VERIFY_VOLUME:
4878  TRACE("IRP_MN_VERIFY_VOLUME\n");
4879 
4881 
4882  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
4883  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
4884  Vcb->removing = TRUE;
4885  ExReleaseResourceLite(&Vcb->tree_lock);
4886  }
4887 
4888  break;
4889 
4890  default:
4891  break;
4892  }
4893 
4894 end:
4895  TRACE("returning %08x\n", Status);
4896 
4897  if (Irp) {
4898  Irp->IoStatus.Status = Status;
4899 
4901  }
4902 
4903  if (top_level)
4905 
4907 
4908  return Status;
4909 }
#define TRUE
Definition: types.h:120
#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
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
GLuint GLuint end
Definition: gl.h:1545
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4048
unsigned int BOOL
Definition: ntddk_ex.h:94
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:342
InsertTailList & Vcb
Definition: btrfs.c:2709
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4046
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, UINT32 type)
Definition: fsctl.c:4803
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4051
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:635
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
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
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IO_NO_INCREMENT
Definition: iotypes.h:565
static NTSTATUS verify_volume(_In_ PDEVICE_OBJECT devobj)
Definition: btrfs.c:4767
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
#define VPB_MOUNTED
Definition: iotypes.h:1763
static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: btrfs.c:4005

◆ _Dispatch_type_() [7/10]

_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 4911 of file btrfs.c.

4914  {
4915 #else
4916 static NTSTATUS drv_lock_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4917 #endif
4918  NTSTATUS Status;
4920  fcb* fcb = IrpSp->FileObject->FsContext;
4922  BOOL top_level;
4923 
4925 
4926  top_level = is_top_level(Irp);
4927 
4928  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4930 
4931  Irp->IoStatus.Status = Status;
4933 
4934  goto exit;
4935  }
4936 
4937  TRACE("lock control\n");
4938 
4940 
4941  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
4942 
4943 exit:
4944  TRACE("returning %08x\n", Status);
4945 
4946  if (top_level)
4948 
4950 
4951  return Status;
4952 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
unsigned int BOOL
Definition: ntddk_ex.h:94
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:267
InsertTailList & Vcb
Definition: btrfs.c:2709
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:256
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1153
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
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:2812
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS vol_lock_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:348
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1618
void exit(int exitcode)
Definition: _exit.c:33

◆ _Dispatch_type_() [8/10]

_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 4954 of file btrfs.c.

4957  {
4958 #else
4959 static NTSTATUS drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4960 #endif
4961  NTSTATUS Status;
4962  BOOL top_level;
4964  LIST_ENTRY* le;
4965 
4967 
4968  TRACE("shutdown\n");
4969 
4970  top_level = is_top_level(Irp);
4971 
4972  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4974  goto end;
4975  }
4976 
4978 
4979  shutting_down = TRUE;
4981 
4982  le = VcbList.Flink;
4983  while (le != &VcbList) {
4984  BOOL open_files;
4985  LIST_ENTRY* le2 = le->Flink;
4986 
4988 
4989  TRACE("shutting down Vcb %p\n", Vcb);
4990 
4991  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
4992  Vcb->removing = TRUE;
4993  open_files = Vcb->open_files > 0;
4994 
4995  if (Vcb->need_write && !Vcb->readonly) {
4996  Status = do_write(Vcb, Irp);
4997  if (!NT_SUCCESS(Status))
4998  ERR("do_write returned %08x\n", Status);
4999  }
5000 
5001  free_trees(Vcb);
5002 
5003  ExReleaseResourceLite(&Vcb->tree_lock);
5004 
5005  if (!open_files)
5006  uninit(Vcb);
5007 
5008  le = le2;
5009  }
5010 
5011 #ifdef _DEBUG
5012  if (comfo) {
5013  ObDereferenceObject(comfo);
5014  comdo = NULL;
5015  comfo = NULL;
5016  }
5017 #endif
5018 
5019 end:
5020  Irp->IoStatus.Status = Status;
5021  Irp->IoStatus.Information = 0;
5022 
5024 
5025  if (top_level)
5027 
5029 
5030  return Status;
5031 }
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LIST_ENTRY VcbList
Definition: btrfs.c:67
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7337
LONG NTSTATUS
Definition: precomp.h:26
BOOL shutting_down
Definition: btrfs.c:99
Status
Definition: btrfs.c:3909
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
GLuint GLuint end
Definition: gl.h:1545
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1778
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
unsigned int BOOL
Definition: ntddk_ex.h:94
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void free_trees(device_extension *Vcb)
Definition: treefuncs.c:793
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
InsertTailList & Vcb
Definition: btrfs.c:2709
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS vol_shutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:867
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
KEVENT mountmgr_thread_event
Definition: btrfs.c:98
Definition: list.h:27
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ _Dispatch_type_() [9/10]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5033 of file btrfs.c.

5036  {
5037 #else
5038 static NTSTATUS drv_power(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
5039 #endif
5040  NTSTATUS Status;
5042  BOOL top_level;
5043 
5045 
5046  top_level = is_top_level(Irp);
5047 
5048  Irp->IoStatus.Information = 0;
5049 
5050  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5052 
5053  Irp->IoStatus.Status = Status;
5055 
5056  goto exit;
5057  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5059 
5060  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5061 
5062  goto exit;
5063  }
5064 
5066  Irp->IoStatus.Status = Status;
5068 
5069 exit:
5070  if (top_level)
5072 
5074 
5075  return Status;
5076 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
unsigned int BOOL
Definition: ntddk_ex.h:94
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS vol_power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:885
InsertTailList & Vcb
Definition: btrfs.c:2709
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:565
void exit(int exitcode)
Definition: _exit.c:33

◆ _Dispatch_type_() [10/10]

_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5078 of file btrfs.c.

5081  {
5082 #else
5083 static NTSTATUS drv_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
5084 #endif
5085  NTSTATUS Status;
5087  BOOL top_level;
5088 
5090 
5091  top_level = is_top_level(Irp);
5092 
5093  Irp->IoStatus.Information = 0;
5094 
5095  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5097 
5099 
5100  Status = IoCallDriver(vde->pdo, Irp);
5101 
5102  goto exit;
5103  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5105 
5106  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5107 
5108  goto exit;
5109  }
5110 
5111  Status = Irp->IoStatus.Status;
5113 
5114 exit:
5115  if (top_level)
5117 
5119 
5120  return Status;
5121 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:840
#define VCB_TYPE_FS
Definition: btrfs_drv.h:634
unsigned int BOOL
Definition: ntddk_ex.h:94
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:2709
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:565
void exit(int exitcode)
Definition: _exit.c:33

◆ _Function_class_() [1/4]

_Function_class_ ( DRIVER_UNLOAD  )

Definition at line 265 of file btrfs.c.

267  {
268 #else
270 #endif
271  UNICODE_STRING dosdevice_nameW;
272 
273  TRACE("(%p)\n");
274 
275  free_cache();
276 
278 
280 #ifdef __REACTOS__
282 #else
283  IoUnregisterPlugPlayNotificationEx(notification_entry2);
284 #endif
285 
287 #ifdef __REACTOS__
289 #else
290  IoUnregisterPlugPlayNotificationEx(notification_entry3);
291 #endif
292 
293  if (notification_entry)
294 #ifdef __REACTOS__
296 #else
297  IoUnregisterPlugPlayNotificationEx(notification_entry);
298 #endif
299 
300  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
301  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
302 
303  IoDeleteSymbolicLink(&dosdevice_nameW);
305 
306  while (!IsListEmpty(&uid_map_list)) {
308  uid_map* um = CONTAINING_RECORD(le, uid_map, listentry);
309 
310  ExFreePool(um->sid);
311 
312  ExFreePool(um);
313  }
314 
315  while (!IsListEmpty(&gid_map_list)) {
317 
318  ExFreePool(gm->sid);
319  ExFreePool(gm);
320  }
321 
322  // FIXME - free volumes and their devpaths
323 
324 #ifdef _DEBUG
325  if (comfo)
326  ObDereferenceObject(comfo);
327 
328  if (log_handle)
329  ZwClose(log_handle);
330 #endif
331 
334 
335  if (log_device.Buffer)
337 
338  if (log_file.Buffer)
340 
341  if (registry_path.Buffer)
343 
344 #ifdef _DEBUG
345  ExDeleteResourceLite(&log_lock);
346 #endif
348 }
NTSTATUS NTAPI IoUnregisterPlugPlayNotification(IN PVOID NotificationEntry)
Definition: pnpnotify.c:372
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
void * notification_entry3
Definition: btrfs.c:92
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1053
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
UNICODE_STRING log_file
Definition: btrfs.c:85
void free_cache()
Definition: cache.c:116
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
void * notification_entry2
Definition: btrfs.c:92
PSID sid
Definition: btrfs_drv.h:871
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UNICODE_STRING registry_path
Definition: btrfs.c:85
PSID sid
Definition: btrfs_drv.h:865
static const WCHAR dosdevice_name[]
Definition: btrfs.c:56
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
void * notification_entry
Definition: btrfs.c:92
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LIST_ENTRY uid_map_list
Definition: btrfs.c:66
Definition: typedefs.h:117
ERESOURCE mapping_lock
Definition: btrfs.c:93
ERESOURCE global_loading_lock
Definition: btrfs.c:68
#define _In_
Definition: no_sal2.h:204
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
static DRIVER_UNLOAD DriverUnload
Definition: kbdclass.c:17
UNICODE_STRING log_device
Definition: btrfs.c:85
ERESOURCE pdo_list_lock
Definition: btrfs.c:93
LIST_ENTRY gid_map_list
Definition: btrfs.c:66
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2168

◆ _Function_class_() [2/4]

_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 993 of file btrfs.c.

995  {
996 #else
997 static NTSTATUS read_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID conptr) {
998 #endif
999  read_context* context = conptr;
1000 
1002 
1003  context->iosb = Irp->IoStatus;
1004  KeSetEvent(&context->Event, 0, FALSE);
1005 
1007 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
Definition: http.c:6587
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define UNUSED(x)
Definition: btrfs_drv.h:81
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

◆ _Function_class_() [3/4]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 5382 of file btrfs.c.

5384  {
5385 #else
5386 static void degraded_wait_thread(_In_ void* context) {
5387 #endif
5388  KTIMER timer;
5390 
5391  UNUSED(context);
5392 
5393  KeInitializeTimer(&timer);
5394 
5395  delay.QuadPart = -30000000; // wait three seconds
5396  KeSetTimer(&timer, delay, NULL);
5398 
5399  TRACE("timer expired\n");
5400 
5401  degraded_wait = FALSE;
5402 
5405 
5407 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
Definition: http.c:6587
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
HANDLE degraded_wait_handle
Definition: btrfs.c:96
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
BOOL degraded_wait
Definition: btrfs.c:97
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define UNUSED(x)
Definition: btrfs_drv.h:81
#define TRACE(s)
Definition: solgame.cpp:4
void delay(unsigned msec)
Definition: i386rtl.c:32
#define _In_
Definition: no_sal2.h:204
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
return STATUS_SUCCESS
Definition: btrfs.c:2745

◆ _Function_class_() [4/4]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 5518 of file btrfs.c.

5520  {
5521 #else
5523 #endif
5524  NTSTATUS Status;
5526  UNICODE_STRING device_nameW;
5527  UNICODE_STRING dosdevice_nameW;
5529  HANDLE regh;
5530  OBJECT_ATTRIBUTES oa;
5531  ULONG dispos;
5532 
5535 
5536 #ifdef _DEBUG
5537  ExInitializeResourceLite(&log_lock);
5538 #endif
5540 
5543  log_file.Buffer = NULL;
5545 
5548 
5549  if (!registry_path.Buffer) {
5550  ERR("out of memory\n");
5552  }
5553 
5555 
5557 
5558 #ifdef _DEBUG
5559  if (debug_log_level > 0)
5560  init_logging();
5561 
5562  log_started = TRUE;
5563 #endif
5564 
5565  TRACE("DriverEntry\n");
5566 
5567 #ifndef __REACTOS__
5568  check_cpu();
5569 #endif
5570 
5573  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
5574 
5575  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
5576  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
5577 
5578  if (fPsIsDiskCountersEnabled) {
5579  diskacc = fPsIsDiskCountersEnabled();
5580 
5581  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
5583 
5584  if (!fPsUpdateDiskCounters)
5585  diskacc = FALSE;
5586 
5587  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
5589  }
5590 
5591  RtlInitUnicodeString(&name, L"CcCopyReadEx");
5593 
5594  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
5596 
5597  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
5599  } else {
5601  fCcCopyReadEx = NULL;
5602  fCcCopyWriteEx = NULL;
5605  }
5606 
5607  drvobj = DriverObject;
5608 
5610 
5612 
5613 #ifdef __REACTOS__
5614  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
5615  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
5616  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
5617  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
5618  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
5619  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
5620  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
5621  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
5622  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
5623  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
5624  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
5625  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
5626  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
5627  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
5628  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
5629  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
5630  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
5631  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
5632  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
5633  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
5634  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
5636 #else
5659 #endif
5660 
5662 
5663  device_nameW.Buffer = (WCHAR*)device_name;
5664  device_nameW.Length = device_nameW.MaximumLength = sizeof(device_name) - sizeof(WCHAR);
5665  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
5666  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
5667 
5670  if (!NT_SUCCESS(Status)) {
5671  ERR("IoCreateDevice returned %08x\n", Status);
5672  return Status;
5673  }
5674 
5677 
5679 
5680  cde->type = VCB_TYPE_CONTROL;
5681 
5683 
5684  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
5685  if (!NT_SUCCESS(Status)) {
5686  ERR("IoCreateSymbolicLink returned %08x\n", Status);
5687  return Status;
5688  }
5689 
5690  Status = init_cache();
5691  if (!NT_SUCCESS(Status)) {
5692  ERR("init_cache returned %08x\n", Status);
5693  return Status;
5694  }
5695 
5699 
5701 
5704  /* ReactOS specific hack: allow BtrFS driver to start in 1st stage with no hive */
5705 #ifndef __REACTOS__
5706  if (!NT_SUCCESS(Status)) {
5707  ERR("ZwCreateKey returned %08x\n", Status);
5708  return Status;
5709  }
5710 
5711  watch_registry(regh);
5712 #else
5713  if (NT_SUCCESS(Status)) {
5714  watch_registry(regh);
5715  }
5716 #endif
5717 
5718  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
5719  NULL, NULL, 0, &cde->buspdo);
5720  if (!NT_SUCCESS(Status)) {
5721  ERR("IoReportDetectedDevice returned %08x\n", Status);
5722  return Status;
5723  }
5724 
5725  Status = IoRegisterDeviceInterface(cde->buspdo, &BtrfsBusInterface, NULL, &cde->bus_name);
5726  if (!NT_SUCCESS(Status))
5727  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5728 
5730 
5732  if (!NT_SUCCESS(Status))
5733  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5734 
5736 
5738 
5739  Status = PsCreateSystemThread(&degraded_wait_handle, 0, NULL, NULL, NULL, degraded_wait_thread, NULL);
5740  if (!NT_SUCCESS(Status))
5741  WARN("PsCreateSystemThread returned %08x\n", Status);
5742 
5744  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
5745  if (!NT_SUCCESS(Status))
5746  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5747 
5749  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
5750  if (!NT_SUCCESS(Status))
5751  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5752 
5754  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
5755  if (!NT_SUCCESS(Status))
5756  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5757 
5759 
5761 
5762 #ifndef __REACTOS__
5763  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, NULL, NULL, NULL, mountmgr_thread, NULL);
5764  if (!NT_SUCCESS(Status))
5765  WARN("PsCreateSystemThread returned %08x\n", Status);
5766 #endif
5767 
5769 
5770  return STATUS_SUCCESS;
5771 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
BOOL log_started
Definition: btrfs.c:84
#define TRUE
Definition: types.h:120
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:382
NTSTATUS init_cache()
Definition: cache.c:101
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_FLUSH_BUFFERS
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IRP_MJ_SHUTDOWN
void * notification_entry3
Definition: btrfs.c:92
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:87
HANDLE degraded_wait_handle
Definition: btrfs.c:96
LIST_ENTRY VcbList
Definition: btrfs.c:67
#define IRP_MJ_SET_SECURITY
static void check_cpu()
Definition: btrfs.c:5274
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
VOID(* tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1799
static const WCHAR device_name[]
Definition: btrfs.c:55
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:3909
UNICODE_STRING log_file
Definition: btrfs.c:85
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:813
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1195
void watch_registry(HANDLE regh)
Definition: registry.c:1024
void * notification_entry2
Definition: btrfs.c:92
BOOLEAN(* tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1792
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:86
UNICODE_STRING bus_name
Definition: btrfs_drv.h:814
NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
Definition: btrfs.c:5412
#define ALLOC_TAG
Definition: btrfs_drv.h:86
UNICODE_STRING registry_path
Definition: btrfs.c:85
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:96
#define RtlIsNtDdiVersionAvailable
Definition: rtlfuncs.h:3429
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3369
BOOLEAN(* tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1784
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2173
static const WCHAR dosdevice_name[]
Definition: btrfs.c:56
#define IRP_MJ_SET_EA
VOID(* tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1786
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:61
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:90
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:88
#define IRP_MJ_QUERY_EA
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
void * notification_entry
Definition: btrfs.c:92
#define TRACE(s)
Definition: solgame.cpp:4
LIST_ENTRY pdo_list
Definition: btrfs.c:94
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:60
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:89
#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:2179
LIST_ENTRY uid_map_list
Definition: btrfs.c:66
UINT32 debug_log_level
Definition: btrfs.c:69
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:250
#define IRP_MJ_SYSTEM_CONTROL
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:635
Status
Definition: gdiplustypes.h:24
ERESOURCE mapping_lock
Definition: btrfs.c:93
ERESOURCE global_loading_lock
Definition: btrfs.c:68
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2111
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2153
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:5090
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
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
BOOL diskacc
Definition: btrfs.c:91
KEVENT mountmgr_thread_event
Definition: btrfs.c:98
#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:85
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
VOID(* tFsRtlUpdateDiskCounters)(ULONG64 BytesRead, ULONG64 BytesWritten)
Definition: btrfs_drv.h:1801
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
BOOL finished_probing
Definition: btrfs.c:95
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
ERESOURCE pdo_list_lock
Definition: btrfs.c:93
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:984
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2176
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG const UNICODE_STRING ULONG PULONG dispos
Definition: reg.c:130
#define IRP_MJ_CLEANUP
Definition: name.c:36
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
#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
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
LIST_ENTRY gid_map_list
Definition: btrfs.c:66
BOOLEAN(* tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1789
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:812
void read_registry(PUNICODE_STRING regpath, BOOL refresh)
Definition: registry.c:763
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
GLuint const GLchar * name
Definition: glext.h:6031

◆ _Requires_exclusive_lock_held_()

_Requires_exclusive_lock_held_ ( Vcb->  tree_lock)

◆ _Success_() [1/2]

_Success_ ( return  = = 0)

Definition at line 391 of file btrfs.c.

392  {
393  DIR_ITEM* xa = (DIR_ITEM*)item;
394  USHORT xasize;
395 
396  while (TRUE) {
397  if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m + xa->n)) {
398  WARN("DIR_ITEM is truncated\n");
399  return FALSE;
400  }
401 
402  if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name, xa->n) == xa->n) {
403  TRACE("found xattr %s\n", name);
404 
405  *datalen = xa->m;
406 
407  if (xa->m > 0) {
409  if (!*data) {
410  ERR("out of memory\n");
411  return FALSE;
412  }
413 
414  RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
415  } else
416  *data = NULL;
417 
418  return TRUE;
419  }
420 
421  xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
422 
423  if (size > xasize) {
424  size -= xasize;
425  xa = (DIR_ITEM*)&xa->name[xa->m + xa->n];
426  } else
427  break;
428  }
429 
430  TRACE("xattr %s not found\n", name);
431 
432  return FALSE;
433 }
#define TRUE
Definition: types.h:120
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
UINT16 m
Definition: btrfs.h:253
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1027
if(!r)
Definition: btrfs.c:2665
#define ALLOC_TAG
Definition: btrfs_drv.h:86
char name[1]
Definition: btrfs.h:256
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
static ATOM item
Definition: dde.c:856
unsigned short USHORT
Definition: pedump.c:61
Definition: name.c:36
UINT16 n
Definition: btrfs.h:254
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by _Dispatch_type_().

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

2943  {
2944  LIST_ENTRY* le;
2945 
2946  le = Vcb->devices.Flink;
2947 
2948  while (le != &Vcb->devices) {
2949  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
2950 
2951  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
2952  InsertHeadList(le->Blink, &dev->list_entry);
2953  return;
2954  }
2955 
2956  le = le->Flink;
2957  }
2958 
2959  InsertTailList(&Vcb->devices, &dev->list_entry);
2960 }
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
UINT64 dev_id
Definition: btrfs.h:157
#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:2709
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:492
uint64_t dev_id

Referenced by find_device_from_uuid(), and load_chunk_root().

◆ AddDevice()

NTSTATUS AddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 5412 of file btrfs.c.

5412  {
5413 #endif
5414  LIST_ENTRY* le;
5415  NTSTATUS Status;
5416  UNICODE_STRING volname;
5417  ULONG i, j;
5418  pdo_device_extension* pdode = NULL;
5419  PDEVICE_OBJECT voldev;
5421 
5422  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
5423 
5425 
5426  le = pdo_list.Flink;
5427  while (le != &pdo_list) {
5429 
5430  if (pdode2->pdo == PhysicalDeviceObject) {
5431  pdode = pdode2;
5432  break;
5433  }
5434 
5435  le = le->Flink;
5436  }
5437 
5438  if (!pdode) {
5439  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
5441  goto end;
5442  }
5443 
5445 
5446  volname.Length = volname.MaximumLength = (sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR)) + ((36 + 1) * sizeof(WCHAR));
5447  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
5448 
5449  if (!volname.Buffer) {
5450  ERR("out of memory\n");
5452  goto end2;
5453  }
5454 
5455  RtlCopyMemory(volname.Buffer, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR));
5456 
5457  j = (sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1;
5458  for (i = 0; i < 16; i++) {
5459  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] >> 4); j++;
5460  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] & 0xf); j++;
5461 
5462  if (i == 3 || i == 5 || i == 7 || i == 9) {
5463  volname.Buffer[j] = '-';
5464  j++;
5465  }
5466  }
5467 
5468  volname.Buffer[j] = '}';
5469 
5472  if (!NT_SUCCESS(Status)) {
5473  ERR("IoCreateDevice returned %08x\n", Status);
5474  goto end2;
5475  }
5476 
5477  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
5478  voldev->Flags |= DO_DIRECT_IO;
5479 
5480  vde = voldev->DeviceExtension;
5481  vde->type = VCB_TYPE_VOLUME;
5482  vde->name = volname;
5483  vde->device = voldev;
5484  vde->mounted_device = NULL;
5485  vde->pdo = PhysicalDeviceObject;
5486  vde->pdode = pdode;
5487  vde->removing = FALSE;
5488  vde->open_count = 0;
5489 
5490  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
5491  if (!NT_SUCCESS(Status))
5492  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5493 
5495 
5496  pdode->vde = vde;
5497 
5498  if (pdode->removable)
5499  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
5500 
5501  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
5502 
5504  if (!NT_SUCCESS(Status))
5505  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5506 
5508 
5509 end2:
5511 
5512 end:
5514 
5515  return Status;
5516 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1699
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
PDEVICE_OBJECT device
Definition: btrfs_drv.h:838
UINT8 uuid[16]
Definition: btrfs.h:119
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3909
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:840
GLuint GLuint end
Definition: gl.h:1545
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
UNICODE_STRING name
Definition: btrfs_drv.h:837
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:852
#define ALLOC_TAG
Definition: btrfs_drv.h:86
UNICODE_STRING bus_name
Definition: btrfs_drv.h:842
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 RtlIsNtDdiVersionAvailable
Definition: rtlfuncs.h:3429
#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:841
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:94
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BTRFS_VOLUME_PREFIX
Definition: btrfs_drv.h:119
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:636
ERESOURCE child_lock
Definition: btrfs_drv.h:857
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:839
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:60
Definition: typedefs.h:117
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:843
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
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:136
Definition: list.h:27
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
ERESOURCE pdo_list_lock
Definition: btrfs.c:93
volume_device_extension * vde
Definition: btrfs_drv.h:851
#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:2745

Referenced by _Function_class_().

◆ calculate_total_space()

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

Definition at line 590 of file btrfs.c.

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

Referenced by _Dispatch_type_().

◆ check_cpu()

static void check_cpu ( )
static

Definition at line 5274 of file btrfs.c.

5274  {
5275  unsigned int cpuInfo[4];
5276 #ifndef _MSC_VER
5277  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
5278  have_sse42 = cpuInfo[2] & bit_SSE4_2;
5279  have_sse2 = cpuInfo[3] & bit_SSE2;
5280 #else
5281  __cpuid(cpuInfo, 1);
5282  have_sse42 = cpuInfo[2] & (1 << 20);
5283  have_sse2 = cpuInfo[3] & (1 << 26);
5284 #endif
5285 
5286  if (have_sse42)
5287  TRACE("SSE4.2 is supported\n");
5288  else
5289  TRACE("SSE4.2 not supported\n");
5290 
5291  if (have_sse2)
5292  TRACE("SSE2 is supported\n");
5293  else
5294  TRACE("SSE2 is not supported\n");
5295 }
BOOL have_sse2
Definition: btrfs.c:63
BOOL have_sse42
Definition: btrfs.c:63
#define TRACE(s)
Definition: solgame.cpp:4
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682

Referenced by _Function_class_().

◆ chunk_lock_range()

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

Definition at line 5145 of file btrfs.c.

5145  {
5146  LIST_ENTRY* le;
5147  BOOL locked;
5148  range_lock* rl;
5149 
5150  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5151  if (!rl) {
5152  ERR("out of memory\n");
5153  return;
5154  }
5155 
5156  rl->start = start;
5157  rl->length = length;
5158  rl->thread = PsGetCurrentThread();
5159 
5160  while (TRUE) {
5161  locked = FALSE;
5162 
5163  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5164 
5165  le = c->range_locks.Flink;
5166  while (le != &c->range_locks) {
5168 
5169  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5170  locked = TRUE;
5171  break;
5172  }
5173 
5174  le = le->Flink;
5175  }
5176 
5177  if (!locked) {
5178  InsertTailList(&c->range_locks, &rl->list_entry);
5179 
5180  ExReleaseResourceLite(&c->range_locks_lock);
5181  return;
5182  }
5183 
5184  KeClearEvent(&c->range_locks_event);
5185 
5186  ExReleaseResourceLite(&c->range_locks_lock);
5187 
5188  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, FALSE, NULL);
5189  }
5190 }
UINT64 length
Definition: btrfs_drv.h:512
#define TRUE
Definition: types.h:120
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#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
unsigned int BOOL
Definition: ntddk_ex.h:94
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:514
InsertTailList & Vcb
Definition: btrfs.c:2709
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:511
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:513
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  start,
_In_ UINT64  length 
)

Definition at line 5192 of file btrfs.c.

5192  {
5193  LIST_ENTRY* le;
5194 
5195  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5196 
5197  le = c->range_locks.Flink;
5198  while (le != &c->range_locks) {
5200 
5201  if (rl->start == start && rl->length == length) {
5203  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5204  break;
5205  }
5206 
5207  le = le->Flink;
5208  }
5209 
5210  KeSetEvent(&c->range_locks_event, 0, FALSE);
5211 
5212  ExReleaseResourceLite(&c->range_locks_lock);
5213 }
UINT64 length
Definition: btrfs_drv.h:512
#define TRUE
Definition: types.h:120
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:514
InsertTailList & Vcb
Definition: btrfs.c:2709
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:511
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 1702 of file btrfs.c.

1702  {
1703  fcb* fcb;
1704  ccb* ccb;
1705  file_ref* fileref = NULL;
1706  LONG open_files;
1707 
1708  UNUSED(Irp);
1709 
1710  TRACE("FileObject = %p\n", FileObject);
1711 
1712  fcb = FileObject->FsContext;
1713  if (!fcb) {
1714  TRACE("FCB was NULL, returning success\n");
1715  return STATUS_SUCCESS;
1716  }
1717 
1718  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1719 
1720  ccb = FileObject->FsContext2;
1721 
1722  TRACE("close called for %S (fcb == %p)\n", file_desc(FileObject), fcb);
1723 
1724  // FIXME - make sure notification gets sent if file is being deleted
1725 
1726  if (ccb) {
1727  if (ccb->query_string.Buffer)
1729 
1730  if (ccb->filename.Buffer)
1732 
1733  // FIXME - use refcounts for fileref
1734  fileref = ccb->fileref;
1735 
1736  if (fcb->Vcb->running_sends > 0) {
1737  BOOL send_cancelled = FALSE;
1738 
1739  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1740 
1741  if (ccb->send) {
1742  ccb->send->cancelling = TRUE;
1743  send_cancelled = TRUE;
1745  }
1746 
1747  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1748 
1749  if (send_cancelled) {
1750  while (ccb->send) {
1751  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1752  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1753  }
1754  }
1755  }
1756 
1757  ExFreePool(ccb);
1758  }
1759 
1761 
1762  if (open_files == 0 && fcb->Vcb->removing) {
1763  uninit(fcb->Vcb);
1764  return STATUS_SUCCESS;
1765  }
1766 
1767  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1768  return STATUS_SUCCESS;
1769 
1770  if (fileref)
1771  free_fileref(fileref);
1772  else
1773  free_fcb(fcb);
1774 
1775  return STATUS_SUCCESS;
1776 }
#define TRUE
Definition: types.h:120
void free_fcb(_Inout_ fcb *fcb)
Definition: btrfs.c:1507
_In_ PIRP Irp
Definition: csq.h:116
BOOL cancelling
Definition: btrfs_drv.h:341
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1778
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UNICODE_STRING filename
Definition: btrfs_drv.h:359
UNICODE_STRING query_string
Definition: btrfs_drv.h:351
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
#define UNUSED(x)
Definition: btrfs_drv.h:81
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TRACE(s)
Definition: solgame.cpp:4
struct _fcb fcb
Definition: btrfs_drv.h:1334
KEVENT cleared_event
Definition: btrfs_drv.h:340
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:1628
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:358
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define VPB_MOUNTED
Definition: iotypes.h:1763
struct _device_extension * Vcb
Definition: btrfs_drv.h:260
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1336
send_info * send
Definition: btrfs_drv.h:367

Referenced by _Dispatch_type_().

◆ create_calc_threads()

static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 3733 of file btrfs.c.

3733  {
3735  ULONG i;
3736 
3737  Vcb->calcthreads.num_threads = KeQueryActiveProcessorCount(NULL);
3738 
3739  Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
3740  if (!Vcb->calcthreads.threads) {
3741  ERR("out of memory\n");
3743  }
3744 
3745  InitializeListHead(&Vcb->calcthreads.job_list);
3746  ExInitializeResourceLite(&Vcb->calcthreads.lock);
3747  KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, FALSE);
3748 
3749  RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads);
3750 
3751  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
3752  NTSTATUS Status;
3753 
3754  Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
3755  KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, FALSE);
3756 
3757  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, NULL, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
3758  if (!NT_SUCCESS(Status)) {
3759  ULONG j;
3760 
3761  ERR("PsCreateSystemThread returned %08x\n", Status);
3762 
3763  for (j = 0; j < i; j++) {
3764  Vcb->calcthreads.threads[i].quit = TRUE;
3765  }
3766 
3767  KeSetEvent(&Vcb->calcthreads.event, 0, FALSE);
3768 
3769  return Status;
3770  }
3771  }
3772 
3773  return STATUS_SUCCESS;
3774 }
#define TRUE
Definition: types.h:120
#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:3909
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ALLOC_TAG
Definition: btrfs_drv.h:86
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
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:2709
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTKERNELAPI ULONG NTAPI KeQueryActiveProcessorCount(OUT PKAFFINITY ActiveProcessors OPTIONAL)
Definition: ke.c:15
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2745

Referenced by mount_vol().

◆ create_root()

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

Definition at line 1009 of file btrfs.c.

1010  {
1011  NTSTATUS Status;
1012  root* r;
1013  tree* t = NULL;
1014  ROOT_ITEM* ri;
1015  traverse_ptr tp;
1016 
1018  if (!r) {
1019  ERR("out of memory\n");
1021  }
1022 
1024  if (!r->nonpaged) {
1025  ERR("out of memory\n");
1026  ExFreePool(r);
1028  }
1029 
1030  if (!no_tree) {
1032  if (!t) {
1033  ERR("out of memory\n");
1034  ExFreePool(r->nonpaged);
1035  ExFreePool(r);
1037  }
1038 
1039  t->nonpaged = NULL;
1040 
1041  t->is_unique = TRUE;
1042  t->uniqueness_determined = TRUE;
1043  t->buf = NULL;
1044  }
1045 
1047  if (!ri) {
1048  ERR("out of memory\n");
1049 
1050  if (t)
1051  ExFreePool(t);
1052 
1053  ExFreePool(r->nonpaged);
1054  ExFreePool(r);
1056  }
1057 
1058  r->id = id;
1059  r->treeholder.address = 0;
1060  r->treeholder.generation = Vcb->superblock.generation;
1061  r->treeholder.tree = t;
1062  r->lastinode = 0;
1063  r->dirty = FALSE;
1064  r->received = FALSE;
1065  r->reserved = NULL;
1066  r->parent = 0;
1067  r->send_ops = 0;
1068  RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
1069  r->root_item.num_references = 1;
1070  r->fcbs_version = 0;
1071  InitializeListHead(&r->fcbs);
1072  RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY*) * 256);
1073 
1074  RtlCopyMemory(ri, &r->root_item, sizeof(ROOT_ITEM));
1075 
1076  // We ask here for a traverse_ptr to the item we're inserting, so we can
1077  // copy some of the tree's variables
1078 
1079  Status = insert_tree_item(Vcb, Vcb->root_root, id, TYPE_ROOT_ITEM, offset, ri, sizeof(ROOT_ITEM), &tp, Irp);
1080  if (!NT_SUCCESS(Status)) {
1081  ERR("insert_tree_item returned %08x\n", Status);
1082  ExFreePool(ri);
1083 
1084  if (t)
1085  ExFreePool(t);
1086 
1087  ExFreePool(r->nonpaged);
1088  ExFreePool(r);
1089  return Status;
1090  }
1091 
1092  ExInitializeResourceLite(&r->nonpaged->load_tree_lock);
1093 
1094  InsertTailList(&Vcb->roots, &r->list_entry);
1095 
1096  if (!no_tree) {
1097  RtlZeroMemory(&t->header, sizeof(tree_header));
1098  t->header.fs_uuid = tp.tree->header.fs_uuid;
1099  t->header.address = 0;
1100  t->header.flags = HEADER_FLAG_MIXED_BACKREF | 1; // 1 == "written"? Why does the Linux driver record this?
1101  t->header.chunk_tree_uuid = tp.tree->header.chunk_tree_uuid;
1102  t->header.generation = Vcb->superblock.generation;
1103  t->header.tree_id = id;
1104  t->header.num_items = 0;
1105  t->header.level = 0;
1106 
1107  t->has_address = FALSE;
1108  t->size = 0;
1109  t->Vcb = Vcb;
1110  t->parent = NULL;
1111  t->paritem = NULL;
1112  t->root = r;
1113 
1114  InitializeListHead(&t->itemlist);
1115 
1116  t->new_address = 0;
1117  t->has_new_address = FALSE;
1118  t->updated_extents = FALSE;
1119 
1120  InsertTailList(&Vcb->trees, &t->list_entry);
1121  t->list_entry_hash.Flink = NULL;
1122 
1123  t->write = TRUE;
1124  Vcb->need_write = TRUE;
1125  }
1126 
1127  *rootptr = r;
1128 
1129  return STATUS_SUCCESS;
1130 }
#define TRUE
Definition: types.h:120
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:2680
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:3909
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2663
#define InsertTailList(ListHead, Entry)
#define HEADER_FLAG_MIXED_BACKREF
Definition: btrfs.h:130
#define ALLOC_TAG
Definition: btrfs_drv.h:86
tree * tree
Definition: btrfs_drv.h:474
smooth NULL
Definition: ftsmooth.c:416
_In_ UINT64 id
Definition: btrfs.c:2662
InsertTailList & Vcb
Definition: btrfs.c:2709
BTRFS_UUID chunk_tree_uuid
Definition: btrfs.h:137
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
tree_header header
Definition: btrfs_drv.h:401
Definition: typedefs.h:117
NTSTATUS insert_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ UINT64 obj_id, _In_ UINT8 obj_type, _In_ UINT64 offset, _In_reads_bytes_opt_(size) _When_(return >=0, __drv_aliasesMem) void *data, _In_ UINT16 size, _Out_opt_ traverse_ptr *ptp, _In_opt_ PIRP Irp)
Definition: treefuncs.c:857
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
BTRFS_UUID fs_uuid
Definition: btrfs.h:134
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define TYPE_ROOT_ITEM
Definition: btrfs.h:26
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY *) *256)
return STATUS_SUCCESS
Definition: btrfs.c:2745
#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_opt_ PIRP  Irp,
_In_ LIST_ENTRY rollback 
)

Definition at line 1969 of file btrfs.c.

1969  {
1970  LARGE_INTEGER newlength, time;
1971  BTRFS_TIME now;
1972  NTSTATUS Status;
1973  ULONG utf8len = 0;
1974 
1977 
1978  ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, TRUE);
1979 
1980  if (fileref->deleted) {
1981  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1982  return STATUS_SUCCESS;
1983  }
1984 
1985  if (fileref->fcb->subvol->send_ops > 0) {
1986  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1987  return STATUS_ACCESS_DENIED;
1988  }
1989 
1990  fileref->deleted = TRUE;
1991  mark_fileref_dirty(fileref);
1992 
1993  // delete INODE_ITEM (0x1)
1994 
1995  TRACE("nlink = %u\n", fileref->fcb->inode_item.st_nlink);
1996 
1997  if (!fileref->fcb->ads) {
1998  if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
1999  LIST_ENTRY* le;
2000 
2001  mark_fcb_dirty(fileref->fcb);
2002 
2003  fileref->fcb->inode_item_changed = TRUE;
2004 
2005  if (fileref->fcb->inode_item.st_nlink > 1) {
2006  fileref->fcb->inode_item.st_nlink--;
2007  fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2008  fileref->fcb->inode_item.sequence++;
2009  fileref->fcb->inode_item.st_ctime = now;
2010  } else {
2011  // excise extents
2012 
2013  if (fileref->fcb->type != BTRFS_TYPE_DIRECTORY && fileref->fcb->inode_item.st_size > 0) {
2014  Status = excise_extents(fileref->fcb->Vcb, fileref->fcb, 0, sector_align(fileref->fcb->inode_item.st_size, fileref->fcb->Vcb->superblock.sector_size), Irp, rollback);
2015  if (!NT_SUCCESS(Status)) {
2016  ERR("excise_extents returned %08x\n", Status);
2017  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2018  return Status;
2019  }
2020  }
2021 
2022  fileref->fcb->Header.AllocationSize.QuadPart = 0;
2023  fileref->fcb->Header.FileSize.QuadPart = 0;
2024  fileref->fcb->Header.ValidDataLength.QuadPart = 0;
2025 
2026  if (FileObject) {
2027  CC_FILE_SIZES ccfs;
2028 
2029  ccfs.AllocationSize = fileref->fcb->Header.AllocationSize;
2030  ccfs.FileSize = fileref->fcb->Header.FileSize;
2031  ccfs.ValidDataLength = fileref->fcb->Header.ValidDataLength;
2032 
2034 
2035  _SEH2_TRY {
2036  CcSetFileSizes(FileObject, &ccfs);
2039  } _SEH2_END;
2040 
2041  if (!NT_SUCCESS(Status)) {
2042  ERR("CcSetFileSizes threw exception %08x\n", Status);
2043  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2044  return Status;
2045  }
2046  }
2047 
2048  fileref->fcb->deleted = TRUE;
2049 
2050  le = fileref->children.Flink;
2051  while (le != &fileref->children) {
2053 
2054  if (fr2->fcb->ads) {
2055  fr2->fcb->deleted = TRUE;
2056  mark_fcb_dirty(fr2->fcb);
2057  }
2058 
2059  le = le->