https://git.reactos.org/?p=reactos.git;a=commitdiff;h=318da0c18c51da3e93425…
commit 318da0c18c51da3e93425de65629ae7e222cabc0
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Sep 1 14:53:20 2019 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Mon Sep 2 08:19:48 2019 +0200
[BTRFS] Upgrade to 1.4
CORE-16354
---
dll/shellext/shellbtrfs/contextmenu.cpp | 8 +-
dll/shellext/shellbtrfs/propsheet.cpp | 16 +-
drivers/filesystems/btrfs/CMakeLists.txt | 4 +-
drivers/filesystems/btrfs/balance.c | 638 +++++-----
drivers/filesystems/btrfs/boot.c | 248 ++++
drivers/filesystems/btrfs/btrfs.c | 1425 +++++++++++++----------
drivers/filesystems/btrfs/btrfs.h | 419 ++++---
drivers/filesystems/btrfs/btrfs.rc | 8 +-
drivers/filesystems/btrfs/btrfs_drv.h | 929 +++++++--------
drivers/filesystems/btrfs/btrfsioctl.h | 179 ++-
drivers/filesystems/btrfs/cache.c | 34 +-
drivers/filesystems/btrfs/calcthread.c | 44 +-
drivers/filesystems/btrfs/compress.c | 266 ++---
drivers/filesystems/btrfs/crc32c.c | 24 +-
drivers/filesystems/btrfs/create.c | 766 ++++++------
drivers/filesystems/btrfs/devctrl.c | 22 +-
drivers/filesystems/btrfs/dirctrl.c | 106 +-
drivers/filesystems/btrfs/extent-tree.c | 490 ++++----
drivers/filesystems/btrfs/fastio.c | 270 +++--
drivers/filesystems/btrfs/fileinfo.c | 612 +++++-----
drivers/filesystems/btrfs/flushthread.c | 1388 +++++++++++-----------
drivers/filesystems/btrfs/free-space.c | 351 +++---
drivers/filesystems/btrfs/fsctl.c | 681 +++++------
drivers/filesystems/btrfs/fsrtl.c | 126 ++
drivers/filesystems/btrfs/galois.c | 38 +-
drivers/filesystems/btrfs/pnp.c | 194 ++-
drivers/filesystems/btrfs/read.c | 980 ++++++++--------
drivers/filesystems/btrfs/registry.c | 128 +-
drivers/filesystems/btrfs/reparse.c | 74 +-
drivers/filesystems/btrfs/scrub.c | 878 +++++++-------
drivers/filesystems/btrfs/search.c | 220 ++--
drivers/filesystems/btrfs/security.c | 104 +-
drivers/filesystems/btrfs/send.c | 712 ++++++-----
drivers/filesystems/btrfs/treefuncs.c | 422 +++----
drivers/filesystems/btrfs/volume.c | 316 ++---
drivers/filesystems/btrfs/worker-thread.c | 42 +-
drivers/filesystems/btrfs/write.c | 958 +++++++--------
drivers/filesystems/btrfs/zstd/fse_compress.c | 35 +-
drivers/filesystems/btrfs/zstd/hist.c | 16 +-
drivers/filesystems/btrfs/zstd/huf.h | 4 -
drivers/filesystems/btrfs/zstd/huf_compress.c | 43 +-
drivers/filesystems/btrfs/zstd/huf_decompress.c | 72 +-
media/doc/README.FSD | 2 +-
43 files changed, 7551 insertions(+), 6741 deletions(-)
diff --git a/dll/shellext/shellbtrfs/contextmenu.cpp
b/dll/shellext/shellbtrfs/contextmenu.cpp
index 6e51a0f9eeb..8fcdf2cc551 100644
--- a/dll/shellext/shellbtrfs/contextmenu.cpp
+++ b/dll/shellext/shellbtrfs/contextmenu.cpp
@@ -542,7 +542,7 @@ void BtrfsContextMenu::reflink_copy(HWND hwnd, const WCHAR* fn, const
WCHAR* dir
wstring dirw, newpath;
FILE_BASIC_INFO fbi;
FILETIME atime, mtime;
- btrfs_inode_info2 bii;
+ btrfs_inode_info bii;
btrfs_set_inode_info bsii;
ULONG bytesret;
NTSTATUS Status;
@@ -575,7 +575,7 @@ void BtrfsContextMenu::reflink_copy(HWND hwnd, const WCHAR* fn, const
WCHAR* dir
if (source == INVALID_HANDLE_VALUE)
throw last_error(GetLastError());
- Status = NtFsControlFile(source, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii, sizeof(btrfs_inode_info2));
+ Status = NtFsControlFile(source, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii, sizeof(btrfs_inode_info));
if (!NT_SUCCESS(Status))
throw ntstatus_error(Status);
@@ -1302,7 +1302,7 @@ static void reflink_copy2(const wstring& srcfn, const
wstring& destdir, const ws
win_handle source, dest;
FILE_BASIC_INFO fbi;
FILETIME atime, mtime;
- btrfs_inode_info2 bii;
+ btrfs_inode_info bii;
btrfs_set_inode_info bsii;
ULONG bytesret;
NTSTATUS Status;
@@ -1313,7 +1313,7 @@ static void reflink_copy2(const wstring& srcfn, const
wstring& destdir, const ws
if (source == INVALID_HANDLE_VALUE)
throw last_error(GetLastError());
- Status = NtFsControlFile(source, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii, sizeof(btrfs_inode_info2));
+ Status = NtFsControlFile(source, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii, sizeof(btrfs_inode_info));
if (!NT_SUCCESS(Status))
throw ntstatus_error(Status);
diff --git a/dll/shellext/shellbtrfs/propsheet.cpp
b/dll/shellext/shellbtrfs/propsheet.cpp
index 4c3478f9e85..153d6484fb4 100644
--- a/dll/shellext/shellbtrfs/propsheet.cpp
+++ b/dll/shellext/shellbtrfs/propsheet.cpp
@@ -111,11 +111,11 @@ void BtrfsPropSheet::do_search(const wstring& fn) {
if (fh != INVALID_HANDLE_VALUE) {
NTSTATUS Status;
IO_STATUS_BLOCK iosb;
- btrfs_inode_info2 bii2;
+ btrfs_inode_info bii2;
memset(&bii2, 0, sizeof(bii2));
- Status = NtFsControlFile(fh, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info2));
+ Status = NtFsControlFile(fh, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info));
if (NT_SUCCESS(Status)) {
sizes[0] += bii2.inline_length;
@@ -167,7 +167,7 @@ HRESULT BtrfsPropSheet::check_file(const wstring& fn, UINT i, UINT
num_files, UI
NTSTATUS Status;
FILE_ACCESS_INFORMATION fai;
BY_HANDLE_FILE_INFORMATION bhfi;
- btrfs_inode_info2 bii2;
+ btrfs_inode_info bii2;
h = CreateFileW(fn.c_str(), MAXIMUM_ALLOWED, FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS |
FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
@@ -192,7 +192,7 @@ HRESULT BtrfsPropSheet::check_file(const wstring& fn, UINT i, UINT
num_files, UI
memset(&bii2, 0, sizeof(bii2));
- Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info2));
+ Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info));
if (NT_SUCCESS(Status) && !bii2.top) {
LARGE_INTEGER filesize;
@@ -396,7 +396,7 @@ void BtrfsPropSheet::set_cmdline(const wstring& cmdline) {
NTSTATUS Status;
UINT sv = 0;
BY_HANDLE_FILE_INFORMATION bhfi;
- btrfs_inode_info2 bii2;
+ btrfs_inode_info bii2;
FILE_ACCESS_INFORMATION fai;
min_mode = 0;
@@ -430,7 +430,7 @@ void BtrfsPropSheet::set_cmdline(const wstring& cmdline) {
memset(&bii2, 0, sizeof(bii2));
- Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info2));
+ Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info));
if (NT_SUCCESS(Status) && !bii2.top) {
LARGE_INTEGER filesize;
@@ -583,7 +583,7 @@ void BtrfsPropSheet::apply_changes_file(HWND hDlg, const wstring&
fn) {
IO_STATUS_BLOCK iosb;
NTSTATUS Status;
btrfs_set_inode_info bsii;
- btrfs_inode_info2 bii2;
+ btrfs_inode_info bii2;
ULONG perms = FILE_TRAVERSE | FILE_READ_ATTRIBUTES;
if (flags_changed || ro_changed)
@@ -603,7 +603,7 @@ void BtrfsPropSheet::apply_changes_file(HWND hDlg, const wstring&
fn) {
ZeroMemory(&bsii, sizeof(btrfs_set_inode_info));
- Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info2));
+ Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb,
FSCTL_BTRFS_GET_INODE_INFO, nullptr, 0, &bii2, sizeof(btrfs_inode_info));
if (!NT_SUCCESS(Status))
throw ntstatus_error(Status);
diff --git a/drivers/filesystems/btrfs/CMakeLists.txt
b/drivers/filesystems/btrfs/CMakeLists.txt
index cd4c76e3501..14e78425fed 100644
--- a/drivers/filesystems/btrfs/CMakeLists.txt
+++ b/drivers/filesystems/btrfs/CMakeLists.txt
@@ -5,6 +5,7 @@ include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/drivers
list(APPEND SOURCE
balance.c
+ boot.c
btrfs.c
cache.c
calcthread.c
@@ -19,6 +20,7 @@ list(APPEND SOURCE
flushthread.c
free-space.c
fsctl.c
+ fsrtl.c
galois.c
guid.c
pnp.c
@@ -55,6 +57,6 @@ add_library(btrfs MODULE ${SOURCE} btrfs.rc)
add_definitions(-D__KERNEL__)
set_module_type(btrfs kernelmodedriver)
-target_link_libraries(btrfs rtlver ntoskrnl_vista zlib_solo chkstk wdmguid ${PSEH_LIB})
+target_link_libraries(btrfs rtlver zlib_solo chkstk wdmguid ${PSEH_LIB})
add_importlibs(btrfs ntoskrnl hal)
add_cd_file(TARGET btrfs DESTINATION reactos/system32/drivers NO_CAB FOR all)
diff --git a/drivers/filesystems/btrfs/balance.c b/drivers/filesystems/btrfs/balance.c
index 83546f03717..b7794125deb 100644
--- a/drivers/filesystems/btrfs/balance.c
+++ b/drivers/filesystems/btrfs/balance.c
@@ -20,19 +20,19 @@
#include <ntddstor.h>
typedef struct {
- UINT64 address;
- UINT64 new_address;
+ uint64_t address;
+ uint64_t new_address;
tree_header* data;
EXTENT_ITEM* ei;
tree* t;
- BOOL system;
+ bool system;
LIST_ENTRY refs;
LIST_ENTRY list_entry;
} metadata_reloc;
typedef struct {
- UINT8 type;
- UINT64 hash;
+ uint8_t type;
+ uint64_t hash;
union {
TREE_BLOCK_REF tbr;
@@ -40,14 +40,14 @@ typedef struct {
};
metadata_reloc* parent;
- BOOL top;
+ bool top;
LIST_ENTRY list_entry;
} metadata_reloc_ref;
typedef struct {
- UINT64 address;
- UINT64 size;
- UINT64 new_address;
+ uint64_t address;
+ uint64_t size;
+ uint64_t new_address;
chunk* newchunk;
EXTENT_ITEM* ei;
LIST_ENTRY refs;
@@ -55,8 +55,8 @@ typedef struct {
} data_reloc;
typedef struct {
- UINT8 type;
- UINT64 hash;
+ uint8_t type;
+ uint64_t hash;
union {
EXTENT_DATA_REF edr;
@@ -67,22 +67,20 @@ typedef struct {
LIST_ENTRY list_entry;
} data_reloc_ref;
-#ifndef __REACTOS__
#ifndef _MSC_VER // not in mingw yet
#define DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED 0x80000000
#endif
-#endif
#define BALANCE_UNIT 0x100000 // only read 1 MB at a time
static NTSTATUS add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, LIST_ENTRY* items, traverse_ptr* tp,
- BOOL skinny, metadata_reloc** mr2, chunk* c,
LIST_ENTRY* rollback) {
+ bool skinny, metadata_reloc** mr2, chunk* c,
LIST_ENTRY* rollback) {
NTSTATUS Status;
metadata_reloc* mr;
EXTENT_ITEM* ei;
- UINT16 len;
- UINT64 inline_rc;
- UINT8* ptr;
+ uint16_t len;
+ uint64_t inline_rc;
+ uint8_t* ptr;
mr = ExAllocatePoolWithTag(PagedPool, sizeof(metadata_reloc), ALLOC_TAG);
if (!mr) {
@@ -93,7 +91,7 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
mr->address = tp->item->key.obj_id;
mr->data = NULL;
mr->ei = (EXTENT_ITEM*)tp->item->data;
- mr->system = FALSE;
+ mr->system = false;
InitializeListHead(&mr->refs);
Status = delete_tree_item(Vcb, tp);
@@ -120,26 +118,26 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
inline_rc = 0;
len = tp->item->size - sizeof(EXTENT_ITEM);
- ptr = (UINT8*)tp->item->data + sizeof(EXTENT_ITEM);
+ ptr = (uint8_t*)tp->item->data + sizeof(EXTENT_ITEM);
if (!skinny) {
len -= sizeof(EXTENT_ITEM2);
ptr += sizeof(EXTENT_ITEM2);
}
while (len > 0) {
- UINT8 secttype = *ptr;
- UINT16 sectlen = secttype == TYPE_TREE_BLOCK_REF ? sizeof(TREE_BLOCK_REF) :
(secttype == TYPE_SHARED_BLOCK_REF ? sizeof(SHARED_BLOCK_REF) : 0);
+ uint8_t secttype = *ptr;
+ uint16_t sectlen = secttype == TYPE_TREE_BLOCK_REF ? sizeof(TREE_BLOCK_REF) :
(secttype == TYPE_SHARED_BLOCK_REF ? sizeof(SHARED_BLOCK_REF) : 0);
metadata_reloc_ref* ref;
len--;
if (sectlen > len) {
- ERR("(%llx,%x,%llx): %x bytes left, expecting at least %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset, len,
sectlen);
+ ERR("(%I64x,%x,%I64x): %x bytes left, expecting at least %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset, len,
sectlen);
return STATUS_INTERNAL_ERROR;
}
if (sectlen == 0) {
- ERR("(%llx,%x,%llx): unrecognized extent type %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset,
secttype);
+ ERR("(%I64x,%x,%I64x): unrecognized extent type %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset,
secttype);
return STATUS_INTERNAL_ERROR;
}
@@ -151,11 +149,11 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
if (secttype == TYPE_TREE_BLOCK_REF) {
ref->type = TYPE_TREE_BLOCK_REF;
- RtlCopyMemory(&ref->tbr, ptr + sizeof(UINT8),
sizeof(TREE_BLOCK_REF));
+ RtlCopyMemory(&ref->tbr, ptr + sizeof(uint8_t),
sizeof(TREE_BLOCK_REF));
inline_rc++;
} else if (secttype == TYPE_SHARED_BLOCK_REF) {
ref->type = TYPE_SHARED_BLOCK_REF;
- RtlCopyMemory(&ref->sbr, ptr + sizeof(UINT8),
sizeof(SHARED_BLOCK_REF));
+ RtlCopyMemory(&ref->sbr, ptr + sizeof(uint8_t),
sizeof(SHARED_BLOCK_REF));
inline_rc++;
} else {
ERR("unexpected tree type %x\n", secttype);
@@ -164,17 +162,17 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
}
ref->parent = NULL;
- ref->top = FALSE;
+ ref->top = false;
InsertTailList(&mr->refs, &ref->list_entry);
len -= sectlen;
- ptr += sizeof(UINT8) + sectlen;
+ ptr += sizeof(uint8_t) + sectlen;
}
if (inline_rc < ei->refcount) { // look for non-inline entries
traverse_ptr tp2 = *tp, next_tp;
- while (find_next_item(Vcb, &tp2, &next_tp, FALSE, NULL)) {
+ while (find_next_item(Vcb, &tp2, &next_tp, false, NULL)) {
tp2 = next_tp;
if (tp2.item->key.obj_id == tp->item->key.obj_id) {
@@ -188,7 +186,7 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
ref->type = TYPE_TREE_BLOCK_REF;
ref->tbr.offset = tp2.item->key.offset;
ref->parent = NULL;
- ref->top = FALSE;
+ ref->top = false;
InsertTailList(&mr->refs, &ref->list_entry);
Status = delete_tree_item(Vcb, &tp2);
@@ -206,7 +204,7 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
ref->type = TYPE_SHARED_BLOCK_REF;
ref->sbr.offset = tp2.item->key.offset;
ref->parent = NULL;
- ref->top = FALSE;
+ ref->top = false;
InsertTailList(&mr->refs, &ref->list_entry);
Status = delete_tree_item(Vcb, &tp2);
@@ -229,11 +227,11 @@ static NTSTATUS
add_metadata_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_l
}
static NTSTATUS
add_metadata_reloc_parent(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, LIST_ENTRY* items,
- UINT64 address, metadata_reloc** mr2,
LIST_ENTRY* rollback) {
+ uint64_t address, metadata_reloc** mr2,
LIST_ENTRY* rollback) {
LIST_ENTRY* le;
KEY searchkey;
traverse_ptr tp;
- BOOL skinny = FALSE;
+ bool skinny = false;
NTSTATUS Status;
le = items->Flink;
@@ -252,24 +250,24 @@ static NTSTATUS
add_metadata_reloc_parent(_Requires_exclusive_lock_held_(_Curr_-
searchkey.obj_type = TYPE_METADATA_ITEM;
searchkey.offset = 0xffffffffffffffff;
- Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
return Status;
}
if (tp.item->key.obj_id == address && tp.item->key.obj_type ==
TYPE_METADATA_ITEM && tp.item->size >= sizeof(EXTENT_ITEM))
- skinny = TRUE;
+ skinny = true;
else if (tp.item->key.obj_id == address && tp.item->key.obj_type ==
TYPE_EXTENT_ITEM && tp.item->key.offset == Vcb->superblock.node_size
&&
tp.item->size >= sizeof(EXTENT_ITEM)) {
EXTENT_ITEM* ei = (EXTENT_ITEM*)tp.item->data;
if (!(ei->flags & EXTENT_ITEM_TREE_BLOCK)) {
- ERR("EXTENT_ITEM for %llx found, but tree flag not set\n",
address);
+ ERR("EXTENT_ITEM for %I64x found, but tree flag not set\n",
address);
return STATUS_INTERNAL_ERROR;
}
} else {
- ERR("could not find valid EXTENT_ITEM for address %llx\n", address);
+ ERR("could not find valid EXTENT_ITEM for address %I64x\n", address);
return STATUS_INTERNAL_ERROR;
}
@@ -294,7 +292,7 @@ static void sort_metadata_reloc_refs(metadata_reloc* mr) {
while (!IsListEmpty(&mr->refs)) {
metadata_reloc_ref* ref = CONTAINING_RECORD(RemoveHeadList(&mr->refs),
metadata_reloc_ref, list_entry);
- BOOL inserted = FALSE;
+ bool inserted = false;
if (ref->type == TYPE_TREE_BLOCK_REF)
ref->hash = ref->tbr.offset;
@@ -307,7 +305,7 @@ static void sort_metadata_reloc_refs(metadata_reloc* mr) {
if (ref->type < ref2->type || (ref->type == ref2->type
&& ref->hash > ref2->hash)) {
InsertHeadList(le->Blink, &ref->list_entry);
- inserted = TRUE;
+ inserted = true;
break;
}
@@ -327,12 +325,12 @@ static void sort_metadata_reloc_refs(metadata_reloc* mr) {
static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, metadata_reloc* mr) {
NTSTATUS Status;
LIST_ENTRY* le;
- UINT64 rc = 0;
- UINT16 inline_len;
- BOOL all_inline = TRUE;
+ uint64_t rc = 0;
+ uint16_t inline_len;
+ bool all_inline = true;
metadata_reloc_ref* first_noninline = NULL;
EXTENT_ITEM* ei;
- UINT8* ptr;
+ uint8_t* ptr;
inline_len = sizeof(EXTENT_ITEM);
if (!(Vcb->superblock.incompat_flags & BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA))
@@ -343,7 +341,7 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
le = mr->refs.Flink;
while (le != &mr->refs) {
metadata_reloc_ref* ref = CONTAINING_RECORD(le, metadata_reloc_ref, list_entry);
- UINT16 extlen = 0;
+ uint16_t extlen = 0;
rc++;
@@ -354,7 +352,7 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
if (all_inline) {
if ((ULONG)(inline_len + 1 + extlen) > (Vcb->superblock.node_size
>> 2)) {
- all_inline = FALSE;
+ all_inline = false;
first_noninline = ref;
} else
inline_len += extlen + 1;
@@ -372,7 +370,7 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
ei->refcount = rc;
ei->generation = mr->ei->generation;
ei->flags = mr->ei->flags;
- ptr = (UINT8*)&ei[1];
+ ptr = (uint8_t*)&ei[1];
if (!(Vcb->superblock.incompat_flags & BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA))
{
EXTENT_ITEM2* ei2 = (EXTENT_ITEM2*)ptr;
@@ -447,11 +445,11 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
if (ei->flags & EXTENT_ITEM_SHARED_BACKREFS || mr->data->flags &
HEADER_FLAG_SHARED_BACKREF || !(mr->data->flags & HEADER_FLAG_MIXED_BACKREF)) {
if (mr->data->level > 0) {
- UINT16 i;
+ uint16_t i;
internal_node* in = (internal_node*)&mr->data[1];
for (i = 0; i < mr->data->num_items; i++) {
- UINT64 sbrrc = find_extent_shared_tree_refcount(Vcb, in[i].address,
mr->address, NULL);
+ uint64_t sbrrc = find_extent_shared_tree_refcount(Vcb, in[i].address,
mr->address, NULL);
if (sbrrc > 0) {
SHARED_BLOCK_REF sbr;
@@ -467,7 +465,7 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
sbr.offset = mr->address;
Status = decrease_extent_refcount(Vcb, in[i].address,
Vcb->superblock.node_size, TYPE_SHARED_BLOCK_REF, &sbr, NULL, 0,
- sbr.offset, FALSE, NULL);
+ sbr.offset, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("decrease_extent_refcount returned %08x\n",
Status);
return Status;
@@ -475,18 +473,18 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
}
}
} else {
- UINT16 i;
+ uint16_t i;
leaf_node* ln = (leaf_node*)&mr->data[1];
for (i = 0; i < mr->data->num_items; i++) {
if (ln[i].key.obj_type == TYPE_EXTENT_DATA && ln[i].size >=
sizeof(EXTENT_DATA) - 1 + sizeof(EXTENT_DATA2)) {
- EXTENT_DATA* ed = (EXTENT_DATA*)((UINT8*)mr->data +
sizeof(tree_header) + ln[i].offset);
+ EXTENT_DATA* ed = (EXTENT_DATA*)((uint8_t*)mr->data +
sizeof(tree_header) + ln[i].offset);
if (ed->type == EXTENT_TYPE_REGULAR || ed->type ==
EXTENT_TYPE_PREALLOC) {
EXTENT_DATA2* ed2 = (EXTENT_DATA2*)ed->data;
if (ed2->size > 0) { // not sparse
- UINT32 sdrrc = find_extent_shared_data_refcount(Vcb,
ed2->address, mr->address, NULL);
+ uint32_t sdrrc = find_extent_shared_data_refcount(Vcb,
ed2->address, mr->address, NULL);
if (sdrrc > 0) {
SHARED_DATA_REF sdr;
@@ -504,7 +502,7 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
sdr.offset = mr->address;
Status = decrease_extent_refcount(Vcb, ed2->address,
ed2->size, TYPE_SHARED_DATA_REF, &sdr, NULL, 0,
- sdr.offset, FALSE,
NULL);
+ sdr.offset, false,
NULL);
if (!NT_SUCCESS(Status)) {
ERR("decrease_extent_refcount returned
%08x\n", Status);
return Status;
@@ -515,7 +513,7 @@ static NTSTATUS
add_metadata_reloc_extent_item(_Requires_exclusive_lock_held_(_C
if (c) {
// check changed_extents
-
ExAcquireResourceExclusiveLite(&c->changed_extents_lock, TRUE);
+
ExAcquireResourceExclusiveLite(&c->changed_extents_lock, true);
le = c->changed_extents.Flink;
@@ -573,7 +571,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
LIST_ENTRY tree_writes, *le;
NTSTATUS Status;
traverse_ptr tp;
- UINT8 level, max_level = 0;
+ uint8_t level, max_level = 0;
chunk* newchunk = NULL;
InitializeListHead(&tree_writes);
@@ -590,26 +588,26 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
return STATUS_INSUFFICIENT_RESOURCES;
}
- Status = read_data(Vcb, mr->address, Vcb->superblock.node_size, NULL, TRUE,
(UINT8*)mr->data,
- c && mr->address >= c->offset &&
mr->address < c->offset + c->chunk_item->size ? c : NULL, &pc, NULL, 0,
FALSE, NormalPagePriority);
+ Status = read_data(Vcb, mr->address, Vcb->superblock.node_size, NULL, true,
(uint8_t*)mr->data,
+ c && mr->address >= c->offset &&
mr->address < c->offset + c->chunk_item->size ? c : NULL, &pc, NULL, 0,
false, NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("read_data returned %08x\n", Status);
return Status;
}
if (pc->chunk_item->type & BLOCK_FLAG_SYSTEM)
- mr->system = TRUE;
+ mr->system = true;
if (data_items && mr->data->level == 0) {
le2 = data_items->Flink;
while (le2 != data_items) {
data_reloc* dr = CONTAINING_RECORD(le2, data_reloc, list_entry);
leaf_node* ln = (leaf_node*)&mr->data[1];
- UINT16 i;
+ uint16_t i;
for (i = 0; i < mr->data->num_items; i++) {
if (ln[i].key.obj_type == TYPE_EXTENT_DATA && ln[i].size
>= sizeof(EXTENT_DATA) - 1 + sizeof(EXTENT_DATA2)) {
- EXTENT_DATA* ed = (EXTENT_DATA*)((UINT8*)mr->data +
sizeof(tree_header) + ln[i].offset);
+ EXTENT_DATA* ed = (EXTENT_DATA*)((uint8_t*)mr->data +
sizeof(tree_header) + ln[i].offset);
if (ed->type == EXTENT_TYPE_REGULAR || ed->type ==
EXTENT_TYPE_PREALLOC) {
EXTENT_DATA2* ed2 = (EXTENT_DATA2*)ed->data;
@@ -652,11 +650,11 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
}
if (!r) {
- ERR("could not find subvol with id %llx\n",
ref->tbr.offset);
+ ERR("could not find subvol with id %I64x\n",
ref->tbr.offset);
return STATUS_INTERNAL_ERROR;
}
- Status = find_item_to_level(Vcb, r, &tp, firstitem, FALSE,
mr->data->level + 1, NULL);
+ Status = find_item_to_level(Vcb, r, &tp, firstitem, false,
mr->data->level + 1, NULL);
if (!NT_SUCCESS(Status) && Status != STATUS_NOT_FOUND) {
ERR("find_item_to_level returned %08x\n", Status);
return Status;
@@ -668,7 +666,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
}
if (!t)
- ref->top = TRUE;
+ ref->top = true;
else {
metadata_reloc* mr2;
@@ -702,11 +700,11 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
while (le != items) {
metadata_reloc* mr = CONTAINING_RECORD(le, metadata_reloc, list_entry);
LIST_ENTRY* le2;
- UINT32 hash;
+ uint32_t hash;
mr->t = NULL;
- hash = calc_crc32c(0xffffffff, (UINT8*)&mr->address, sizeof(UINT64));
+ hash = calc_crc32c(0xffffffff, (uint8_t*)&mr->address, sizeof(uint64_t));
le2 = Vcb->trees_ptrs[hash >> 24];
@@ -733,10 +731,10 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
metadata_reloc* mr = CONTAINING_RECORD(le, metadata_reloc, list_entry);
if (mr->data->level == level) {
- BOOL done = FALSE;
+ bool done = false;
LIST_ENTRY* le2;
tree_write* tw;
- UINT64 flags;
+ uint64_t flags;
tree* t3;
if (mr->system)
@@ -751,15 +749,15 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
if (newchunk->chunk_item->type == flags &&
find_metadata_address_in_chunk(Vcb, newchunk, &mr->new_address)) {
newchunk->used += Vcb->superblock.node_size;
- space_list_subtract(newchunk, FALSE, mr->new_address,
Vcb->superblock.node_size, rollback);
- done = TRUE;
+ space_list_subtract(newchunk, false, mr->new_address,
Vcb->superblock.node_size, rollback);
+ done = true;
}
release_chunk_lock(newchunk, Vcb);
}
if (!done) {
- ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
le2 = Vcb->chunks.Flink;
while (le2 != &Vcb->chunks) {
@@ -771,10 +769,10 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
if ((c2->chunk_item->size - c2->used) >=
Vcb->superblock.node_size) {
if (find_metadata_address_in_chunk(Vcb, c2,
&mr->new_address)) {
c2->used += Vcb->superblock.node_size;
- space_list_subtract(c2, FALSE, mr->new_address,
Vcb->superblock.node_size, rollback);
+ space_list_subtract(c2, false, mr->new_address,
Vcb->superblock.node_size, rollback);
release_chunk_lock(c2, Vcb);
newchunk = c2;
- done = TRUE;
+ done = true;
break;
}
}
@@ -787,7 +785,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
// allocate new chunk if necessary
if (!done) {
- Status = alloc_chunk(Vcb, flags, &newchunk, FALSE);
+ Status = alloc_chunk(Vcb, flags, &newchunk, false);
if (!NT_SUCCESS(Status)) {
ERR("alloc_chunk returned %08x\n", Status);
@@ -807,7 +805,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
goto end;
} else {
newchunk->used += Vcb->superblock.node_size;
- space_list_subtract(newchunk, FALSE, mr->new_address,
Vcb->superblock.node_size, rollback);
+ space_list_subtract(newchunk, false, mr->new_address,
Vcb->superblock.node_size, rollback);
}
release_chunk_lock(newchunk, Vcb);
@@ -822,7 +820,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
metadata_reloc_ref* ref = CONTAINING_RECORD(le2, metadata_reloc_ref,
list_entry);
if (ref->parent) {
- UINT16 i;
+ uint16_t i;
internal_node* in =
(internal_node*)&ref->parent->data[1];
for (i = 0; i < ref->parent->data->num_items; i++) {
@@ -880,14 +878,14 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
searchkey.obj_type = TYPE_ROOT_ITEM;
searchkey.offset = 0xffffffffffffffff;
- Status = find_item(Vcb, Vcb->root_root, &tp,
&searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->root_root, &tp,
&searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
goto end;
}
if (tp.item->key.obj_id != searchkey.obj_id ||
tp.item->key.obj_type != searchkey.obj_type) {
- ERR("could not find ROOT_ITEM for tree
%llx\n", searchkey.obj_id);
+ ERR("could not find ROOT_ITEM for tree
%I64x\n", searchkey.obj_id);
Status = STATUS_INTERNAL_ERROR;
goto end;
}
@@ -924,8 +922,8 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
t3 = mr->t;
while (t3) {
- UINT8 h;
- BOOL inserted;
+ uint8_t h;
+ bool inserted;
tree* t4 = NULL;
// check if tree loaded more than once
@@ -955,11 +953,11 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
RemoveEntryList(&t3->list_entry_hash);
- t3->hash = calc_crc32c(0xffffffff,
(UINT8*)&t3->header.address, sizeof(UINT64));
+ t3->hash = calc_crc32c(0xffffffff,
(uint8_t*)&t3->header.address, sizeof(uint64_t));
h = t3->hash >> 24;
if (!Vcb->trees_ptrs[h]) {
- UINT8 h2 = h;
+ uint8_t h2 = h;
le2 = Vcb->trees_hash.Flink;
@@ -977,13 +975,13 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
} else
le2 = Vcb->trees_ptrs[h];
- inserted = FALSE;
+ inserted = false;
while (le2 != &Vcb->trees_hash) {
tree* t2 = CONTAINING_RECORD(le2, tree, list_entry_hash);
if (t2->hash >= t3->hash) {
InsertHeadList(le2->Blink, &t3->list_entry_hash);
- inserted = TRUE;
+ inserted = true;
break;
}
@@ -1027,7 +1025,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
t3 = t4;
}
- *((UINT32*)mr->data) = ~calc_crc32c(0xffffffff,
(UINT8*)&mr->data->fs_uuid, Vcb->superblock.node_size -
sizeof(mr->data->csum));
+ *((uint32_t*)mr->data) = ~calc_crc32c(0xffffffff,
(uint8_t*)&mr->data->fs_uuid, Vcb->superblock.node_size -
sizeof(mr->data->csum));
tw = ExAllocatePoolWithTag(PagedPool, sizeof(tree_write), ALLOC_TAG);
if (!tw) {
@@ -1038,12 +1036,12 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
tw->address = mr->new_address;
tw->length = Vcb->superblock.node_size;
- tw->data = (UINT8*)mr->data;
+ tw->data = (uint8_t*)mr->data;
if (IsListEmpty(&tree_writes))
InsertTailList(&tree_writes, &tw->list_entry);
else {
- BOOL inserted = FALSE;
+ bool inserted = false;
le2 = tree_writes.Flink;
while (le2 != &tree_writes) {
@@ -1051,7 +1049,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
if (tw2->address > tw->address) {
InsertHeadList(le2->Blink, &tw->list_entry);
- inserted = TRUE;
+ inserted = true;
break;
}
@@ -1067,7 +1065,7 @@ static NTSTATUS
write_metadata_items(_Requires_exclusive_lock_held_(_Curr_->tree
}
}
- Status = do_tree_writes(Vcb, &tree_writes, TRUE);
+ Status = do_tree_writes(Vcb, &tree_writes, true);
if (!NT_SUCCESS(Status)) {
ERR("do_tree_writes returned %08x\n", Status);
goto end;
@@ -1097,26 +1095,26 @@ end:
return Status;
}
-static NTSTATUS balance_metadata_chunk(device_extension* Vcb, chunk* c, BOOL* changed) {
+static NTSTATUS balance_metadata_chunk(device_extension* Vcb, chunk* c, bool* changed) {
KEY searchkey;
traverse_ptr tp;
NTSTATUS Status;
- BOOL b;
+ bool b;
LIST_ENTRY items, rollback;
- UINT32 loaded = 0;
+ uint32_t loaded = 0;
- TRACE("chunk %llx\n", c->offset);
+ TRACE("chunk %I64x\n", c->offset);
InitializeListHead(&rollback);
InitializeListHead(&items);
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
searchkey.obj_id = c->offset;
searchkey.obj_type = TYPE_METADATA_ITEM;
searchkey.offset = 0xffffffffffffffff;
- Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
goto end;
@@ -1129,17 +1127,17 @@ static NTSTATUS balance_metadata_chunk(device_extension* Vcb,
chunk* c, BOOL* ch
break;
if (tp.item->key.obj_id >= c->offset &&
(tp.item->key.obj_type == TYPE_EXTENT_ITEM || tp.item->key.obj_type ==
TYPE_METADATA_ITEM)) {
- BOOL tree = FALSE, skinny = FALSE;
+ bool tree = false, skinny = false;
if (tp.item->key.obj_type == TYPE_METADATA_ITEM &&
tp.item->size >= sizeof(EXTENT_ITEM)) {
- tree = TRUE;
- skinny = TRUE;
+ tree = true;
+ skinny = true;
} else if (tp.item->key.obj_type == TYPE_EXTENT_ITEM &&
tp.item->key.offset == Vcb->superblock.node_size &&
tp.item->size >= sizeof(EXTENT_ITEM)) {
EXTENT_ITEM* ei = (EXTENT_ITEM*)tp.item->data;
if (ei->flags & EXTENT_ITEM_TREE_BLOCK)
- tree = TRUE;
+ tree = true;
}
if (tree) {
@@ -1157,18 +1155,18 @@ static NTSTATUS balance_metadata_chunk(device_extension* Vcb,
chunk* c, BOOL* ch
}
}
- b = find_next_item(Vcb, &tp, &next_tp, FALSE, NULL);
+ b = find_next_item(Vcb, &tp, &next_tp, false, NULL);
if (b)
tp = next_tp;
} while (b);
if (IsListEmpty(&items)) {
- *changed = FALSE;
+ *changed = false;
Status = STATUS_SUCCESS;
goto end;
} else
- *changed = TRUE;
+ *changed = true;
Status = write_metadata_items(Vcb, &items, NULL, c, &rollback);
if (!NT_SUCCESS(Status)) {
@@ -1178,7 +1176,7 @@ static NTSTATUS balance_metadata_chunk(device_extension* Vcb, chunk*
c, BOOL* ch
Status = STATUS_SUCCESS;
- Vcb->need_write = TRUE;
+ Vcb->need_write = true;
end:
if (NT_SUCCESS(Status)) {
@@ -1219,7 +1217,7 @@ static NTSTATUS
data_reloc_add_tree_edr(_Requires_lock_held_(_Curr_->tree_lock)
traverse_ptr tp;
root* r = NULL;
metadata_reloc* mr;
- UINT64 last_tree = 0;
+ uint64_t last_tree = 0;
data_reloc_ref* ref;
le = Vcb->roots.Flink;
@@ -1235,7 +1233,7 @@ static NTSTATUS
data_reloc_add_tree_edr(_Requires_lock_held_(_Curr_->tree_lock)
}
if (!r) {
- ERR("could not find subvol %llx\n", edr->count);
+ ERR("could not find subvol %I64x\n", edr->count);
return STATUS_INTERNAL_ERROR;
}
@@ -1243,7 +1241,7 @@ static NTSTATUS
data_reloc_add_tree_edr(_Requires_lock_held_(_Curr_->tree_lock)
searchkey.obj_type = TYPE_EXTENT_DATA;
searchkey.offset = 0;
- Status = find_item(Vcb, r, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, r, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
return Status;
@@ -1252,10 +1250,10 @@ static NTSTATUS
data_reloc_add_tree_edr(_Requires_lock_held_(_Curr_->tree_lock)
if (tp.item->key.obj_id < searchkey.obj_id || (tp.item->key.obj_id ==
searchkey.obj_id && tp.item->key.obj_type < searchkey.obj_type)) {
traverse_ptr tp2;
- if (find_next_item(Vcb, &tp, &tp2, FALSE, NULL))
+ if (find_next_item(Vcb, &tp, &tp2, false, NULL))
tp = tp2;
else {
- ERR("could not find EXTENT_DATA for inode %llx in root %llx\n",
searchkey.obj_id, r->id);
+ ERR("could not find EXTENT_DATA for inode %I64x in root %I64x\n",
searchkey.obj_id, r->id);
return STATUS_INTERNAL_ERROR;
}
}
@@ -1301,7 +1299,7 @@ static NTSTATUS
data_reloc_add_tree_edr(_Requires_lock_held_(_Curr_->tree_lock)
}
}
- if (find_next_item(Vcb, &tp, &tp2, FALSE, NULL))
+ if (find_next_item(Vcb, &tp, &tp2, false, NULL))
tp = tp2;
else
break;
@@ -1315,9 +1313,9 @@ static NTSTATUS
add_data_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
NTSTATUS Status;
data_reloc* dr;
EXTENT_ITEM* ei;
- UINT16 len;
- UINT64 inline_rc;
- UINT8* ptr;
+ uint16_t len;
+ uint64_t inline_rc;
+ uint8_t* ptr;
dr = ExAllocatePoolWithTag(PagedPool, sizeof(data_reloc), ALLOC_TAG);
if (!dr) {
@@ -1353,26 +1351,26 @@ static NTSTATUS
add_data_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
inline_rc = 0;
len = tp->item->size - sizeof(EXTENT_ITEM);
- ptr = (UINT8*)tp->item->data + sizeof(EXTENT_ITEM);
+ ptr = (uint8_t*)tp->item->data + sizeof(EXTENT_ITEM);
while (len > 0) {
- UINT8 secttype = *ptr;
- UINT16 sectlen = secttype == TYPE_EXTENT_DATA_REF ? sizeof(EXTENT_DATA_REF) :
(secttype == TYPE_SHARED_DATA_REF ? sizeof(SHARED_DATA_REF) : 0);
+ uint8_t secttype = *ptr;
+ uint16_t sectlen = secttype == TYPE_EXTENT_DATA_REF ? sizeof(EXTENT_DATA_REF) :
(secttype == TYPE_SHARED_DATA_REF ? sizeof(SHARED_DATA_REF) : 0);
len--;
if (sectlen > len) {
- ERR("(%llx,%x,%llx): %x bytes left, expecting at least %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset, len,
sectlen);
+ ERR("(%I64x,%x,%I64x): %x bytes left, expecting at least %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset, len,
sectlen);
return STATUS_INTERNAL_ERROR;
}
if (sectlen == 0) {
- ERR("(%llx,%x,%llx): unrecognized extent type %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset,
secttype);
+ ERR("(%I64x,%x,%I64x): unrecognized extent type %x\n",
tp->item->key.obj_id, tp->item->key.obj_type, tp->item->key.offset,
secttype);
return STATUS_INTERNAL_ERROR;
}
if (secttype == TYPE_EXTENT_DATA_REF) {
- EXTENT_DATA_REF* edr = (EXTENT_DATA_REF*)(ptr + sizeof(UINT8));
+ EXTENT_DATA_REF* edr = (EXTENT_DATA_REF*)(ptr + sizeof(uint8_t));
inline_rc += edr->count;
@@ -1392,7 +1390,7 @@ static NTSTATUS
add_data_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
}
ref->type = TYPE_SHARED_DATA_REF;
- RtlCopyMemory(&ref->sdr, ptr + sizeof(UINT8),
sizeof(SHARED_DATA_REF));
+ RtlCopyMemory(&ref->sdr, ptr + sizeof(uint8_t),
sizeof(SHARED_DATA_REF));
inline_rc += ref->sdr.count;
Status = add_metadata_reloc_parent(Vcb, metadata_items, ref->sdr.offset,
&mr, rollback);
@@ -1412,13 +1410,13 @@ static NTSTATUS
add_data_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
len -= sectlen;
- ptr += sizeof(UINT8) + sectlen;
+ ptr += sizeof(uint8_t) + sectlen;
}
if (inline_rc < ei->refcount) { // look for non-inline entries
traverse_ptr tp2 = *tp, next_tp;
- while (find_next_item(Vcb, &tp2, &next_tp, FALSE, NULL)) {
+ while (find_next_item(Vcb, &tp2, &next_tp, false, NULL)) {
tp2 = next_tp;
if (tp2.item->key.obj_id == tp->item->key.obj_id) {
@@ -1434,7 +1432,7 @@ static NTSTATUS
add_data_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
ERR("delete_tree_item returned %08x\n", Status);
return Status;
}
- } else if (tp2.item->key.obj_type == TYPE_SHARED_DATA_REF &&
tp2.item->size >= sizeof(UINT32)) {
+ } else if (tp2.item->key.obj_type == TYPE_SHARED_DATA_REF &&
tp2.item->size >= sizeof(uint32_t)) {
metadata_reloc* mr;
data_reloc_ref* ref;
@@ -1446,7 +1444,7 @@ static NTSTATUS
add_data_reloc(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
ref->type = TYPE_SHARED_DATA_REF;
ref->sdr.offset = tp2.item->key.offset;
- ref->sdr.count = *((UINT32*)tp2.item->data);
+ ref->sdr.count = *((uint32_t*)tp2.item->data);
Status = add_metadata_reloc_parent(Vcb, metadata_items,
ref->sdr.offset, &mr, rollback);
if (!NT_SUCCESS(Status)) {
@@ -1486,7 +1484,7 @@ static void sort_data_reloc_refs(data_reloc* dr) {
while (!IsListEmpty(&dr->refs)) {
data_reloc_ref* ref = CONTAINING_RECORD(RemoveHeadList(&dr->refs),
data_reloc_ref, list_entry);
- BOOL inserted = FALSE;
+ bool inserted = false;
if (ref->type == TYPE_EXTENT_DATA_REF)
ref->hash = get_extent_data_ref_hash2(ref->edr.root, ref->edr.objid,
ref->edr.offset);
@@ -1499,7 +1497,7 @@ static void sort_data_reloc_refs(data_reloc* dr) {
if (ref->type < ref2->type || (ref->type == ref2->type
&& ref->hash > ref2->hash)) {
InsertHeadList(le->Blink, &ref->list_entry);
- inserted = TRUE;
+ inserted = true;
break;
}
@@ -1538,12 +1536,12 @@ static void sort_data_reloc_refs(data_reloc* dr) {
static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, data_reloc* dr) {
NTSTATUS Status;
LIST_ENTRY* le;
- UINT64 rc = 0;
- UINT16 inline_len;
- BOOL all_inline = TRUE;
+ uint64_t rc = 0;
+ uint16_t inline_len;
+ bool all_inline = true;
data_reloc_ref* first_noninline = NULL;
EXTENT_ITEM* ei;
- UINT8* ptr;
+ uint8_t* ptr;
inline_len = sizeof(EXTENT_ITEM);
@@ -1552,7 +1550,7 @@ static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_
le = dr->refs.Flink;
while (le != &dr->refs) {
data_reloc_ref* ref = CONTAINING_RECORD(le, data_reloc_ref, list_entry);
- UINT16 extlen = 0;
+ uint16_t extlen = 0;
if (ref->type == TYPE_EXTENT_DATA_REF) {
extlen += sizeof(EXTENT_DATA_REF);
@@ -1564,7 +1562,7 @@ static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_
if (all_inline) {
if ((ULONG)(inline_len + 1 + extlen) > (Vcb->superblock.node_size
>> 2)) {
- all_inline = FALSE;
+ all_inline = false;
first_noninline = ref;
} else
inline_len += extlen + 1;
@@ -1582,7 +1580,7 @@ static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_
ei->refcount = rc;
ei->generation = dr->ei->generation;
ei->flags = dr->ei->flags;
- ptr = (UINT8*)&ei[1];
+ ptr = (uint8_t*)&ei[1];
le = dr->refs.Flink;
while (le != &dr->refs) {
@@ -1641,9 +1639,9 @@ static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_
return Status;
}
} else if (ref->type == TYPE_SHARED_DATA_REF) {
- UINT32* sdr;
+ uint32_t* sdr;
- sdr = ExAllocatePoolWithTag(PagedPool, sizeof(UINT32), ALLOC_TAG);
+ sdr = ExAllocatePoolWithTag(PagedPool, sizeof(uint32_t), ALLOC_TAG);
if (!sdr) {
ERR("out of memory\n");
return STATUS_INSUFFICIENT_RESOURCES;
@@ -1651,7 +1649,7 @@ static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_
*sdr = ref->sdr.count;
- Status = insert_tree_item(Vcb, Vcb->extent_root, dr->new_address,
TYPE_SHARED_DATA_REF, ref->parent->new_address, sdr, sizeof(UINT32), NULL, NULL);
+ Status = insert_tree_item(Vcb, Vcb->extent_root, dr->new_address,
TYPE_SHARED_DATA_REF, ref->parent->new_address, sdr, sizeof(uint32_t), NULL, NULL);
if (!NT_SUCCESS(Status)) {
ERR("insert_tree_item returned %08x\n", Status);
return Status;
@@ -1665,29 +1663,29 @@ static NTSTATUS
add_data_reloc_extent_item(_Requires_exclusive_lock_held_(_Curr_
return STATUS_SUCCESS;
}
-static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c, BOOL* changed) {
+static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c, bool* changed) {
KEY searchkey;
traverse_ptr tp;
NTSTATUS Status;
- BOOL b;
+ bool b;
LIST_ENTRY items, metadata_items, rollback, *le;
- UINT64 loaded = 0, num_loaded = 0;
+ uint64_t loaded = 0, num_loaded = 0;
chunk* newchunk = NULL;
- UINT8* data = NULL;
+ uint8_t* data = NULL;
- TRACE("chunk %llx\n", c->offset);
+ TRACE("chunk %I64x\n", c->offset);
InitializeListHead(&rollback);
InitializeListHead(&items);
InitializeListHead(&metadata_items);
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
searchkey.obj_id = c->offset;
searchkey.obj_type = TYPE_EXTENT_ITEM;
searchkey.offset = 0xffffffffffffffff;
- Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
goto end;
@@ -1700,13 +1698,13 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
break;
if (tp.item->key.obj_id >= c->offset && tp.item->key.obj_type
== TYPE_EXTENT_ITEM) {
- BOOL tree = FALSE;
+ bool tree = false;
if (tp.item->key.obj_type == TYPE_EXTENT_ITEM && tp.item->size
>= sizeof(EXTENT_ITEM)) {
EXTENT_ITEM* ei = (EXTENT_ITEM*)tp.item->data;
if (ei->flags & EXTENT_ITEM_TREE_BLOCK)
- tree = TRUE;
+ tree = true;
}
if (!tree) {
@@ -1725,18 +1723,18 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
}
}
- b = find_next_item(Vcb, &tp, &next_tp, FALSE, NULL);
+ b = find_next_item(Vcb, &tp, &next_tp, false, NULL);
if (b)
tp = next_tp;
} while (b);
if (IsListEmpty(&items)) {
- *changed = FALSE;
+ *changed = false;
Status = STATUS_SUCCESS;
goto end;
} else
- *changed = TRUE;
+ *changed = true;
data = ExAllocatePoolWithTag(PagedPool, BALANCE_UNIT, ALLOC_TAG);
if (!data) {
@@ -1748,27 +1746,27 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
le = items.Flink;
while (le != &items) {
data_reloc* dr = CONTAINING_RECORD(le, data_reloc, list_entry);
- BOOL done = FALSE;
+ bool done = false;
LIST_ENTRY* le2;
- UINT32* csum;
+ uint32_t* csum;
RTL_BITMAP bmp;
ULONG* bmparr;
- ULONG runlength, index, lastoff;
+ ULONG bmplen, runlength, index, lastoff;
if (newchunk) {
acquire_chunk_lock(newchunk, Vcb);
if (find_data_address_in_chunk(Vcb, newchunk, dr->size,
&dr->new_address)) {
newchunk->used += dr->size;
- space_list_subtract(newchunk, FALSE, dr->new_address, dr->size,
&rollback);
- done = TRUE;
+ space_list_subtract(newchunk, false, dr->new_address, dr->size,
&rollback);
+ done = true;
}
release_chunk_lock(newchunk, Vcb);
}
if (!done) {
- ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
le2 = Vcb->chunks.Flink;
while (le2 != &Vcb->chunks) {
@@ -1780,10 +1778,10 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
if ((c2->chunk_item->size - c2->used) >= dr->size) {
if (find_data_address_in_chunk(Vcb, c2, dr->size,
&dr->new_address)) {
c2->used += dr->size;
- space_list_subtract(c2, FALSE, dr->new_address,
dr->size, &rollback);
+ space_list_subtract(c2, false, dr->new_address,
dr->size, &rollback);
release_chunk_lock(c2, Vcb);
newchunk = c2;
- done = TRUE;
+ done = true;
break;
}
}
@@ -1796,7 +1794,7 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
// allocate new chunk if necessary
if (!done) {
- Status = alloc_chunk(Vcb, Vcb->data_flags, &newchunk, FALSE);
+ Status = alloc_chunk(Vcb, Vcb->data_flags, &newchunk, false);
if (!NT_SUCCESS(Status)) {
ERR("alloc_chunk returned %08x\n", Status);
@@ -1816,7 +1814,7 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
goto end;
} else {
newchunk->used += dr->size;
- space_list_subtract(newchunk, FALSE, dr->new_address, dr->size,
&rollback);
+ space_list_subtract(newchunk, false, dr->new_address, dr->size,
&rollback);
}
release_chunk_lock(newchunk, Vcb);
@@ -1827,14 +1825,16 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
dr->newchunk = newchunk;
- bmparr = ExAllocatePoolWithTag(PagedPool, (ULONG)sector_align((dr->size /
Vcb->superblock.sector_size) + 1, sizeof(ULONG)), ALLOC_TAG);
+ bmplen = (ULONG)(dr->size / Vcb->superblock.sector_size);
+
+ bmparr = ExAllocatePoolWithTag(PagedPool, (ULONG)sector_align(bmplen + 1,
sizeof(ULONG)), ALLOC_TAG);
if (!bmparr) {
ERR("out of memory\n");
Status = STATUS_INSUFFICIENT_RESOURCES;
goto end;
}
- csum = ExAllocatePoolWithTag(PagedPool, (ULONG)(dr->size * sizeof(UINT32) /
Vcb->superblock.sector_size), ALLOC_TAG);
+ csum = ExAllocatePoolWithTag(PagedPool, (ULONG)(dr->size * sizeof(uint32_t) /
Vcb->superblock.sector_size), ALLOC_TAG);
if (!csum) {
ERR("out of memory\n");
ExFreePool(bmparr);
@@ -1842,14 +1842,14 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
goto end;
}
- RtlInitializeBitMap(&bmp, bmparr, (ULONG)(dr->size /
Vcb->superblock.sector_size));
+ RtlInitializeBitMap(&bmp, bmparr, bmplen);
RtlSetAllBits(&bmp); // 1 = no csum, 0 = csum
searchkey.obj_id = EXTENT_CSUM_ID;
searchkey.obj_type = TYPE_EXTENT_CSUM;
searchkey.offset = dr->address;
- Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, FALSE,
NULL);
+ Status = find_item(Vcb, Vcb->checksum_root, &tp, &searchkey, false,
NULL);
if (!NT_SUCCESS(Status) && Status != STATUS_NOT_FOUND) {
ERR("find_item returned %08x\n", Status);
ExFreePool(csum);
@@ -1864,13 +1864,13 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
if (tp.item->key.obj_type == TYPE_EXTENT_CSUM) {
if (tp.item->key.offset >= dr->address + dr->size)
break;
- else if (tp.item->size >= sizeof(UINT32) &&
tp.item->key.offset + (tp.item->size * Vcb->superblock.sector_size /
sizeof(UINT32)) >= dr->address) {
- UINT64 cs = max(dr->address, tp.item->key.offset);
- UINT64 ce = min(dr->address + dr->size,
tp.item->key.offset + (tp.item->size * Vcb->superblock.sector_size /
sizeof(UINT32)));
+ else if (tp.item->size >= sizeof(uint32_t) &&
tp.item->key.offset + (tp.item->size * Vcb->superblock.sector_size /
sizeof(uint32_t)) >= dr->address) {
+ uint64_t cs = max(dr->address, tp.item->key.offset);
+ uint64_t ce = min(dr->address + dr->size,
tp.item->key.offset + (tp.item->size * Vcb->superblock.sector_size /
sizeof(uint32_t)));
RtlCopyMemory(csum + ((cs - dr->address) /
Vcb->superblock.sector_size),
- tp.item->data + ((cs - tp.item->key.offset) *
sizeof(UINT32) / Vcb->superblock.sector_size),
- (ULONG)((ce - cs) * sizeof(UINT32) /
Vcb->superblock.sector_size));
+ tp.item->data + ((cs - tp.item->key.offset) *
sizeof(uint32_t) / Vcb->superblock.sector_size),
+ (ULONG)((ce - cs) * sizeof(uint32_t) /
Vcb->superblock.sector_size));
RtlClearBits(&bmp, (ULONG)((cs - dr->address) /
Vcb->superblock.sector_size), (ULONG)((ce - cs) / Vcb->superblock.sector_size));
@@ -1879,17 +1879,27 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
}
}
- if (find_next_item(Vcb, &tp, &next_tp, FALSE, NULL))
+ if (find_next_item(Vcb, &tp, &next_tp, false, NULL))
tp = next_tp;
else
break;
- } while (TRUE);
+ } while (true);
}
lastoff = 0;
runlength = RtlFindFirstRunClear(&bmp, &index);
while (runlength != 0) {
+ if (index >= bmplen)
+ break;
+
+ if (index + runlength >= bmplen) {
+ runlength = bmplen - index;
+
+ if (runlength == 0)
+ break;
+ }
+
if (index > lastoff) {
ULONG off = lastoff;
ULONG size = index - lastoff;
@@ -1903,8 +1913,8 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
else
rl = size;
- Status = read_data(Vcb, dr->address + (off *
Vcb->superblock.sector_size), rl * Vcb->superblock.sector_size, NULL, FALSE, data,
- c, NULL, NULL, 0, FALSE, NormalPagePriority);
+ Status = read_data(Vcb, dr->address + (off *
Vcb->superblock.sector_size), rl * Vcb->superblock.sector_size, NULL, false, data,
+ c, NULL, NULL, 0, false, NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("read_data returned %08x\n", Status);
ExFreePool(csum);
@@ -1913,7 +1923,7 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
}
Status = write_data_complete(Vcb, dr->new_address + (off *
Vcb->superblock.sector_size), data, rl * Vcb->superblock.sector_size,
- NULL, newchunk, FALSE, 0,
NormalPagePriority);
+ NULL, newchunk, false, 0,
NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("write_data_complete returned %08x\n", Status);
ExFreePool(csum);
@@ -1938,8 +1948,8 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
else
rl = runlength;
- Status = read_data(Vcb, dr->address + (index *
Vcb->superblock.sector_size), rl * Vcb->superblock.sector_size, &csum[index],
FALSE, data,
- c, NULL, NULL, 0, FALSE, NormalPagePriority);
+ Status = read_data(Vcb, dr->address + (index *
Vcb->superblock.sector_size), rl * Vcb->superblock.sector_size, &csum[index],
false, data,
+ c, NULL, NULL, 0, false, NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("read_data returned %08x\n", Status);
ExFreePool(csum);
@@ -1948,7 +1958,7 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
}
Status = write_data_complete(Vcb, dr->new_address + (index *
Vcb->superblock.sector_size), data, rl * Vcb->superblock.sector_size,
- NULL, newchunk, FALSE, 0,
NormalPagePriority);
+ NULL, newchunk, false, 0,
NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("write_data_complete returned %08x\n", Status);
ExFreePool(csum);
@@ -1980,15 +1990,15 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk*
c, BOOL* change
else
rl = size;
- Status = read_data(Vcb, dr->address + (off *
Vcb->superblock.sector_size), rl * Vcb->superblock.sector_size, NULL, FALSE, data,
- c, NULL, NULL, 0, FALSE, NormalPagePriority);
+ Status = read_data(Vcb, dr->address + (off *
Vcb->superblock.sector_size), rl * Vcb->superblock.sector_size, NULL, false, data,
+ c, NULL, NULL, 0, false, NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("read_data returned %08x\n", Status);
goto end;
}
Status = write_data_complete(Vcb, dr->new_address + (off *
Vcb->superblock.sector_size), data, rl * Vcb->superblock.sector_size,
- NULL, newchunk, FALSE, 0,
NormalPagePriority);
+ NULL, newchunk, false, 0,
NormalPagePriority);
if (!NT_SUCCESS(Status)) {
ERR("write_data_complete returned %08x\n", Status);
goto end;
@@ -2050,7 +2060,7 @@ static NTSTATUS balance_data_chunk(device_extension* Vcb, chunk* c,
BOOL* change
Status = STATUS_SUCCESS;
- Vcb->need_write = TRUE;
+ Vcb->need_write = true;
end:
if (NT_SUCCESS(Status)) {
@@ -2062,7 +2072,7 @@ end:
if (c2->cache) {
LIST_ENTRY* le2;
- ExAcquireResourceExclusiveLite(c2->cache->Header.Resource, TRUE);
+ ExAcquireResourceExclusiveLite(c2->cache->Header.Resource, true);
le2 = c2->cache->extents.Flink;
while (le2 != &c2->cache->extents) {
@@ -2113,7 +2123,7 @@ end:
struct _fcb* fcb = CONTAINING_RECORD(le, struct _fcb, list_entry_all);
LIST_ENTRY* le2;
- ExAcquireResourceExclusiveLite(fcb->Header.Resource, TRUE);
+ ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
le2 = fcb->extents.Flink;
while (le2 != &fcb->extents) {
@@ -2183,7 +2193,7 @@ end:
return Status;
}
-static __inline UINT64 get_chunk_dup_type(chunk* c) {
+static __inline uint64_t get_chunk_dup_type(chunk* c) {
if (c->chunk_item->type & BLOCK_FLAG_RAID0)
return BLOCK_FLAG_RAID0;
else if (c->chunk_item->type & BLOCK_FLAG_RAID1)
@@ -2200,42 +2210,42 @@ static __inline UINT64 get_chunk_dup_type(chunk* c) {
return BLOCK_FLAG_SINGLE;
}
-static BOOL should_balance_chunk(device_extension* Vcb, UINT8 sort, chunk* c) {
+static bool should_balance_chunk(device_extension* Vcb, uint8_t sort, chunk* c) {
btrfs_balance_opts* opts;
opts = &Vcb->balance.opts[sort];
if (!(opts->flags & BTRFS_BALANCE_OPTS_ENABLED))
- return FALSE;
+ return false;
if (opts->flags & BTRFS_BALANCE_OPTS_PROFILES) {
- UINT64 type = get_chunk_dup_type(c);
+ uint64_t type = get_chunk_dup_type(c);
if (!(type & opts->profiles))
- return FALSE;
+ return false;
}
if (opts->flags & BTRFS_BALANCE_OPTS_DEVID) {
- UINT16 i;
+ uint16_t i;
CHUNK_ITEM_STRIPE* cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
- BOOL b = FALSE;
+ bool b = false;
for (i = 0; i < c->chunk_item->num_stripes; i++) {
if (cis[i].dev_id == opts->devid) {
- b = TRUE;
+ b = true;
break;
}
}
if (!b)
- return FALSE;
+ return false;
}
if (opts->flags & BTRFS_BALANCE_OPTS_DRANGE) {
- UINT16 i, factor;
- UINT64 physsize;
+ uint16_t i, factor;
+ uint64_t physsize;
CHUNK_ITEM_STRIPE* cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
- BOOL b = FALSE;
+ bool b = false;
if (c->chunk_item->type & BLOCK_FLAG_RAID0)
factor = c->chunk_item->num_stripes;
@@ -2253,44 +2263,44 @@ static BOOL should_balance_chunk(device_extension* Vcb, UINT8
sort, chunk* c) {
for (i = 0; i < c->chunk_item->num_stripes; i++) {
if (cis[i].offset < opts->drange_end && cis[i].offset +
physsize >= opts->drange_start &&
(!(opts->flags & BTRFS_BALANCE_OPTS_DEVID) || cis[i].dev_id ==
opts->devid)) {
- b = TRUE;
+ b = true;
break;
}
}
if (!b)
- return FALSE;
+ return false;
}
if (opts->flags & BTRFS_BALANCE_OPTS_VRANGE) {
if (c->offset + c->chunk_item->size <= opts->vrange_start ||
c->offset > opts->vrange_end)
- return FALSE;
+ return false;
}
if (opts->flags & BTRFS_BALANCE_OPTS_STRIPES) {
if (c->chunk_item->num_stripes < opts->stripes_start ||
c->chunk_item->num_stripes < opts->stripes_end)
- return FALSE;
+ return false;
}
if (opts->flags & BTRFS_BALANCE_OPTS_USAGE) {
- UINT64 usage = c->used * 100 / c->chunk_item->size;
+ uint64_t usage = c->used * 100 / c->chunk_item->size;
// usage == 0 should mean completely empty, not just that usage rounds to 0%
if (c->used > 0 && usage == 0)
usage = 1;
if (usage < opts->usage_start || usage > opts->usage_end)
- return FALSE;
+ return false;
}
if (opts->flags & BTRFS_BALANCE_OPTS_CONVERT && opts->flags &
BTRFS_BALANCE_OPTS_SOFT) {
- UINT64 type = get_chunk_dup_type(c);
+ uint64_t type = get_chunk_dup_type(c);
if (type == opts->convert)
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
static void copy_balance_args(btrfs_balance_opts* opts, BALANCE_ARGS* args) {
@@ -2338,8 +2348,8 @@ static void copy_balance_args(btrfs_balance_opts* opts,
BALANCE_ARGS* args) {
if (opts->flags & BTRFS_BALANCE_OPTS_LIMIT) {
if (args->limit_start == 0) {
args->flags |= BALANCE_ARGS_FLAGS_LIMIT_RANGE;
- args->limit_start = (UINT32)opts->limit_start;
- args->limit_end = (UINT32)opts->limit_end;
+ args->limit_start = (uint32_t)opts->limit_start;
+ args->limit_end = (uint32_t)opts->limit_end;
} else {
args->flags |= BALANCE_ARGS_FLAGS_LIMIT;
args->limit = opts->limit_end;
@@ -2363,9 +2373,9 @@ static NTSTATUS add_balance_item(device_extension* Vcb) {
searchkey.obj_type = TYPE_TEMP_ITEM;
searchkey.offset = 0;
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
- Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
goto end;
@@ -2435,9 +2445,9 @@ static NTSTATUS remove_balance_item(device_extension* Vcb) {
searchkey.obj_type = TYPE_TEMP_ITEM;
searchkey.offset = 0;
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
- Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
goto end;
@@ -2479,12 +2489,12 @@ static void load_balance_args(btrfs_balance_opts* opts,
BALANCE_ARGS* args) {
opts->flags |= BTRFS_BALANCE_OPTS_USAGE;
opts->usage_start = 0;
- opts->usage_end = (UINT8)args->usage;
+ opts->usage_end = (uint8_t)args->usage;
} else if (args->flags & BALANCE_ARGS_FLAGS_USAGE_RANGE) {
opts->flags |= BTRFS_BALANCE_OPTS_USAGE;
- opts->usage_start = (UINT8)args->usage_start;
- opts->usage_end = (UINT8)args->usage_end;
+ opts->usage_start = (uint8_t)args->usage_start;
+ opts->usage_end = (uint8_t)args->usage_end;
}
if (args->flags & BALANCE_ARGS_FLAGS_DEVID) {
@@ -2519,8 +2529,8 @@ static void load_balance_args(btrfs_balance_opts* opts,
BALANCE_ARGS* args) {
if (args->flags & BALANCE_ARGS_FLAGS_STRIPES_RANGE) {
opts->flags |= BTRFS_BALANCE_OPTS_STRIPES;
- opts->stripes_start = (UINT16)args->stripes_start;
- opts->stripes_end = (UINT16)args->stripes_end;
+ opts->stripes_start = (uint16_t)args->stripes_start;
+ opts->stripes_end = (uint16_t)args->stripes_end;
}
if (args->flags & BALANCE_ARGS_FLAGS_CONVERT) {
@@ -2546,7 +2556,7 @@ static NTSTATUS remove_superblocks(device* dev) {
RtlZeroMemory(sb, sizeof(superblock));
while (superblock_addrs[i] > 0 && dev->devitem.num_bytes >=
superblock_addrs[i] + sizeof(superblock)) {
- Status = write_data_phys(dev->devobj, superblock_addrs[i], sb,
sizeof(superblock));
+ Status = write_data_phys(dev->devobj, dev->fileobj, superblock_addrs[i],
sb, sizeof(superblock));
if (!NT_SUCCESS(Status)) {
ExFreePool(sb);
@@ -2587,7 +2597,7 @@ static NTSTATUS
finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tr
searchkey.obj_type = TYPE_DEV_ITEM;
searchkey.offset = dev->devitem.dev_id;
- Status = find_item(Vcb, Vcb->chunk_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->chunk_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
return Status;
@@ -2608,7 +2618,7 @@ static NTSTATUS
finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tr
searchkey.obj_type = TYPE_DEV_STATS;
searchkey.offset = dev->devitem.dev_id;
- Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
return Status;
@@ -2655,7 +2665,7 @@ static NTSTATUS
finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tr
if (dev->devobj) {
pdo_device_extension* pdode = vde->pdode;
- ExAcquireResourceExclusiveLite(&pdode->child_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&pdode->child_lock, true);
le = pdode->children.Flink;
while (le != &pdode->children) {
@@ -2676,7 +2686,7 @@ static NTSTATUS
finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tr
else {
MOUNTDEV_NAME mdn;
- Status = dev_ioctl(dev->devobj,
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, &mdn, sizeof(MOUNTDEV_NAME), TRUE, NULL);
+ Status = dev_ioctl(dev->devobj,
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, &mdn, sizeof(MOUNTDEV_NAME), true, NULL);
if (!NT_SUCCESS(Status) && Status !=
STATUS_BUFFER_OVERFLOW)
ERR("IOCTL_MOUNTDEV_QUERY_DEVICE_NAME returned
%08x\n", Status);
else {
@@ -2687,7 +2697,7 @@ static NTSTATUS
finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tr
if (!mdn2)
ERR("out of memory\n");
else {
- Status = dev_ioctl(dev->devobj,
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, mdn2, mdnsize, TRUE, NULL);
+ Status = dev_ioctl(dev->devobj,
IOCTL_MOUNTDEV_QUERY_DEVICE_NAME, NULL, 0, mdn2, mdnsize, true, NULL);
if (!NT_SUCCESS(Status))
ERR("IOCTL_MOUNTDEV_QUERY_DEVICE_NAME returned
%08x\n", Status);
else {
@@ -2757,14 +2767,14 @@ static NTSTATUS
finish_removing_device(_Requires_exclusive_lock_held_(_Curr_->tr
ExFreePool(dev);
if (Vcb->trim) {
- Vcb->trim = FALSE;
+ Vcb->trim = false;
le = Vcb->devices.Flink;
while (le != &Vcb->devices) {
device* dev2 = CONTAINING_RECORD(le, device, list_entry);
if (dev2->trim) {
- Vcb->trim = TRUE;
+ Vcb->trim = true;
break;
}
@@ -2784,8 +2794,8 @@ static void
trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_ex
KEY searchkey;
traverse_ptr tp;
NTSTATUS Status;
- BOOL b;
- UINT64 lastoff = 0x100000; // don't TRIM the first megabyte, in case someone has
been daft enough to install GRUB there
+ bool b;
+ uint64_t lastoff = 0x100000; // don't TRIM the first megabyte, in case someone
has been daft enough to install GRUB there
LIST_ENTRY* le;
dev->num_trim_entries = 0;
@@ -2794,7 +2804,7 @@ static void
trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_ex
searchkey.obj_type = TYPE_DEV_EXTENT;
searchkey.offset = 0;
- Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
return;
@@ -2812,12 +2822,12 @@ static void
trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_ex
lastoff = tp.item->key.offset + de->length;
} else {
- ERR("(%llx,%x,%llx) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DEV_EXTENT));
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DEV_EXTENT));
return;
}
}
- b = find_next_item(Vcb, &tp, &next_tp, FALSE, NULL);
+ b = find_next_item(Vcb, &tp, &next_tp, false, NULL);
if (b) {
tp = next_tp;
@@ -2832,7 +2842,7 @@ static void
trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_ex
if (dev->num_trim_entries == 0)
return;
- datalen = (ULONG)sector_align(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES),
sizeof(UINT64)) + (dev->num_trim_entries * sizeof(DEVICE_DATA_SET_RANGE));
+ datalen = (ULONG)sector_align(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES),
sizeof(uint64_t)) + (dev->num_trim_entries * sizeof(DEVICE_DATA_SET_RANGE));
dmdsa = ExAllocatePoolWithTag(PagedPool, datalen, ALLOC_TAG);
if (!dmdsa) {
@@ -2845,10 +2855,10 @@ static void
trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_ex
dmdsa->Flags = DEVICE_DSM_FLAG_TRIM_NOT_FS_ALLOCATED;
dmdsa->ParameterBlockOffset = 0;
dmdsa->ParameterBlockLength = 0;
- dmdsa->DataSetRangesOffset =
(ULONG)sector_align(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES), sizeof(UINT64));
+ dmdsa->DataSetRangesOffset =
(ULONG)sector_align(sizeof(DEVICE_MANAGE_DATA_SET_ATTRIBUTES), sizeof(uint64_t));
dmdsa->DataSetRangesLength = dev->num_trim_entries *
sizeof(DEVICE_DATA_SET_RANGE);
- ranges = (DEVICE_DATA_SET_RANGE*)((UINT8*)dmdsa + dmdsa->DataSetRangesOffset);
+ ranges = (DEVICE_DATA_SET_RANGE*)((uint8_t*)dmdsa + dmdsa->DataSetRangesOffset);
i = 0;
le = dev->trim_list.Flink;
@@ -2862,7 +2872,7 @@ static void
trim_unalloc_space(_Requires_lock_held_(_Curr_->tree_lock) device_ex
le = le->Flink;
}
- Status = dev_ioctl(dev->devobj, IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES, dmdsa,
datalen, NULL, 0, TRUE, NULL);
+ Status = dev_ioctl(dev->devobj, IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES, dmdsa,
datalen, NULL, 0, true, NULL);
if (!NT_SUCCESS(Status))
WARN("IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES returned %08x\n",
Status);
@@ -2877,20 +2887,20 @@ end:
dev->num_trim_entries = 0;
}
-static NTSTATUS try_consolidation(device_extension* Vcb, UINT64 flags, chunk** newchunk)
{
+static NTSTATUS try_consolidation(device_extension* Vcb, uint64_t flags, chunk**
newchunk) {
NTSTATUS Status;
- BOOL changed;
+ bool changed;
LIST_ENTRY* le;
chunk* rc;
// FIXME - allow with metadata chunks?
- while (TRUE) {
+ while (true) {
rc = NULL;
- ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
- ExAcquireResourceSharedLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->chunk_lock, true);
// choose the least-used chunk we haven't looked at yet
le = Vcb->chunks.Flink;
@@ -2917,26 +2927,26 @@ static NTSTATUS try_consolidation(device_extension* Vcb, UINT64
flags, chunk** n
}
rc->list_entry_balance.Flink = (LIST_ENTRY*)1; // so it doesn't get
dropped
- rc->reloc = TRUE;
+ rc->reloc = true;
ExReleaseResourceLite(&Vcb->tree_lock);
do {
- changed = FALSE;
+ changed = false;
Status = balance_data_chunk(Vcb, rc, &changed);
if (!NT_SUCCESS(Status)) {
ERR("balance_data_chunk returned %08x\n", Status);
Vcb->balance.status = Status;
rc->list_entry_balance.Flink = NULL;
- rc->reloc = FALSE;
+ rc->reloc = false;
return Status;
}
- KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode,
FALSE, NULL);
+ KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode,
false, NULL);
if (Vcb->readonly)
- Vcb->balance.stopping = TRUE;
+ Vcb->balance.stopping = true;
if (Vcb->balance.stopping)
return STATUS_SUCCESS;
@@ -2944,8 +2954,8 @@ static NTSTATUS try_consolidation(device_extension* Vcb, UINT64
flags, chunk** n
rc->list_entry_balance.Flink = NULL;
- rc->changed = TRUE;
- rc->space_changed = TRUE;
+ rc->changed = true;
+ rc->space_changed = true;
rc->balance_num = Vcb->balance.balance_num;
Status = do_write(Vcb, NULL);
@@ -2957,9 +2967,9 @@ static NTSTATUS try_consolidation(device_extension* Vcb, UINT64
flags, chunk** n
free_trees(Vcb);
}
- ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
- Status = alloc_chunk(Vcb, flags, &rc, TRUE);
+ Status = alloc_chunk(Vcb, flags, &rc, true);
ExReleaseResourceLite(&Vcb->chunk_lock);
@@ -2987,16 +2997,16 @@ static NTSTATUS regenerate_space_list(device_extension* Vcb,
device* dev) {
le = Vcb->chunks.Flink;
while (le != &Vcb->chunks) {
- UINT16 n;
+ uint16_t n;
chunk* c = CONTAINING_RECORD(le, chunk, list_entry);
CHUNK_ITEM_STRIPE* cis = (CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
for (n = 0; n < c->chunk_item->num_stripes; n++) {
- UINT64 stripe_size = 0;
+ uint64_t stripe_size = 0;
if (cis[n].dev_id == dev->devitem.dev_id) {
if (stripe_size == 0) {
- UINT16 factor;
+ uint16_t factor;
if (c->chunk_item->type & BLOCK_FLAG_RAID0)
factor = c->chunk_item->num_stripes;
@@ -3023,22 +3033,18 @@ static NTSTATUS regenerate_space_list(device_extension* Vcb,
device* dev) {
}
_Function_class_(KSTART_ROUTINE)
-#ifndef __REACTOS__
-void balance_thread(void* context) {
-#else
-void NTAPI balance_thread(void* context) {
-#endif
+void __stdcall balance_thread(void* context) {
device_extension* Vcb = (device_extension*)context;
LIST_ENTRY chunks;
LIST_ENTRY* le;
- UINT64 num_chunks[3], okay_metadata_chunks = 0, okay_data_chunks = 0,
okay_system_chunks = 0;
- UINT64 old_data_flags = 0, old_metadata_flags = 0, old_system_flags = 0;
+ uint64_t num_chunks[3], okay_metadata_chunks = 0, okay_data_chunks = 0,
okay_system_chunks = 0;
+ uint64_t old_data_flags = 0, old_metadata_flags = 0, old_system_flags = 0;
NTSTATUS Status;
Vcb->balance.balance_num++;
- Vcb->balance.stopping = FALSE;
- KeInitializeEvent(&Vcb->balance.finished, NotificationEvent, FALSE);
+ Vcb->balance.stopping = false;
+ KeInitializeEvent(&Vcb->balance.finished, NotificationEvent, false);
if (Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_ENABLED
&& Vcb->balance.opts[BALANCE_OPTS_DATA].flags & BTRFS_BALANCE_OPTS_CONVERT)
{
old_data_flags = Vcb->data_flags;
@@ -3094,17 +3100,17 @@ void NTAPI balance_thread(void* context) {
}
}
- KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, FALSE,
NULL);
+ KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode, false,
NULL);
if (Vcb->balance.stopping)
goto end;
- ExAcquireResourceSharedLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->chunk_lock, true);
le = Vcb->chunks.Flink;
while (le != &Vcb->chunks) {
chunk* c = CONTAINING_RECORD(le, chunk, list_entry);
- UINT8 sort;
+ uint8_t sort;
acquire_chunk_lock(c, Vcb);
@@ -3115,7 +3121,7 @@ void NTAPI balance_thread(void* context) {
else if (c->chunk_item->type & BLOCK_FLAG_SYSTEM)
sort = BALANCE_OPTS_SYSTEM;
else {
- ERR("unexpected chunk type %llx\n", c->chunk_item->type);
+ ERR("unexpected chunk type %I64x\n", c->chunk_item->type);
release_chunk_lock(c, Vcb);
break;
}
@@ -3155,13 +3161,13 @@ void NTAPI balance_thread(void* context) {
// If we're doing a full balance, try and allocate a new chunk now, before we
mess things up
if (okay_metadata_chunks == 0 || okay_data_chunks == 0 || okay_system_chunks == 0) {
- BOOL consolidated = FALSE;
+ bool consolidated = false;
chunk* c;
if (okay_metadata_chunks == 0) {
- ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
- Status = alloc_chunk(Vcb, Vcb->metadata_flags, &c, TRUE);
+ Status = alloc_chunk(Vcb, Vcb->metadata_flags, &c, true);
if (NT_SUCCESS(Status))
c->balance_num = Vcb->balance.balance_num;
else if (Status != STATUS_DISK_FULL || consolidated) {
@@ -3182,7 +3188,7 @@ void NTAPI balance_thread(void* context) {
} else
c->balance_num = Vcb->balance.balance_num;
- consolidated = TRUE;
+ consolidated = true;
if (Vcb->balance.stopping)
goto end;
@@ -3190,9 +3196,9 @@ void NTAPI balance_thread(void* context) {
}
if (okay_data_chunks == 0) {
- ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
- Status = alloc_chunk(Vcb, Vcb->data_flags, &c, TRUE);
+ Status = alloc_chunk(Vcb, Vcb->data_flags, &c, true);
if (NT_SUCCESS(Status))
c->balance_num = Vcb->balance.balance_num;
else if (Status != STATUS_DISK_FULL || consolidated) {
@@ -3213,7 +3219,7 @@ void NTAPI balance_thread(void* context) {
} else
c->balance_num = Vcb->balance.balance_num;
- consolidated = TRUE;
+ consolidated = true;
if (Vcb->balance.stopping)
goto end;
@@ -3221,9 +3227,9 @@ void NTAPI balance_thread(void* context) {
}
if (okay_system_chunks == 0) {
- ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->chunk_lock, true);
- Status = alloc_chunk(Vcb, Vcb->system_flags, &c, TRUE);
+ Status = alloc_chunk(Vcb, Vcb->system_flags, &c, true);
if (NT_SUCCESS(Status))
c->balance_num = Vcb->balance.balance_num;
else if (Status != STATUS_DISK_FULL || consolidated) {
@@ -3244,7 +3250,7 @@ void NTAPI balance_thread(void* context) {
} else
c->balance_num = Vcb->balance.balance_num;
- consolidated = TRUE;
+ consolidated = true;
if (Vcb->balance.stopping)
goto end;
@@ -3252,13 +3258,13 @@ void NTAPI balance_thread(void* context) {
}
}
- ExAcquireResourceSharedLite(&Vcb->chunk_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->chunk_lock, true);
le = chunks.Flink;
while (le != &chunks) {
chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
- c->reloc = TRUE;
+ c->reloc = true;
le = le->Flink;
}
@@ -3272,10 +3278,10 @@ void NTAPI balance_thread(void* context) {
LIST_ENTRY* le2 = le->Flink;
if (c->chunk_item->type & BLOCK_FLAG_DATA) {
- BOOL changed;
+ bool changed;
do {
- changed = FALSE;
+ changed = false;
Status = balance_data_chunk(Vcb, c, &changed);
if (!NT_SUCCESS(Status)) {
@@ -3284,17 +3290,17 @@ void NTAPI balance_thread(void* context) {
goto end;
}
- KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode,
FALSE, NULL);
+ KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode,
false, NULL);
if (Vcb->readonly)
- Vcb->balance.stopping = TRUE;
+ Vcb->balance.stopping = true;
if (Vcb->balance.stopping)
break;
} while (changed);
- c->changed = TRUE;
- c->space_changed = TRUE;
+ c->changed = true;
+ c->space_changed = true;
}
if (Vcb->balance.stopping)
@@ -3314,7 +3320,7 @@ void NTAPI balance_thread(void* context) {
// do metadata chunks
while (!IsListEmpty(&chunks)) {
chunk* c;
- BOOL changed;
+ bool changed;
le = RemoveHeadList(&chunks);
c = CONTAINING_RECORD(le, chunk, list_entry_balance);
@@ -3328,17 +3334,17 @@ void NTAPI balance_thread(void* context) {
goto end;
}
- KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode,
FALSE, NULL);
+ KeWaitForSingleObject(&Vcb->balance.event, Executive, KernelMode,
false, NULL);
if (Vcb->readonly)
- Vcb->balance.stopping = TRUE;
+ Vcb->balance.stopping = true;
if (Vcb->balance.stopping)
break;
} while (changed);
- c->changed = TRUE;
- c->space_changed = TRUE;
+ c->changed = true;
+ c->space_changed = true;
}
if (Vcb->balance.stopping)
@@ -3355,7 +3361,7 @@ end:
le = chunks.Flink;
while (le != &chunks) {
chunk* c = CONTAINING_RECORD(le, chunk, list_entry_balance);
- c->reloc = FALSE;
+ c->reloc = false;
le = le->Flink;
c->list_entry_balance.Flink = NULL;
@@ -3374,7 +3380,7 @@ end:
if (Vcb->balance.removing) {
device* dev = NULL;
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
le = Vcb->devices.Flink;
while (le != &Vcb->devices) {
@@ -3394,17 +3400,17 @@ end:
if (!NT_SUCCESS(Status)) {
ERR("finish_removing_device returned %08x\n", Status);
- dev->reloc = FALSE;
+ dev->reloc = false;
}
} else
- dev->reloc = FALSE;
+ dev->reloc = false;
}
ExReleaseResourceLite(&Vcb->tree_lock);
} else if (Vcb->balance.shrinking) {
device* dev = NULL;
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
le = Vcb->devices.Flink;
while (le != &Vcb->devices) {
@@ -3419,7 +3425,7 @@ end:
}
if (!dev) {
- ERR("could not find device %llx\n",
Vcb->balance.opts[0].devid);
+ ERR("could not find device %I64x\n",
Vcb->balance.opts[0].devid);
Vcb->balance.status = STATUS_INTERNAL_ERROR;
}
@@ -3430,7 +3436,7 @@ end:
WARN("regenerate_space_list returned %08x\n", Status);
}
} else {
- UINT64 old_size;
+ uint64_t old_size;
old_size = dev->devitem.num_bytes;
dev->devitem.num_bytes = Vcb->balance.opts[0].drange_start;
@@ -3468,7 +3474,7 @@ end:
}
if (Vcb->trim && !Vcb->options.no_trim) {
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
le = Vcb->devices.Flink;
while (le != &Vcb->devices) {
@@ -3487,13 +3493,13 @@ end:
ZwClose(Vcb->balance.thread);
Vcb->balance.thread = NULL;
- KeSetEvent(&Vcb->balance.finished, 0, FALSE);
+ KeSetEvent(&Vcb->balance.finished, 0, false);
}
NTSTATUS start_balance(device_extension* Vcb, void* data, ULONG length, KPROCESSOR_MODE
processor_mode) {
NTSTATUS Status;
btrfs_start_balance* bsb = (btrfs_start_balance*)data;
- UINT8 i;
+ uint8_t i;
if (length < sizeof(btrfs_start_balance) || !data)
return STATUS_INVALID_PARAMETER;
@@ -3587,9 +3593,9 @@ NTSTATUS start_balance(device_extension* Vcb, void* data, ULONG
length, KPROCESS
RtlCopyMemory(&Vcb->balance.opts[BALANCE_OPTS_METADATA],
&bsb->opts[BALANCE_OPTS_METADATA], sizeof(btrfs_balance_opts));
RtlCopyMemory(&Vcb->balance.opts[BALANCE_OPTS_SYSTEM],
&bsb->opts[BALANCE_OPTS_SYSTEM], sizeof(btrfs_balance_opts));
- Vcb->balance.paused = FALSE;
- Vcb->balance.removing = FALSE;
- Vcb->balance.shrinking = FALSE;
+ Vcb->balance.paused = false;
+ Vcb->balance.removing = false;
+ Vcb->balance.shrinking = false;
Vcb->balance.status = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->balance.event, NotificationEvent,
!Vcb->balance.paused);
@@ -3613,7 +3619,7 @@ NTSTATUS
look_for_balance_item(_Requires_lock_held_(_Curr_->tree_lock) device_ex
searchkey.obj_type = TYPE_TEMP_ITEM;
searchkey.offset = 0;
- Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, FALSE, NULL);
+ Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, false, NULL);
if (!NT_SUCCESS(Status)) {
ERR("find_item returned %08x\n", Status);
return Status;
@@ -3625,7 +3631,7 @@ NTSTATUS
look_for_balance_item(_Requires_lock_held_(_Curr_->tree_lock) device_ex
}
if (tp.item->size < sizeof(BALANCE_ITEM)) {
- WARN("(%llx,%x,%llx) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
+ WARN("(%I64x,%x,%I64x) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(BALANCE_ITEM));
return STATUS_INTERNAL_ERROR;
}
@@ -3664,12 +3670,12 @@ NTSTATUS
look_for_balance_item(_Requires_lock_held_(_Curr_->tree_lock) device_ex
}
if (Vcb->readonly || Vcb->options.skip_balance)
- Vcb->balance.paused = TRUE;
+ Vcb->balance.paused = true;
else
- Vcb->balance.paused = FALSE;
+ Vcb->balance.paused = false;
- Vcb->balance.removing = FALSE;
- Vcb->balance.shrinking = FALSE;
+ Vcb->balance.removing = false;
+ Vcb->balance.shrinking = false;
Vcb->balance.status = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->balance.event, NotificationEvent,
!Vcb->balance.paused);
@@ -3730,7 +3736,7 @@ NTSTATUS pause_balance(device_extension* Vcb, KPROCESSOR_MODE
processor_mode) {
if (Vcb->balance.paused)
return STATUS_DEVICE_NOT_READY;
- Vcb->balance.paused = TRUE;
+ Vcb->balance.paused = true;
KeClearEvent(&Vcb->balance.event);
return STATUS_SUCCESS;
@@ -3749,8 +3755,8 @@ NTSTATUS resume_balance(device_extension* Vcb, KPROCESSOR_MODE
processor_mode) {
if (Vcb->readonly)
return STATUS_MEDIA_WRITE_PROTECTED;
- Vcb->balance.paused = FALSE;
- KeSetEvent(&Vcb->balance.event, 0, FALSE);
+ Vcb->balance.paused = false;
+ KeSetEvent(&Vcb->balance.event, 0, false);
return STATUS_SUCCESS;
}
@@ -3762,33 +3768,33 @@ NTSTATUS stop_balance(device_extension* Vcb, KPROCESSOR_MODE
processor_mode) {
if (!Vcb->balance.thread)
return STATUS_DEVICE_NOT_READY;
- Vcb->balance.paused = FALSE;
- Vcb->balance.stopping = TRUE;
+ Vcb->balance.paused = false;
+ Vcb->balance.stopping = true;
Vcb->balance.status = STATUS_SUCCESS;
- KeSetEvent(&Vcb->balance.event, 0, FALSE);
+ KeSetEvent(&Vcb->balance.event, 0, false);
return STATUS_SUCCESS;
}
NTSTATUS remove_device(device_extension* Vcb, void* data, ULONG length, KPROCESSOR_MODE
processor_mode) {
- UINT64 devid;
+ uint64_t devid;
LIST_ENTRY* le;
device* dev = NULL;
NTSTATUS Status;
int i;
- UINT64 num_rw_devices;
+ uint64_t num_rw_devices;
TRACE("(%p, %p, %x)\n", Vcb, data, length);
if (!SeSinglePrivilegeCheck(RtlConvertLongToLuid(SE_MANAGE_VOLUME_PRIVILEGE),
processor_mode))
return STATUS_PRIVILEGE_NOT_HELD;
- if (length < sizeof(UINT64))
+ if (length < sizeof(uint64_t))
return STATUS_INVALID_PARAMETER;
- devid = *(UINT64*)data;
+ devid = *(uint64_t*)data;
- ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
if (Vcb->readonly) {
ExReleaseResourceLite(&Vcb->tree_lock);
@@ -3812,7 +3818,7 @@ NTSTATUS remove_device(device_extension* Vcb, void* data, ULONG
length, KPROCESS
if (!dev) {
ExReleaseResourceLite(&Vcb->tree_lock);
- WARN("device %llx not found\n", devid);
+ WARN("device %I64x not found\n", devid);
return STATUS_NOT_FOUND;
}
@@ -3855,7 +3861,7 @@ NTSTATUS remove_device(device_extension* Vcb, void* data, ULONG
length, KPROCESS
return STATUS_DEVICE_NOT_READY;
}
- dev->reloc = TRUE;
+ dev->reloc = true;
RtlZeroMemory(Vcb->balance.opts, sizeof(btrfs_balance_opts) * 3);
@@ -3864,16 +3870,16 @@ NTSTATUS remove_device(device_extension* Vcb, void* data, ULONG
length, KPROCESS
Vcb->balance.opts[i].devid = devid;
}
- Vcb->balance.paused = FALSE;
- Vcb->balance.removing = TRUE;
- Vcb->balance.shrinking = FALSE;
+ Vcb->balance.paused = false;
+ Vcb->balance.removing = true;
+ Vcb->balance.shrinking = false;
Vcb->balance.status = STATUS_SUCCESS;
KeInitializeEvent(&Vcb->balance.event, NotificationEvent,
!Vcb->balance.paused);
Status = PsCreateSystemThread(&Vcb->balance.thread, 0, NULL, NULL, NULL,
balance_thread, Vcb);
if (!NT_SUCCESS(Status)) {
ERR("PsCreateSystemThread returned %08x\n", Status);
- dev->reloc = FALSE;
+ dev->reloc = false;
return Status;
}
diff --git a/drivers/filesystems/btrfs/boot.c b/drivers/filesystems/btrfs/boot.c
new file mode 100755
index 00000000000..f73fc38b4e8
--- /dev/null
+++ b/drivers/filesystems/btrfs/boot.c
@@ -0,0 +1,248 @@
+/* Copyright (c) Mark Harmstone 2019
+ *
+ * This file is part of WinBtrfs.
+ *
+ * WinBtrfs is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public Licence as published by
+ * the Free Software Foundation, either version 3 of the Licence, or
+ * (at your option) any later version.
+ *
+ * WinBtrfs is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public Licence
+ * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "btrfs_drv.h"
+
+#ifndef __REACTOS__
+#ifdef _MSC_VER
+#include <ntstrsafe.h>
+#endif
+#else
+#include <ntstrsafe.h>
+#endif
+
+extern ERESOURCE pdo_list_lock;
+extern LIST_ENTRY pdo_list;
+
+#ifndef _MSC_VER
+NTSTATUS RtlUnicodeStringPrintf(PUNICODE_STRING DestinationString, const WCHAR*
pszFormat, ...); // not in mingw
+#endif
+
+static bool get_system_root_partition(uint32_t* disk_num, uint32_t* partition_num) {
+ NTSTATUS Status;
+ HANDLE h;
+ UNICODE_STRING us, target;
+ OBJECT_ATTRIBUTES objatt;
+ WCHAR* s;
+ ULONG retlen = 0, left;
+
+ static const WCHAR system_root[] = L"\\SystemRoot";
+ static const WCHAR arc_prefix[] = L"\\ArcName\\multi(0)disk(0)rdisk(";
+ static const WCHAR arc_middle[] = L")partition(";
+
+ us.Buffer = (WCHAR*)system_root;
+ us.Length = us.MaximumLength = sizeof(system_root) - sizeof(WCHAR);
+
+ InitializeObjectAttributes(&objatt, &us, OBJ_CASE_INSENSITIVE |
OBJ_KERNEL_HANDLE, NULL, NULL);
+
+ Status = ZwOpenSymbolicLinkObject(&h, GENERIC_READ, &objatt);
+ if (!NT_SUCCESS(Status)) {
+ ERR("ZwOpenSymbolicLinkObject returned %08x\n", Status);
+ return false;
+ }
+
+ target.Length = target.MaximumLength = 0;
+
+ Status = ZwQuerySymbolicLinkObject(h, &target, &retlen);
+ if (Status != STATUS_BUFFER_TOO_SMALL) {
+ ERR("ZwQuerySymbolicLinkObject returned %08x\n", Status);
+ NtClose(h);
+ return false;
+ }
+
+ if (retlen == 0) {
+ NtClose(h);
+ return false;
+ }
+
+ target.Buffer = ExAllocatePoolWithTag(NonPagedPool, retlen, ALLOC_TAG);
+ if (!target.Buffer) {
+ ERR("out of memory\n");
+ NtClose(h);
+ return false;
+ }
+
+ target.Length = target.MaximumLength = (USHORT)retlen;
+
+ Status = ZwQuerySymbolicLinkObject(h, &target, NULL);
+ if (!NT_SUCCESS(Status)) {
+ ERR("ZwQuerySymbolicLinkObject returned %08x\n", Status);
+ NtClose(h);
+ ExFreePool(target.Buffer);
+ return false;
+ }
+
+ NtClose(h);
+
+ TRACE("system root is %.*S\n", target.Length / sizeof(WCHAR),
target.Buffer);
+
+ if (target.Length <= sizeof(arc_prefix) - sizeof(WCHAR) ||
+ RtlCompareMemory(target.Buffer, arc_prefix, sizeof(arc_prefix) - sizeof(WCHAR))
!= sizeof(arc_prefix) - sizeof(WCHAR)) {
+ ExFreePool(target.Buffer);
+ return false;
+ }
+
+ s = &target.Buffer[(sizeof(arc_prefix) / sizeof(WCHAR)) - 1];
+ left = ((target.Length - sizeof(arc_prefix)) / sizeof(WCHAR)) + 1;
+
+ if (left == 0 || s[0] < '0' || s[0] > '9') {
+ ExFreePool(target.Buffer);
+ return false;
+ }
+
+ *disk_num = 0;
+
+ while (left > 0 && s[0] >= '0' && s[0] <=
'9') {
+ *disk_num *= 10;
+ *disk_num += s[0] - '0';
+ s++;
+ left--;
+ }
+
+ if (left <= (sizeof(arc_middle) / sizeof(WCHAR)) - 1 ||
+ RtlCompareMemory(s, arc_middle, sizeof(arc_middle) - sizeof(WCHAR)) !=
sizeof(arc_middle) - sizeof(WCHAR)) {
+ ExFreePool(target.Buffer);
+ return false;
+ }
+
+ s = &s[(sizeof(arc_middle) / sizeof(WCHAR)) - 1];
+ left -= (sizeof(arc_middle) / sizeof(WCHAR)) - 1;
+
+ if (left == 0 || s[0] < '0' || s[0] > '9') {
+ ExFreePool(target.Buffer);
+ return false;
+ }
+
+ *partition_num = 0;
+
+ while (left > 0 && s[0] >= '0' && s[0] <=
'9') {
+ *partition_num *= 10;
+ *partition_num += s[0] - '0';
+ s++;
+ left--;
+ }
+
+ ExFreePool(target.Buffer);
+
+ return true;
+}
+
+static void change_symlink(uint32_t disk_num, uint32_t partition_num, BTRFS_UUID* uuid)
{
+ NTSTATUS Status;
+ UNICODE_STRING us, us2;
+ WCHAR symlink[60], target[(sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) + 36], *w;
+#ifdef __REACTOS__
+ unsigned int i;
+#endif
+
+ us.Buffer = symlink;
+ us.Length = 0;
+ us.MaximumLength = sizeof(symlink);
+
+ Status = RtlUnicodeStringPrintf(&us,
L"\\Device\\Harddisk%u\\Partition%u", disk_num, partition_num);
+ if (!NT_SUCCESS(Status)) {
+ ERR("RtlUnicodeStringPrintf returned %08x\n", Status);
+ return;
+ }
+
+ Status = IoDeleteSymbolicLink(&us);
+ if (!NT_SUCCESS(Status))
+ ERR("IoDeleteSymbolicLink returned %08x\n", Status);
+
+ RtlCopyMemory(target, BTRFS_VOLUME_PREFIX, sizeof(BTRFS_VOLUME_PREFIX) -
sizeof(WCHAR));
+
+ w = &target[(sizeof(BTRFS_VOLUME_PREFIX) / sizeof(WCHAR)) - 1];
+
+#ifndef __REACTOS__
+ for (unsigned int i = 0; i < 16; i++) {
+#else
+ for (i = 0; i < 16; i++) {
+#endif
+ *w = hex_digit(uuid->uuid[i] >> 4); w++;
+ *w = hex_digit(uuid->uuid[i] & 0xf); w++;
+
+ if (i == 3 || i == 5 || i == 7 || i == 9) {
+ *w = L'-';
+ w++;
+ }
+ }
+
+ *w = L'}';
+
+ us2.Buffer = target;
+ us2.Length = us2.MaximumLength = sizeof(target);
+
+ Status = IoCreateSymbolicLink(&us, &us2);
+ if (!NT_SUCCESS(Status))
+ ERR("IoCreateSymbolicLink returned %08x\n", Status);
+}
+
+/* If booting from Btrfs, Windows will pass the device object for the raw partition to
+ * mount_vol - which is no good to us, as we only use the \Device\Btrfs{} devices we
+ * create so that RAID works correctly.
+ * At the time check_system_root gets called, \SystemRoot is a symlink to the ARC
device,
+ * e.g. \ArcName\multi(0)disk(0)rdisk(0)partition(1)\Windows. We can't change the
symlink,
+ * as it gets clobbered by IopReassignSystemRoot shortly afterwards, and we can't
touch
+ * the \ArcName symlinks as they haven't been created yet. Instead, we need to change
the
+ * symlink \Device\HarddiskX\PartitionY, which is what the ArcName symlink will shortly
+ * point to.
+ */
+void __stdcall check_system_root(PDRIVER_OBJECT DriverObject, PVOID Context, ULONG Count)
{
+ uint32_t disk_num, partition_num;
+ LIST_ENTRY* le;
+ bool done = false;
+
+ TRACE("(%p, %p, %u)\n", DriverObject, Context, Count);
+
+ if (!get_system_root_partition(&disk_num, &partition_num))
+ return;
+
+ TRACE("system boot partition is disk %u, partition %u\n", disk_num,
partition_num);
+
+ ExAcquireResourceSharedLite(&pdo_list_lock, true);
+
+ le = pdo_list.Flink;
+ while (le != &pdo_list) {
+ LIST_ENTRY* le2;
+ pdo_device_extension* pdode = CONTAINING_RECORD(le, pdo_device_extension,
list_entry);
+
+ ExAcquireResourceSharedLite(&pdode->child_lock, true);
+
+ le2 = pdode->children.Flink;
+
+ while (le2 != &pdode->children) {
+ volume_child* vc = CONTAINING_RECORD(le2, volume_child, list_entry);
+
+ if (vc->disk_num == disk_num && vc->part_num == partition_num)
{
+ change_symlink(disk_num, partition_num, &pdode->uuid);
+ done = true;
+ break;
+ }
+
+ le2 = le2->Flink;
+ }
+
+ ExReleaseResourceLite(&pdode->child_lock);
+
+ if (done)
+ break;
+
+ le = le->Flink;
+ }
+
+ ExReleaseResourceLite(&pdo_list_lock);
+}
diff --git a/drivers/filesystems/btrfs/btrfs.c b/drivers/filesystems/btrfs/btrfs.c
index c480d9f0502..61f3dc666db 100644
--- a/drivers/filesystems/btrfs/btrfs.c
+++ b/drivers/filesystems/btrfs/btrfs.c
@@ -46,6 +46,12 @@
#undef INITGUID
#endif
+#ifdef _MSC_VER
+#include <ntstrsafe.h>
+#else
+NTSTATUS RtlStringCbVPrintfA(char* pszDest, size_t cbDest, const char* pszFormat, va_list
argList); // not in mingw
+#endif
+
#define INCOMPAT_SUPPORTED (BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF |
BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL | BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS | \
BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO |
BTRFS_INCOMPAT_FLAGS_BIG_METADATA | BTRFS_INCOMPAT_FLAGS_RAID56 | \
BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF |
BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA | BTRFS_INCOMPAT_FLAGS_NO_HOLES | \
@@ -58,45 +64,49 @@ static const WCHAR dosdevice_name[] =
{'\\','D','o','s','D','e','v','i','c','e',
DEFINE_GUID(BtrfsBusInterface, 0x4d414874, 0x6865, 0x6761, 0x6d, 0x65, 0x83, 0x69, 0x17,
0x9a, 0x7d, 0x1d);
PDRIVER_OBJECT drvobj;
-PDEVICE_OBJECT master_devobj;
+PDEVICE_OBJECT master_devobj, busobj;
#ifndef __REACTOS__
-BOOL have_sse42 = FALSE, have_sse2 = FALSE;
+bool have_sse42 = false, have_sse2 = false;
#endif
-UINT64 num_reads = 0;
+uint64_t num_reads = 0;
LIST_ENTRY uid_map_list, gid_map_list;
LIST_ENTRY VcbList;
ERESOURCE global_loading_lock;
-UINT32 debug_log_level = 0;
-UINT32 mount_compress = 0;
-UINT32 mount_compress_force = 0;
-UINT32 mount_compress_type = 0;
-UINT32 mount_zlib_level = 3;
-UINT32 mount_zstd_level = 3;
-UINT32 mount_flush_interval = 30;
-UINT32 mount_max_inline = 2048;
-UINT32 mount_skip_balance = 0;
-UINT32 mount_no_barrier = 0;
-UINT32 mount_no_trim = 0;
-UINT32 mount_clear_cache = 0;
-UINT32 mount_allow_degraded = 0;
-UINT32 mount_readonly = 0;
-UINT32 no_pnp = 0;
-BOOL log_started = FALSE;
+uint32_t debug_log_level = 0;
+uint32_t mount_compress = 0;
+uint32_t mount_compress_force = 0;
+uint32_t mount_compress_type = 0;
+uint32_t mount_zlib_level = 3;
+uint32_t mount_zstd_level = 3;
+uint32_t mount_flush_interval = 30;
+uint32_t mount_max_inline = 2048;
+uint32_t mount_skip_balance = 0;
+uint32_t mount_no_barrier = 0;
+uint32_t mount_no_trim = 0;
+uint32_t mount_clear_cache = 0;
+uint32_t mount_allow_degraded = 0;
+uint32_t mount_readonly = 0;
+uint32_t no_pnp = 0;
+bool log_started = false;
UNICODE_STRING log_device, log_file, registry_path;
tPsUpdateDiskCounters fPsUpdateDiskCounters;
tCcCopyReadEx fCcCopyReadEx;
tCcCopyWriteEx fCcCopyWriteEx;
tCcSetAdditionalCacheAttributesEx fCcSetAdditionalCacheAttributesEx;
tFsRtlUpdateDiskCounters fFsRtlUpdateDiskCounters;
-BOOL diskacc = FALSE;
+tIoUnregisterPlugPlayNotificationEx fIoUnregisterPlugPlayNotificationEx;
+tFsRtlGetEcpListFromIrp fFsRtlGetEcpListFromIrp;
+tFsRtlGetNextExtraCreateParameter fFsRtlGetNextExtraCreateParameter;
+tFsRtlValidateReparsePointBuffer fFsRtlValidateReparsePointBuffer;
+bool diskacc = false;
void *notification_entry = NULL, *notification_entry2 = NULL, *notification_entry3 =
NULL;
ERESOURCE pdo_list_lock, mapping_lock;
LIST_ENTRY pdo_list;
-BOOL finished_probing = FALSE;
+bool finished_probing = false;
HANDLE degraded_wait_handle = NULL, mountmgr_thread_handle = NULL;
-BOOL degraded_wait = TRUE;
+bool degraded_wait = true;
KEVENT mountmgr_thread_event;
-BOOL shutting_down = FALSE;
+bool shutting_down = false;
#ifdef _DEBUG
PFILE_OBJECT comfo = NULL;
@@ -105,7 +115,7 @@ HANDLE log_handle = NULL;
ERESOURCE log_lock;
HANDLE serial_thread_handle = NULL;
-static void init_serial(BOOL first_time);
+static void init_serial(bool first_time);
#endif
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp);
@@ -115,19 +125,24 @@ typedef struct {
IO_STATUS_BLOCK iosb;
} read_context;
+// no longer in Windows headers??
+extern BOOLEAN WdmlibRtlIsNtDdiVersionAvailable(ULONG Version);
+
#ifdef _DEBUG
_Function_class_(IO_COMPLETION_ROUTINE)
-static NTSTATUS dbg_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_
PVOID conptr) {
+static NTSTATUS __stdcall dbg_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp,
_In_ PVOID conptr) {
read_context* context = conptr;
UNUSED(DeviceObject);
context->iosb = Irp->IoStatus;
- KeSetEvent(&context->Event, 0, FALSE);
+ KeSetEvent(&context->Event, 0, false);
return STATUS_MORE_PROCESSING_REQUIRED;
}
+#define DEBUG_MESSAGE_LEN 1024
+
#ifdef DEBUG_LONG_MESSAGES
void _debug_message(_In_ const char* func, _In_ const char* file, _In_ unsigned int line,
_In_ char* s, ...) {
#else
@@ -140,9 +155,9 @@ void _debug_message(_In_ const char* func, _In_ char* s, ...) {
va_list ap;
char *buf2, *buf;
read_context context;
- UINT32 length;
+ uint32_t length;
- buf2 = ExAllocatePoolWithTag(NonPagedPool, 1024, ALLOC_TAG);
+ buf2 = ExAllocatePoolWithTag(NonPagedPool, DEBUG_MESSAGE_LEN, ALLOC_TAG);
if (!buf2) {
DbgPrint("Couldn't allocate buffer in debug_message\n");
@@ -157,29 +172,29 @@ void _debug_message(_In_ const char* func, _In_ char* s, ...) {
buf = &buf2[strlen(buf2)];
va_start(ap, s);
- vsprintf(buf, s, ap);
- ExAcquireResourceSharedLite(&log_lock, TRUE);
+ RtlStringCbVPrintfA(buf, DEBUG_MESSAGE_LEN - strlen(buf2), s, ap);
+
+ ExAcquireResourceSharedLite(&log_lock, true);
if (!log_started || (log_device.Length == 0 && log_file.Length == 0)) {
DbgPrint(buf2);
} else if (log_device.Length > 0) {
if (!comdo) {
- DbgPrint("comdo is NULL :-(\n");
DbgPrint(buf2);
goto exit2;
}
- length = (UINT32)strlen(buf2);
+ length = (uint32_t)strlen(buf2);
offset.u.LowPart = 0;
offset.u.HighPart = 0;
RtlZeroMemory(&context, sizeof(read_context));
- KeInitializeEvent(&context.Event, NotificationEvent, FALSE);
+ KeInitializeEvent(&context.Event, NotificationEvent, false);
- Irp = IoAllocateIrp(comdo->StackSize, FALSE);
+ Irp = IoAllocateIrp(comdo->StackSize, false);
if (!Irp) {
DbgPrint("IoAllocateIrp failed\n");
@@ -188,13 +203,14 @@ void _debug_message(_In_ const char* func, _In_ char* s, ...) {
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MajorFunction = IRP_MJ_WRITE;
+ IrpSp->FileObject = comfo;
if (comdo->Flags & DO_BUFFERED_IO) {
Irp->AssociatedIrp.SystemBuffer = buf2;
Irp->Flags = IRP_BUFFERED_IO;
} else if (comdo->Flags & DO_DIRECT_IO) {
- Irp->MdlAddress = IoAllocateMdl(buf2, length, FALSE, FALSE, NULL);
+ Irp->MdlAddress = IoAllocateMdl(buf2, length, false, false, NULL);
if (!Irp->MdlAddress) {
DbgPrint("IoAllocateMdl failed\n");
goto exit;
@@ -212,12 +228,12 @@ void _debug_message(_In_ const char* func, _In_ char* s, ...) {
Irp->UserEvent = &context.Event;
- IoSetCompletionRoutine(Irp, dbg_completion, &context, TRUE, TRUE, TRUE);
+ IoSetCompletionRoutine(Irp, dbg_completion, &context, true, true, true);
Status = IoCallDriver(comdo, Irp);
if (Status == STATUS_PENDING) {
- KeWaitForSingleObject(&context.Event, Executive, KernelMode, FALSE,
NULL);
+ KeWaitForSingleObject(&context.Event, Executive, KernelMode, false,
NULL);
Status = context.iosb.Status;
}
@@ -234,7 +250,7 @@ exit:
} else if (log_handle != NULL) {
IO_STATUS_BLOCK iosb;
- length = (UINT32)strlen(buf2);
+ length = (uint32_t)strlen(buf2);
Status = ZwWriteFile(log_handle, NULL, NULL, NULL, &iosb, buf2, length, NULL,
NULL);
@@ -253,49 +269,45 @@ exit2:
}
#endif
-BOOL is_top_level(_In_ PIRP Irp) {
+bool is_top_level(_In_ PIRP Irp) {
if (!IoGetTopLevelIrp()) {
IoSetTopLevelIrp(Irp);
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
_Function_class_(DRIVER_UNLOAD)
-#ifdef __REACTOS__
-static void NTAPI DriverUnload(_In_ PDRIVER_OBJECT DriverObject) {
-#else
-static void DriverUnload(_In_ PDRIVER_OBJECT DriverObject) {
-#endif
+static void __stdcall DriverUnload(_In_ PDRIVER_OBJECT DriverObject) {
UNICODE_STRING dosdevice_nameW;
- TRACE("(%p)\n");
+ TRACE("(%p)\n", DriverObject);
free_cache();
IoUnregisterFileSystem(DriverObject->DeviceObject);
- if (notification_entry2)
-#ifdef __REACTOS__
- IoUnregisterPlugPlayNotification(notification_entry2);
-#else
- IoUnregisterPlugPlayNotificationEx(notification_entry2);
-#endif
+ if (notification_entry2) {
+ if (fIoUnregisterPlugPlayNotificationEx)
+ fIoUnregisterPlugPlayNotificationEx(notification_entry2);
+ else
+ IoUnregisterPlugPlayNotification(notification_entry2);
+ }
- if (notification_entry3)
-#ifdef __REACTOS__
- IoUnregisterPlugPlayNotification(notification_entry3);
-#else
- IoUnregisterPlugPlayNotificationEx(notification_entry3);
-#endif
+ if (notification_entry3) {
+ if (fIoUnregisterPlugPlayNotificationEx)
+ fIoUnregisterPlugPlayNotificationEx(notification_entry3);
+ else
+ IoUnregisterPlugPlayNotification(notification_entry3);
+ }
- if (notification_entry)
-#ifdef __REACTOS__
- IoUnregisterPlugPlayNotification(notification_entry);
-#else
- IoUnregisterPlugPlayNotificationEx(notification_entry);
-#endif
+ if (notification_entry) {
+ if (fIoUnregisterPlugPlayNotificationEx)
+ fIoUnregisterPlugPlayNotificationEx(notification_entry);
+ else
+ IoUnregisterPlugPlayNotification(notification_entry);
+ }
dosdevice_nameW.Buffer = (WCHAR*)dosdevice_name;
dosdevice_nameW.Length = dosdevice_nameW.MaximumLength = sizeof(dosdevice_name) -
sizeof(WCHAR);
@@ -347,7 +359,7 @@ static void DriverUnload(_In_ PDRIVER_OBJECT DriverObject) {
ExDeleteResourceLite(&mapping_lock);
}
-static BOOL get_last_inode(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, _In_ root* r, _In_opt_ PIRP Irp) {
+static bool get_last_inode(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, _In_ root* r, _In_opt_ PIRP Irp) {
KEY searchkey;
traverse_ptr tp, prev_tp;
NTSTATUS Status;
@@ -357,46 +369,46 @@ static BOOL get_last_inode(_In_
_Requires_exclusive_lock_held_(_Curr_->tree_lock
searchkey.obj_type = 0xff;
searchkey.offset = 0xffffffffffffffff;
- Status = find_item(Vcb, r, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, r, &tp, &searchkey, false, Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
- return FALSE;
+ return false;
}
if (tp.item->key.obj_type == TYPE_INODE_ITEM || (tp.item->key.obj_type ==
TYPE_ROOT_ITEM && !(tp.item->key.obj_id & 0x8000000000000000))) {
r->lastinode = tp.item->key.obj_id;
- TRACE("last inode for tree %llx is %llx\n", r->id,
r->lastinode);
- return TRUE;
+ TRACE("last inode for tree %I64x is %I64x\n", r->id,
r->lastinode);
+ return true;
}
while (find_prev_item(Vcb, &tp, &prev_tp, Irp)) {
tp = prev_tp;
- TRACE("moving on to %llx,%x,%llx\n", tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset);
+ TRACE("moving on to %I64x,%x,%I64x\n", tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset);
if (tp.item->key.obj_type == TYPE_INODE_ITEM || (tp.item->key.obj_type ==
TYPE_ROOT_ITEM && !(tp.item->key.obj_id & 0x8000000000000000))) {
r->lastinode = tp.item->key.obj_id;
- TRACE("last inode for tree %llx is %llx\n", r->id,
r->lastinode);
- return TRUE;
+ TRACE("last inode for tree %I64x is %I64x\n", r->id,
r->lastinode);
+ return true;
}
}
r->lastinode = SUBVOL_ROOT_INODE;
- WARN("no INODE_ITEMs in tree %llx\n", r->id);
+ WARN("no INODE_ITEMs in tree %I64x\n", r->id);
- return TRUE;
+ return true;
}
_Success_(return)
-static BOOL extract_xattr(_In_reads_bytes_(size) void* item, _In_ USHORT size, _In_z_
char* name, _Out_ UINT8** data, _Out_ UINT16* datalen) {
+static bool extract_xattr(_In_reads_bytes_(size) void* item, _In_ USHORT size, _In_z_
char* name, _Out_ uint8_t** data, _Out_ uint16_t* datalen) {
DIR_ITEM* xa = (DIR_ITEM*)item;
USHORT xasize;
- while (TRUE) {
+ while (true) {
if (size < sizeof(DIR_ITEM) || size < (sizeof(DIR_ITEM) - 1 + xa->m +
xa->n)) {
WARN("DIR_ITEM is truncated\n");
- return FALSE;
+ return false;
}
if (xa->n == strlen(name) && RtlCompareMemory(name, xa->name,
xa->n) == xa->n) {
@@ -408,14 +420,14 @@ static BOOL extract_xattr(_In_reads_bytes_(size) void* item, _In_
USHORT size, _
*data = ExAllocatePoolWithTag(PagedPool, xa->m, ALLOC_TAG);
if (!*data) {
ERR("out of memory\n");
- return FALSE;
+ return false;
}
RtlCopyMemory(*data, &xa->name[xa->n], xa->m);
} else
*data = NULL;
- return TRUE;
+ return true;
}
xasize = sizeof(DIR_ITEM) - 1 + xa->m + xa->n;
@@ -429,36 +441,36 @@ static BOOL extract_xattr(_In_reads_bytes_(size) void* item, _In_
USHORT size, _
TRACE("xattr %s not found\n", name);
- return FALSE;
+ return false;
}
_Success_(return)
-BOOL get_xattr(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb,
_In_ root* subvol, _In_ UINT64 inode, _In_z_ char* name, _In_ UINT32 crc32,
- _Out_ UINT8** data, _Out_ UINT16* datalen, _In_opt_ PIRP Irp) {
+bool get_xattr(_In_ _Requires_lock_held_(_Curr_->tree_lock) device_extension* Vcb,
_In_ root* subvol, _In_ uint64_t inode, _In_z_ char* name, _In_ uint32_t crc32,
+ _Out_ uint8_t** data, _Out_ uint16_t* datalen, _In_opt_ PIRP Irp) {
KEY searchkey;
traverse_ptr tp;
NTSTATUS Status;
- TRACE("(%p, %llx, %llx, %s, %08x, %p, %p)\n", Vcb, subvol->id, inode,
name, crc32, data, datalen);
+ TRACE("(%p, %I64x, %I64x, %s, %08x, %p, %p)\n", Vcb, subvol->id, inode,
name, crc32, data, datalen);
searchkey.obj_id = inode;
searchkey.obj_type = TYPE_XATTR_ITEM;
searchkey.offset = crc32;
- Status = find_item(Vcb, subvol, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, subvol, &tp, &searchkey, false, Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
- return FALSE;
+ return false;
}
if (keycmp(tp.item->key, searchkey)) {
- TRACE("could not find item (%llx,%x,%llx)\n", searchkey.obj_id,
searchkey.obj_type, searchkey.offset);
- return FALSE;
+ TRACE("could not find item (%I64x,%x,%I64x)\n", searchkey.obj_id,
searchkey.obj_type, searchkey.offset);
+ return false;
}
if (tp.item->size < sizeof(DIR_ITEM)) {
- ERR("(%llx,%x,%llx) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DIR_ITEM));
- return FALSE;
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DIR_ITEM));
+ return false;
}
return extract_xattr(tp.item->data, tp.item->size, name, data, datalen);
@@ -466,15 +478,11 @@ BOOL get_xattr(_In_ _Requires_lock_held_(_Curr_->tree_lock)
device_extension* Vc
_Dispatch_type_(IRP_MJ_CLOSE)
_Function_class_(DRIVER_DISPATCH)
-#ifdef __REACTOS__
-static NTSTATUS NTAPI drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
-#else
-static NTSTATUS drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
-#endif
+static NTSTATUS __stdcall drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
device_extension* Vcb = DeviceObject->DeviceExtension;
- BOOL top_level;
+ bool top_level;
FsRtlEnterFileSystem();
@@ -519,17 +527,13 @@ end:
_Dispatch_type_(IRP_MJ_FLUSH_BUFFERS)
_Function_class_(DRIVER_DISPATCH)
-#ifdef __REACTOS__
-static NTSTATUS NTAPI drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
{
-#else
-static NTSTATUS drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
-#endif
+static NTSTATUS __stdcall drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP
Irp) {
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
PFILE_OBJECT FileObject = IrpSp->FileObject;
fcb* fcb = FileObject->FsContext;
device_extension* Vcb = DeviceObject->DeviceExtension;
- BOOL top_level;
+ bool top_level;
FsRtlEnterFileSystem();
@@ -541,18 +545,18 @@ static NTSTATUS drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Ir
Status = vol_flush_buffers(DeviceObject, Irp);
goto end;
} else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
- Status = STATUS_INVALID_PARAMETER;
+ Status = STATUS_SUCCESS;
goto end;
}
if (!fcb) {
ERR("fcb was NULL\n");
- Status = STATUS_INVALID_PARAMETER;
+ Status = STATUS_SUCCESS;
goto end;
}
if (fcb == Vcb->volume_fcb) {
- Status = STATUS_INVALID_PARAMETER;
+ Status = STATUS_SUCCESS;
goto end;
}
@@ -564,10 +568,10 @@ static NTSTATUS drv_flush_buffers(_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Ir
Irp->IoStatus.Status = Status;
if (fcb->type != BTRFS_TYPE_DIRECTORY) {
- CcFlushCache(&fcb->nonpaged->segment_object, NULL, 0,
&Irp->IoStatus);
+ CcFlushCache(FileObject->SectionObjectPointer, NULL, 0,
&Irp->IoStatus);
if (fcb->Header.PagingIoResource) {
- ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
+ ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
ExReleaseResourceLite(fcb->Header.PagingIoResource);
}
@@ -587,8 +591,8 @@ end:
return Status;
}
-static void calculate_total_space(_In_ device_extension* Vcb, _Out_ UINT64* totalsize,
_Out_ UINT64* freespace) {
- UINT64 nfactor, dfactor, sectors_used;
+static void calculate_total_space(_In_ device_extension* Vcb, _Out_ uint64_t* totalsize,
_Out_ uint64_t* freespace) {
+ uint64_t nfactor, dfactor, sectors_used;
if (Vcb->data_flags & BLOCK_FLAG_DUPLICATE || Vcb->data_flags &
BLOCK_FLAG_RAID1 || Vcb->data_flags & BLOCK_FLAG_RAID10) {
nfactor = 1;
@@ -617,7 +621,7 @@ static void calculate_total_space(_In_ device_extension* Vcb, _Out_
UINT64* tota
// The command mklink refuses to create hard links on anything other than NTFS, so we
have to
// blacklist cmd.exe too.
-static BOOL lie_about_fs_type() {
+static bool lie_about_fs_type() {
NTSTATUS Status;
PROCESS_BASIC_INFORMATION pbi;
PPEB peb;
@@ -640,34 +644,34 @@ static BOOL lie_about_fs_type() {
fsutilus.Length = fsutilus.MaximumLength = sizeof(fsutil) - sizeof(WCHAR);
if (!PsGetCurrentProcess())
- return FALSE;
+ return false;
#ifdef _AMD64_
Status = ZwQueryInformationProcess(NtCurrentProcess(), ProcessWow64Information,
&wow64info, sizeof(wow64info), NULL);
if (NT_SUCCESS(Status) && wow64info != 0)
- return TRUE;
+ return true;
#endif
Status = ZwQueryInformationProcess(NtCurrentProcess(), ProcessBasicInformation,
&pbi, sizeof(pbi), &retlen);
if (!NT_SUCCESS(Status)) {
ERR("ZwQueryInformationProcess returned %08x\n", Status);
- return FALSE;
+ return false;
}
if (!pbi.PebBaseAddress)
- return FALSE;
+ return false;
peb = pbi.PebBaseAddress;
if (!peb->Ldr)
- return FALSE;
+ return false;
le = peb->Ldr->InMemoryOrderModuleList.Flink;
while (le != &peb->Ldr->InMemoryOrderModuleList) {
LDR_DATA_TABLE_ENTRY* entry = CONTAINING_RECORD(le, LDR_DATA_TABLE_ENTRY,
InMemoryOrderLinks);
- BOOL blacklist = FALSE;
+ bool blacklist = false;
if (entry->FullDllName.Length >= mprus.Length) {
UNICODE_STRING name;
@@ -675,7 +679,7 @@ static BOOL lie_about_fs_type() {
name.Buffer = &entry->FullDllName.Buffer[(entry->FullDllName.Length
- mprus.Length) / sizeof(WCHAR)];
name.Length = name.MaximumLength = mprus.Length;
- blacklist = FsRtlAreNamesEqual(&name, &mprus, TRUE, NULL);
+ blacklist = FsRtlAreNamesEqual(&name, &mprus, true, NULL);
}
if (!blacklist && entry->FullDllName.Length >= cmdus.Length) {
@@ -684,7 +688,7 @@ static BOOL lie_about_fs_type() {
name.Buffer = &entry->FullDllName.Buffer[(entry->FullDllName.Length
- cmdus.Length) / sizeof(WCHAR)];
name.Length = name.MaximumLength = cmdus.Length;
- blacklist = FsRtlAreNamesEqual(&name, &cmdus, TRUE, NULL);
+ blacklist = FsRtlAreNamesEqual(&name, &cmdus, true, NULL);
}
if (!blacklist && entry->FullDllName.Length >= fsutilus.Length) {
@@ -693,7 +697,7 @@ static BOOL lie_about_fs_type() {
name.Buffer = &entry->FullDllName.Buffer[(entry->FullDllName.Length
- fsutilus.Length) / sizeof(WCHAR)];
name.Length = name.MaximumLength = fsutilus.Length;
- blacklist = FsRtlAreNamesEqual(&name, &fsutilus, TRUE, NULL);
+ blacklist = FsRtlAreNamesEqual(&name, &fsutilus, true, NULL);
}
if (blacklist) {
@@ -703,7 +707,7 @@ static BOOL lie_about_fs_type() {
frames = ExAllocatePoolWithTag(PagedPool, 256 * sizeof(void*), ALLOC_TAG);
if (!frames) {
ERR("out of memory\n");
- return FALSE;
+ return false;
}
num_frames = RtlWalkFrameChain(frames, 256, 1);
@@ -712,7 +716,7 @@ static BOOL lie_about_fs_type() {
// entry->Reserved3[1] appears to be the image size
if (frames[i] >= entry->DllBase && (ULONG_PTR)frames[i]
<= (ULONG_PTR)entry->DllBase + (ULONG_PTR)entry->Reserved3[1]) {
ExFreePool(frames);
- return TRUE;
+ return true;
}
}
@@ -722,22 +726,217 @@ static BOOL lie_about_fs_type() {
le = le->Flink;
}
- return FALSE;
+ return false;
}
#endif
-_Dispatch_type_(IRP_MJ_QUERY_VOLUME_INFORMATION)
-_Function_class_(DRIVER_DISPATCH)
+// version of RtlUTF8ToUnicodeN for Vista and below
+NTSTATUS utf8_to_utf16(WCHAR* dest, ULONG dest_max, ULONG* dest_len, char* src, ULONG
src_len) {
+ NTSTATUS Status = STATUS_SUCCESS;
+ uint8_t* in = (uint8_t*)src;
+ uint16_t* out = (uint16_t*)dest;
+ ULONG needed = 0, left = dest_max / sizeof(uint16_t);
+#ifdef __REACTOS__
+ ULONG i;
+
+ for (i = 0; i < src_len; ++i) {
+#else
+
+ for (ULONG i = 0; i < src_len; i++) {
+#endif
+ uint32_t cp;
+
+ if (!(in[i] & 0x80))
+ cp = in[i];
+ else if ((in[i] & 0xe0) == 0xc0) {
+ if (i == src_len - 1 || (in[i+1] & 0xc0) != 0x80) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ } else {
+ cp = ((in[i] & 0x1f) << 6) | (in[i+1] & 0x3f);
+ i++;
+ }
+ } else if ((in[i] & 0xf0) == 0xe0) {
+ if (i >= src_len - 2 || (in[i+1] & 0xc0) != 0x80 || (in[i+2] &
0xc0) != 0x80) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ } else {
+ cp = ((in[i] & 0xf) << 12) | ((in[i+1] & 0x3f) << 6)
| (in[i+2] & 0x3f);
+ i += 2;
+ }
+ } else if ((in[i] & 0xf8) == 0xf0) {
+ if (i >= src_len - 3 || (in[i+1] & 0xc0) != 0x80 || (in[i+2] &
0xc0) != 0x80 || (in[i+3] & 0xc0) != 0x80) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ } else {
+ cp = ((in[i] & 0x7) << 18) | ((in[i+1] & 0x3f) << 12)
| ((in[i+2] & 0x3f) << 6) | (in[i+3] & 0x3f);
+ i += 3;
+ }
+ } else {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ }
+
+ if (cp > 0x10ffff) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ }
+
+ if (dest) {
+ if (cp <= 0xffff) {
+ if (left < 1)
+ return STATUS_BUFFER_OVERFLOW;
+
+ *out = (uint16_t)cp;
+ out++;
+
+ left--;
+ } else {
+ if (left < 2)
+ return STATUS_BUFFER_OVERFLOW;
+
+ cp -= 0x10000;
+
+ *out = 0xd800 | ((cp & 0xffc00) >> 10);
+ out++;
+
+ *out = 0xdc00 | (cp & 0x3ff);
+ out++;
+
+ left -= 2;
+ }
+ }
+
+ if (cp <= 0xffff)
+ needed += sizeof(uint16_t);
+ else
+ needed += 2 * sizeof(uint16_t);
+ }
+
+ if (dest_len)
+ *dest_len = needed;
+
+ return Status;
+}
+
+// version of RtlUnicodeToUTF8N for Vista and below
+NTSTATUS utf16_to_utf8(char* dest, ULONG dest_max, ULONG* dest_len, WCHAR* src, ULONG
src_len) {
+ NTSTATUS Status = STATUS_SUCCESS;
+ uint16_t* in = (uint16_t*)src;
+ uint8_t* out = (uint8_t*)dest;
+ ULONG in_len = src_len / sizeof(uint16_t);
+ ULONG needed = 0, left = dest_max;
#ifdef __REACTOS__
-static NTSTATUS NTAPI drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
+ ULONG i = 0;
+
+ for (i = 0; i < in_len; i++) {
#else
-static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP
Irp) {
+
+ for (ULONG i = 0; i < in_len; i++) {
#endif
+ uint32_t cp = *in;
+ in++;
+
+ if ((cp & 0xfc00) == 0xd800) {
+ if (i == in_len - 1 || (*in & 0xfc00) != 0xdc00) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ } else {
+ cp = (cp & 0x3ff) << 10;
+ cp |= *in & 0x3ff;
+ cp += 0x10000;
+
+ in++;
+ i++;
+ }
+ } else if ((cp & 0xfc00) == 0xdc00) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ }
+
+ if (cp > 0x10ffff) {
+ cp = 0xfffd;
+ Status = STATUS_SOME_NOT_MAPPED;
+ }
+
+ if (dest) {
+ if (cp < 0x80) {
+ if (left < 1)
+ return STATUS_BUFFER_OVERFLOW;
+
+ *out = (uint8_t)cp;
+ out++;
+
+ left--;
+ } else if (cp < 0x800) {
+ if (left < 2)
+ return STATUS_BUFFER_OVERFLOW;
+
+ *out = 0xc0 | ((cp & 0x7c0) >> 6);
+ out++;
+
+ *out = 0x80 | (cp & 0x3f);
+ out++;
+
+ left -= 2;
+ } else if (cp < 0x10000) {
+ if (left < 3)
+ return STATUS_BUFFER_OVERFLOW;
+
+ *out = 0xe0 | ((cp & 0xf000) >> 12);
+ out++;
+
+ *out = 0x80 | ((cp & 0xfc0) >> 6);
+ out++;
+
+ *out = 0x80 | (cp & 0x3f);
+ out++;
+
+ left -= 3;
+ } else {
+ if (left < 4)
+ return STATUS_BUFFER_OVERFLOW;
+
+ *out = 0xf0 | ((cp & 0x1c0000) >> 18);
+ out++;
+
+ *out = 0x80 | ((cp & 0x3f000) >> 12);
+ out++;
+
+ *out = 0x80 | ((cp & 0xfc0) >> 6);
+ out++;
+
+ *out = 0x80 | (cp & 0x3f);
+ out++;
+
+ left -= 4;
+ }
+ }
+
+ if (cp < 0x80)
+ needed++;
+ else if (cp < 0x800)
+ needed += 2;
+ else if (cp < 0x10000)
+ needed += 3;
+ else
+ needed += 4;
+ }
+
+ if (dest_len)
+ *dest_len = needed;
+
+ return Status;
+}
+
+_Dispatch_type_(IRP_MJ_QUERY_VOLUME_INFORMATION)
+_Function_class_(DRIVER_DISPATCH)
+static NTSTATUS __stdcall drv_query_volume_information(_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Irp) {
PIO_STACK_LOCATION IrpSp;
NTSTATUS Status;
ULONG BytesCopied = 0;
device_extension* Vcb = DeviceObject->DeviceExtension;
- BOOL top_level;
+ bool top_level;
FsRtlEnterFileSystem();
@@ -760,7 +959,7 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
case FileFsAttributeInformation:
{
FILE_FS_ATTRIBUTE_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
- BOOL overflow = FALSE;
+ bool overflow = false;
#ifndef __REACTOS__
static const WCHAR ntfs[] = L"NTFS";
#endif
@@ -789,7 +988,7 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
else
fs_name_len = 0;
- overflow = TRUE;
+ overflow = true;
}
data->FileSystemAttributes = FILE_CASE_PRESERVED_NAMES |
FILE_CASE_SENSITIVE_SEARCH |
@@ -818,7 +1017,7 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
ffdi->DeviceType = FILE_DEVICE_DISK;
- ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
ffdi->Characteristics = Vcb->Vpb->RealDevice->Characteristics;
ExReleaseResourceLite(&Vcb->tree_lock);
@@ -839,10 +1038,10 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
TRACE("FileFsFullSizeInformation\n");
- calculate_total_space(Vcb,
(UINT64*)&ffsi->TotalAllocationUnits.QuadPart,
(UINT64*)&ffsi->ActualAvailableAllocationUnits.QuadPart);
+ calculate_total_space(Vcb,
(uint64_t*)&ffsi->TotalAllocationUnits.QuadPart,
(uint64_t*)&ffsi->ActualAvailableAllocationUnits.QuadPart);
ffsi->CallerAvailableAllocationUnits.QuadPart =
ffsi->ActualAvailableAllocationUnits.QuadPart;
- ffsi->SectorsPerAllocationUnit = 1;
- ffsi->BytesPerSector = Vcb->superblock.sector_size;
+ ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
+ ffsi->BytesPerSector = 512;
BytesCopied = sizeof(FILE_FS_FULL_SIZE_INFORMATION);
Status = STATUS_SUCCESS;
@@ -871,9 +1070,9 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
TRACE("FileFsSizeInformation\n");
- calculate_total_space(Vcb,
(UINT64*)&ffsi->TotalAllocationUnits.QuadPart,
(UINT64*)&ffsi->AvailableAllocationUnits.QuadPart);
- ffsi->SectorsPerAllocationUnit = 1;
- ffsi->BytesPerSector = Vcb->superblock.sector_size;
+ calculate_total_space(Vcb,
(uint64_t*)&ffsi->TotalAllocationUnits.QuadPart,
(uint64_t*)&ffsi->AvailableAllocationUnits.QuadPart);
+ ffsi->SectorsPerAllocationUnit = Vcb->superblock.sector_size / 512;
+ ffsi->BytesPerSector = 512;
BytesCopied = sizeof(FILE_FS_SIZE_INFORMATION);
Status = STATUS_SUCCESS;
@@ -885,17 +1084,17 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
{
FILE_FS_VOLUME_INFORMATION* data = Irp->AssociatedIrp.SystemBuffer;
FILE_FS_VOLUME_INFORMATION ffvi;
- BOOL overflow = FALSE;
+ bool overflow = false;
ULONG label_len, orig_label_len;
TRACE("FileFsVolumeInformation\n");
TRACE("max length = %u\n",
IrpSp->Parameters.QueryVolume.Length);
- ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
- Status = RtlUTF8ToUnicodeN(NULL, 0, &label_len, Vcb->superblock.label,
(ULONG)strlen(Vcb->superblock.label));
+ Status = utf8_to_utf16(NULL, 0, &label_len, Vcb->superblock.label,
(ULONG)strlen(Vcb->superblock.label));
if (!NT_SUCCESS(Status)) {
- ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
+ ERR("utf8_to_utf16 returned %08x\n", Status);
ExReleaseResourceLite(&Vcb->tree_lock);
break;
}
@@ -908,7 +1107,7 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
else
label_len = 0;
- overflow = TRUE;
+ overflow = true;
}
TRACE("label_len = %u\n", label_len);
@@ -916,16 +1115,16 @@ static NTSTATUS drv_query_volume_information(_In_ PDEVICE_OBJECT
DeviceObject, _
ffvi.VolumeCreationTime.QuadPart = 0; // FIXME
ffvi.VolumeSerialNumber = Vcb->superblock.uuid.uuid[12] << 24 |
Vcb->superblock.uuid.uuid[13] << 16 | Vcb->superblock.uuid.uuid[14] << 8
| Vcb->superblock.uuid.uuid[15];
ffvi.VolumeLabelLength = orig_label_len;
- ffvi.SupportsObjects = FALSE;
+ ffvi.SupportsObjects = false;
RtlCopyMemory(data, &ffvi, min(sizeof(FILE_FS_VOLUME_INFORMATION) -
sizeof(WCHAR), IrpSp->Parameters.QueryVolume.Length));
if (label_len > 0) {
ULONG bytecount;
- Status = RtlUTF8ToUnicodeN(&data->VolumeLabel[0], label_len,
&bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
+ Status = utf8_to_utf16(&data->VolumeLabel[0], label_len,
&bytecount, Vcb->superblock.label, (ULONG)strlen(Vcb->superblock.label));
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL) {
- ERR("RtlUTF8ToUnicodeN returned %08x\n", Status);
+ ERR("utf8_to_utf16 returned %08x\n", Status);
ExReleaseResourceLite(&Vcb->tree_lock);
break;
}
@@ -992,23 +1191,19 @@ end:
}
_Function_class_(IO_COMPLETION_ROUTINE)
-#ifdef __REACTOS__
-static NTSTATUS NTAPI read_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp,
_In_ PVOID conptr) {
-#else
-static NTSTATUS read_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_
PVOID conptr) {
-#endif
+static NTSTATUS __stdcall read_completion(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP
Irp, _In_ PVOID conptr) {
read_context* context = conptr;
UNUSED(DeviceObject);
context->iosb = Irp->IoStatus;
- KeSetEvent(&context->Event, 0, FALSE);
+ KeSetEvent(&context->Event, 0, false);
return STATUS_MORE_PROCESSING_REQUIRED;
}
-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) {
+NTSTATUS create_root(_In_ _Requires_exclusive_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, _In_ uint64_t id,
+ _Out_ root** rootptr, _In_ bool no_tree, _In_ uint64_t offset,
_In_opt_ PIRP Irp) {
NTSTATUS Status;
root* r;
tree* t = NULL;
@@ -1039,8 +1234,8 @@ NTSTATUS create_root(_In_
_Requires_exclusive_lock_held_(_Curr_->tree_lock) devi
t->nonpaged = NULL;
- t->is_unique = TRUE;
- t->uniqueness_determined = TRUE;
+ t->is_unique = true;
+ t->uniqueness_determined = true;
t->buf = NULL;
}
@@ -1061,15 +1256,15 @@ NTSTATUS create_root(_In_
_Requires_exclusive_lock_held_(_Curr_->tree_lock) devi
r->treeholder.generation = Vcb->superblock.generation;
r->treeholder.tree = t;
r->lastinode = 0;
- r->dirty = FALSE;
- r->received = FALSE;
+ r->dirty = false;
+ r->received = false;
r->reserved = NULL;
r->parent = 0;
r->send_ops = 0;
RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
r->root_item.num_references = 1;
r->fcbs_version = 0;
- r->checked_for_orphans = TRUE;
+ r->checked_for_orphans = true;
InitializeListHead(&r->fcbs);
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY*) * 256);
@@ -1106,7 +1301,7 @@ NTSTATUS create_root(_In_
_Requires_exclusive_lock_held_(_Curr_->tree_lock) devi
t->header.num_items = 0;
t->header.level = 0;
- t->has_address = FALSE;
+ t->has_address = false;
t->size = 0;
t->Vcb = Vcb;
t->parent = NULL;
@@ -1116,14 +1311,14 @@ NTSTATUS create_root(_In_
_Requires_exclusive_lock_held_(_Curr_->tree_lock) devi
InitializeListHead(&t->itemlist);
t->new_address = 0;
- t->has_new_address = FALSE;
- t->updated_extents = FALSE;
+ t->has_new_address = false;
+ t->updated_extents = false;
InsertTailList(&Vcb->trees, &t->list_entry);
t->list_entry_hash.Flink = NULL;
- t->write = TRUE;
- Vcb->need_write = TRUE;
+ t->write = true;
+ Vcb->need_write = true;
}
*rootptr = r;
@@ -1153,7 +1348,7 @@ static NTSTATUS set_label(_In_ device_extension* Vcb, _In_
FILE_FS_LABEL_INFORMA
if (vollen == 0) {
utf8len = 0;
} else {
- Status = RtlUnicodeToUTF8N(NULL, 0, &utf8len, ffli->VolumeLabel, vollen);
+ Status = utf16_to_utf8(NULL, 0, &utf8len, ffli->VolumeLabel, vollen);
if (!NT_SUCCESS(Status))
goto end;
@@ -1163,10 +1358,10 @@ static NTSTATUS set_label(_In_ device_extension* Vcb, _In_
FILE_FS_LABEL_INFORMA
}
}
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
if (utf8len > 0) {
- Status = RtlUnicodeToUTF8N((PCHAR)&Vcb->superblock.label, MAX_LABEL_SIZE,
&utf8len, ffli->VolumeLabel, vollen);
+ Status = utf16_to_utf8((PCHAR)&Vcb->superblock.label, MAX_LABEL_SIZE,
&utf8len, ffli->VolumeLabel, vollen);
if (!NT_SUCCESS(Status))
goto release;
} else
@@ -1175,7 +1370,7 @@ static NTSTATUS set_label(_In_ device_extension* Vcb, _In_
FILE_FS_LABEL_INFORMA
if (utf8len < MAX_LABEL_SIZE)
RtlZeroMemory(Vcb->superblock.label + utf8len, MAX_LABEL_SIZE - utf8len);
- Vcb->need_write = TRUE;
+ Vcb->need_write = true;
release:
ExReleaseResourceLite(&Vcb->tree_lock);
@@ -1188,15 +1383,11 @@ end:
_Dispatch_type_(IRP_MJ_SET_VOLUME_INFORMATION)
_Function_class_(DRIVER_DISPATCH)
-#ifdef __REACTOS__
-static NTSTATUS NTAPI drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
-#else
-static NTSTATUS drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP
Irp) {
-#endif
+static NTSTATUS __stdcall drv_set_volume_information(_In_ PDEVICE_OBJECT DeviceObject,
_In_ PIRP Irp) {
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
device_extension* Vcb = DeviceObject->DeviceExtension;
NTSTATUS Status;
- BOOL top_level;
+ bool top_level;
FsRtlEnterFileSystem();
@@ -1280,7 +1471,7 @@ static WCHAR* file_desc_fcb(_In_ fcb* fcb) {
// GCC doesn't like %llx in sprintf, and MSVC won't let us use swprintf
// without the CRT, which breaks drivers.
- sprintf(s, "subvol %x, inode %x", (UINT32)fcb->subvol->id,
(UINT32)fcb->inode);
+ sprintf(s, "subvol %x, inode %x", (uint32_t)fcb->subvol->id,
(uint32_t)fcb->inode);
as.Buffer = s;
as.Length = as.MaximumLength = (USHORT)strlen(s);
@@ -1289,7 +1480,7 @@ static WCHAR* file_desc_fcb(_In_ fcb* fcb) {
us.MaximumLength = 60 * sizeof(WCHAR);
us.Length = 0;
- Status = RtlAnsiStringToUnicodeString(&us, &as, FALSE);
+ Status = RtlAnsiStringToUnicodeString(&us, &as, false);
if (!NT_SUCCESS(Status))
return L"(RtlAnsiStringToUnicodeString error)";
@@ -1340,6 +1531,9 @@ WCHAR* file_desc(_In_ PFILE_OBJECT FileObject) {
ccb* ccb = FileObject->FsContext2;
file_ref* fileref = ccb ? ccb->fileref : NULL;
+ if (fcb->Header.Flags2 & FSRTL_FLAG2_IS_PAGING_FILE)
+ return L"(paging file)";
+
if (fileref)
return file_desc_fileref(fileref);
else
@@ -1397,7 +1591,7 @@ void send_notification_fcb(_In_ file_ref* fileref, _In_ ULONG
filter_match, _In_
return;
}
- ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
le = fcb->hardlinks.Flink;
while (le != &fcb->hardlinks) {
@@ -1472,7 +1666,7 @@ void mark_fcb_dirty(_In_ fcb* fcb) {
#ifdef DEBUG_FCB_REFCOUNTS
LONG rc;
#endif
- fcb->dirty = TRUE;
+ fcb->dirty = true;
#ifdef DEBUG_FCB_REFCOUNTS
rc = InterlockedIncrement(&fcb->refcount);
@@ -1481,25 +1675,25 @@ void mark_fcb_dirty(_In_ fcb* fcb) {
InterlockedIncrement(&fcb->refcount);
#endif
- ExAcquireResourceExclusiveLite(&fcb->Vcb->dirty_fcbs_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&fcb->Vcb->dirty_fcbs_lock, true);
InsertTailList(&fcb->Vcb->dirty_fcbs, &fcb->list_entry_dirty);
ExReleaseResourceLite(&fcb->Vcb->dirty_fcbs_lock);
}
- fcb->Vcb->need_write = TRUE;
+ fcb->Vcb->need_write = true;
}
void mark_fileref_dirty(_In_ file_ref* fileref) {
if (!fileref->dirty) {
- fileref->dirty = TRUE;
+ fileref->dirty = true;
increase_fileref_refcount(fileref);
-
ExAcquireResourceExclusiveLite(&fileref->fcb->Vcb->dirty_filerefs_lock,
TRUE);
+
ExAcquireResourceExclusiveLite(&fileref->fcb->Vcb->dirty_filerefs_lock,
true);
InsertTailList(&fileref->fcb->Vcb->dirty_filerefs,
&fileref->list_entry_dirty);
ExReleaseResourceLite(&fileref->fcb->Vcb->dirty_filerefs_lock);
}
- fileref->fcb->Vcb->need_write = TRUE;
+ fileref->fcb->Vcb->need_write = true;
}
#ifdef DEBUG_FCB_REFCOUNTS
@@ -1511,16 +1705,12 @@ void free_fcb(_Inout_ fcb* fcb) {
#endif
#ifdef DEBUG_FCB_REFCOUNTS
-#ifdef DEBUG_LONG_MESSAGES
- ERR("fcb %p (%s): refcount now %i (subvol %llx, inode %llx)\n", fcb, func,
rc, fcb->subvol ? fcb->subvol->id : 0, fcb->inode);
-#else
- ERR("fcb %p (%s): refcount now %i (subvol %llx, inode %llx)\n", fcb, func,
rc, fcb->subvol ? fcb->subvol->id : 0, fcb->inode);
-#endif
+ ERR("fcb %p (%s): refcount now %i (subvol %I64x, inode %I64x)\n", fcb,
func, rc, fcb->subvol ? fcb->subvol->id : 0, fcb->inode);
#endif
}
void reap_fcb(fcb* fcb) {
- UINT8 c = fcb->hash >> 24;
+ uint8_t c = fcb->hash >> 24;
if (fcb->subvol && fcb->subvol->fcbs_ptrs[c] ==
&fcb->list_entry) {
if (fcb->list_entry.Flink != &fcb->subvol->fcbs &&
(CONTAINING_RECORD(fcb->list_entry.Flink, struct _fcb, list_entry)->hash >>
24) == c)
@@ -1736,21 +1926,21 @@ static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP
Irp) {
fileref = ccb->fileref;
if (fcb->Vcb->running_sends > 0) {
- BOOL send_cancelled = FALSE;
+ bool send_cancelled = false;
- ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock, true);
if (ccb->send) {
- ccb->send->cancelling = TRUE;
- send_cancelled = TRUE;
- KeSetEvent(&ccb->send->cleared_event, 0, FALSE);
+ ccb->send->cancelling = true;
+ send_cancelled = true;
+ KeSetEvent(&ccb->send->cleared_event, 0, false);
}
ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
if (send_cancelled) {
while (ccb->send) {
- ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock,
TRUE);
+ ExAcquireResourceExclusiveLite(&fcb->Vcb->send_load_lock,
true);
ExReleaseResourceLite(&fcb->Vcb->send_load_lock);
}
}
@@ -1778,15 +1968,15 @@ static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP
Irp) {
}
void uninit(_In_ device_extension* Vcb) {
- UINT64 i;
+ uint64_t i;
KIRQL irql;
NTSTATUS Status;
LIST_ENTRY* le;
LARGE_INTEGER time;
if (!Vcb->removing) {
- ExAcquireResourceExclusiveLite(&Vcb->tree_lock, TRUE);
- Vcb->removing = TRUE;
+ ExAcquireResourceExclusiveLite(&Vcb->tree_lock, true);
+ Vcb->removing = true;
ExReleaseResourceLite(&Vcb->tree_lock);
}
@@ -1798,33 +1988,33 @@ void uninit(_In_ device_extension* Vcb) {
RemoveEntryList(&Vcb->list_entry);
if (Vcb->balance.thread) {
- Vcb->balance.paused = FALSE;
- Vcb->balance.stopping = TRUE;
- KeSetEvent(&Vcb->balance.event, 0, FALSE);
- KeWaitForSingleObject(&Vcb->balance.finished, Executive, KernelMode,
FALSE, NULL);
+ Vcb->balance.paused = false;
+ Vcb->balance.stopping = true;
+ KeSetEvent(&Vcb->balance.event, 0, false);
+ KeWaitForSingleObject(&Vcb->balance.finished, Executive, KernelMode,
false, NULL);
}
if (Vcb->scrub.thread) {
- Vcb->scrub.paused = FALSE;
- Vcb->scrub.stopping = TRUE;
- KeSetEvent(&Vcb->scrub.event, 0, FALSE);
- KeWaitForSingleObject(&Vcb->scrub.finished, Executive, KernelMode, FALSE,
NULL);
+ Vcb->scrub.paused = false;
+ Vcb->scrub.stopping = true;
+ KeSetEvent(&Vcb->scrub.event, 0, false);
+ KeWaitForSingleObject(&Vcb->scrub.finished, Executive, KernelMode, false,
NULL);
}
if (Vcb->running_sends != 0) {
- BOOL send_cancelled = FALSE;
+ bool send_cancelled = false;
- ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, true);
le = Vcb->send_ops.Flink;
while (le != &Vcb->send_ops) {
send_info* send = CONTAINING_RECORD(le, send_info, list_entry);
if (!send->cancelling) {
- send->cancelling = TRUE;
- send_cancelled = TRUE;
+ send->cancelling = true;
+ send_cancelled = true;
send->ccb = NULL;
- KeSetEvent(&send->cleared_event, 0, FALSE);
+ KeSetEvent(&send->cleared_event, 0, false);
}
le = le->Flink;
@@ -1834,7 +2024,7 @@ void uninit(_In_ device_extension* Vcb) {
if (send_cancelled) {
while (Vcb->running_sends != 0) {
- ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->send_load_lock, true);
ExReleaseResourceLite(&Vcb->send_load_lock);
}
}
@@ -1845,13 +2035,13 @@ void uninit(_In_ device_extension* Vcb) {
WARN("registry_mark_volume_unmounted returned %08x\n", Status);
for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
- Vcb->calcthreads.threads[i].quit = TRUE;
+ Vcb->calcthreads.threads[i].quit = true;
}
- KeSetEvent(&Vcb->calcthreads.event, 0, FALSE);
+ KeSetEvent(&Vcb->calcthreads.event, 0, false);
for (i = 0; i < Vcb->calcthreads.num_threads; i++) {
- KeWaitForSingleObject(&Vcb->calcthreads.threads[i].finished, Executive,
KernelMode, FALSE, NULL);
+ KeWaitForSingleObject(&Vcb->calcthreads.threads[i].finished, Executive,
KernelMode, false, NULL);
ZwClose(Vcb->calcthreads.threads[i].handle);
}
@@ -1861,7 +2051,7 @@ void uninit(_In_ device_extension* Vcb) {
time.QuadPart = 0;
KeSetTimer(&Vcb->flush_thread_timer, time, NULL); // trigger the timer early
- KeWaitForSingleObject(&Vcb->flush_thread_finished, Executive, KernelMode,
FALSE, NULL);
+ KeWaitForSingleObject(&Vcb->flush_thread_finished, Executive, KernelMode,
false, NULL);
reap_fcb(Vcb->volume_fcb);
reap_fcb(Vcb->dummy_fcb);
@@ -1936,7 +2126,7 @@ void uninit(_In_ device_extension* Vcb) {
ExFreePool(dev);
}
- ExAcquireResourceExclusiveLite(&Vcb->scrub.stats_lock, TRUE);
+ ExAcquireResourceExclusiveLite(&Vcb->scrub.stats_lock, true);
while (!IsListEmpty(&Vcb->scrub.errors)) {
scrub_error* err = CONTAINING_RECORD(RemoveHeadList(&Vcb->scrub.errors),
scrub_error, list_entry);
@@ -2007,14 +2197,14 @@ static NTSTATUS delete_fileref_fcb(_In_ file_ref* fileref,
_In_opt_ PFILE_OBJECT
}
}
- fileref->fcb->deleted = TRUE;
+ fileref->fcb->deleted = true;
le = fileref->children.Flink;
while (le != &fileref->children) {
file_ref* fr2 = CONTAINING_RECORD(le, file_ref, list_entry);
if (fr2->fcb->ads) {
- fr2->fcb->deleted = TRUE;
+ fr2->fcb->deleted = true;
mark_fcb_dirty(fr2->fcb);
}
@@ -2024,7 +2214,7 @@ static NTSTATUS delete_fileref_fcb(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT
return STATUS_SUCCESS;
}
-NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_ PFILE_OBJECT FileObject, _In_
BOOL make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY* rollback) {
+NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_ PFILE_OBJECT FileObject, _In_
bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY* rollback) {
LARGE_INTEGER newlength, time;
BTRFS_TIME now;
NTSTATUS Status;
@@ -2033,7 +2223,7 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
KeQuerySystemTime(&time);
win_time_to_unix(time, &now);
- ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, TRUE);
+ ExAcquireResourceExclusiveLite(fileref->fcb->Header.Resource, true);
if (fileref->deleted) {
ExReleaseResourceLite(fileref->fcb->Header.Resource);
@@ -2045,7 +2235,7 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
return STATUS_ACCESS_DENIED;
}
- fileref->deleted = TRUE;
+ fileref->deleted = true;
mark_fileref_dirty(fileref);
// delete INODE_ITEM (0x1)
@@ -2058,7 +2248,7 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
mark_fcb_dirty(fileref->fcb);
- fileref->fcb->inode_item_changed = TRUE;
+ fileref->fcb->inode_item_changed = true;
if (fileref->fcb->inode_item.st_nlink > 1 || make_orphan) {
fileref->fcb->inode_item.st_nlink--;
@@ -2114,7 +2304,7 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
file_ref* fr2 = CONTAINING_RECORD(le, file_ref, list_entry);
if (fr2->fcb->ads) {
- fr2->fcb->deleted = TRUE;
+ fr2->fcb->deleted = true;
mark_fcb_dirty(fr2->fcb);
}
@@ -2123,7 +2313,7 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
}
}
} else {
- fileref->fcb->deleted = TRUE;
+ fileref->fcb->deleted = true;
mark_fcb_dirty(fileref->fcb);
}
@@ -2132,7 +2322,7 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
if (fileref->dc) {
TRACE("delete file %.*S\n", fileref->dc->name.Length /
sizeof(WCHAR), fileref->dc->name.Buffer);
-
ExAcquireResourceExclusiveLite(&fileref->parent->fcb->nonpaged->dir_children_lock,
TRUE);
+
ExAcquireResourceExclusiveLite(&fileref->parent->fcb->nonpaged->dir_children_lock,
true);
RemoveEntryList(&fileref->dc->list_entry_index);
if (!fileref->fcb->ads)
@@ -2158,20 +2348,20 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
// update INODE_ITEM of parent
- ExAcquireResourceExclusiveLite(fileref->parent->fcb->Header.Resource,
TRUE);
+ ExAcquireResourceExclusiveLite(fileref->parent->fcb->Header.Resource,
true);
fileref->parent->fcb->inode_item.transid =
fileref->fcb->Vcb->superblock.generation;
fileref->parent->fcb->inode_item.sequence++;
fileref->parent->fcb->inode_item.st_ctime = now;
if (!fileref->fcb->ads) {
- TRACE("fileref->parent->fcb->inode_item.st_size (inode %llx) was
%llx\n", fileref->parent->fcb->inode,
fileref->parent->fcb->inode_item.st_size);
+ TRACE("fileref->parent->fcb->inode_item.st_size (inode %I64x) was
%I64x\n", fileref->parent->fcb->inode,
fileref->parent->fcb->inode_item.st_size);
fileref->parent->fcb->inode_item.st_size -= utf8len * 2;
- TRACE("fileref->parent->fcb->inode_item.st_size (inode %llx) now
%llx\n", fileref->parent->fcb->inode,
fileref->parent->fcb->inode_item.st_size);
+ TRACE("fileref->parent->fcb->inode_item.st_size (inode %I64x) now
%I64x\n", fileref->parent->fcb->inode,
fileref->parent->fcb->inode_item.st_size);
fileref->parent->fcb->inode_item.st_mtime = now;
}
- fileref->parent->fcb->inode_item_changed = TRUE;
+ fileref->parent->fcb->inode_item_changed = true;
ExReleaseResourceLite(fileref->parent->fcb->Header.Resource);
if (!fileref->fcb->ads && fileref->parent->dc)
@@ -2194,17 +2384,13 @@ NTSTATUS delete_fileref(_In_ file_ref* fileref, _In_opt_
PFILE_OBJECT FileObject
_Dispatch_type_(IRP_MJ_CLEANUP)
_Function_class_(DRIVER_DISPATCH)
-#ifdef __REACTOS__
-static NTSTATUS NTAPI drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
-#else
-static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
-#endif
+static NTSTATUS __stdcall drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
PFILE_OBJECT FileObject = IrpSp->FileObject;
device_extension* Vcb = DeviceObject->DeviceExtension;
fcb* fcb = FileObject->FsContext;
- BOOL top_level;
+ bool top_level;
FsRtlEnterFileSystem();
@@ -2243,7 +2429,7 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
LONG oc;
ccb* ccb;
file_ref* fileref;
- BOOL locked = TRUE;
+ bool locked = true;
ccb = FileObject->FsContext2;
fileref = ccb ? ccb->fileref : NULL;
@@ -2251,12 +2437,14 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
TRACE("cleanup called for FileObject %p\n", FileObject);
TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref,
file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ?
fileref->open_count : 0);
- ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
+ ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
- ExAcquireResourceExclusiveLite(fcb->Header.Resource, TRUE);
+ ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
IoRemoveShareAccess(FileObject, &fcb->share_access);
+ FsRtlFastUnlockAll(&fcb->lock, FileObject, IoGetRequestorProcess(Irp),
NULL);
+
if (ccb)
FsRtlNotifyCleanup(fcb->Vcb->NotifySync,
&fcb->Vcb->DirNotifyList, ccb);
@@ -2268,10 +2456,10 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
}
if (ccb && ccb->options & FILE_DELETE_ON_CLOSE &&
fileref)
- fileref->delete_on_close = TRUE;
+ fileref->delete_on_close = true;
if (fileref && fileref->delete_on_close && fcb->type ==
BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb !=
fcb->Vcb->dummy_fcb)
- fileref->delete_on_close = FALSE;
+ fileref->delete_on_close = false;
if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj ==
FileObject) {
TRACE("unlocking volume\n");
@@ -2281,7 +2469,7 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
if (ccb && ccb->reserving) {
fcb->subvol->reserved = NULL;
- ccb->reserving = FALSE;
+ ccb->reserving = false;
// FIXME - flush all of subvol's fcbs
}
@@ -2318,10 +2506,10 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
}
ExReleaseResourceLite(fcb->Header.Resource);
- locked = FALSE;
+ locked = false;
// fileref_lock needs to be acquired before fcb->Header.Resource
- ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock,
TRUE);
+ ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock,
true);
Status = delete_fileref(fileref, FileObject, oc > 0 &&
fileref->posix_delete, Irp, &rollback);
if (!NT_SUCCESS(Status)) {
@@ -2335,7 +2523,7 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
clear_rollback(&rollback);
- } else if (FileObject->Flags & FO_CACHE_SUPPORTED &&
fcb->nonpaged->segment_object.DataSectionObject) {
+ } else if (FileObject->Flags & FO_CACHE_SUPPORTED &&
FileObject->SectionObjectPointer->DataSectionObject) {
IO_STATUS_BLOCK iosb;
CcFlushCache(FileObject->SectionObjectPointer, NULL, 0,
&iosb);
@@ -2344,13 +2532,13 @@ static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_
PIRP Irp) {
}
if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource))
{
- ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource,
TRUE);
+ ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource,
true);
ExReleaseResourceLite(fcb->Header.PagingIoResource);
}
- CcPurgeCacheSection(&fcb->nonpaged->segment_object, NULL,
0, FALSE);
+ CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0,
false);
- TRACE("flushed cache on close (FileObject = %p, fcb = %p,
AllocationSize = %llx, FileSize = %llx, ValidDataLength = %llx)\n",
+ TRACE("flushed cache on close (FileObject = %p, fcb = %p,
AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
FileObject, fcb, fcb->Header.AllocationSize.QuadPart,
fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
}
}
@@ -2386,7 +2574,7 @@ exit:
}
_Success_(return)
-BOOL get_file_attributes_from_xattr(_In_reads_bytes_(len) char* val, _In_ UINT16 len,
_Out_ ULONG* atts) {
+bool get_file_attributes_from_xattr(_In_reads_bytes_(len) char* val, _In_ uint16_t len,
_Out_ ULONG* atts) {
if (len > 2 && val[0] == '0' && val[1] == 'x') {
int i;
ULONG dosnum = 0;
@@ -2406,19 +2594,19 @@ BOOL get_file_attributes_from_xattr(_In_reads_bytes_(len) char*
val, _In_ UINT16
*atts = dosnum;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
-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) {
+ULONG get_file_attributes(_In_ _Requires_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, _In_ root* r, _In_ uint64_t inode,
+ _In_ uint8_t type, _In_ bool dotfile, _In_ bool ignore_xa,
_In_opt_ PIRP Irp) {
ULONG att;
char* eaval;
- UINT16 ealen;
+ uint16_t ealen;
- if (!ignore_xa && get_xattr(Vcb, r, inode, EA_DOSATTRIB, EA_DOSATTRIB_HASH,
(UINT8**)&eaval, &ealen, Irp)) {
+ if (!ignore_xa && get_xattr(Vcb, r, inode, EA_DOSATTRIB, EA_DOSATTRIB_HASH,
(uint8_t**)&eaval, &ealen, Irp)) {
ULONG dosnum = 0;
if (get_file_attributes_from_xattr(eaval, ealen, &dosnum)) {
@@ -2481,8 +2669,8 @@ ULONG get_file_attributes(_In_
_Requires_lock_held_(_Curr_->tree_lock) device_ex
return att;
}
-NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_ UINT64 StartingOffset,
_In_ ULONG Length,
- _Out_writes_bytes_(Length) PUCHAR Buffer, _In_ BOOL override) {
+NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_ PFILE_OBJECT FileObject,
_In_ uint64_t StartingOffset, _In_ ULONG Length,
+ _Out_writes_bytes_(Length) PUCHAR Buffer, _In_ bool override) {
IO_STATUS_BLOCK IoStatus;
LARGE_INTEGER Offset;
PIRP Irp;
@@ -2493,11 +2681,11 @@ NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_
UINT64 StartingOf
num_reads++;
RtlZeroMemory(&context, sizeof(read_context));
- KeInitializeEvent(&context.Event, NotificationEvent, FALSE);
+ KeInitializeEvent(&context.Event, NotificationEvent, false);
Offset.QuadPart = (LONGLONG)StartingOffset;
- Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
+ Irp = IoAllocateIrp(DeviceObject->StackSize, false);
if (!Irp) {
ERR("IoAllocateIrp failed\n");
@@ -2507,6 +2695,7 @@ NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_
UINT64 StartingOf
Irp->Flags |= IRP_NOCACHE;
IrpSp = IoGetNextIrpStackLocation(Irp);
IrpSp->MajorFunction = IRP_MJ_READ;
+ IrpSp->FileObject = FileObject;
if (override)
IrpSp->Flags |= SL_OVERRIDE_VERIFY_VOLUME;
@@ -2523,7 +2712,7 @@ NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_
UINT64 StartingOf
Irp->UserBuffer = Buffer;
} else if (DeviceObject->Flags & DO_DIRECT_IO) {
- Irp->MdlAddress = IoAllocateMdl(Buffer, Length, FALSE, FALSE, NULL);
+ Irp->MdlAddress = IoAllocateMdl(Buffer, Length, false, false, NULL);
if (!Irp->MdlAddress) {
ERR("IoAllocateMdl failed\n");
Status = STATUS_INSUFFICIENT_RESOURCES;
@@ -2553,12 +2742,12 @@ NTSTATUS sync_read_phys(_In_ PDEVICE_OBJECT DeviceObject, _In_
UINT64 StartingOf
Irp->UserEvent = &context.Event;
- IoSetCompletionRoutine(Irp, read_completion, &context, TRUE, TRUE, TRUE);
+ IoSetCompletionRoutine(Irp, read_completion, &context, true, true, true);
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING) {
- KeWaitForSingleObject(&context.Event, Executive, KernelMode, FALSE, NULL);
+ KeWaitForSingleObject(&context.Event, Executive, KernelMode, false, NULL);
Status = context.iosb.Status;
}
@@ -2573,11 +2762,11 @@ exit:
return Status;
}
-static NTSTATUS read_superblock(_In_ device_extension* Vcb, _In_ PDEVICE_OBJECT device,
_In_ UINT64 length) {
+static NTSTATUS read_superblock(_In_ device_extension* Vcb, _In_ PDEVICE_OBJECT device,
_In_ PFILE_OBJECT fileobj, _In_ uint64_t length) {
NTSTATUS Status;
superblock* sb;
ULONG i, to_read;
- UINT8 valid_superblocks;
+ uint8_t valid_superblocks;
to_read = device->SectorSize == 0 ? sizeof(superblock) :
(ULONG)sector_align(sizeof(superblock), device->SectorSize);
@@ -2597,12 +2786,12 @@ static NTSTATUS read_superblock(_In_ device_extension* Vcb, _In_
PDEVICE_OBJECT
valid_superblocks = 0;
while (superblock_addrs[i] > 0) {
- UINT32 crc32;
+ uint32_t crc32;
if (i > 0 && superblock_addrs[i] + to_read > length)
break;
- Status = sync_read_phys(device, superblock_addrs[i], to_read, (PUCHAR)sb,
FALSE);
+ Status = sync_read_phys(device, fileobj, superblock_addrs[i], to_read,
(PUCHAR)sb, false);
if (!NT_SUCCESS(Status)) {
ERR("Failed to read superblock %u: %08x\n", i, Status);
ExFreePool(sb);
@@ -2618,10 +2807,10 @@ static NTSTATUS read_superblock(_In_ device_extension* Vcb, _In_
PDEVICE_OBJECT
} else {
TRACE("got superblock %u!\n", i);
- crc32 = ~calc_crc32c(0xffffffff, (UINT8*)&sb->uuid,
(ULONG)sizeof(superblock) - sizeof(sb->checksum));
+ crc32 = ~calc_crc32c(0xffffffff, (uint8_t*)&sb->uuid,
(ULONG)sizeof(superblock) - sizeof(sb->checksum));
- if (crc32 != *((UINT32*)sb->checksum))
- WARN("crc32 was %08x, expected %08x\n", crc32,
*((UINT32*)sb->checksum));
+ if (crc32 != *((uint32_t*)sb->checksum))
+ WARN("crc32 was %08x, expected %08x\n", crc32,
*((uint32_t*)sb->checksum));
else if (sb->sector_size == 0)
WARN("superblock sector size was 0\n");
else if (sb->node_size < sizeof(tree_header) + sizeof(internal_node) ||
sb->node_size > 0x10000)
@@ -2650,14 +2839,14 @@ static NTSTATUS read_superblock(_In_ device_extension* Vcb, _In_
PDEVICE_OBJECT
}
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) {
+ _Out_writes_bytes_opt_(OutputBufferSize) PVOID OutputBuffer, _In_
ULONG OutputBufferSize, _In_ bool Override, _Out_opt_ IO_STATUS_BLOCK* iosb) {
PIRP Irp;
KEVENT Event;
NTSTATUS Status;
PIO_STACK_LOCATION IrpSp;
IO_STATUS_BLOCK IoStatus;
- KeInitializeEvent(&Event, NotificationEvent, FALSE);
+ KeInitializeEvent(&Event, NotificationEvent, false);
Irp = IoBuildDeviceIoControlRequest(ControlCode,
DeviceObject,
@@ -2665,7 +2854,7 @@ NTSTATUS dev_ioctl(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG
ControlCode, _In
InputBufferSize,
OutputBuffer,
OutputBufferSize,
- FALSE,
+ false,
&Event,
&IoStatus);
@@ -2679,7 +2868,7 @@ NTSTATUS dev_ioctl(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG
ControlCode, _In
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING) {
- KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+ KeWaitForSingleObject(&Event, Executive, KernelMode, false, NULL);
Status = IoStatus.Status;
}
@@ -2690,8 +2879,8 @@ NTSTATUS dev_ioctl(_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG
ControlCode, _In
}
_Requires_exclusive_lock_held_(Vcb->tree_lock)
-static NTSTATUS add_root(_Inout_ device_extension* Vcb, _In_ UINT64 id, _In_ UINT64
addr,
- _In_ UINT64 generation, _In_opt_ traverse_ptr* tp) {
+static NTSTATUS add_root(_Inout_ device_extension* Vcb, _In_ uint64_t id, _In_ uint64_t
addr,
+ _In_ uint64_t generation, _In_opt_ traverse_ptr* tp) {
root* r = ExAllocatePoolWithTag(PagedPool, sizeof(root), ALLOC_TAG);
if (!r) {
ERR("out of memory\n");
@@ -2699,8 +2888,8 @@ static NTSTATUS add_root(_Inout_ device_extension* Vcb, _In_ UINT64
id, _In_ UIN
}
r->id = id;
- r->dirty = FALSE;
- r->received = FALSE;
+ r->dirty = false;
+ r->received = false;
r->reserved = NULL;
r->treeholder.address = addr;
r->treeholder.tree = NULL;
@@ -2708,7 +2897,7 @@ static NTSTATUS add_root(_Inout_ device_extension* Vcb, _In_ UINT64
id, _In_ UIN
r->parent = 0;
r->send_ops = 0;
r->fcbs_version = 0;
- r->checked_for_orphans = FALSE;
+ r->checked_for_orphans = false;
InitializeListHead(&r->fcbs);
RtlZeroMemory(r->fcbs_ptrs, sizeof(LIST_ENTRY*) * 256);
@@ -2726,7 +2915,7 @@ static NTSTATUS add_root(_Inout_ device_extension* Vcb, _In_ UINT64
id, _In_ UIN
if (tp) {
RtlCopyMemory(&r->root_item, tp->item->data, min(sizeof(ROOT_ITEM),
tp->item->size));
if (tp->item->size < sizeof(ROOT_ITEM))
- RtlZeroMemory(((UINT8*)&r->root_item) + tp->item->size,
sizeof(ROOT_ITEM) - tp->item->size);
+ RtlZeroMemory(((uint8_t*)&r->root_item) + tp->item->size,
sizeof(ROOT_ITEM) - tp->item->size);
} else
RtlZeroMemory(&r->root_item, sizeof(ROOT_ITEM));
@@ -2780,29 +2969,29 @@ static NTSTATUS add_root(_Inout_ device_extension* Vcb, _In_
UINT64 id, _In_ UIN
static NTSTATUS look_for_roots(_Requires_exclusive_lock_held_(_Curr_->tree_lock) _In_
device_extension* Vcb, _In_opt_ PIRP Irp) {
traverse_ptr tp, next_tp;
KEY searchkey;
- BOOL b;
+ bool b;
NTSTATUS Status;
searchkey.obj_id = 0;
searchkey.obj_type = 0;
searchkey.offset = 0;
- Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, false, Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
return Status;
}
do {
- TRACE("(%llx,%x,%llx)\n", tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset);
+ TRACE("(%I64x,%x,%I64x)\n", tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset);
if (tp.item->key.obj_type == TYPE_ROOT_ITEM) {
ROOT_ITEM* ri = (ROOT_ITEM*)tp.item->data;
if (tp.item->size < offsetof(ROOT_ITEM, byte_limit)) {
- ERR("(%llx,%x,%llx) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, offsetof(ROOT_ITEM, byte_limit));
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, offsetof(ROOT_ITEM, byte_limit));
} else {
- TRACE("root %llx - address %llx\n", tp.item->key.obj_id,
ri->block_number);
+ TRACE("root %I64x - address %I64x\n", tp.item->key.obj_id,
ri->block_number);
Status = add_root(Vcb, tp.item->key.obj_id, ri->block_number,
ri->generation, &tp);
if (!NT_SUCCESS(Status)) {
@@ -2817,7 +3006,7 @@ static NTSTATUS
look_for_roots(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
lastroot->parent = tp.item->key.offset;
}
- b = find_next_item(Vcb, &tp, &next_tp, FALSE, Irp);
+ b = find_next_item(Vcb, &tp, &next_tp, false, Irp);
if (b)
tp = next_tp;
@@ -2826,14 +3015,14 @@ static NTSTATUS
look_for_roots(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
if (!Vcb->readonly && !Vcb->data_reloc_root) {
root* reloc_root;
INODE_ITEM* ii;
- UINT16 irlen;
+ uint16_t irlen;
INODE_REF* ir;
LARGE_INTEGER time;
BTRFS_TIME now;
WARN("data reloc root doesn't exist, creating it\n");
- Status = create_root(Vcb, BTRFS_ROOT_DATA_RELOC, &reloc_root, FALSE, 0,
Irp);
+ Status = create_root(Vcb, BTRFS_ROOT_DATA_RELOC, &reloc_root, false, 0,
Irp);
if (!NT_SUCCESS(Status)) {
ERR("create_root returned %08x\n", Status);
@@ -2874,7 +3063,7 @@ static NTSTATUS
look_for_roots(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
return Status;
}
- irlen = (UINT16)offsetof(INODE_REF, name[0]) + 2;
+ irlen = (uint16_t)offsetof(INODE_REF, name[0]) + 2;
ir = ExAllocatePoolWithTag(PagedPool, irlen, ALLOC_TAG);
if (!ir) {
ERR("out of memory\n");
@@ -2894,7 +3083,7 @@ static NTSTATUS
look_for_roots(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
}
Vcb->data_reloc_root = reloc_root;
- Vcb->need_write = TRUE;
+ Vcb->need_write = true;
}
return STATUS_SUCCESS;
@@ -2903,8 +3092,8 @@ static NTSTATUS
look_for_roots(_Requires_exclusive_lock_held_(_Curr_->tree_lock)
static NTSTATUS find_disk_holes(_In_ _Requires_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, _In_ device* dev, _In_opt_ PIRP Irp) {
KEY searchkey;
traverse_ptr tp, next_tp;
- BOOL b;
- UINT64 lastaddr;
+ bool b;
+ uint64_t lastaddr;
NTSTATUS Status;
InitializeListHead(&dev->space);
@@ -2913,15 +3102,15 @@ static NTSTATUS find_disk_holes(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
searchkey.obj_type = TYPE_DEV_STATS;
searchkey.offset = dev->devitem.dev_id;
- Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, false, Irp);
if (NT_SUCCESS(Status) && !keycmp(tp.item->key, searchkey))
- RtlCopyMemory(dev->stats, tp.item->data, min(sizeof(UINT64) * 5,
tp.item->size));
+ RtlCopyMemory(dev->stats, tp.item->data, min(sizeof(uint64_t) * 5,
tp.item->size));
searchkey.obj_id = dev->devitem.dev_id;
searchkey.obj_type = TYPE_DEV_EXTENT;
searchkey.offset = 0;
- Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, Vcb->dev_root, &tp, &searchkey, false, Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
return Status;
@@ -2944,11 +3133,11 @@ static NTSTATUS find_disk_holes(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
lastaddr = tp.item->key.offset + de->length;
} else {
- ERR("(%llx,%x,%llx) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DEV_EXTENT));
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DEV_EXTENT));
}
}
- b = find_next_item(Vcb, &tp, &next_tp, FALSE, Irp);
+ b = find_next_item(Vcb, &tp, &next_tp, false, Irp);
if (b) {
tp = next_tp;
@@ -3001,12 +3190,12 @@ device* find_device_from_uuid(_In_ device_extension* Vcb, _In_
BTRFS_UUID* uuid)
while (le != &Vcb->devices) {
device* dev = CONTAINING_RECORD(le, device, list_entry);
- TRACE("device %llx, uuid
%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
dev->devitem.dev_id,
+ TRACE("device %I64x, uuid
%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
dev->devitem.dev_id,
dev->devitem.device_uuid.uuid[0], dev->devitem.device_uuid.uuid[1],
dev->devitem.device_uuid.uuid[2], dev->devitem.device_uuid.uuid[3],
dev->devitem.device_uuid.uuid[4], dev->devitem.device_uuid.uuid[5],
dev->devitem.device_uuid.uuid[6], dev->devitem.device_uuid.uuid[7],
dev->devitem.device_uuid.uuid[8], dev->devitem.device_uuid.uuid[9],
dev->devitem.device_uuid.uuid[10], dev->devitem.device_uuid.uuid[11],
dev->devitem.device_uuid.uuid[12], dev->devitem.device_uuid.uuid[13],
dev->devitem.device_uuid.uuid[14], dev->devitem.device_uuid.uuid[15]);
if (RtlCompareMemory(&dev->devitem.device_uuid, uuid, sizeof(BTRFS_UUID))
== sizeof(BTRFS_UUID)) {
- TRACE("returning device %llx\n", dev->devitem.dev_id);
+ TRACE("returning device %I64x\n", dev->devitem.dev_id);
return dev;
}
@@ -3020,7 +3209,7 @@ device* find_device_from_uuid(_In_ device_extension* Vcb, _In_
BTRFS_UUID* uuid)
pdode = vde->pdode;
- ExAcquireResourceSharedLite(&pdode->child_lock, TRUE);
+ ExAcquireResourceSharedLite(&pdode->child_lock, true);
if (Vcb->devices_loaded < Vcb->superblock.num_devices) {
le = pdode->children.Flink;
@@ -3040,13 +3229,14 @@ device* find_device_from_uuid(_In_ device_extension* Vcb, _In_
BTRFS_UUID* uuid)
RtlZeroMemory(dev, sizeof(device));
dev->devobj = vc->devobj;
+ dev->fileobj = vc->fileobj;
dev->devitem.device_uuid = *uuid;
dev->devitem.dev_id = vc->devid;
dev->devitem.num_bytes = vc->size;
dev->seeding = vc->seeding;
dev->readonly = dev->seeding;
- dev->reloc = FALSE;
- dev->removable = FALSE;
+ dev->reloc = false;
+ dev->removable = false;
dev->disk_num = vc->disk_num;
dev->part_num = vc->part_num;
dev->num_trim_entries = 0;
@@ -3074,18 +3264,18 @@ end:
return NULL;
}
-static BOOL is_device_removable(_In_ PDEVICE_OBJECT devobj) {
+static bool is_device_removable(_In_ PDEVICE_OBJECT devobj) {
NTSTATUS Status;
STORAGE_HOTPLUG_INFO shi;
- Status = dev_ioctl(devobj, IOCTL_STORAGE_GET_HOTPLUG_INFO, NULL, 0, &shi,
sizeof(STORAGE_HOTPLUG_INFO), TRUE, NULL);
+ Status = dev_ioctl(devobj, IOCTL_STORAGE_GET_HOTPLUG_INFO, NULL, 0, &shi,
sizeof(STORAGE_HOTPLUG_INFO), true, NULL);
if (!NT_SUCCESS(Status)) {
ERR("dev_ioctl returned %08x\n", Status);
- return FALSE;
+ return false;
}
- return shi.MediaRemovable != 0 ? TRUE : FALSE;
+ return shi.MediaRemovable != 0 ? true : false;
}
static ULONG get_device_change_count(_In_ PDEVICE_OBJECT devobj) {
@@ -3093,7 +3283,7 @@ static ULONG get_device_change_count(_In_ PDEVICE_OBJECT devobj) {
ULONG cc;
IO_STATUS_BLOCK iosb;
- Status = dev_ioctl(devobj, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, &cc,
sizeof(ULONG), TRUE, &iosb);
+ Status = dev_ioctl(devobj, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, &cc,
sizeof(ULONG), true, &iosb);
if (!NT_SUCCESS(Status)) {
ERR("dev_ioctl returned %08x\n", Status);
@@ -3108,7 +3298,7 @@ static ULONG get_device_change_count(_In_ PDEVICE_OBJECT devobj) {
return cc;
}
-void init_device(_In_ device_extension* Vcb, _Inout_ device* dev, _In_ BOOL get_nums) {
+void init_device(_In_ device_extension* Vcb, _Inout_ device* dev, _In_ bool get_nums) {
NTSTATUS Status;
ULONG aptelen;
ATA_PASS_THROUGH_EX* apte;
@@ -3122,7 +3312,7 @@ void init_device(_In_ device_extension* Vcb, _Inout_ device* dev,
_In_ BOOL get_
STORAGE_DEVICE_NUMBER sdn;
Status = dev_ioctl(dev->devobj, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0,
- &sdn, sizeof(STORAGE_DEVICE_NUMBER), TRUE, NULL);
+ &sdn, sizeof(STORAGE_DEVICE_NUMBER), true, NULL);
if (!NT_SUCCESS(Status)) {
WARN("IOCTL_STORAGE_GET_DEVICE_NUMBER returned %08x\n", Status);
@@ -3134,18 +3324,18 @@ void init_device(_In_ device_extension* Vcb, _Inout_ device* dev,
_In_ BOOL get_
}
}
- dev->trim = FALSE;
+ dev->trim = false;
dev->readonly = dev->seeding;
- dev->reloc = FALSE;
+ dev->reloc = false;
dev->num_trim_entries = 0;
- dev->stats_changed = FALSE;
+ dev->stats_changed = false;
InitializeListHead(&dev->trim_list);
if (!dev->readonly) {
Status = dev_ioctl(dev->devobj, IOCTL_DISK_IS_WRITABLE, NULL, 0,
- NULL, 0, TRUE, NULL);
+ NULL, 0, true, NULL);
if (Status == STATUS_MEDIA_WRITE_PROTECTED)
- dev->readonly = TRUE;
+ dev->readonly = true;
}
aptelen = sizeof(ATA_PASS_THROUGH_EX) + 512;
@@ -3165,15 +3355,15 @@ void init_device(_In_ device_extension* Vcb, _Inout_ device* dev,
_In_ BOOL get_
apte->CurrentTaskFile[6] = IDE_COMMAND_IDENTIFY;
Status = dev_ioctl(dev->devobj, IOCTL_ATA_PASS_THROUGH, apte, aptelen,
- apte, aptelen, TRUE, NULL);
+ apte, aptelen, true, NULL);
if (!NT_SUCCESS(Status))
TRACE("IOCTL_ATA_PASS_THROUGH returned %08x for IDENTIFY DEVICE\n",
Status);
else {
- IDENTIFY_DEVICE_DATA* idd = (IDENTIFY_DEVICE_DATA*)((UINT8*)apte +
sizeof(ATA_PASS_THROUGH_EX));
+ IDENTIFY_DEVICE_DATA* idd = (IDENTIFY_DEVICE_DATA*)((uint8_t*)apte +
sizeof(ATA_PASS_THROUGH_EX));
if (idd->CommandSetSupport.FlushCache) {
- dev->can_flush = TRUE;
+ dev->can_flush = true;
TRACE("FLUSH CACHE supported\n");
} else
TRACE("FLUSH CACHE not supported\n");
@@ -3181,29 +3371,34 @@ void init_device(_In_ device_extension* Vcb, _Inout_ device* dev,
_In_ BOOL get_
ExFreePool(apte);
+#ifdef DEBUG_TRIM_EMULATION
+ dev->trim = true;
+ Vcb->trim = true;
+#else
spq.PropertyId = StorageDeviceTrimProperty;
spq.QueryType = PropertyStandardQuery;
spq.AdditionalParameters[0] = 0;
Status = dev_ioctl(dev->devobj, IOCTL_STORAGE_QUERY_PROPERTY, &spq,
sizeof(STORAGE_PROPERTY_QUERY),
- &dtd, sizeof(DEVICE_TRIM_DESCRIPTOR), TRUE, NULL);
+ &dtd, sizeof(DEVICE_TRIM_DESCRIPTOR), true, NULL);
if (NT_SUCCESS(Status)) {
if (dtd.TrimEnabled) {
- dev->trim = TRUE;
- Vcb->trim = TRUE;
+ dev->trim = true;
+ Vcb->trim = true;
TRACE("TRIM supported\n");
} else
TRACE("TRIM not supported\n");
}
+#endif
- RtlZeroMemory(dev->stats, sizeof(UINT64) * 5);
+ RtlZeroMemory(dev->stats, sizeof(uint64_t) * 5);
}
static NTSTATUS load_chunk_root(_In_ _Requires_lock_held_(_Curr_->tree_lock)
device_extension* Vcb, _In_opt_ PIRP Irp) {
traverse_ptr tp, next_tp;
KEY searchkey;
- BOOL b;
+ bool b;
chunk* c;
NTSTATUS Status;
@@ -3215,22 +3410,22 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
Vcb->metadata_flags = 0;
Vcb->system_flags = 0;
- Status = find_item(Vcb, Vcb->chunk_root, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, Vcb->chunk_root, &tp, &searchkey, false, Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
return Status;
}
do {
- TRACE("(%llx,%x,%llx)\n", tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset);
+ TRACE("(%I64x,%x,%I64x)\n", tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset);
if (tp.item->key.obj_id == 1 && tp.item->key.obj_type ==
TYPE_DEV_ITEM) {
if (tp.item->size < sizeof(DEV_ITEM)) {
- ERR("(%llx,%x,%llx) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DEV_ITEM));
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DEV_ITEM));
} else {
DEV_ITEM* di = (DEV_ITEM*)tp.item->data;
LIST_ENTRY* le;
- BOOL done = FALSE;
+ bool done = false;
le = Vcb->devices.Flink;
while (le != &Vcb->devices) {
@@ -3240,9 +3435,9 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
RtlCopyMemory(&dev->devitem, tp.item->data,
min(tp.item->size, sizeof(DEV_ITEM)));
if (le != Vcb->devices.Flink)
- init_device(Vcb, dev, TRUE);
+ init_device(Vcb, dev, true);
- done = TRUE;
+ done = true;
break;
}
@@ -3253,7 +3448,7 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
volume_device_extension* vde = Vcb->vde;
pdo_device_extension* pdode = vde->pdode;
- ExAcquireResourceSharedLite(&pdode->child_lock, TRUE);
+ ExAcquireResourceSharedLite(&pdode->child_lock, true);
if (Vcb->devices_loaded < Vcb->superblock.num_devices) {
le = pdode->children.Flink;
@@ -3274,12 +3469,13 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
RtlZeroMemory(dev, sizeof(device));
dev->devobj = vc->devobj;
+ dev->fileobj = vc->fileobj;
RtlCopyMemory(&dev->devitem, di,
min(tp.item->size, sizeof(DEV_ITEM)));
dev->seeding = vc->seeding;
- init_device(Vcb, dev, FALSE);
+ init_device(Vcb, dev, false);
if (dev->devitem.num_bytes > vc->size) {
- WARN("device %llx: DEV_ITEM says %llx bytes, but
Windows only reports %llx\n", tp.item->key.offset,
+ WARN("device %I64x: DEV_ITEM says %I64x bytes,
but Windows only reports %I64x\n", tp.item->key.offset,
dev->devitem.num_bytes, vc->size);
dev->devitem.num_bytes = vc->size;
@@ -3290,7 +3486,7 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
add_device_to_list(Vcb, dev);
Vcb->devices_loaded++;
- done = TRUE;
+ done = true;
break;
}
@@ -3299,7 +3495,7 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
if (!done) {
if (!Vcb->options.allow_degraded) {
- ERR("volume not found: device %llx, uuid
%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
tp.item->key.offset,
+ ERR("volume not found: device %I64x, uuid
%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
tp.item->key.offset,
di->device_uuid.uuid[0],
di->device_uuid.uuid[1], di->device_uuid.uuid[2], di->device_uuid.uuid[3],
di->device_uuid.uuid[4], di->device_uuid.uuid[5], di->device_uuid.uuid[6],
di->device_uuid.uuid[7],
di->device_uuid.uuid[8],
di->device_uuid.uuid[9], di->device_uuid.uuid[10], di->device_uuid.uuid[11],
di->device_uuid.uuid[12], di->device_uuid.uuid[13], di->device_uuid.uuid[14],
di->device_uuid.uuid[15]);
} else {
@@ -3323,14 +3519,14 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
}
}
} else
- ERR("unexpected device %llx found\n",
tp.item->key.offset);
+ ERR("unexpected device %I64x found\n",
tp.item->key.offset);
ExReleaseResourceLite(&pdode->child_lock);
}
}
} else if (tp.item->key.obj_type == TYPE_CHUNK_ITEM) {
if (tp.item->size < sizeof(CHUNK_ITEM)) {
- ERR("(%llx,%x,%llx) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(CHUNK_ITEM));
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(CHUNK_ITEM));
} else {
c = ExAllocatePoolWithTag(NonPagedPool, sizeof(chunk), ALLOC_TAG);
@@ -3343,12 +3539,12 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
c->offset = tp.item->key.offset;
c->used = c->oldused = 0;
c->cache = c->old_cache = NULL;
- c->created = FALSE;
- c->readonly = FALSE;
- c->reloc = FALSE;
- c->cache_loaded = FALSE;
- c->changed = FALSE;
- c->space_changed = FALSE;
+ c->created = false;
+ c->readonly = false;
+ c->reloc = false;
+ c->cache_loaded = false;
+ c->changed = false;
+ c->space_changed = false;
c->balance_num = 0;
c->chunk_item = ExAllocatePoolWithTag(NonPagedPool, tp.item->size,
ALLOC_TAG);
@@ -3372,7 +3568,7 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
if (c->chunk_item->type & BLOCK_FLAG_RAID10) {
if (c->chunk_item->sub_stripes == 0 ||
c->chunk_item->sub_stripes > c->chunk_item->num_stripes) {
- ERR("chunk %llx: invalid stripes (num_stripes %u,
sub_stripes %u)\n", c->offset, c->chunk_item->num_stripes,
c->chunk_item->sub_stripes);
+ ERR("chunk %I64x: invalid stripes (num_stripes %u,
sub_stripes %u)\n", c->offset, c->chunk_item->num_stripes,
c->chunk_item->sub_stripes);
ExFreePool(c->chunk_item);
ExFreePool(c);
return STATUS_INTERNAL_ERROR;
@@ -3381,7 +3577,7 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
if (c->chunk_item->num_stripes > 0) {
CHUNK_ITEM_STRIPE* cis =
(CHUNK_ITEM_STRIPE*)&c->chunk_item[1];
- UINT16 i;
+ uint16_t i;
c->devices = ExAllocatePoolWithTag(NonPagedPool, sizeof(device*) *
c->chunk_item->num_stripes, ALLOC_TAG);
@@ -3394,7 +3590,7 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
for (i = 0; i < c->chunk_item->num_stripes; i++) {
c->devices[i] = find_device_from_uuid(Vcb,
&cis[i].dev_uuid);
- TRACE("device %llu = %p\n", i, c->devices[i]);
+ TRACE("device %I64u = %p\n", i, c->devices[i]);
if (!c->devices[i]) {
ERR("missing device\n");
@@ -3404,10 +3600,10 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
}
if (c->devices[i]->readonly)
- c->readonly = TRUE;
+ c->readonly = true;
}
} else {
- ERR("chunk %llx: number of stripes is 0\n", c->offset);
+ ERR("chunk %I64x: number of stripes is 0\n",
c->offset);
ExFreePool(c->chunk_item);
ExFreePool(c);
return STATUS_INTERNAL_ERROR;
@@ -3423,12 +3619,12 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
InitializeListHead(&c->range_locks);
ExInitializeResourceLite(&c->range_locks_lock);
- KeInitializeEvent(&c->range_locks_event, NotificationEvent,
FALSE);
+ KeInitializeEvent(&c->range_locks_event, NotificationEvent,
false);
InitializeListHead(&c->partial_stripes);
ExInitializeResourceLite(&c->partial_stripes_lock);
- c->last_alloc_set = FALSE;
+ c->last_alloc_set = false;
c->last_stripe = 0;
@@ -3438,13 +3634,13 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
}
}
- b = find_next_item(Vcb, &tp, &next_tp, FALSE, Irp);
+ b = find_next_item(Vcb, &tp, &next_tp, false, Irp);
if (b)
tp = next_tp;
} while (b);
- Vcb->log_to_phys_loaded = TRUE;
+ Vcb->log_to_phys_loaded = true;
if (Vcb->data_flags == 0)
Vcb->data_flags = BLOCK_FLAG_DATA | (Vcb->superblock.num_devices > 1 ?
BLOCK_FLAG_RAID0 : 0);
@@ -3464,14 +3660,14 @@ static NTSTATUS load_chunk_root(_In_
_Requires_lock_held_(_Curr_->tree_lock) dev
}
void protect_superblocks(_Inout_ chunk* c) {
- UINT16 i = 0, j;
- UINT64 off_start, off_end;
+ uint16_t i = 0, j;
+ uint64_t off_start, off_end;
// The Linux driver also protects all the space before the first superblock.
// I realize this confuses physical and logical addresses, but this is what
btrfs-progs does -
// evidently Linux assumes the chunk at 0 is always SINGLE.
if (c->offset < superblock_addrs[0])
- space_list_subtract(c, FALSE, c->offset, superblock_addrs[0] - c->offset,
NULL);
+ space_list_subtract(c, false, c->offset, superblock_addrs[0] - c->offset,
NULL);
while (superblock_addrs[i] != 0) {
CHUNK_ITEM* ci = c->chunk_item;
@@ -3479,15 +3675,15 @@ void protect_superblocks(_Inout_ chunk* c) {
if (ci->type & BLOCK_FLAG_RAID0 || ci->type & BLOCK_FLAG_RAID10) {
for (j = 0; j < ci->num_stripes; j++) {
- UINT16 sub_stripes = max(ci->sub_stripes, 1);
+ uint16_t sub_stripes = max(ci->sub_stripes, 1);
if (cis[j].offset + (ci->size * ci->num_stripes / sub_stripes) >
superblock_addrs[i] && cis[j].offset <= superblock_addrs[i] +
sizeof(superblock)) {
#ifdef _DEBUG
- UINT64 startoff;
- UINT16 startoffstripe;
+ uint64_t startoff;
+ uint16_t startoffstripe;
#endif
- TRACE("cut out superblock in chunk %llx\n", c->offset);
+ TRACE("cut out superblock in chunk %I64x\n",
c->offset);
off_start = superblock_addrs[i] - cis[j].offset;
off_start -= off_start % ci->stripe_length;
@@ -3499,18 +3695,18 @@ void protect_superblocks(_Inout_ chunk* c) {
#ifdef _DEBUG
get_raid0_offset(off_start, ci->stripe_length, ci->num_stripes
/ sub_stripes, &startoff, &startoffstripe);
TRACE("j = %u, startoffstripe = %u\n", j, startoffstripe);
- TRACE("startoff = %llx, superblock = %llx\n", startoff +
cis[j].offset, superblock_addrs[i]);
+ TRACE("startoff = %I64x, superblock = %I64x\n", startoff +
cis[j].offset, superblock_addrs[i]);
#endif
- space_list_subtract(c, FALSE, c->offset + off_start, off_end -
off_start, NULL);
+ space_list_subtract(c, false, c->offset + off_start, off_end -
off_start, NULL);
}
}
} else if (ci->type & BLOCK_FLAG_RAID5) {
- UINT64 stripe_size = ci->size / (ci->num_stripes - 1);
+ uint64_t stripe_size = ci->size / (ci->num_stripes - 1);
for (j = 0; j < ci->num_stripes; j++) {
if (cis[j].offset + stripe_size > superblock_addrs[i] &&
cis[j].offset <= superblock_addrs[i] + sizeof(superblock)) {
- TRACE("cut out superblock in chunk %llx\n", c->offset);
+ TRACE("cut out superblock in chunk %I64x\n",
c->offset);
off_start = superblock_addrs[i] - cis[j].offset;
off_start -= off_start % ci->stripe_length;
@@ -3519,17 +3715,17 @@ void protect_superblocks(_Inout_ chunk* c) {
off_end = sector_align(superblock_addrs[i] - cis[j].offset +
sizeof(superblock), ci->stripe_length);
off_end *= ci->num_stripes - 1;
- TRACE("cutting out %llx, size %llx\n", c->offset +
off_start, off_end - off_start);
+ TRACE("cutting out %I64x, size %I64x\n", c->offset +
off_start, off_end - off_start);
- space_list_subtract(c, FALSE, c->offset + off_start, off_end -
off_start, NULL);
+ space_list_subtract(c, false, c->offset + off_start, off_end -
off_start, NULL);
}
}
} else if (ci->type & BLOCK_FLAG_RAID6) {
- UINT64 stripe_size = ci->size / (ci->num_stripes - 2);
+ uint64_t stripe_size = ci->size / (ci->num_stripes - 2);
for (j = 0; j < ci->num_stripes; j++) {
if (cis[j].offset + stripe_size > superblock_addrs[i] &&
cis[j].offset <= superblock_addrs[i] + sizeof(superblock)) {
- TRACE("cut out superblock in chunk %llx\n", c->offset);
+ TRACE("cut out superblock in chunk %I64x\n",
c->offset);
off_start = superblock_addrs[i] - cis[j].offset;
off_start -= off_start % ci->stripe_length;
@@ -3538,22 +3734,22 @@ void protect_superblocks(_Inout_ chunk* c) {
off_end = sector_align(superblock_addrs[i] - cis[j].offset +
sizeof(superblock), ci->stripe_length);
off_end *= ci->num_stripes - 2;
- TRACE("cutting out %llx, size %llx\n", c->offset +
off_start, off_end - off_start);
+ TRACE("cutting out %I64x, size %I64x\n", c->offset +
off_start, off_end - off_start);
- space_list_subtract(c, FALSE, c->offset + off_start, off_end -
off_start, NULL);
+ space_list_subtract(c, false, c->offset + off_start, off_end -
off_start, NULL);
}
}
} else { // SINGLE, DUPLICATE, RAID1
for (j = 0; j < ci->num_stripes; j++) {
if (cis[j].offset + ci->size > superblock_addrs[i] &&
cis[j].offset <= superblock_addrs[i] + sizeof(superblock)) {
- TRACE("cut out superblock in chunk %llx\n", c->offset);
+ TRACE("cut out superblock in chunk %I64x\n",
c->offset);
// The Linux driver protects the whole stripe in which the superblock
lives
off_start = ((superblock_addrs[i] - cis[j].offset) /
c->chunk_item->stripe_length) * c->chunk_item->stripe_length;
off_end = sector_align(superblock_addrs[i] - cis[j].offset +
sizeof(superblock), c->chunk_item->stripe_length);
- space_list_subtract(c, FALSE, c->offset + off_start, off_end -
off_start, NULL);
+ space_list_subtract(c, false, c->offset + off_start, off_end -
off_start, NULL);
}
}
}
@@ -3562,8 +3758,8 @@ void protect_superblocks(_Inout_ chunk* c) {
}
}
-UINT64 chunk_estimate_phys_size(device_extension* Vcb, chunk* c, UINT64 u) {
- UINT64 nfactor, dfactor;
+uint64_t chunk_estimate_phys_size(device_extension* Vcb, chunk* c, uint64_t u) {
+ uint64_t nfactor, dfactor;
if (c->chunk_item->type & BLOCK_FLAG_DUPLICATE || c->chunk_item->type
& BLOCK_FLAG_RAID1 || c->chunk_item->type & BLOCK_FLAG_RAID10) {
nfactor = 1;
@@ -3600,7 +3796,7 @@ NTSTATUS find_chunk_usage(_In_
_Requires_lock_held_(_Curr_->tree_lock) device_ex
searchkey.obj_id = c->offset;
searchkey.offset = c->chunk_item->size;
- Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, FALSE,
Irp);
+ Status = find_item(Vcb, Vcb->extent_root, &tp, &searchkey, false,
Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
return Status;
@@ -3612,11 +3808,11 @@ NTSTATUS find_chunk_usage(_In_
_Requires_lock_held_(_Curr_->tree_lock) device_ex
c->used = c->oldused = bgi->used;
- TRACE("chunk %llx has %llx bytes used\n", c->offset,
c->used);
+ TRACE("chunk %I64x has %I64x bytes used\n", c->offset,
c->used);
Vcb->superblock.bytes_used += chunk_estimate_phys_size(Vcb, c,
bgi->used);
} else {
- ERR("(%llx;%llx,%x,%llx) is %u bytes, expected %u\n",
+ ERR("(%I64x;%I64x,%x,%I64x) is %u bytes, expected %u\n",
Vcb->extent_root->id, tp.item->key.obj_id,
tp.item->key.obj_type, tp.item->key.offset, tp.item->size,
sizeof(BLOCK_GROUP_ITEM));
}
}
@@ -3624,7 +3820,7 @@ NTSTATUS find_chunk_usage(_In_
_Requires_lock_held_(_Curr_->tree_lock) device_ex
le = le->Flink;
}
- Vcb->chunk_usage_found = TRUE;
+ Vcb->chunk_usage_found = true;
return STATUS_SUCCESS;
}
@@ -3640,7 +3836,7 @@ static NTSTATUS load_sys_chunks(_In_ device_extension* Vcb) {
} else
return STATUS_SUCCESS;
- TRACE("bootstrap: %llx,%x,%llx\n", key.obj_id, key.obj_type,
key.offset);
+ TRACE("bootstrap: %I64x,%x,%I64x\n", key.obj_id, key.obj_type,
key.offset);
if (key.obj_type == TYPE_CHUNK_ITEM) {
CHUNK_ITEM* ci;
@@ -3678,7 +3874,7 @@ static NTSTATUS load_sys_chunks(_In_ device_extension* Vcb) {
n -= cisize;
} else {
- ERR("unexpected item %llx,%x,%llx in bootstrap\n", key.obj_id,
key.obj_type, key.offset);
+ ERR("unexpected item %I64x,%x,%I64x in bootstrap\n", key.obj_id,
key.obj_type, key.offset);
return STATUS_INTERNAL_ERROR;
}
}
@@ -3691,7 +3887,7 @@ static root* find_default_subvol(_In_
_Requires_lock_held_(_Curr_->tree_lock) de
LIST_ENTRY* le;
static const char fn[] = "default";
- static UINT32 crc32 = 0x8dbfc2d2;
+ static uint32_t crc32 = 0x8dbfc2d2;
if (Vcb->options.subvol_id != 0) {
le = Vcb->roots.Flink;
@@ -3715,26 +3911,26 @@ static root* find_default_subvol(_In_
_Requires_lock_held_(_Curr_->tree_lock) de
searchkey.obj_type = TYPE_DIR_ITEM;
searchkey.offset = crc32;
- Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, FALSE, Irp);
+ Status = find_item(Vcb, Vcb->root_root, &tp, &searchkey, false, Irp);
if (!NT_SUCCESS(Status)) {
ERR("error - find_item returned %08x\n", Status);
goto end;
}
if (keycmp(tp.item->key, searchkey)) {
- ERR("could not find (%llx,%x,%llx) in root tree\n",
searchkey.obj_id, searchkey.obj_type, searchkey.offset);
+ ERR("could not find (%I64x,%x,%I64x) in root tree\n",
searchkey.obj_id, searchkey.obj_type, searchkey.offset);
goto end;
}
if (tp.item->size < sizeof(DIR_ITEM)) {
- ERR("(%llx,%x,%llx) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DIR_ITEM));
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected at least %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DIR_ITEM));
goto end;
}
di = (DIR_ITEM*)tp.item->data;
if (tp.item->size < sizeof(DIR_ITEM) - 1 + di->n) {
- ERR("(%llx,%x,%llx) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DIR_ITEM) - 1 + di->n);
+ ERR("(%I64x,%x,%I64x) was %u bytes, expected %u\n",
tp.item->key.obj_id, tp.item->key.obj_type, tp.item->key.offset,
tp.item->size, sizeof(DIR_ITEM) - 1 + di->n);
goto end;
}
@@ -3744,7 +3940,7 @@ static root* find_default_subvol(_In_
_Requires_lock_held_(_Curr_->tree_lock) de
}
if (di->key.obj_type != TYPE_ROOT_ITEM) {
- ERR("default root has key (%llx,%x,%llx), expected subvolume\n",
di->key.obj_id, di->key.obj_type, di->key.offset);
+ ERR("default root has key (%I64x,%x,%I64x), expected subvolume\n",
di->key.obj_id, di->key.obj_type, di->key.offset);
goto end;
}
@@ -3758,7 +3954,7 @@ static root* find_default_subvol(_In_
_Requires_lock_held_(_Curr_->tree_lock) de
le = le->Flink;
}
- ERR("could not find root %llx, using default instead\n",
di->key.obj_id);
+ ERR("could not find root %I64x, using default instead\n",
di->key.obj_id);
}
end:
@@ -3778,7 +3974,7 @@ end:
void init_file_cache(_In_ PFILE_OBJECT FileObject, _In_ CC_FILE_SIZES* ccfs) {
TRACE("(%p, %p)\n", FileObject, ccfs);
- CcInitializeCacheMap(FileObject, ccfs, FALSE, cache_callbacks, FileObject);
+ CcInitializeCacheMap(FileObject, ccfs, false, cache_callbacks, FileObject);
if (diskacc)
fCcSetAdditionalCacheAttributesEx(FileObject, CC_ENABLE_DISK_IO_ACCOUNTING);
@@ -3786,11 +3982,25 @@ void init_file_cache(_In_ PFILE_OBJECT FileObject, _In_
CC_FILE_SIZES* ccfs) {
CcSetReadAheadGranularity(FileObject, READ_AHEAD_GRANULARITY);
}
+uint32_t get_num_of_processors() {
+ KAFFINITY p = KeQueryActiveProcessors();
+ uint32_t r = 0;
+
+ while (p != 0) {
+ if (p & 1)
+ r++;
+
+ p >>= 1;
+ }
+
+ return r;
+}
+
static NTSTATUS create_calc_threads(_In_ PDEVICE_OBJECT DeviceObject) {
device_extension* Vcb = DeviceObject->DeviceExtension;
ULONG i;
- Vcb->calcthreads.num_threads = KeQueryActiveProcessorCount(NULL);
+ Vcb->calcthreads.num_threads = get_num_of_processors();
Vcb->calcthreads.threads = ExAllocatePoolWithTag(NonPagedPool,
sizeof(drv_calc_thread) * Vcb->calcthreads.num_threads, ALLOC_TAG);
if (!Vcb->calcthreads.threads) {
@@ -3800,7 +4010,7 @@ static NTSTATUS create_calc_threads(_In_ PDEVICE_OBJECT
DeviceObject) {
InitializeListHead(&Vcb->calcthreads.job_list);
ExInitializeResourceLite(&Vcb->calcthreads.lock);
- KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, FALSE);
+ KeInitializeEvent(&Vcb->calcthreads.event, NotificationEvent, false);
RtlZeroMemory(Vcb->calcthreads.threads, sizeof(drv_calc_thread) *
Vcb->calcthreads.num_threads);
@@ -3808,7 +4018,7 @@ static NTSTATUS create_calc_threads(_In_ PDEVICE_OBJECT
DeviceObject) {
... 34480 lines suppressed ...