ReactOS  0.4.11-dev-765-g5e024bf
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_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
 
 _Dispatch_type_ (IRP_MJ_CLEANUP)
 
ULONG get_file_attributes (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ UINT64 inode, _In_ UINT8 type, _In_ BOOL dotfile, _In_ BOOL ignore_xa, _In_opt_ PIRP Irp)
 
NTSTATUS sync_read_phys (_In_ PDEVICE_OBJECT DeviceObject, _In_ UINT64 StartingOffset, _In_ ULONG Length, _Out_writes_bytes_(Length) PUCHAR Buffer, _In_ BOOL override)
 
static NTSTATUS read_superblock (_In_ device_extension *Vcb, _In_ PDEVICE_OBJECT device, _In_ UINT64 length)
 
NTSTATUS dev_ioctl (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize, _Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _In_ BOOLEAN Override, _Out_opt_ IO_STATUS_BLOCK *iosb)
 
 _Requires_exclusive_lock_held_ (Vcb->tree_lock) static NTSTATUS add_root(_Inout_ device_extension *Vcb
 
 if (!r)
 
 if (!r->nonpaged)
 
 if (tp)
 
else RtlZeroMemoryr (ROOT_ITEM)
 
 if (!Vcb->readonly &&(r->id==BTRFS_ROOT_ROOT||r->id==BTRFS_ROOT_FSTREE||(r->id >=0x100 &&!(r->id &0xf000000000000000))))
 
 switch (r->id)
 
static NTSTATUS look_for_roots (_Requires_exclusive_lock_held_(_Curr_->tree_lock) _In_ device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS find_disk_holes (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ device *dev, _In_opt_ PIRP Irp)
 
static void add_device_to_list (_In_ device_extension *Vcb, _In_ device *dev)
 
_Ret_maybenull_ devicefind_device_from_uuid (_In_ device_extension *Vcb, _In_ BTRFS_UUID *uuid)
 
static BOOL is_device_removable (_In_ PDEVICE_OBJECT devobj)
 
static ULONG get_device_change_count (_In_ PDEVICE_OBJECT devobj)
 
void init_device (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ BOOL get_nums)
 
static NTSTATUS load_chunk_root (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
void protect_superblocks (_Inout_ chunk *c)
 
NTSTATUS find_chunk_usage (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
static NTSTATUS load_sys_chunks (_In_ device_extension *Vcb)
 
static _Ret_maybenull_ rootfind_default_subvol (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
void init_file_cache (_In_ PFILE_OBJECT FileObject, _In_ CC_FILE_SIZES *ccfs)
 
static NTSTATUS create_calc_threads (_In_ PDEVICE_OBJECT DeviceObject)
 
static BOOL is_btrfs_volume (_In_ PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS get_device_pnp_name_guid (_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _In_ const GUID *guid)
 
NTSTATUS get_device_pnp_name (_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _Out_ const GUID **guid)
 
 _Success_ (return >=0) static NTSTATUS check_mount_device(_In_ PDEVICE_OBJECT DeviceObject
 
 if (!NT_SUCCESS(Status))
 
 if (sb->magic!=BTRFS_MAGIC)
 
 if (crc32!=*((UINT32 *) sb->checksum))
 
 if (pnp_name.Length==0)*no_pnp
 
 volume_arrival (drvobj,&pnp_name)
 
static BOOL still_has_superblock (_In_ PDEVICE_OBJECT device)
 
static NTSTATUS mount_vol (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS verify_device (_In_ device_extension *Vcb, _Inout_ device *dev)
 
static NTSTATUS verify_volume (_In_ PDEVICE_OBJECT devobj)
 
 _Dispatch_type_ (IRP_MJ_FILE_SYSTEM_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_LOCK_CONTROL)
 
 _Dispatch_type_ (IRP_MJ_SHUTDOWN)
 
 _Dispatch_type_ (IRP_MJ_POWER)
 
 _Dispatch_type_ (IRP_MJ_SYSTEM_CONTROL)
 
BOOL is_file_name_valid (_In_ PUNICODE_STRING us, _In_ BOOL posix)
 
void chunk_lock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ UINT64 start, _In_ UINT64 length)
 
void chunk_unlock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ UINT64 start, _In_ UINT64 length)
 
void log_device_error (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ int error)
 
static void check_cpu ()
 
 _Function_class_ (KSTART_ROUTINE)
 
NTSTATUS AddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
 
 _Function_class_ (DRIVER_INITIALIZE)
 

Variables

static 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_EXTENDED_IREF
Definition: btrfs.h:108
#define BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA
Definition: btrfs.h:110
#define BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO
Definition: btrfs.h:105
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:104
#define BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF
Definition: btrfs.h:102
#define BTRFS_INCOMPAT_FLAGS_BIG_METADATA
Definition: btrfs.h:107
#define BTRFS_INCOMPAT_FLAGS_NO_HOLES
Definition: btrfs.h:111
#define BTRFS_INCOMPAT_FLAGS_RAID56
Definition: btrfs.h:109
#define BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL
Definition: btrfs.h:103

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.

468  {
469 #else
470 static NTSTATUS drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
471 #endif
474  device_extension* Vcb = DeviceObject->DeviceExtension;
475  BOOL top_level;
476 
478 
479  TRACE("close\n");
480 
481  top_level = is_top_level(Irp);
482 
483  if (DeviceObject == master_devobj) {
484  TRACE("Closing file system\n");
485  Status = STATUS_SUCCESS;
486  goto end;
487  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
488  Status = vol_close(DeviceObject, Irp);
489  goto end;
490  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
491  Status = STATUS_INVALID_PARAMETER;
492  goto end;
493  }
494 
495  IrpSp = IoGetCurrentIrpStackLocation(Irp);
496 
497  // FIXME - unmount if called for volume
498  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
499 
500  Status = close_file(IrpSp->FileObject, Irp);
501 
502 end:
503  Irp->IoStatus.Status = Status;
504  Irp->IoStatus.Information = 0;
505 
507 
508  if (top_level)
510 
511  TRACE("returning %08x\n", Status);
512 
514 
515  return Status;
516 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Status
Definition: btrfs.c:3874
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
GLuint GLuint end
Definition: gl.h:1545
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:60
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2674
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1646
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:48
PVOID PIRP
Definition: usb.h:38
return STATUS_SUCCESS
Definition: btrfs.c:2710
_Dispatch_type_ ( IRP_MJ_FLUSH_BUFFERS  )

Definition at line 518 of file btrfs.c.

521  {
522 #else
523 static NTSTATUS drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
524 #endif
528  fcb* fcb = FileObject->FsContext;
529  device_extension* Vcb = DeviceObject->DeviceExtension;
530  BOOL top_level;
531 
533 
534  TRACE("flush buffers\n");
535 
536  top_level = is_top_level(Irp);
537 
538  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
539  Status = vol_flush_buffers(DeviceObject, Irp);
540  goto end;
541  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
542  Status = STATUS_INVALID_PARAMETER;
543  goto end;
544  }
545 
546  if (!fcb) {
547  ERR("fcb was NULL\n");
548  Status = STATUS_INVALID_PARAMETER;
549  goto end;
550  }
551 
552  if (fcb == Vcb->volume_fcb) {
553  Status = STATUS_INVALID_PARAMETER;
554  goto end;
555  }
556 
557  Irp->IoStatus.Information = 0;
558 
559  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
560 
561  Status = STATUS_SUCCESS;
562  Irp->IoStatus.Status = Status;
563 
564  if (fcb->type != BTRFS_TYPE_DIRECTORY) {
565  CcFlushCache(&fcb->nonpaged->segment_object, NULL, 0, &Irp->IoStatus);
566 
567  if (fcb->Header.PagingIoResource) {
568  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
569  ExReleaseResourceLite(fcb->Header.PagingIoResource);
570  }
571 
572  Status = Irp->IoStatus.Status;
573  }
574 
575 end:
577 
578  TRACE("returning %08x\n", Status);
579 
580  if (top_level)
582 
584 
585  return Status;
586 }
#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
Status
Definition: btrfs.c:3874
NTSTATUS vol_flush_buffers(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:304
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
GLuint GLuint end
Definition: gl.h:1545
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:69
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
InsertTailList & Vcb
Definition: btrfs.c:2674
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:249
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:250
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
UINT8 type
Definition: btrfs_drv.h:256
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1570
return STATUS_SUCCESS
Definition: btrfs.c:2710
_Dispatch_type_ ( IRP_MJ_QUERY_VOLUME_INFORMATION  )

Definition at line 717 of file btrfs.c.

720  {
721 #else
722 static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
723 #endif
726  ULONG BytesCopied = 0;
727  device_extension* Vcb = DeviceObject->DeviceExtension;
728  BOOL top_level;
729 
731 
732  TRACE("query volume information\n");
733  top_level = is_top_level(Irp);
734 
735  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
736  Status = vol_query_volume_information(DeviceObject, Irp);
737  goto end;
738  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
739  Status = STATUS_INVALID_PARAMETER;
740  goto end;
741  }
742 
743  IrpSp = IoGetCurrentIrpStackLocation(Irp);
744 
745  Status = STATUS_NOT_IMPLEMENTED;
746 
747  switch (IrpSp->Parameters.QueryVolume.FsInformationClass) {
749  {
750  FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
751  BOOL overflow = FALSE;
752 #ifndef __REACTOS__
753  WCHAR* fs_name = (Irp->RequestorMode == UserMode && lie_about_fs_type()) ? L"NTFS" : L"Btrfs";
754  ULONG fs_name_len = (ULONG)wcslen(fs_name) * sizeof(WCHAR);
755 #else
756  WCHAR* fs_name = L"Btrfs";
757  ULONG fs_name_len = 5 * sizeof(WCHAR);
758 #endif
759  ULONG orig_fs_name_len = fs_name_len;
760 
761  TRACE("FileFsAttributeInformation\n");
762 
763  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len) {
764  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR))
765  fs_name_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + sizeof(WCHAR);
766  else
767  fs_name_len = 0;
768 
769  overflow = TRUE;
770  }
771 
776  if (Vcb->readonly)
778 
779  // should also be FILE_FILE_COMPRESSION when supported
780  data->MaximumComponentNameLength = 255; // FIXME - check
781  data->FileSystemNameLength = orig_fs_name_len;
782  RtlCopyMemory(data->FileSystemName, fs_name, fs_name_len);
783 
784  BytesCopied = sizeof(FILE_FS_ATTRIBUTE_INFORMATION) - sizeof(WCHAR) + fs_name_len;
785  Status = overflow ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
786  break;
787  }
788 
790  {
791  FILE_FS_DEVICE_INFORMATION* ffdi = Irp->AssociatedIrp.SystemBuffer;
792 
793  TRACE("FileFsDeviceInformation\n");
794 
796 
797  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
798  ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
799  ExReleaseResourceLite(&Vcb->tree_lock);
800 
801  if (Vcb->readonly)
803  else
805 
806  BytesCopied = sizeof(FILE_FS_DEVICE_INFORMATION);
807  Status = STATUS_SUCCESS;
808 
809  break;
810  }
811 
813  {
814  FILE_FS_FULL_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
815 
816  TRACE("FileFsFullSizeInformation\n");
817 
820  ffsi->SectorsPerAllocationUnit = 1;
822 
823  BytesCopied = sizeof(FILE_FS_FULL_SIZE_INFORMATION);
824  Status = STATUS_SUCCESS;
825 
826  break;
827  }
828 
830  {
831  FILE_FS_OBJECTID_INFORMATION* ffoi = Irp->AssociatedIrp.SystemBuffer;
832 
833  TRACE("FileFsObjectIdInformation\n");
834 
835  RtlCopyMemory(ffoi->ObjectId, &Vcb->superblock.uuid.uuid[0], sizeof(UCHAR) * 16);
836  RtlZeroMemory(ffoi->ExtendedInfo, sizeof(ffoi->ExtendedInfo));
837 
838  BytesCopied = sizeof(FILE_FS_OBJECTID_INFORMATION);
839  Status = STATUS_SUCCESS;
840 
841  break;
842  }
843 
845  {
846  FILE_FS_SIZE_INFORMATION* ffsi = Irp->AssociatedIrp.SystemBuffer;
847 
848  TRACE("FileFsSizeInformation\n");
849 
851  ffsi->SectorsPerAllocationUnit = 1;
853 
854  BytesCopied = sizeof(FILE_FS_SIZE_INFORMATION);
855  Status = STATUS_SUCCESS;
856 
857  break;
858  }
859 
861  {
862  FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
864  BOOL overflow = FALSE;
865  ULONG label_len, orig_label_len;
866 
867  TRACE("FileFsVolumeInformation\n");
868  TRACE("max length = %u\n", IrpSp->Parameters.QueryVolume.Length);
869 
870  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
871 
872  Status = RtlUTF8ToUnicodeN(NULL, 0, &label_len, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
873  if (!NT_SUCCESS(Status)) {
874  ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
875  ExReleaseResourceLite(&Vcb->tree_lock);
876  break;
877  }
878 
879  orig_label_len = label_len;
880 
881  if (IrpSp->Parameters.QueryVolume.Length < sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len) {
882  if (IrpSp->Parameters.QueryVolume.Length > sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR))
883  label_len = IrpSp->Parameters.QueryVolume.Length - sizeof(FILE_FS_VOLUME_INFORMATION) + sizeof(WCHAR);
884  else
885  label_len = 0;
886 
887  overflow = TRUE;
888  }
889 
890  TRACE("label_len = %u\n", label_len);
891 
892  ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
893  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];
894  ffvi.VolumeLabelLength = orig_label_len;
895  ffvi.SupportsObjects = FALSE;
896 
897  RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
898 
899  if (label_len > 0) {
900  ULONG bytecount;
901 
902  Status = RtlUTF8ToUnicodeN(&data->VolumeLabel[0], label_len, &bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
903  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL) {
904  ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
905  ExReleaseResourceLite(&Vcb->tree_lock);
906  break;
907  }
908 
909  TRACE("label = %.*S\n", label_len / sizeof(WCHAR), data->VolumeLabel);
910  }
911 
912  ExReleaseResourceLite(&Vcb->tree_lock);
913 
914  BytesCopied = sizeof(FILE_FS_VOLUME_INFORMATION) - sizeof(WCHAR) + label_len;
915  Status = overflow ? STATUS_BUFFER_OVERFLOW : STATUS_SUCCESS;
916  break;
917  }
918 
919 #ifndef __REACTOS__
920 #ifdef _MSC_VER // not in mingw yet
921  case FileFsSectorSizeInformation:
922  {
923  FILE_FS_SECTOR_SIZE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
924 
925  data->LogicalBytesPerSector = Vcb->superblock.sector_size;
926  data->PhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
927  data->PhysicalBytesPerSectorForPerformance = Vcb->superblock.sector_size;
928  data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity = Vcb->superblock.sector_size;
929  data->ByteOffsetForSectorAlignment = 0;
930  data->ByteOffsetForPartitionAlignment = 0;
931 
932  data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
933 
934  if (Vcb->trim && !Vcb->options.no_trim)
935  data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
936 
937  BytesCopied = sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
938 
939  break;
940  }
941 #endif
942 #endif /* __REACTOS__ */
943 
944  default:
945  Status = STATUS_INVALID_PARAMETER;
946  WARN("unknown FsInformationClass %u\n", IrpSp->Parameters.QueryVolume.FsInformationClass);
947  break;
948  }
949 
950  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW)
951  Irp->IoStatus.Information = 0;
952  else
953  Irp->IoStatus.Information = BytesCopied;
954 
955 end:
956  Irp->IoStatus.Status = Status;
957 
959 
960  if (top_level)
962 
963  TRACE("query volume information returning %08x\n", Status);
964 
966 
967  return Status;
968 }
mount_options options
Definition: btrfs_drv.h:713
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
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
superblock superblock
Definition: btrfs_drv.h:721
UINT8 uuid[16]
Definition: btrfs.h:118
#define WARN(fmt,...)
Definition: debug.h:111
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
Status
Definition: btrfs.c:3874
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:619
GLuint GLuint end
Definition: gl.h:1545
struct _FILE_FS_ATTRIBUTE_INFORMATION FILE_FS_ATTRIBUTE_INFORMATION
#define WCHAR
Definition: msvc.h:43
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:52
LARGE_INTEGER ActualAvailableAllocationUnits
Definition: from_kernel.h:272
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
#define FALSE
Definition: types.h:117
LARGE_INTEGER AvailableAllocationUnits
Definition: from_kernel.h:264
smooth NULL
Definition: ftsmooth.c:416
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3149
UINT32 sector_size
Definition: btrfs.h:216
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2674
#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
LONG NTSTATUS
Definition: precomp.h:26
#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:621
#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
static void calculate_total_space(_In_ device_extension *Vcb, _Out_ UINT64 *totalsize, _Out_ UINT64 *freespace)
Definition: btrfs.c:588
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define FILE_NAMED_STREAMS
Definition: from_kernel.h:245
#define FILE_SUPPORTS_OPEN_BY_FILE_ID
Definition: from_kernel.h:251
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static const WCHAR L[]
Definition: oid.c:1087
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
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define FILE_SUPPORTS_SPARSE_FILES
Definition: from_kernel.h:239
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
#define FILE_SUPPORTS_HARD_LINKS
Definition: from_kernel.h:249
BTRFS_UUID uuid
Definition: btrfs.h:203
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define min(a, b)
Definition: monoChain.cc:55
static BOOL lie_about_fs_type()
Definition: btrfs.c:618
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
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
PVOID PIRP
Definition: usb.h:38
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define FILE_PERSISTENT_ACLS
Definition: from_kernel.h:236
#define FILE_READ_ONLY_VOLUME
Definition: from_kernel.h:246
unsigned long long UINT64
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2710
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 1160 of file btrfs.c.

1163  {
1164 #else
1165 static NTSTATUS drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
1166 #endif
1168  device_extension* Vcb = DeviceObject->DeviceExtension;
1169  NTSTATUS Status;
1170  BOOL top_level;
1171 
1173 
1174  TRACE("set volume information\n");
1175 
1176  top_level = is_top_level(Irp);
1177 
1178  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
1179  Status = vol_set_volume_information(DeviceObject, Irp);
1180  goto end;
1181  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
1182  Status = STATUS_INVALID_PARAMETER;
1183  goto end;
1184  }
1185 
1186  Status = STATUS_NOT_IMPLEMENTED;
1187 
1188  if (Vcb->readonly) {
1190  goto end;
1191  }
1192 
1193  if (Vcb->removing || Vcb->locked) {
1194  Status = STATUS_ACCESS_DENIED;
1195  goto end;
1196  }
1197 
1198  switch (IrpSp->Parameters.SetVolume.FsInformationClass) {
1200  FIXME("STUB: FileFsControlInformation\n");
1201  break;
1202 
1204  TRACE("FileFsLabelInformation\n");
1205 
1206  Status = set_label(Vcb, Irp->AssociatedIrp.SystemBuffer);
1207  break;
1208 
1210  FIXME("STUB: FileFsObjectIdInformation\n");
1211  break;
1212 
1213  default:
1214  WARN("Unrecognized FsInformationClass 0x%x\n", IrpSp->Parameters.SetVolume.FsInformationClass);
1215  break;
1216  }
1217 
1218 end:
1219  Irp->IoStatus.Status = Status;
1220  Irp->IoStatus.Information = 0;
1221 
1222  TRACE("returning %08x\n", Status);
1223 
1225 
1226  if (top_level)
1228 
1230 
1231  return Status;
1232 }
#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
Status
Definition: btrfs.c:3874
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
GLuint GLuint end
Definition: gl.h:1545
#define FIXME(fmt,...)
Definition: debug.h:110
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
InsertTailList & Vcb
Definition: btrfs.c:2674
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
static NTSTATUS set_label(_In_ device_extension *Vcb, _In_ FILE_FS_LABEL_INFORMATION *ffli)
Definition: btrfs.c:1105
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
NTSTATUS vol_set_volume_information(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:316
_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2146 of file btrfs.c.

2149  {
2150 #else
2151 static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
2152 #endif
2153  NTSTATUS Status;
2156  device_extension* Vcb = DeviceObject->DeviceExtension;
2157  fcb* fcb = FileObject->FsContext;
2158  BOOL top_level;
2159 
2161 
2162  TRACE("cleanup\n");
2163 
2164  top_level = is_top_level(Irp);
2165 
2166  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2167  Status = vol_cleanup(DeviceObject, Irp);
2168  goto exit;
2169  } else if (DeviceObject == master_devobj) {
2170  TRACE("closing file system\n");
2171  Status = STATUS_SUCCESS;
2172  goto exit;
2173  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2174  Status = STATUS_INVALID_PARAMETER;
2175  goto exit;
2176  }
2177 
2178  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2179  TRACE("FileObject %p already cleaned up\n", FileObject);
2180  Status = STATUS_SUCCESS;
2181  goto exit;
2182  }
2183 
2184  if (!fcb) {
2185  ERR("fcb was NULL\n");
2186  Status = STATUS_INVALID_PARAMETER;
2187  goto exit;
2188  }
2189 
2190  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2191  // messages belonging to other devices.
2192 
2193  if (FileObject && FileObject->FsContext) {
2194  LONG oc;
2195  ccb* ccb;
2196  file_ref* fileref;
2197  BOOL locked = TRUE;
2198 
2199  ccb = FileObject->FsContext2;
2200  fileref = ccb ? ccb->fileref : NULL;
2201 
2202  TRACE("cleanup called for FileObject %p\n", FileObject);
2203  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2204 
2205  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
2206 
2207  ExAcquireResourceExclusiveLite(fcb->Header.Resource, TRUE);
2208 
2209  IoRemoveShareAccess(FileObject, &fcb->share_access);
2210 
2211  if (ccb)
2212  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2213 
2214  if (fileref) {
2215  oc = InterlockedDecrement(&fileref->open_count);
2216 #ifdef DEBUG_FCB_REFCOUNTS
2217  ERR("fileref %p: open_count now %i\n", fileref, oc);
2218 #endif
2219  }
2220 
2221  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2222  fileref->delete_on_close = TRUE;
2223 
2224  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2225  fileref->delete_on_close = FALSE;
2226 
2227  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2228  TRACE("unlocking volume\n");
2229  do_unlock_volume(fcb->Vcb);
2231  }
2232 
2233  if (ccb && ccb->reserving) {
2234  fcb->subvol->reserved = NULL;
2235  ccb->reserving = FALSE;
2236  // FIXME - flush all of subvol's fcbs
2237  }
2238 
2239  if (fileref && oc == 0) {
2240  if (!fcb->Vcb->removing) {
2241  if (fileref && fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2243 
2244  InitializeListHead(&rollback);
2245 
2246  if (!fileref->fcb->ads || fileref->dc) {
2247  if (fileref->fcb->ads) {
2249  FILE_ACTION_REMOVED, &fileref->dc->name);
2250  } else
2252  }
2253 
2254  ExReleaseResourceLite(fcb->Header.Resource);
2255  locked = FALSE;
2256 
2257  // fcb_lock needs to be acquired before fcb->Header.Resource
2258  acquire_fcb_lock_exclusive(fcb->Vcb);
2259 
2260  Status = delete_fileref(fileref, FileObject, Irp, &rollback);
2261  if (!NT_SUCCESS(Status)) {
2262  ERR("delete_fileref returned %08x\n", Status);
2263  do_rollback(fcb->Vcb, &rollback);
2264  release_fcb_lock(fcb->Vcb);
2265  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2266  goto exit;
2267  }
2268 
2269  release_fcb_lock(fcb->Vcb);
2270 
2271  locked = FALSE;
2272 
2273  clear_rollback(&rollback);
2274  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && fcb->nonpaged->segment_object.DataSectionObject) {
2276  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2277 
2278  if (!NT_SUCCESS(iosb.Status)) {
2279  ERR("CcFlushCache returned %08x\n", iosb.Status);
2280  }
2281 
2282  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2283  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
2284  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2285  }
2286 
2287  CcPurgeCacheSection(&fcb->nonpaged->segment_object, NULL, 0, FALSE);
2288 
2289  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %llx, FileSize = %llx, ValidDataLength = %llx)\n",
2290  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2291  }
2292  }
2293 
2294  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2295  CcUninitializeCacheMap(FileObject, NULL, NULL);
2296  }
2297 
2298  if (locked)
2299  ExReleaseResourceLite(fcb->Header.Resource);
2300 
2301  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2302 
2303  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2304  }
2305 
2306  Status = STATUS_SUCCESS;
2307 
2308 exit:
2309  TRACE("returning %08x\n", Status);
2310 
2311  Irp->IoStatus.Status = Status;
2312  Irp->IoStatus.Information = 0;
2313 
2315 
2316  if (top_level)
2318 
2320 
2321  return Status;
2322 }
struct _file_ref * parent
Definition: btrfs_drv.h:319
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1026
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1005
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:342
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
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
Status
Definition: btrfs.c:3874
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:318
#define FILE_NOTIFY_CHANGE_DIR_NAME
void send_notification_fileref(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1320
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3478
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
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:60
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:69
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG refcount
Definition: btrfs_drv.h:317
InsertTailList & Vcb
Definition: btrfs.c:2674
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:249
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
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:621
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1737
BOOL ads
Definition: btrfs_drv.h:292
dir_child * dc
Definition: btrfs_drv.h:321
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define InterlockedDecrement
Definition: armddk.h:52
NTSTATUS vol_cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:322
fcb * fcb
Definition: btrfs_drv.h:309
Definition: typedefs.h:117
INODE_ITEM inode_item
Definition: btrfs_drv.h:257
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1289
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
UINT64 st_size
Definition: btrfs.h:266
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:250
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1746
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _root * subvol
Definition: btrfs_drv.h:254
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
UINT8 type
Definition: btrfs_drv.h:256
BOOL delete_on_close
Definition: btrfs_drv.h:312
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:1934
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
BOOL reserving
Definition: btrfs_drv.h:349
SHARE_ACCESS share_access
Definition: btrfs_drv.h:263
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:351
return STATUS_SUCCESS
Definition: btrfs.c:2710
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2261
struct _device_extension * Vcb
Definition: btrfs_drv.h:253
UNICODE_STRING name
Definition: btrfs_drv.h:224
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1309
_Dispatch_type_ ( IRP_MJ_FILE_SYSTEM_CONTROL  )

Definition at line 4789 of file btrfs.c.

4792  {
4793 #else
4794 static NTSTATUS drv_file_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4795 #endif
4797  NTSTATUS Status;
4798  device_extension* Vcb = DeviceObject->DeviceExtension;
4799  BOOL top_level;
4800 
4802 
4803  TRACE("file system control\n");
4804 
4805  top_level = is_top_level(Irp);
4806 
4807  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4808  Status = vol_file_system_control(DeviceObject, Irp);
4809  goto end;
4810  } else if (!Vcb || (Vcb->type != VCB_TYPE_FS && Vcb->type != VCB_TYPE_CONTROL)) {
4811  Status = STATUS_INVALID_PARAMETER;
4812  goto end;
4813  }
4814 
4815  Status = STATUS_NOT_IMPLEMENTED;
4816 
4817  IrpSp = IoGetCurrentIrpStackLocation( Irp );
4818 
4819  Irp->IoStatus.Information = 0;
4820 
4821  switch (IrpSp->MinorFunction) {
4822  case IRP_MN_MOUNT_VOLUME:
4823  TRACE("IRP_MN_MOUNT_VOLUME\n");
4824 
4825  Status = mount_vol(DeviceObject, Irp);
4826  break;
4827 
4828  case IRP_MN_KERNEL_CALL:
4829  TRACE("IRP_MN_KERNEL_CALL\n");
4830 
4831  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4832  break;
4833 
4835  TRACE("IRP_MN_USER_FS_REQUEST\n");
4836 
4837  Status = fsctl_request(DeviceObject, &Irp, IrpSp->Parameters.FileSystemControl.FsControlCode);
4838  break;
4839 
4840  case IRP_MN_VERIFY_VOLUME:
4841  TRACE("IRP_MN_VERIFY_VOLUME\n");
4842 
4843  Status = verify_volume(DeviceObject);
4844 
4845  if (!NT_SUCCESS(Status) && Vcb->Vpb->Flags & VPB_MOUNTED) {
4846  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
4847  Vcb->removing = TRUE;
4848  ExReleaseResourceLite(&Vcb->tree_lock);
4849  }
4850 
4851  break;
4852 
4853  default:
4854  break;
4855  }
4856 
4857 end:
4858  TRACE("returning %08x\n", Status);
4859 
4860  if (Irp) {
4861  Irp->IoStatus.Status = Status;
4862 
4864  }
4865 
4866  if (top_level)
4868 
4870 
4871  return Status;
4872 }
#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
Status
Definition: btrfs.c:3874
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
GLuint GLuint end
Definition: gl.h:1545
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define IRP_MN_VERIFY_VOLUME
Definition: iotypes.h:4048
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS vol_file_system_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:336
InsertTailList & Vcb
Definition: btrfs.c:2674
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4047
#define IRP_MN_USER_FS_REQUEST
Definition: iotypes.h:4046
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
NTSTATUS fsctl_request(PDEVICE_OBJECT DeviceObject, PIRP *Pirp, UINT32 type)
Definition: fsctl.c:4766
#define IRP_MN_KERNEL_CALL
Definition: iotypes.h:4051
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:620
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
static NTSTATUS verify_volume(_In_ PDEVICE_OBJECT devobj)
Definition: btrfs.c:4730
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
#define VPB_MOUNTED
Definition: iotypes.h:1763
static NTSTATUS mount_vol(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
Definition: btrfs.c:3970
_Dispatch_type_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 4874 of file btrfs.c.

4877  {
4878 #else
4879 static NTSTATUS drv_lock_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4880 #endif
4881  NTSTATUS Status;
4883  fcb* fcb = IrpSp->FileObject->FsContext;
4884  device_extension* Vcb = DeviceObject->DeviceExtension;
4885  BOOL top_level;
4886 
4888 
4889  top_level = is_top_level(Irp);
4890 
4891  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4892  Status = vol_lock_control(DeviceObject, Irp);
4893 
4894  Irp->IoStatus.Status = Status;
4896 
4897  goto exit;
4898  }
4899 
4900  TRACE("lock control\n");
4901 
4902  Status = FsRtlProcessFileLock(&fcb->lock, Irp, NULL);
4903 
4904  fcb->Header.IsFastIoPossible = fast_io_possible(fcb);
4905 
4906 exit:
4907  TRACE("returning %08x\n", Status);
4908 
4909  if (top_level)
4911 
4913 
4914  return Status;
4915 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
Status
Definition: btrfs.c:3874
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FILE_LOCK lock
Definition: btrfs_drv.h:259
InsertTailList & Vcb
Definition: btrfs.c:2674
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:249
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1153
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS vol_lock_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:342
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define fast_io_possible(fcb)
Definition: btrfs_drv.h:1570
void exit(int exitcode)
Definition: _exit.c:33
_Dispatch_type_ ( IRP_MJ_SHUTDOWN  )

Definition at line 4917 of file btrfs.c.

4920  {
4921 #else
4922 static NTSTATUS drv_shutdown(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
4923 #endif
4924  NTSTATUS Status;
4925  BOOL top_level;
4926  device_extension* Vcb = DeviceObject->DeviceExtension;
4927 #ifdef __REACTOS__
4928  LIST_ENTRY *Vcble, *le;
4929 #endif
4930 
4932 
4933  TRACE("shutdown\n");
4934 
4935  top_level = is_top_level(Irp);
4936 
4937  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4938  Status = vol_shutdown(DeviceObject, Irp);
4939  goto end;
4940  }
4941 
4942  Status = STATUS_SUCCESS;
4943 
4944  shutting_down = TRUE;
4946 
4947 #ifndef __REACTOS__
4948  while (!IsListEmpty(&VcbList)) {
4950 
4951  TRACE("shutting down Vcb %p\n", Vcb);
4952 
4953  uninit(Vcb, TRUE);
4954  }
4955 #else
4956  Vcble = VcbList.Flink;
4957  while (Vcble != &VcbList) {
4959 
4960  TRACE("shutting down Vcb %p\n", Vcb);
4961 
4962  if (Vcb->balance.thread) {
4963  Vcb->balance.paused = FALSE;
4964  Vcb->balance.stopping = TRUE;
4965  KeSetEvent(&Vcb->balance.event, 0, FALSE);
4967  }
4968 
4969  if (Vcb->scrub.thread) {
4970  Vcb->scrub.paused = FALSE;
4971  Vcb->scrub.stopping = TRUE;
4972  KeSetEvent(&Vcb->scrub.event, 0, FALSE);
4974  }
4975 
4976  if (Vcb->running_sends != 0) {
4977  BOOL send_cancelled = FALSE;
4978 
4980 
4981  le = Vcb->send_ops.Flink;
4982  while (le != &Vcb->send_ops) {
4984 
4985  if (!send->cancelling) {
4986  send->cancelling = TRUE;
4987  send_cancelled = TRUE;
4988  send->ccb = NULL;
4989  KeSetEvent(&send->cleared_event, 0, FALSE);
4990  }
4991 
4992  le = le->Flink;
4993  }
4994 
4996 
4997  if (send_cancelled) {
4998  while (Vcb->running_sends != 0) {
5001  }
5002  }
5003  }
5004 
5005  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
5006 
5007  if (Vcb->need_write && !Vcb->readonly) {
5008  Status = do_write(Vcb, Irp);
5009 
5010  if (!NT_SUCCESS(Status))
5011  ERR("do_write returned %08x\n", Status);
5012  }
5013 
5014  Vcb->removing = TRUE;
5015 
5016  ExReleaseResourceLite(&Vcb->tree_lock);
5017  Vcble = Vcble->Flink;
5018  }
5019 #endif
5020 
5021 #ifdef _DEBUG
5022  if (comfo) {
5023  ObDereferenceObject(comfo);
5024  comdo = NULL;
5025  comfo = NULL;
5026  }
5027 #endif
5028 
5029 end:
5030  Irp->IoStatus.Status = Status;
5031  Irp->IoStatus.Information = 0;
5032 
5034 
5035  if (top_level)
5037 
5039 
5040  return Status;
5041 }
BOOL stopping
Definition: btrfs_drv.h:656
#define TRUE
Definition: types.h:120
scrub_info scrub
Definition: btrfs_drv.h:773
#define FsRtlEnterFileSystem
BOOL paused
Definition: btrfs_drv.h:696
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
LIST_ENTRY VcbList
Definition: btrfs.c:66
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7272
BOOL cancelling
Definition: btrfs_drv.h:334
BOOL shutting_down
Definition: btrfs.c:97
KEVENT event
Definition: btrfs_drv.h:693
Status
Definition: btrfs.c:3874
HANDLE thread
Definition: btrfs_drv.h:651
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
ERESOURCE send_load_lock
Definition: btrfs_drv.h:774
GLuint GLuint end
Definition: gl.h:1545
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
balance_info balance
Definition: btrfs_drv.h:772
KEVENT finished
Definition: btrfs_drv.h:663
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define FALSE
Definition: types.h:117
LIST_ENTRY send_ops
Definition: btrfs_drv.h:776
BOOL stopping
Definition: btrfs_drv.h:695
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
InsertTailList & Vcb
Definition: btrfs.c:2674
void uninit(_In_ device_extension *Vcb, _In_ BOOL flush)
Definition: btrfs.c:1729
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS vol_shutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:838
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
KEVENT finished
Definition: btrfs_drv.h:694
KEVENT cleared_event
Definition: btrfs_drv.h:333
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
KEVENT event
Definition: btrfs_drv.h:662
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
struct _ccb * ccb
Definition: btrfs_drv.h:331
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
HANDLE thread
Definition: btrfs_drv.h:691
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
KEVENT mountmgr_thread_event
Definition: btrfs.c:96
Definition: list.h:27
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2710
_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 5043 of file btrfs.c.

5046  {
5047 #else
5048 static NTSTATUS drv_power(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
5049 #endif
5050  NTSTATUS Status;
5051  device_extension* Vcb = DeviceObject->DeviceExtension;
5052  BOOL top_level;
5053 
5055 
5056  top_level = is_top_level(Irp);
5057 
5058  Irp->IoStatus.Information = 0;
5059 
5060  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5061  Status = vol_power(DeviceObject, Irp);
5062 
5063  Irp->IoStatus.Status = Status;
5065 
5066  goto exit;
5067  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5069 
5070  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5071 
5072  goto exit;
5073  }
5074 
5076  Irp->IoStatus.Status = Status;
5078 
5079 exit:
5080  if (top_level)
5082 
5084 
5085  return Status;
5086 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
Status
Definition: btrfs.c:3874
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS vol_power(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:856
InsertTailList & Vcb
Definition: btrfs.c:2674
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
void exit(int exitcode)
Definition: _exit.c:33
_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5088 of file btrfs.c.

5091  {
5092 #else
5093 static NTSTATUS drv_system_control(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
5094 #endif
5095  NTSTATUS Status;
5096  device_extension* Vcb = DeviceObject->DeviceExtension;
5097  BOOL top_level;
5098 
5100 
5101  top_level = is_top_level(Irp);
5102 
5103  Irp->IoStatus.Information = 0;
5104 
5105  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5106  volume_device_extension* vde = DeviceObject->DeviceExtension;
5107 
5109 
5110  Status = IoCallDriver(vde->pdo, Irp);
5111 
5112  goto exit;
5113  } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5115 
5116  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5117 
5118  goto exit;
5119  }
5120 
5121  Status = Irp->IoStatus.Status;
5123 
5124 exit:
5125  if (top_level)
5127 
5129 
5130  return Status;
5131 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
Status
Definition: btrfs.c:3874
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:820
#define VCB_TYPE_FS
Definition: btrfs_drv.h:619
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2674
unsigned int BOOL
Definition: ntddk_ex.h:94
LONG NTSTATUS
Definition: precomp.h:26
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:621
struct _DEVICE_OBJECT * RealDevice
Definition: iotypes.h:172
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:254
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
PVOID PIRP
Definition: usb.h:38
#define IO_NO_INCREMENT
Definition: iotypes.h:565
void exit(int exitcode)
Definition: _exit.c:33
_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_entry3
Definition: btrfs.c:90
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1053
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
UNICODE_STRING log_file
Definition: btrfs.c:83
void free_cache()
Definition: cache.c:116
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
void * notification_entry2
Definition: btrfs.c:90
#define WCHAR
Definition: msvc.h:43
PSID sid
Definition: btrfs_drv.h:851
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UNICODE_STRING registry_path
Definition: btrfs.c:83
PSID sid
Definition: btrfs_drv.h:845
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
void * notification_entry
Definition: btrfs.c:90
static WCHAR dosdevice_name[]
Definition: btrfs.c:55
LIST_ENTRY uid_map_list
Definition: btrfs.c:65
Definition: typedefs.h:117
ERESOURCE mapping_lock
Definition: btrfs.c:91
ERESOURCE global_loading_lock
Definition: btrfs.c:67
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1059
unsigned short USHORT
Definition: pedump.c:61
static DRIVER_UNLOAD DriverUnload
Definition: kbdclass.c:17
UNICODE_STRING log_device
Definition: btrfs.c:83
ERESOURCE pdo_list_lock
Definition: btrfs.c:91
LIST_ENTRY gid_map_list
Definition: btrfs.c:65
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 970 of file btrfs.c.

972  {
973 #else
974 static NTSTATUS read_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PVOID conptr) {
975 #endif
976  read_context* context = conptr;
977 
978  UNUSED(DeviceObject);
979 
980  context->iosb = Irp->IoStatus;
981  KeSetEvent(&context->Event, 0, FALSE);
982 
984 }
DWORD *typedef PVOID
Definition: winlogon.h:61
IO_STATUS_BLOCK iosb
Definition: btrfs.c:113
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:51
Definition: http.c:6587
_In_ PIRP Irp
Definition: csq.h:116
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
LONG NTSTATUS
Definition: precomp.h:26
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PVOID PIRP
Definition: usb.h:38
_Function_class_ ( KSTART_ROUTINE  )

Definition at line 5392 of file btrfs.c.

5394  {
5395 #else
5396 static void degraded_wait_thread(_In_ void* context) {
5397 #endif
5398  KTIMER timer;
5400 
5401  UNUSED(context);
5402 
5403  KeInitializeTimer(&timer);
5404 
5405  delay.QuadPart = -30000000; // wait three seconds
5406  KeSetTimer(&timer, delay, NULL);
5408 
5409  TRACE("timer expired\n");
5410 
5411  degraded_wait = FALSE;
5412 
5415 
5417 }
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
Definition: http.c:6587
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
HANDLE degraded_wait_handle
Definition: btrfs.c:94
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
BOOL degraded_wait
Definition: btrfs.c:95
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
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
return STATUS_SUCCESS
Definition: btrfs.c:2710
LONGLONG QuadPart
Definition: typedefs.h:112
_Function_class_ ( DRIVER_INITIALIZE  )

Definition at line 5528 of file btrfs.c.

5530  {
5531 #else
5533 #endif
5534  NTSTATUS Status;
5536  UNICODE_STRING device_nameW;
5537  UNICODE_STRING dosdevice_nameW;
5539  HANDLE regh;
5540  OBJECT_ATTRIBUTES oa;
5541  ULONG dispos;
5542 
5545 
5546 #ifdef _DEBUG
5547  ExInitializeResourceLite(&log_lock);
5548 #endif
5550 
5553  log_file.Buffer = NULL;
5555 
5556  registry_path.Length = registry_path.MaximumLength = RegistryPath->Length;
5558 
5559  if (!registry_path.Buffer) {
5560  ERR("out of memory\n");
5562  }
5563 
5564  RtlCopyMemory(registry_path.Buffer, RegistryPath->Buffer, registry_path.Length);
5565 
5567 
5568 #ifdef _DEBUG
5569  if (debug_log_level > 0)
5570  init_logging();
5571 
5572  log_started = TRUE;
5573 #endif
5574 
5575  TRACE("DriverEntry\n");
5576 
5577 #ifndef __REACTOS__
5578  check_cpu();
5579 #endif
5580 
5583  tPsIsDiskCountersEnabled fPsIsDiskCountersEnabled;
5584 
5585  RtlInitUnicodeString(&name, L"PsIsDiskCountersEnabled");
5586  fPsIsDiskCountersEnabled = (tPsIsDiskCountersEnabled)MmGetSystemRoutineAddress(&name);
5587 
5588  if (fPsIsDiskCountersEnabled) {
5589  diskacc = fPsIsDiskCountersEnabled();
5590 
5591  RtlInitUnicodeString(&name, L"PsUpdateDiskCounters");
5593 
5594  if (!fPsUpdateDiskCounters)
5595  diskacc = FALSE;
5596 
5597  RtlInitUnicodeString(&name, L"FsRtlUpdateDiskCounters");
5599  }
5600 
5601  RtlInitUnicodeString(&name, L"CcCopyReadEx");
5603 
5604  RtlInitUnicodeString(&name, L"CcCopyWriteEx");
5606 
5607  RtlInitUnicodeString(&name, L"CcSetAdditionalCacheAttributesEx");
5609  } else {
5611  fCcCopyReadEx = NULL;
5612  fCcCopyWriteEx = NULL;
5615  }
5616 
5617  drvobj = DriverObject;
5618 
5619  DriverObject->DriverUnload = DriverUnload;
5620 
5621  DriverObject->DriverExtension->AddDevice = AddDevice;
5622 
5623 #ifdef __REACTOS__
5624  DriverObject->MajorFunction[IRP_MJ_CREATE] = drv_create;
5625  DriverObject->MajorFunction[IRP_MJ_CLOSE] = drv_close;
5626  DriverObject->MajorFunction[IRP_MJ_READ] = drv_read;
5627  DriverObject->MajorFunction[IRP_MJ_WRITE] = drv_write;
5628  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = drv_query_information;
5629  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = drv_set_information;
5630  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = drv_query_ea;
5631  DriverObject->MajorFunction[IRP_MJ_SET_EA] = drv_set_ea;
5632  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = drv_flush_buffers;
5633  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = drv_query_volume_information;
5634  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = drv_set_volume_information;
5635  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = drv_directory_control;
5636  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = drv_file_system_control;
5637  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = drv_device_control;
5638  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = drv_shutdown;
5639  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = drv_lock_control;
5640  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = drv_cleanup;
5641  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = drv_query_security;
5642  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = drv_set_security;
5643  DriverObject->MajorFunction[IRP_MJ_POWER] = drv_power;
5644  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = drv_system_control;
5645  DriverObject->MajorFunction[IRP_MJ_PNP] = drv_pnp;
5646 #else
5647  DriverObject->MajorFunction[IRP_MJ_CREATE] = (PDRIVER_DISPATCH)drv_create;
5648  DriverObject->MajorFunction[IRP_MJ_CLOSE] = (PDRIVER_DISPATCH)drv_close;
5649  DriverObject->MajorFunction[IRP_MJ_READ] = (PDRIVER_DISPATCH)drv_read;
5650  DriverObject->MajorFunction[IRP_MJ_WRITE] = (PDRIVER_DISPATCH)drv_write;
5651  DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = (PDRIVER_DISPATCH)drv_query_information;
5652  DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = (PDRIVER_DISPATCH)drv_set_information;
5653  DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = (PDRIVER_DISPATCH)drv_query_ea;
5654  DriverObject->MajorFunction[IRP_MJ_SET_EA] = (PDRIVER_DISPATCH)drv_set_ea;
5655  DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = (PDRIVER_DISPATCH)drv_flush_buffers;
5656  DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = (PDRIVER_DISPATCH)drv_query_volume_information;
5657  DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = (PDRIVER_DISPATCH)drv_set_volume_information;
5658  DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = (PDRIVER_DISPATCH)drv_directory_control;
5659  DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = (PDRIVER_DISPATCH)drv_file_system_control;
5660  DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = (PDRIVER_DISPATCH)drv_device_control;
5661  DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = (PDRIVER_DISPATCH)drv_shutdown;
5662  DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = (PDRIVER_DISPATCH)drv_lock_control;
5663  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = (PDRIVER_DISPATCH)drv_cleanup;
5664  DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = (PDRIVER_DISPATCH)drv_query_security;
5665  DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = (PDRIVER_DISPATCH)drv_set_security;
5666  DriverObject->MajorFunction[IRP_MJ_POWER] = (PDRIVER_DISPATCH)drv_power;
5667  DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = (PDRIVER_DISPATCH)drv_system_control;
5668  DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH)drv_pnp;
5669 #endif
5670 
5671  init_fast_io_dispatch(&DriverObject->FastIoDispatch);
5672 
5673  device_nameW.Buffer = device_name;
5674  device_nameW.Length = device_nameW.MaximumLength = (USHORT)wcslen(device_name) * sizeof(WCHAR);
5675  dosdevice_nameW.Buffer = dosdevice_name;
5676  dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = (USHORT)wcslen(dosdevice_name) * sizeof(WCHAR);
5677 
5678  Status = IoCreateDevice(DriverObject, sizeof(control_device_extension), &device_nameW, FILE_DEVICE_DISK_FILE_SYSTEM,
5679  FILE_DEVICE_SECURE_OPEN, FALSE, &DeviceObject);
5680  if (!NT_SUCCESS(Status)) {
5681  ERR("IoCreateDevice returned %08x\n", Status);
5682  return Status;
5683  }
5684 
5687 
5689 
5690  cde->type = VCB_TYPE_CONTROL;
5691 
5692  DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
5693 
5694  Status = IoCreateSymbolicLink(&dosdevice_nameW, &device_nameW);
5695  if (!NT_SUCCESS(Status)) {
5696  ERR("IoCreateSymbolicLink returned %08x\n", Status);
5697  return Status;
5698  }
5699 
5700  Status = init_cache();
5701  if (!NT_SUCCESS(Status)) {
5702  ERR("init_cache returned %08x\n", Status);
5703  return Status;
5704  }
5705 
5709 
5711 
5713  Status = ZwCreateKey(&regh, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY, &oa, 0, NULL, REG_OPTION_NON_VOLATILE, &dispos);
5714  /* ReactOS specific hack: allow BtrFS driver to start in 1st stage with no hive */
5715 #ifndef __REACTOS__
5716  if (!NT_SUCCESS(Status)) {
5717  ERR("ZwCreateKey returned %08x\n", Status);
5718  return Status;
5719  }
5720 
5721  watch_registry(regh);
5722 #else
5723  if (NT_SUCCESS(Status)) {
5724  watch_registry(regh);
5725  }
5726 #endif
5727 
5728  Status = IoReportDetectedDevice(drvobj, InterfaceTypeUndefined, 0xFFFFFFFF, 0xFFFFFFFF,
5729  NULL, NULL, 0, &cde->buspdo);
5730  if (!NT_SUCCESS(Status)) {
5731  ERR("IoReportDetectedDevice returned %08x\n", Status);
5732  return Status;
5733  }
5734 
5735  Status = IoRegisterDeviceInterface(cde->buspdo, &BtrfsBusInterface, NULL, &cde->bus_name);
5736  if (!NT_SUCCESS(Status))
5737  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5738 
5739  cde->attached_device = IoAttachDeviceToDeviceStack(DeviceObject, cde->buspdo);
5740 
5741  Status = IoSetDeviceInterfaceState(&cde->bus_name, TRUE);
5742  if (!NT_SUCCESS(Status))
5743  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5744 
5745  DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
5746 
5748 
5749  Status = PsCreateSystemThread(&degraded_wait_handle, 0, NULL, NULL, NULL, degraded_wait_thread, NULL);
5750  if (!NT_SUCCESS(Status))
5751  WARN("PsCreateSystemThread returned %08x\n", Status);
5752 
5754  (PVOID)&GUID_DEVINTERFACE_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry2);
5755  if (!NT_SUCCESS(Status))
5756  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5757 
5759  (PVOID)&GUID_DEVINTERFACE_HIDDEN_VOLUME, DriverObject, volume_notification, DriverObject, &notification_entry3);
5760  if (!NT_SUCCESS(Status))
5761  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5762 
5764  (PVOID)&GUID_DEVINTERFACE_DISK, DriverObject, pnp_notification, DriverObject, &notification_entry);
5765  if (!NT_SUCCESS(Status))
5766  ERR("IoRegisterPlugPlayNotification returned %08x\n", Status);
5767 
5769 
5771 
5772 #ifndef __REACTOS__
5773  Status = PsCreateSystemThread(&mountmgr_thread_handle, 0, NULL, NULL, NULL, mountmgr_thread, NULL);
5774  if (!NT_SUCCESS(Status))
5775  WARN("PsCreateSystemThread returned %08x\n", Status);
5776 #endif
5777 
5778  IoRegisterFileSystem(DeviceObject);
5779 
5780  return STATUS_SUCCESS;
5781 }
DWORD *typedef PVOID
Definition: winlogon.h:61
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
BOOL log_started
Definition: btrfs.c:82
#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
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define IRP_MJ_SHUTDOWN
void * notification_entry3
Definition: btrfs.c:90
tCcCopyReadEx fCcCopyReadEx
Definition: btrfs.c:85
HANDLE degraded_wait_handle
Definition: btrfs.c:94
LIST_ENTRY VcbList
Definition: btrfs.c:66
#define IRP_MJ_SET_SECURITY
static void check_cpu()
Definition: btrfs.c:5284
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define WARN(fmt,...)
Definition: debug.h:111
static WCHAR device_name[]
Definition: btrfs.c:54
#define IRP_MJ_SET_VOLUME_INFORMATION
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
BOOLEAN(* tPsIsDiskCountersEnabled)()
Definition: btrfs_drv.h:1732
Status
Definition: btrfs.c:3874
UNICODE_STRING log_file
Definition: btrfs.c:83
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:793
#define PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES
Definition: iotypes.h:1195
void watch_registry(HANDLE regh)
Definition: registry.c:1013
void * notification_entry2
Definition: btrfs.c:90
#define WCHAR
Definition: msvc.h:43
tPsUpdateDiskCounters fPsUpdateDiskCounters
Definition: btrfs.c:84
UNICODE_STRING bus_name
Definition: btrfs_drv.h:794
NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
Definition: btrfs.c:5422
GLuint const GLchar * name
Definition: glext.h:6031
#define ALLOC_TAG
Definition: btrfs_drv.h:85
UNICODE_STRING registry_path
Definition: btrfs.c:83
NTSTATUS NTAPI IoReportDetectedDevice(IN PDRIVER_OBJECT DriverObject, IN INTERFACE_TYPE LegacyBusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PCM_RESOURCE_LIST ResourceList, IN PIO_RESOURCE_REQUIREMENTS_LIST ResourceRequirements OPTIONAL, IN BOOLEAN ResourceAssigned, IN OUT PDEVICE_OBJECT *DeviceObject OPTIONAL)
Definition: pnpreport.c:162
HANDLE mountmgr_thread_handle
Definition: btrfs.c:94
#define FALSE
Definition: types.h:117
#define RtlIsNtDdiVersionAvailable
Definition: rtlfuncs.h:3429
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3464
BOOLEAN(* tCcCopyReadEx)(PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread)
Definition: btrfs_drv.h:1740
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:800
#define IRP_MJ_SET_EA
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:60
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters
Definition: btrfs.c:88
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:1737
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
tCcCopyWriteEx fCcCopyWriteEx
Definition: btrfs.c:86
#define IRP_MJ_QUERY_EA
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
void * notification_entry
Definition: btrfs.c:90
#define TRACE(s)
Definition: solgame.cpp:4
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY pdo_list
Definition: btrfs.c:92
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define IRP_MJ_FILE_SYSTEM_CONTROL
static WCHAR dosdevice_name[]
Definition: btrfs.c:55
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
VOID(* tCcSetAdditionalCacheAttributesEx)(PFILE_OBJECT FileObject, ULONG Flags)
Definition: btrfs_drv.h:1747
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:59
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx
Definition: btrfs.c:87
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1087
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
LIST_ENTRY uid_map_list
Definition: btrfs.c:65
UINT32 debug_log_level
Definition: btrfs.c:68
NTSTATUS NTAPI IoRegisterPlugPlayNotification(IN IO_NOTIFICATION_EVENT_CATEGORY EventCategory, IN ULONG EventCategoryFlags, IN PVOID EventCategoryData OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDRIVER_NOTIFICATION_CALLBACK_ROUTINE CallbackRoutine, IN PVOID Context, OUT PVOID *NotificationEntry)
Definition: pnpnotify.c:250
#define IRP_MJ_SYSTEM_CONTROL
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:620
VOID(* tPsUpdateDiskCounters)(PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
Definition: btrfs_drv.h:1734
ERESOURCE mapping_lock
Definition: btrfs.c:91
ERESOURCE global_loading_lock
Definition: btrfs.c:67
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
DRIVER_DISPATCH * PDRIVER_DISPATCH
Definition: iotypes.h:2153
DWORD *typedef HANDLE
Definition: winlogon.h:61
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:4935
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:959
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
BOOL diskacc
Definition: btrfs.c:89
unsigned short USHORT
Definition: pedump.c:61
KEVENT mountmgr_thread_event
Definition: btrfs.c:96
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_NOTIFY
Definition: nt_native.h:1020
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static DRIVER_UNLOAD DriverUnload
Definition: kbdclass.c:17
UNICODE_STRING log_device
Definition: btrfs.c:83
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:1749
BOOL finished_probing
Definition: btrfs.c:93
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
ERESOURCE pdo_list_lock
Definition: btrfs.c:91
#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
#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:865
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
LIST_ENTRY gid_map_list
Definition: btrfs.c:65
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
PDEVICE_OBJECT buspdo
Definition: btrfs_drv.h:792
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.

Referenced by _Dispatch_type_().

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
if(!r)
Definition: btrfs.c:2632
#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:416
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
static ATOM item
Definition: dde.c:856
unsigned short USHORT
Definition: pedump.c:61
Definition: name.c:36
UINT16 n
Definition: btrfs.h: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 2908 of file btrfs.c.

Referenced by find_device_from_uuid(), and load_chunk_root().

2908  {
2909  LIST_ENTRY* le;
2910 
2911  le = Vcb->devices.Flink;
2912 
2913  while (le != &Vcb->devices) {
2914  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
2915 
2916  if (dev2->devitem.dev_id > dev->devitem.dev_id) {
2917  InsertHeadList(le->Blink, &dev->list_entry);
2918  return;
2919  }
2920 
2921  le = le->Flink;
2922  }
2923 
2924  InsertTailList(&Vcb->devices, &dev->list_entry);
2925 }
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:39
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
InsertTailList & Vcb
Definition: btrfs.c:2674
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:478
NTSTATUS AddDevice ( PDRIVER_OBJECT  DriverObject,
PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 5422 of file btrfs.c.

Referenced by _Function_class_().

5422  {
5423 #endif
5424  LIST_ENTRY* le;
5425  NTSTATUS Status;
5426  UNICODE_STRING volname;
5427  ULONG i, j;
5428  pdo_device_extension* pdode = NULL;
5429  PDEVICE_OBJECT voldev;
5431 
5432  TRACE("(%p, %p)\n", DriverObject, PhysicalDeviceObject);
5433 
5435 
5436  le = pdo_list.Flink;
5437  while (le != &pdo_list) {
5439 
5440  if (pdode2->pdo == PhysicalDeviceObject) {
5441  pdode = pdode2;
5442  break;
5443  }
5444 
5445  le = le->Flink;
5446  }
5447 
5448  if (!pdode) {
5449  WARN("unrecognized PDO %p\n", PhysicalDeviceObject);
5450  Status = STATUS_NOT_SUPPORTED;
5451  goto end;
5452  }
5453 
5455 
5456  volname.Length = volname.MaximumLength = (USHORT)((wcslen(BTRFS_VOLUME_PREFIX) + 36 + 1) * sizeof(WCHAR));
5457  volname.Buffer = ExAllocatePoolWithTag(PagedPool, volname.MaximumLength, ALLOC_TAG); // FIXME - when do we free this?
5458 
5459  if (!volname.Buffer) {
5460  ERR("out of memory\n");
5462  goto end2;
5463  }
5464 
5466 
5468  for (i = 0; i < 16; i++) {
5469  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] >> 4); j++;
5470  volname.Buffer[j] = hex_digit(pdode->uuid.uuid[i] & 0xf); j++;
5471 
5472  if (i == 3 || i == 5 || i == 7 || i == 9) {
5473  volname.Buffer[j] = '-';
5474  j++;
5475  }
5476  }
5477 
5478  volname.Buffer[j] = '}';
5479 
5480  Status = IoCreateDevice(drvobj, sizeof(volume_device_extension), &volname, FILE_DEVICE_DISK,
5482  if (!NT_SUCCESS(Status)) {
5483  ERR("IoCreateDevice returned %08x\n", Status);
5484  goto end2;
5485  }
5486 
5487  voldev->SectorSize = PhysicalDeviceObject->SectorSize;
5488  voldev->Flags |= DO_DIRECT_IO;
5489 
5490  vde = voldev->DeviceExtension;
5491  vde->type = VCB_TYPE_VOLUME;
5492  vde->name = volname;
5493  vde->device = voldev;
5494  vde->mounted_device = NULL;
5495  vde->pdo = PhysicalDeviceObject;
5496  vde->pdode = pdode;
5497  vde->removing = FALSE;
5498  vde->open_count = 0;
5499 
5500  Status = IoRegisterDeviceInterface(PhysicalDeviceObject, &GUID_DEVINTERFACE_VOLUME, NULL, &vde->bus_name);
5501  if (!NT_SUCCESS(Status))
5502  WARN("IoRegisterDeviceInterface returned %08x\n", Status);
5503 
5504  vde->attached_device = IoAttachDeviceToDeviceStack(voldev, PhysicalDeviceObject);
5505 
5506  pdode->vde = vde;
5507 
5508  if (pdode->removable)
5509  voldev->Characteristics |= FILE_REMOVABLE_MEDIA;
5510 
5511  voldev->Flags &= ~DO_DEVICE_INITIALIZING;
5512 
5513  Status = IoSetDeviceInterfaceState(&vde->bus_name, TRUE);
5514  if (!NT_SUCCESS(Status))
5515  WARN("IoSetDeviceInterfaceState returned %08x\n", Status);
5516 
5517  Status = STATUS_SUCCESS;
5518 
5519 end2:
5521 
5522 end:
5524 
5525  return Status;
5526 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define hex_digit(c)
Definition: btrfs_drv.h:1651
#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
PDEVICE_OBJECT device
Definition: btrfs_drv.h:818
UINT8 uuid[16]
Definition: btrfs.h:118
#define WARN(fmt,...)
Definition: debug.h:111
Status
Definition: btrfs.c:3874
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:820
GLuint GLuint end
Definition: gl.h:1545
#define WCHAR
Definition: msvc.h:43
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
UNICODE_STRING name
Definition: btrfs_drv.h:817
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:832
#define ALLOC_TAG
Definition: btrfs_drv.h:85
UNICODE_STRING bus_name
Definition: btrfs_drv.h:822
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:800
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1315
struct pdo_device_extension * pdode
Definition: btrfs_drv.h:821
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define TRACE(s)
Definition: solgame.cpp:4
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY pdo_list
Definition: btrfs.c:92
#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:621
ERESOURCE child_lock
Definition: btrfs_drv.h:837
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PDEVICE_OBJECT mounted_device
Definition: btrfs_drv.h:819
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PDRIVER_OBJECT drvobj
Definition: btrfs.c:59
Definition: typedefs.h:117
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:823
#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
#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
ERESOURCE pdo_list_lock
Definition: btrfs.c:91
volume_device_extension * vde
Definition: btrfs_drv.h:831
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:865
#define NTDDI_WIN8
Definition: sdkddkver.h:113
return STATUS_SUCCESS
Definition: btrfs.c:2710
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 588 of file btrfs.c.

Referenced by _Dispatch_type_().

588  {
589  UINT64 nfactor, dfactor, sectors_used;
590 
591  if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags & BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
592  nfactor = 1;
593  dfactor = 2;
594  } else if (Vcb->data_flags & BLOCK_FLAG_RAID5) {
595  nfactor = Vcb->superblock.num_devices - 1;
596  dfactor = Vcb->superblock.num_devices;
597  } else if (Vcb->data_flags & BLOCK_FLAG_RAID6) {
598  nfactor = Vcb->superblock.num_devices - 2;
599  dfactor = Vcb->superblock.num_devices;
600  } else {
601  nfactor = 1;
602  dfactor = 1;
603  }
604 
605  sectors_used = Vcb->superblock.bytes_used / Vcb->superblock.sector_size;
606 
607  *totalsize = (Vcb->superblock.total_bytes / Vcb->superblock.sector_size) * nfactor / dfactor;
608  *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
609 }
#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:64
InsertTailList & Vcb
Definition: btrfs.c:2674
#define BLOCK_FLAG_RAID6
Definition: shellext.h:66
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:63
#define BLOCK_FLAG_RAID5
Definition: shellext.h:65
unsigned long long UINT64
#define BLOCK_FLAG_RAID1
Definition: shellext.h:62
static void check_cpu ( )
static

Definition at line 5284 of file btrfs.c.

Referenced by _Function_class_().

5284  {
5285  unsigned int cpuInfo[4];
5286 #ifndef _MSC_VER
5287  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
5288  have_sse42 = cpuInfo[2] & bit_SSE4_2;
5289  have_sse2 = cpuInfo[3] & bit_SSE2;
5290 #else
5291  __cpuid(cpuInfo, 1);
5292  have_sse42 = cpuInfo[2] & (1 << 20);
5293  have_sse2 = cpuInfo[3] & (1 << 26);
5294 #endif
5295 
5296  if (have_sse42)
5297  TRACE("SSE4.2 is supported\n");
5298  else
5299  TRACE("SSE4.2 not supported\n");
5300 
5301  if (have_sse2)
5302  TRACE("SSE2 is supported\n");
5303  else
5304  TRACE("SSE2 is not supported\n");
5305 }
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 5155 of file btrfs.c.

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

5155  {
5156  LIST_ENTRY* le;
5157  BOOL locked;
5158  range_lock* rl;
5159 
5160  rl = ExAllocateFromNPagedLookasideList(&Vcb->range_lock_lookaside);
5161  if (!rl) {
5162  ERR("out of memory\n");
5163  return;
5164  }
5165 
5166  rl->start = start;
5167  rl->length = length;
5168  rl->thread = PsGetCurrentThread();
5169 
5170  while (TRUE) {
5171  locked = FALSE;
5172 
5173  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5174 
5175  le = c->range_locks.Flink;
5176  while (le != &c->range_locks) {
5178 
5179  if (rl2->start < start + length && rl2->start + rl2->length > start && rl2->thread != PsGetCurrentThread()) {
5180  locked = TRUE;
5181  break;
5182  }
5183 
5184  le = le->Flink;
5185  }
5186 
5187  if (!locked) {
5188  InsertTailList(&c->range_locks, &rl->list_entry);
5189 
5190  ExReleaseResourceLite(&c->range_locks_lock);
5191  return;
5192  }
5193 
5194  KeClearEvent(&c->range_locks_event);
5195 
5196  ExReleaseResourceLite(&c->range_locks_lock);
5197 
5198  KeWaitForSingleObject(&c->range_locks_event, UserRequest, KernelMode, FALSE, NULL);
5199  }
5200 }
UINT64 length
Definition: btrfs_drv.h:498
#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:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY list_entry
Definition: btrfs_drv.h:500
InsertTailList & Vcb
Definition: btrfs.c:2674
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:497
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
PETHREAD thread
Definition: btrfs_drv.h:499
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
GLuint start
Definition: gl.h:1545
Definition: list.h:27
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
void chunk_unlock_range ( _In_ device_extension Vcb,
_In_ chunk c,
_In_ UINT64  start,
_In_ UINT64  length 
)

Definition at line 5202 of file btrfs.c.

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

5202  {
5203  LIST_ENTRY* le;
5204 
5205  ExAcquireResourceExclusiveLite(&c->range_locks_lock, TRUE);
5206 
5207  le = c->range_locks.Flink;
5208  while (le != &c->range_locks) {
5210 
5211  if (rl->start == start && rl->length == length) {
5213  ExFreeToNPagedLookasideList(&Vcb->range_lock_lookaside, rl);
5214  break;
5215  }
5216 
5217  le = le->Flink;
5218  }
5219 
5220  KeSetEvent(&c->range_locks_event, 0, FALSE);
5221 
5222  ExReleaseResourceLite(&c->range_locks_lock);
5223 }
UINT64 length
Definition: btrfs_drv.h:498
#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
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY list_entry
Definition: btrfs_drv.h:500
InsertTailList & Vcb
Definition: btrfs.c:2674
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
UINT64 start
Definition: btrfs_drv.h:497
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
static NTSTATUS close_file ( _In_ PFILE_OBJECT  FileObject,
_In_ PIRP  Irp 
)
static

Definition at line 1646 of file btrfs.c.

Referenced by _Dispatch_type_().

1646  {
1647  fcb* fcb;
1648  ccb* ccb;
1649  file_ref* fileref = NULL;
1650  LONG open_files;
1652 
1653  UNUSED(Irp);
1654 
1655  TRACE("FileObject = %p\n", FileObject);
1656 
1657  fcb = FileObject->FsContext;
1658  if (!fcb) {
1659  TRACE("FCB was NULL, returning success\n");
1660  return STATUS_SUCCESS;
1661  }
1662 
1663  open_files = InterlockedDecrement(&fcb->Vcb->open_files);
1664 
1665  ccb = FileObject->FsContext2;
1666 
1667  TRACE("close called for %S (fcb == %p)\n", file_desc(FileObject), fcb);
1668 
1669  // FIXME - make sure notification gets sent if file is being deleted
1670 
1671  if (ccb) {
1672  if (ccb->query_string.Buffer)
1674 
1675  if (ccb->filename.Buffer)
1676  ExFreePool(ccb->filename.Buffer);
1677 
1678  // FIXME - use refcounts for fileref
1679  fileref = ccb->fileref;
1680 
1681  if (fcb->Vcb->running_sends > 0) {
1682  BOOL send_cancelled = FALSE;
1683 
1684  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1685 
1686  if (ccb->send) {
1687  ccb->send->cancelling = TRUE;
1688  send_cancelled = TRUE;
1689  KeSetEvent(&ccb->send->cleared_event, 0, FALSE);
1690  }
1691 
1692  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1693 
1694  if (send_cancelled) {
1695  while (ccb->send) {
1696  ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
1697  ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
1698  }
1699  }
1700  }
1701 
1702  ExFreePool(ccb);
1703  }
1704 
1706 
1707  if (open_files == 0 && fcb->Vcb->removing) {
1708  uninit(fcb->Vcb, FALSE);
1709  return STATUS_SUCCESS;
1710  }
1711 
1712  if (!(fcb->Vcb->Vpb->Flags & VPB_MOUNTED))
1713  return STATUS_SUCCESS;
1714 
1715  Vcb = fcb->Vcb;
1716 
1717  acquire_fcb_lock_exclusive(Vcb);
1718 
1719  if (fileref)
1720  free_fileref(fcb->Vcb, fileref);
1721  else
1722  free_fcb(Vcb, fcb);
1723 
1724  release_fcb_lock(Vcb);
1725 
1726  return STATUS_SUCCESS;
1727 }
void free_fileref(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ file_ref *fr)
Definition: btrfs.c:1587
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
BOOL cancelling
Definition: btrfs_drv.h:334
void free_fcb(_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ fcb *fcb)
Definition: btrfs.c:1479
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UNICODE_STRING filename
Definition: btrfs_drv.h:352
UNICODE_STRING query_string
Definition: btrfs_drv.h:344
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
smooth NULL
Definition: ftsmooth.c:416
#define UNUSED(x)
Definition: btrfs_drv.h:80
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
InsertTailList & Vcb
Definition: btrfs.c:2674
void uninit(_In_ device_extension *Vcb, _In_ BOOL flush)
Definition: btrfs.c:1729
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
struct _fcb fcb
Definition: btrfs_drv.h:1289
KEVENT cleared_event
Definition: btrfs_drv.h:333
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:351
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define VPB_MOUNTED
Definition: iotypes.h:1763
struct _device_extension * Vcb
Definition: btrfs_drv.h:253
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1309
send_info * send
Definition: btrfs_drv.h:360
static NTSTATUS create_calc_threads ( _In_ PDEVICE_OBJECT  DeviceObject)
static

Definition at line 3698 of file btrfs.c.

Referenced by mount_vol().

3698  {
3700  ULONG i;
3701 
3703 
3705  if (!Vcb->calcthreads.threads) {
3706  ERR("out of memory\n");
3708  }
3709 
3713 
3715 
3716  for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
3717  NTSTATUS Status;
3718 
3721 
3722  Status = PsCreateSystemThread(&Vcb->calcthreads.threads[i].handle, 0, NULL, NULL, NULL, calc_thread, &Vcb->calcthreads.threads[i]);
3723  if (!NT_SUCCESS(Status)) {
3724  ULONG j;
3725 
3726  ERR("PsCreateSystemThread returned %08x\n", Status);
3727 
3728  for (j = 0; j < i; j++) {
3729  Vcb->calcthreads.threads[i].quit = TRUE;
3730  }
3731 
3732  KeSetEvent(&Vcb->calcthreads.event, 0, FALSE);
3733 
3734  return Status;
3735  }
3736  }
3737 
3738  return STATUS_SUCCESS;
3739 }
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
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:3874
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define ALLOC_TAG
Definition: btrfs_drv.h:85
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY job_list
Definition: btrfs_drv.h:596
InsertTailList & Vcb
Definition: btrfs.c:2674
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
ERESOURCE lock
Definition: btrfs_drv.h:597
#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
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
drv_calc_threads calcthreads
Definition: btrfs_drv.h:771
#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:598
KEVENT finished
Definition: btrfs_drv.h:590
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2710
PDEVICE_OBJECT DeviceObject
Definition: btrfs_drv.h:588
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 986 of file btrfs.c.

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

987  {
989  root* r;
990  tree* t = NULL;
991  ROOT_ITEM* ri;
993 
995  if (!r) {
996  ERR("out of memory\n");
998  }
999 
1001  if (!r->nonpaged) {
1002  ERR("out of memory\n");
1003  ExFreePool(r);
1005  }
1006 
1007  if (!no_tree) {
1009  if (!t) {
1010  ERR("out of memory\n");
1011  ExFreePool(r->nonpaged);
1012  ExFreePool(r);
1014  }
1015 
1016  t->is_unique = TRUE;
1018  t->buf = NULL;
1019  }
1020 
1022  if (!ri) {
1023  ERR("out of memory\n");
1024 
1025  if (t)
1026  ExFreePool(t);
1027 
1028  ExFreePool(r->nonpaged);
1029  ExFreePool(r);
1031  }
1032 
1033  r->id = id;
1034  r->treeholder.address = 0;
1035  r->treeholder.generation = Vcb->superblock.generation;
1036  r->treeholder.tree = t;
1037  r->lastinode = 0;
1038  r->dirty = FALSE;
1039  r->received = FALSE;
1040  r->reserved = NULL;
1041  r->parent = 0;
1042  r->send_ops = 0;
1043  RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
1044  r->root_item.num_references = 1;
1045  InitializeListHead(&r->fcbs);
1046 
1047  RtlCopyMemory(ri, &r->root_item, sizeof(ROOT_ITEM));
1048 
1049  // We ask here for a traverse_ptr to the item we're inserting, so we can
1050  // copy some of the tree's variables
1051 
1052  Status = insert_tree_item(Vcb, Vcb->root_root, id, TYPE_ROOT_ITEM, offset, ri, sizeof(ROOT_ITEM), &tp, Irp);
1053  if (!NT_SUCCESS(Status)) {
1054  ERR("insert_tree_item returned %08x\n", Status);
1055  ExFreePool(ri);
1056 
1057  if (t)
1058  ExFreePool(t);
1059 
1060  ExFreePool(r->nonpaged);
1061  ExFreePool(r);
1062  return Status;
1063  }
1064 
1066 
1067  InsertTailList(&Vcb->roots, &r->list_entry);
1068 
1069  if (!no_tree) {
1070  RtlZeroMemory(&t->header, sizeof(tree_header));
1071  t->header.fs_uuid = tp.tree->header.fs_uuid;
1072  t->header.address = 0;
1073  t->header.flags = HEADER_FLAG_MIXED_BACKREF | 1; // 1 == "written"? Why does the Linux driver record this?
1075  t->header.generation = Vcb->superblock.generation;
1076  t->header.tree_id = id;
1077  t->header.num_items = 0;
1078  t->header.level = 0;
1079 
1080  t->has_address = FALSE;
1081  t->size = 0;
1082  t->Vcb = Vcb;
1083  t->parent = NULL;
1084  t->paritem = NULL;
1085  t->root = r;
1086 
1088 
1089  t->new_address = 0;
1090  t->has_new_address = FALSE;
1091  t->updated_extents = FALSE;
1092 
1093  InsertTailList(&Vcb->trees, &t->list_entry);
1094  t->list_entry_hash.Flink = NULL;
1095 
1096  t->write = TRUE;
1097  Vcb->need_write = TRUE;
1098  }
1099 
1100  *rootptr = r;
1101 
1102  return STATUS_SUCCESS;
1103 }
UINT64 id
Definition: btrfs_drv.h:414
UINT64 address
Definition: btrfs_drv.h:367
UINT64 generation
Definition: btrfs.h:137
struct _root * root
Definition: btrfs_drv.h:396
#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:403
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
BOOL uniqueness_determined
Definition: btrfs_drv.h:405
UINT32 num_items
Definition: btrfs.h:139
UINT64 flags
Definition: btrfs.h:135
UINT64 new_address
Definition: btrfs_drv.h:400
LIST_ENTRY list_entry
Definition: btrfs_drv.h:425
_In_ PIRP Irp
Definition: csq.h:116
InitializeListHead & r
Definition: btrfs.c:2646
GLintptr offset
Definition: glext.h:5920
LIST_ENTRY list_entry_hash
Definition: btrfs_drv.h:399
GLdouble GLdouble t
Definition: gl.h:2047
ERESOURCE load_tree_lock
Definition: btrfs_drv.h:410
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
Status
Definition: btrfs.c:3874
ROOT_ITEM root_item
Definition: btrfs_drv.h:418
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2630
LONGLONG lastinode
Definition: btrfs_drv.h:415
LIST_ENTRY fcbs
Definition: btrfs_drv.h:424
UINT8 * buf
Definition: btrfs_drv.h:406
#define InsertTailList(ListHead, Entry)
LIST_ENTRY list_entry
Definition: btrfs_drv.h:398
#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:393
root_nonpaged * nonpaged
Definition: btrfs_drv.h:417
tree * tree
Definition: btrfs_drv.h:460
#define FALSE
Definition: types.h:117
struct _tree * tree
Definition: btrfs_drv.h:369
tree_data * paritem
Definition: btrfs_drv.h:395
BOOL dirty
Definition: btrfs_drv.h:419
BOOL is_unique
Definition: btrfs_drv.h:404
smooth NULL
Definition: ftsmooth.c:416
UINT64 address
Definition: btrfs.h:134
BOOL updated_extents
Definition: btrfs_drv.h:402
struct _tree * parent
Definition: btrfs_drv.h:394
_In_ UINT64 id
Definition: btrfs.c:2629
InsertTailList & Vcb
Definition: btrfs.c:2674
BTRFS_UUID chunk_tree_uuid
Definition: btrfs.h:136
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LONG send_ops
Definition: btrfs_drv.h:423
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
LIST_ENTRY itemlist
Definition: btrfs_drv.h:397
BOOL received
Definition: btrfs_drv.h:420
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
PEPROCESS reserved
Definition: btrfs_drv.h:421
tree_header header
Definition: btrfs_drv.h:389
tree_holder treeholder
Definition: btrfs_drv.h:416
BOOL has_new_address
Definition: btrfs_drv.h:401
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:391
UINT64 tree_id
Definition: btrfs.h:138
UINT64 generation
Definition: btrfs_drv.h:368
#define ERR(fmt,...)
Definition: debug.h:109
BTRFS_UUID fs_uuid
Definition: btrfs.h:133
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define TYPE_ROOT_ITEM
Definition: btrfs.h:26
UINT64 parent
Definition: btrfs_drv.h:422
UINT32 size
Definition: btrfs_drv.h:392
UINT8 level
Definition: btrfs.h:140
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
UINT32 num_references
Definition: btrfs.h:292
return STATUS_SUCCESS
Definition: btrfs.c:2710
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
DEFINE_GUID ( BtrfsBusInterface  ,
0x4d414874  ,
0x6865  ,
0x6761  ,
0x6d  ,
0x65  ,
0x83  ,
0x69  ,
0x17  ,
0x9a  ,
0x7d  ,
0x1d   
)
NTSTATUS delete_fileref ( _In_ file_ref fileref,
_In_opt_ PFILE_OBJECT  FileObject,
_In_opt_ PIRP  Irp,
_In_ LIST_ENTRY rollback 
)

Definition at line 1934 of file btrfs.c.

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

1934  {
1935  LARGE_INTEGER newlength, time;
1936  BTRFS_TIME now;
1937  NTSTATUS Status;
1938  ULONG utf8len = 0;
1939 
1940  KeQuerySystemTime(&time);
1941  win_time_to_unix(time, &now);
1942 
1943  ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, TRUE);
1944 
1945  if (fileref->deleted) {
1946  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1947  return STATUS_SUCCESS;
1948  }
1949 
1950  if (fileref->fcb->subvol->send_ops > 0) {
1951  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1952  return STATUS_ACCESS_DENIED;
1953  }
1954 
1955  fileref->deleted = TRUE;
1956  mark_fileref_dirty(fileref);
1957 
1958  // delete INODE_ITEM (0x1)
1959 
1960  TRACE("nlink = %u\n", fileref->fcb->inode_item.st_nlink);
1961 
1962  if (!fileref->fcb->ads) {
1963  if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
1964  LIST_ENTRY* le;
1965 
1966  mark_fcb_dirty(fileref->fcb);
1967 
1968  fileref->fcb->inode_item_changed = TRUE;
1969 
1970  if (fileref->fcb->inode_item.st_nlink > 1) {
1971  fileref->fcb->inode_item.st_nlink--;
1972  fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
1973  fileref->fcb->inode_item.sequence++;
1974  fileref->fcb->inode_item.st_ctime = now;
1975  } else {
1976  // excise extents
1977 
1978  if (fileref->fcb->type != BTRFS_TYPE_DIRECTORY && fileref->fcb->inode_item.st_size > 0) {
1979  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);
1980  if (!NT_SUCCESS(Status)) {
1981  ERR("excise_extents returned %08x\n", Status);
1982  ExReleaseResourceLite(fileref->fcb->Header.Resource);
1983  return Status;
1984  }
1985  }
1986 
1987  fileref->fcb->Header.AllocationSize.QuadPart = 0;
1988  fileref->fcb->Header.FileSize.QuadPart = 0;
1989  fileref->fcb->Header.ValidDataLength.QuadPart = 0;
1990 
1991  if (FileObject) {
1992  CC_FILE_SIZES ccfs;
1993 
1994  ccfs.AllocationSize = fileref->fcb->Header.AllocationSize;
1995  ccfs.FileSize = fileref->fcb->Header.FileSize;
1996  ccfs.ValidDataLength = fileref->fcb->Header.ValidDataLength;
1997 
1998  Status = STATUS_SUCCESS;
1999 
2000  _SEH2_TRY {
2001  CcSetFileSizes(FileObject, &ccfs);
2003  Status = _SEH2_GetExceptionCode();
2004  } _SEH2_END;
2005 
2006  if (!NT_SUCCESS(Status)) {
2007  ERR("CcSetFileSizes threw exception %08x\n", Status);
2008  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2009  return Status;
2010  }
2011  }
2012 
2013  fileref->fcb->deleted = TRUE;
2014 
2015  le = fileref->children.Flink;
2016  while (le != &fileref->children) {
2018 
2019  if (fr2->fcb->ads) {
2020  fr2->fcb->deleted = TRUE;
2021  mark_fcb_dirty(fr2->fcb);
2022  }
2023 
2024  le = le->Flink;
2025  }
2026  }
2027 
2028  if (fileref->dc) {
2029  le = fileref->fcb->hardlinks.Flink;
2030  while (le != &fileref->fcb->hardlinks) {
2032 
2033  if (hl->parent == fileref->parent->fcb->inode && hl->index == fileref->dc->index) {
2035 
2036  if (hl->name.Buffer)
2037  ExFreePool(hl->name.Buffer);
2038 
2039  if (hl->utf8.Buffer)
2040  ExFreePool(hl->utf8.Buffer);
2041 
2042  ExFreePool(hl);
2043  break;
2044  }
2045 
2046  le = le->Flink;
2047  }
2048  }
2049  } else if (fileref->fcb->subvol->parent == fileref->parent->fcb->subvol->id) { // valid subvolume
2050  if (fileref->fcb->subvol->root_item.num_references > 1) {
2051  fileref->fcb->subvol->root_item.num_references--;
2052 
2053  mark_fcb_dirty(fileref->fcb); // so ROOT_ITEM gets updated
2054  } else {
2055  LIST_ENTRY* le;
2056 
2057  // FIXME - we need a lock here
2058 
2059  RemoveEntryList(&fileref->fcb->subvol->list_entry);
2060 
2061  InsertTailList(&fileref->fcb->Vcb->drop_roots, &fileref->fcb->subvol->list_entry);
2062 
2063  le = fileref->children.Flink;
2064  while (le != &fileref->children) {
2066