ReactOS  0.4.14-dev-41-g31d7680
btrfs_drv.h File Reference
#include <ntifs.h>
#include <ntddk.h>
#include <mountmgr.h>
#include <windef.h>
#include <wdm.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <emmintrin.h>
#include "btrfs.h"
#include "btrfsioctl.h"
Include dependency graph for btrfs_drv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _FILE_ID_128
 
struct  _DUPLICATE_EXTENTS_DATA
 
struct  _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER
 
struct  _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER
 
struct  _fcb_nonpaged
 
struct  extent
 
struct  hardlink
 
struct  dir_child
 
struct  xattr
 
struct  _fcb
 
struct  file_ref_nonpaged
 
struct  _file_ref
 
struct  send_info
 
struct  _ccb
 
struct  tree_holder
 
struct  _tree_data
 
struct  tree_nonpaged
 
struct  _tree
 
struct  root_nonpaged
 
struct  _root
 
struct  batch_item
 
struct  batch_root
 
struct  traverse_ptr
 
struct  _root_cache
 
struct  space
 
struct  device
 
struct  range_lock
 
struct  partial_stripe
 
struct  chunk
 
struct  changed_extent
 
struct  changed_extent_ref
 
struct  sys_chunk
 
struct  calc_job
 
struct  drv_calc_thread
 
struct  drv_calc_threads
 
struct  mount_options
 
struct  balance_info
 
struct  scrub_error
 
struct  scrub_info
 
struct  _device_extension
 
struct  control_device_extension
 
struct  bus_device_extension
 
struct  volume_child
 
struct  _volume_device_extension
 
struct  pdo_device_extension
 
struct  uid_map
 
struct  gid_map
 
struct  write_data_stripe
 
struct  _write_data_context
 
struct  tree_write
 
struct  name_bit
 
struct  rollback_space
 
struct  rollback_extent
 
struct  rollback_item
 
struct  ea_item
 
struct  _LDR_DATA_TABLE_ENTRY
 
struct  _PEB_LDR_DATA
 
struct  _RTL_USER_PROCESS_PARAMETERS
 
struct  _PEB
 

Macros

#define _WIN32_WINNT   0x0601
 
#define NTDDI_VERSION   0x06020000
 
#define _CRT_SECURE_NO_WARNINGS
 
#define _NO_CRT_STDIO_INLINE
 
#define UNUSED(x)   (void)(x)
 
#define BTRFS_NODE_TYPE_CCB   0x2295
 
#define BTRFS_NODE_TYPE_FCB   0x2296
 
#define ALLOC_TAG   0x7442484D
 
#define ALLOC_TAG_ZLIB   0x7A42484D
 
#define UID_NOBODY   65534
 
#define GID_NOBODY   65534
 
#define EA_NTACL   "security.NTACL"
 
#define EA_NTACL_HASH   0x45922146
 
#define EA_DOSATTRIB   "user.DOSATTRIB"
 
#define EA_DOSATTRIB_HASH   0x914f9939
 
#define EA_REPARSE   "user.reparse"
 
#define EA_REPARSE_HASH   0xfabad1fe
 
#define EA_EA   "user.EA"
 
#define EA_EA_HASH   0x8270dd43
 
#define EA_CASE_SENSITIVE   "user.casesensitive"
 
#define EA_CASE_SENSITIVE_HASH   0x1a9d97d4
 
#define EA_PROP_COMPRESSION   "btrfs.compression"
 
#define EA_PROP_COMPRESSION_HASH   0x20ccdf69
 
#define MAX_EXTENT_SIZE   0x8000000
 
#define COMPRESSED_EXTENT_SIZE   0x20000
 
#define READ_AHEAD_GRANULARITY   COMPRESSED_EXTENT_SIZE
 
#define IO_REPARSE_TAG_LXSS_SYMLINK   0xa000001d
 
#define IO_REPARSE_TAG_LXSS_SOCKET   0x80000023
 
#define IO_REPARSE_TAG_LXSS_FIFO   0x80000024
 
#define IO_REPARSE_TAG_LXSS_CHARDEV   0x80000025
 
#define IO_REPARSE_TAG_LXSS_BLOCKDEV   0x80000026
 
#define BTRFS_VOLUME_PREFIX   L"\\Device\\Btrfs{"
 
#define try   if (1)
 
#define except(x)   if (0 && (x))
 
#define finally   if (1)
 
#define FILE_SUPPORTS_BLOCK_REFCOUNTING   0x08000000
 
#define FILE_SUPPORTS_POSIX_UNLINK_RENAME   0x00000400
 
#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL   0x00020000
 
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 209, METHOD_BUFFERED, FILE_WRITE_ACCESS)
 
#define FSCTL_GET_INTEGRITY_INFORMATION   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 159, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
#define FSCTL_SET_INTEGRITY_INFORMATION   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 160, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
 
#define __drv_aliasesMem
 
#define _Requires_lock_held_(a)
 
#define _Requires_exclusive_lock_held_(a)
 
#define _Releases_lock_(a)
 
#define _Out_writes_bytes_opt_(a)
 
#define _Pre_satisfies_(a)
 
#define _Post_satisfies_(a)
 
#define _Releases_exclusive_lock_(a)
 
#define _Dispatch_type_(a)
 
#define _Create_lock_level_(a)
 
#define _Lock_level_order_(a, b)
 
#define _Has_lock_level_(a)
 
#define _Requires_lock_not_held_(a)
 
#define _Acquires_exclusive_lock_(a)
 
#define _Acquires_shared_lock_(a)
 
#define VCB_TYPE_FS   1
 
#define VCB_TYPE_CONTROL   2
 
#define VCB_TYPE_VOLUME   3
 
#define VCB_TYPE_PDO   4
 
#define VCB_TYPE_BUS   5
 
#define BALANCE_OPTS_DATA   0
 
#define BALANCE_OPTS_METADATA   1
 
#define BALANCE_OPTS_SYSTEM   2
 
#define keycmp(key1, key2)
 
#define acquire_chunk_lock(c, Vcb)   ExAcquireResourceExclusiveLite(&(c)->lock, true)
 
#define release_chunk_lock(c, Vcb)   ExReleaseResourceLite(&(c)->lock)
 
#define funcname   __func__
 
#define TRACE(s, ...)
 
#define WARN(s, ...)
 
#define FIXME(s, ...)   DbgPrint("Btrfs FIXME : %s : " s, funcname, ##__VA_ARGS__)
 
#define ERR(s, ...)   DbgPrint("Btrfs ERR : %s : " s, funcname, ##__VA_ARGS__)
 
#define makedev(major, minor)   (((minor) & 0xFF) | (((major) & 0xFFF) << 8) | (((uint64_t)((minor) & ~0xFF)) << 12) | (((uint64_t)((major) & ~0xFFF)) << 32))
 
#define fast_io_possible(fcb)   (!FsRtlAreThereCurrentFileLocks(&fcb->lock) && !fcb->Vcb->readonly ? FastIoIsPossible : FastIoIsQuestionable)
 
#define increase_fileref_refcount(fileref)   InterlockedIncrement(&fileref->refcount)
 
#define int3   asm("int3;")
 
#define hex_digit(c)   ((c) <= 9) ? ((c) + '0') : ((c) - 10 + 'a')
 
#define __S_IFMT   0170000 /* These bits determine file type. */
 
#define __S_IFDIR   0040000 /* Directory. */
 
#define __S_IFCHR   0020000 /* Character device. */
 
#define __S_IFBLK   0060000 /* Block device. */
 
#define __S_IFREG   0100000 /* Regular file. */
 
#define __S_IFIFO   0010000 /* FIFO. */
 
#define __S_IFLNK   0120000 /* Symbolic link. */
 
#define __S_IFSOCK   0140000 /* Socket. */
 
#define __S_ISTYPE(mode, mask)   (((mode) & __S_IFMT) == (mask))
 
#define S_ISDIR(mode)   __S_ISTYPE((mode), __S_IFDIR)
 
#define S_IRUSR   0000400
 
#define S_IWUSR   0000200
 
#define S_IXUSR   0000100
 
#define S_IRGRP   (S_IRUSR >> 3)
 
#define S_IWGRP   (S_IWUSR >> 3)
 
#define S_IXGRP   (S_IXUSR >> 3)
 
#define S_IROTH   (S_IRGRP >> 3)
 
#define S_IWOTH   (S_IWGRP >> 3)
 
#define S_IXOTH   (S_IXGRP >> 3)
 
#define S_ISUID   0004000
 
#define S_ISGID   0002000
 
#define S_ISVTX   0001000
 
#define major(rdev)   ((((rdev) >> 8) & 0xFFF) | ((uint32_t)((rdev) >> 32) & ~0xFFF))
 
#define minor(rdev)   (((rdev) & 0xFF) | ((uint32_t)((rdev) >> 12) & ~0xFF))
 
#define CC_ENABLE_DISK_IO_ACCOUNTING   0x00000010
 

Typedefs

typedef struct _FILE_ID_128 FILE_ID_128
 
typedef struct _FILE_ID_128PFILE_ID_128
 
typedef struct _DUPLICATE_EXTENTS_DATA DUPLICATE_EXTENTS_DATA
 
typedef struct _DUPLICATE_EXTENTS_DATAPDUPLICATE_EXTENTS_DATA
 
typedef struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER FSCTL_GET_INTEGRITY_INFORMATION_BUFFER
 
typedef struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFERPFSCTL_GET_INTEGRITY_INFORMATION_BUFFER
 
typedef struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER FSCTL_SET_INTEGRITY_INFORMATION_BUFFER
 
typedef struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFERPFSCTL_SET_INTEGRITY_INFORMATION_BUFFER
 
typedef struct _fcb_nonpaged fcb_nonpaged
 
typedef struct _fcb fcb
 
typedef struct _file_ref file_ref
 
typedef struct _ccb ccb
 
typedef struct _tree_data tree_data
 
typedef struct _tree tree
 
typedef struct _root root
 
typedef struct _root_cache root_cache
 
typedef struct _device_extension device_extension
 
typedef struct _volume_device_extension volume_device_extension
 
typedef struct pdo_device_extension pdo_device_extension
 
typedef struct _write_data_context write_data_context
 
typedef BOOLEAN(* tPsIsDiskCountersEnabled) ()
 
typedef VOID(* tPsUpdateDiskCounters) (PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)
 
typedef BOOLEAN(* tCcCopyWriteEx) (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PETHREAD IoIssuerThread)
 
typedef BOOLEAN(* tCcCopyReadEx) (PFILE_OBJECT FileObject, PLARGE_INTEGER FileOffset, ULONG Length, BOOLEAN Wait, PVOID Buffer, PIO_STATUS_BLOCK IoStatus, PETHREAD IoIssuerThread)
 
typedef VOID(* tCcSetAdditionalCacheAttributesEx) (PFILE_OBJECT FileObject, ULONG Flags)
 
typedef VOID(* tFsRtlUpdateDiskCounters) (ULONG64 BytesRead, ULONG64 BytesWritten)
 
typedef NTSTATUS(* tIoUnregisterPlugPlayNotificationEx) (PVOID NotificationEntry)
 
typedef NTSTATUS(* tFsRtlGetEcpListFromIrp) (PIRP Irp, PECP_LIST *EcpList)
 
typedef NTSTATUS(* tFsRtlGetNextExtraCreateParameter) (PECP_LIST EcpList, PVOID CurrentEcpContext, LPGUID NextEcpType, PVOID *NextEcpContext, ULONG *NextEcpContextSize)
 
typedef NTSTATUS(* tFsRtlValidateReparsePointBuffer) (ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer)
 
typedef struct _LDR_DATA_TABLE_ENTRY LDR_DATA_TABLE_ENTRY
 
typedef struct _LDR_DATA_TABLE_ENTRYPLDR_DATA_TABLE_ENTRY
 
typedef struct _PEB_LDR_DATA PEB_LDR_DATA
 
typedef struct _PEB_LDR_DATAPPEB_LDR_DATA
 
typedef struct _RTL_USER_PROCESS_PARAMETERS RTL_USER_PROCESS_PARAMETERS
 
typedef struct _RTL_USER_PROCESS_PARAMETERSPRTL_USER_PROCESS_PARAMETERS
 
typedef VOID(NTAPIPPS_POST_PROCESS_INIT_ROUTINE) (VOID)
 
typedef struct _PEB PEB
 
typedef struct _PEBPPEB
 

Enumerations

enum  prop_compression_type { PropCompression_None, PropCompression_Zlib, PropCompression_LZO, PropCompression_ZSTD }
 
enum  batch_operation {
  Batch_Delete, Batch_DeleteInode, Batch_DeleteDirItem, Batch_DeleteInodeRef,
  Batch_DeleteInodeExtRef, Batch_DeleteXattr, Batch_DeleteExtentData, Batch_DeleteFreeSpace,
  Batch_Insert, Batch_SetXattr, Batch_DirItem, Batch_InodeRef,
  Batch_InodeExtRef
}
 
enum  write_data_status {
  WriteDataStatus_Pending, WriteDataStatus_Success, WriteDataStatus_Error, WriteDataStatus_Cancelling,
  WriteDataStatus_Cancelled, WriteDataStatus_Ignore
}
 
enum  rollback_type { ROLLBACK_INSERT_EXTENT, ROLLBACK_DELETE_EXTENT, ROLLBACK_ADD_SPACE, ROLLBACK_SUBTRACT_SPACE }
 

Functions

 _Create_lock_level_ (tree_lock) _Create_lock_level_(fcb_lock) _Lock_level_order_(tree_lock
 
 _Requires_lock_not_held_ (Vcb->fcb_lock) _Acquires_shared_lock_(Vcb -> fcb_lock) static __inline void acquire_fcb_lock_shared(device_extension *Vcb)
 
 _Requires_lock_held_ (Vcb->fcb_lock) _Releases_lock_(Vcb -> fcb_lock) static __inline void release_fcb_lock(device_extension *Vcb)
 
static __inline voidmap_user_buffer (PIRP Irp, ULONG priority)
 
static __inline uint64_t unix_time_to_win (BTRFS_TIME *t)
 
static __inline void win_time_to_unix (LARGE_INTEGER t, BTRFS_TIME *out)
 
_Post_satisfies_ static stripe __inline void get_raid0_offset (_In_ uint64_t off, _In_ uint64_t stripe_length, _In_ uint16_t num_stripes, _Out_ uint64_t *stripeoff, _Out_ uint16_t *stripe)
 
static __inline uint64_t make_file_id (root *r, uint64_t inode)
 
 _Post_satisfies_ (return >=n) __inline static uint64_t sector_align(_In_ uint64_t n
 
static __inline bool is_subvol_readonly (root *r, PIRP Irp)
 
static __inline uint16_t get_extent_data_len (uint8_t type)
 
static __inline uint32_t get_extent_data_refcount (uint8_t type, void *data)
 
_Ret_maybenull_ devicefind_device_from_uuid (_In_ device_extension *Vcb, _In_ BTRFS_UUID *uuid)
 
 _Success_ (return) bool get_file_attributes_from_xattr(_In_reads_bytes_(len) char *val
 
ULONG get_file_attributes (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ uint64_t inode, _In_ uint8_t type, _In_ bool dotfile, _In_ bool ignore_xa, _In_opt_ PIRP Irp)
 
void free_fcb (_Inout_ fcb *fcb)
 
void free_fileref (_Inout_ file_ref *fr)
 
void protect_superblocks (_Inout_ chunk *c)
 
bool is_top_level (_In_ PIRP Irp)
 
NTSTATUS create_root (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ uint64_t id, _Out_ root **rootptr, _In_ bool no_tree, _In_ uint64_t offset, _In_opt_ PIRP Irp)
 
void uninit (_In_ device_extension *Vcb)
 
NTSTATUS dev_ioctl (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_reads_bytes_opt_(InputBufferSize) PVOID InputBuffer, _In_ ULONG InputBufferSize, _Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_ ULONG OutputBufferSize, _In_ bool Override, _Out_opt_ IO_STATUS_BLOCK *iosb)
 
bool is_file_name_valid (_In_ PUNICODE_STRING us, _In_ bool posix)
 
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)
 
_Ret_z_ WCHARfile_desc (_In_ PFILE_OBJECT FileObject)
 
WCHARfile_desc_fileref (_In_ file_ref *fileref)
 
void mark_fcb_dirty (_In_ fcb *fcb)
 
void mark_fileref_dirty (_In_ file_ref *fileref)
 
NTSTATUS delete_fileref (_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_ bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
 
void chunk_lock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ uint64_t start, _In_ uint64_t length)
 
void chunk_unlock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ uint64_t start, _In_ uint64_t length)
 
void init_device (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ bool get_nums)
 
void init_file_cache (_In_ PFILE_OBJECT FileObject, _In_ CC_FILE_SIZES *ccfs)
 
NTSTATUS sync_read_phys (_In_ PDEVICE_OBJECT DeviceObject, _In_ PFILE_OBJECT FileObject, _In_ uint64_t StartingOffset, _In_ ULONG Length, _Out_writes_bytes_(Length) PUCHAR Buffer, _In_ bool override)
 
NTSTATUS get_device_pnp_name (_In_ PDEVICE_OBJECT DeviceObject, _Out_ PUNICODE_STRING pnp_name, _Out_ const GUID **guid)
 
void log_device_error (_In_ device_extension *Vcb, _Inout_ device *dev, _In_ int error)
 
NTSTATUS find_chunk_usage (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_opt_ PIRP Irp)
 
 _Function_class_ (DRIVER_ADD_DEVICE) NTSTATUS __stdcall AddDevice(PDRIVER_OBJECT DriverObject
 
void reap_fcb (fcb *fcb)
 
void reap_fcbs (device_extension *Vcb)
 
void reap_fileref (device_extension *Vcb, file_ref *fr)
 
void reap_filerefs (device_extension *Vcb, file_ref *fr)
 
uint64_t chunk_estimate_phys_size (device_extension *Vcb, chunk *c, uint64_t u)
 
NTSTATUS utf8_to_utf16 (WCHAR *dest, ULONG dest_max, ULONG *dest_len, char *src, ULONG src_len)
 
NTSTATUS utf16_to_utf8 (char *dest, ULONG dest_max, ULONG *dest_len, WCHAR *src, ULONG src_len)
 
uint32_t get_num_of_processors ()
 
void init_fast_io_dispatch (FAST_IO_DISPATCH **fiod)
 
uint32_t calc_crc32c (_In_ uint32_t seed, _In_reads_bytes_(msglen) uint8_t *msg, _In_ ULONG msglen)
 
NTSTATUS find_item (_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _Out_ traverse_ptr *tp, _In_ const KEY *searchkey, _In_ bool ignore, _In_opt_ PIRP Irp)
 
NTSTATUS find_item_to_level (device_extension *Vcb, root *r, traverse_ptr *tp, const KEY *searchkey, bool ignore, uint8_t level, PIRP Irp)
 
bool find_next_item (_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, const traverse_ptr *tp, traverse_ptr *next_tp, bool ignore, PIRP Irp)
 
bool find_prev_item (_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, const traverse_ptr *tp, traverse_ptr *prev_tp, PIRP Irp)
 
void free_trees (device_extension *Vcb)
 
NTSTATUS insert_tree_item (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ uint64_t obj_id, _In_ uint8_t obj_type, _In_ uint64_t offset, _In_reads_bytes_opt_(size) _When_(return >=0, __drv_aliasesMem) void *data, _In_ uint16_t size, _Out_opt_ traverse_ptr *ptp, _In_opt_ PIRP Irp)
 
NTSTATUS delete_tree_item (_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _Inout_ traverse_ptr *tp)
 
void free_tree (tree *t)
 
NTSTATUS load_tree (device_extension *Vcb, uint64_t addr, uint8_t *buf, root *r, tree **pt)
 
NTSTATUS do_load_tree (device_extension *Vcb, tree_holder *th, root *r, tree *t, tree_data *td, PIRP Irp)
 
void clear_rollback (LIST_ENTRY *rollback)
 
void do_rollback (device_extension *Vcb, LIST_ENTRY *rollback)
 
void free_trees_root (device_extension *Vcb, root *r)
 
void add_rollback (_In_ LIST_ENTRY *rollback, _In_ enum rollback_type type, _In_ __drv_aliasesMem void *ptr)
 
NTSTATUS commit_batch_list (_Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, LIST_ENTRY *batchlist, PIRP Irp)
 
void clear_batch_list (device_extension *Vcb, LIST_ENTRY *batchlist)
 
NTSTATUS skip_to_difference (device_extension *Vcb, traverse_ptr *tp, traverse_ptr *tp2, bool *ended1, bool *ended2)
 
NTSTATUS remove_drive_letter (PDEVICE_OBJECT mountmgr, PUNICODE_STRING devpath)
 
 _Function_class_ (KSTART_ROUTINE) void __stdcall mountmgr_thread(_In_ void *context)
 
 _Function_class_ (DRIVER_NOTIFICATION_CALLBACK_ROUTINE) NTSTATUS __stdcall pnp_notification(PVOID NotificationStructure
 
void disk_arrival (PDRIVER_OBJECT DriverObject, PUNICODE_STRING devpath)
 
void volume_arrival (PDRIVER_OBJECT DriverObject, PUNICODE_STRING devpath)
 
void volume_removal (PDRIVER_OBJECT DriverObject, PUNICODE_STRING devpath)
 
void remove_volume_child (_Inout_ _Requires_exclusive_lock_held_(_Curr_->child_lock) _Releases_exclusive_lock_(_Curr_->child_lock) _In_ volume_device_extension *vde, _In_ volume_child *vc, _In_ bool skip_dev)
 
NTSTATUS init_cache ()
 
void free_cache ()
 
NTSTATUS write_file (device_extension *Vcb, PIRP Irp, bool wait, bool deferred_write)
 
NTSTATUS write_file2 (device_extension *Vcb, PIRP Irp, LARGE_INTEGER offset, void *buf, ULONG *length, bool paging_io, bool no_cache, bool wait, bool deferred_write, bool write_irp, LIST_ENTRY *rollback)
 
NTSTATUS truncate_file (fcb *fcb, uint64_t end, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS extend_file (fcb *fcb, file_ref *fileref, uint64_t end, bool prealloc, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS excise_extents (device_extension *Vcb, fcb *fcb, uint64_t start_data, uint64_t end_data, PIRP Irp, LIST_ENTRY *rollback)
 
chunkget_chunk_from_address (device_extension *Vcb, uint64_t address)
 
NTSTATUS alloc_chunk (device_extension *Vcb, uint64_t flags, chunk **pc, bool full_size)
 
NTSTATUS write_data (_In_ device_extension *Vcb, _In_ uint64_t address, _In_reads_bytes_(length) void *data, _In_ uint32_t length, _In_ write_data_context *wtc, _In_opt_ PIRP Irp, _In_opt_ chunk *c, _In_ bool file_write, _In_ uint64_t irp_offset, _In_ ULONG priority)
 
NTSTATUS write_data_complete (device_extension *Vcb, uint64_t address, void *data, uint32_t length, PIRP Irp, chunk *c, bool file_write, uint64_t irp_offset, ULONG priority)
 
void free_write_data_stripes (write_data_context *wtc)
 
 _Dispatch_type_ (IRP_MJ_WRITE) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_write(IN PDEVICE_OBJECT DeviceObject
 
 _Requires_lock_held_ (c->lock) _When_(return !=0
 
 _Releases_lock_ (c->lock)) bool insert_extent_chunk(_In_ device_extension *Vcb
 
NTSTATUS do_write_file (fcb *fcb, uint64_t start_data, uint64_t end_data, void *data, PIRP Irp, bool file_write, uint32_t irp_offset, LIST_ENTRY *rollback)
 
NTSTATUS write_compressed (fcb *fcb, uint64_t start_data, uint64_t end_data, void *data, PIRP Irp, LIST_ENTRY *rollback)
 
bool find_data_address_in_chunk (device_extension *Vcb, chunk *c, uint64_t length, uint64_t *address)
 
void get_raid56_lock_range (chunk *c, uint64_t address, uint64_t length, uint64_t *lockaddr, uint64_t *locklen)
 
NTSTATUS calc_csum (_In_ device_extension *Vcb, _In_reads_bytes_(sectors *Vcb->superblock.sector_size) uint8_t *data, _In_ uint32_t sectors, _Out_writes_bytes_(sectors *sizeof(uint32_t)) uint32_t *csum)
 
void add_insert_extent_rollback (LIST_ENTRY *rollback, fcb *fcb, extent *ext)
 
NTSTATUS add_extent_to_fcb (_In_ fcb *fcb, _In_ uint64_t offset, _In_reads_bytes_(edsize) EXTENT_DATA *ed, _In_ uint16_t edsize, _In_ bool unique, _In_opt_ _When_(return >=0, __drv_aliasesMem) uint32_t *csum, _In_ LIST_ENTRY *rollback)
 
void add_extent (_In_ fcb *fcb, _In_ LIST_ENTRY *prevextle, _In_ __drv_aliasesMem extent *newext)
 
 _Dispatch_type_ (IRP_MJ_DIRECTORY_CONTROL) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_directory_control(IN PDEVICE_OBJECT DeviceObject
 
ULONG get_reparse_tag (device_extension *Vcb, root *subvol, uint64_t inode, uint8_t type, ULONG atts, bool lxss, PIRP Irp)
 
ULONG get_reparse_tag_fcb (fcb *fcb)
 
 _Dispatch_type_ (IRP_MJ_QUERY_SECURITY) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_query_security(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_SET_SECURITY) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_set_security(IN PDEVICE_OBJECT DeviceObject
 
void fcb_get_sd (fcb *fcb, struct _fcb *parent, bool look_for_xattr, PIRP Irp)
 
void add_user_mapping (WCHAR *sidstring, ULONG sidstringlength, uint32_t uid)
 
void add_group_mapping (WCHAR *sidstring, ULONG sidstringlength, uint32_t gid)
 
uint32_t sid_to_uid (PSID sid)
 
NTSTATUS uid_to_sid (uint32_t uid, PSID *sid)
 
NTSTATUS fcb_get_new_sd (fcb *fcb, file_ref *parfileref, ACCESS_STATE *as)
 
void find_gid (struct _fcb *fcb, struct _fcb *parfcb, PSECURITY_SUBJECT_CONTEXT subjcont)
 
 _Dispatch_type_ (IRP_MJ_SET_INFORMATION) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_set_information(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_QUERY_INFORMATION) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_query_information(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_QUERY_EA) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_query_ea(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_SET_EA) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_set_ea(IN PDEVICE_OBJECT DeviceObject
 
bool has_open_children (file_ref *fileref)
 
NTSTATUS stream_set_end_of_file_information (device_extension *Vcb, uint16_t end, fcb *fcb, file_ref *fileref, bool advance_only)
 
NTSTATUS fileref_get_filename (file_ref *fileref, PUNICODE_STRING fn, USHORT *name_offset, ULONG *preqlen)
 
void insert_dir_child_into_hash_lists (fcb *fcb, dir_child *dc)
 
void remove_dir_child_from_hash_lists (fcb *fcb, dir_child *dc)
 
NTSTATUS get_reparse_point (PDEVICE_OBJECT DeviceObject, PFILE_OBJECT FileObject, void *buffer, DWORD buflen, ULONG_PTR *retlen)
 
NTSTATUS set_reparse_point2 (fcb *fcb, REPARSE_DATA_BUFFER *rdb, ULONG buflen, ccb *ccb, file_ref *fileref, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS set_reparse_point (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS delete_reparse_point (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
 _Dispatch_type_ (IRP_MJ_CREATE) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_create(IN PDEVICE_OBJECT DeviceObject
 
NTSTATUS open_fileref (_Requires_lock_held_(_Curr_->tree_lock) _Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Out_ file_ref **pfr, _In_ PUNICODE_STRING fnus, _In_opt_ file_ref *related, _In_ bool parent, _Out_opt_ USHORT *parsed, _Out_opt_ ULONG *fn_offset, _In_ POOL_TYPE pooltype, _In_ bool case_sensitive, _In_opt_ PIRP Irp)
 
NTSTATUS open_fcb (_Requires_lock_held_(_Curr_->tree_lock) _Requires_exclusive_lock_held_(_Curr_->fcb_lock) device_extension *Vcb, root *subvol, uint64_t inode, uint8_t type, PANSI_STRING utf8, bool always_add_hl, fcb *parent, fcb **pfcb, POOL_TYPE pooltype, PIRP Irp)
 
NTSTATUS load_csum (_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, uint32_t *csum, uint64_t start, uint64_t length, PIRP Irp)
 
NTSTATUS load_dir_children (_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, fcb *fcb, bool ignore_size, PIRP Irp)
 
NTSTATUS add_dir_child (fcb *fcb, uint64_t inode, bool subvol, PANSI_STRING utf8, PUNICODE_STRING name, uint8_t type, dir_child **pdc)
 
NTSTATUS open_fileref_child (_Requires_lock_held_(_Curr_->tree_lock) _Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _In_ file_ref *sf, _In_ PUNICODE_STRING name, _In_ bool case_sensitive, _In_ bool lastpart, _In_ bool streampart, _In_ POOL_TYPE pooltype, _Out_ file_ref **psf2, _In_opt_ PIRP Irp)
 
fcbcreate_fcb (device_extension *Vcb, POOL_TYPE pool_type)
 
NTSTATUS find_file_in_dir (PUNICODE_STRING filename, fcb *fcb, root **subvol, uint64_t *inode, dir_child **pdc, bool case_sensitive)
 
uint32_t inherit_mode (fcb *parfcb, bool is_dir)
 
file_refcreate_fileref (device_extension *Vcb)
 
NTSTATUS open_fileref_by_inode (_Requires_exclusive_lock_held_(_Curr_->fcb_lock) device_extension *Vcb, root *subvol, uint64_t inode, file_ref **pfr, PIRP Irp)
 
NTSTATUS fsctl_request (PDEVICE_OBJECT DeviceObject, PIRP *Pirp, uint32_t type)
 
void do_unlock_volume (device_extension *Vcb)
 
void trim_whole_device (device *dev)
 
void flush_subvol_fcbs (root *subvol)
 
bool fcb_is_inline (fcb *fcb)
 
NTSTATUS do_write (device_extension *Vcb, PIRP Irp)
 
NTSTATUS get_tree_new_address (device_extension *Vcb, tree *t, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS flush_fcb (fcb *fcb, bool cache, LIST_ENTRY *batchlist, PIRP Irp)
 
NTSTATUS write_data_phys (_In_ PDEVICE_OBJECT device, _In_ PFILE_OBJECT fileobj, _In_ uint64_t address, _In_reads_bytes_(length) void *data, _In_ uint32_t length)
 
bool is_tree_unique (device_extension *Vcb, tree *t, PIRP Irp)
 
NTSTATUS do_tree_writes (device_extension *Vcb, LIST_ENTRY *tree_writes, bool no_free)
 
void add_checksum_entry (device_extension *Vcb, uint64_t address, ULONG length, uint32_t *csum, PIRP Irp)
 
bool find_metadata_address_in_chunk (device_extension *Vcb, chunk *c, uint64_t *address)
 
void add_trim_entry_avoid_sb (device_extension *Vcb, device *dev, uint64_t address, uint64_t size)
 
NTSTATUS insert_tree_item_batch (LIST_ENTRY *batchlist, device_extension *Vcb, root *r, uint64_t objid, uint8_t objtype, uint64_t offset, _In_opt_ _When_(return >=0, __drv_aliasesMem) void *data, uint16_t datalen, enum batch_operation operation)
 
NTSTATUS flush_partial_stripe (device_extension *Vcb, chunk *c, partial_stripe *ps)
 
NTSTATUS update_dev_item (device_extension *Vcb, device *device, PIRP Irp)
 
 _Dispatch_type_ (IRP_MJ_READ) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_read(PDEVICE_OBJECT DeviceObject
 
NTSTATUS read_data (_In_ device_extension *Vcb, _In_ uint64_t addr, _In_ uint32_t length, _In_reads_bytes_opt_(length *sizeof(uint32_t)/Vcb->superblock.sector_size) uint32_t *csum, _In_ bool is_tree, _Out_writes_bytes_(length) uint8_t *buf, _In_opt_ chunk *c, _Out_opt_ chunk **pc, _In_opt_ PIRP Irp, _In_ uint64_t generation, _In_ bool file_read, _In_ ULONG priority)
 
NTSTATUS read_file (fcb *fcb, uint8_t *data, uint64_t start, uint64_t length, ULONG *pbr, PIRP Irp)
 
NTSTATUS read_stream (fcb *fcb, uint8_t *data, uint64_t start, ULONG length, ULONG *pbr)
 
NTSTATUS do_read (PIRP Irp, bool wait, ULONG *bytes_read)
 
NTSTATUS check_csum (device_extension *Vcb, uint8_t *data, uint32_t sectors, uint32_t *csum)
 
void raid6_recover2 (uint8_t *sectors, uint16_t num_stripes, ULONG sector_size, uint16_t missing1, uint16_t missing2, uint8_t *out)
 
 _Dispatch_type_ (IRP_MJ_PNP) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_pnp(PDEVICE_OBJECT DeviceObject
 
NTSTATUS pnp_surprise_removal (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS pnp_query_remove_device (PDEVICE_OBJECT DeviceObject, PIRP Irp)
 
NTSTATUS load_cache_chunk (device_extension *Vcb, chunk *c, PIRP Irp)
 
NTSTATUS clear_free_space_cache (device_extension *Vcb, LIST_ENTRY *batchlist, PIRP Irp)
 
NTSTATUS allocate_cache (device_extension *Vcb, bool *changed, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS update_chunk_caches (device_extension *Vcb, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS update_chunk_caches_tree (device_extension *Vcb, PIRP Irp)
 
NTSTATUS add_space_entry (LIST_ENTRY *list, LIST_ENTRY *list_size, uint64_t offset, uint64_t size)
 
void space_list_add (chunk *c, uint64_t address, uint64_t length, LIST_ENTRY *rollback)
 
void space_list_add2 (LIST_ENTRY *list, LIST_ENTRY *list_size, uint64_t address, uint64_t length, chunk *c, LIST_ENTRY *rollback)
 
void space_list_subtract (chunk *c, bool deleting, uint64_t address, uint64_t length, LIST_ENTRY *rollback)
 
void space_list_subtract2 (LIST_ENTRY *list, LIST_ENTRY *list_size, uint64_t address, uint64_t length, chunk *c, LIST_ENTRY *rollback)
 
NTSTATUS load_stored_free_space_cache (device_extension *Vcb, chunk *c, bool load_only, PIRP Irp)
 
NTSTATUS increase_extent_refcount_data (device_extension *Vcb, uint64_t address, uint64_t size, uint64_t root, uint64_t inode, uint64_t offset, uint32_t refcount, PIRP Irp)
 
NTSTATUS decrease_extent_refcount_data (device_extension *Vcb, uint64_t address, uint64_t size, uint64_t root, uint64_t inode, uint64_t offset, uint32_t refcount, bool superseded, PIRP Irp)
 
NTSTATUS decrease_extent_refcount_tree (device_extension *Vcb, uint64_t address, uint64_t size, uint64_t root, uint8_t level, PIRP Irp)
 
uint64_t get_extent_refcount (device_extension *Vcb, uint64_t address, uint64_t size, PIRP Irp)
 
bool is_extent_unique (device_extension *Vcb, uint64_t address, uint64_t size, PIRP Irp)
 
NTSTATUS increase_extent_refcount (device_extension *Vcb, uint64_t address, uint64_t size, uint8_t type, void *data, KEY *firstitem, uint8_t level, PIRP Irp)
 
uint64_t get_extent_flags (device_extension *Vcb, uint64_t address, PIRP Irp)
 
void update_extent_flags (device_extension *Vcb, uint64_t address, uint64_t flags, PIRP Irp)
 
NTSTATUS update_changed_extent_ref (device_extension *Vcb, chunk *c, uint64_t address, uint64_t size, uint64_t root, uint64_t objid, uint64_t offset, int32_t count, bool no_csum, bool superseded, PIRP Irp)
 
void add_changed_extent_ref (chunk *c, uint64_t address, uint64_t size, uint64_t root, uint64_t objid, uint64_t offset, uint32_t count, bool no_csum)
 
uint64_t find_extent_shared_tree_refcount (device_extension *Vcb, uint64_t address, uint64_t parent, PIRP Irp)
 
uint32_t find_extent_shared_data_refcount (device_extension *Vcb, uint64_t address, uint64_t parent, PIRP Irp)
 
NTSTATUS decrease_extent_refcount (device_extension *Vcb, uint64_t address, uint64_t size, uint8_t type, void *data, KEY *firstitem, uint8_t level, uint64_t parent, bool superseded, PIRP Irp)
 
uint64_t get_extent_data_ref_hash2 (uint64_t root, uint64_t objid, uint64_t offset)
 
NTSTATUS do_read_job (PIRP Irp)
 
NTSTATUS do_write_job (device_extension *Vcb, PIRP Irp)
 
bool add_thread_job (device_extension *Vcb, PIRP Irp)
 
void read_registry (PUNICODE_STRING regpath, bool refresh)
 
NTSTATUS registry_mark_volume_mounted (BTRFS_UUID *uuid)
 
NTSTATUS registry_mark_volume_unmounted (BTRFS_UUID *uuid)
 
NTSTATUS registry_load_volume_options (device_extension *Vcb)
 
void watch_registry (HANDLE regh)
 
NTSTATUS zlib_decompress (uint8_t *inbuf, uint32_t inlen, uint8_t *outbuf, uint32_t outlen)
 
NTSTATUS lzo_decompress (uint8_t *inbuf, uint32_t inlen, uint8_t *outbuf, uint32_t outlen, uint32_t inpageoff)
 
NTSTATUS zstd_decompress (uint8_t *inbuf, uint32_t inlen, uint8_t *outbuf, uint32_t outlen)
 
NTSTATUS write_compressed_bit (fcb *fcb, uint64_t start_data, uint64_t end_data, void *data, bool *compressed, PIRP Irp, LIST_ENTRY *rollback)
 
void galois_double (uint8_t *data, uint32_t len)
 
void galois_divpower (uint8_t *data, uint8_t div, uint32_t readlen)
 
uint8_t gpow2 (uint8_t e)
 
uint8_t gmul (uint8_t a, uint8_t b)
 
uint8_t gdiv (uint8_t a, uint8_t b)
 
 _Dispatch_type_ (IRP_MJ_DEVICE_CONTROL) _Function_class_(DRIVER_DISPATCH) NTSTATUS __stdcall drv_device_control(IN PDEVICE_OBJECT DeviceObject
 
NTSTATUS add_calc_job (device_extension *Vcb, uint8_t *data, uint32_t sectors, uint32_t *csum, calc_job **pcj)
 
void free_calc_job (calc_job *cj)
 
NTSTATUS start_balance (device_extension *Vcb, void *data, ULONG length, KPROCESSOR_MODE processor_mode)
 
NTSTATUS query_balance (device_extension *Vcb, void *data, ULONG length)
 
NTSTATUS pause_balance (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS resume_balance (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS stop_balance (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS look_for_balance_item (_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb)
 
NTSTATUS remove_device (device_extension *Vcb, void *data, ULONG length, KPROCESSOR_MODE processor_mode)
 
NTSTATUS vol_create (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_close (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_read (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_write (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_query_information (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_set_information (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_query_ea (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_set_ea (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_flush_buffers (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_query_volume_information (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_set_volume_information (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_cleanup (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_directory_control (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_file_system_control (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_lock_control (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_device_control (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_shutdown (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_query_security (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS vol_set_security (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
void add_volume_device (superblock *sb, PUNICODE_STRING devpath, uint64_t length, ULONG disk_num, ULONG part_num)
 
NTSTATUS mountmgr_add_drive_letter (PDEVICE_OBJECT mountmgr, PUNICODE_STRING devpath)
 
NTSTATUS start_scrub (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS query_scrub (device_extension *Vcb, KPROCESSOR_MODE processor_mode, void *data, ULONG length)
 
NTSTATUS pause_scrub (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS resume_scrub (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS stop_scrub (device_extension *Vcb, KPROCESSOR_MODE processor_mode)
 
NTSTATUS send_subvol (device_extension *Vcb, void *data, ULONG datalen, PFILE_OBJECT FileObject, PIRP Irp)
 
NTSTATUS read_send_buffer (device_extension *Vcb, PFILE_OBJECT FileObject, void *data, ULONG datalen, ULONG_PTR *retlen, KPROCESSOR_MODE processor_mode)
 
NTSTATUS compat_FsRtlValidateReparsePointBuffer (IN ULONG BufferLength, IN PREPARSE_DATA_BUFFER ReparseBuffer)
 
void __stdcall check_system_root (PDRIVER_OBJECT DriverObject, PVOID Context, ULONG Count)
 
static __inline void print_open_trees (device_extension *Vcb)
 
static __inline bool write_fcb_compressed (fcb *fcb)
 
static __inline void do_xor (uint8_t *buf1, uint8_t *buf2, uint32_t len)
 
static __inline uint64_t fcb_alloc_size (fcb *fcb)
 
PEPROCESS PsGetThreadProcess (_In_ PETHREAD Thread)
 

Variables

_In_ uint64_t a
 
return n
 
_In_ uint16_t len
 
_In_ uint16_t _Out_ ULONGatts
 
PDEVICE_OBJECT PhysicalDeviceObject
 
bool have_sse2
 
uint32_t mount_compress
 
uint32_t mount_compress_force
 
uint32_t mount_compress_type
 
uint32_t mount_zlib_level
 
uint32_t mount_zstd_level
 
uint32_t mount_flush_interval
 
uint32_t mount_max_inline
 
uint32_t mount_skip_balance
 
uint32_t mount_no_barrier
 
uint32_t mount_no_trim
 
uint32_t mount_clear_cache
 
uint32_t mount_allow_degraded
 
uint32_t mount_readonly
 
uint32_t no_pnp
 
static const char lxuid [] = "$LXUID"
 
static const char lxgid [] = "$LXGID"
 
static const char lxmod [] = "$LXMOD"
 
static const char lxdev [] = "$LXDEV"
 
PVOID Context
 
CACHE_MANAGER_CALLBACKScache_callbacks
 
IN PIRP Irp
 
_In_ fcb _In_ chunkc
 
_In_ fcb _In_ chunk _In_ uint64_t start_data
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t length
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool prealloc
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ voiddata
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRYrollback
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t compression = compression
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t _In_ uint64_t decoded_size = decoded_size
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t _In_ uint64_t _In_ bool file_write
 
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ uint8_t _In_ uint64_t _In_ bool _In_ uint64_t irp_offset
 

Macro Definition Documentation

◆ __drv_aliasesMem

#define __drv_aliasesMem

Definition at line 183 of file btrfs_drv.h.

◆ __S_IFBLK

#define __S_IFBLK   0060000 /* Block device. */

Definition at line 1664 of file btrfs_drv.h.

◆ __S_IFCHR

#define __S_IFCHR   0020000 /* Character device. */

Definition at line 1663 of file btrfs_drv.h.

◆ __S_IFDIR

#define __S_IFDIR   0040000 /* Directory. */

Definition at line 1662 of file btrfs_drv.h.

◆ __S_IFIFO

#define __S_IFIFO   0010000 /* FIFO. */

Definition at line 1666 of file btrfs_drv.h.

◆ __S_IFLNK

#define __S_IFLNK   0120000 /* Symbolic link. */

Definition at line 1667 of file btrfs_drv.h.

◆ __S_IFMT

#define __S_IFMT   0170000 /* These bits determine file type. */

Definition at line 1661 of file btrfs_drv.h.

◆ __S_IFREG

#define __S_IFREG   0100000 /* Regular file. */

Definition at line 1665 of file btrfs_drv.h.

◆ __S_IFSOCK

#define __S_IFSOCK   0140000 /* Socket. */

Definition at line 1668 of file btrfs_drv.h.

◆ __S_ISTYPE

#define __S_ISTYPE (   mode,
  mask 
)    (((mode) & __S_IFMT) == (mask))

Definition at line 1669 of file btrfs_drv.h.

◆ _Acquires_exclusive_lock_

#define _Acquires_exclusive_lock_ (   a)

Definition at line 196 of file btrfs_drv.h.

◆ _Acquires_shared_lock_

#define _Acquires_shared_lock_ (   a)

Definition at line 197 of file btrfs_drv.h.

◆ _Create_lock_level_

#define _Create_lock_level_ (   a)

Definition at line 192 of file btrfs_drv.h.

◆ _CRT_SECURE_NO_WARNINGS

#define _CRT_SECURE_NO_WARNINGS

Definition at line 26 of file btrfs_drv.h.

◆ _Dispatch_type_

#define _Dispatch_type_ (   a)

Definition at line 191 of file btrfs_drv.h.

◆ _Has_lock_level_

#define _Has_lock_level_ (   a)

Definition at line 194 of file btrfs_drv.h.

◆ _Lock_level_order_

#define _Lock_level_order_ (   a,
  b 
)

Definition at line 193 of file btrfs_drv.h.

◆ _NO_CRT_STDIO_INLINE

#define _NO_CRT_STDIO_INLINE

Definition at line 27 of file btrfs_drv.h.

◆ _Out_writes_bytes_opt_

#define _Out_writes_bytes_opt_ (   a)

Definition at line 187 of file btrfs_drv.h.

◆ _Post_satisfies_

#define _Post_satisfies_ (   a)

Definition at line 189 of file btrfs_drv.h.

◆ _Pre_satisfies_

#define _Pre_satisfies_ (   a)

Definition at line 188 of file btrfs_drv.h.

◆ _Releases_exclusive_lock_

#define _Releases_exclusive_lock_ (   a)

Definition at line 190 of file btrfs_drv.h.

◆ _Releases_lock_

#define _Releases_lock_ (   a)

Definition at line 186 of file btrfs_drv.h.

◆ _Requires_exclusive_lock_held_

#define _Requires_exclusive_lock_held_ (   a)

Definition at line 185 of file btrfs_drv.h.

◆ _Requires_lock_held_

#define _Requires_lock_held_ (   a)

Definition at line 184 of file btrfs_drv.h.

◆ _Requires_lock_not_held_

#define _Requires_lock_not_held_ (   a)

Definition at line 195 of file btrfs_drv.h.

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0601

Definition at line 24 of file btrfs_drv.h.

◆ acquire_chunk_lock

#define acquire_chunk_lock (   c,
  Vcb 
)    ExAcquireResourceExclusiveLite(&(c)->lock, true)

Definition at line 1093 of file btrfs_drv.h.

◆ ALLOC_TAG

#define ALLOC_TAG   0x7442484D

Definition at line 91 of file btrfs_drv.h.

◆ ALLOC_TAG_ZLIB

#define ALLOC_TAG_ZLIB   0x7A42484D

Definition at line 92 of file btrfs_drv.h.

◆ BALANCE_OPTS_DATA

#define BALANCE_OPTS_DATA   0

Definition at line 663 of file btrfs_drv.h.

◆ BALANCE_OPTS_METADATA

#define BALANCE_OPTS_METADATA   1

Definition at line 664 of file btrfs_drv.h.

◆ BALANCE_OPTS_SYSTEM

#define BALANCE_OPTS_SYSTEM   2

Definition at line 665 of file btrfs_drv.h.

◆ BTRFS_NODE_TYPE_CCB

#define BTRFS_NODE_TYPE_CCB   0x2295

Definition at line 88 of file btrfs_drv.h.

◆ BTRFS_NODE_TYPE_FCB

#define BTRFS_NODE_TYPE_FCB   0x2296

Definition at line 89 of file btrfs_drv.h.

◆ BTRFS_VOLUME_PREFIX

#define BTRFS_VOLUME_PREFIX   L"\\Device\\Btrfs{"

Definition at line 127 of file btrfs_drv.h.

◆ CC_ENABLE_DISK_IO_ACCOUNTING

#define CC_ENABLE_DISK_IO_ACCOUNTING   0x00000010

Definition at line 1753 of file btrfs_drv.h.

◆ COMPRESSED_EXTENT_SIZE

#define COMPRESSED_EXTENT_SIZE   0x20000

Definition at line 116 of file btrfs_drv.h.

◆ EA_CASE_SENSITIVE

#define EA_CASE_SENSITIVE   "user.casesensitive"

Definition at line 109 of file btrfs_drv.h.

◆ EA_CASE_SENSITIVE_HASH

#define EA_CASE_SENSITIVE_HASH   0x1a9d97d4

Definition at line 110 of file btrfs_drv.h.

◆ EA_DOSATTRIB

#define EA_DOSATTRIB   "user.DOSATTRIB"

Definition at line 100 of file btrfs_drv.h.

◆ EA_DOSATTRIB_HASH

#define EA_DOSATTRIB_HASH   0x914f9939

Definition at line 101 of file btrfs_drv.h.

◆ EA_EA

#define EA_EA   "user.EA"

Definition at line 106 of file btrfs_drv.h.

◆ EA_EA_HASH

#define EA_EA_HASH   0x8270dd43

Definition at line 107 of file btrfs_drv.h.

◆ EA_NTACL

#define EA_NTACL   "security.NTACL"

Definition at line 97 of file btrfs_drv.h.

◆ EA_NTACL_HASH

#define EA_NTACL_HASH   0x45922146

Definition at line 98 of file btrfs_drv.h.

◆ EA_PROP_COMPRESSION

#define EA_PROP_COMPRESSION   "btrfs.compression"

Definition at line 112 of file btrfs_drv.h.

◆ EA_PROP_COMPRESSION_HASH

#define EA_PROP_COMPRESSION_HASH   0x20ccdf69

Definition at line 113 of file btrfs_drv.h.

◆ EA_REPARSE

#define EA_REPARSE   "user.reparse"

Definition at line 103 of file btrfs_drv.h.

◆ EA_REPARSE_HASH

#define EA_REPARSE_HASH   0xfabad1fe

Definition at line 104 of file btrfs_drv.h.

◆ ERR

#define ERR (   s,
  ... 
)    DbgPrint("Btrfs ERR : %s : " s, funcname, ##__VA_ARGS__)

Definition at line 1182 of file btrfs_drv.h.

◆ except

#define except (   x)    if (0 && (x))

Definition at line 135 of file btrfs_drv.h.

◆ fast_io_possible

#define fast_io_possible (   fcb)    (!FsRtlAreThereCurrentFileLocks(&fcb->lock) && !fcb->Vcb->readonly ? FastIoIsPossible : FastIoIsQuestionable)

Definition at line 1575 of file btrfs_drv.h.

◆ FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL

#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL   0x00020000

Definition at line 148 of file btrfs_drv.h.

◆ FILE_SUPPORTS_BLOCK_REFCOUNTING

#define FILE_SUPPORTS_BLOCK_REFCOUNTING   0x08000000

Definition at line 140 of file btrfs_drv.h.

◆ FILE_SUPPORTS_POSIX_UNLINK_RENAME

#define FILE_SUPPORTS_POSIX_UNLINK_RENAME   0x00000400

Definition at line 144 of file btrfs_drv.h.

◆ finally

#define finally   if (1)

Definition at line 136 of file btrfs_drv.h.

◆ FIXME

#define FIXME (   s,
  ... 
)    DbgPrint("Btrfs FIXME : %s : " s, funcname, ##__VA_ARGS__)

Definition at line 1181 of file btrfs_drv.h.

◆ FSCTL_DUPLICATE_EXTENTS_TO_FILE

#define FSCTL_DUPLICATE_EXTENTS_TO_FILE   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 209, METHOD_BUFFERED, FILE_WRITE_ACCESS)

Definition at line 162 of file btrfs_drv.h.

◆ FSCTL_GET_INTEGRITY_INFORMATION

#define FSCTL_GET_INTEGRITY_INFORMATION   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 159, METHOD_BUFFERED, FILE_ANY_ACCESS)

Definition at line 178 of file btrfs_drv.h.

◆ FSCTL_SET_INTEGRITY_INFORMATION

#define FSCTL_SET_INTEGRITY_INFORMATION   CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 160, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)

Definition at line 179 of file btrfs_drv.h.

◆ funcname

#define funcname   __func__

Definition at line 1128 of file btrfs_drv.h.

◆ GID_NOBODY

#define GID_NOBODY   65534

Definition at line 95 of file btrfs_drv.h.

◆ hex_digit

#define hex_digit (   c)    ((c) <= 9) ? ((c) + '0') : ((c) - 10 + 'a')

Definition at line 1656 of file btrfs_drv.h.

◆ increase_fileref_refcount

#define increase_fileref_refcount (   fileref)    InterlockedIncrement(&fileref->refcount)

Definition at line 1647 of file btrfs_drv.h.

◆ int3

#define int3   asm("int3;")

Definition at line 1653 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_BLOCKDEV

#define IO_REPARSE_TAG_LXSS_BLOCKDEV   0x80000026

Definition at line 125 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_CHARDEV

#define IO_REPARSE_TAG_LXSS_CHARDEV   0x80000025

Definition at line 124 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_FIFO

#define IO_REPARSE_TAG_LXSS_FIFO   0x80000024

Definition at line 123 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_SOCKET

#define IO_REPARSE_TAG_LXSS_SOCKET   0x80000023

Definition at line 122 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_SYMLINK

#define IO_REPARSE_TAG_LXSS_SYMLINK   0xa000001d

Definition at line 120 of file btrfs_drv.h.

◆ keycmp

#define keycmp (   key1,
  key2 
)
Value:
((key1.obj_id < key2.obj_id) ? -1 :\
((key1.obj_id > key2.obj_id) ? 1 :\
((key1.obj_type < key2.obj_type) ? -1 :\
((key1.obj_type > key2.obj_type) ? 1 :\
((key1.offset < key2.offset) ? -1 :\
((key1.offset > key2.offset) ? 1 :\
0))))))
GLuint64EXT GLuint GLuint GLenum GLenum GLuint GLuint GLenum GLuint GLuint key1
Definition: glext.h:10608

Definition at line 980 of file btrfs_drv.h.

◆ major

#define major (   rdev)    ((((rdev) >> 8) & 0xFFF) | ((uint32_t)((rdev) >> 32) & ~0xFFF))

Definition at line 1729 of file btrfs_drv.h.

◆ makedev

#define makedev (   major,
  minor 
)    (((minor) & 0xFF) | (((major) & 0xFFF) << 8) | (((uint64_t)((minor) & ~0xFF)) << 12) | (((uint64_t)((major) & ~0xFFF)) << 32))

Definition at line 1573 of file btrfs_drv.h.

◆ MAX_EXTENT_SIZE

#define MAX_EXTENT_SIZE   0x8000000

Definition at line 115 of file btrfs_drv.h.

◆ minor

#define minor (   rdev)    (((rdev) & 0xFF) | ((uint32_t)((rdev) >> 12) & ~0xFF))

Definition at line 1730 of file btrfs_drv.h.

◆ NTDDI_VERSION

#define NTDDI_VERSION   0x06020000

Definition at line 25 of file btrfs_drv.h.

◆ READ_AHEAD_GRANULARITY

#define READ_AHEAD_GRANULARITY   COMPRESSED_EXTENT_SIZE

Definition at line 118 of file btrfs_drv.h.

◆ release_chunk_lock

#define release_chunk_lock (   c,
  Vcb 
)    ExReleaseResourceLite(&(c)->lock)

Definition at line 1094 of file btrfs_drv.h.

◆ S_IRGRP

#define S_IRGRP   (S_IRUSR >> 3)

Definition at line 1693 of file btrfs_drv.h.

◆ S_IROTH

#define S_IROTH   (S_IRGRP >> 3)

Definition at line 1705 of file btrfs_drv.h.

◆ S_IRUSR

#define S_IRUSR   0000400

Definition at line 1676 of file btrfs_drv.h.

◆ S_ISDIR

#define S_ISDIR (   mode)    __S_ISTYPE((mode), __S_IFDIR)

Definition at line 1672 of file btrfs_drv.h.

◆ S_ISGID

#define S_ISGID   0002000

Definition at line 1721 of file btrfs_drv.h.

◆ S_ISUID

#define S_ISUID   0004000

Definition at line 1717 of file btrfs_drv.h.

◆ S_ISVTX

#define S_ISVTX   0001000

Definition at line 1725 of file btrfs_drv.h.

◆ S_IWGRP

#define S_IWGRP   (S_IWUSR >> 3)

Definition at line 1697 of file btrfs_drv.h.

◆ S_IWOTH

#define S_IWOTH   (S_IWGRP >> 3)

Definition at line 1709 of file btrfs_drv.h.

◆ S_IWUSR

#define S_IWUSR   0000200

Definition at line 1680 of file btrfs_drv.h.

◆ S_IXGRP

#define S_IXGRP   (S_IXUSR >> 3)

Definition at line 1701 of file btrfs_drv.h.

◆ S_IXOTH

#define S_IXOTH   (S_IXGRP >> 3)

Definition at line 1713 of file btrfs_drv.h.

◆ S_IXUSR

#define S_IXUSR   0000100

Definition at line 1684 of file btrfs_drv.h.

◆ TRACE

#define TRACE (   s,
  ... 
)

Definition at line 1179 of file btrfs_drv.h.

◆ try

#define try   if (1)

Definition at line 134 of file btrfs_drv.h.

◆ UID_NOBODY

#define UID_NOBODY   65534

Definition at line 94 of file btrfs_drv.h.

◆ UNUSED

#define UNUSED (   x)    (void)(x)

Definition at line 86 of file btrfs_drv.h.

◆ VCB_TYPE_BUS

#define VCB_TYPE_BUS   5

Definition at line 661 of file btrfs_drv.h.

◆ VCB_TYPE_CONTROL

#define VCB_TYPE_CONTROL   2

Definition at line 658 of file btrfs_drv.h.

◆ VCB_TYPE_FS

#define VCB_TYPE_FS   1

Definition at line 657 of file btrfs_drv.h.

◆ VCB_TYPE_PDO

#define VCB_TYPE_PDO   4

Definition at line 660 of file btrfs_drv.h.

◆ VCB_TYPE_VOLUME

#define VCB_TYPE_VOLUME   3

Definition at line 659 of file btrfs_drv.h.

◆ WARN

#define WARN (   s,
  ... 
)

Definition at line 1180 of file btrfs_drv.h.

Typedef Documentation

◆ ccb

typedef struct _ccb ccb

◆ device_extension

◆ DUPLICATE_EXTENTS_DATA

◆ fcb

Definition at line 1301 of file btrfs_drv.h.

◆ fcb_nonpaged

◆ FILE_ID_128

◆ file_ref

◆ FSCTL_GET_INTEGRITY_INFORMATION_BUFFER

◆ FSCTL_SET_INTEGRITY_INFORMATION_BUFFER

◆ LDR_DATA_TABLE_ENTRY

◆ pdo_device_extension

◆ PDUPLICATE_EXTENTS_DATA

◆ PEB

typedef struct _PEB PEB

◆ PEB_LDR_DATA

◆ PFILE_ID_128

◆ PFSCTL_GET_INTEGRITY_INFORMATION_BUFFER

◆ PFSCTL_SET_INTEGRITY_INFORMATION_BUFFER

◆ PLDR_DATA_TABLE_ENTRY

◆ PPEB

typedef struct _PEB* PPEB

◆ PPEB_LDR_DATA

◆ PPS_POST_PROCESS_INIT_ROUTINE

typedef VOID(NTAPI * PPS_POST_PROCESS_INIT_ROUTINE) (VOID)

Definition at line 1809 of file btrfs_drv.h.

◆ PRTL_USER_PROCESS_PARAMETERS

◆ root

typedef struct _root root

◆ root_cache

◆ RTL_USER_PROCESS_PARAMETERS

◆ tCcCopyReadEx

Definition at line 1749 of file btrfs_drv.h.

◆ tCcCopyWriteEx

Definition at line 1746 of file btrfs_drv.h.

◆ tCcSetAdditionalCacheAttributesEx

typedef VOID(* tCcSetAdditionalCacheAttributesEx) (PFILE_OBJECT FileObject, ULONG Flags)

Definition at line 1761 of file btrfs_drv.h.

◆ tFsRtlGetEcpListFromIrp

typedef NTSTATUS(* tFsRtlGetEcpListFromIrp) (PIRP Irp, PECP_LIST *EcpList)

Definition at line 1767 of file btrfs_drv.h.

◆ tFsRtlGetNextExtraCreateParameter

Definition at line 1769 of file btrfs_drv.h.

◆ tFsRtlUpdateDiskCounters

typedef VOID(* tFsRtlUpdateDiskCounters) (ULONG64 BytesRead, ULONG64 BytesWritten)

Definition at line 1763 of file btrfs_drv.h.

◆ tFsRtlValidateReparsePointBuffer

typedef NTSTATUS(* tFsRtlValidateReparsePointBuffer) (ULONG BufferLength, PREPARSE_DATA_BUFFER ReparseBuffer)

Definition at line 1772 of file btrfs_drv.h.

◆ tIoUnregisterPlugPlayNotificationEx

typedef NTSTATUS(* tIoUnregisterPlugPlayNotificationEx) (PVOID NotificationEntry)

Definition at line 1765 of file btrfs_drv.h.

◆ tPsIsDiskCountersEnabled

typedef BOOLEAN(* tPsIsDiskCountersEnabled) ()

Definition at line 1741 of file btrfs_drv.h.

◆ tPsUpdateDiskCounters

typedef VOID(* tPsUpdateDiskCounters) (PEPROCESS Process, ULONG64 BytesRead, ULONG64 BytesWritten, ULONG ReadOperationCount, ULONG WriteOperationCount, ULONG FlushOperationCount)

Definition at line 1743 of file btrfs_drv.h.

◆ tree

typedef struct _tree tree

◆ tree_data

◆ volume_device_extension

◆ write_data_context

Enumeration Type Documentation

◆ batch_operation

Enumerator
Batch_Delete 
Batch_DeleteInode 
Batch_DeleteDirItem 
Batch_DeleteInodeRef 
Batch_DeleteInodeExtRef 
Batch_DeleteXattr 
Batch_DeleteExtentData 
Batch_DeleteFreeSpace 
Batch_Insert 
Batch_SetXattr 
Batch_DirItem 
Batch_InodeRef 
Batch_InodeExtRef 

Definition at line 464 of file btrfs_drv.h.

◆ prop_compression_type

Enumerator
PropCompression_None 
PropCompression_Zlib 
PropCompression_LZO 
PropCompression_ZSTD 

Definition at line 256 of file btrfs_drv.h.

◆ rollback_type

Enumerator
ROLLBACK_INSERT_EXTENT 
ROLLBACK_DELETE_EXTENT 
ROLLBACK_ADD_SPACE 
ROLLBACK_SUBTRACT_SPACE 

Definition at line 1210 of file btrfs_drv.h.

◆ write_data_status

Enumerator
WriteDataStatus_Pending 
WriteDataStatus_Success 
WriteDataStatus_Error 
WriteDataStatus_Cancelling 
WriteDataStatus_Cancelled 
WriteDataStatus_Ignore 

Definition at line 879 of file btrfs_drv.h.

Function Documentation

◆ _Create_lock_level_()

_Create_lock_level_ ( tree_lock  )

◆ _Dispatch_type_() [1/12]

_Dispatch_type_ ( IRP_MJ_WRITE  )

◆ _Dispatch_type_() [2/12]

_Dispatch_type_ ( IRP_MJ_DIRECTORY_CONTROL  )

◆ _Dispatch_type_() [3/12]

_Dispatch_type_ ( IRP_MJ_QUERY_SECURITY  )

◆ _Dispatch_type_() [4/12]

_Dispatch_type_ ( IRP_MJ_SET_SECURITY  )

◆ _Dispatch_type_() [5/12]

_Dispatch_type_ ( IRP_MJ_SET_INFORMATION  )

◆ _Dispatch_type_() [6/12]

_Dispatch_type_ ( IRP_MJ_QUERY_INFORMATION  )

◆ _Dispatch_type_() [7/12]

_Dispatch_type_ ( IRP_MJ_QUERY_EA  )

◆ _Dispatch_type_() [8/12]

_Dispatch_type_ ( IRP_MJ_SET_EA  )

◆ _Dispatch_type_() [9/12]

_Dispatch_type_ ( IRP_MJ_CREATE  )

◆ _Dispatch_type_() [10/12]

_Dispatch_type_ ( IRP_MJ_READ  )

◆ _Dispatch_type_() [11/12]

_Dispatch_type_ ( IRP_MJ_PNP  )

◆ _Dispatch_type_() [12/12]

_Dispatch_type_ ( IRP_MJ_DEVICE_CONTROL  )

◆ _Function_class_() [1/3]

_Function_class_ ( DRIVER_ADD_DEVICE  )

◆ _Function_class_() [2/3]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 3035 of file balance.c.

3036  {
3038  LIST_ENTRY chunks;
3039  LIST_ENTRY* le;
3040  uint64_t num_chunks[3], okay_metadata_chunks = 0, okay_data_chunks = 0, okay_system_chunks = 0;
3041  uint64_t old_data_flags = 0, old_metadata_flags = 0, old_system_flags = 0;
3042  NTSTATUS Status;
3043 
3044  Vcb->balance.balance_num++;
3045 
3046  Vcb->balance.stopping = false;
3047  KeInitializeEvent(&Vcb->balance.finished, NotificationEvent, false);
3048 
3049  if (Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_ENABLED && Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_CONVERT) {
3050  old_data_flags = Vcb->data_flags;
3051  Vcb->data_flags = BLOCK_FLAG_DATA | (Vcb->balance.opts[BALANCE_OPTS_DATA].convert == BLOCK_FLAG_SINGLE ? 0 : Vcb->balance.opts[BALANCE_OPTS_DATA].convert);
3052 
3054  }
3055 
3056  if (Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_ENABLED && Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_CONVERT) {
3057  old_metadata_flags = Vcb->metadata_flags;
3058  Vcb->metadata_flags = BLOCK_FLAG_METADATA | (Vcb->balance.opts[BALANCE_OPTS_METADATA].convert == BLOCK_FLAG_SINGLE ? 0 : Vcb->balance.opts[BALANCE_OPTS_METADATA].convert);
3059  }
3060 
3061  if (Vcb->balance.opts[BALANCE_OPTS_SYSTEM].flags & BTRFS_BALANCE_OPTS_ENABLED && Vcb->balance.opts[BALANCE_OPTS_SYSTEM].flags & BTRFS_BALANCE_OPTS_CONVERT) {
3062  old_system_flags = Vcb->system_flags;
3063  Vcb->system_flags = BLOCK_FLAG_SYSTEM | (Vcb->balance.opts[BALANCE_OPTS_SYSTEM].convert == BLOCK_FLAG_SINGLE ? 0 : Vcb->balance.opts[BALANCE_OPTS_SYSTEM].convert);
3064  }
3065 
3066  if (Vcb->superblock.incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS) {
3067  if (Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_ENABLED)
3068  RtlCopyMemory(&Vcb->balance.opts[BALANCE_OPTS_METADATA], &Vcb->balance.opts[BALANCE_OPTS_DATA], sizeof(btrfs_balance_opts));
3069  else if (Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_ENABLED)
3070  RtlCopyMemory(&Vcb->balance.opts[BALANCE_OPTS_DATA], &Vcb->balance.opts[BALANCE_OPTS_METADATA], sizeof(btrfs_balance_opts));
3071  }
3072 
3073  num_chunks[0] = num_chunks[1] = num_chunks[2] = 0;
3074  Vcb->balance.total_chunks = Vcb->balance.chunks_left = 0;
3075 
3076  InitializeListHead(&chunks);
3077 
3078  // FIXME - what are we supposed to do with limit_start?
3079 
3080  if (!Vcb->readonly) {
3081  if (!Vcb->balance.removing && !Vcb->balance.shrinking) {
3083  if (!NT_SUCCESS(Status)) {
3084  ERR("add_balance_item returned %08x\n", Status);
3085  Vcb->balance.status = Status;
3086  goto end;
3087  }
3088  } else {
3089  if (Vcb->need_write) {
3090  Status = do_write(Vcb, NULL);
3091 
3092  free_trees(Vcb);
3093 
3094  if (!NT_SUCCESS(Status)) {
3095  ERR("do_write returned %08x\n", Status);
3096  Vcb->balance.status = Status;
3097  goto end;
3098  }
3099  }
3100  }
3101  }
3102 
3103  KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, false, NULL);
3104 
3105  if (Vcb->balance.stopping)
3106  goto end;
3107 
3108  ExAcquireResourceSharedLite(&Vcb->chunk_lock, true);
3109 
3110  le = Vcb->chunks.Flink;
3111  while (le != &Vcb->chunks) {
3113  uint8_t sort;
3114 
3116 
3117  if (c->chunk_item->type & BLOCK_FLAG_DATA)
3119  else if (c->chunk_item->type & BLOCK_FLAG_METADATA)
3121  else if (c->chunk_item->type & BLOCK_FLAG_SYSTEM)
3123  else {
3124  ERR("unexpected chunk type %I64x\n", c->chunk_item->type);
3126  break;
3127  }
3128 
3129  if ((!(Vcb->balance.opts[sort].flags & BTRFS_BALANCE_OPTS_LIMIT) || num_chunks[sort] < Vcb->balance.opts[sort].limit_end) &&
3131  InsertTailList(&chunks, &c->list_entry_balance);
3132 
3133  num_chunks[sort]++;
3134  Vcb->balance.total_chunks++;
3135  Vcb->balance.chunks_left++;
3136  } else if (sort == BALANCE_OPTS_METADATA)
3137  okay_metadata_chunks++;
3138  else if (sort == BALANCE_OPTS_DATA)
3139  okay_data_chunks++;
3140  else if (sort == BALANCE_OPTS_SYSTEM)
3141  okay_system_chunks++;
3142 
3143  if (!c->cache_loaded) {
3145 
3146  if (!NT_SUCCESS(Status)) {
3147  ERR("load_cache_chunk returned %08x\n", Status);
3148  Vcb->balance.status = Status;
3150  ExReleaseResourceLite(&Vcb->chunk_lock);
3151  goto end;
3152  }
3153  }
3154 
3156 
3157  le = le->Flink;
3158  }
3159 
3160  ExReleaseResourceLite(&Vcb->chunk_lock);
3161 
3162  // If we're doing a full balance, try and allocate a new chunk now, before we mess things up
3163  if (okay_metadata_chunks == 0 || okay_data_chunks == 0 || okay_system_chunks == 0) {
3164  bool consolidated = false;
3165  chunk* c;
3166 
3167  if (okay_metadata_chunks == 0) {
3168  ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
3169 
3170  Status = alloc_chunk(Vcb, Vcb->metadata_flags, &c, true);
3171  if (NT_SUCCESS(Status))
3172  c->balance_num = Vcb->balance.balance_num;
3173  else if (Status != STATUS_DISK_FULL || consolidated) {
3174  ERR("alloc_chunk returned %08x\n", Status);
3175  ExReleaseResourceLite(&Vcb->chunk_lock);
3176  Vcb->balance.status = Status;
3177  goto end;
3178  }
3179 
3180  ExReleaseResourceLite(&Vcb->chunk_lock);
3181 
3182  if (Status == STATUS_DISK_FULL) {
3183  Status = try_consolidation(Vcb, Vcb->metadata_flags, &c);
3184  if (!NT_SUCCESS(Status)) {
3185  ERR("try_consolidation returned %08x\n", Status);
3186  Vcb->balance.status = Status;
3187  goto end;
3188  } else
3189  c->balance_num = Vcb->balance.balance_num;
3190 
3191  consolidated = true;
3192 
3193  if (Vcb->balance.stopping)
3194  goto end;
3195  }
3196  }
3197 
3198  if (okay_data_chunks == 0) {
3199  ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
3200 
3201  Status = alloc_chunk(Vcb, Vcb->data_flags, &c, true);
3202  if (NT_SUCCESS(Status))
3203  c->balance_num = Vcb->balance.balance_num;
3204  else if (Status != STATUS_DISK_FULL || consolidated) {
3205  ERR("alloc_chunk returned %08x\n", Status);
3206  ExReleaseResourceLite(&Vcb->chunk_lock);
3207  Vcb->balance.status = Status;
3208  goto end;
3209  }
3210 
3211  ExReleaseResourceLite(&Vcb->chunk_lock);
3212 
3213  if (Status == STATUS_DISK_FULL) {
3214  Status = try_consolidation(Vcb, Vcb->data_flags, &c);
3215  if (!NT_SUCCESS(Status)) {
3216  ERR("try_consolidation returned %08x\n", Status);
3217  Vcb->balance.status = Status;
3218  goto end;
3219  } else
3220  c->balance_num = Vcb->balance.balance_num;
3221 
3222  consolidated = true;
3223 
3224  if (Vcb->balance.stopping)
3225  goto end;
3226  }
3227  }
3228 
3229  if (okay_system_chunks == 0) {
3230  ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
3231 
3232  Status = alloc_chunk(Vcb, Vcb->system_flags, &c, true);
3233  if (NT_SUCCESS(Status))
3234  c->balance_num = Vcb->balance.balance_num;
3235  else if (Status != STATUS_DISK_FULL || consolidated) {
3236  ERR("alloc_chunk returned %08x\n", Status);
3237  ExReleaseResourceLite(&Vcb->chunk_lock);
3238  Vcb->balance.status = Status;
3239  goto end;
3240  }
3241 
3242  ExReleaseResourceLite(&Vcb->chunk_lock);
3243 
3244  if (Status == STATUS_DISK_FULL) {
3245  Status = try_consolidation(Vcb, Vcb->system_flags, &c);
3246  if (!NT_SUCCESS(Status)) {
3247  ERR("try_consolidation returned %08x\n", Status);
3248  Vcb->balance.status = Status;
3249  goto end;
3250  } else
3251  c->balance_num = Vcb->balance.balance_num;
3252 
3253  consolidated = true;
3254 
3255  if (Vcb->balance.stopping)
3256  goto end;
3257  }
3258  }
3259  }
3260 
3261  ExAcquireResourceSharedLite(&Vcb->chunk_lock, true);
3262 
3263  le = chunks.Flink;
3264  while (le != &chunks) {
3265  chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3266 
3267  c->reloc = true;
3268 
3269  le = le->Flink;
3270  }
3271 
3272  ExReleaseResourceLite(&Vcb->chunk_lock);
3273 
3274  // do data chunks before metadata
3275  le = chunks.Flink;
3276  while (le != &chunks) {
3277  chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3278  LIST_ENTRY* le2 = le->Flink;
3279 
3280  if (c->chunk_item->type & BLOCK_FLAG_DATA) {
3281  bool changed;
3282 
3283  do {
3284  changed = false;
3285 
3286  Status = balance_data_chunk(Vcb, c, &changed);
3287  if (!NT_SUCCESS(Status)) {
3288  ERR("balance_data_chunk returned %08x\n", Status);
3289  Vcb->balance.status = Status;
3290  goto end;
3291  }
3292 
3293  KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, false, NULL);
3294 
3295  if (Vcb->readonly)
3296  Vcb->balance.stopping = true;
3297 
3298  if (Vcb->balance.stopping)
3299  break;
3300  } while (changed);
3301 
3302  c->changed = true;
3303  c->space_changed = true;
3304  }
3305 
3306  if (Vcb->balance.stopping)
3307  goto end;
3308 
3309  if (c->chunk_item->type & BLOCK_FLAG_DATA &&
3310  (!(Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_ENABLED) || !(c->chunk_item->type & BLOCK_FLAG_METADATA))) {
3311  RemoveEntryList(&c->list_entry_balance);
3312  c->list_entry_balance.Flink = NULL;
3313 
3314  Vcb->balance.chunks_left--;
3315  }
3316 
3317  le = le2;
3318  }
3319 
3320  // do metadata chunks
3321  while (!IsListEmpty(&chunks)) {
3322  chunk* c;
3323  bool changed;
3324 
3325  le = RemoveHeadList(&chunks);
3326  c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3327 
3328  if (c->chunk_item->type & BLOCK_FLAG_METADATA || c->chunk_item->type & BLOCK_FLAG_SYSTEM) {
3329  do {
3330  Status = balance_metadata_chunk(Vcb, c, &changed);
3331  if (!NT_SUCCESS(Status)) {
3332  ERR("balance_metadata_chunk returned %08x\n", Status);
3333  Vcb->balance.status = Status;
3334  goto end;
3335  }
3336 
3337  KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, false, NULL);
3338 
3339  if (Vcb->readonly)
3340  Vcb->balance.stopping = true;
3341 
3342  if (Vcb->balance.stopping)
3343  break;
3344  } while (changed);
3345 
3346  c->changed = true;
3347  c->space_changed = true;
3348  }
3349 
3350  if (Vcb->balance.stopping)
3351  break;
3352 
3353  c->list_entry_balance.Flink = NULL;
3354 
3355  Vcb->balance.chunks_left--;
3356  }
3357 
3358 end:
3359  if (!Vcb->readonly) {
3360  if (Vcb->balance.stopping || !NT_SUCCESS(Vcb->balance.status)) {
3361  le = chunks.Flink;
3362  while (le != &chunks) {
3363  chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3364  c->reloc = false;
3365 
3366  le = le->Flink;
3367  c->list_entry_balance.Flink = NULL;
3368  }
3369 
3370  if (old_data_flags != 0)
3371  Vcb->data_flags = old_data_flags;
3372 
3373  if (old_metadata_flags != 0)
3374  Vcb->metadata_flags = old_metadata_flags;
3375 
3376  if (old_system_flags != 0)
3377  Vcb->system_flags = old_system_flags;
3378  }
3379 
3380  if (Vcb->balance.removing) {
3381  device* dev = NULL;
3382 
3383  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
3384 
3385  le = Vcb->devices.Flink;
3386  while (le != &Vcb->devices) {
3387  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3388 
3389  if (dev2->devitem.dev_id == Vcb->balance.opts[0].devid) {
3390  dev = dev2;
3391  break;
3392  }
3393 
3394  le = le->Flink;
3395  }
3396 
3397  if (dev) {
3398  if (Vcb->balance.chunks_left == 0) {
3400 
3401  if (!NT_SUCCESS(Status)) {
3402  ERR("finish_removing_device returned %08x\n", Status);
3403  dev->reloc = false;
3404  }
3405  } else
3406  dev->reloc = false;
3407  }
3408 
3409  ExReleaseResourceLite(&Vcb->tree_lock);
3410  } else if (Vcb->balance.shrinking) {
3411  device* dev = NULL;
3412 
3413  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
3414 
3415  le = Vcb->devices.Flink;
3416  while (le != &Vcb->devices) {
3417  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3418 
3419  if (dev2->devitem.dev_id == Vcb->balance.opts[0].devid) {
3420  dev = dev2;
3421  break;
3422  }
3423 
3424  le = le->Flink;
3425  }
3426 
3427  if (!dev) {
3428  ERR("could not find device %I64x\n", Vcb->balance.opts[0].devid);
3429  Vcb->balance.status = STATUS_INTERNAL_ERROR;
3430  }
3431 
3432  if (Vcb->balance.stopping || !NT_SUCCESS(Vcb->balance.status)) {
3433  if (dev) {
3435  if (!NT_SUCCESS(Status))
3436  WARN("regenerate_space_list returned %08x\n", Status);
3437  }
3438  } else {
3439  uint64_t old_size;
3440 
3441  old_size = dev->devitem.num_bytes;
3442  dev->devitem.num_bytes = Vcb->balance.opts[0].drange_start;
3443 
3445  if (!NT_SUCCESS(Status)) {
3446  ERR("update_dev_item returned %08x\n", Status);
3447  dev->devitem.num_bytes = old_size;
3448  Vcb->balance.status = Status;
3449 
3451  if (!NT_SUCCESS(Status))
3452  WARN("regenerate_space_list returned %08x\n", Status);
3453  } else {
3454  Vcb->superblock.total_bytes -= old_size - dev->devitem.num_bytes;
3455 
3456  Status = do_write(Vcb, NULL);
3457  if (!NT_SUCCESS(Status))
3458  ERR("do_write returned %08x\n", Status);
3459 
3460  free_trees(Vcb);
3461  }
3462  }
3463 
3464  ExReleaseResourceLite(&Vcb->tree_lock);
3465 
3466  if (!Vcb->balance.stopping && NT_SUCCESS(Vcb->balance.status))
3468  } else {
3470  if (!NT_SUCCESS(Status)) {
3471  ERR("remove_balance_item returned %08x\n", Status);
3472  goto end;
3473  }
3474  }
3475 
3476  if (Vcb->trim && !Vcb->options.no_trim) {
3477  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
3478 
3479  le = Vcb->devices.Flink;
3480  while (le != &Vcb->devices) {
3481  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3482 
3483  if (dev2->devobj && !dev2->readonly && dev2->trim)
3484  trim_unalloc_space(Vcb, dev2);
3485 
3486  le = le->Flink;
3487  }
3488 
3489  ExReleaseResourceLite(&Vcb->tree_lock);
3490  }
3491  }
3492 
3493  ZwClose(Vcb->balance.thread);
3494  Vcb->balance.thread = NULL;
3495 
3496  KeSetEvent(&Vcb->balance.finished, 0, false);
3497 }
static bool should_balance_chunk(device_extension *Vcb, uint8_t sort, chunk *c)
Definition: balance.c:2213
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define BALANCE_OPTS_SYSTEM
Definition: btrfs_drv.h:665
Definition: http.c:6587
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_STLP_MOVE_TO_STD_NAMESPACE void sort(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:993
NTSTATUS do_write(device_extension *Vcb, PIRP Irp)
Definition: flushthread.c:7652
PDEVICE_OBJECT devobj
Definition: btrfs_drv.h:512
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
release_chunk_lock(c, Vcb)
bool readonly
Definition: btrfs_drv.h:517
GLuint GLuint end
Definition: gl.h:1545
#define InsertTailList(ListHead, Entry)
static NTSTATUS balance_metadata_chunk(device_extension *Vcb, chunk *c, bool *changed)
Definition: balance.c:1098
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
#define BLOCK_FLAG_SINGLE
Definition: btrfsioctl.h:139
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 STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
static NTSTATUS try_consolidation(device_extension *Vcb, uint64_t flags, chunk **newchunk)
Definition: balance.c:2890
#define BTRFS_BALANCE_OPTS_CONVERT
Definition: btrfsioctl.h:136
Definition: devices.h:37
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:107
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:71
bool trim
Definition: btrfs_drv.h:519
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
void free_trees(device_extension *Vcb)
Definition: treefuncs.c:793
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define FSRTL_VOLUME_CHANGE_SIZE
Definition: fsrtltypes.h:101
static NTSTATUS add_balance_item(device_extension *Vcb)
Definition: balance.c:2366
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
static NTSTATUS regenerate_space_list(device_extension *Vcb, device *dev)
Definition: balance.c:2985
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define Vcb
Definition: cdprocs.h:1425
#define BTRFS_BALANCE_OPTS_LIMIT
Definition: btrfsioctl.h:133
const GLubyte * c
Definition: glext.h:8905
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
NTSTATUS update_dev_item(device_extension *Vcb, device *device, PIRP Irp)
Definition: flushthread.c:4052
#define BTRFS_BALANCE_OPTS_ENABLED
Definition: btrfsioctl.h:128
#define BLOCK_FLAG_METADATA
Definition: shellext.h:72
uint64_t dev_id
Definition: btrfs.h:161
Definition: typedefs.h:117
BYTE uint8_t
Definition: msvideo1.c:66
Status
Definition: gdiplustypes.h:24
NTSTATUS load_cache_chunk(device_extension *Vcb, chunk *c, PIRP Irp)
Definition: free-space.c:979
#define ERR(fmt,...)
Definition: debug.h:109
static NTSTATUS remove_balance_item(device_extension *Vcb)
Definition: balance.c:2439
static NTSTATUS balance_data_chunk(device_extension *Vcb, chunk *c, bool *changed)
Definition: balance.c:1666
UINT64 uint64_t
Definition: types.h:77
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define acquire_chunk_lock(c, Vcb)
Definition: btrfs_drv.h:1093
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:514
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define BLOCK_FLAG_DATA
Definition: shellext.h:70
static NTSTATUS finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, device *dev)
Definition: balance.c:2574
#define STATUS_DISK_FULL
Definition: udferr_usr.h:155
static void trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, device *dev)
Definition: balance.c:2790
#define c
Definition: ke_i.h:80
#define BALANCE_OPTS_METADATA
Definition: btrfs_drv.h:664
NTSTATUS alloc_chunk(device_extension *Vcb, uint64_t flags, chunk **pc, bool full_size)
Definition: write.c:361
#define BALANCE_OPTS_DATA
Definition: btrfs_drv.h:663

◆ _Function_class_() [3/3]

_Function_class_ ( DRIVER_NOTIFICATION_CALLBACK_ROUTINE  )

◆ _Post_satisfies_()

_Post_satisfies_ ( return >=  n)

◆ _Releases_lock_()

_Releases_lock_ ( c->  lock)

◆ _Requires_lock_held_() [1/2]

_Requires_lock_held_ ( Vcb->  fcb_lock) -> fcb_lock) static __inline void release_fcb_lock(device_extension* Vcb)

Definition at line 935 of file btrfs_drv.h.

937  {
938  ExReleaseResourceLite(&Vcb->fcb_lock);
939 }
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817

◆ _Requires_lock_held_() [2/2]

_Requires_lock_held_ ( c->  lock)
pure virtual

◆ _Requires_lock_not_held_()

_Requires_lock_not_held_ ( Vcb->  fcb_lock) -> fcb_lock) static __inline void acquire_fcb_lock_shared(device_extension* Vcb)

Definition at line 923 of file btrfs_drv.h.

925  {
926  ExAcquireResourceSharedLite(&Vcb->fcb_lock, true);
927 }
#define Vcb
Definition: cdprocs.h:1425
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885

◆ _Success_()

_Success_ ( return  )

◆ add_calc_job()

NTSTATUS add_calc_job ( device_extension Vcb,
uint8_t data,
uint32_t  sectors,
uint32_t csum,
calc_job **  pcj 
)

Definition at line 22 of file calcthread.c.

22  {
23  calc_job* cj;
24 
26  if (!cj) {
27  ERR("out of memory\n");
29  }
30 
31  cj->data = data;
32  cj->sectors = sectors;
33  cj->csum = csum;
34  cj->pos = 0;
35  cj->done = 0;
36  cj->refcount = 1;
37  KeInitializeEvent(&cj->event, NotificationEvent, false);
38 
39  ExAcquireResourceExclusiveLite(&Vcb->calcthreads.lock, true);
40 
41  InsertTailList(&Vcb->calcthreads.job_list, &cj->list_entry);
42 
43  KeSetEvent(&Vcb->calcthreads.event, 0, false);
44  KeClearEvent(&Vcb->calcthreads.event);
45 
46  ExReleaseResourceLite(&Vcb->calcthreads.lock);
47 
48  *pcj = cj;
49 
50  return STATUS_SUCCESS;
51 }
_In_ ULONG cj
Definition: winddi.h:3540
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG * pcj
Definition: winddi.h:3642
#define InsertTailList(ListHead, Entry)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define ALLOC_TAG
Definition: btrfs_drv.h:91
uint32_t * csum
Definition: write.c:2821
#define Vcb
Definition: cdprocs.h:1425
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
__u8 sectors[2]
Definition: mkdosfs.c:366
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by calc_csum(), and check_csum().

◆ add_changed_extent_ref()

void add_changed_extent_ref ( chunk c,
uint64_t  address,
uint64_t  size,
uint64_t  root,
uint64_t  objid,
uint64_t  offset,
uint32_t  count,
bool  no_csum 
)

Definition at line 2075 of file extent-tree.c.

2075  {
2076  changed_extent* ce;
2077  changed_extent_ref* cer;
2078  LIST_ENTRY* le;
2079 
2080  ce = get_changed_extent_item(c, address, size, no_csum);
2081 
2082  if (!ce) {
2083  ERR("get_changed_extent_item failed\n");
2084  return;
2085  }
2086 
2087  le = ce->refs.Flink;
2088  while (le != &ce->refs) {
2090 
2091  if (cer->type == TYPE_EXTENT_DATA_REF && cer->edr.root == root && cer->edr.objid == objid && cer->edr.offset == offset) {
2092  ce->count += count;
2093  cer->edr.count += count;
2094  return;
2095  }
2096 
2097  le = le->Flink;
2098  }
2099 
2101 
2102  if (!cer) {
2103  ERR("out of memory\n");
2104  return;
2105  }
2106 
2107  cer->type = TYPE_EXTENT_DATA_REF;
2108  cer->edr.root = root;
2109  cer->edr.objid = objid;
2110  cer->edr.offset = offset;
2111  cer->edr.count = count;
2112 
2113  InsertTailList(&ce->refs, &cer->list_entry);
2114 
2115  ce->count += count;
2116 }
uint64_t offset
Definition: btrfs.h:396
LIST_ENTRY list_entry
Definition: btrfs_drv.h:604
GLuint GLuint GLsizei count
Definition: gl.h:1545
struct _root root
uint64_t objid
Definition: btrfs.h:395
GLintptr offset
Definition: glext.h:5920
#define InsertTailList(ListHead, Entry)
#define ALLOC_TAG
Definition: btrfs_drv.h:91
EXTENT_DATA_REF edr
Definition: btrfs_drv.h:600
uint32_t count
Definition: btrfs.h:397
uint64_t count
Definition: btrfs_drv.h:587
uint64_t root
Definition: btrfs.h:394
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define TYPE_EXTENT_DATA_REF
Definition: btrfs.h:34
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
GLsizeiptr size
Definition: glext.h:5919
const GLubyte * c
Definition: glext.h:8905
GLuint address
Definition: glext.h:9393
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
LIST_ENTRY refs
Definition: btrfs_drv.h:591
static changed_extent * get_changed_extent_item(chunk *c, uint64_t address, uint64_t size, bool no_csum)
Definition: extent-tree.c:1915
Definition: list.h:27

Referenced by rationalize_extents().

◆ add_checksum_entry()

void add_checksum_entry ( device_extension Vcb,
uint64_t  address,
ULONG  length,
uint32_t csum,
PIRP  Irp 
)

Definition at line 2550 of file flushthread.c.

2550  {
2551  KEY searchkey;
2552  traverse_ptr tp, next_tp;
2553  NTSTATUS Status;
2554  uint64_t startaddr, endaddr;
2555  ULONG len;
2556  uint32_t* checksums;
2557  RTL_BITMAP bmp;
2558  ULONG* bmparr;
2559  ULONG runlength, index;
2560 
2561  TRACE("(%p, %I64x, %x, %p, %p)\n", Vcb, address, length, csum, Irp);
2562 
2563  searchkey.obj_id = EXTENT_CSUM_ID;
2564  searchkey.obj_type = TYPE_EXTENT_CSUM;
2565  searchkey.offset = address;
2566 
2567  // FIXME - create checksum_root if it doesn't exist at all
2568 
2569  Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, false, Irp);
2570  if (Status == STATUS_NOT_FOUND) { // tree is completely empty
2571  if (csum) { // not deleted
2572  ULONG length2 = length;
2573  uint64_t off = address;
2574  uint32_t* data = csum;
2575 
2576  do {
2577  uint16_t il = (uint16_t)min(length2, MAX_CSUM_SIZE / sizeof(uint32_t));
2578 
2579  checksums = ExAllocatePoolWithTag(PagedPool, il * sizeof(uint32_t), ALLOC_TAG);
2580  if (!checksums) {
2581  ERR("out of memory\n");
2582  return;
2583  }
2584 
2585  RtlCopyMemory(checksums, data, il * sizeof(uint32_t));
2586 
2587  Status = insert_tree_item(Vcb, Vcb->checksum_root, EXTENT_CSUM_ID, TYPE_EXTENT_CSUM, off, checksums,
2588  il * sizeof(uint32_t), NULL, Irp);
2589  if (!NT_SUCCESS(Status)) {
2590  ERR("insert_tree_item returned %08x\n", Status);
2591  ExFreePool(checksums);
2592  return;
2593  }
2594 
2595  length2 -= il;
2596 
2597  if (length2 > 0) {
2598  off += il * Vcb->superblock.sector_size;
2599  data += il;
2600  }
2601  } while (length2 > 0);
2602  }
2603  } else if (!NT_SUCCESS(Status)) {
2604  ERR("find_item returned %08x\n", Status);
2605  return;
2606  } else {
2607  uint32_t tplen;
2608 
2609  // FIXME - check entry is TYPE_EXTENT_CSUM?
2610 
2611  if (tp.item->key.offset < address && tp.item->key.offset + (tp.item->size * Vcb->superblock.sector_size / sizeof(uint32_t)) >= address)
2612  startaddr = tp.item->key.offset;
2613  else
2614  startaddr = address;
2615 
2616  searchkey.obj_id = EXTENT_CSUM_ID;
2617  searchkey.obj_type = TYPE_EXTENT_CSUM;
2618  searchkey.offset = address + (length * Vcb->superblock.sector_size);
2619 
2620  Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, false, Irp);
2621  if (!NT_SUCCESS(Status)) {
2622  ERR("find_item returned %08x\n", Status);
2623  return;
2624  }
2625 
2626  tplen = tp.item->size / sizeof(uint32_t);
2627 
2628  if (tp.item->key.offset + (tplen * Vcb->superblock.sector_size) >= address + (length * Vcb->superblock.sector_size))
2629  endaddr = tp.item->key.offset + (tplen * Vcb->superblock.sector_size);
2630  else
2631  endaddr = address + (length * Vcb->superblock.sector_size);
2632 
2633  TRACE("cs starts at %I64x (%x sectors)\n", address, length);
2634  TRACE("startaddr = %I64x\n", startaddr);
2635  TRACE("endaddr = %I64x\n", endaddr);
2636 
2637  len = (ULONG)((endaddr - startaddr) / Vcb->superblock.sector_size);
2638 
2639  checksums = ExAllocatePoolWithTag(PagedPool, sizeof(uint32_t) * len, ALLOC_TAG);
2640  if (!checksums) {
2641  ERR("out of memory\n");
2642  return;
2643  }
2644 
2645  bmparr = ExAllocatePoolWithTag(PagedPool, sizeof(ULONG) * ((len/8)+1), ALLOC_TAG);
2646  if (!bmparr) {
2647  ERR("out of memory\n");
2648  ExFreePool(checksums);
2649  return;
2650  }
2651 
2652  RtlInitializeBitMap(&bmp, bmparr, len);
2653  RtlSetAllBits(&bmp);
2654 
2655  searchkey.obj_id = EXTENT_CSUM_ID;
2656  searchkey.obj_type = TYPE_EXTENT_CSUM;
2657  searchkey.offset = address;
2658 
2659  Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, false, Irp);
2660  if (!NT_SUCCESS(Status)) {
2661  ERR("find_item returned %08x\n", Status);
2662  ExFreePool(checksums);
2663  ExFreePool(bmparr);
2664  return;
2665  }
2666 
2667  // set bit = free space, cleared bit = allocated sector
2668 
2669  while (tp.item->key.offset < endaddr) {
2670  if (tp.item->key.offset >= startaddr) {
2671  if (tp.item->size > 0) {
2672  ULONG itemlen = (ULONG)min((len - (tp.item->key.offset - startaddr) / Vcb->superblock.sector_size) * sizeof(uint32_t), tp.item->size);
2673 
2674  RtlCopyMemory(&checksums[(tp.item->key.offset - startaddr) / Vcb->superblock.sector_size], tp.item->data, itemlen);
2675  RtlClearBits(&bmp, (ULONG)((tp.item->key.offset - startaddr) / Vcb->superblock.sector_size), itemlen / sizeof(uint32_t));
2676  }
2677 
2679  if (!NT_SUCCESS(Status)) {
2680  ERR("delete_tree_item returned %08x\n", Status);
2681  ExFreePool(checksums);
2682  ExFreePool(bmparr);
2683  return;
2684  }
2685  }
2686 
2687  if (find_next_item(Vcb, &tp, &next_tp, false, Irp)) {
2688  tp = next_tp;
2689  } else
2690  break;
2691  }
2692 
2693  if (!csum) { // deleted
2694  RtlSetBits(&bmp, (ULONG)((address - startaddr) / Vcb->superblock.sector_size), length);
2695  } else {
2696  RtlCopyMemory(&checksums[(address - startaddr) / Vcb->superblock.sector_size], csum, length * sizeof(uint32_t));
2697  RtlClearBits(&bmp, (ULONG)((address - startaddr) / Vcb->superblock.sector_size), length);
2698  }
2699 
2700  runlength = RtlFindFirstRunClear(&bmp, &index);
2701 
2702  while (runlength != 0) {
2703  if (index >= len)
2704  break;
2705 
2706  if (index + runlength >= len) {
2707  runlength = len - index;
2708 
2709  if (runlength == 0)
2710  break;
2711  }
2712 
2713  do {
2714  uint16_t rl;
2715  uint64_t off;
2716  uint32_t* data;
2717 
2718  if (runlength * sizeof(uint32_t) > MAX_CSUM_SIZE)
2719  rl = MAX_CSUM_SIZE / sizeof(uint32_t);
2720  else
2721  rl = (uint16_t)runlength;
2722 
2724  if (!data) {
2725  ERR("out of memory\n");
2726  ExFreePool(bmparr);
2727  ExFreePool(checksums);
2728  return;
2729  }
2730 
2731  RtlCopyMemory(data, &checksums[index], sizeof(uint32_t) * rl);
2732 
2733  off = startaddr + UInt32x32To64(index, Vcb->superblock.sector_size);
2734 
2735  Status = insert_tree_item(Vcb, Vcb->checksum_root, EXTENT_CSUM_ID, TYPE_EXTENT_CSUM, off, data, sizeof(uint32_t) * rl, NULL, Irp);
2736  if (!NT_SUCCESS(Status)) {
2737  ERR("insert_tree_item returned %08x\n", Status);
2738  ExFreePool(data);
2739  ExFreePool(bmparr);
2740  ExFreePool(checksums);
2741  return;
2742  }
2743 
2744  runlength -= rl;
2745  index += rl;
2746  } while (runlength > 0);
2747 
2748  runlength = RtlFindNextForwardRunClear(&bmp, index, &index);
2749  }
2750 
2751  ExFreePool(bmparr);
2752  ExFreePool(checksums);
2753  }
2754 }
uint64_t obj_id
Definition: btrfs.h:127
NTSYSAPI void WINAPI RtlClearBits(PRTL_BITMAP, ULONG, ULONG)
#define MAX_CSUM_SIZE
Definition: flushthread.c:23
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
uint8_t obj_type
Definition: btrfs.h:128
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
uint16_t size
Definition: btrfs_drv.h:409
unsigned short int uint16_t
Definition: acefiex.h:54
#define uint16_t
Definition: nsiface.idl:60
uint64_t offset
Definition: btrfs.h:129
uint8_t * data
Definition: btrfs_drv.h:410
#define TYPE_EXTENT_CSUM
Definition: btrfs.h:27
#define ALLOC_TAG
Definition: btrfs_drv.h:91
NTSYSAPI ULONG WINAPI RtlFindNextForwardRunClear(PCRTL_BITMAP, ULONG, PULONG)
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2883
uint32_t * csum
Definition: write.c:2821
static LONG find_item(PropertyBag *This, LPCOLESTR name)
Definition: propertybag.c:110
#define STATUS_NOT_FOUND
Definition: shellext.h:67
#define TRACE(s)
Definition: solgame.cpp:4
bool find_next_item(_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, const traverse_ptr *tp, traverse_ptr *next_tp, bool ignore, PIRP Irp)
Definition: treefuncs.c:592
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define Vcb
Definition: cdprocs.h:1425
GLuint address
Definition: glext.h:9393
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
BITMAP bmp
Definition: alphablend.c:62
NTSTATUS insert_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ uint64_t obj_id, _In_ uint8_t obj_type, _In_ uint64_t offset, _In_reads_bytes_opt_(size) _When_(return >=0, __drv_aliasesMem) void *data, _In_ uint16_t size, _Out_opt_ traverse_ptr *ptp, _In_opt_ PIRP Irp)
Definition: treefuncs.c:857
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
tree_data * item
Definition: btrfs_drv.h:496
#define index(s, c)
Definition: various.h:29
GLenum GLsizei len
Definition: glext.h:6722
static void startaddr(void)
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
Definition: btrfs.h:126
#define EXTENT_CSUM_ID
Definition: btrfs.h:84
UINT64 uint64_t
Definition: types.h:77
NTSYSAPI ULONG NTAPI RtlFindFirstRunClear(_In_ PRTL_BITMAP BitMapHeader, _Out_ PULONG StartingIndex)
#define min(a, b)
Definition: monoChain.cc:55
UINT32 uint32_t
Definition: types.h:75
Definition: fs.h:216
NTSYSAPI void WINAPI RtlSetAllBits(PRTL_BITMAP)
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI void WINAPI RtlSetBits(PRTL_BITMAP, ULONG, ULONG)
#define uint32_t
Definition: nsiface.idl:61
#define UInt32x32To64(a, b)
Definition: intsafe.h:258
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS delete_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _Inout_ traverse_ptr *tp)
Definition: treefuncs.c:989
off
Definition: i386-dis.c:3909

Referenced by balance_data_chunk(), decrease_extent_refcount(), flush_fcb(), and rationalize_extents().

◆ add_dir_child()

NTSTATUS add_dir_child ( fcb fcb,
uint64_t  inode,
bool  subvol,
PANSI_STRING  utf8,
PUNICODE_STRING  name,
uint8_t  type,
dir_child **  pdc 
)

Definition at line 1757 of file create.c.

1757  {
1758  NTSTATUS Status;
1759  dir_child* dc;
1760  bool locked;
1761 
1763  if (!dc) {
1764  ERR("out of memory\n");
1766  }
1767 
1768  dc->utf8.Buffer = ExAllocatePoolWithTag(PagedPool, utf8->Length, ALLOC_TAG);
1769  if (!dc->utf8.Buffer) {
1770  ERR("out of memory\n");
1771  ExFreePool(dc);
1773  }
1774 
1775  dc->name.Buffer = ExAllocatePoolWithTag(PagedPool, name->Length, ALLOC_TAG);
1776  if (!dc->name.Buffer) {
1777  ERR("out of memory\n");
1778  ExFreePool(dc->utf8.Buffer);
1779  ExFreePool(dc);
1781  }
1782 
1783  dc->key.obj_id = inode;
1784  dc->key.obj_type = subvol ? TYPE_ROOT_ITEM : TYPE_INODE_ITEM;
1785  dc->key.offset = subvol ? 0xffffffffffffffff : 0;
1786  dc->type = type;
1787  dc->fileref = NULL;
1788 
1789  dc->utf8.Length = dc->utf8.MaximumLength = utf8->Length;
1790  RtlCopyMemory(dc->utf8.Buffer, utf8->Buffer, utf8->Length);
1791 
1792  dc->name.Length = dc->name.MaximumLength = name->Length;
1793  RtlCopyMemory(dc->name.Buffer, name->Buffer, name->Length);
1794 
1795  Status = RtlUpcaseUnicodeString(&dc->name_uc, name, true);
1796  if (!NT_SUCCESS(Status)) {
1797  ERR("RtlUpcaseUnicodeString returned %08x\n", Status);
1798  ExFreePool(dc->utf8.Buffer);
1799  ExFreePool(dc->name.Buffer);
1800  ExFreePool(dc);
1801  return Status;
1802  }
1803 
1804  dc->hash = calc_crc32c(0xffffffff, (uint8_t*)dc->name.Buffer, dc->name.Length);
1805  dc->hash_uc = calc_crc32c(0xffffffff, (uint8_t*)dc->name_uc.Buffer, dc->name_uc.Length);
1806 
1807  locked = ExIsResourceAcquiredExclusive(&fcb->nonpaged->dir_children_lock);
1808 
1809  if (!locked)
1810  ExAcquireResourceExclusiveLite(&fcb->nonpaged->dir_children_lock, true);
1811 
1813  dc->index = 2;
1814  else {
1815  dir_child* dc2 = CONTAINING_RECORD(fcb->dir_children_index.Blink, dir_child, list_entry_index);
1816 
1817  dc->index = max(2, dc2->index + 1);
1818  }
1819 
1820  InsertTailList(&fcb->dir_children_index, &dc->list_entry_index);
1821 
1823 
1824  if (!locked)
1825  ExReleaseResourceLite(&fcb->nonpaged->dir_children_lock);
1826 
1827  *pdc = dc;
1828 
1829  return STATUS_SUCCESS;
1830 }
#define max(a, b)
Definition: svc.c:63
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS RtlUpcaseUnicodeString(PUNICODE_STRING dst, PUNICODE_STRING src, BOOLEAN Alloc)
Definition: string_lib.cpp:46
Iosb Status
Definition: create.c:4311
struct _LIST_ENTRY * Blink
Definition: typedefs.h:120
LONG NTSTATUS
Definition: precomp.h:26
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
HDC dc
Definition: cylfrac.c:34
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
static uint32_t calc_crc32c(uint32_t seed, uint8_t *msg, ULONG msglen)
Definition: recv.cpp:134
Definition: fs.h:78
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define ALLOC_TAG
Definition: btrfs_drv.h:91
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 dir_children_index
Definition: btrfs_drv.h:303
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
uint64_t index
Definition: btrfs_drv.h:242
#define TYPE_INODE_ITEM
Definition: btrfs.h:19
BYTE uint8_t
Definition: msvideo1.c:66
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:273
#define TYPE_ROOT_ITEM
Definition: btrfs.h:28
void insert_dir_child_into_hash_lists(fcb *fcb, dir_child *dc)
Definition: fileinfo.c:1413
Definition: name.c:36
#define ExIsResourceAcquiredExclusive
Definition: exfuncs.h:347
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by create_subvol(), do_create_snapshot(), file_create2(), mknod(), and set_link_information().

◆ add_extent()

void add_extent ( _In_ fcb fcb,
_In_ LIST_ENTRY prevextle,
_In_ __drv_aliasesMem extent newext 
)

Definition at line 2351 of file write.c.

2351  {
2352  LIST_ENTRY* le = prevextle->Flink;
2353 
2354  while (le != &fcb->extents) {
2356 
2357  if (ext->offset >= newext->offset) {
2358  InsertHeadList(ext->list_entry.Blink, &newext->list_entry);
2359  return;
2360  }
2361 
2362  le = le->Flink;
2363  }
2364 
2365  InsertTailList(&fcb->extents, &newext->list_entry);
2366 }
FORCEINLINE VOID InsertHeadList(_Inout_ PLIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PLIST_ENTRY Entry)
Definition: rtlfuncs.h:201
#define InsertTailList(ListHead, Entry)
char ext[3]
Definition: mkdosfs.c:358
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
LIST_ENTRY extents
Definition: btrfs_drv.h:290
Definition: typedefs.h:117
Definition: list.h:27

Referenced by do_write_file_prealloc(), duplicate_extents(), and excise_extents().

◆ add_extent_to_fcb()

NTSTATUS add_extent_to_fcb ( _In_ fcb fcb,
_In_ uint64_t  offset,
_In_reads_bytes_(edsize) EXTENT_DATA ed,
_In_ uint16_t  edsize,
_In_ bool  unique,
_In_opt_ _When_(return >=0, __drv_aliasesMem) uint32_t csum,
_In_ LIST_ENTRY rollback 
)

Definition at line 2720 of file write.c.

2721  {
2722  extent* ext;
2723  LIST_ENTRY* le;
2724 
2726  if (!ext) {
2727  ERR("out of memory\n");
2729  }
2730 
2731  ext->offset = offset;
2732  ext->datalen = edsize;
2733  ext->unique = unique;
2734  ext->ignore = false;
2735  ext->inserted = true;
2736  ext->csum = csum;
2737 
2738  RtlCopyMemory(&ext->extent_data, ed, edsize);
2739 
2740  le = fcb->extents.Flink;
2741  while (le != &fcb->extents) {
2742  extent* oldext = CONTAINING_RECORD(le, extent, list_entry);
2743 
2744  if (oldext->offset >= offset) {
2745  InsertHeadList(le->Blink, &ext->list_entry);
2746  goto end;
2747  }
2748 
2749  le = le->Flink;
2750  }
2751 
2752  InsertTailList(&fcb->extents, &ext->list_entry);
2753 
2754 end:
2756 
2757  return STATUS_SUCCESS;
2758 }
void add_insert_extent_rollback(LIST_ENTRY *rollback, fcb *fcb, extent *ext)
Definition: write.c:2701
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
GLintptr offset
Definition: glext.h:5920
GLuint GLuint end
Definition: gl.h:1545
#define InsertTailList(ListHead, Entry)
#define ALLOC_TAG
Definition: btrfs_drv.h:91
uint64_t offset
Definition: btrfs_drv.h:218
#define offsetof(TYPE, MEMBER)
char ext[3]
Definition: mkdosfs.c:358
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
uint32_t * csum
Definition: write.c:2821
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: write.c:2814
LIST_ENTRY extents
Definition: btrfs_drv.h:290
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
uint16_t edsize
Definition: write.c:2820
#define ERR(fmt,...)
Definition: debug.h:109
ed2 offset
Definition: write.c:2845
Definition: list.h:27
_ForwardIter unique(_ForwardIter __first, _ForwardIter __last)
Definition: _algo.h:298
return STATUS_SUCCESS
Definition: btrfs.c:2966
EXTENT_DATA * ed
Definition: write.c:2818

Referenced by duplicate_extents(), extend_file(), truncate_file(), write_file2(), and zero_data().

◆ add_group_mapping()

void add_group_mapping ( WCHAR sidstring,
ULONG  sidstringlength,
uint32_t  gid 
)

Definition at line 145 of file security.c.

145  {
146  unsigned int i, np;
147  uint8_t numdashes;
148  uint64_t val;
149  ULONG sidsize;
150  sid_header* sid;
151  gid_map* gm;
152 
153  if (sidstringlength < 4 || sidstring[0] != 'S' || sidstring[1] != '-' || sidstring[2] != '1' || sidstring[3] != '-') {
154  ERR("invalid SID\n");
155  return;
156  }
157 
158  sidstring = &sidstring[4];
159  sidstringlength -= 4;
160 
161  numdashes = 0;
162  for (i = 0; i < sidstringlength; i++) {
163  if (sidstring[i] == '-') {
164  numdashes++;
165  sidstring[i] = 0;
166  }
167  }
168 
169  sidsize = 8 + (numdashes * 4);
171  if (!sid) {
172  ERR("out of memory\n");
173  return;
174  }
175 
176  sid->revision = 0x01;
177  sid->elements = numdashes;
178 
179  np = 0;
180  while (sidstringlength > 0) {
181  val = 0;
182  i = 0;
183  while (sidstring[i] != '-' && i < sidstringlength) {
184  if (sidstring[i] >= '0' && sidstring[i] <= '9') {
185  val *= 10;
186  val += sidstring[i] - '0';
187  } else
188  break;
189 
190  i++;
191  }
192 
193  i++;
194  TRACE("val = %u, i = %u, ssl = %u\n", (uint32_t)val, i, sidstringlength);
195 
196  if (np == 0) {
197  sid->auth[0] = (uint8_t)((val & 0xff0000000000) >> 40);
198  sid->auth[1] = (uint8_t)((val & 0xff00000000) >> 32);
199  sid->auth[2] = (uint8_t)((val & 0xff000000) >> 24);
200  sid->auth[3] = (uint8_t)((val & 0xff0000) >> 16);
201  sid->auth[4] = (uint8_t)((val & 0xff00) >> 8);
202  sid->auth[5] = val & 0xff;
203  } else
204  sid->nums[np-1] = (uint32_t)val;
205 
206  np++;
207 
208  if (sidstringlength > i) {
209  sidstringlength -= i;
210 
211  sidstring = &sidstring[i];
212  } else
213  break;
214  }
215 
217  if (!gm) {
218  ERR("out of memory\n");
219  ExFreePool(sid);
220  return;
221  }
222 
223  gm->sid = sid;
224  gm->gid = gid;
225 
227 }
FT_UInt sid
Definition: cffcmap.c:139
#define InsertTailList(ListHead, Entry)
PSID sid
Definition: btrfs_drv.h:875
#define ALLOC_TAG
Definition: btrfs_drv.h:91
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLuint GLfloat * val
Definition: glext.h:7180
#define TRACE(s)
Definition: solgame.cpp:4
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
LIST_ENTRY listentry
Definition: btrfs_drv.h:874
BYTE uint8_t
Definition: msvideo1.c:66
#define ERR(fmt,...)
Definition: debug.h:109
uint32_t gid
Definition: btrfs_drv.h:876
UINT64 uint64_t
Definition: types.h:77
#define uint8_t
Definition: nsiface.idl:59
LIST_ENTRY gid_map_list
Definition: btrfs.c:72
UINT32 uint32_t
Definition: types.h:75
unsigned int ULONG
Definition: retypes.h:1
#define uint32_t
Definition: nsiface.idl:61
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by read_group_mappings().

◆ add_insert_extent_rollback()

void add_insert_extent_rollback ( LIST_ENTRY rollback,
fcb fcb,
extent ext 
)

Definition at line 2701 of file write.c.

2701  {
2702  rollback_extent* re;
2703 
2705  if (!re) {
2706  ERR("out of memory\n");
2707  return;
2708  }
2709 
2710  re->fcb = fcb;
2711  re->ext = ext;
2712 
2714 }
#define ALLOC_TAG
Definition: btrfs_drv.h:91
char ext[3]
Definition: mkdosfs.c:358
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: write.c:2814
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
extent * ext
Definition: btrfs_drv.h:1207
_In_ fcb * fcb
Definition: write.c:2814
void add_rollback(_In_ LIST_ENTRY *rollback, _In_ enum rollback_type type, _In_ __drv_aliasesMem void *ptr)
Definition: treefuncs.c:836

Referenced by add_extent_to_fcb(), and do_write_file_prealloc().

◆ add_rollback()

void add_rollback ( _In_ LIST_ENTRY rollback,
_In_ enum rollback_type  type,
_In_ __drv_aliasesMem void ptr 
)

Definition at line 836 of file treefuncs.c.

836  {
837  rollback_item* ri;
838 
840  if (!ri) {
841  ERR("out of memory\n");
842  return;
843  }
844 
845  ri->type = type;
846  ri->ptr = ptr;
848 }
enum rollback_type type
Definition: btrfs_drv.h:1218
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define InsertTailList(ListHead, Entry)
#define ALLOC_TAG
Definition: btrfs_drv.h:91
static PVOID ptr
Definition: dispmode.c:27
LIST_ENTRY list_entry
Definition: btrfs_drv.h:1220
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1301

Referenced by add_insert_extent_rollback(), add_rollback_space(), and remove_fcb_extent().

◆ add_space_entry()

NTSTATUS add_space_entry ( LIST_ENTRY list,
LIST_ENTRY list_size,
uint64_t  offset,
uint64_t  size 
)

Definition at line 189 of file free-space.c.

189  {
190  space* s;
191 
193 
194  if (!s) {
195  ERR("out of memory\n");
197  }
198 
199  s->address = offset;
200  s->size = size;
201 
202  if (IsListEmpty(list))
203  InsertTailList(list, &s->list_entry);
204  else {
206 
207  if (s2->address < offset)
208  InsertTailList(list, &s->list_entry);
209  else {
210  LIST_ENTRY* le;
211 
212  le = list->Flink;
213  while (le != list) {
215 
216  if (s2->address > offset) {
217  InsertTailList(le, &s->list_entry);
218  goto size;
219  }
220 
221  le = le->Flink;
222  }
223  }
224  }
225 
226 size:
227  if (!list_size)
228  return STATUS_SUCCESS;
229 
230  if (IsListEmpty(list_size))
231  InsertTailList(list_size, &s->list_entry_size);
232  else {
233  space* s2 = CONTAINING_RECORD(list_size->Blink, space, list_entry_size);
234 
235  if (s2->size >= size)
236  InsertTailList(list_size, &s->list_entry_size);
237  else {
238  LIST_ENTRY* le;
239 
240  le = list_size->Flink;
241  while (le != list_size) {
242  s2 = CONTAINING_RECORD(le, space, list_entry_size);
243 
244  if (s2->size <= size) {
245  InsertHeadList(le->Blink, &s->list_entry_size);
246  return STATUS_SUCCESS;
247  }
248 
249  le = le->Flink;
250  }
251  }
252  }
253 
254  return STATUS_SUCCESS;
255 }
struct S2 s2
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
GLintptr offset
Definition: glext.h:5920
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define ALLOC_TAG
Definition: btrfs_drv.h:91
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
GLsizeiptr size
Definition: glext.h:5919
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
GLdouble s
Definition: gl.h:2039
Definition: _list.h:228
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
Definition: list.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by add_device(), find_disk_holes(), load_free_space_bitmap(), load_stored_free_space_cache(), and load_stored_free_space_tree().

◆ add_thread_job()

bool add_thread_job ( device_extension Vcb,
PIRP  Irp 
)

Definition at line 109 of file worker-thread.c.

109  {
110  job_info* ji;
111 
113  if (!ji) {
114  ERR("out of memory\n");
115  return false;
116  }
117 
118  ji->Vcb = Vcb;
119  ji->Irp = Irp;
120 
121  if (!Irp->MdlAddress) {
122  PMDL Mdl;
124  ULONG len;
126 
127  if (IrpSp->MajorFunction == IRP_MJ_READ) {
128  op = IoWriteAccess;
129  len = IrpSp->Parameters.Read.Length;
130  } else if (IrpSp->MajorFunction == IRP_MJ_WRITE) {
131  op = IoReadAccess;
132  len = IrpSp->Parameters.Write.Length;
133  } else {
134  ERR("unexpected major function %u\n", IrpSp->MajorFunction);
135  ExFreePool(ji);
136  return false;
137  }
138 
139  Mdl = IoAllocateMdl(Irp->UserBuffer, len, false, false, Irp);
140 
141  if (!Mdl) {
142  ERR("out of memory\n");
143  ExFreePool(ji);
144  return false;
145  }
146 
147  _SEH2_TRY {
148  MmProbeAndLockPages(Mdl, Irp->RequestorMode, op);
150  ERR("MmProbeAndLockPages raised status %08x\n", _SEH2_GetExceptionCode());
151 
152  IoFreeMdl(Mdl);
153  Irp->MdlAddress = NULL;
154  ExFreePool(ji);
155 
156  _SEH2_YIELD(return FALSE);
157  } _SEH2_END;
158  }
159 
160  ExInitializeWorkItem(&ji->item, do_job, ji);
162 
163  return true;
164 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
_In_ PIRP Irp
Definition: csq.h:116