53#define INCOMPAT_SUPPORTED (BTRFS_INCOMPAT_FLAGS_MIXED_BACKREF | BTRFS_INCOMPAT_FLAGS_DEFAULT_SUBVOL | BTRFS_INCOMPAT_FLAGS_MIXED_GROUPS | \
54 BTRFS_INCOMPAT_FLAGS_COMPRESS_LZO | BTRFS_INCOMPAT_FLAGS_BIG_METADATA | BTRFS_INCOMPAT_FLAGS_RAID56 | \
55 BTRFS_INCOMPAT_FLAGS_EXTENDED_IREF | BTRFS_INCOMPAT_FLAGS_SKINNY_METADATA | BTRFS_INCOMPAT_FLAGS_NO_HOLES | \
56 BTRFS_INCOMPAT_FLAGS_COMPRESS_ZSTD | BTRFS_INCOMPAT_FLAGS_METADATA_UUID | BTRFS_INCOMPAT_FLAGS_RAID1C34)
57#define COMPAT_RO_SUPPORTED (BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE | BTRFS_COMPAT_RO_FLAGS_FREE_SPACE_CACHE_VALID | \
58 BTRFS_COMPAT_RO_FLAGS_VERITY)
61static const WCHAR dosdevice_name[] = {
'\\',
'D',
'o',
's',
'D',
'e',
'v',
'i',
'c',
'e',
's',
'\\',
'B',
't',
'r',
'f',
's',0};
63DEFINE_GUID(BtrfsBusInterface, 0x4d414874, 0x6865, 0x6761, 0x6d, 0x65, 0x83, 0x69, 0x17, 0x9a, 0x7d, 0x1d);
121static void init_serial(
bool first_time);
150#define DEBUG_MESSAGE_LEN 1024
152#ifdef DEBUG_LONG_MESSAGES
155void _debug_message(
_In_ const char*
func,
_In_ char*
s, ...) {
169 DbgPrint(
"Couldn't allocate buffer in debug_message\n");
173#ifdef DEBUG_LONG_MESSAGES
215 Irp->AssociatedIrp.SystemBuffer = buf2;
220 if (!
Irp->MdlAddress) {
227 Irp->UserBuffer = buf2;
256 }
else if (log_handle !=
NULL) {
290#if defined(_ARM_) || defined(_ARM64_)
307#if defined(_AMD64_) || defined(_ARM64_)
323 for (
j = 0;
j <
len;
j++) {
392 searchkey.
obj_id = 0xffffffffffffffff;
394 searchkey.
offset = 0xffffffffffffffff;
398 ERR(
"error - find_item returned %08lx\n",
Status);
404 TRACE(
"last inode for tree %I64x is %I64x\n",
r->id,
r->lastinode);
415 TRACE(
"last inode for tree %I64x is %I64x\n",
r->id,
r->lastinode);
422 WARN(
"no INODE_ITEMs in tree %I64x\n",
r->id);
434 WARN(
"DIR_ITEM is truncated\n");
446 ERR(
"out of memory\n");
457 xasize =
sizeof(
DIR_ITEM) - 1 + xa->
m + xa->
n;
478 TRACE(
"(%p, %I64x, %I64x, %s, %08x, %p, %p)\n",
Vcb, subvol->id,
inode,
name,
crc32,
data,
datalen);
486 ERR(
"error - find_item returned %08lx\n",
Status);
518 TRACE(
"Closing file system\n");
537 Irp->IoStatus.Information = 0;
563 TRACE(
"flush buffers\n");
576 ERR(
"fcb was NULL\n");
581 if (
fcb ==
Vcb->volume_fcb) {
588 Irp->IoStatus.Information = 0;
626 nfactor =
Vcb->superblock.num_devices - 1;
629 nfactor =
Vcb->superblock.num_devices - 2;
642 sectors_used = (
Vcb->superblock.bytes_used >>
Vcb->sector_shift) * nfactor /
dfactor;
644 *totalsize = (
Vcb->superblock.total_bytes >>
Vcb->sector_shift) * nfactor /
dfactor;
645 *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
657 for (
unsigned int i = 0;
i < us1->
Length;
i++) {
662 if (c1 >=
'a' && c1 <=
'z')
665 if (c2 >=
'a' && c2 <=
'z')
679#define INIT_UNICODE_STRING(var, val) UNICODE_STRING us##var; us##var.Buffer = (WCHAR*)val; us##var.Length = us##var.MaximumLength = sizeof(val) - sizeof(WCHAR);
718 ERR(
"ZwQueryInformationProcess returned %08lx\n",
Status);
722 if (!
pbi.PebBaseAddress)
725 peb =
pbi.PebBaseAddress;
733 bool blacklist =
false;
735 if (
entry->FullDllName.Length >= usmpr.Length) {
738 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usmpr.Length) /
sizeof(
WCHAR)];
739 name.Length =
name.MaximumLength = usmpr.Length;
744 if (!blacklist &&
entry->FullDllName.Length >= uscmd.Length) {
747 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - uscmd.Length) /
sizeof(
WCHAR)];
748 name.Length =
name.MaximumLength = uscmd.Length;
753 if (!blacklist &&
entry->FullDllName.Length >= usfsutil.Length) {
756 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usfsutil.Length) /
sizeof(
WCHAR)];
757 name.Length =
name.MaximumLength = usfsutil.Length;
762 if (!blacklist &&
entry->FullDllName.Length >= usstorsvc.Length) {
765 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usstorsvc.Length) /
sizeof(
WCHAR)];
766 name.Length =
name.MaximumLength = usstorsvc.Length;
771 if (!blacklist &&
entry->FullDllName.Length >= usifstest.Length) {
774 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usifstest.Length) /
sizeof(
WCHAR)];
775 name.Length =
name.MaximumLength = usifstest.Length;
786 ERR(
"out of memory\n");
792 for (
i = 0;
i < num_frames;
i++) {
817 for (
ULONG i = 0;
i < src_len;
i++) {
822 else if ((
in[
i] & 0xe0) == 0xc0) {
823 if (
i == src_len - 1 || (
in[
i+1] & 0xc0) != 0x80) {
827 cp = ((
in[
i] & 0x1f) << 6) | (
in[
i+1] & 0x3f);
830 }
else if ((
in[
i] & 0xf0) == 0xe0) {
831 if (
i >= src_len - 2 || (
in[
i+1] & 0xc0) != 0x80 || (
in[
i+2] & 0xc0) != 0x80) {
835 cp = ((
in[
i] & 0xf) << 12) | ((
in[
i+1] & 0x3f) << 6) | (
in[
i+2] & 0x3f);
838 }
else if ((
in[
i] & 0xf8) == 0xf0) {
839 if (
i >= src_len - 3 || (
in[
i+1] & 0xc0) != 0x80 || (
in[
i+2] & 0xc0) != 0x80 || (
in[
i+3] & 0xc0) != 0x80) {
843 cp = ((
in[
i] & 0x7) << 18) | ((
in[
i+1] & 0x3f) << 12) | ((
in[
i+2] & 0x3f) << 6) | (
in[
i+3] & 0x3f);
871 *
out = 0xd800 | ((
cp & 0xffc00) >> 10);
874 *
out = 0xdc00 | (
cp & 0x3ff);
901 for (
ULONG i = 0;
i < in_len;
i++) {
905 if ((
cp & 0xfc00) == 0xd800) {
906 if (
i == in_len - 1 || (*
in & 0xfc00) != 0xdc00) {
910 cp = (
cp & 0x3ff) << 10;
917 }
else if ((
cp & 0xfc00) == 0xdc00) {
936 }
else if (
cp < 0x800) {
940 *
out = 0xc0 | ((
cp & 0x7c0) >> 6);
943 *
out = 0x80 | (
cp & 0x3f);
947 }
else if (
cp < 0x10000) {
951 *
out = 0xe0 | ((
cp & 0xf000) >> 12);
954 *
out = 0x80 | ((
cp & 0xfc0) >> 6);
957 *
out = 0x80 | (
cp & 0x3f);
965 *
out = 0xf0 | ((
cp & 0x1c0000) >> 18);
968 *
out = 0x80 | ((
cp & 0x3f000) >> 12);
971 *
out = 0x80 | ((
cp & 0xfc0) >> 6);
974 *
out = 0x80 | (
cp & 0x3f);
985 else if (
cp < 0x10000)
1008 TRACE(
"query volume information\n");
1027 bool overflow =
false;
1029 static const WCHAR ntfs[] =
L"NTFS";
1031 static const WCHAR btrfs[] =
L"Btrfs";
1032 const WCHAR* fs_name;
1033 ULONG fs_name_len, orig_fs_name_len;
1038 orig_fs_name_len = fs_name_len =
sizeof(ntfs) -
sizeof(
WCHAR);
1041 orig_fs_name_len = fs_name_len =
sizeof(btrfs) -
sizeof(
WCHAR);
1045 orig_fs_name_len = fs_name_len =
sizeof(btrfs) -
sizeof(
WCHAR);
1048 TRACE(
"FileFsAttributeInformation\n");
1068 data->MaximumComponentNameLength = 255;
1069 data->FileSystemNameLength = orig_fs_name_len;
1081 TRACE(
"FileFsDeviceInformation\n");
1104 TRACE(
"FileFsFullSizeInformation\n");
1121 TRACE(
"FileFsObjectIdInformation\n");
1136 TRACE(
"FileFsSizeInformation\n");
1152 bool overflow =
false;
1153 ULONG label_len, orig_label_len;
1155 TRACE(
"FileFsVolumeInformation\n");
1162 ERR(
"utf8_to_utf16 returned %08lx\n",
Status);
1167 orig_label_len = label_len;
1178 TRACE(
"label_len = %lu\n", label_len);
1182 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];
1187 if (label_len > 0) {
1192 ERR(
"utf8_to_utf16 returned %08lx\n",
Status);
1197 TRACE(
"label = %.*S\n", (
int)(label_len /
sizeof(
WCHAR)),
data->VolumeLabel);
1209 case FileFsSectorSizeInformation:
1211 FILE_FS_SECTOR_SIZE_INFORMATION*
data =
Irp->AssociatedIrp.SystemBuffer;
1213 data->LogicalBytesPerSector =
Vcb->superblock.sector_size;
1214 data->PhysicalBytesPerSectorForAtomicity =
Vcb->superblock.sector_size;
1215 data->PhysicalBytesPerSectorForPerformance =
Vcb->superblock.sector_size;
1216 data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity =
Vcb->superblock.sector_size;
1217 data->ByteOffsetForSectorAlignment = 0;
1218 data->ByteOffsetForPartitionAlignment = 0;
1220 data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
1222 if (
Vcb->trim && !
Vcb->options.no_trim)
1223 data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
1225 BytesCopied =
sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
1240 Irp->IoStatus.Information = 0;
1252 TRACE(
"query volume information returning %08lx\n",
Status);
1280 ERR(
"out of memory\n");
1286 ERR(
"out of memory\n");
1293 ERR(
"out of memory\n");
1301 r->treeholder.address = 0;
1302 r->treeholder.generation =
Vcb->superblock.generation;
1303 r->treeholder.tree =
NULL;
1306 r->received =
false;
1311 r->root_item.num_references = 1;
1312 r->fcbs_version = 0;
1313 r->checked_for_orphans =
true;
1325 ERR(
"insert_tree_item returned %08lx\n",
Status);
1339 ERR(
"out of memory\n");
1351 t->is_unique =
true;
1352 t->uniqueness_determined =
true;
1355 r->treeholder.tree =
t;
1359 t->header.address = 0;
1362 t->header.generation =
Vcb->superblock.generation;
1363 t->header.tree_id =
id;
1364 t->header.num_items = 0;
1365 t->header.level = 0;
1367 t->has_address =
false;
1377 t->has_new_address =
false;
1378 t->updated_extents =
false;
1381 t->list_entry_hash.Flink =
NULL;
1384 Vcb->need_write =
true;
1397 TRACE(
"label = %.*S\n", (
int)(ffli->VolumeLabelLength /
sizeof(
WCHAR)), ffli->VolumeLabel);
1399 vollen = ffli->VolumeLabelLength;
1401 for (
i = 0;
i < ffli->VolumeLabelLength /
sizeof(
WCHAR);
i++) {
1402 if (ffli->VolumeLabel[
i] == 0) {
1403 vollen =
i *
sizeof(
WCHAR);
1405 }
else if (ffli->VolumeLabel[
i] ==
'/' || ffli->VolumeLabel[
i] ==
'\\') {
1436 Vcb->need_write =
true;
1457 TRACE(
"set volume information\n");
1471 if (
Vcb->readonly) {
1476 if (
Vcb->removing ||
Vcb->locked) {
1483 FIXME(
"STUB: FileFsControlInformation\n");
1487 TRACE(
"FileFsLabelInformation\n");
1493 FIXME(
"STUB: FileFsObjectIdInformation\n");
1503 Irp->IoStatus.Information = 0;
1524 fn.Length =
fn.MaximumLength = 0;
1527 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1531 if (reqlen > 0xffff) {
1532 WARN(
"reqlen was too long for FsRtlNotifyFilterReportChange\n");
1538 ERR(
"out of memory\n");
1547 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1563 if (fileref->fcb->inode_item.st_nlink == 1) {
1580 ERR(
"open_fileref_by_inode returned %08lx\n",
Status);
1585 fn.Length =
fn.MaximumLength = 0;
1588 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1593 if (parfr !=
fcb->
Vcb->root_fileref)
1594 pathlen +=
sizeof(
WCHAR);
1597 WARN(
"pathlen + hl->name.Length was too long for FsRtlNotifyFilterReportChange\n");
1605 ERR(
"out of memory\n");
1612 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1618 if (parfr !=
fcb->
Vcb->root_fileref) {
1619 fn.Buffer[(pathlen /
sizeof(
WCHAR)) - 1] =
'\\';
1673 ERR(
"out of memory\n");
1679 ERR(
"out of memory\n");
1697#ifdef DEBUG_FCB_REFCOUNTS
1702#ifdef DEBUG_FCB_REFCOUNTS
1704 WARN(
"fcb %p: refcount now %i\n",
fcb, rc);
1714 fcb->
Vcb->need_write =
true;
1718 if (!fileref->dirty) {
1719 fileref->dirty =
true;
1723 InsertTailList(&fileref->fcb->Vcb->dirty_filerefs, &fileref->list_entry_dirty);
1727 fileref->fcb->Vcb->need_write =
true;
1730#ifdef DEBUG_FCB_REFCOUNTS
1738#ifdef DEBUG_FCB_REFCOUNTS
1838 ExFreeToPagedLookasideList(&
fcb->
Vcb->fcb_lookaside,
fcb);
1844 le =
Vcb->all_fcbs.Flink;
1845 while (le != &
Vcb->all_fcbs) {
1857#if defined(_DEBUG) || defined(DEBUG_FCB_REFCOUNTS)
1860#ifdef DEBUG_FCB_REFCOUNTS
1861 ERR(
"fileref %p: refcount now %i\n", fr, rc);
1866 ERR(
"fileref %p: refcount now %li\n", fr, rc);
1903 ExFreeToPagedLookasideList(&
Vcb->fileref_lookaside, fr);
1937 TRACE(
"FCB was NULL, returning success\n");
1945 TRACE(
"close called for fcb %p)\n",
fcb);
1959 if (
fcb->
Vcb->running_sends > 0) {
1960 bool send_cancelled =
false;
1966 send_cancelled =
true;
1972 if (send_cancelled) {
1985 if (open_files == 0 &&
fcb->
Vcb->removing) {
2008 if (!
Vcb->removing) {
2010 Vcb->removing =
true;
2014 if (
Vcb->vde &&
Vcb->vde->mounted_device ==
Vcb->devobj)
2015 Vcb->vde->mounted_device =
NULL;
2018 Vcb->Vpb->Flags &= ~VPB_MOUNTED;
2020 Vcb->Vpb->DeviceObject =
NULL;
2024 if (
Vcb->list_entry.Flink)
2027 if (
Vcb->balance.thread) {
2028 Vcb->balance.paused =
false;
2029 Vcb->balance.stopping =
true;
2034 if (
Vcb->scrub.thread) {
2035 Vcb->scrub.paused =
false;
2036 Vcb->scrub.stopping =
true;
2041 if (
Vcb->running_sends != 0) {
2042 bool send_cancelled =
false;
2046 le =
Vcb->send_ops.Flink;
2047 while (le != &
Vcb->send_ops) {
2050 if (!
send->cancelling) {
2051 send->cancelling =
true;
2052 send_cancelled =
true;
2062 if (send_cancelled) {
2063 while (
Vcb->running_sends != 0) {
2072 WARN(
"registry_mark_volume_unmounted returned %08lx\n",
Status);
2074 for (
i = 0;
i <
Vcb->calcthreads.num_threads;
i++) {
2075 Vcb->calcthreads.threads[
i].quit =
true;
2080 for (
i = 0;
i <
Vcb->calcthreads.num_threads;
i++) {
2098 le =
Vcb->chunks.Flink;
2099 while (le != &
Vcb->chunks) {
2208 if (
Vcb->devobj->AttachedDevice)
2223 ERR(
"excise_extents returned %08lx\n",
Status);
2228 fileref->fcb->Header.AllocationSize.QuadPart = 0;
2229 fileref->fcb->Header.FileSize.QuadPart = 0;
2230 fileref->fcb->Header.ValidDataLength.QuadPart = 0;
2236 ccfs.
FileSize = fileref->fcb->Header.FileSize;
2248 ERR(
"CcSetFileSizes threw exception %08lx\n",
Status);
2253 fileref->fcb->deleted =
true;
2255 le = fileref->children.
Flink;
2256 while (le != &fileref->children) {
2281 if (fileref->deleted) {
2286 if (fileref->fcb->subvol->send_ops > 0) {
2291 fileref->deleted =
true;
2296 TRACE(
"nlink = %u\n", fileref->fcb->inode_item.st_nlink);
2298 if (!fileref->fcb->ads) {
2299 if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
2304 fileref->fcb->inode_item_changed =
true;
2306 if (fileref->fcb->inode_item.st_nlink > 1 || make_orphan) {
2307 fileref->fcb->inode_item.st_nlink--;
2308 fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2309 fileref->fcb->inode_item.sequence++;
2310 fileref->fcb->inode_item.st_ctime =
now;
2314 ERR(
"delete_fileref_fcb returned %08lx\n",
Status);
2321 le = fileref->fcb->hardlinks.
Flink;
2322 while (le != &fileref->fcb->hardlinks) {
2325 if (hl->
parent == fileref->parent->fcb->inode && hl->
index == fileref->dc->index) {
2341 }
else if (fileref->fcb->subvol->parent == fileref->parent->fcb->subvol->id) {
2342 if (fileref->fcb->subvol->root_item.num_references > 1) {
2343 fileref->fcb->subvol->root_item.num_references--;
2353 InsertTailList(&fileref->fcb->Vcb->drop_roots, &fileref->fcb->subvol->list_entry);
2355 le = fileref->children.
Flink;
2356 while (le != &fileref->children) {
2369 fileref->fcb->deleted =
true;
2376 TRACE(
"delete file %.*S\n", (
int)(fileref->dc->name.Length /
sizeof(
WCHAR)), fileref->dc->name.Buffer);
2381 if (!fileref->fcb->ads)
2386 if (!fileref->oldutf8.Buffer)
2387 fileref->oldutf8 = fileref->dc->utf8;
2391 utf8len = fileref->dc->utf8.Length;
2393 fileref->oldindex = fileref->dc->index;
2406 fileref->parent->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2407 fileref->parent->fcb->inode_item.sequence++;
2408 fileref->parent->fcb->inode_item.st_ctime =
now;
2410 if (!fileref->fcb->ads) {
2411 TRACE(
"fileref->parent->fcb->inode_item.st_size (inode %I64x) was %I64x\n", fileref->parent->fcb->inode, fileref->parent->fcb->inode_item.st_size);
2412 fileref->parent->fcb->inode_item.st_size -= utf8len * 2;
2413 TRACE(
"fileref->parent->fcb->inode_item.st_size (inode %I64x) now %I64x\n", fileref->parent->fcb->inode, fileref->parent->fcb->inode_item.st_size);
2414 fileref->parent->fcb->inode_item.st_mtime =
now;
2417 fileref->parent->fcb->inode_item_changed =
true;
2420 if (!fileref->fcb->ads && fileref->parent->dc)
2425 fileref->fcb->subvol->root_item.ctransid = fileref->fcb->Vcb->superblock.generation;
2426 fileref->fcb->subvol->root_item.ctime =
now;
2431 TRACE(
"CcUninitializeCacheMap failed\n");
2455 Irp->IoStatus.Information = 0;
2459 TRACE(
"closing file system\n");
2474 ERR(
"fcb was NULL\n");
2493 TRACE(
"fileref %p, refcount = %li, open_count = %li\n", fileref, fileref ? fileref->
refcount : 0, fileref ? fileref->
open_count : 0);
2513 TRACE(
"unlocking volume\n");
2526#ifdef DEBUG_FCB_REFCOUNTS
2527 ERR(
"fileref %p: open_count now %i\n", fileref, oc);
2531 if (!
fcb->
Vcb->removing) {
2540 ERR(
"delete_fileref_fcb returned %08lx\n",
Status);
2555 if (!fileref->
fcb->
ads || fileref->
dc) {
2571 ERR(
"delete_fileref returned %08lx\n",
Status);
2601 TRACE(
"flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2625 Irp->IoStatus.Information = 0;
2639 if (
len > 2 &&
val[0] ==
'0' &&
val[1] ==
'x') {
2643 for (
i = 2;
i <
len;
i++) {
2646 if (
val[
i] >=
'0' &&
val[
i] <=
'9')
2647 dosnum |=
val[
i] -
'0';
2648 else if (
val[
i] >=
'a' &&
val[
i] <=
'f')
2649 dosnum |=
val[
i] + 10 -
'a';
2650 else if (
val[
i] >=
'A' &&
val[
i] <=
'F')
2651 dosnum |=
val[
i] + 10 -
'a';
2654 TRACE(
"DOSATTRIB: %08lx\n", dosnum);
2673 if (get_file_attributes_from_xattr(eaval, ealen, &dosnum)) {
2682 dosnum &= ~FILE_ATTRIBUTE_DIRECTORY;
2688 dosnum &= ~FILE_ATTRIBUTE_READONLY;
2720 att &= ~FILE_ATTRIBUTE_READONLY;
2751 ERR(
"IoAllocateIrp failed\n");
2765 if (!
Irp->AssociatedIrp.SystemBuffer) {
2766 ERR(
"out of memory\n");
2776 if (!
Irp->MdlAddress) {
2777 ERR(
"IoAllocateMdl failed\n");
2791 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
2857 WARN(
"superblock hash was invalid\n");
2870 WARN(
"superblock hash was invalid\n");
2892 ERR(
"out of memory\n");
2897 WARN(
"device was too short to have any superblock\n");
2903 valid_superblocks = 0;
2911 ERR(
"Failed to read superblock %lu: %08lx\n",
i,
Status);
2918 TRACE(
"not a BTRFS volume\n");
2923 TRACE(
"got superblock %lu!\n",
i);
2926 WARN(
"superblock sector size was 0\n");
2928 WARN(
"superblock sector size was not power of 2\n");
2935 valid_superblocks++;
2944 if (valid_superblocks == 0) {
2945 ERR(
"could not find any valid superblocks\n");
2949 TRACE(
"label is %s\n",
Vcb->superblock.label);
2999 ERR(
"out of memory\n");
3005 r->received =
false;
3012 r->fcbs_version = 0;
3013 r->checked_for_orphans =
false;
3020 ERR(
"out of memory\n");
3041 r->lastinode = 0x100;
3052 Vcb->extent_root =
r;
3056 Vcb->chunk_root =
r;
3064 Vcb->checksum_root =
r;
3072 Vcb->space_root =
r;
3076 Vcb->data_reloc_root =
r;
3095 ERR(
"error - find_item returned %08lx\n",
Status);
3112 ERR(
"add_root returned %08lx\n",
Status);
3129 if (!
Vcb->readonly && !
Vcb->data_reloc_root) {
3137 WARN(
"data reloc root doesn't exist, creating it\n");
3142 ERR(
"create_root returned %08lx\n",
Status);
3148 reloc_root->root_item.inode.st_blocks =
Vcb->superblock.node_size;
3150 reloc_root->root_item.inode.st_mode = 040755;
3151 reloc_root->root_item.inode.flags = 0x80000000;
3152 reloc_root->root_item.inode.flags_ro = 0xffffffff;
3154 reloc_root->root_item.bytes_used =
Vcb->superblock.node_size;
3158 ERR(
"out of memory\n");
3176 ERR(
"insert_tree_item returned %08lx\n",
Status);
3184 ERR(
"out of memory\n");
3195 ERR(
"insert_tree_item returned %08lx\n",
Status);
3201 Vcb->need_write =
true;
3230 ERR(
"error - find_item returned %08lx\n",
Status);
3244 ERR(
"add_space_entry returned %08lx\n",
Status);
3264 if (lastaddr < dev->devitem.num_bytes) {
3267 ERR(
"add_space_entry returned %08lx\n",
Status);
3282 le =
Vcb->devices.Flink;
3284 while (le != &
Vcb->devices) {
3304 le =
Vcb->devices.Flink;
3305 while (le != &
Vcb->devices) {
3308 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,
3309 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],
3310 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]);
3329 if (
Vcb->devices_loaded <
Vcb->superblock.num_devices) {
3341 ERR(
"out of memory\n");
3348 dev->devitem.device_uuid = *
uuid;
3350 dev->devitem.num_bytes = vc->
size;
3352 dev->readonly =
dev->seeding;
3354 dev->removable =
false;
3357 dev->num_trim_entries = 0;
3361 Vcb->devices_loaded++;
3375 WARN(
"could not find device with uuid %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
3389 ERR(
"dev_ioctl returned %08lx\n",
Status);
3404 ERR(
"dev_ioctl returned %08lx\n",
Status);
3409 ERR(
"iosb.Information was too short\n");
3433 WARN(
"IOCTL_STORAGE_GET_DEVICE_NUMBER returned %08lx\n",
Status);
3434 dev->disk_num = 0xffffffff;
3435 dev->part_num = 0xffffffff;
3443 dev->readonly =
dev->seeding;
3445 dev->num_trim_entries = 0;
3446 dev->stats_changed =
false;
3449 if (!
dev->readonly) {
3453 dev->readonly =
true;
3459 ERR(
"out of memory\n");
3473 apte, aptelen,
true,
NULL);
3476 TRACE(
"IOCTL_ATA_PASS_THROUGH returned %08lx for IDENTIFY DEVICE\n",
Status);
3481 dev->can_flush =
true;
3482 TRACE(
"FLUSH CACHE supported\n");
3484 TRACE(
"FLUSH CACHE not supported\n");
3489#ifdef DEBUG_TRIM_EMULATION
3504 TRACE(
"TRIM supported\n");
3506 TRACE(
"TRIM not supported\n");
3524 Vcb->data_flags = 0;
3525 Vcb->metadata_flags = 0;
3526 Vcb->system_flags = 0;
3530 ERR(
"error - find_item returned %08lx\n",
Status);
3545 le =
Vcb->devices.Flink;
3552 if (le !=
Vcb->devices.Flink)
3562 if (!done &&
Vcb->vde) {
3568 if (
Vcb->devices_loaded <
Vcb->superblock.num_devices) {
3580 ERR(
"out of memory\n");
3592 if (
dev->devitem.num_bytes > vc->
size) {
3593 WARN(
"device %I64x: DEV_ITEM says %I64x bytes, but Windows only reports %I64x\n",
tp.
item->
key.
offset,
3594 dev->devitem.num_bytes, vc->
size);
3596 dev->devitem.num_bytes = vc->
size;
3602 Vcb->devices_loaded++;
3612 if (!
Vcb->options.allow_degraded) {
3613 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,
3622 ERR(
"out of memory\n");