ReactOS  r76032
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, _In_ BOOL flush)
 
NTSTATUS delete_fileref (_In_ file_ref *fileref, _In_ 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 WCHAR device_name [] = {'\\','B','t','r','f','s',0}
 
static 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_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_ptr
tp
 
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

Definition at line 52 of file btrfs.c.

Referenced by mount_vol().

#define INCOMPAT_SUPPORTED
Value:
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:104
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:110
#define BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF
Definition: btrfs.h:108
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:107
#define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL
Definition: btrfs.h:103
#define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO
Definition: btrfs.h:105
#define BTRFS_INCOMPAT_FLAGS_NO_HOLES
Definition: btrfs.h:111
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:102
#define BTRFS_INCOMPAT_FLAGS_RAID56
Definition: btrfs.h:109

Definition at line 49 of file btrfs.c.

Referenced by mount_vol().

Function Documentation

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 465 of file btrfs.c.

467  {
470  device_extension* Vcb = DeviceObject->DeviceExtension;
471  BOOL top_level;
472 
474 
475  TRACE("close\n");
476 
477  top_level = is_top_level(Irp);
478 
479  if (DeviceObject == master_devobj) {
480  TRACE("Closing file system\n");
481  Status = STATUS_SUCCESS;
482  goto end;
483  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
484  Status = vol_close(DeviceObject, Irp);
485  goto end;
486  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
487  Status = STATUS_INVALID_PARAMETER;
488  goto end;
489  }
490 
492 
493  // FIXME - unmount if called for volume
494  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
495 
496  Status = close_file(IrpSp->FileObject, Irp);
497 
498 end:
499  Irp->IoStatus.Status = Status;
500  Irp->IoStatus.Information = 0;
501 
503 
504  if (top_level)
506 
507  TRACE("returning %08x\n", Status);
508 
510 
511  return Status;
512 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:60
return STATUS_SUCCESS
Definition: btrfs.c:2664
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1630
#define VCB_TYPE_FS
Definition: btrfs_drv.h:616
GLuint GLuint end
Definition: gl.h:1545
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2787
LONG NTSTATUS
Definition: DriverTester.h:11
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:48
InsertTailList & Vcb
Definition: btrfs.c:2628
_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 514 of file btrfs.c.

516  {
520  fcb* fcb = FileObject->FsContext;
521  device_extension* Vcb = DeviceObject->DeviceExtension;
522  BOOL top_level;
523 
525 
526  TRACE("flush buffers\n");
527 
528  top_level = is_top_level(Irp);
529 
530  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
532  goto end;
533  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
534  Status = STATUS_INVALID_PARAMETER;
535  goto end;
536  }
537 
538  if (!fcb) {
539  ERR("fcb was NULL\n");
540  Status = STATUS_INVALID_PARAMETER;
541  goto end;
542  }
543 
544  if (fcb == Vcb->volume_fcb) {
545  Status = STATUS_INVALID_PARAMETER;
546  goto end;
547  }
548 
549  Irp->IoStatus.Information = 0;
550 
551  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
552 
553  Status = STATUS_SUCCESS;
554  Irp->IoStatus.Status = Status;
555 
556  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
557  CcFlushCache(&fcb->nonpaged->segment_object, NULL, 0, &Irp->IoStatus);
558 
559  if (fcb->Header.PagingIoResource) {
560  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
561  ExReleaseResourceLite(fcb->Header.PagingIoResource);
562  }
563 
564  Status = Irp->IoStatus.Status;
565  }
566 
567 end:
569 
570  TRACE("returning %08x\n", Status);
571 
572  if (top_level)
574 
576 
577  return Status;
578 }
#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
return STATUS_SUCCESS
Definition: btrfs.c:2664
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:304
#define VCB_TYPE_FS
Definition: btrfs_drv.h:616
GLuint GLuint end
Definition: gl.h:1545
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:67
smooth NULL
Definition: ftsmooth.c:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
#define IoCompleteRequest
Definition: irp.c:1177
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:246
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1949
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
#define ERR(fmt,...)
Definition: debug.h:109
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2787
LONG NTSTATUS
Definition: DriverTester.h:11
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:247
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
UINT8 type
Definition: btrfs_drv.h:253
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1518
InsertTailList & Vcb
Definition: btrfs.c:2628
_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 709 of file btrfs.c.

711  {
714  ULONG BytesCopied = 0;
715  device_extension* Vcb = DeviceObject->DeviceExtension;
716  BOOL top_level;
717 
719 
720  TRACE("query volume information\n");
721  top_level = is_top_level(Irp);
722 
723  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
725  goto end;
726  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
727  Status = STATUS_INVALID_PARAMETER;
728  goto end;
729  }
730 
732 
733  Status = STATUS_NOT_IMPLEMENTED;
734 
735  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
737  {
738  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
739  BOOL overflow = FALSE;
740 #ifndef __REACTOS__
741  WCHAR* fs_name = (Irp->RequestorMode == UserMode && lie_about_fs_type()) ? L"NTFS" : L"Btrfs";
742  ULONG fs_name_len = (ULONG)wcslen(fs_name) * sizeof(WCHAR);
743 #else
744  WCHAR* fs_name = L"Btrfs";
745  ULONG fs_name_len = 5 * sizeof(WCHAR);
746 #endif
747  ULONG orig_fs_name_len = fs_name_len;
748 
749  TRACE("FileFsAttributeInformation\n");
750 
751  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
752  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
753  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
754  else
755  fs_name_len = 0;
756 
757  overflow = TRUE;
758  }
759 
764  if (Vcb->readonly)
766 
767  // should also be FILE_FILE_COMPRESSION when supported
768  data->MaximumComponentNameLength = 255; // FIXME - check
769  data->FileSystemNameLength = orig_fs_name_len;
770  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
771 
772  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
773  Status = overflow ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
774  break;
775  }
776 
778  {
779  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
780 
781  TRACE("FileFsDeviceInformation\n");
782 
784 
785  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
786  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
787  ExReleaseResourceLite(&Vcb->tree_lock);
788 
789  if (Vcb->readonly)
791  else
793 
794  BytesCopied = sizeof(FILE_FS_DEVICE_INFORMATION);
795  Status = STATUS_SUCCESS;
796 
797  break;
798  }
799 
801  {
802  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
803 
804  TRACE("FileFsFullSizeInformation\n");
805 
808  ffsi->SectorsPerAllocationUnit = 1;
810 
811  BytesCopied = sizeof(FILE_FS_FULL_SIZE_INFORMATION);
812  Status = STATUS_SUCCESS;
813 
814  break;
815  }
816 
818  {
819  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
820 
821  TRACE("FileFsObjectIdInformation\n");
822 
823  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
824  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
825 
826  BytesCopied = sizeof(FILE_FS_OBJECTID_INFORMATION);
827  Status = STATUS_SUCCESS;
828 
829  break;
830  }
831 
833  {
834  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
835 
836  TRACE("FileFsSizeInformation\n");
837 
839  ffsi->SectorsPerAllocationUnit = 1;
841 
842  BytesCopied = sizeof(FILE_FS_SIZE_INFORMATION);
843  Status = STATUS_SUCCESS;
844 
845  break;
846  }
847 
849  {
850  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
852  BOOL overflow = FALSE;
853  ULONG label_len, orig_label_len;
854 
855  TRACE("FileFsVolumeInformation\n");
856  TRACE("max length = %u\n", IrpSp->Parameters.QueryVolume.Length);
857 
858  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
859 
860  Status = RtlUTF8ToUnicodeN(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
861  if (!NT_SUCCESS(Status)) {
862  ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
863  ExReleaseResourceLite(&Vcb->tree_lock);
864  break;
865  }
866 
867  orig_label_len = label_len;
868 
869  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len) {
870  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR))
871  label_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_VOLUME_INFORMATION) + sizeof(WCHAR);
872  else
873  label_len = 0;
874 
875  overflow = TRUE;
876  }
877 
878  TRACE("label_len = %u\n", label_len);
879 
880  ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
881  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];
882  ffvi.VolumeLabelLength = orig_label_len;
883  ffvi.SupportsObjects = FALSE;
884 
885  RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
886 
887  if (label_len > 0) {
888  ULONG bytecount;
889 
890  Status = RtlUTF8ToUnicodeN(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
891  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL) {
892  ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
893  ExReleaseResourceLite(&Vcb->tree_lock);
894  break;
895  }
896 
897  TRACE("label = %.*S\n", label_len / sizeof(WCHAR), data->VolumeLabel);
898  }
899 
900  ExReleaseResourceLite(&Vcb->tree_lock);
901 
902  BytesCopied = sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len;
903  Status = overflow ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
904  break;
905  }
906 
907 #ifndef __REACTOS__
908 #ifdef _MSC_VER // not in mingw yet
909  case FileFsSectorSizeInformation:
910  {
911  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
912 
913  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
914  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
915  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
916  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
917  data->ByteOffsetForSectorAlignment = 0;
918  data->ByteOffsetForPartitionAlignment = 0;
919 
920  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
921 
922  if (Vcb->trim && !Vcb->options.no_trim)
923  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
924 
925  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
926 
927  break;
928  }
929 #endif
930 #endif /* __REACTOS__ */
931 
932  default:
933  Status = STATUS_INVALID_PARAMETER;
934  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
935  break;
936  }
937 
938  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW)
939  Irp->IoStatus.Information = 0;
940  else
941  Irp->IoStatus.Information = BytesCopied;
942 
943 end:
944  Irp->IoStatus.Status = Status;
945 
947 
948  if (top_level)
950 
951  TRACE("query volume information returning %08x\n", Status);
952 
954 
955  return Status;
956 }
mount_options options
Definition: btrfs_drv.h:707
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:310
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
Definition: bidi.c:75
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_ PIRP Irp
Definition: csq.h:116
char label[MAX_LABEL_SIZE]
Definition: btrfs.h:230
#define FILE_SUPPORTS_OBJECT_IDS
Definition: from_kernel.h:243
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
superblock superblock
Definition: btrfs_drv.h:715
UINT8 uuid[16]
Definition: btrfs.h:118
#define WARN(fmt,...)
Definition: debug.h:111
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
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:616
GLuint GLuint end
Definition: gl.h:1545
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
#define WCHAR
Definition: msvc.h:43
Status
Definition: btrfs.c:3828
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:50
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
#define FALSE
Definition: types.h:117
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
smooth NULL
Definition: ftsmooth.c:557
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3148
UINT32 sector_size
Definition: btrfs.h:216
#define IoCompleteRequest
Definition: irp.c:1177
#define FILE_UNICODE_ON_DISK
Definition: from_kernel.h:235
#define TRACE(s)
Definition: solgame.cpp:4
LARGE_INTEGER VolumeCreationTime
Definition: winioctl.h:408
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FILE_SUPPORTS_BLOCK_REFCOUNTING
Definition: btrfs_drv.h:126
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
#define FILE_CASE_SENSITIVE_SEARCH
Definition: from_kernel.h:233
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define FILE_NAMED_STREAMS
Definition: from_kernel.h:245
#define FILE_SUPPORTS_OPEN_BY_FILE_ID
Definition: from_kernel.h:251
union _IO_STACK_LOCATION::@3397 Parameters
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define FILE_CASE_PRESERVED_NAMES
Definition: from_kernel.h:234
struct _FILE_FS_SIZE_INFORMATION FILE_FS_SIZE_INFORMATION
#define ERR(fmt,...)
Definition: debug.h:109
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
LONG NTSTATUS
Definition: DriverTester.h:11
#define FILE_SUPPORTS_SPARSE_FILES
Definition: from_kernel.h:239
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:47
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
BTRFS_UUID uuid
Definition: btrfs.h:203
static void calculate_total_space(_In_ device_extension *Vcb, _Out_ UINT64 *totalsize, _Out_ UINT64 *freespace)
Definition: btrfs.c:580
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
#define min(a, b)
Definition: monoChain.cc:55
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES
Definition: from_kernel.h:250
struct _FILE_FS_VOLUME_INFORMATION FILE_FS_VOLUME_INFORMATION
unsigned int ULONG
Definition: retypes.h:1
#define 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 _IO_STACK_LOCATION::@3397::@3407 QueryVolume
static BOOL lie_about_fs_type()
Definition: btrfs.c:610
InsertTailList & Vcb
Definition: btrfs.c:2628
LARGE_INTEGER CallerAvailableAllocationUnits
Definition: from_kernel.h:271
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#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_ ( IRP_MJ_SET_VOLUME_INFORMATION  )

Definition at line 1148 of file btrfs.c.

1150  {
1152  device_extension* Vcb = DeviceObject->DeviceExtension;
1153  NTSTATUS Status;
1154  BOOL top_level;
1155 
1157 
1158  TRACE("set volume information\n");
1159 
1160  top_level = is_top_level(Irp);
1161 
1162  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1164  goto end;
1165  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1166  Status = STATUS_INVALID_PARAMETER;
1167  goto end;
1168  }
1169 
1170  Status = STATUS_NOT_IMPLEMENTED;
1171 
1172  if (Vcb->readonly) {
1174  goto end;
1175  }
1176 
1177  if (Vcb->removing || Vcb->locked) {
1178  Status = STATUS_ACCESS_DENIED;
1179  goto end;
1180  }
1181 
1182  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1184  FIXME("STUB: FileFsControlInformation\n");
1185  break;
1186 
1188  TRACE("FileFsLabelInformation\n");
1189 
1190  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1191  break;
1192 
1194  FIXME("STUB: FileFsObjectIdInformation\n");
1195  break;
1196 
1197  default:
1198  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1199  break;
1200  }
1201 
1202 end:
1203  Irp->IoStatus.Status = Status;
1204  Irp->IoStatus.Information = 0;
1205 
1206  TRACE("returning %08x\n", Status);
1207 
1209 
1210  if (top_level)
1212 
1214 
1215  return Status;
1216 }
#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
#define VCB_TYPE_FS
Definition: btrfs_drv.h:616
GLuint GLuint end
Definition: gl.h:1545
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1093
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
union _IO_STACK_LOCATION::@3397 Parameters
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
LONG NTSTATUS
Definition: DriverTester.h:11
struct _IO_STACK_LOCATION::@3397::@3408 SetVolume
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
#define IO_NO_INCREMENT
Definition: iotypes.h:565
NTSTATUS vol_set_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:316
InsertTailList & Vcb
Definition: btrfs.c:2628
_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2104 of file btrfs.c.

2106  {
2107  NTSTATUS Status;
2110  device_extension* Vcb = DeviceObject->DeviceExtension;
2111  fcb* fcb = FileObject->FsContext;
2112  BOOL top_level;
2113 
2115 
2116  TRACE("cleanup\n");
2117 
2118  top_level = is_top_level(Irp);
2119 
2120  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2121  Status = vol_cleanup(DeviceObject, Irp);
2122  goto exit;
2123  } else if (DeviceObject == master_devobj) {
2124  TRACE("closing file system\n");
2125  Status = STATUS_SUCCESS;
2126  goto exit;
2127  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2128  Status = STATUS_INVALID_PARAMETER;
2129  goto exit;
2130  }
2131 
2132  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2133  TRACE("FileObject %p already cleaned up\n", FileObject);
2134  Status = STATUS_SUCCESS;
2135  goto exit;
2136  }
2137 
2138  if (!fcb) {
2139  ERR("fcb was NULL\n");
2140  Status = STATUS_INVALID_PARAMETER;
2141  goto exit;
2142  }
2143 
2144  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2145  // messages belonging to other devices.
2146 
2147  if (FileObject && FileObject->FsContext) {
2148  LONG oc;
2149  ccb* ccb;
2150  file_ref* fileref;
2151  BOOL locked = TRUE;
2152 
2153  ccb = FileObject->FsContext2;
2154  fileref = ccb ? ccb->fileref : NULL;
2155 
2156  TRACE("cleanup called for FileObject %p\n", FileObject);
2157  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2158 
2159  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
2160 
2161  ExAcquireResourceExclusiveLite(fcb->Header.Resource, TRUE);
2162 
2163  IoRemoveShareAccess(FileObject, &fcb->share_access);
2164 
2165  if (ccb)
2166  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2167 
2168  if (fileref) {
2169  oc = InterlockedDecrement(&fileref->open_count);
2170 #ifdef DEBUG_FCB_REFCOUNTS
2171  ERR("fileref %p: open_count now %i\n", fileref, oc);
2172 #endif
2173  }
2174 
2175  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2176  fileref->delete_on_close = TRUE;
2177 
2178  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2179  fileref->delete_on_close = FALSE;
2180 
2181  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2182  TRACE("unlocking volume\n");
2183  do_unlock_volume(fcb->Vcb);
2185  }
2186 
2187  if (ccb && ccb->reserving) {
2188  fcb->subvol->reserved = NULL;
2189  ccb->reserving = FALSE;
2190  // FIXME - flush all of subvol's fcbs
2191  }
2192 
2193  if (fileref && oc == 0) {
2194  if (!fcb->Vcb->removing) {
2195  if (fileref && fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2197 
2198  InitializeListHead(&rollback);
2199 
2200  if (!fileref->fcb->ads || fileref->dc) {
2201  if (fileref->fcb->ads) {
2203  FILE_ACTION_REMOVED, &fileref->dc->name);
2204  } else
2206  }
2207 
2208  ExReleaseResourceLite(fcb->Header.Resource);
2209  locked = FALSE;
2210 
2211  // fcb_lock needs to be acquired before fcb->Header.Resource
2212  ExAcquireResourceExclusiveLite(&fcb->Vcb->fcb_lock, TRUE);
2213 
2214  Status = delete_fileref(fileref, FileObject, Irp, &rollback);
2215  if (!NT_SUCCESS(Status)) {
2216  ERR("delete_fileref returned %08x\n", Status);
2217  do_rollback(fcb->Vcb, &rollback);
2218  ExReleaseResourceLite(&fcb->Vcb->fcb_lock);
2219  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2220  goto exit;
2221  }
2222 
2223  ExReleaseResourceLite(&fcb->Vcb->fcb_lock);
2224 
2225  locked = FALSE;
2226 
2227  clear_rollback(&rollback);
2228  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && fcb->nonpaged->segment_object.DataSectionObject) {
2230  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2231 
2232  if (!NT_SUCCESS(iosb.Status)) {
2233  ERR("CcFlushCache returned %08x\n", iosb.Status);
2234  }
2235 
2236  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2237  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
2238  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2239  }
2240 
2241  CcPurgeCacheSection(&fcb->nonpaged->segment_object, NULL, 0, FALSE);
2242 
2243  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %llx, FileSize = %llx, ValidDataLength = %llx)\n",
2244  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2245  }
2246  }
2247 
2248  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2249  CcUninitializeCacheMap(FileObject, NULL, NULL);
2250  }
2251 
2252  if (locked)
2253  ExReleaseResourceLite(fcb->Header.Resource);
2254 
2255  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2256 
2257  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2258  }
2259 
2260  Status = STATUS_SUCCESS;
2261 
2262 exit:
2263  TRACE("returning %08x\n", Status);
2264 
2265  Irp->IoStatus.Status = Status;
2266  Irp->IoStatus.Information = 0;
2267 
2269 
2270  if (top_level)
2272 
2274 
2275  return Status;
2276 }
struct _file_ref * parent
Definition: btrfs_drv.h:316
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1026
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:1005
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:339
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
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:60
return STATUS_SUCCESS
Definition: btrfs.c:2664
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1293
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
#define VCB_TYPE_FS
Definition: btrfs_drv.h:616
#define FILE_NOTIFY_CHANGE_FILE_NAME
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
LONG open_count
Definition: btrfs_drv.h:315
#define FILE_NOTIFY_CHANGE_DIR_NAME
Status
Definition: btrfs.c:3828
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3082
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
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:67
smooth NULL
Definition: ftsmooth.c:557
#define FILE_ACTION_REMOVED
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
#define IoCompleteRequest
Definition: irp.c:1177
void send_notification_fileref(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1304
LONG refcount
Definition: btrfs_drv.h:314
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:246
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
struct _file_ref * fileref
Definition: btrfs_drv.h:268
static PIO_STATUS_BLOCK iosb
Definition: file.c:95
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1949
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1732
BOOL ads
Definition: btrfs_drv.h:289
dir_child * dc
Definition: btrfs_drv.h:318
#define exit(n)
Definition: config.h:202
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
#define InterlockedDecrement
Definition: armddk.h:52
NTSTATUS vol_cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:322
fcb * fcb
Definition: btrfs_drv.h:306
Definition: typedefs.h:117
INODE_ITEM inode_item
Definition: btrfs_drv.h:254
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1237
#define ERR(fmt,...)
Definition: debug.h:109
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2787
LONG NTSTATUS
Definition: DriverTester.h:11
UINT64 st_size
Definition: btrfs.h:266
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:247
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:1741
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
struct _root * subvol
Definition: btrfs_drv.h:251
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
UINT8 type
Definition: btrfs_drv.h:253
BOOL delete_on_close
Definition: btrfs_drv.h:309
#define IO_NO_INCREMENT
Definition: iotypes.h:565
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
BOOL reserving
Definition: btrfs_drv.h:346
SHARE_ACCESS share_access
Definition: btrfs_drv.h:260
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:348
InsertTailList & Vcb
Definition: btrfs.c:2628
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2261
struct _device_extension * Vcb
Definition: btrfs_drv.h:250
UNICODE_STRING name
Definition: btrfs_drv.h:221
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:1918
_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 4729 of file btrfs.c.

4731  {
4733  NTSTATUS Status;
4734  device_extension* Vcb = DeviceObject->DeviceExtension;
4735  BOOL top_level;
4736 
4738 
4739  TRACE("file system control\n");
4740 
4741  top_level = is_top_level(Irp);
4742 
4743  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4745  goto end;
4746  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
4747  Status = STATUS_INVALID_PARAMETER;
4748  goto end;
4749  }
4750 
4751  Status = STATUS_NOT_IMPLEMENTED;
4752 
4753  IrpSp = IoGetCurrentIrpStackLocation( Irp );
4754 
4755  Irp->IoStatus.Information = 0;
4756 
4757  switch (IrpSp->MinorFunction) {
4758  case IRP_MN_MOUNT_VOLUME:
4759  TRACE("IRP_MN_MOUNT_VOLUME\n");
4760 
4761  Status = mount_vol(DeviceObject, Irp);
4762  break;
4763 
4764  case IRP_MN_KERNEL_CALL:
4765  TRACE("IRP_MN_KERNEL_CALL\n");
4766 
4767  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4768  break;
4769 
4771  TRACE("IRP_MN_USER_FS_REQUEST\n");
4772 
4773  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4774  break;
4775 
4776  case IRP_MN_VERIFY_VOLUME:
4777  TRACE("IRP_MN_VERIFY_VOLUME\n");
4778 
4779  Status = verify_volume(DeviceObject);
4780 
4781  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
4782  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
4783  Vcb->removing = TRUE;
4784  ExReleaseResourceLite(&Vcb->tree_lock);
4785  }
4786 
4787  break;
4788 
4789  default:
4790  break;
4791  }
4792 
4793 end:
4794  TRACE("returning %08x\n", Status);
4795 
4796  if (Irp) {
4797  Irp->IoStatus.Status = Status;
4798 
4800  }
4801 
4802  if (top_level)
4804 
4806 
4807  return Status;
4808 }
static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: btrfs.c:3924
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
USHORT Flags
Definition: iotypes.h:169
#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 VCB_TYPE_FS
Definition: btrfs_drv.h:616
GLuint GLuint end
Definition: gl.h:1545
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4016
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
NTSTATUS vol_file_system_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:336
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4015
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4014
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
static NTSTATUS verify_volume(_In_ PDEVICE_OBJECT devobj)
Definition: btrfs.c:4670
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
union _IO_STACK_LOCATION::@3397 Parameters
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, UINT32 type)
Definition: fsctl.c:4765
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4019
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:617
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
LONG NTSTATUS
Definition: DriverTester.h:11
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
struct _IO_STACK_LOCATION::@3397::@3409 FileSystemControl
#define IO_NO_INCREMENT
Definition: iotypes.h:565
InsertTailList & Vcb
Definition: btrfs.c:2628
#define VPB_MOUNTED
Definition: iotypes.h:1758
_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 4810 of file btrfs.c.

4812  {
4813  NTSTATUS Status;
4815  fcb* fcb = IrpSp->FileObject->FsContext;
4816  device_extension* Vcb = DeviceObject->DeviceExtension;
4817  BOOL top_level;
4818 
4820 
4821  top_level = is_top_level(Irp);
4822 
4823  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4824  Status = vol_lock_control(DeviceObject, Irp);
4825 
4826  Irp->IoStatus.Status = Status;
4828 
4829  goto exit;
4830  }
4831 
4832  TRACE("lock control\n");
4833 
4834  Status = FsRtlProcessFileLock(&fcb->lock, Irp, NULL);
4835 
4836  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
4837 
4838 exit:
4839  TRACE("returning %08x\n", Status);
4840 
4841  if (top_level)
4843 
4845 
4846  return Status;
4847 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
FILE_LOCK lock
Definition: btrfs_drv.h:256
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:246
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
#define exit(n)
Definition: config.h:202
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1153
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2787
LONG NTSTATUS
Definition: DriverTester.h:11
NTSTATUS vol_lock_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:342
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1518
InsertTailList & Vcb
Definition: btrfs.c:2628
_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 4849 of file btrfs.c.

4851  {
4852  NTSTATUS Status;
4853  BOOL top_level;
4854  device_extension* Vcb = DeviceObject->DeviceExtension;
4855 
4857 
4858  TRACE("shutdown\n");
4859 
4860  top_level = is_top_level(Irp);
4861 
4862  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4863  Status = vol_shutdown(DeviceObject, Irp);
4864  goto end;
4865  }
4866 
4867  Status = STATUS_SUCCESS;
4868 
4869  shutting_down = TRUE;
4871 
4872  while (!IsListEmpty(&VcbList)) {
4874 
4875  TRACE("shutting down Vcb %p\n", Vcb);
4876 
4877  uninit(Vcb, TRUE);
4878  }
4879 
4880 #ifdef _DEBUG
4881  if (comfo) {
4882  ObDereferenceObject(comfo);
4883  comdo = NULL;
4884  comfo = NULL;
4885  }
4886 #endif
4887 
4888 end:
4889  Irp->IoStatus.Status = Status;
4890  Irp->IoStatus.Information = 0;
4891 
4893 
4894  if (top_level)
4896 
4898 
4899  return Status;
4900 }
void uninit(_In_ device_extension *Vcb, _In_ BOOL flush)
Definition: btrfs.c:1713
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
return STATUS_SUCCESS
Definition: btrfs.c:2664
KEVENT mountmgr_thread_event
Definition: btrfs.c:96
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
GLuint GLuint end
Definition: gl.h:1545
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
Status
Definition: btrfs.c:3828
#define FALSE
Definition: types.h:117
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
LIST_ENTRY VcbList
Definition: btrfs.c:66
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS vol_shutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:838
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
LONG NTSTATUS
Definition: DriverTester.h:11
Definition: list.h:27
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
InsertTailList & Vcb
Definition: btrfs.c:2628
BOOL shutting_down
Definition: btrfs.c:97
_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 4902 of file btrfs.c.

4904  {
4905  NTSTATUS Status;
4906  device_extension* Vcb = DeviceObject->DeviceExtension;
4907  BOOL top_level;
4908 
4910 
4911  top_level = is_top_level(Irp);
4912 
4913  Irp->IoStatus.Information = 0;
4914 
4915  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4916  Status = vol_power(DeviceObject, Irp);
4917 
4918  Irp->IoStatus.Status = Status;
4920 
4921  goto exit;
4922  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
4924 
4925  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
4926 
4927  goto exit;
4928  }
4929 
4931  Irp->IoStatus.Status = Status;
4933 
4934 exit:
4935  if (top_level)
4937 
4939 
4940  return Status;
4941 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define VCB_TYPE_FS
Definition: btrfs_drv.h:616
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
NTSTATUS vol_power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:856
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
#define exit(n)
Definition: config.h:202
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
LONG NTSTATUS
Definition: DriverTester.h:11
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1155
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:565
InsertTailList & Vcb
Definition: btrfs.c:2628
_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 4943 of file btrfs.c.

4945  {
4946  NTSTATUS Status;
4947  device_extension* Vcb = DeviceObject->DeviceExtension;
4948  BOOL top_level;
4949 
4951 
4952  top_level = is_top_level(Irp);
4953 
4954  Irp->IoStatus.Information = 0;
4955 
4956  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4957  volume_device_extension* vde = DeviceObject->DeviceExtension;
4958 
4960 
4961  Status = IoCallDriver(vde->pdo, Irp);
4962 
4963  goto exit;
4964  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
4966 
4967  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
4968 
4969  goto exit;
4970  }
4971 
4972  Status = Irp->IoStatus.Status;
4974 
4975 exit:
4976  if (top_level)
4978 
4980 
4981  return Status;
4982 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:814
#define VCB_TYPE_FS
Definition: btrfs_drv.h:616
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
Status
Definition: btrfs.c:3828
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
smooth NULL
Definition: ftsmooth.c:557
#define IoCompleteRequest
Definition: irp.c:1177
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
#define exit(n)
Definition: config.h:202
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:1923
LONG NTSTATUS
Definition: DriverTester.h:11
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1155
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:565
InsertTailList & Vcb
Definition: btrfs.c:2628
_Function_class_ ( DRIVER_UNLOAD  )

Definition at line 263 of file btrfs.c.

265  {
266 #else
268 #endif
269  UNICODE_STRING dosdevice_nameW;
270 
271  ERR("DriverUnload\n");
272 
273  free_cache();
274 
275  IoUnregisterFileSystem(DriverObject->DeviceObject);
276 
278 #ifdef __REACTOS__
280 #else
281  IoUnregisterPlugPlayNotificationEx(notification_entry2);
282 #endif
283 
285 #ifdef __REACTOS__
287 #else
288  IoUnregisterPlugPlayNotificationEx(notification_entry3);
289 #endif
290 
291  if (notification_entry)
292 #ifdef __REACTOS__
294 #else
295  IoUnregisterPlugPlayNotificationEx(notification_entry);
296 #endif
297 
298  dosdevice_nameW.Buffer = dosdevice_name;
299  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = (USHORT)wcslen(dosdevice_name) * sizeof(WCHAR);
300 
301  IoDeleteSymbolicLink(&dosdevice_nameW);
302  IoDeleteDevice(DriverObject->DeviceObject);
303 
304  while (!IsListEmpty(&uid_map_list)) {
306  uid_map* um = CONTAINING_RECORD(le, uid_map, listentry);
307 
308  ExFreePool(um->sid);
309 
310  ExFreePool(um);
311  }
312 
313  while (!IsListEmpty(&gid_map_list)) {
315 
316  ExFreePool(gm->sid);
317  ExFreePool(gm);
318  }
319 
320  // FIXME - free volumes and their devpaths
321 
322 #ifdef _DEBUG
323  if (comfo)
324  ObDereferenceObject(comfo);
325 
326  if (log_handle)
327  ZwClose(log_handle);
328 #endif
329 
332 
333  if (log_device.Buffer)
335 
336  if (log_file.Buffer)
338 
339  if (registry_path.Buffer)
341 
342 #ifdef _DEBUG
343  ExDeleteResourceLite(&log_lock);
344 #endif
346 }
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_entry
Definition: btrfs.c:90
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1053
LIST_ENTRY gid_map_list
Definition: btrfs.c:65
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
void free_cache()
Definition: cache.c:116
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:267
#define WCHAR
Definition: msvc.h:43
LIST_ENTRY uid_map_list
Definition: btrfs.c:65
PSID sid
Definition: btrfs_drv.h:845
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
void * notification_entry2
Definition: btrfs.c:90
PSID sid
Definition: btrfs_drv.h:839
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
ERESOURCE pdo_list_lock
Definition: btrfs.c:91
ERESOURCE global_loading_lock
Definition: btrfs.c:67
void * notification_entry3
Definition: btrfs.c:90
Definition: typedefs.h:117
UNICODE_STRING registry_path
Definition: btrfs.c:83
UNICODE_STRING log_device
Definition: btrfs.c:83
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
ERESOURCE mapping_lock
Definition: btrfs.c:91
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1025
unsigned short USHORT
Definition: pedump.c:61
static DRIVER_UNLOAD DriverUnload
Definition: kbdclass.c:17
static WCHAR dosdevice_name[]
Definition: btrfs.c:55
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
UNICODE_STRING log_file
Definition: btrfs.c:83
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Function_class_ ( IO_COMPLETION_ROUTINE  )

Definition at line 958 of file btrfs.c.

960  {
961 #else
962 static NTSTATUS read_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID conptr) {
963 #endif
964  read_context* context = conptr;
965 
966  UNUSED(DeviceObject);
967 
968  context->iosb = Irp->IoStatus;
969  KeSetEvent(&context->Event, 0, FALSE);
970 
972 }
DWORD *typedef PVOID
Definition: winlogon.h:52
IO_STATUS_BLOCK iosb
Definition: btrfs.c:113
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:49
Definition: http.c:6587
_In_ PIRP Irp
Definition: csq.h:116
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
KEVENT Event
Definition: btrfs.c:112
#define FALSE
Definition: types.h:117
#define UNUSED(x)
Definition: btrfs_drv.h:80
#define _In_
Definition: no_sal2.h:204
LONG NTSTATUS
Definition: DriverTester.h:11
PVOID PIRP
Definition: usb.h:38
_Function_class_ ( KSTART_ROUTINE  )

Definition at line 5243 of file btrfs.c.

5245  {
5246 #else
5247 static void degraded_wait_thread(_In_ void* context) {
5248 #endif
5249  KTIMER timer;
5251 
5252  UNUSED(context);
5253 
5254  KeInitializeTimer(&timer);
5255 
5256  delay.QuadPart = -30000000; // wait three seconds
5257  KeSetTimer(&timer, delay, NULL);
5259 
5260  TRACE("timer expired\n");
5261 
5262  degraded_wait = FALSE;
5263 
5266 
5268 }
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)
return STATUS_SUCCESS
Definition: btrfs.c:2664
BOOL degraded_wait
Definition: btrfs.c:95
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
HANDLE degraded_wait_handle
Definition: btrfs.c:94
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define UNUSED(x)
Definition: btrfs_drv.h:80
#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
LONGLONG QuadPart
Definition: typedefs.h:112
_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 5379 of file btrfs.c.

5381  {
5382 #else
5384 #endif
5385  NTSTATUS Status;
5387  UNICODE_STRING device_nameW;
5388  UNICODE_STRING dosdevice_nameW;
5390  HANDLE regh;
5391  OBJECT_ATTRIBUTES oa;
5392  ULONG dispos;
5393 
5396 
5397 #ifdef _DEBUG
5398  ExInitializeResourceLite(&log_lock);
5399 #endif
5401 
5404  log_file.Buffer = NULL;
5406 
5407  registry_path.Length = registry_path.MaximumLength = RegistryPath->Length;
5409 
5410  if (!registry_path.Buffer) {
5411  ERR("out of memory\n");
5413  }
5414 
5415  RtlCopyMemory(registry_path.Buffer, RegistryPath->Buffer, registry_path.Length);
5416 
5418 
5419 #ifdef _DEBUG
5420  if (debug_log_level > 0)
5421  init_logging();
5422 
5423  log_started = TRUE;
5424 #endif
5425 
5426  TRACE("DriverEntry\n");
5427 
5428 #ifndef __REACTOS__
5429  check_cpu();
5430 #endif
5431 
5434  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
5435 
5436  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
5437  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
5438 
5439  if (fPsIsDiskCountersEnabled) {
5440  diskacc = fPsIsDiskCountersEnabled();
5441 
5442  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
5444 
5445  if (!fPsUpdateDiskCounters)
5446  diskacc = FALSE;
5447 
5448  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
5450  }
5451 
5452  RtlInitUnicodeString(&name, L"CcCopyReadEx");
5454 
5455  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
5457 
5458  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
5460  } else {
5462  fCcCopyReadEx = NULL;
5463  fCcCopyWriteEx = NULL;
5466  }
5467 
5468  drvobj = DriverObject;
5469 
5470  DriverObject->DriverUnload = DriverUnload;
5471 
5472  DriverObject->DriverExtension->AddDevice = AddDevice;
5473 
5474  DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)drv_create;
5475  DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)drv_close;
5476  DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)drv_read;
5477  DriverObject->MajorFunction[IRP_MJ_WRITE] = (PDRIVER_DISPATCH)drv_write;
5478  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = (PDRIVER_DISPATCH)drv_query_information;
5479  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = (PDRIVER_DISPATCH)drv_set_information;
5480  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = (PDRIVER_DISPATCH)drv_query_ea;
5481  DriverObject->MajorFunction[IRP_MJ_SET_EA] = (PDRIVER_DISPATCH)drv_set_ea;
5482  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = (PDRIVER_DISPATCH)drv_flush_buffers;
5483  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = (PDRIVER_DISPATCH)drv_query_volume_information;
5484  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = (PDRIVER_DISPATCH)drv_set_volume_information;
5485  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = (PDRIVER_DISPATCH)drv_directory_control;
5486  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = (PDRIVER_DISPATCH)drv_file_system_control;
5487  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH)drv_device_control;
5488  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = (PDRIVER_DISPATCH)drv_shutdown;
5489  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = (PDRIVER_DISPATCH)drv_lock_control;
5490  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = (PDRIVER_DISPATCH)drv_cleanup;
5491  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = (PDRIVER_DISPATCH)drv_query_security;
5492  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = (PDRIVER_DISPATCH)drv_set_security;
5493  DriverObject->MajorFunction[IRP_MJ_POWER] = (PDRIVER_DISPATCH)drv_power;
5494  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = (PDRIVER_DISPATCH)drv_system_control;
5495  DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH)drv_pnp;
5496 
5497  init_fast_io_dispatch(&DriverObject->FastIoDispatch);
5498 
5499  device_nameW.Buffer = device_name;
5500  device_nameW.Length = device_nameW.MaximumLength = (USHORT)wcslen(device_name) * sizeof(WCHAR);
5501  dosdevice_nameW.Buffer = dosdevice_name;
5502  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = (USHORT)wcslen(dosdevice_name) * sizeof(WCHAR);
5503 
5504  Status = IoCreateDevice(DriverObject, sizeof(control_device_extension), &device_nameW, FILE_DEVICE_DISK_FILE_SYSTEM,
5505  FILE_DEVICE_SECURE_OPEN, FALSE, &DeviceObject);
5506  if (!NT_SUCCESS(Status)) {
5507  ERR("IoCreateDevice returned %08x\n", Status);
5508  return Status;
5509  }
5510 
5513 
5515 
5516  cde->type = VCB_TYPE_CONTROL;
5517 
5518  DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
5519 
5520  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
5521  if (!NT_SUCCESS(Status)) {
5522  ERR("IoCreateSymbolicLink returned %08x\n", Status);
5523  return Status;
5524  }
5525 
5526  Status = init_cache();
5527  if (!NT_SUCCESS(Status)) {
5528  ERR("init_cache returned %08x\n", Status);
5529  return Status;
5530  }
5531 
5535 
5537 
5539  Status = ZwCreateKey(&regh, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY, &oa, 0, NULL, REG_OPTION_NON_VOLATILE, &dispos);
5540  if (!NT_SUCCESS(Status)) {
5541  ERR("ZwCreateKey returned %08x\n", Status);
5542  return Status;
5543  }
5544 
5545  watch_registry(regh);
5546 
5547  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
5548  NULL, NULL, 0, &cde->buspdo);
5549  if (!NT_SUCCESS(Status)) {
5550  ERR("IoReportDetectedDevice returned %08x\n", Status);
5551  return Status;
5552  }
5553 
5554  Status = IoRegisterDeviceInterface(cde->buspdo, &BtrfsBusInterface, NULL, &cde->bus_name);
5555  if (!NT_SUCCESS(Status))
5556  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5557 
5558  cde->attached_device = IoAttachDeviceToDeviceStack(DeviceObject, cde->buspdo);
5559 
5560  Status = IoSetDeviceInterfaceState(&cde->bus_name, TRUE);
5561  if (!NT_SUCCESS(Status))
5562  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5563 
5564  DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
5565 
5567 
5568  Status = PsCreateSystemThread(&degraded_wait_handle, 0, NULL, NULL, NULL, degraded_wait_thread, NULL);
5569  if (!NT_SUCCESS(Status))
5570  WARN("PsCreateSystemThread returned %08x\n", Status);
5571 
5573  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
5574  if (!NT_SUCCESS(Status))
5575  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5576 
5578  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
5579  if (!NT_SUCCESS(Status))
5580  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5581 
5583  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
5584  if (!NT_SUCCESS(Status))
5585  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5586 
5588 
5590 
5591 #ifndef __REACTOS__
5592  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, NULL, NULL, NULL, mountmgr_thread, NULL);
5593  if (!NT_SUCCESS(Status))
5594  WARN("PsCreateSystemThread returned %08x\n", Status);
5595 #endif
5596 
5597  IoRegisterFileSystem(DeviceObject);
5598 
5599  return STATUS_SUCCESS;
5600 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:88
#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:367
NTSTATUS init_cache()
Definition: cache.c:101
#define IRP_MJ_QUERY_SECURITY
#define IRP_MJ_FLUSH_BUFFERS
HANDLE mountmgr_thread_handle
Definition: btrfs.c:94
USHORT MaximumLength
Definition: env_spec_w32.h:370
Definition: bidi.c:75
#define IRP_MJ_SHUTDOWN
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:60
return STATUS_SUCCESS
Definition: btrfs.c:2664
BOOL log_started
Definition: btrfs.c:82
KEVENT mountmgr_thread_event
Definition: btrfs.c:96
BOOL diskacc
Definition: btrfs.c:89
#define IRP_MJ_SET_SECURITY
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
void * notification_entry
Definition: btrfs.c:90
#define WARN(fmt,...)
Definition: debug.h:111
LIST_ENTRY gid_map_list
Definition: btrfs.c:65
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
BOOLEAN(* tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1680
static void check_cpu()
Definition: btrfs.c:5135
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:787
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1195
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
void watch_registry(HANDLE regh)
Definition: registry.c:1007
#define WCHAR
Definition: msvc.h:43
LIST_ENTRY pdo_list
Definition: btrfs.c:92
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:87
LIST_ENTRY uid_map_list
Definition: btrfs.c:65
Status
Definition: btrfs.c:3828
void * notification_entry2
Definition: btrfs.c:90
HANDLE degraded_wait_handle
Definition: btrfs.c:94
UNICODE_STRING bus_name
Definition: btrfs_drv.h:788
GLuint const GLchar * name
Definition: glext.h:6031
#define ALLOC_TAG
Definition: btrfs_drv.h:85
NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
Definition: btrfs.c:5273
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
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:84
#define FALSE
Definition: types.h:117
#define RtlIsNtDdiVersionAvailable
Definition: rtlfuncs.h:3429
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3452
BOOLEAN(* tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1688
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:766
#define IRP_MJ_SET_EA
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:557
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1315
BOOLEAN(* tCcCopyWriteEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1685
#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
LIST_ENTRY VcbList
Definition: btrfs.c:66
#define IRP_MJ_QUERY_EA
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
ERESOURCE pdo_list_lock
Definition: btrfs.c:91
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define IRP_MJ_FILE_SYSTEM_CONTROL
ERESOURCE global_loading_lock
Definition: btrfs.c:67
tCcCopyWriteEx fCcCopyWriteEx
Definition: btrfs.c:86
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
VOID(* tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1695
PDRIVER_OBJECT drvobj
Definition: btrfs.c:59
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2174
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
void * notification_entry3
Definition: btrfs.c:90
UNICODE_STRING registry_path
Definition: btrfs.c:83
UNICODE_STRING log_device
Definition: btrfs.c:83
#define IRP_MJ_SYSTEM_CONTROL
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:85
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:617
VOID(* tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1682
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
ERESOURCE mapping_lock
Definition: btrfs.c:91
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2148
DWORD *typedef HANDLE
Definition: winlogon.h:52
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:4771
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:959
LONG NTSTATUS
Definition: DriverTester.h:11
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
unsigned short USHORT
Definition: pedump.c:61
#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
static WCHAR device_name[]
Definition: btrfs.c:54
UINT32 debug_log_level
Definition: btrfs.c:68
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:1697
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_READ
Definition: rdpdr.c:46
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:984
static ACCESS_MASK const OBJECT_ATTRIBUTES ULONG const UNICODE_STRING ULONG PULONG dispos
Definition: reg.c:130
#define IRP_MJ_CLEANUP
static WCHAR dosdevice_name[]
Definition: btrfs.c:55
#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:831
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
#define NTDDI_WIN8
Definition: sdkddkver.h:113
BOOL finished_probing
Definition: btrfs.c:93
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:786
UNICODE_STRING log_file
Definition: btrfs.c:83
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
void read_registry(PUNICODE_STRING regpath, BOOL refresh)
Definition: registry.c:753
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
_Requires_exclusive_lock_held_ ( Vcb->  tree_lock)
_Success_ ( return  = = 0)

Definition at line 389 of file btrfs.c.

390  {
391  DIR_ITEM* xa = (DIR_ITEM*)item;
392  USHORT xasize;
393 
394  while (TRUE) {
395  if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m + xa->n)) {
396  WARN("DIR_ITEM is truncated\n");
397  return FALSE;
398  }
399 
400  if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name, xa->n) == xa->n) {
401  TRACE("found xattr %s\n", name);
402 
403  *datalen = xa->m;
404 
405  if (xa->m > 0) {
407  if (!*data) {
408  ERR("out of memory\n");
409  return FALSE;
410  }
411 
412  RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
413  } else
414  *data = NULL;
415 
416  return TRUE;
417  }
418 
419  xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
420 
421  if (size > xasize) {
422  size -= xasize;
423  xa = (DIR_ITEM*)&xa->name[xa->m + xa->n];
424  } else
425  break;
426  }
427 
428  TRACE("xattr %s not found\n", name);
429 
430  return FALSE;
431 }
#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:252
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1027
#define ALLOC_TAG
Definition: btrfs_drv.h:85
#define FALSE
Definition: types.h:117
char name[1]
Definition: btrfs.h:255
smooth NULL
Definition: ftsmooth.c:557
#define TRACE(s)
Definition: solgame.cpp:4
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
GLsizeiptr size
Definition: glext.h:5919
Definition: name.c:23
if(!r)
Definition: btrfs.c:2586
UINT16 n
Definition: btrfs.h:253
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
_Success_ ( return >=  0)
static void add_device_to_list ( _In_ device_extension Vcb,
_In_ device dev 
)
static

Definition at line 2862 of file btrfs.c.

Referenced by find_device_from_uuid(), and load_chunk_root().

2862  {
2863  LIST_ENTRY* le;
2864 
2865  le = Vcb->devices.Flink;
2866 
2867  while (le != &Vcb->devices) {
2868  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
2869 
2870  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
2871  InsertHeadList(le->Blink, &dev->list_entry);
2872  return;
2873  }
2874 
2875  le = le->Flink;
2876  }
2877 
2878  InsertTailList(&Vcb->devices, &dev->list_entry);
2879 }
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:156
#define InsertTailList(ListHead, Entry)
Definition: devices.h:37
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
UINT64 dev_id
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:475
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
InsertTailList & Vcb
Definition: btrfs.c:2628
NTSTATUS AddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 5273 of file btrfs.c.

Referenced by _Function_class_().

5273  {
5274 #endif
5275  LIST_ENTRY* le;
5276  NTSTATUS Status;
5277  UNICODE_STRING volname;
5278  ULONG i, j;
5279  pdo_device_extension* pdode = NULL;
5280  PDEVICE_OBJECT voldev;
5282 
5283  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
5284 
5286 
5287  le = pdo_list.Flink;
5288  while (le != &pdo_list) {
5290 
5291  if (pdode2->pdo == PhysicalDeviceObject) {
5292  pdode = pdode2;
5293  break;
5294  }
5295 
5296  le = le->Flink;
5297  }
5298 
5299  if (!pdode) {
5300  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
5301  Status = STATUS_NOT_SUPPORTED;
5302  goto end;
5303  }
5304 
5306 
5307  volname.Length = volname.MaximumLength = (USHORT)((wcslen(BTRFS_VOLUME_PREFIX) + 36 + 1) * sizeof(WCHAR));
5308  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
5309 
5310  if (!volname.Buffer) {
5311  ERR("out of memory\n");
5313  goto end2;
5314  }
5315 
5317 
5319  for (i = 0; i < 16; i++) {
5320  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] >> 4); j++;
5321  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] & 0xf); j++;
5322 
5323  if (i == 3 || i == 5 || i == 7 || i == 9) {
5324  volname.Buffer[j] = '-';
5325  j++;
5326  }
5327  }
5328 
5329  volname.Buffer[j] = '}';
5330 
5331  Status = IoCreateDevice(drvobj, sizeof(volume_device_extension), &volname, FILE_DEVICE_DISK,
5333  if (!NT_SUCCESS(Status)) {
5334  ERR("IoCreateDevice returned %08x\n", Status);
5335  goto end2;
5336  }
5337 
5338  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
5339  voldev->Flags |= DO_DIRECT_IO;
5340 
5341  vde = voldev->DeviceExtension;
5342  vde->type = VCB_TYPE_VOLUME;
5343  vde->name = volname;
5344  vde->device = voldev;
5345  vde->mounted_device = NULL;
5346  vde->pdo = PhysicalDeviceObject;
5347  vde->pdode = pdode;
5348  vde->removing = FALSE;
5349  vde->open_count = 0;
5350 
5351  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
5352  if (!NT_SUCCESS(Status))
5353  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5354 
5355  vde->attached_device = IoAttachDeviceToDeviceStack(voldev, PhysicalDeviceObject);
5356 
5357  pdode->vde = vde;
5358 
5359  if (pdode->removable)
5360  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
5361 
5362  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
5363 
5364  Status = IoSetDeviceInterfaceState(&vde->bus_name, TRUE);
5365  if (!NT_SUCCESS(Status))
5366  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5367 
5368  Status = STATUS_SUCCESS;
5369 
5370 end2:
5372 
5373 end:
5375 
5376  return Status;
5377 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1599
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#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
__wchar_t WCHAR
Definition: xmlstorage.h:180
return STATUS_SUCCESS
Definition: btrfs.c:2664
PDEVICE_OBJECT device
Definition: btrfs_drv.h:812
UINT8 uuid[16]
Definition: btrfs.h:118
#define WARN(fmt,...)
Definition: debug.h:111
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:814
GLuint GLuint end
Definition: gl.h:1545
#define WCHAR
Definition: msvc.h:43
LIST_ENTRY pdo_list
Definition: btrfs.c:92
Status
Definition: btrfs.c:3828
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
UNICODE_STRING name
Definition: btrfs_drv.h:811
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:826
#define ALLOC_TAG
Definition: btrfs_drv.h:85
UNICODE_STRING bus_name
Definition: btrfs_drv.h:816
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
#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:766
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:557
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1315
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:815
ERESOURCE pdo_list_lock
Definition: btrfs.c:91
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define BTRFS_VOLUME_PREFIX
Definition: btrfs_drv.h:113
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:618
ERESOURCE child_lock
Definition: btrfs_drv.h:831
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:813
PDRIVER_OBJECT drvobj
Definition: btrfs.c:59
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:817
#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:959
LONG NTSTATUS
Definition: DriverTester.h:11
#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL
Definition: btrfs_drv.h:130
unsigned short USHORT
Definition: pedump.c:61
Definition: list.h:27
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
volume_device_extension * vde
Definition: btrfs_drv.h:825
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
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:831
#define NTDDI_WIN8
Definition: sdkddkver.h:113
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static void calculate_total_space ( _In_ device_extension Vcb,
_Out_ UINT64 totalsize,
_Out_ UINT64 freespace 
)
static

Definition at line 580 of file btrfs.c.

Referenced by _Dispatch_type_().

580  {
581  UINT64 nfactor, dfactor, sectors_used;
582 
583  if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags & BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
584  nfactor = 1;
585  dfactor = 2;
586  } else if (Vcb->data_flags & BLOCK_FLAG_RAID5) {
587  nfactor = Vcb->superblock.num_devices - 1;
588  dfactor = Vcb->superblock.num_devices;
589  } else if (Vcb->data_flags & BLOCK_FLAG_RAID6) {
590  nfactor = Vcb->superblock.num_devices - 2;
591  dfactor = Vcb->superblock.num_devices;
592  } else {
593  nfactor = 1;
594  dfactor = 1;
595  }
596 
597  sectors_used = Vcb->superblock.bytes_used / Vcb->superblock.sector_size;
598 
599  *totalsize = (Vcb->superblock.total_bytes / Vcb->superblock.sector_size) * nfactor / dfactor;
600  *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
601 }
#define freespace(fs, percentreserved)
Definition: fs.h:640
GLenum GLclampf GLint GLenum GLuint GLenum GLenum dfactor
Definition: glfuncs.h:18
#define BLOCK_FLAG_RAID10
Definition: shellext.h:62
#define BLOCK_FLAG_RAID6
Definition: shellext.h:64
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:61
#define BLOCK_FLAG_RAID5
Definition: shellext.h:63
unsigned long long UINT64
InsertTailList & Vcb
Definition: btrfs.c:2628
#define BLOCK_FLAG_RAID1
Definition: shellext.h:60
static void check_cpu ( )
static

Definition at line 5135 of file btrfs.c.

Referenced by _Function_class_().

5135  {
5136  unsigned int cpuInfo[4];
5137 #ifndef _MSC_VER
5138  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
5139  have_sse42 = cpuInfo[2] & bit_SSE4_2;
5140  have_sse2 = cpuInfo[3] & bit_SSE2;
5141 #else
5142  __cpuid(cpuInfo, 1);
5143  have_sse42 = cpuInfo[2] & (1 << 20);
5144  have_sse2 = cpuInfo[3] & (1 << 26);
5145 #endif
5146 
5147  if (have_sse42)
5148  TRACE("SSE4.2 is supported\n");
5149  else
5150  TRACE("SSE4.2 not supported\n");
5151 
5152  if (have_sse2)
5153  TRACE("SSE2 is supported\n");
5154  else
5155  TRACE("SSE2 is not supported\n");
5156 }
BOOL have_sse2
Definition: btrfs.c:62
BOOL have_sse42
Definition: btrfs.c:62
#define TRACE(s)
Definition: solgame.cpp:4
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
void chunk_lock_range ( _In_ device_extension Vcb,
_In_ chunk c,
_In_ UINT64  start,
_In_ UINT64  length 
)

Definition at line 5006 of file btrfs.c.

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

5006  {
5007  LIST_ENTRY* le;
5008  BOOL locked;
5009  range_lock* rl;
5010 
5011  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5012  if (!rl) {
5013  ERR("out of memory\n");
5014  return;
5015  }
5016 
5017  rl->start = start;
5018  rl->length = length;
5019  rl->thread = PsGetCurrentThread();
5020 
5021  while (TRUE) {
5022  locked = FALSE;
5023 
5024  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5025 
5026  le = c->range_locks.Flink;
5027  while (le != &c->range_locks) {
5029 
5030  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5031  locked = TRUE;
5032  break;
5033  }
5034 
5035  le = le->Flink;
5036  }
5037 
5038  if (!locked) {
5039  InsertTailList(&c->range_locks, &rl->list_entry);
5040 
5041  ExReleaseResourceLite(&c->range_locks_lock);
5042  return;
5043  }
5044 
5045  KeClearEvent(&c->range_locks_event);
5046 
5047  ExReleaseResourceLite(&c->range_locks_lock);
5048 
5049  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, FALSE, NULL);
5050  }
5051 }
UINT64 length
Definition: btrfs_drv.h:495
#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
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
LIST_ENTRY list_entry
Definition: btrfs_drv.h:497
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:494
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:496
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
GLuint start
Definition: gl.h:1545
Definition: list.h:27
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
InsertTailList & Vcb
Definition: btrfs.c:2628
void chunk_unlock_range ( _In_ device_extension Vcb,
_In_ chunk c,
_In_ UINT64  start,
_In_ UINT64  length 
)

Definition at line 5053 of file btrfs.c.

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

5053  {
5054  LIST_ENTRY* le;
5055 
5056  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5057 
5058  le = c->range_locks.Flink;
5059  while (le != &c->range_locks) {
5061 
5062  if (rl->start == start && rl->length == length) {
5064  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5065  break;
5066  }
5067 
5068  le = le->Flink;
5069  }
5070 
5071  KeSetEvent(&c->range_locks_event, 0, FALSE);
5072 
5073  ExReleaseResourceLite(&c->range_locks_lock);
5074 }
UINT64 length
Definition: btrfs_drv.h:495
#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
#define FALSE
Definition: types.h:117
LIST_ENTRY list_entry
Definition: btrfs_drv.h:497
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:494
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
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
InsertTailList & Vcb
Definition: btrfs.c:2628
static NTSTATUS close_file ( _In_ PFILE_OBJECT  FileObject,
_In_ PIRP  Irp 
)
static

Definition at line 1630 of file btrfs.c.

Referenced by _Dispatch_type_().

1630  {
1631  fcb* fcb;
1632  ccb* ccb;
1633  file_ref* fileref = NULL;
1634  LONG open_files;
1636 
1637  UNUSED(Irp);
1638 
1639  TRACE("FileObject = %p\n", FileObject);
1640 
1641  fcb = FileObject->FsContext;
1642  if (!fcb) {
1643  TRACE("FCB was NULL, returning success\n");
1644  return STATUS_SUCCESS;
1645  }
1646 
1647  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1648 
1649  ccb = FileObject->FsContext2;
1650 
1651  TRACE("close called for %S (fcb == %p)\n", file_desc(FileObject), fcb);
1652 
1653  // FIXME - make sure notification gets sent if file is being deleted
1654 
1655  if (ccb) {
1656  if (ccb->query_string.Buffer)
1658 
1659  if (ccb->filename.Buffer)
1660  ExFreePool(ccb->filename.Buffer);
1661 
1662  // FIXME - use refcounts for fileref
1663  fileref = ccb->fileref;
1664 
1665  if (fcb->Vcb->running_sends > 0) {
1666  BOOL send_cancelled = FALSE;
1667 
1668  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1669 
1670  if (ccb->send) {
1671  ccb->send->cancelling = TRUE;
1672  send_cancelled = TRUE;
1673  KeSetEvent(&ccb->send->cleared_event, 0, FALSE);
1674  }
1675 
1676  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1677 
1678  if (send_cancelled) {
1679  while (ccb->send) {
1680  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1681  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1682  }
1683  }
1684  }
1685 
1686  ExFreePool(ccb);
1687  }
1688 
1690 
1691  if (open_files == 0 && fcb->Vcb->removing) {
1692  uninit(fcb->Vcb, FALSE);
1693  return STATUS_SUCCESS;
1694  }
1695 
1696  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1697  return STATUS_SUCCESS;
1698 
1699  Vcb = fcb->Vcb;
1700 
1701  ExAcquireResourceExclusiveLite(&Vcb->fcb_lock, TRUE);
1702 
1703  if (fileref)
1704  free_fileref(fcb->Vcb, fileref);
1705  else
1706  free_fcb(Vcb, fcb);
1707 
1708  ExReleaseResourceLite(&Vcb->fcb_lock);
1709 
1710  return STATUS_SUCCESS;
1711 }
void uninit(_In_ device_extension *Vcb, _In_ BOOL flush)
Definition: btrfs.c:1713
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
return STATUS_SUCCESS
Definition: btrfs.c:2664
BOOL cancelling
Definition: btrfs_drv.h:331
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1293
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UNICODE_STRING filename
Definition: btrfs_drv.h:349
UNICODE_STRING query_string
Definition: btrfs_drv.h:341
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
void free_fileref(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ file_ref *fr)
Definition: btrfs.c:1571
smooth NULL
Definition: ftsmooth.c:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
#define UNUSED(x)
Definition: btrfs_drv.h:80
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
struct _fcb fcb
Definition: btrfs_drv.h:1237
KEVENT cleared_event
Definition: btrfs_drv.h:330
struct _file_ref * fileref
Definition: btrfs_drv.h:268
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:348
InsertTailList & Vcb
Definition: btrfs.c:2628
#define VPB_MOUNTED
Definition: iotypes.h:1758
struct _device_extension * Vcb
Definition: btrfs_drv.h:250
void free_fcb(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ fcb *fcb)
Definition: btrfs.c:1463
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
send_info * send
Definition: btrfs_drv.h:357
static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 3652 of file btrfs.c.

Referenced by mount_vol().

3652  {
3653  device_extension* Vcb = DeviceObject->DeviceExtension;
3654  ULONG i;
3655 
3657 
3659  if (!Vcb->calcthreads.threads) {
3660  ERR("out of memory\n");
3662  }
3663 
3667 
3669 
3670  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
3671  NTSTATUS Status;
3672 
3675 
3676  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, NULL, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
3677  if (!NT_SUCCESS(Status)) {
3678  ULONG j;
3679 
3680  ERR("PsCreateSystemThread returned %08x\n", Status);
3681 
3682  for (j = 0; j < i; j++) {
3683  Vcb->calcthreads.threads[i].quit = TRUE;
3684  }
3685 
3686  KeSetEvent(&Vcb->calcthreads.event, 0, FALSE);
3687 
3688  return Status;
3689  }
3690  }
3691 
3692  return STATUS_SUCCESS;
3693 }
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble const GLfloat const GLdouble const GLfloat GLenum GLint GLint GLint GLint GLint GLint j
Definition: glfuncs.h:98
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
return STATUS_SUCCESS
Definition: btrfs.c:2664
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
Status
Definition: btrfs.c:3828
#define ALLOC_TAG
Definition: btrfs_drv.h:85
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
LIST_ENTRY job_list
Definition: btrfs_drv.h:593
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ERESOURCE lock
Definition: btrfs_drv.h:594
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTKERNELAPI ULONG NTAPI KeQueryActiveProcessorCount(OUT PKAFFINITY ActiveProcessors OPTIONAL)
Definition: ke.c:15
#define ERR(fmt,...)
Definition: debug.h:109
LONG NTSTATUS
Definition: DriverTester.h:11
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
drv_calc_threads calcthreads
Definition: btrfs_drv.h:765
#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
drv_calc_thread * threads
Definition: btrfs_drv.h:595
KEVENT finished
Definition: btrfs_drv.h:587
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
InsertTailList & Vcb
Definition: btrfs.c:2628
PDEVICE_OBJECT DeviceObject
Definition: btrfs_drv.h:585
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 974 of file btrfs.c.

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

975  {
977  root* r;
978  tree* t = NULL;
979  ROOT_ITEM* ri;
981 
983  if (!r) {
984  ERR("out of memory\n");
986  }
987 
989  if (!r->nonpaged) {
990  ERR("out of memory\n");
991  ExFreePool(r);
993  }
994 
995  if (!no_tree) {
997  if (!t) {
998  ERR("out of memory\n");
999  ExFreePool(r->nonpaged);
1000  ExFreePool(r);
1002  }
1003 
1004  t->is_unique = TRUE;
1006  t->buf = NULL;
1007  }
1008 
1010  if (!ri) {
1011  ERR("out of memory\n");
1012 
1013  if (t)
1014  ExFreePool(t);
1015 
1016  ExFreePool(r->nonpaged);
1017  ExFreePool(r);
1019  }
1020 
1021  r->id = id;
1022  r->treeholder.address = 0;
1023  r->treeholder.generation = Vcb->superblock.generation;
1024  r->treeholder.tree = t;
1025  r->lastinode = 0;
1026  r->dirty = FALSE;
1027  r->received = FALSE;
1028  r->reserved = NULL;
1029  r->parent = 0;
1030  r->send_ops = 0;
1031  RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
1032  r->root_item.num_references = 1;
1033  InitializeListHead(&r->fcbs);
1034 
1035  RtlCopyMemory(ri, &r->root_item, sizeof(ROOT_ITEM));
1036 
1037  // We ask here for a traverse_ptr to the item we're inserting, so we can
1038  // copy some of the tree's variables
1039 
1040  Status = insert_tree_item(Vcb, Vcb->root_root, id, TYPE_ROOT_ITEM, offset, ri, sizeof(ROOT_ITEM), &tp, Irp);
1041  if (!NT_SUCCESS(Status)) {
1042  ERR("insert_tree_item returned %08x\n", Status);
1043  ExFreePool(ri);
1044 
1045  if (t)
1046  ExFreePool(t);
1047 
1048  ExFreePool(r->nonpaged);
1049  ExFreePool(r);
1050  return Status;
1051  }
1052 
1054 
1055  InsertTailList(&Vcb->roots, &r->list_entry);
1056 
1057  if (!no_tree) {
1058  RtlZeroMemory(&t->header, sizeof(tree_header));
1059  t->header.fs_uuid = tp.tree->header.fs_uuid;
1060  t->header.address = 0;
1061  t->header.flags = HEADER_FLAG_MIXED_BACKREF | 1; // 1 == "written"? Why does the Linux driver record this?
1063  t->header.generation = Vcb->superblock.generation;
1064  t->header.tree_id = id;
1065  t->header.num_items = 0;
1066  t->header.level = 0;
1067 
1068  t->has_address = FALSE;
1069  t->size = 0;
1070  t->Vcb = Vcb;
1071  t->parent = NULL;
1072  t->paritem = NULL;
1073  t->root = r;
1074 
1076 
1077  t->new_address = 0;
1078  t->has_new_address = FALSE;
1079  t->updated_extents = FALSE;
1080 
1081  InsertTailList(&Vcb->trees, &t->list_entry);
1082  t->list_entry_hash.Flink = NULL;
1083 
1084  t->write = TRUE;
1085  Vcb->need_write = TRUE;
1086  }
1087 
1088  *rootptr = r;
1089 
1090  return STATUS_SUCCESS;
1091 }
UINT64 id
Definition: btrfs_drv.h:411
#define TYPE_ROOT_ITEM
Definition: btrfs.h:26
UINT64 address
Definition: btrfs_drv.h:364
UINT64 generation
Definition: btrfs.h:137
struct _root * root
Definition: btrfs_drv.h:393
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
BOOL write
Definition: btrfs_drv.h:400
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOL uniqueness_determined
Definition: btrfs_drv.h:402
UINT32 num_items
Definition: btrfs.h:139
UINT64 flags
Definition: btrfs.h:135
UINT64 new_address
Definition: btrfs_drv.h:397
LIST_ENTRY list_entry
Definition: btrfs_drv.h:422
_In_ PIRP Irp
Definition: csq.h:116
return STATUS_SUCCESS
Definition: btrfs.c:2664
LIST_ENTRY list_entry_hash
Definition: btrfs_drv.h:396
GLdouble GLdouble t
Definition: gl.h:2047
ERESOURCE load_tree_lock
Definition: btrfs_drv.h:407
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
ROOT_ITEM root_item
Definition: btrfs_drv.h:415
LONGLONG lastinode
Definition: btrfs_drv.h:412
LIST_ENTRY fcbs
Definition: btrfs_drv.h:421
UINT8 * buf
Definition: btrfs_drv.h:403
#define InsertTailList(ListHead, Entry)
LIST_ENTRY list_entry
Definition: btrfs_drv.h:395
Status
Definition: btrfs.c:3828
#define HEADER_FLAG_MIXED_BACKREF
Definition: btrfs.h:129
#define ALLOC_TAG
Definition: btrfs_drv.h:85
struct _device_extension * Vcb
Definition: btrfs_drv.h:390
root_nonpaged * nonpaged
Definition: btrfs_drv.h:414
tree * tree
Definition: btrfs_drv.h:457
#define FALSE
Definition: types.h:117
struct _tree * tree
Definition: btrfs_drv.h:366
tree_data * paritem
Definition: btrfs_drv.h:392
BOOL dirty
Definition: btrfs_drv.h:416
BOOL is_unique
Definition: btrfs_drv.h:401
smooth NULL
Definition: ftsmooth.c:557
UINT64 address
Definition: btrfs.h:134
BOOL updated_extents
Definition: btrfs_drv.h:399
struct _tree * parent
Definition: btrfs_drv.h:391
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2584
BTRFS_UUID chunk_tree_uuid
Definition: btrfs.h:136
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LONG send_ops
Definition: btrfs_drv.h:420
_In_ UINT64 id
Definition: btrfs.c:2583
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
LIST_ENTRY itemlist
Definition: btrfs_drv.h:394
BOOL received
Definition: btrfs_drv.h:417
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PEPROCESS reserved
Definition: btrfs_drv.h:418
tree_header header
Definition: btrfs_drv.h:386
tree_holder treeholder
Definition: btrfs_drv.h:413
BOOL has_new_address
Definition: btrfs_drv.h:398
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:832
BOOL has_address
Definition: btrfs_drv.h:388
UINT64 tree_id
Definition: btrfs.h:138
UINT64 generation
Definition: btrfs_drv.h:365
#define ERR(fmt,...)
Definition: debug.h:109
LONG NTSTATUS
Definition: DriverTester.h:11
BTRFS_UUID fs_uuid
Definition: btrfs.h:133
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
UINT64 parent
Definition: btrfs_drv.h:419
UINT32 size
Definition: btrfs_drv.h:389
UINT8 level
Definition: btrfs.h:140
InitializeListHead & r
Definition: btrfs.c:2600
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
UINT32 num_references
Definition: btrfs.h:292
InsertTailList & Vcb
Definition: btrfs.c:2628
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
GLintptr offset
Definition: glext.h:5920
DEFINE_GUID ( BtrfsBusInterface  ,
0x4d414874  ,
0x6865  ,
0x6761  ,
0x6d  ,
0x65  ,
0x83  ,
0x69  ,
0x17  ,
0x9a  ,
0x7d  ,
0x1d   
)
NTSTATUS delete_fileref ( _In_ file_ref fileref,
_In_ PFILE_OBJECT  FileObject,
_In_opt_ PIRP  Irp,
_In_ LIST_ENTRY rollback 
)

Definition at line 1918 of file btrfs.c.

Referenced by _Dispatch_type_(), move_across_subvols(), set_link_information(), and set_rename_information().

1918  {
1919  LARGE_INTEGER newlength, time;
1920  BTRFS_TIME now;
1921  NTSTATUS Status;
1922  ULONG utf8len = 0;
1923 
1924  KeQuerySystemTime(&time);
1925  win_time_to_unix(time, &now);
1926 
1927  ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, TRUE);
1928 
1929  if (fileref->deleted) {
1930  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1931  return STATUS_SUCCESS;
1932  }
1933 
1934  if (fileref->fcb->subvol->send_ops > 0) {
1935  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1936  return STATUS_ACCESS_DENIED;
1937  }
1938 
1939  fileref->deleted = TRUE;
1941 
1942  // delete INODE_ITEM (0x1)
1943 
1944  TRACE("nlink = %u\n", fileref->fcb->inode_item.st_nlink);
1945 
1946  if (!fileref->fcb->ads) {
1947  if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
1948  LIST_ENTRY* le;
1949 
1950  mark_fcb_dirty(fileref->fcb);
1951 
1952  fileref->fcb->inode_item_changed = TRUE;
1953 
1954  if (fileref->fcb->inode_item.st_nlink > 1) {
1955  fileref->fcb->inode_item.st_nlink--;
1956  fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
1957  fileref->fcb->inode_item.sequence++;
1958  fileref->fcb->inode_item.st_ctime = now;
1959  } else {
1960  // excise extents
1961 
1962  if (fileref->fcb->type != BTRFS_TYPE_DIRECTORY && fileref->fcb->inode_item.st_size > 0) {
1963  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);
1964  if (!NT_SUCCESS(Status)) {
1965  ERR("excise_extents returned %08x\n", Status);
1966  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1967  return Status;
1968  }
1969  }
1970 
1971  fileref->fcb->Header.AllocationSize.QuadPart = 0;
1972  fileref->fcb->Header.FileSize.QuadPart = 0;
1973  fileref->fcb->Header.ValidDataLength.QuadPart = 0;
1974 
1975  if (FileObject) {
1976  CC_FILE_SIZES ccfs;
1977 
1978  ccfs.AllocationSize = fileref->fcb->Header.AllocationSize;
1979  ccfs.FileSize = fileref->fcb->Header.FileSize;
1980  ccfs.ValidDataLength = fileref->fcb->Header.ValidDataLength;
1981 
1982  Status = STATUS_SUCCESS;
1983 
1984  _SEH2_TRY {
1985  CcSetFileSizes(FileObject, &ccfs);
1987  Status = _SEH2_GetExceptionCode();
1988  } _SEH2_END;
1989 
1990  if (!NT_SUCCESS(Status)) {
1991  ERR("CcSetFileSizes threw exception %08x\n", Status);
1992  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1993  return Status;
1994  }
1995  }
1996 
1997  fileref->fcb->deleted = TRUE;
1998  }
1999 
2000  if (fileref->dc) {
2001  le = fileref->fcb->hardlinks.Flink;
2002  while (le != &fileref->fcb->hardlinks) {
2004 
2005  if (hl->parent == fileref->parent->fcb->inode && hl->index == fileref->dc->index) {
2007 
2008  if (hl->name.Buffer)
2009  ExFreePool(hl->name.Buffer);
2010 
2011  if (hl->utf8.Buffer)
2012  ExFreePool(hl->utf8.Buffer);
2013 
2014  ExFreePool(hl);
2015  break;
2016  }
2017 
2018  le = le->Flink;
2019  }
2020  }
2021  } else if (fileref->fcb->subvol->parent == fileref->parent->fcb->subvol->id) { // valid subvolume
2022  if (fileref->fcb->subvol->root_item.num_references > 1) {
2023  fileref->fcb->subvol->root_item.num_references--;
2024 
2025  mark_fcb_dirty(fileref->fcb); // so ROOT_ITEM gets updated
2026  } else {
2027  // FIXME - we need a lock here
2028 
2029  RemoveEntryList(&fileref->fcb->subvol->list_entry);
2030 
2031  InsertTailList(&fileref->fcb->Vcb->drop_roots, &fileref->fcb->subvol->list_entry);
2032  }
2033  }
2034  } else {
2035  fileref->fcb->deleted = TRUE;
2036  mark_fcb_dirty(fileref->fcb);
2037  }
2038 
2039  // remove dir_child from parent
2040 
2041  if (fileref->dc) {
2042  TRACE("delete file %.*S\n", fileref->dc->name.Length / sizeof(WCHAR), fileref->dc->name.Buffer);
2043 
2044  ExAcquireResourceExclusiveLite(&fileref->parent->fcb->nonpaged->dir_children_lock, TRUE);
2045  RemoveEntryList(&fileref->dc->list_entry_index);
2046 
2047  if (!fileref->fcb->ads)
2049 
2050  ExReleaseResourceLite(&fileref->parent->fcb->nonpaged->dir_children_lock);
2051 
2052  if (!fileref->oldutf8.Buffer)
2053  fileref->oldutf8 = fileref->dc->utf8;
2054  else
2055  ExFreePool(fileref->dc->utf8.Buffer);
2056 
2057  utf8len = fileref->dc->utf8.Length;
2058 
2059  fileref->oldindex = fileref->dc->index;
2060 
2061  ExFreePool(fileref->dc->name.Buffer);
2062  ExFreePool(fileref->dc->name_uc.Buffer);
2063  ExFreePool(fileref->dc);
2064 
2065  fileref->dc = NULL;
2066  }
2067 
2068  // update INODE_ITEM of parent
2069 
2070  ExAcquireResourceExclusiveLite(fileref->parent->fcb->Header.Resource, TRUE);
2071 
2072  fileref->parent->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2073  fileref->parent->fcb->inode_item.sequence++;
2074  fileref->parent->fcb->inode_item.st_ctime = now;
2075 
2076  if (!fileref->fcb->ads) {
2077  TRACE("fileref->parent->fcb->inode_item.st_size (inode %llx) was %llx\n", fileref->parent->fcb->inode, fileref->parent->fcb->inode_item.st_size);
2078  fileref->parent->fcb->inode_item.st_size -= utf8len * 2;
2079  TRACE("fileref->parent->fcb->inode_item.st_size (inode %llx) now %llx\n", fileref->parent->fcb->inode, fileref->parent->fcb->inode_item.st_size);
2080  fileref->parent->fcb->inode_item.st_mtime = now;
2081  }
2082 
2083  fileref->parent->fcb->inode_item_changed = TRUE;
2084  ExReleaseResourceLite(fileref->parent->fcb->Header.Resource);
2085 
2086  if (!fileref->fcb->ads && fileref->parent->dc)
2088 
2089  mark_fcb_dirty(fileref->parent->fcb);
2090 
2091  fileref->fcb->subvol->root_item.ctransid = fileref->fcb->Vcb->superblock.generation;
2092  fileref->fcb->subvol->root_item.ctime = now;
2093 
2094  newlength.QuadPart = 0;
2095 
2096  if (FileObject && !CcUninitializeCacheMap(FileObject, &newlength, NULL))
2097  TRACE("CcUninitializeCacheMap failed\n");
2098 
2099  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2100 
2101  return STATUS_SUCCESS;
2102 }
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
static UINT64 __inline sector_align(UINT64 n, UINT64 a)
#define TRUE
Definition: types.h:120
NTSTATUS excise_extents(device_extension *Vcb, fcb *fcb, UINT64 start_data, UINT64 end_data, PIRP Irp, LIST_ENTRY *rollback)
Definition: write.c:2363
_In_ PIRP Irp
Definition: csq.h:116
__wchar_t WCHAR
Definition: xmlstorage.h:180
void send_notification_fcb(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1344
return STATUS_SUCCESS
Definition: btrfs.c:2664
#define FILE_NOTIFY_CHANGE_LAST_WRITE
__u16 time
Definition: mkdosfs.c:366
#define InsertTailList(ListHead, Entry)
Status
Definition: btrfs.c:3828
LARGE_INTEGER FileSize
Definition: cctypes.h:16
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
time_t now
Definition: finger.c:65
#define _SEH2_END
Definition: pseh2_64.h:7
#define FILE_ACTION_MODIFIED
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:67
smooth NULL
Definition: ftsmooth.c:557
_In_ PFILE_OBJECT FileObject
Definition: classpnp.h:1229
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
void mark_fcb_dirty(_In_ fcb *fcb)
Definition: btrfs.c:1425
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
struct _file_ref * fileref
Definition: btrfs_drv.h:268
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
LARGE_INTEGER ValidDataLength
Definition: cctypes.h:17
Definition: typedefs.h:117
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1237
#define ERR(fmt,...)
Definition: debug.h:109
LONG NTSTATUS
Definition: DriverTester.h:11
LARGE_INTEGER AllocationSize
Definition: cctypes.h:15
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:354
void remove_dir_child_from_hash_lists(fcb *fcb, dir_child *dc)
Definition: fileinfo.c:551
#define _SEH2_TRY
Definition: pseh2_64.h:5
void mark_fileref_dirty(_In_ file_ref *fileref)
Definition: btrfs.c:1447
Definition: list.h:27
static __inline void win_time_to_unix(LARGE_INTEGER t, BTRFS_TIME *out)
Definition: btrfs_drv.h:905
unsigned int ULONG
Definition: retypes.h:1
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:259
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112
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 
)

Definition at line 2542 of file btrfs.c.

Referenced by _Function_class_(), add_device(), disk_arrival(), finish_removing_device(), get_device_change_count(), get_devices(), init_device(), is_btrfs_volume(), is_device_removable(), is_volume_mounted(), mount_vol(), mountmgr_add_drive_letter(), mountmgr_process_drive(), probe_volume(), query_filesystems(), remove_drive_letter(), remove_volume_child(), resize_device(), test_vol(), trim_unalloc_space(), trim_whole_device(), verify_device(), verify_vcb(), vol_check_verify(), vol_get_disk_extents(), vol_is_writable(), and volume_arrival().

2543  {
2544  PIRP Irp;
2545  KEVENT Event;
2546  NTSTATUS Status;
2549 
2551 
2553  DeviceObject,
2554  InputBuffer,
2555  InputBufferSize,
2556  OutputBuffer,
2557  OutputBufferSize,
2558  FALSE,
2559  &Event,
2560  &IoStatus);
2561 
2562  if (!Irp) return STATUS_INSUFFICIENT_RESOURCES;
2563 
2564  if (Override) {
2565  IrpSp = IoGetNextIrpStackLocation(Irp);
2566  IrpSp->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
2567  }
2568 
2569  Status = IoCallDriver(DeviceObject, Irp);
2570 
2571  if (Status == STATUS_PENDING) {
2573  Status = IoStatus.Status;
2574  }
2575 
2576  if (iosb)
2577  *iosb = IoStatus;
2578 
2579  return Status;
2580 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK _In_ PDEVICE_OBJECT DeviceObject
Definition: npfs.h:636
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
Status
Definition: btrfs.c:3828
CHAR InputBuffer[80]
Definition: conmgr.c:33
ACPI_EFI_EVENT Event
Definition: acefiex.h:633
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:557
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1774
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define STATUS_PENDING
Definition: ntstatus.h:82
static PIO_STATUS_BLOCK iosb
Definition: file.c:95
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
_In_ PLARGE_INTEGER _In_ ULONG _In_ BOOLEAN _In_ ULONG _Out_ PVOID _Out_ PIO_STATUS_BLOCK IoStatus
Definition: npfs.h:636
LONG NTSTATUS
Definition: DriverTester.h:11
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
_In_ PIRP _In_ PIO_STACK_LOCATION IrpSp
Definition: tdikrnl.h:1069
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1155
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:818
PVOID PIRP
Definition: usb.h:38
_Ret_z_ WCHAR* file_desc ( _In_ PFILE_OBJECT  FileObject)

Definition at line 1293 of file btrfs.c.

Referenced b