ReactOS  0.4.13-dev-235-g7373cb3
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 <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  _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  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_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_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 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)((minor) & ~0xFF)) << 12) | (((UINT64)((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)((rdev) >> 32) & ~0xFFF))
 
#define minor(rdev)   (((rdev) & 0xFF) | ((UINT32)((rdev) >> 12) & ~0xFF))
 
#define CC_ENABLE_DISK_IO_ACCOUNTING   0x00000010
 

Typedefs

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 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 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 off, _In_ UINT64 stripe_length, _In_ UINT16 num_stripes, _Out_ UINT64 *stripeoff, _Out_ UINT16 *stripe)
 
static __inline UINT64 make_file_id (root *r, UINT64 inode)
 
 _Post_satisfies_ (return >=n) __inline static UINT64 sector_align(_In_ UINT64 n
 
static __inline BOOL is_subvol_readonly (root *r, PIRP Irp)
 
static __inline UINT16 get_extent_data_len (UINT8 type)
 
static __inline UINT32 get_extent_data_refcount (UINT8 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 inode, _In_ UINT8 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 id, _Out_ root **rootptr, _In_ BOOL no_tree, _In_ UINT64 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_ BOOLEAN 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_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
 
void chunk_lock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ UINT64 start, _In_ UINT64 length)
 
void chunk_unlock_range (_In_ device_extension *Vcb, _In_ chunk *c, _In_ UINT64 start, _In_ UINT64 length)
 
void 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_ UINT64 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)
 
NTSTATUS AddDevice (PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT PhysicalDeviceObject)
 
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)
 
void init_fast_io_dispatch (FAST_IO_DISPATCH **fiod)
 
UINT32 calc_crc32c (_In_ UINT32 seed, _In_reads_bytes_(msglen) UINT8 *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 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 obj_id, _In_ UINT8 obj_type, _In_ UINT64 offset, _In_reads_bytes_opt_(size) _When_(return >=0, __drv_aliasesMem) void *data, _In_ UINT16 size, _Out_opt_ traverse_ptr *ptp, _In_opt_ PIRP Irp)
 
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 addr, UINT8 *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 mountmgr_thread(_In_ void *context)
 
 _Function_class_ (DRIVER_NOTIFICATION_CALLBACK_ROUTINE) NTSTATUS 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, BOOLEAN wait, BOOLEAN deferred_write)
 
NTSTATUS write_file2 (device_extension *Vcb, PIRP Irp, LARGE_INTEGER offset, void *buf, ULONG *length, BOOLEAN paging_io, BOOLEAN no_cache, BOOLEAN wait, BOOLEAN deferred_write, BOOLEAN write_irp, LIST_ENTRY *rollback)
 
NTSTATUS truncate_file (fcb *fcb, UINT64 end, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS extend_file (fcb *fcb, file_ref *fileref, UINT64 end, BOOL prealloc, PIRP Irp, LIST_ENTRY *rollback)
 
NTSTATUS excise_extents (device_extension *Vcb, fcb *fcb, UINT64 start_data, UINT64 end_data, PIRP Irp, LIST_ENTRY *rollback)
 
chunkget_chunk_from_address (device_extension *Vcb, UINT64 address)
 
NTSTATUS alloc_chunk (device_extension *Vcb, UINT64 flags, chunk **pc, BOOL full_size)
 
NTSTATUS write_data (_In_ device_extension *Vcb, _In_ UINT64 address, _In_reads_bytes_(length) void *data, _In_ UINT32 length, _In_ write_data_context *wtc, _In_opt_ PIRP Irp, _In_opt_ chunk *c, _In_ BOOL file_write, _In_ UINT64 irp_offset, _In_ ULONG priority)
 
NTSTATUS write_data_complete (device_extension *Vcb, UINT64 address, void *data, UINT32 length, PIRP Irp, chunk *c, BOOL file_write, UINT64 irp_offset, ULONG priority)
 
void free_write_data_stripes (write_data_context *wtc)
 
 _Dispatch_type_ (IRP_MJ_WRITE) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI 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 start_data, UINT64 end_data, void *data, PIRP Irp, BOOL file_write, UINT32 irp_offset, LIST_ENTRY *rollback)
 
NTSTATUS write_compressed (fcb *fcb, UINT64 start_data, UINT64 end_data, void *data, PIRP Irp, LIST_ENTRY *rollback)
 
BOOL find_data_address_in_chunk (device_extension *Vcb, chunk *c, UINT64 length, UINT64 *address)
 
void get_raid56_lock_range (chunk *c, UINT64 address, UINT64 length, UINT64 *lockaddr, UINT64 *locklen)
 
NTSTATUS calc_csum (_In_ device_extension *Vcb, _In_reads_bytes_(sectors *Vcb->superblock.sector_size) UINT8 *data, _In_ UINT32 sectors, _Out_writes_bytes_(sectors *sizeof(UINT32)) UINT32 *csum)
 
void add_insert_extent_rollback (LIST_ENTRY *rollback, fcb *fcb, extent *ext)
 
NTSTATUS add_extent_to_fcb (_In_ fcb *fcb, _In_ UINT64 offset, _In_reads_bytes_(edsize) EXTENT_DATA *ed, _In_ UINT16 edsize, _In_ BOOL unique, _In_opt_ _When_(return >=0, __drv_aliasesMem) UINT32 *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 NTAPI drv_directory_control(IN PDEVICE_OBJECT DeviceObject
 
ULONG get_reparse_tag (device_extension *Vcb, root *subvol, UINT64 inode, UINT8 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 NTAPI drv_query_security(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_SET_SECURITY) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI 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 uid)
 
void add_group_mapping (WCHAR *sidstring, ULONG sidstringlength, UINT32 gid)
 
UINT32 sid_to_uid (PSID sid)
 
NTSTATUS uid_to_sid (UINT32 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 NTAPI drv_set_information(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_QUERY_INFORMATION) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI drv_query_information(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_QUERY_EA) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI drv_query_ea(IN PDEVICE_OBJECT DeviceObject
 
 _Dispatch_type_ (IRP_MJ_SET_EA) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI 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 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 NTAPI 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 inode, UINT8 type, PANSI_STRING utf8, fcb *parent, fcb **pfcb, POOL_TYPE pooltype, PIRP Irp)
 
NTSTATUS load_csum (_Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, UINT32 *csum, UINT64 start, UINT64 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 inode, BOOL subvol, PANSI_STRING utf8, PUNICODE_STRING name, UINT8 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 *inode, dir_child **pdc, BOOL case_sensitive)
 
UINT32 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 inode, file_ref **pfr, PIRP Irp)
 
NTSTATUS fsctl_request (PDEVICE_OBJECT DeviceObject, PIRP *Pirp, UINT32 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_ UINT64 address, _In_reads_bytes_(length) void *data, _In_ UINT32 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 address, ULONG length, UINT32 *csum, PIRP Irp)
 
BOOL find_metadata_address_in_chunk (device_extension *Vcb, chunk *c, UINT64 *address)
 
void add_trim_entry_avoid_sb (device_extension *Vcb, device *dev, UINT64 address, UINT64 size)
 
NTSTATUS insert_tree_item_batch (LIST_ENTRY *batchlist, device_extension *Vcb, root *r, UINT64 objid, UINT8 objtype, UINT64 offset, _In_opt_ _When_(return >=0, __drv_aliasesMem) void *data, UINT16 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 NTAPI drv_read(PDEVICE_OBJECT DeviceObject
 
NTSTATUS read_data (_In_ device_extension *Vcb, _In_ UINT64 addr, _In_ UINT32 length, _In_reads_bytes_opt_(length *sizeof(UINT32)/Vcb->superblock.sector_size) UINT32 *csum, _In_ BOOL is_tree, _Out_writes_bytes_(length) UINT8 *buf, _In_opt_ chunk *c, _Out_opt_ chunk **pc, _In_opt_ PIRP Irp, _In_ UINT64 generation, _In_ BOOL file_read, _In_ ULONG priority)
 
NTSTATUS read_file (fcb *fcb, UINT8 *data, UINT64 start, UINT64 length, ULONG *pbr, PIRP Irp)
 
NTSTATUS read_stream (fcb *fcb, UINT8 *data, UINT64 start, ULONG length, ULONG *pbr)
 
NTSTATUS do_read (PIRP Irp, BOOLEAN wait, ULONG *bytes_read)
 
NTSTATUS check_csum (device_extension *Vcb, UINT8 *data, UINT32 sectors, UINT32 *csum)
 
void raid6_recover2 (UINT8 *sectors, UINT16 num_stripes, ULONG sector_size, UINT16 missing1, UINT16 missing2, UINT8 *out)
 
 _Dispatch_type_ (IRP_MJ_PNP) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI 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 offset, UINT64 size)
 
void space_list_add (chunk *c, UINT64 address, UINT64 length, LIST_ENTRY *rollback)
 
void space_list_add2 (LIST_ENTRY *list, LIST_ENTRY *list_size, UINT64 address, UINT64 length, chunk *c, LIST_ENTRY *rollback)
 
void space_list_subtract (chunk *c, BOOL deleting, UINT64 address, UINT64 length, LIST_ENTRY *rollback)
 
void space_list_subtract2 (LIST_ENTRY *list, LIST_ENTRY *list_size, UINT64 address, UINT64 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 address, UINT64 size, UINT64 root, UINT64 inode, UINT64 offset, UINT32 refcount, PIRP Irp)
 
NTSTATUS decrease_extent_refcount_data (device_extension *Vcb, UINT64 address, UINT64 size, UINT64 root, UINT64 inode, UINT64 offset, UINT32 refcount, BOOL superseded, PIRP Irp)
 
NTSTATUS decrease_extent_refcount_tree (device_extension *Vcb, UINT64 address, UINT64 size, UINT64 root, UINT8 level, PIRP Irp)
 
UINT64 get_extent_refcount (device_extension *Vcb, UINT64 address, UINT64 size, PIRP Irp)
 
BOOL is_extent_unique (device_extension *Vcb, UINT64 address, UINT64 size, PIRP Irp)
 
NTSTATUS increase_extent_refcount (device_extension *Vcb, UINT64 address, UINT64 size, UINT8 type, void *data, KEY *firstitem, UINT8 level, PIRP Irp)
 
UINT64 get_extent_flags (device_extension *Vcb, UINT64 address, PIRP Irp)
 
void update_extent_flags (device_extension *Vcb, UINT64 address, UINT64 flags, PIRP Irp)
 
NTSTATUS update_changed_extent_ref (device_extension *Vcb, chunk *c, UINT64 address, UINT64 size, UINT64 root, UINT64 objid, UINT64 offset, INT32 count, BOOL no_csum, BOOL superseded, PIRP Irp)
 
void add_changed_extent_ref (chunk *c, UINT64 address, UINT64 size, UINT64 root, UINT64 objid, UINT64 offset, UINT32 count, BOOL no_csum)
 
UINT64 find_extent_shared_tree_refcount (device_extension *Vcb, UINT64 address, UINT64 parent, PIRP Irp)
 
UINT32 find_extent_shared_data_refcount (device_extension *Vcb, UINT64 address, UINT64 parent, PIRP Irp)
 
NTSTATUS decrease_extent_refcount (device_extension *Vcb, UINT64 address, UINT64 size, UINT8 type, void *data, KEY *firstitem, UINT8 level, UINT64 parent, BOOL superseded, PIRP Irp)
 
UINT64 get_extent_data_ref_hash2 (UINT64 root, UINT64 objid, UINT64 offset)
 
void do_read_job (PIRP Irp)
 
void 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 *inbuf, UINT32 inlen, UINT8 *outbuf, UINT32 outlen)
 
NTSTATUS lzo_decompress (UINT8 *inbuf, UINT32 inlen, UINT8 *outbuf, UINT32 outlen, UINT32 inpageoff)
 
NTSTATUS zstd_decompress (UINT8 *inbuf, UINT32 inlen, UINT8 *outbuf, UINT32 outlen)
 
NTSTATUS write_compressed_bit (fcb *fcb, UINT64 start_data, UINT64 end_data, void *data, BOOL *compressed, PIRP Irp, LIST_ENTRY *rollback)
 
void galois_double (UINT8 *data, UINT32 len)
 
void galois_divpower (UINT8 *data, UINT8 div, UINT32 readlen)
 
UINT8 gpow2 (UINT8 e)
 
UINT8 gmul (UINT8 a, UINT8 b)
 
UINT8 gdiv (UINT8 a, UINT8 b)
 
 _Dispatch_type_ (IRP_MJ_DEVICE_CONTROL) _Function_class_(DRIVER_DISPATCH) NTSTATUS NTAPI drv_device_control(IN PDEVICE_OBJECT DeviceObject
 
NTSTATUS add_calc_job (device_extension *Vcb, UINT8 *data, UINT32 sectors, UINT32 *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)
 
NTSTATUS vol_power (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
void add_volume_device (superblock *sb, PDEVICE_OBJECT mountmgr, PUNICODE_STRING devpath, UINT64 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)
 
static __inline void print_open_trees (device_extension *Vcb)
 
static __inline BOOL write_fcb_compressed (fcb *fcb)
 
static __inline void do_xor (UINT8 *buf1, UINT8 *buf2, UINT32 len)
 
static __inline UINT64 fcb_alloc_size (fcb *fcb)
 
BOOLEAN RtlIsNtDdiVersionAvailable (ULONG Version)
 
PEPROCESS PsGetThreadProcess (_In_ PETHREAD Thread)
 

Variables

_In_ UINT64 a
 
return n
 
_In_ UINT16 len
 
_In_ UINT16 _Out_ ULONGatts
 
BOOL have_sse2
 
UINT32 mount_compress
 
UINT32 mount_compress_force
 
UINT32 mount_compress_type
 
UINT32 mount_zlib_level
 
UINT32 mount_zstd_level
 
UINT32 mount_flush_interval
 
UINT32 mount_max_inline
 
UINT32 mount_skip_balance
 
UINT32 mount_no_barrier
 
UINT32 mount_no_trim
 
UINT32 mount_clear_cache
 
UINT32 mount_allow_degraded
 
UINT32 mount_readonly
 
UINT32 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 start_data
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 length
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL prealloc
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ voiddata
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRYrollback
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ UINT8 compression = compression
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ UINT8 _In_ UINT64 decoded_size = decoded_size
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ UINT8 _In_ UINT64 _In_ BOOL file_write
 
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY _In_ UINT8 _In_ UINT64 _In_ BOOL _In_ UINT64 irp_offset
 

Macro Definition Documentation

◆ __drv_aliasesMem

#define __drv_aliasesMem

Definition at line 167 of file btrfs_drv.h.

◆ __S_IFBLK

#define __S_IFBLK   0060000 /* Block device. */

Definition at line 1707 of file btrfs_drv.h.

◆ __S_IFCHR

#define __S_IFCHR   0020000 /* Character device. */

Definition at line 1706 of file btrfs_drv.h.

◆ __S_IFDIR

#define __S_IFDIR   0040000 /* Directory. */

Definition at line 1705 of file btrfs_drv.h.

◆ __S_IFIFO

#define __S_IFIFO   0010000 /* FIFO. */

Definition at line 1709 of file btrfs_drv.h.

◆ __S_IFLNK

#define __S_IFLNK   0120000 /* Symbolic link. */

Definition at line 1710 of file btrfs_drv.h.

◆ __S_IFMT

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

Definition at line 1704 of file btrfs_drv.h.

◆ __S_IFREG

#define __S_IFREG   0100000 /* Regular file. */

Definition at line 1708 of file btrfs_drv.h.

◆ __S_IFSOCK

#define __S_IFSOCK   0140000 /* Socket. */

Definition at line 1711 of file btrfs_drv.h.

◆ __S_ISTYPE

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

Definition at line 1712 of file btrfs_drv.h.

◆ _Acquires_exclusive_lock_

#define _Acquires_exclusive_lock_ (   a)

Definition at line 180 of file btrfs_drv.h.

◆ _Acquires_shared_lock_

#define _Acquires_shared_lock_ (   a)

Definition at line 181 of file btrfs_drv.h.

◆ _Create_lock_level_

#define _Create_lock_level_ (   a)

Definition at line 176 of file btrfs_drv.h.

◆ _CRT_SECURE_NO_WARNINGS

#define _CRT_SECURE_NO_WARNINGS

Definition at line 27 of file btrfs_drv.h.

◆ _Dispatch_type_

#define _Dispatch_type_ (   a)

Definition at line 175 of file btrfs_drv.h.

◆ _Has_lock_level_

#define _Has_lock_level_ (   a)

Definition at line 178 of file btrfs_drv.h.

◆ _Lock_level_order_

#define _Lock_level_order_ (   a,
  b 
)

Definition at line 177 of file btrfs_drv.h.

◆ _NO_CRT_STDIO_INLINE

#define _NO_CRT_STDIO_INLINE

Definition at line 28 of file btrfs_drv.h.

◆ _Out_writes_bytes_opt_

#define _Out_writes_bytes_opt_ (   a)

Definition at line 171 of file btrfs_drv.h.

◆ _Post_satisfies_

#define _Post_satisfies_ (   a)

Definition at line 173 of file btrfs_drv.h.

◆ _Pre_satisfies_

#define _Pre_satisfies_ (   a)

Definition at line 172 of file btrfs_drv.h.

◆ _Releases_exclusive_lock_

#define _Releases_exclusive_lock_ (   a)

Definition at line 174 of file btrfs_drv.h.

◆ _Releases_lock_

#define _Releases_lock_ (   a)

Definition at line 170 of file btrfs_drv.h.

◆ _Requires_exclusive_lock_held_

#define _Requires_exclusive_lock_held_ (   a)

Definition at line 169 of file btrfs_drv.h.

◆ _Requires_lock_held_

#define _Requires_lock_held_ (   a)

Definition at line 168 of file btrfs_drv.h.

◆ _Requires_lock_not_held_

#define _Requires_lock_not_held_ (   a)

Definition at line 179 of file btrfs_drv.h.

◆ _WIN32_WINNT

#define _WIN32_WINNT   0x0601

Definition at line 25 of file btrfs_drv.h.

◆ acquire_chunk_lock

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

Definition at line 1117 of file btrfs_drv.h.

◆ ALLOC_TAG

#define ALLOC_TAG   0x7442484D

Definition at line 86 of file btrfs_drv.h.

◆ ALLOC_TAG_ZLIB

#define ALLOC_TAG_ZLIB   0x7A42484D

Definition at line 87 of file btrfs_drv.h.

◆ BALANCE_OPTS_DATA

#define BALANCE_OPTS_DATA   0

Definition at line 661 of file btrfs_drv.h.

◆ BALANCE_OPTS_METADATA

#define BALANCE_OPTS_METADATA   1

Definition at line 662 of file btrfs_drv.h.

◆ BALANCE_OPTS_SYSTEM

#define BALANCE_OPTS_SYSTEM   2

Definition at line 663 of file btrfs_drv.h.

◆ BTRFS_NODE_TYPE_CCB

#define BTRFS_NODE_TYPE_CCB   0x2295

Definition at line 83 of file btrfs_drv.h.

◆ BTRFS_NODE_TYPE_FCB

#define BTRFS_NODE_TYPE_FCB   0x2296

Definition at line 84 of file btrfs_drv.h.

◆ BTRFS_VOLUME_PREFIX

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

Definition at line 119 of file btrfs_drv.h.

◆ CC_ENABLE_DISK_IO_ACCOUNTING

#define CC_ENABLE_DISK_IO_ACCOUNTING   0x00000010

Definition at line 1796 of file btrfs_drv.h.

◆ COMPRESSED_EXTENT_SIZE

#define COMPRESSED_EXTENT_SIZE   0x20000

Definition at line 108 of file btrfs_drv.h.

◆ EA_DOSATTRIB

#define EA_DOSATTRIB   "user.DOSATTRIB"

Definition at line 95 of file btrfs_drv.h.

◆ EA_DOSATTRIB_HASH

#define EA_DOSATTRIB_HASH   0x914f9939

Definition at line 96 of file btrfs_drv.h.

◆ EA_EA

#define EA_EA   "user.EA"

Definition at line 101 of file btrfs_drv.h.

◆ EA_EA_HASH

#define EA_EA_HASH   0x8270dd43

Definition at line 102 of file btrfs_drv.h.

◆ EA_NTACL

#define EA_NTACL   "security.NTACL"

Definition at line 92 of file btrfs_drv.h.

◆ EA_NTACL_HASH

#define EA_NTACL_HASH   0x45922146

Definition at line 93 of file btrfs_drv.h.

◆ EA_PROP_COMPRESSION

#define EA_PROP_COMPRESSION   "btrfs.compression"

Definition at line 104 of file btrfs_drv.h.

◆ EA_PROP_COMPRESSION_HASH

#define EA_PROP_COMPRESSION_HASH   0x20ccdf69

Definition at line 105 of file btrfs_drv.h.

◆ EA_REPARSE

#define EA_REPARSE   "user.reparse"

Definition at line 98 of file btrfs_drv.h.

◆ EA_REPARSE_HASH

#define EA_REPARSE_HASH   0xfabad1fe

Definition at line 99 of file btrfs_drv.h.

◆ ERR

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

Definition at line 1203 of file btrfs_drv.h.

◆ except

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

Definition at line 127 of file btrfs_drv.h.

◆ fast_io_possible

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

Definition at line 1618 of file btrfs_drv.h.

◆ FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL

#define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL   0x00020000

Definition at line 136 of file btrfs_drv.h.

◆ FILE_SUPPORTS_BLOCK_REFCOUNTING

#define FILE_SUPPORTS_BLOCK_REFCOUNTING   0x08000000

Definition at line 132 of file btrfs_drv.h.

◆ finally

#define finally   if (1)

Definition at line 128 of file btrfs_drv.h.

◆ FIXME

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

Definition at line 1202 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 146 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 162 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 163 of file btrfs_drv.h.

◆ funcname

#define funcname   __func__

Definition at line 1149 of file btrfs_drv.h.

◆ GID_NOBODY

#define GID_NOBODY   65534

Definition at line 90 of file btrfs_drv.h.

◆ hex_digit

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

Definition at line 1699 of file btrfs_drv.h.

◆ increase_fileref_refcount

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

Definition at line 1690 of file btrfs_drv.h.

◆ int3

#define int3   asm("int3;")

Definition at line 1696 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_BLOCKDEV

#define IO_REPARSE_TAG_LXSS_BLOCKDEV   0x80000026

Definition at line 117 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_CHARDEV

#define IO_REPARSE_TAG_LXSS_CHARDEV   0x80000025

Definition at line 116 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_FIFO

#define IO_REPARSE_TAG_LXSS_FIFO   0x80000024

Definition at line 115 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_SOCKET

#define IO_REPARSE_TAG_LXSS_SOCKET   0x80000023

Definition at line 114 of file btrfs_drv.h.

◆ IO_REPARSE_TAG_LXSS_SYMLINK

#define IO_REPARSE_TAG_LXSS_SYMLINK   0xa000001d

Definition at line 112 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 1004 of file btrfs_drv.h.

◆ major

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

Definition at line 1772 of file btrfs_drv.h.

◆ makedev

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

Definition at line 1616 of file btrfs_drv.h.

◆ MAX_EXTENT_SIZE

#define MAX_EXTENT_SIZE   0x8000000

Definition at line 107 of file btrfs_drv.h.

◆ minor

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

Definition at line 1773 of file btrfs_drv.h.

◆ NTDDI_VERSION

#define NTDDI_VERSION   0x06020000

Definition at line 26 of file btrfs_drv.h.

◆ READ_AHEAD_GRANULARITY

#define READ_AHEAD_GRANULARITY   COMPRESSED_EXTENT_SIZE

Definition at line 110 of file btrfs_drv.h.

◆ release_chunk_lock

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

Definition at line 1118 of file btrfs_drv.h.

◆ S_IRGRP

#define S_IRGRP   (S_IRUSR >> 3)

Definition at line 1736 of file btrfs_drv.h.

◆ S_IROTH

#define S_IROTH   (S_IRGRP >> 3)

Definition at line 1748 of file btrfs_drv.h.

◆ S_IRUSR

#define S_IRUSR   0000400

Definition at line 1719 of file btrfs_drv.h.

◆ S_ISDIR

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

Definition at line 1715 of file btrfs_drv.h.

◆ S_ISGID

#define S_ISGID   0002000

Definition at line 1764 of file btrfs_drv.h.

◆ S_ISUID

#define S_ISUID   0004000

Definition at line 1760 of file btrfs_drv.h.

◆ S_ISVTX

#define S_ISVTX   0001000

Definition at line 1768 of file btrfs_drv.h.

◆ S_IWGRP

#define S_IWGRP   (S_IWUSR >> 3)

Definition at line 1740 of file btrfs_drv.h.

◆ S_IWOTH

#define S_IWOTH   (S_IWGRP >> 3)

Definition at line 1752 of file btrfs_drv.h.

◆ S_IWUSR

#define S_IWUSR   0000200

Definition at line 1723 of file btrfs_drv.h.

◆ S_IXGRP

#define S_IXGRP   (S_IXUSR >> 3)

Definition at line 1744 of file btrfs_drv.h.

◆ S_IXOTH

#define S_IXOTH   (S_IXGRP >> 3)

Definition at line 1756 of file btrfs_drv.h.

◆ S_IXUSR

#define S_IXUSR   0000100

Definition at line 1727 of file btrfs_drv.h.

◆ TRACE

#define TRACE (   s,
  ... 
)

Definition at line 1200 of file btrfs_drv.h.

◆ try

#define try   if (1)

Definition at line 126 of file btrfs_drv.h.

◆ UID_NOBODY

#define UID_NOBODY   65534

Definition at line 89 of file btrfs_drv.h.

◆ UNUSED

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

Definition at line 81 of file btrfs_drv.h.

◆ VCB_TYPE_CONTROL

#define VCB_TYPE_CONTROL   2

Definition at line 635 of file btrfs_drv.h.

◆ VCB_TYPE_FS

#define VCB_TYPE_FS   1

Definition at line 634 of file btrfs_drv.h.

◆ VCB_TYPE_PDO

#define VCB_TYPE_PDO   4

Definition at line 637 of file btrfs_drv.h.

◆ VCB_TYPE_VOLUME

#define VCB_TYPE_VOLUME   3

Definition at line 636 of file btrfs_drv.h.

◆ WARN

#define WARN (   s,
  ... 
)

Definition at line 1201 of file btrfs_drv.h.

Typedef Documentation

◆ ccb

typedef struct _ccb ccb

◆ device_extension

◆ DUPLICATE_EXTENTS_DATA

◆ fcb

Definition at line 1334 of file btrfs_drv.h.

◆ fcb_nonpaged

◆ 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

◆ 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 1843 of file btrfs_drv.h.

◆ PRTL_USER_PROCESS_PARAMETERS

◆ root

typedef struct _root root

◆ root_cache

◆ RTL_USER_PROCESS_PARAMETERS

◆ tCcCopyReadEx

Definition at line 1792 of file btrfs_drv.h.

◆ tCcCopyWriteEx

Definition at line 1789 of file btrfs_drv.h.

◆ tCcSetAdditionalCacheAttributesEx

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

Definition at line 1799 of file btrfs_drv.h.

◆ tFsRtlUpdateDiskCounters

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

Definition at line 1801 of file btrfs_drv.h.

◆ tPsIsDiskCountersEnabled

typedef BOOLEAN(* tPsIsDiskCountersEnabled) ()

Definition at line 1784 of file btrfs_drv.h.

◆ tPsUpdateDiskCounters

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

Definition at line 1786 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 443 of file btrfs_drv.h.

◆ prop_compression_type

Enumerator
PropCompression_None 
PropCompression_Zlib 
PropCompression_LZO 
PropCompression_ZSTD 

Definition at line 240 of file btrfs_drv.h.

◆ rollback_type

Enumerator
ROLLBACK_INSERT_EXTENT 
ROLLBACK_DELETE_EXTENT 
ROLLBACK_ADD_SPACE 
ROLLBACK_SUBTRACT_SPACE 

Definition at line 1231 of file btrfs_drv.h.

◆ write_data_status

Enumerator
WriteDataStatus_Pending 
WriteDataStatus_Success 
WriteDataStatus_Error 
WriteDataStatus_Cancelling 
WriteDataStatus_Cancelled 
WriteDataStatus_Ignore 

Definition at line 875 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/2]

_Function_class_ ( KSTART_ROUTINE  )

Definition at line 3025 of file balance.c.

3027  {
3028 #else
3029 void NTAPI balance_thread(void* context) {
3030 #endif
3032  LIST_ENTRY chunks;
3033  LIST_ENTRY* le;
3034  UINT64 num_chunks[3], okay_metadata_chunks = 0, okay_data_chunks = 0, okay_system_chunks = 0;
3035  UINT64 old_data_flags = 0, old_metadata_flags = 0, old_system_flags = 0;
3036  NTSTATUS Status;
3037 
3038  Vcb->balance.balance_num++;
3039 
3040  Vcb->balance.stopping = FALSE;
3041  KeInitializeEvent(&Vcb->balance.finished, NotificationEvent, FALSE);
3042 
3043  if (Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_ENABLED && Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_CONVERT) {
3044  old_data_flags = Vcb->data_flags;
3045  Vcb->data_flags = BLOCK_FLAG_DATA | (Vcb->balance.opts[BALANCE_OPTS_DATA].convert == BLOCK_FLAG_SINGLE ? 0 : Vcb->balance.opts[BALANCE_OPTS_DATA].convert);
3046 
3048  }
3049 
3050  if (Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_ENABLED && Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_CONVERT) {
3051  old_metadata_flags = Vcb->metadata_flags;
3052  Vcb->metadata_flags = BLOCK_FLAG_METADATA | (Vcb->balance.opts[BALANCE_OPTS_METADATA].convert == BLOCK_FLAG_SINGLE ? 0 : Vcb->balance.opts[BALANCE_OPTS_METADATA].convert);
3053  }
3054 
3055  if (Vcb->balance.opts[BALANCE_OPTS_SYSTEM].flags & BTRFS_BALANCE_OPTS_ENABLED && Vcb->balance.opts[BALANCE_OPTS_SYSTEM].flags & BTRFS_BALANCE_OPTS_CONVERT) {
3056  old_system_flags = Vcb->system_flags;
3057  Vcb->system_flags = BLOCK_FLAG_SYSTEM | (Vcb->balance.opts[BALANCE_OPTS_SYSTEM].convert == BLOCK_FLAG_SINGLE ? 0 : Vcb->balance.opts[BALANCE_OPTS_SYSTEM].convert);
3058  }
3059 
3060  if (Vcb->superblock.incompat_flags & BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS) {
3061  if (Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_ENABLED)
3062  RtlCopyMemory(&Vcb->balance.opts[BALANCE_OPTS_METADATA], &Vcb->balance.opts[BALANCE_OPTS_DATA], sizeof(btrfs_balance_opts));
3063  else if (Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_ENABLED)
3064  RtlCopyMemory(&Vcb->balance.opts[BALANCE_OPTS_DATA], &Vcb->balance.opts[BALANCE_OPTS_METADATA], sizeof(btrfs_balance_opts));
3065  }
3066 
3067  num_chunks[0] = num_chunks[1] = num_chunks[2] = 0;
3068  Vcb->balance.total_chunks = Vcb->balance.chunks_left = 0;
3069 
3070  InitializeListHead(&chunks);
3071 
3072  // FIXME - what are we supposed to do with limit_start?
3073 
3074  if (!Vcb->readonly) {
3075  if (!Vcb->balance.removing && !Vcb->balance.shrinking) {
3077  if (!NT_SUCCESS(Status)) {
3078  ERR("add_balance_item returned %08x\n", Status);
3079  Vcb->balance.status = Status;
3080  goto end;
3081  }
3082  } else {
3083  if (Vcb->need_write) {
3084  Status = do_write(Vcb, NULL);
3085 
3086  free_trees(Vcb);
3087 
3088  if (!NT_SUCCESS(Status)) {
3089  ERR("do_write returned %08x\n", Status);
3090  Vcb->balance.status = Status;
3091  goto end;
3092  }
3093  }
3094  }
3095  }
3096 
3097  KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, FALSE, NULL);
3098 
3099  if (Vcb->balance.stopping)
3100  goto end;
3101 
3102  ExAcquireResourceSharedLite(&Vcb->chunk_lock, TRUE);
3103 
3104  le = Vcb->chunks.Flink;
3105  while (le != &Vcb->chunks) {
3107  UINT8 sort;
3108 
3110 
3111  if (c->chunk_item->type & BLOCK_FLAG_DATA)
3113  else if (c->chunk_item->type & BLOCK_FLAG_METADATA)
3115  else if (c->chunk_item->type & BLOCK_FLAG_SYSTEM)
3117  else {
3118  ERR("unexpected chunk type %llx\n", c->chunk_item->type);
3120  break;
3121  }
3122 
3123  if ((!(Vcb->balance.opts[sort].flags & BTRFS_BALANCE_OPTS_LIMIT) || num_chunks[sort] < Vcb->balance.opts[sort].limit_end) &&
3125  InsertTailList(&chunks, &c->list_entry_balance);
3126 
3127  num_chunks[sort]++;
3128  Vcb->balance.total_chunks++;
3129  Vcb->balance.chunks_left++;
3130  } else if (sort == BALANCE_OPTS_METADATA)
3131  okay_metadata_chunks++;
3132  else if (sort == BALANCE_OPTS_DATA)
3133  okay_data_chunks++;
3134  else if (sort == BALANCE_OPTS_SYSTEM)
3135  okay_system_chunks++;
3136 
3137  if (!c->cache_loaded) {
3139 
3140  if (!NT_SUCCESS(Status)) {
3141  ERR("load_cache_chunk returned %08x\n", Status);
3142  Vcb->balance.status = Status;
3144  ExReleaseResourceLite(&Vcb->chunk_lock);
3145  goto end;
3146  }
3147  }
3148 
3150 
3151  le = le->Flink;
3152  }
3153 
3154  ExReleaseResourceLite(&Vcb->chunk_lock);
3155 
3156  // If we're doing a full balance, try and allocate a new chunk now, before we mess things up
3157  if (okay_metadata_chunks == 0 || okay_data_chunks == 0 || okay_system_chunks == 0) {
3158  BOOL consolidated = FALSE;
3159  chunk* c;
3160 
3161  if (okay_metadata_chunks == 0) {
3162  ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
3163 
3164  Status = alloc_chunk(Vcb, Vcb->metadata_flags, &c, TRUE);
3165  if (NT_SUCCESS(Status))
3166  c->balance_num = Vcb->balance.balance_num;
3167  else if (Status != STATUS_DISK_FULL || consolidated) {
3168  ERR("alloc_chunk returned %08x\n", Status);
3169  ExReleaseResourceLite(&Vcb->chunk_lock);
3170  Vcb->balance.status = Status;
3171  goto end;
3172  }
3173 
3174  ExReleaseResourceLite(&Vcb->chunk_lock);
3175 
3176  if (Status == STATUS_DISK_FULL) {
3177  Status = try_consolidation(Vcb, Vcb->metadata_flags, &c);
3178  if (!NT_SUCCESS(Status)) {
3179  ERR("try_consolidation returned %08x\n", Status);
3180  Vcb->balance.status = Status;
3181  goto end;
3182  } else
3183  c->balance_num = Vcb->balance.balance_num;
3184 
3185  consolidated = TRUE;
3186 
3187  if (Vcb->balance.stopping)
3188  goto end;
3189  }
3190  }
3191 
3192  if (okay_data_chunks == 0) {
3193  ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
3194 
3195  Status = alloc_chunk(Vcb, Vcb->data_flags, &c, TRUE);
3196  if (NT_SUCCESS(Status))
3197  c->balance_num = Vcb->balance.balance_num;
3198  else if (Status != STATUS_DISK_FULL || consolidated) {
3199  ERR("alloc_chunk returned %08x\n", Status);
3200  ExReleaseResourceLite(&Vcb->chunk_lock);
3201  Vcb->balance.status = Status;
3202  goto end;
3203  }
3204 
3205  ExReleaseResourceLite(&Vcb->chunk_lock);
3206 
3207  if (Status == STATUS_DISK_FULL) {
3208  Status = try_consolidation(Vcb, Vcb->data_flags, &c);
3209  if (!NT_SUCCESS(Status)) {
3210  ERR("try_consolidation returned %08x\n", Status);
3211  Vcb->balance.status = Status;
3212  goto end;
3213  } else
3214  c->balance_num = Vcb->balance.balance_num;
3215 
3216  consolidated = TRUE;
3217 
3218  if (Vcb->balance.stopping)
3219  goto end;
3220  }
3221  }
3222 
3223  if (okay_system_chunks == 0) {
3224  ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
3225 
3226  Status = alloc_chunk(Vcb, Vcb->system_flags, &c, TRUE);
3227  if (NT_SUCCESS(Status))
3228  c->balance_num = Vcb->balance.balance_num;
3229  else if (Status != STATUS_DISK_FULL || consolidated) {
3230  ERR("alloc_chunk returned %08x\n", Status);
3231  ExReleaseResourceLite(&Vcb->chunk_lock);
3232  Vcb->balance.status = Status;
3233  goto end;
3234  }
3235 
3236  ExReleaseResourceLite(&Vcb->chunk_lock);
3237 
3238  if (Status == STATUS_DISK_FULL) {
3239  Status = try_consolidation(Vcb, Vcb->system_flags, &c);
3240  if (!NT_SUCCESS(Status)) {
3241  ERR("try_consolidation returned %08x\n", Status);
3242  Vcb->balance.status = Status;
3243  goto end;
3244  } else
3245  c->balance_num = Vcb->balance.balance_num;
3246 
3247  consolidated = TRUE;
3248 
3249  if (Vcb->balance.stopping)
3250  goto end;
3251  }
3252  }
3253  }
3254 
3255  ExAcquireResourceSharedLite(&Vcb->chunk_lock, TRUE);
3256 
3257  le = chunks.Flink;
3258  while (le != &chunks) {
3259  chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3260 
3261  c->reloc = TRUE;
3262 
3263  le = le->Flink;
3264  }
3265 
3266  ExReleaseResourceLite(&Vcb->chunk_lock);
3267 
3268  // do data chunks before metadata
3269  le = chunks.Flink;
3270  while (le != &chunks) {
3271  chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3272  LIST_ENTRY* le2 = le->Flink;
3273 
3274  if (c->chunk_item->type & BLOCK_FLAG_DATA) {
3275  BOOL changed;
3276 
3277  do {
3278  changed = FALSE;
3279 
3280  Status = balance_data_chunk(Vcb, c, &changed);
3281  if (!NT_SUCCESS(Status)) {
3282  ERR("balance_data_chunk returned %08x\n", Status);
3283  Vcb->balance.status = Status;
3284  goto end;
3285  }
3286 
3287  KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, FALSE, NULL);
3288 
3289  if (Vcb->readonly)
3290  Vcb->balance.stopping = TRUE;
3291 
3292  if (Vcb->balance.stopping)
3293  break;
3294  } while (changed);
3295 
3296  c->changed = TRUE;
3297  c->space_changed = TRUE;
3298  }
3299 
3300  if (Vcb->balance.stopping)
3301  goto end;
3302 
3303  if (c->chunk_item->type & BLOCK_FLAG_DATA &&
3304  (!(Vcb->balance.opts[BALANCE_OPTS_METADATA].flags & BTRFS_BALANCE_OPTS_ENABLED) || !(c->chunk_item->type & BLOCK_FLAG_METADATA))) {
3305  RemoveEntryList(&c->list_entry_balance);
3306  c->list_entry_balance.Flink = NULL;
3307 
3308  Vcb->balance.chunks_left--;
3309  }
3310 
3311  le = le2;
3312  }
3313 
3314  // do metadata chunks
3315  while (!IsListEmpty(&chunks)) {
3316  chunk* c;
3317  BOOL changed;
3318 
3319  le = RemoveHeadList(&chunks);
3320  c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3321 
3322  if (c->chunk_item->type & BLOCK_FLAG_METADATA || c->chunk_item->type & BLOCK_FLAG_SYSTEM) {
3323  do {
3324  Status = balance_metadata_chunk(Vcb, c, &changed);
3325  if (!NT_SUCCESS(Status)) {
3326  ERR("balance_metadata_chunk returned %08x\n", Status);
3327  Vcb->balance.status = Status;
3328  goto end;
3329  }
3330 
3331  KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, FALSE, NULL);
3332 
3333  if (Vcb->readonly)
3334  Vcb->balance.stopping = TRUE;
3335 
3336  if (Vcb->balance.stopping)
3337  break;
3338  } while (changed);
3339 
3340  c->changed = TRUE;
3341  c->space_changed = TRUE;
3342  }
3343 
3344  if (Vcb->balance.stopping)
3345  break;
3346 
3347  c->list_entry_balance.Flink = NULL;
3348 
3349  Vcb->balance.chunks_left--;
3350  }
3351 
3352 end:
3353  if (!Vcb->readonly) {
3354  if (Vcb->balance.stopping || !NT_SUCCESS(Vcb->balance.status)) {
3355  le = chunks.Flink;
3356  while (le != &chunks) {
3357  chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
3358  c->reloc = FALSE;
3359 
3360  le = le->Flink;
3361  c->list_entry_balance.Flink = NULL;
3362  }
3363 
3364  if (old_data_flags != 0)
3365  Vcb->data_flags = old_data_flags;
3366 
3367  if (old_metadata_flags != 0)
3368  Vcb->metadata_flags = old_metadata_flags;
3369 
3370  if (old_system_flags != 0)
3371  Vcb->system_flags = old_system_flags;
3372  }
3373 
3374  if (Vcb->balance.removing) {
3375  device* dev = NULL;
3376 
3377  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
3378 
3379  le = Vcb->devices.Flink;
3380  while (le != &Vcb->devices) {
3381  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3382 
3383  if (dev2->devitem.dev_id == Vcb->balance.opts[0].devid) {
3384  dev = dev2;
3385  break;
3386  }
3387 
3388  le = le->Flink;
3389  }
3390 
3391  if (dev) {
3392  if (Vcb->balance.chunks_left == 0) {
3394 
3395  if (!NT_SUCCESS(Status)) {
3396  ERR("finish_removing_device returned %08x\n", Status);
3397  dev->reloc = FALSE;
3398  }
3399  } else
3400  dev->reloc = FALSE;
3401  }
3402 
3403  ExReleaseResourceLite(&Vcb->tree_lock);
3404  } else if (Vcb->balance.shrinking) {
3405  device* dev = NULL;
3406 
3407  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
3408 
3409  le = Vcb->devices.Flink;
3410  while (le != &Vcb->devices) {
3411  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3412 
3413  if (dev2->devitem.dev_id == Vcb->balance.opts[0].devid) {
3414  dev = dev2;
3415  break;
3416  }
3417 
3418  le = le->Flink;
3419  }
3420 
3421  if (!dev) {
3422  ERR("could not find device %llx\n", Vcb->balance.opts[0].devid);
3423  Vcb->balance.status = STATUS_INTERNAL_ERROR;
3424  }
3425 
3426  if (Vcb->balance.stopping || !NT_SUCCESS(Vcb->balance.status)) {
3427  if (dev) {
3429  if (!NT_SUCCESS(Status))
3430  WARN("regenerate_space_list returned %08x\n", Status);
3431  }
3432  } else {
3433  UINT64 old_size;
3434 
3435  old_size = dev->devitem.num_bytes;
3436  dev->devitem.num_bytes = Vcb->balance.opts[0].drange_start;
3437 
3439  if (!NT_SUCCESS(Status)) {
3440  ERR("update_dev_item returned %08x\n", Status);
3441  dev->devitem.num_bytes = old_size;
3442  Vcb->balance.status = Status;
3443 
3445  if (!NT_SUCCESS(Status))
3446  WARN("regenerate_space_list returned %08x\n", Status);
3447  } else {
3448  Vcb->superblock.total_bytes -= old_size - dev->devitem.num_bytes;
3449 
3450  Status = do_write(Vcb, NULL);
3451  if (!NT_SUCCESS(Status))
3452  ERR("do_write returned %08x\n", Status);
3453 
3454  free_trees(Vcb);
3455  }
3456  }
3457 
3458  ExReleaseResourceLite(&Vcb->tree_lock);
3459 
3460  if (!Vcb->balance.stopping && NT_SUCCESS(Vcb->balance.status))
3462  } else {
3464  if (!NT_SUCCESS(Status)) {
3465  ERR("remove_balance_item returned %08x\n", Status);
3466  goto end;
3467  }
3468  }
3469 
3470  if (Vcb->trim && !Vcb->options.no_trim) {
3471  ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
3472 
3473  le = Vcb->devices.Flink;
3474  while (le != &Vcb->devices) {
3475  device* dev2 = CONTAINING_RECORD(le, device, list_entry);
3476 
3477  if (dev2->devobj && !dev2->readonly && dev2->trim)
3478  trim_unalloc_space(Vcb, dev2);
3479 
3480  le = le->Flink;
3481  }
3482 
3483  ExReleaseResourceLite(&Vcb->tree_lock);
3484  }
3485  }
3486 
3487  ZwClose(Vcb->balance.thread);
3488  Vcb->balance.thread = NULL;
3489 
3490  KeSetEvent(&Vcb->balance.finished, 0, FALSE);
3491 }
BOOL readonly
Definition: btrfs_drv.h:495
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define BALANCE_OPTS_SYSTEM
Definition: btrfs_drv.h:663
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:7337
PDEVICE_OBJECT devobj
Definition: btrfs_drv.h:491
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS balance_data_chunk(device_extension *Vcb, chunk *c, BOOL *changed)
Definition: balance.c:1668
release_chunk_lock(c, Vcb)
UINT64 dev_id
Definition: btrfs.h:157
GLuint GLuint end
Definition: gl.h:1545
#define InsertTailList(ListHead, Entry)
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:154
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 flags, chunk **newchunk)
Definition: balance.c:2880
#define BTRFS_BALANCE_OPTS_CONVERT
Definition: btrfsioctl.h:151
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned int BOOL
Definition: ntddk_ex.h:94
Definition: devices.h:37
#define BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS
Definition: btrfs.h:105
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:71
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:2356
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
static NTSTATUS regenerate_space_list(device_extension *Vcb, device *dev)
Definition: balance.c:2975
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:148
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:3911
#define BTRFS_BALANCE_OPTS_ENABLED
Definition: btrfsioctl.h:143
#define BLOCK_FLAG_METADATA
Definition: shellext.h:72
Definition: typedefs.h:117
static NTSTATUS balance_metadata_chunk(device_extension *Vcb, chunk *c, BOOL *changed)
Definition: balance.c:1100
NTSTATUS alloc_chunk(device_extension *Vcb, UINT64 flags, chunk **pc, BOOL full_size)
Definition: write.c:365
Status
Definition: gdiplustypes.h:24
NTSTATUS load_cache_chunk(device_extension *Vcb, chunk *c, PIRP Irp)
Definition: free-space.c:952
#define ERR(fmt,...)
Definition: debug.h:109
static NTSTATUS remove_balance_item(device_extension *Vcb)
Definition: balance.c:2429
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define acquire_chunk_lock(c, Vcb)
Definition: btrfs_drv.h:1117
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
Definition: list.h:27
DEV_ITEM devitem
Definition: btrfs_drv.h:492
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:2564
#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:2780
#define c
Definition: ke_i.h:80
BOOL trim
Definition: btrfs_drv.h:497
unsigned long long UINT64
#define BALANCE_OPTS_METADATA
Definition: btrfs_drv.h:662
static BOOL should_balance_chunk(device_extension *Vcb, UINT8 sort, chunk *c)
Definition: balance.c:2203
unsigned char UINT8
#define BALANCE_OPTS_DATA
Definition: btrfs_drv.h:661

◆ _Function_class_() [2/2]

_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 959 of file btrfs_drv.h.

961  {
962  ExReleaseResourceLite(&Vcb->fcb_lock);
963 }
#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 919 of file btrfs_drv.h.

921  {
922 #ifdef DEBUG_STATS
923  LARGE_INTEGER time1, time2;
924 
925  if (ExAcquireResourceSharedLite(&Vcb->fcb_lock, FALSE))
926  return;
927 
929 #endif
930 
931  ExAcquireResourceSharedLite(&Vcb->fcb_lock, TRUE);
932 
933 #ifdef DEBUG_STATS
935  Vcb->stats.fcb_lock_time += time2.QuadPart - time1.QuadPart;
936 #endif
937 }
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
#define TRUE
Definition: types.h:120
smooth NULL
Definition: ftsmooth.c:416
#define Vcb
Definition: cdprocs.h:1425
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
LONGLONG QuadPart
Definition: typedefs.h:112

◆ _Success_()

_Success_ ( return  )

◆ add_calc_job()

NTSTATUS add_calc_job ( device_extension Vcb,
UINT8 data,
UINT32  sectors,
UINT32 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;
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 }
#define TRUE
Definition: types.h:120
_In_ ULONG cj
Definition: winddi.h:3540
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG * pcj
Definition: winddi.h:3642
UINT32 * csum
Definition: write.c:2829
#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:86
#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:2745

Referenced by calc_csum(), and check_csum().

◆ add_changed_extent_ref()

void add_changed_extent_ref ( chunk c,
UINT64  address,
UINT64  size,
UINT64  root,
UINT64  objid,
UINT64  offset,
UINT32  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 }
LIST_ENTRY list_entry
Definition: btrfs_drv.h:581
GLuint GLuint GLsizei count
Definition: gl.h:1545
struct _root root
GLintptr offset
Definition: glext.h:5920
#define InsertTailList(ListHead, Entry)
#define ALLOC_TAG
Definition: btrfs_drv.h:86
UINT64 count
Definition: btrfs_drv.h:564
EXTENT_DATA_REF edr
Definition: btrfs_drv.h:577
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:32
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
UINT32 count
Definition: btrfs.h:393
UINT64 root
Definition: btrfs.h:390
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
UINT64 offset
Definition: btrfs.h:392
LIST_ENTRY refs
Definition: btrfs_drv.h:568
Definition: list.h:27
UINT64 objid
Definition: btrfs.h:391
static changed_extent * get_changed_extent_item(chunk *c, UINT64 address, UINT64 size, BOOL no_csum)
Definition: extent-tree.c:1915

Referenced by rationalize_extents().

◆ add_checksum_entry()

void add_checksum_entry ( device_extension Vcb,
UINT64  address,
ULONG  length,
UINT32 csum,
PIRP  Irp 
)

Definition at line 2438 of file flushthread.c.

2438  {
2439  KEY searchkey;
2440  traverse_ptr tp, next_tp;
2441  NTSTATUS Status;
2442  UINT64 startaddr, endaddr;
2443  ULONG len;
2444  UINT32* checksums;
2445  RTL_BITMAP bmp;
2446  ULONG* bmparr;
2447  ULONG runlength, index;
2448 
2449  searchkey.obj_id = EXTENT_CSUM_ID;
2450  searchkey.obj_type = TYPE_EXTENT_CSUM;
2451  searchkey.offset = address;
2452 
2453  // FIXME - create checksum_root if it doesn't exist at all
2454 
2455  Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, FALSE, Irp);
2456  if (Status == STATUS_NOT_FOUND) { // tree is completely empty
2457  if (csum) { // not deleted
2458  ULONG length2 = length;
2459  UINT64 off = address;
2460  UINT32* data = csum;
2461 
2462  do {
2463  UINT16 il = (UINT16)min(length2, MAX_CSUM_SIZE / sizeof(UINT32));
2464 
2465  checksums = ExAllocatePoolWithTag(PagedPool, il * sizeof(UINT32), ALLOC_TAG);
2466  if (!checksums) {
2467  ERR("out of memory\n");
2468  return;
2469  }
2470 
2471  RtlCopyMemory(checksums, data, il * sizeof(UINT32));
2472 
2473  Status = insert_tree_item(Vcb, Vcb->checksum_root, EXTENT_CSUM_ID, TYPE_EXTENT_CSUM, off, checksums,
2474  il * sizeof(UINT32), NULL, Irp);
2475  if (!NT_SUCCESS(Status)) {
2476  ERR("insert_tree_item returned %08x\n", Status);
2477  ExFreePool(checksums);
2478  return;
2479  }
2480 
2481  length2 -= il;
2482 
2483  if (length2 > 0) {
2484  off += il * Vcb->superblock.sector_size;
2485  data += il;
2486  }
2487  } while (length2 > 0);
2488  }
2489  } else if (!NT_SUCCESS(Status)) {
2490  ERR("find_item returned %08x\n", Status);
2491  return;
2492  } else {
2493  UINT32 tplen;
2494 
2495  // FIXME - check entry is TYPE_EXTENT_CSUM?
2496 
2497  if (tp.item->key.offset < address && tp.item->key.offset + (tp.item->size * Vcb->superblock.sector_size / sizeof(UINT32)) >= address)
2498  startaddr = tp.item->key.offset;
2499  else
2500  startaddr = address;
2501 
2502  searchkey.obj_id = EXTENT_CSUM_ID;
2503  searchkey.obj_type = TYPE_EXTENT_CSUM;
2504  searchkey.offset = address + (length * Vcb->superblock.sector_size);
2505 
2506  Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, FALSE, Irp);
2507  if (!NT_SUCCESS(Status)) {
2508  ERR("find_item returned %08x\n", Status);
2509  return;
2510  }
2511 
2512  tplen = tp.item->size / sizeof(UINT32);
2513 
2514  if (tp.item->key.offset + (tplen * Vcb->superblock.sector_size) >= address + (length * Vcb->superblock.sector_size))
2515  endaddr = tp.item->key.offset + (tplen * Vcb->superblock.sector_size);
2516  else
2517  endaddr = address + (length * Vcb->superblock.sector_size);
2518 
2519  TRACE("cs starts at %llx (%x sectors)\n", address, length);
2520  TRACE("startaddr = %llx\n", startaddr);
2521  TRACE("endaddr = %llx\n", endaddr);
2522 
2523  len = (ULONG)((endaddr - startaddr) / Vcb->superblock.sector_size);
2524 
2525  checksums = ExAllocatePoolWithTag(PagedPool, sizeof(UINT32) * len, ALLOC_TAG);
2526  if (!checksums) {
2527  ERR("out of memory\n");
2528  return;
2529  }
2530 
2531  bmparr = ExAllocatePoolWithTag(PagedPool, sizeof(ULONG) * ((len/8)+1), ALLOC_TAG);
2532  if (!bmparr) {
2533  ERR("out of memory\n");
2534  ExFreePool(checksums);
2535  return;
2536  }
2537 
2538  RtlInitializeBitMap(&bmp, bmparr, len);
2539  RtlSetAllBits(&bmp);
2540 
2541  searchkey.obj_id = EXTENT_CSUM_ID;
2542  searchkey.obj_type = TYPE_EXTENT_CSUM;
2543  searchkey.offset = address;
2544 
2545  Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, FALSE, Irp);
2546  if (!NT_SUCCESS(Status)) {
2547  ERR("find_item returned %08x\n", Status);
2548  ExFreePool(checksums);
2549  ExFreePool(bmparr);
2550  return;
2551  }
2552 
2553  // set bit = free space, cleared bit = allocated sector
2554 
2555  while (tp.item->key.offset < endaddr) {
2556  if (tp.item->key.offset >= startaddr) {
2557  if (tp.item->size > 0) {
2558  ULONG itemlen = (ULONG)min((len - (tp.item->key.offset - startaddr) / Vcb->superblock.sector_size) * sizeof(UINT32), tp.item->size);
2559 
2560  RtlCopyMemory(&checksums[(tp.item->key.offset - startaddr) / Vcb->superblock.sector_size], tp.item->data, itemlen);
2561  RtlClearBits(&bmp, (ULONG)((tp.item->key.offset - startaddr) / Vcb->superblock.sector_size), itemlen / sizeof(UINT32));
2562  }
2563 
2565  if (!NT_SUCCESS(Status)) {
2566  ERR("delete_tree_item returned %08x\n", Status);
2567  ExFreePool(checksums);
2568  ExFreePool(bmparr);
2569  return;
2570  }
2571  }
2572 
2573  if (find_next_item(Vcb, &tp, &next_tp, FALSE, Irp)) {
2574  tp = next_tp;
2575  } else
2576  break;
2577  }
2578 
2579  if (!csum) { // deleted
2580  RtlSetBits(&bmp, (ULONG)((address - startaddr) / Vcb->superblock.sector_size), length);
2581  } else {
2582  RtlCopyMemory(&checksums[(address - startaddr) / Vcb->superblock.sector_size], csum, length * sizeof(UINT32));
2583  RtlClearBits(&bmp, (ULONG)((address - startaddr) / Vcb->superblock.sector_size), length);
2584  }
2585 
2586  runlength = RtlFindFirstRunClear(&bmp, &index);
2587 
2588  while (runlength != 0) {
2589  do {
2590  UINT16 rl;
2591  UINT64 off;
2592  UINT32* data;
2593 
2594  if (runlength * sizeof(UINT32) > MAX_CSUM_SIZE)
2595  rl = MAX_CSUM_SIZE / sizeof(UINT32);
2596  else
2597  rl = (UINT16)runlength;
2598 
2600  if (!data) {
2601  ERR("out of memory\n");
2602  ExFreePool(bmparr);
2603  ExFreePool(checksums);
2604  return;
2605  }
2606 
2607  RtlCopyMemory(data, &checksums[index], sizeof(UINT32) * rl);
2608 
2609  off = startaddr + UInt32x32To64(index, Vcb->superblock.sector_size);
2610 
2611  Status = insert_tree_item(Vcb, Vcb->checksum_root, EXTENT_CSUM_ID, TYPE_EXTENT_CSUM, off, data, sizeof(UINT32) * rl, NULL, Irp);
2612  if (!NT_SUCCESS(Status)) {
2613  ERR("insert_tree_item returned %08x\n", Status);
2614  ExFreePool(data);
2615  ExFreePool(bmparr);
2616  ExFreePool(checksums);
2617  return;
2618  }
2619 
2620  runlength -= rl;
2621  index += rl;
2622  } while (runlength > 0);
2623 
2624  runlength = RtlFindNextForwardRunClear(&bmp, index, &index);
2625  }
2626 
2627  ExFreePool(bmparr);
2628  ExFreePool(checksums);
2629  }
2630 }
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)
NTSYSAPI void WINAPI RtlInitializeBitMap(PRTL_BITMAP, PULONG, ULONG)
UINT64 offset
Definition: btrfs.h:125
_In_ PIRP Irp
Definition: csq.h:116
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
LONG NTSTATUS
Definition: precomp.h:26
UINT64 obj_id
Definition: btrfs.h:123
UINT32 * csum
Definition: write.c:2829
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2663
UINT16 size
Definition: btrfs_drv.h:389
UINT8 obj_type
Definition: btrfs.h:124
#define TYPE_EXTENT_CSUM
Definition: btrfs.h:25
#define ALLOC_TAG
Definition: btrfs_drv.h:86
unsigned int UINT32
NTSYSAPI ULONG WINAPI RtlFindNextForwardRunClear(PCRTL_BITMAP, ULONG, PULONG)
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
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
#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
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
tree_data * item
Definition: btrfs_drv.h:475
#define index(s, c)
Definition: various.h:29
GLenum GLsizei len
Definition: glext.h:6722
static void startaddr(void)
NTSTATUS insert_tree_item(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock) device_extension *Vcb, _In_ root *r, _In_ UINT64 obj_id, _In_ UINT8 obj_type, _In_ UINT64 offset, _In_reads_bytes_opt_(size) _When_(return >=0, __drv_aliasesMem) void *data, _In_ UINT16 size, _Out_opt_ traverse_ptr *ptp, _In_opt_ PIRP Irp)
Definition: treefuncs.c:857
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
Definition: btrfs.h:122
#define EXTENT_CSUM_ID
Definition: btrfs.h:82
NTSYSAPI ULONG NTAPI RtlFindFirstRunClear(_In_ PRTL_BITMAP BitMapHeader, _Out_ PULONG StartingIndex)
unsigned short UINT16
#define min(a, b)
Definition: monoChain.cc:55
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)
unsigned long long UINT64
#define UInt32x32To64(a, b)
Definition: intsafe.h:258
UINT8 * data
Definition: btrfs_drv.h:390
#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  inode,
BOOL  subvol,
PANSI_STRING  utf8,
PUNICODE_STRING  name,
UINT8  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*)dc->name.Buffer, dc->name.Length);
1805  dc->hash_uc = calc_crc32c(0xffffffff, (UINT8*)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
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
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
UINT64 inode
Definition: btrfs_drv.h:262
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
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define ALLOC_TAG
Definition: btrfs_drv.h:86
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
LIST_ENTRY dir_children_index
Definition: btrfs_drv.h:284
UINT64 index
Definition: btrfs_drv.h:226
#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
#define TYPE_INODE_ITEM
Definition: btrfs.h:18
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:257
#define TYPE_ROOT_ITEM
Definition: btrfs.h:26
void insert_dir_child_into_hash_lists(fcb *fcb, dir_child *dc)
Definition: fileinfo.c:1264
struct _root * subvol
Definition: btrfs_drv.h:261
Definition: name.c:36
#define ExIsResourceAcquiredExclusive
Definition: exfuncs.h:347
return STATUS_SUCCESS
Definition: btrfs.c:2745
unsigned char UINT8
#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 2359 of file write.c.

2359  {
2360  LIST_ENTRY* le = prevextle->Flink;
2361 
2362  while (le != &fcb->extents) {
2364 
2365  if (ext->offset >= newext->offset) {
2366  InsertHeadList(ext->list_entry.Blink, &newext->list_entry);
2367  return;
2368  }
2369 
2370  le = le->Flink;
2371  }
2372 
2373  InsertTailList(&fcb->extents, &newext->list_entry);
2374 }
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:274
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  offset,
_In_reads_bytes_(edsize) EXTENT_DATA ed,
_In_ UINT16  edsize,
_In_ BOOL  unique,
_In_opt_ _When_(return >=0, __drv_aliasesMem) UINT32 csum,
_In_ LIST_ENTRY rollback 
)

Definition at line 2728 of file write.c.

2729  {
2730  extent* ext;
2731  LIST_ENTRY* le;
2732 
2734  if (!ext) {
2735  ERR("out of memory\n");
2737  }
2738 
2739  ext->offset = offset;
2740  ext->datalen = edsize;
2741  ext->unique = unique;
2742  ext->ignore = FALSE;
2743  ext->inserted = TRUE;
2744  ext->csum = csum;
2745 
2746  RtlCopyMemory(&ext->extent_data, ed, edsize);
2747 
2748  le = fcb->extents.Flink;
2749  while (le != &fcb->extents) {
2750  extent* oldext = CONTAINING_RECORD(le, extent, list_entry);
2751 
2752  if (oldext->offset >= offset) {
2753  InsertHeadList(le->Blink, &ext->list_entry);
2754  goto end;
2755  }
2756 
2757  le = le->Flink;
2758  }
2759 
2760  InsertTailList(&fcb->extents, &ext->list_entry);
2761 
2762 end:
2764 
2765  return STATUS_SUCCESS;
2766 }
return TRUE
Definition: write.c:2909
void add_insert_extent_rollback(LIST_ENTRY *rollback, fcb *fcb, extent *ext)
Definition: write.c:2709
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
UINT32 * csum
Definition: write.c:2829
GLuint GLuint end
Definition: gl.h:1545
#define InsertTailList(ListHead, Entry)
#define ALLOC_TAG
Definition: btrfs_drv.h:86
UINT64 offset
Definition: btrfs_drv.h:202
#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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY extents
Definition: btrfs_drv.h:274
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
#define ERR(fmt,...)
Definition: debug.h:109
ed2 offset
Definition: write.c:2853
Definition: list.h:27
UINT16 edsize
Definition: write.c:2828
_ForwardIter unique(_ForwardIter __first, _ForwardIter __last)
Definition: _algo.h:298
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: write.c:2822
return STATUS_SUCCESS
Definition: btrfs.c:2745
EXTENT_DATA * ed
Definition: write.c:2826

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  gid 
)

Definition at line 145 of file security.c.

145  {
146  unsigned int i, np;
147  UINT8 numdashes;
148  UINT64 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)val, i, sidstringlength);
195 
196  if (np == 0) {
197  sid->auth[0] = (UINT8)((val & 0xff0000000000) >> 40);
198  sid->auth[1] = (UINT8)((val & 0xff00000000) >> 32);
199  sid->auth[2] = (UINT8)((val & 0xff000000) >> 24);
200  sid->auth[3] = (UINT8)((val & 0xff0000) >> 16);
201  sid->auth[4] = (UINT8)((val & 0xff00) >> 8);
202  sid->auth[5] = val & 0xff;
203  } else
204  sid->nums[np-1] = (UINT32)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:871
#define ALLOC_TAG
Definition: btrfs_drv.h:86
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT32
GLuint GLfloat * val
Definition: glext.h:7180
#define TRACE(s)
Definition: solgame.cpp:4
UINT32 gid
Definition: btrfs_drv.h:872
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
LIST_ENTRY listentry
Definition: btrfs_drv.h:870
#define ERR(fmt,...)
Definition: debug.h:109
LIST_ENTRY gid_map_list
Definition: btrfs.c:66
unsigned int ULONG
Definition: retypes.h:1
unsigned long long UINT64
unsigned char UINT8
#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 2709 of file write.c.

2709  {
2710  rollback_extent* re;
2711 
2713  if (!re) {
2714  ERR("out of memory\n");
2715  return;
2716  }
2717 
2718  re->fcb = fcb;
2719  re->ext = ext;
2720 
2722 }
#define ALLOC_TAG
Definition: btrfs_drv.h:86
char ext[3]
Definition: mkdosfs.c:358
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ERR(fmt,...)
Definition: debug.h:109
extent * ext
Definition: btrfs_drv.h:1228
_In_ fcb * fcb
Definition: write.c:2822
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: write.c:2822
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:1239
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define InsertTailList(ListHead, Entry)
#define ALLOC_TAG
Definition: btrfs_drv.h:86
static PVOID ptr
Definition: dispmode.c:27
LIST_ENTRY list_entry
Definition: btrfs_drv.h:1241
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1334
#define ERR(fmt,...)
Definition: debug.h:109

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  offset,
UINT64  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:86
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:2745

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 }
#define TRUE
Definition: types.h:120
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
_In_ PIRP Irp
Definition: csq.h:116
_SEH2_TRY
Definition: create.c:4250
#define ALLOC_TAG
Definition: btrfs_drv.h:86
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
#define Vcb
Definition: cdprocs.h:1425
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
GLenum GLsizei len
Definition: glext.h:6722
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define ERR(fmt,...)
Definition: debug.h:109
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
enum _LOCK_OPERATION LOCK_OPERATION
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
device_extension * Vcb
Definition: worker-thread.c:21
#define IRP_MJ_READ
Definition: rdpdr.c:46
unsigned int ULONG
Definition: retypes.h:1
WORK_QUEUE_ITEM item
Definition: worker-thread.c:23
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
UINT op
Definition: effect.c:223
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by _Dispatch_type_().

◆ add_trim_entry_avoid_sb()

void add_trim_entry_avoid_sb ( device_extension Vcb,
device dev,
UINT64  address,
UINT64  size 
)

Definition at line 5171 of file flushthread.c.

5171  {
5172  int i;
5173  ULONG sblen = (ULONG)sector_align(sizeof(superblock), Vcb->superblock.sector_size);
5174 
5175  i = 0;
5176  while (superblock_addrs[i] != 0) {
5177  if (superblock_addrs<