ReactOS  0.4.12-dev-945-g5a2911d
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 (_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ fcb *fcb)
 
void free_fileref (_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ 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)
 
 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
 
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:3889
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
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:2689
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
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:1669
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:48
return STATUS_SUCCESS
Definition: btrfs.c:2725

◆ _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:3889
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:310
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
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:2689
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:629
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:263
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1605
return STATUS_SUCCESS
Definition: btrfs.c:2725

◆ _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:3889
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:627
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:3149
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2689
#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:629
#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
#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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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:2725
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 1183 of file btrfs.c.

1186  {
1187 #else
1188 static NTSTATUS drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
1189 #endif
1192  NTSTATUS Status;
1193  BOOL top_level;
1194 
1196 
1197  TRACE("set volume information\n");
1198 
1199  top_level = is_top_level(Irp);
1200 
1201  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1203  goto end;
1204  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1206  goto end;
1207  }
1208 
1210 
1211  if (Vcb->readonly) {
1213  goto end;
1214  }
1215 
1216  if (Vcb->removing || Vcb->locked) {
1218  goto end;
1219  }
1220 
1221  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1223  FIXME("STUB: FileFsControlInformation\n");
1224  break;
1225 
1227  TRACE("FileFsLabelInformation\n");
1228 
1229  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1230  break;
1231 
1233  FIXME("STUB: FileFsObjectIdInformation\n");
1234  break;
1235 
1236  default:
1237  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1238  break;
1239  }
1240 
1241 end:
1242  Irp->IoStatus.Status = Status;
1243  Irp->IoStatus.Information = 0;
1244 
1245  TRACE("returning %08x\n", Status);
1246 
1248 
1249  if (top_level)
1251 
1253 
1254  return Status;
1255 }
#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:3889
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
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:2689
#define TRACE(s)
Definition: solgame.cpp:4
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1128
#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 2161 of file btrfs.c.

2164  {
2165 #else
2166 static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
2167 #endif
2168  NTSTATUS Status;
2172  fcb* fcb = FileObject->FsContext;
2173  BOOL top_level;
2174 
2176 
2177  TRACE("cleanup\n");
2178 
2179  top_level = is_top_level(Irp);
2180 
2181  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2183  goto exit;
2184  } else if (DeviceObject == master_devobj) {
2185  TRACE("closing file system\n");
2187  goto exit;
2188  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2190  goto exit;
2191  }
2192 
2193  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2194  TRACE("FileObject %p already cleaned up\n", FileObject);
2196  goto exit;
2197  }
2198 
2199  if (!fcb) {
2200  ERR("fcb was NULL\n");
2202  goto exit;
2203  }
2204 
2205  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2206  // messages belonging to other devices.
2207 
2208  if (FileObject && FileObject->FsContext) {
2209  LONG oc;
2210  ccb* ccb;
2211  file_ref* fileref;
2212  BOOL locked = TRUE;
2213 
2214  ccb = FileObject->FsContext2;
2215  fileref = ccb ? ccb->fileref : NULL;
2216 
2217  TRACE("cleanup called for FileObject %p\n", FileObject);
2218  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2219 
2220  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
2221 
2223 
2225 
2226  if (ccb)
2227  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2228 
2229  if (fileref) {
2230  oc = InterlockedDecrement(&fileref->open_count);
2231 #ifdef DEBUG_FCB_REFCOUNTS
2232  ERR("fileref %p: open_count now %i\n", fileref, oc);
2233 #endif
2234  }
2235 
2236  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2237  fileref->delete_on_close = TRUE;
2238 
2239  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2240  fileref->delete_on_close = FALSE;
2241 
2242  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2243  TRACE("unlocking volume\n");
2246  }
2247 
2248  if (ccb && ccb->reserving) {
2249  fcb->subvol->reserved = NULL;
2250  ccb->reserving = FALSE;
2251  // FIXME - flush all of subvol's fcbs
2252  }
2253 
2254  if (fileref && oc == 0) {
2255  if (!fcb->Vcb->removing) {
2256  if (fileref && fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2258 
2260 
2261  if (!fileref->fcb->ads || fileref->dc) {
2262  if (fileref->fcb->ads) {
2264  FILE_ACTION_REMOVED, &fileref->dc->name);
2265  } else
2267  }
2268 
2269  ExReleaseResourceLite(fcb->Header.Resource);
2270  locked = FALSE;
2271 
2272  // fcb_lock needs to be acquired before fcb->Header.Resource
2273  acquire_fcb_lock_exclusive(fcb->Vcb);
2274 
2275  Status = delete_fileref(fileref, FileObject, Irp, &rollback);
2276  if (!NT_SUCCESS(Status)) {
2277  ERR("delete_fileref returned %08x\n", Status);
2279  release_fcb_lock(fcb->Vcb);
2280  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2281  goto exit;
2282  }
2283 
2284  release_fcb_lock(fcb->Vcb);
2285 
2286  locked = FALSE;
2287 
2289  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && fcb->nonpaged->segment_object.DataSectionObject) {
2291  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2292 
2293  if (!NT_SUCCESS(iosb.Status)) {
2294  ERR("CcFlushCache returned %08x\n", iosb.Status);
2295  }
2296 
2297  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2298  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
2299  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2300  }
2301 
2302  CcPurgeCacheSection(&fcb->nonpaged->segment_object, NULL, 0, FALSE);
2303 
2304  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %llx, FileSize = %llx, ValidDataLength = %llx)\n",
2305  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2306  }
2307  }
2308 
2309  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2311  }
2312 
2313  if (locked)
2314  ExReleaseResourceLite(fcb->Header.Resource);
2315 
2316  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2317 
2318  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2319  }
2320 
2322 
2323 exit:
2324  TRACE("returning %08x\n", Status);
2325 
2326  Irp->IoStatus.Status = Status;
2327  Irp->IoStatus.Information = 0;
2328 
2330 
2331  if (top_level)
2333 
2335 
2336  return Status;
2337 }
struct _file_ref * parent
Definition: btrfs_drv.h:326
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1032
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:1011
#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:3889
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
#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:1343
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:2689
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:629
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:299
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:264
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1321
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:263
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:1949
#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:270
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:2725
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2300
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:1332

◆ _Dispatch_type_() [6/10]

_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 4804 of file btrfs.c.

4807  {
4808 #else
4809 static NTSTATUS drv_file_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4810 #endif
4812  NTSTATUS Status;
4814  BOOL top_level;
4815 
4817 
4818  TRACE("file system control\n");
4819 
4820  top_level = is_top_level(Irp);
4821 
4822  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4824  goto end;
4825  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
4827  goto end;
4828  }
4829 
4831 
4833 
4834  Irp->IoStatus.Information = 0;
4835 
4836  switch (IrpSp->MinorFunction) {
4837  case IRP_MN_MOUNT_VOLUME:
4838  TRACE("IRP_MN_MOUNT_VOLUME\n");
4839 
4841  break;
4842 
4843  case IRP_MN_KERNEL_CALL:
4844  TRACE("IRP_MN_KERNEL_CALL\n");
4845 
4846  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4847  break;
4848 
4850  TRACE("IRP_MN_USER_FS_REQUEST\n");
4851 
4852  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4853  break;
4854 
4855  case IRP_MN_VERIFY_VOLUME:
4856  TRACE("IRP_MN_VERIFY_VOLUME\n");
4857 
4859 
4860  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
4861  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
4862  Vcb->removing = TRUE;
4863  ExReleaseResourceLite(&Vcb->tree_lock);
4864  }
4865 
4866  break;
4867 
4868  default:
4869  break;
4870  }
4871 
4872 end:
4873  TRACE("returning %08x\n", Status);
4874 
4875  if (Irp) {
4876  Irp->IoStatus.Status = Status;
4877 
4879  }
4880 
4881  if (top_level)
4883 
4885 
4886  return Status;
4887 }
#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:3889
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
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:2689
#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:629
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, UINT32 type)
Definition: fsctl.c:4794
#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:628
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:4745
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:3985

◆ _Dispatch_type_() [7/10]

_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 4889 of file btrfs.c.

4892  {
4893 #else
4894 static NTSTATUS drv_lock_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4895 #endif
4896  NTSTATUS Status;
4898  fcb* fcb = IrpSp->FileObject->FsContext;
4900  BOOL top_level;
4901 
4903 
4904  top_level = is_top_level(Irp);
4905 
4906  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4908 
4909  Irp->IoStatus.Status = Status;
4911 
4912  goto exit;
4913  }
4914 
4915  TRACE("lock control\n");
4916 
4918 
4919  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
4920 
4921 exit:
4922  TRACE("returning %08x\n", Status);
4923 
4924  if (top_level)
4926 
4928 
4929  return Status;
4930 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3889
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:266
InsertTailList & Vcb
Definition: btrfs.c:2689
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:629
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:1605
void exit(int exitcode)
Definition: _exit.c:33

◆ _Dispatch_type_() [8/10]

_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 4932 of file btrfs.c.

4935  {
4936 #else
4937 static NTSTATUS drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4938 #endif
4939  NTSTATUS Status;
4940  BOOL top_level;
4942  LIST_ENTRY* le;
4943 
4945 
4946  TRACE("shutdown\n");
4947 
4948  top_level = is_top_level(Irp);
4949 
4950  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4952  goto end;
4953  }
4954 
4956 
4957  shutting_down = TRUE;
4959 
4960  le = VcbList.Flink;
4961  while (le != &VcbList) {
4962  BOOL open_files;
4963  LIST_ENTRY* le2 = le->Flink;
4964 
4966 
4967  TRACE("shutting down Vcb %p\n", Vcb);
4968 
4969  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
4970  Vcb->removing = TRUE;
4971  open_files = Vcb->open_files > 0;
4972 
4973  if (Vcb->need_write && !Vcb->readonly) {
4974  Status = do_write(Vcb, Irp);
4975  if (!NT_SUCCESS(Status))
4976  ERR("do_write returned %08x\n", Status);
4977  }
4978 
4979  free_trees(Vcb);
4980 
4981  ExReleaseResourceLite(&Vcb->tree_lock);
4982 
4983  if (!open_files)
4984  uninit(Vcb);
4985 
4986  le = le2;
4987  }
4988 
4989 #ifdef _DEBUG
4990  if (comfo) {
4991  ObDereferenceObject(comfo);
4992  comdo = NULL;
4993  comfo = NULL;
4994  }
4995 #endif
4996 
4997 end:
4998  Irp->IoStatus.Status = Status;
4999  Irp->IoStatus.Information = 0;
5000 
5002 
5003  if (top_level)
5005 
5007 
5008  return Status;
5009 }
#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:7287
LONG NTSTATUS
Definition: precomp.h:26
BOOL shutting_down
Definition: btrfs.c:99
Status
Definition: btrfs.c:3889
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:1752
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:777
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:2689
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:844
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
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:2725

◆ _Dispatch_type_() [9/10]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5011 of file btrfs.c.

5014  {
5015 #else
5016 static NTSTATUS drv_power(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
5017 #endif
5018  NTSTATUS Status;
5020  BOOL top_level;
5021 
5023 
5024  top_level = is_top_level(Irp);
5025 
5026  Irp->IoStatus.Information = 0;
5027 
5028  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5030 
5031  Irp->IoStatus.Status = Status;
5033 
5034  goto exit;
5035  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5037 
5038  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5039 
5040  goto exit;
5041  }
5042 
5044  Irp->IoStatus.Status = Status;
5046 
5047 exit:
5048  if (top_level)
5050 
5052 
5053  return Status;
5054 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3889
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
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:862
InsertTailList & Vcb
Definition: btrfs.c:2689
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
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 5056 of file btrfs.c.

5059  {
5060 #else
5061 static NTSTATUS drv_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
5062 #endif
5063  NTSTATUS Status;
5065  BOOL top_level;
5066 
5068 
5069  top_level = is_top_level(Irp);
5070 
5071  Irp->IoStatus.Information = 0;
5072 
5073  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5075 
5077 
5078  Status = IoCallDriver(vde->pdo, Irp);
5079 
5080  goto exit;
5081  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5083 
5084  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5085 
5086  goto exit;
5087  }
5088 
5089  Status = Irp->IoStatus.Status;
5091 
5092 exit:
5093  if (top_level)
5095 
5097 
5098  return Status;
5099 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3889
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:831
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
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:2689
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
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:862
_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:856
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 5360 of file btrfs.c.

5362  {
5363 #else
5364 static void degraded_wait_thread(_In_ void* context) {
5365 #endif
5366  KTIMER timer;
5368 
5369  UNUSED(context);
5370 
5371  KeInitializeTimer(&timer);
5372 
5373  delay.QuadPart = -30000000; // wait three seconds
5374  KeSetTimer(&timer, delay, NULL);
5376 
5377  TRACE("timer expired\n");
5378 
5379  degraded_wait = FALSE;
5380 
5383 
5385 }
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:2725

◆ _Function_class_() [4/4]

_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 5496 of file btrfs.c.

5498  {
5499 #else
5501 #endif
5502  NTSTATUS Status;
5504  UNICODE_STRING device_nameW;
5505  UNICODE_STRING dosdevice_nameW;
5507  HANDLE regh;
5508  OBJECT_ATTRIBUTES oa;
5509  ULONG dispos;
5510 
5513 
5514 #ifdef _DEBUG
5515  ExInitializeResourceLite(&log_lock);
5516 #endif
5518 
5521  log_file.Buffer = NULL;
5523 
5526 
5527  if (!registry_path.Buffer) {
5528  ERR("out of memory\n");
5530  }
5531 
5533 
5535 
5536 #ifdef _DEBUG
5537  if (debug_log_level > 0)
5538  init_logging();
5539 
5540  log_started = TRUE;
5541 #endif
5542 
5543  TRACE("DriverEntry\n");
5544 
5545 #ifndef __REACTOS__
5546  check_cpu();
5547 #endif
5548 
5551  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
5552 
5553  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
5554  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
5555 
5556  if (fPsIsDiskCountersEnabled) {
5557  diskacc = fPsIsDiskCountersEnabled();
5558 
5559  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
5561 
5562  if (!fPsUpdateDiskCounters)
5563  diskacc = FALSE;
5564 
5565  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
5567  }
5568 
5569  RtlInitUnicodeString(&name, L"CcCopyReadEx");
5571 
5572  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
5574 
5575  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
5577  } else {
5579  fCcCopyReadEx = NULL;
5580  fCcCopyWriteEx = NULL;
5583  }
5584 
5585  drvobj = DriverObject;
5586 
5588 
5590 
5591 #ifdef __REACTOS__
5592  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
5593  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
5594  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
5595  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
5596  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
5597  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
5598  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
5599  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
5600  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
5601  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
5602  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
5603  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
5604  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
5605  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
5606  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
5607  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
5608  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
5609  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
5610  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
5611  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
5612  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
5614 #else
5637 #endif
5638 
5640 
5641  device_nameW.Buffer = (WCHAR*)device_name;
5642  device_nameW.Length = device_nameW.MaximumLength = sizeof(device_name) - sizeof(WCHAR);
5643  dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
5644  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) - sizeof(WCHAR);
5645 
5648  if (!NT_SUCCESS(Status)) {
5649  ERR("IoCreateDevice returned %08x\n", Status);
5650  return Status;
5651  }
5652 
5655 
5657 
5658  cde->type = VCB_TYPE_CONTROL;
5659 
5661 
5662  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
5663  if (!NT_SUCCESS(Status)) {
5664  ERR("IoCreateSymbolicLink returned %08x\n", Status);
5665  return Status;
5666  }
5667 
5668  Status = init_cache();
5669  if (!NT_SUCCESS(Status)) {
5670  ERR("init_cache returned %08x\n", Status);
5671  return Status;
5672  }
5673 
5677 
5679 
5682  /* ReactOS specific hack: allow BtrFS driver to start in 1st stage with no hive */
5683 #ifndef __REACTOS__
5684  if (!NT_SUCCESS(Status)) {
5685  ERR("ZwCreateKey returned %08x\n", Status);
5686  return Status;
5687  }
5688 
5689  watch_registry(regh);
5690 #else
5691  if (NT_SUCCESS(Status)) {
5692  watch_registry(regh);
5693  }
5694 #endif
5695 
5696  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
5697  NULL, NULL, 0, &cde->buspdo);
5698  if (!NT_SUCCESS(Status)) {
5699  ERR("IoReportDetectedDevice returned %08x\n", Status);
5700  return Status;
5701  }
5702 
5703  Status = IoRegisterDeviceInterface(cde->buspdo, &BtrfsBusInterface, NULL, &cde->bus_name);
5704  if (!NT_SUCCESS(Status))
5705  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5706 
5708 
5710  if (!NT_SUCCESS(Status))
5711  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5712 
5714 
5716 
5717  Status = PsCreateSystemThread(&degraded_wait_handle, 0, NULL, NULL, NULL, degraded_wait_thread, NULL);
5718  if (!NT_SUCCESS(Status))
5719  WARN("PsCreateSystemThread returned %08x\n", Status);
5720 
5722  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
5723  if (!NT_SUCCESS(Status))
5724  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5725 
5727  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
5728  if (!NT_SUCCESS(Status))
5729  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5730 
5732  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
5733  if (!NT_SUCCESS(Status))
5734  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5735 
5737 
5739 
5740 #ifndef __REACTOS__
5741  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, NULL, NULL, NULL, mountmgr_thread, NULL);
5742  if (!NT_SUCCESS(Status))
5743  WARN("PsCreateSystemThread returned %08x\n", Status);
5744 #endif
5745 
5747 
5748  return STATUS_SUCCESS;
5749 }
#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:5252
#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:1786
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:3889
UNICODE_STRING log_file
Definition: btrfs.c:85
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:804
#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:1779
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:86
UNICODE_STRING bus_name
Definition: btrfs_drv.h:805
NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
Definition: btrfs.c:5390
#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:3367
BOOLEAN(* tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1771
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:1773
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:1316
#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:628
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:5082
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:960
#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:1788
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 RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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:1776
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:803
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:2647
#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 2923 of file btrfs.c.

2923  {
2924  LIST_ENTRY* le;
2925 
2926  le = Vcb->devices.Flink;
2927 
2928  while (le != &Vcb->devices) {
2929  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
2930 
2931  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
2932  InsertHeadList(le->Blink, &dev->list_entry);
2933  return;
2934  }
2935 
2936  le = le->Flink;
2937  }
2938 
2939  InsertTailList(&Vcb->devices, &dev->list_entry);
2940 }
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:2689
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:485
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 5390 of file btrfs.c.

5390  {
5391 #endif
5392  LIST_ENTRY* le;
5393  NTSTATUS Status;
5394  UNICODE_STRING volname;
5395  ULONG i, j;
5396  pdo_device_extension* pdode = NULL;
5397  PDEVICE_OBJECT voldev;
5399 
5400  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
5401 
5403 
5404  le = pdo_list.Flink;
5405  while (le != &pdo_list) {
5407 
5408  if (pdode2->pdo == PhysicalDeviceObject) {
5409  pdode = pdode2;
5410  break;
5411  }
5412 
5413  le = le->Flink;
5414  }
5415 
5416  if (!pdode) {
5417  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
5419  goto end;
5420  }
5421 
5423 
5424  volname.Length = volname.MaximumLength = (sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR)) + ((36 + 1) * sizeof(WCHAR));
5425  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
5426 
5427  if (!volname.Buffer) {
5428  ERR("out of memory\n");
5430  goto end2;
5431  }
5432 
5433  RtlCopyMemory(volname.Buffer, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) - sizeof(WCHAR));
5434 
5435  j = (sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1;
5436  for (i = 0; i < 16; i++) {
5437  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] >> 4); j++;
5438  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] & 0xf); j++;
5439 
5440  if (i == 3 || i == 5 || i == 7 || i == 9) {
5441  volname.Buffer[j] = '-';
5442  j++;
5443  }
5444  }
5445 
5446  volname.Buffer[j] = '}';
5447 
5450  if (!NT_SUCCESS(Status)) {
5451  ERR("IoCreateDevice returned %08x\n", Status);
5452  goto end2;
5453  }
5454 
5455  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
5456  voldev->Flags |= DO_DIRECT_IO;
5457 
5458  vde = voldev->DeviceExtension;
5459  vde->type = VCB_TYPE_VOLUME;
5460  vde->name = volname;
5461  vde->device = voldev;
5462  vde->mounted_device = NULL;
5463  vde->pdo = PhysicalDeviceObject;
5464  vde->pdode = pdode;
5465  vde->removing = FALSE;
5466  vde->open_count = 0;
5467 
5468  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
5469  if (!NT_SUCCESS(Status))
5470  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5471 
5473 
5474  pdode->vde = vde;
5475 
5476  if (pdode->removable)
5477  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
5478 
5479  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
5480 
5482  if (!NT_SUCCESS(Status))
5483  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5484 
5486 
5487 end2:
5489 
5490 end:
5492 
5493  return Status;
5494 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1686
#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:829
UINT8 uuid[16]
Definition: btrfs.h:119
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3889
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:831
GLuint GLuint end
Definition: gl.h:1545
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
UNICODE_STRING name
Definition: btrfs_drv.h:828
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:843
#define ALLOC_TAG
Definition: btrfs_drv.h:86
UNICODE_STRING bus_name
Definition: btrfs_drv.h:833
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:1316
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:832
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:629
ERESOURCE child_lock
Definition: btrfs_drv.h:848
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:830
#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:834
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:960
#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:842
#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:2725

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:2689
#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 5252 of file btrfs.c.

5252  {
5253  unsigned int cpuInfo[4];
5254 #ifndef _MSC_VER
5255  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
5256  have_sse42 = cpuInfo[2] & bit_SSE4_2;
5257  have_sse2 = cpuInfo[3] & bit_SSE2;
5258 #else
5259  __cpuid(cpuInfo, 1);
5260  have_sse42 = cpuInfo[2] & (1 << 20);
5261  have_sse2 = cpuInfo[3] & (1 << 26);
5262 #endif
5263 
5264  if (have_sse42)
5265  TRACE("SSE4.2 is supported\n");
5266  else
5267  TRACE("SSE4.2 not supported\n");
5268 
5269  if (have_sse2)
5270  TRACE("SSE2 is supported\n");
5271  else
5272  TRACE("SSE2 is not supported\n");
5273 }
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 5123 of file btrfs.c.

5123  {
5124  LIST_ENTRY* le;
5125  BOOL locked;
5126  range_lock* rl;
5127 
5128  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5129  if (!rl) {
5130  ERR("out of memory\n");
5131  return;
5132  }
5133 
5134  rl->start = start;
5135  rl->length = length;
5136  rl->thread = PsGetCurrentThread();
5137 
5138  while (TRUE) {
5139  locked = FALSE;
5140 
5141  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5142 
5143  le = c->range_locks.Flink;
5144  while (le != &c->range_locks) {
5146 
5147  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5148  locked = TRUE;
5149  break;
5150  }
5151 
5152  le = le->Flink;
5153  }
5154 
5155  if (!locked) {
5156  InsertTailList(&c->range_locks, &rl->list_entry);
5157 
5158  ExReleaseResourceLite(&c->range_locks_lock);
5159  return;
5160  }
5161 
5162  KeClearEvent(&c->range_locks_event);
5163 
5164  ExReleaseResourceLite(&c->range_locks_lock);
5165 
5166  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, FALSE, NULL);
5167  }
5168 }
UINT64 length
Definition: btrfs_drv.h:505
#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:507
InsertTailList & Vcb
Definition: btrfs.c:2689
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:504
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:506
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 5170 of file btrfs.c.

5170  {
5171  LIST_ENTRY* le;
5172 
5173  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5174 
5175  le = c->range_locks.Flink;
5176  while (le != &c->range_locks) {
5178 
5179  if (rl->start == start && rl->length == length) {
5181  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5182  break;
5183  }
5184 
5185  le = le->Flink;
5186  }
5187 
5188  KeSetEvent(&c->range_locks_event, 0, FALSE);
5189 
5190  ExReleaseResourceLite(&c->range_locks_lock);
5191 }
UINT64 length
Definition: btrfs_drv.h:505
#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:507
InsertTailList & Vcb
Definition: btrfs.c:2689
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:504
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 1669 of file btrfs.c.

1669  {
1670  fcb* fcb;
1671  ccb* ccb;
1672  file_ref* fileref = NULL;
1673  LONG open_files;
1675 
1676  UNUSED(Irp);
1677 
1678  TRACE("FileObject = %p\n", FileObject);
1679 
1680  fcb = FileObject->FsContext;
1681  if (!fcb) {
1682  TRACE("FCB was NULL, returning success\n");
1683  return STATUS_SUCCESS;
1684  }
1685 
1686  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1687 
1688  ccb = FileObject->FsContext2;
1689 
1690  TRACE("close called for %S (fcb == %p)\n", file_desc(FileObject), fcb);
1691 
1692  // FIXME - make sure notification gets sent if file is being deleted
1693 
1694  if (ccb) {
1695  if (ccb->query_string.Buffer)
1697 
1698  if (ccb->filename.Buffer)
1700 
1701  // FIXME - use refcounts for fileref
1702  fileref = ccb->fileref;
1703 
1704  if (fcb->Vcb->running_sends > 0) {
1705  BOOL send_cancelled = FALSE;
1706 
1707  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1708 
1709  if (ccb->send) {
1710  ccb->send->cancelling = TRUE;
1711  send_cancelled = TRUE;
1713  }
1714 
1715  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1716 
1717  if (send_cancelled) {
1718  while (ccb->send) {
1719  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1720  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1721  }
1722  }
1723  }
1724 
1725  ExFreePool(ccb);
1726  }
1727 
1729 
1730  if (open_files == 0 && fcb->Vcb->removing) {
1731  uninit(fcb->Vcb);
1732  return STATUS_SUCCESS;
1733  }
1734 
1735  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1736  return STATUS_SUCCESS;
1737 
1738  Vcb = fcb->Vcb;
1739 
1740  acquire_fcb_lock_exclusive(Vcb);
1741 
1742  if (fileref)
1743  free_fileref(fcb->Vcb, fileref);
1744  else
1745  free_fcb(Vcb, fcb);
1746 
1747  release_fcb_lock(Vcb);
1748 
1749  return STATUS_SUCCESS;
1750 }
void free_fileref(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ file_ref *fr)
Definition: btrfs.c:1610
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
BOOL cancelling
Definition: btrfs_drv.h:341
void free_fcb(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ fcb *fcb)
Definition: btrfs.c:1502
void uninit(_In_ device_extension *Vcb)
Definition: btrfs.c:1752
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
InsertTailList & Vcb
Definition: btrfs.c:2689
#define TRACE(s)
Definition: solgame.cpp:4
struct _fcb fcb
Definition: btrfs_drv.h:1321
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
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:358
return STATUS_SUCCESS
Definition: btrfs.c:2725
#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:1332
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 3713 of file btrfs.c.

3713  {
3715  ULONG i;
3716 
3717  Vcb->calcthreads.num_threads = KeQueryActiveProcessorCount(NULL);
3718 
3719  Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
3720  if (!Vcb->calcthreads.threads) {
3721  ERR("out of memory\n");
3723  }
3724 
3725  InitializeListHead(&Vcb->calcthreads.job_list);
3726  ExInitializeResourceLite(&Vcb->calcthreads.lock);
3727  KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, FALSE);
3728 
3729  RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads);
3730 
3731  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
3732  NTSTATUS Status;
3733 
3734  Vcb->calcthreads.threads[i].DeviceObject = DeviceObject;
3735  KeInitializeEvent(&Vcb->calcthreads.threads[i].finished, NotificationEvent, FALSE);
3736 
3737  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, NULL, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
3738  if (!NT_SUCCESS(Status)) {
3739  ULONG j;
3740 
3741  ERR("PsCreateSystemThread returned %08x\n", Status);
3742 
3743  for (j = 0; j < i; j++) {
3744  Vcb->calcthreads.threads[i].quit = TRUE;
3745  }
3746 
3747  KeSetEvent(&Vcb->calcthreads.event, 0, FALSE);
3748 
3749  return Status;
3750  }
3751  }
3752 
3753  return STATUS_SUCCESS;
3754 }
#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:3889
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:2689
#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
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2725

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->is_unique = TRUE;
1040  t->uniqueness_determined = TRUE;
1041  t->buf = NULL;
1042  }
1043 
1045  if (!ri) {
1046  ERR("out of memory\n");
1047 
1048  if (t)
1049  ExFreePool(t);
1050 
1051  ExFreePool(r->nonpaged);
1052  ExFreePool(r);
1054  }
1055 
1056  r->id = id;
1057  r->treeholder.address = 0;
1058  r->treeholder.generation = Vcb->superblock.generation;
1059  r->treeholder.tree = t;
1060  r->lastinode = 0;
1061  r->dirty = FALSE;
1062  r->received = FALSE;
1063  r->reserved = NULL;
1064  r->parent = 0;
1065  r->send_ops = 0;
1066  RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
1067  r->root_item.num_references = 1;
1068  InitializeListHead(&r->fcbs);
1069 
1070  RtlCopyMemory(ri, &r->root_item, sizeof(ROOT_ITEM));
1071 
1072  // We ask here for a traverse_ptr to the item we're inserting, so we can
1073  // copy some of the tree's variables
1074 
1075  Status = insert_tree_item(Vcb, Vcb->root_root, id, TYPE_ROOT_ITEM, offset, ri, sizeof(ROOT_ITEM), &tp, Irp);
1076  if (!NT_SUCCESS(Status)) {
1077  ERR("insert_tree_item returned %08x\n", Status);
1078  ExFreePool(ri);
1079 
1080  if (t)
1081  ExFreePool(t);
1082 
1083  ExFreePool(r->nonpaged);
1084  ExFreePool(r);
1085  return Status;
1086  }
1087 
1088  ExInitializeResourceLite(&r->nonpaged->load_tree_lock);
1089 
1090  InsertTailList(&Vcb->roots, &r->list_entry);
1091 
1092  if (!no_tree) {
1093  RtlZeroMemory(&t->header, sizeof(tree_header));
1094  t->header.fs_uuid = tp.tree->header.fs_uuid;
1095  t->header.address = 0;
1096  t->header.flags = HEADER_FLAG_MIXED_BACKREF | 1; // 1 == "written"? Why does the Linux driver record this?
1097  t->header.chunk_tree_uuid = tp.tree->header.chunk_tree_uuid;
1098  t->header.generation = Vcb->superblock.generation;
1099  t->header.tree_id = id;
1100  t->header.num_items = 0;
1101  t->header.level = 0;
1102 
1103  t->has_address = FALSE;
1104  t->size = 0;
1105  t->Vcb = Vcb;
1106  t->parent = NULL;
1107  t->paritem = NULL;
1108  t->root = r;
1109 
1110  InitializeListHead(&t->itemlist);
1111 
1112  t->new_address = 0;
1113  t->has_new_address = FALSE;
1114  t->updated_extents = FALSE;
1115 
1116  InsertTailList(&Vcb->trees, &t->list_entry);
1117  t->list_entry_hash.Flink = NULL;
1118 
1119  t->write = TRUE;
1120  Vcb->need_write = TRUE;
1121  }
1122 
1123  *rootptr = r;
1124 
1125  return STATUS_SUCCESS;
1126 }
#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:2661
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:3889
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2645
#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:467
smooth NULL
Definition: ftsmooth.c:416
_In_ UINT64 id
Definition: btrfs.c:2644
InsertTailList & Vcb
Definition: btrfs.c:2689
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:396
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:838
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2725
#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 1949 of file btrfs.c.

1949  {
1950  LARGE_INTEGER newlength, time;
1951  BTRFS_TIME now;
1952  NTSTATUS Status;
1953  ULONG utf8len = 0;
1954 
1957 
1958  ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, TRUE);
1959 
1960  if (fileref->deleted) {
1961  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1962  return STATUS_SUCCESS;
1963  }
1964 
1965  if (fileref->fcb->subvol->send_ops > 0) {
1966  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1967  return STATUS_ACCESS_DENIED;
1968  }
1969 
1970  fileref->deleted = TRUE;
1971  mark_fileref_dirty(fileref);
1972 
1973  // delete INODE_ITEM (0x1)
1974 
1975  TRACE("nlink = %u\n", fileref->fcb->inode_item.st_nlink);
1976 
1977  if (!fileref->fcb->ads) {
1978  if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
1979  LIST_ENTRY* le;
1980 
1981  mark_fcb_dirty(fileref->fcb);
1982 
1983  fileref->fcb->inode_item_changed = TRUE;
1984 
1985  if (fileref->fcb->inode_item.st_nlink > 1) {
1986  fileref->fcb->inode_item.st_nlink--;
1987  fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
1988  fileref->fcb->inode_item.sequence++;
1989  fileref->fcb->inode_item.st_ctime = now;
1990  } else {
1991  // excise extents
1992 
1993  if (fileref->fcb->type != BTRFS_TYPE_DIRECTORY && fileref->fcb->inode_item.st_size > 0) {
1994  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);
1995  if (!NT_SUCCESS(Status)) {
1996  ERR("excise_extents returned %08x\n", Status);
1997  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1998  return Status;
1999  }
2000  }
2001 
2002  fileref->fcb->Header.AllocationSize.QuadPart = 0;
2003  fileref->fcb->Header.FileSize.QuadPart = 0;
2004  fileref->fcb->Header.ValidDataLength.QuadPart = 0;
2005 
2006  if (FileObject) {
2007  CC_FILE_SIZES ccfs;
2008 
2009  ccfs.AllocationSize = fileref->fcb->Header.AllocationSize;
2010  ccfs.FileSize = fileref->fcb->Header.FileSize;
2011  ccfs.ValidDataLength = fileref->fcb->Header.ValidDataLength;
2012 
2014 
2015  _SEH2_TRY {
2016  CcSetFileSizes(FileObject, &ccfs);
2019  } _SEH2_END;
2020 
2021  if (!NT_SUCCESS(Status)) {
2022  ERR("CcSetFileSizes threw exception %08x\n", Status);
2023  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2024  return Status;
2025  }
2026  }
2027 
2028  fileref->fcb->deleted = TRUE;
2029 
2030  le = fileref->children.Flink;
2031  while (le != &fileref->children) {
2033 
2034  if (fr2->fcb->ads) {
2035  fr2->fcb->deleted = TRUE;
2036  mark_fcb_dirty(fr2->fcb);
2037  }
2038 
2039  le = le->Flink;
2040  }
2041  }
2042 
2043  if (fileref->dc) {
2044  le = fileref->fcb->hardlinks.Flink;
2045  while (le != &fileref->fcb->hardlinks) {
2047 
2048  if (hl->parent == fileref->parent->fcb->inode && hl->index == fileref->dc->index) {
2049