ReactOS  0.4.12-dev-396-g37af787
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
 
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 (_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ fcb *fcb)
 
void free_fileref (_Requires_exclusive_lock_held_(_Curr_->fcb_lock) _In_ device_extension *Vcb, _Inout_ file_ref *fr)
 
void 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 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)
 
treefree_tree (tree *t)
 
NTSTATUS load_tree (device_extension *Vcb, UINT64 addr, root *r, tree **pt, UINT64 generation, PIRP Irp)
 
NTSTATUS do_load_tree (device_extension *Vcb, tree_holder *th, root *r, tree *t, tree_data *td, BOOL *loaded, 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)
 
NTSTATUS open_fileref_by_inode (_Requires_exclusive_lock_held_(_Curr_->fcb_lock) device_extension *Vcb, root *subvol, UINT64 inode, file_ref **pfr, PIRP Irp)
 
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 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 1694 of file btrfs_drv.h.

◆ __S_IFCHR

#define __S_IFCHR   0020000 /* Character device. */

Definition at line 1693 of file btrfs_drv.h.

◆ __S_IFDIR

#define __S_IFDIR   0040000 /* Directory. */

Definition at line 1692 of file btrfs_drv.h.

◆ __S_IFIFO

#define __S_IFIFO   0010000 /* FIFO. */

Definition at line 1696 of file btrfs_drv.h.

◆ __S_IFLNK

#define __S_IFLNK   0120000 /* Symbolic link. */

Definition at line 1697 of file btrfs_drv.h.

◆ __S_IFMT

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

Definition at line 1691 of file btrfs_drv.h.

◆ __S_IFREG

#define __S_IFREG   0100000 /* Regular file. */

Definition at line 1695 of file btrfs_drv.h.

◆ __S_IFSOCK

#define __S_IFSOCK   0140000 /* Socket. */

Definition at line 1698 of file btrfs_drv.h.

◆ __S_ISTYPE

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

Definition at line 1699 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 1108 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 654 of file btrfs_drv.h.

◆ BALANCE_OPTS_METADATA

#define BALANCE_OPTS_METADATA   1

Definition at line 655 of file btrfs_drv.h.

◆ BALANCE_OPTS_SYSTEM

#define BALANCE_OPTS_SYSTEM   2

Definition at line 656 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 1783 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 1190 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 1605 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 1189 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 1136 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 1686 of file btrfs_drv.h.

◆ increase_fileref_refcount

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

Definition at line 1677 of file btrfs_drv.h.

◆ int3

#define int3   asm("int3;")

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

◆ major

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

Definition at line 1759 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 1603 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 1760 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 1109 of file btrfs_drv.h.

◆ S_IRGRP

#define S_IRGRP   (S_IRUSR >> 3)

Definition at line 1723 of file btrfs_drv.h.

◆ S_IROTH

#define S_IROTH   (S_IRGRP >> 3)

Definition at line 1735 of file btrfs_drv.h.

◆ S_IRUSR

#define S_IRUSR   0000400

Definition at line 1706 of file btrfs_drv.h.

◆ S_ISDIR

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

Definition at line 1702 of file btrfs_drv.h.

◆ S_ISGID

#define S_ISGID   0002000

Definition at line 1751 of file btrfs_drv.h.

◆ S_ISUID

#define S_ISUID   0004000

Definition at line 1747 of file btrfs_drv.h.

◆ S_ISVTX

#define S_ISVTX   0001000

Definition at line 1755 of file btrfs_drv.h.

◆ S_IWGRP

#define S_IWGRP   (S_IWUSR >> 3)

Definition at line 1727 of file btrfs_drv.h.

◆ S_IWOTH

#define S_IWOTH   (S_IWGRP >> 3)

Definition at line 1739 of file btrfs_drv.h.

◆ S_IWUSR

#define S_IWUSR   0000200

Definition at line 1710 of file btrfs_drv.h.

◆ S_IXGRP

#define S_IXGRP   (S_IXUSR >> 3)

Definition at line 1731 of file btrfs_drv.h.

◆ S_IXOTH

#define S_IXOTH   (S_IXGRP >> 3)

Definition at line 1743 of file btrfs_drv.h.

◆ S_IXUSR

#define S_IXUSR   0000100

Definition at line 1714 of file btrfs_drv.h.

◆ TRACE

#define TRACE (   s,
  ... 
)

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

◆ VCB_TYPE_FS

#define VCB_TYPE_FS   1

Definition at line 627 of file btrfs_drv.h.

◆ VCB_TYPE_PDO

#define VCB_TYPE_PDO   4

Definition at line 630 of file btrfs_drv.h.

◆ VCB_TYPE_VOLUME

#define VCB_TYPE_VOLUME   3

Definition at line 629 of file btrfs_drv.h.

◆ WARN

#define WARN (   s,
  ... 
)

Definition at line 1188 of file btrfs_drv.h.

Typedef Documentation

◆ ccb

typedef struct _ccb ccb

◆ device_extension

◆ DUPLICATE_EXTENTS_DATA

◆ fcb

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

◆ PRTL_USER_PROCESS_PARAMETERS

◆ root

typedef struct _root root

◆ root_cache

◆ RTL_USER_PROCESS_PARAMETERS

◆ tCcCopyReadEx

Definition at line 1779 of file btrfs_drv.h.

◆ tCcCopyWriteEx

Definition at line 1776 of file btrfs_drv.h.

◆ tCcSetAdditionalCacheAttributesEx

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

Definition at line 1786 of file btrfs_drv.h.

◆ tFsRtlUpdateDiskCounters

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

Definition at line 1788 of file btrfs_drv.h.

◆ tPsIsDiskCountersEnabled

typedef BOOLEAN(* tPsIsDiskCountersEnabled) ()

Definition at line 1771 of file btrfs_drv.h.

◆ tPsUpdateDiskCounters

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

Definition at line 1773 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 436 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 1218 of file btrfs_drv.h.

◆ write_data_status

Enumerator
WriteDataStatus_Pending 
WriteDataStatus_Success 
WriteDataStatus_Error 
WriteDataStatus_Cancelling 
WriteDataStatus_Cancelled 
WriteDataStatus_Ignore 

Definition at line 866 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 3029 of file balance.c.

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

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

952  {
953  ExReleaseResourceLite(&Vcb->fcb_lock);
954 }
#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 910 of file btrfs_drv.h.

912  {
913 #ifdef DEBUG_STATS
914  LARGE_INTEGER time1, time2;
915 
916  if (ExAcquireResourceSharedLite(&Vcb->fcb_lock, FALSE))
917  return;
918 
920 #endif
921 
922  ExAcquireResourceSharedLite(&Vcb->fcb_lock, TRUE);
923 
924 #ifdef DEBUG_STATS
926  Vcb->stats.fcb_lock_time += time2.QuadPart - time1.QuadPart;
927 #endif
928 }
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:2725

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:574
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:557
EXTENT_DATA_REF edr
Definition: btrfs_drv.h:570
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:561
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:582
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:2645
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:24
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:468
#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:838
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:972
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 1586 of file create.c.

1586  {
1587  NTSTATUS Status;
1588  dir_child* dc;
1589 
1591  if (!dc) {
1592  ERR("out of memory\n");
1594  }
1595 
1596  dc->utf8.Buffer = ExAllocatePoolWithTag(PagedPool, utf8->Length, ALLOC_TAG);
1597  if (!dc->utf8.Buffer) {
1598  ERR("out of memory\n");
1599  ExFreePool(dc);
1601  }
1602 
1603  dc->name.Buffer = ExAllocatePoolWithTag(PagedPool, name->Length, ALLOC_TAG);
1604  if (!dc->name.Buffer) {
1605  ERR("out of memory\n");
1606  ExFreePool(dc->utf8.Buffer);
1607  ExFreePool(dc);
1609  }
1610 
1611  dc->key.obj_id = inode;
1612  dc->key.obj_type = subvol ? TYPE_ROOT_ITEM : TYPE_INODE_ITEM;
1613  dc->key.offset = subvol ? 0xffffffffffffffff : 0;
1614  dc->type = type;
1615  dc->fileref = NULL;
1616 
1617  dc->utf8.Length = dc->utf8.MaximumLength = utf8->Length;
1618  RtlCopyMemory(dc->utf8.Buffer, utf8->Buffer, utf8->Length);
1619 
1620  dc->name.Length = dc->name.MaximumLength = name->Length;
1621  RtlCopyMemory(dc->name.Buffer, name->Buffer, name->Length);
1622 
1623  Status = RtlUpcaseUnicodeString(&dc->name_uc, name, TRUE);
1624  if (!NT_SUCCESS(Status)) {
1625  ERR("RtlUpcaseUnicodeString returned %08x\n", Status);
1626  ExFreePool(dc->utf8.Buffer);
1627  ExFreePool(dc->name.Buffer);
1628  ExFreePool(dc);
1629  return Status;
1630  }
1631 
1632  dc->hash = calc_crc32c(0xffffffff, (UINT8*)dc->name.Buffer, dc->name.Length);
1633  dc->hash_uc = calc_crc32c(0xffffffff, (UINT8*)dc->name_uc.Buffer, dc->name_uc.Length);
1634 
1635  ExAcquireResourceExclusiveLite(&fcb->nonpaged->dir_children_lock, TRUE);
1636 
1638  dc->index = 2;
1639  else {
1640  dir_child* dc2 = CONTAINING_RECORD(fcb->dir_children_index.Blink, dir_child, list_entry_index);
1641 
1642  dc->index = max(2, dc2->index + 1);
1643  }
1644 
1645  InsertTailList(&fcb->dir_children_index, &dc->list_entry_index);
1646 
1648 
1649  ExReleaseResourceLite(&fcb->nonpaged->dir_children_lock);
1650 
1651  *pdc = dc;
1652 
1653  return STATUS_SUCCESS;
1654 }
#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
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:283
UINT64 index
Definition: btrfs_drv.h:226
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
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:1253
struct _root * subvol
Definition: btrfs_drv.h:261
Definition: name.c:36
return STATUS_SUCCESS
Definition: btrfs.c:2725
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:273
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:273
#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:2725
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:862
#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:863
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
LIST_ENTRY listentry
Definition: btrfs_drv.h:861
#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:1215
_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:817

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 817 of file treefuncs.c.

817  {
818  rollback_item* ri;
819 
821  if (!ri) {
822  ERR("out of memory\n");
823  return;
824  }
825 
826  ri->type = type;
827  ri->ptr = ptr;
829 }
enum rollback_type type
Definition: btrfs_drv.h:1226
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:1228
#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:1321
#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:2725

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 5124 of file flushthread.c.

5124  {
5125  int i;
5126  ULONG sblen = (ULONG)sector_align(sizeof(superblock), Vcb->superblock.sector_size);
5127 
5128  i = 0;
5129  while (superblock_addrs[i] != 0) {
5130  if (superblock_addrs[i] + sblen >= address && superblock_addrs[i] < address + size) {
5131  if (superblock_addrs[i] > address)
5133 
5134  if (size <= superblock_addrs[i] + sblen - address)
5135  return;
5136 
5137  size -= superblock_addrs[i] + sblen - address;
5138  add