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) 61 static const WCHAR dosdevice_name[] = {
'\\',
'D',
'o',
's',
'D',
'e',
'v',
'i',
'c',
'e',
's',
'\\',
'B',
't',
'r',
'f',
's',0};
63 DEFINE_GUID(BtrfsBusInterface, 0x4d414874, 0x6865, 0x6761, 0x6d, 0x65, 0x83, 0x69, 0x17, 0x9a, 0x7d, 0x1d);
120 static void init_serial(
bool first_time);
149 #define DEBUG_MESSAGE_LEN 1024 151 #ifdef DEBUG_LONG_MESSAGES 154 void _debug_message(
_In_ const char*
func,
_In_ char*
s, ...) {
168 DbgPrint(
"Couldn't allocate buffer in debug_message\n");
172 #ifdef DEBUG_LONG_MESSAGES 214 Irp->AssociatedIrp.SystemBuffer = buf2;
219 if (!
Irp->MdlAddress) {
226 Irp->UserBuffer = buf2;
255 }
else if (log_handle !=
NULL) {
289 #if defined(_ARM_) || defined(_ARM64_) 306 #if defined(_AMD64_) || defined(_ARM64_) 322 for (
j = 0;
j <
len;
j++) {
391 searchkey.
obj_id = 0xffffffffffffffff;
393 searchkey.
offset = 0xffffffffffffffff;
397 ERR(
"error - find_item returned %08lx\n",
Status);
403 TRACE(
"last inode for tree %I64x is %I64x\n",
r->id,
r->lastinode);
414 TRACE(
"last inode for tree %I64x is %I64x\n",
r->id,
r->lastinode);
421 WARN(
"no INODE_ITEMs in tree %I64x\n",
r->id);
433 WARN(
"DIR_ITEM is truncated\n");
445 ERR(
"out of memory\n");
456 xasize =
sizeof(
DIR_ITEM) - 1 + xa->
m + xa->
n;
477 TRACE(
"(%p, %I64x, %I64x, %s, %08x, %p, %p)\n",
Vcb, subvol->id,
inode,
name,
crc32,
data,
datalen);
485 ERR(
"error - find_item returned %08lx\n",
Status);
517 TRACE(
"Closing file system\n");
536 Irp->IoStatus.Information = 0;
562 TRACE(
"flush buffers\n");
575 ERR(
"fcb was NULL\n");
580 if (
fcb ==
Vcb->volume_fcb) {
587 Irp->IoStatus.Information = 0;
625 nfactor =
Vcb->superblock.num_devices - 1;
628 nfactor =
Vcb->superblock.num_devices - 2;
641 sectors_used = (
Vcb->superblock.bytes_used >>
Vcb->sector_shift) * nfactor /
dfactor;
643 *totalsize = (
Vcb->superblock.total_bytes >>
Vcb->sector_shift) * nfactor /
dfactor;
644 *freespace = sectors_used > *totalsize ? 0 : (*totalsize - sectors_used);
648 #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); 687 ERR(
"ZwQueryInformationProcess returned %08lx\n",
Status);
691 if (!
pbi.PebBaseAddress)
694 peb =
pbi.PebBaseAddress;
702 bool blacklist =
false;
704 if (
entry->FullDllName.Length >= usmpr.Length) {
707 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usmpr.Length) /
sizeof(
WCHAR)];
708 name.Length =
name.MaximumLength = usmpr.Length;
713 if (!blacklist &&
entry->FullDllName.Length >= uscmd.Length) {
716 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - uscmd.Length) /
sizeof(
WCHAR)];
717 name.Length =
name.MaximumLength = uscmd.Length;
722 if (!blacklist &&
entry->FullDllName.Length >= usfsutil.Length) {
725 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usfsutil.Length) /
sizeof(
WCHAR)];
726 name.Length =
name.MaximumLength = usfsutil.Length;
731 if (!blacklist &&
entry->FullDllName.Length >= usstorsvc.Length) {
734 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usstorsvc.Length) /
sizeof(
WCHAR)];
735 name.Length =
name.MaximumLength = usstorsvc.Length;
740 if (!blacklist &&
entry->FullDllName.Length >= usifstest.Length) {
743 name.Buffer = &
entry->FullDllName.Buffer[(
entry->FullDllName.Length - usifstest.Length) /
sizeof(
WCHAR)];
744 name.Length =
name.MaximumLength = usifstest.Length;
755 ERR(
"out of memory\n");
761 for (
i = 0;
i < num_frames;
i++) {
777 #endif // __REACTOS__ 786 for (
ULONG i = 0;
i < src_len;
i++) {
791 else if ((
in[
i] & 0xe0) == 0xc0) {
792 if (
i == src_len - 1 || (
in[
i+1] & 0xc0) != 0x80) {
796 cp = ((
in[
i] & 0x1f) << 6) | (
in[
i+1] & 0x3f);
799 }
else if ((
in[
i] & 0xf0) == 0xe0) {
800 if (
i >= src_len - 2 || (
in[
i+1] & 0xc0) != 0x80 || (
in[
i+2] & 0xc0) != 0x80) {
804 cp = ((
in[
i] & 0xf) << 12) | ((
in[
i+1] & 0x3f) << 6) | (
in[
i+2] & 0x3f);
807 }
else if ((
in[
i] & 0xf8) == 0xf0) {
808 if (
i >= src_len - 3 || (
in[
i+1] & 0xc0) != 0x80 || (
in[
i+2] & 0xc0) != 0x80 || (
in[
i+3] & 0xc0) != 0x80) {
812 cp = ((
in[
i] & 0x7) << 18) | ((
in[
i+1] & 0x3f) << 12) | ((
in[
i+2] & 0x3f) << 6) | (
in[
i+3] & 0x3f);
840 *
out = 0xd800 | ((
cp & 0xffc00) >> 10);
843 *
out = 0xdc00 | (
cp & 0x3ff);
870 for (
ULONG i = 0;
i < in_len;
i++) {
874 if ((
cp & 0xfc00) == 0xd800) {
875 if (
i == in_len - 1 || (*
in & 0xfc00) != 0xdc00) {
879 cp = (
cp & 0x3ff) << 10;
886 }
else if ((
cp & 0xfc00) == 0xdc00) {
905 }
else if (
cp < 0x800) {
909 *
out = 0xc0 | ((
cp & 0x7c0) >> 6);
912 *
out = 0x80 | (
cp & 0x3f);
916 }
else if (
cp < 0x10000) {
920 *
out = 0xe0 | ((
cp & 0xf000) >> 12);
923 *
out = 0x80 | ((
cp & 0xfc0) >> 6);
926 *
out = 0x80 | (
cp & 0x3f);
934 *
out = 0xf0 | ((
cp & 0x1c0000) >> 18);
937 *
out = 0x80 | ((
cp & 0x3f000) >> 12);
940 *
out = 0x80 | ((
cp & 0xfc0) >> 6);
943 *
out = 0x80 | (
cp & 0x3f);
954 else if (
cp < 0x10000)
977 TRACE(
"query volume information\n");
996 bool overflow =
false;
998 static const WCHAR ntfs[] =
L"NTFS";
1000 static const WCHAR btrfs[] =
L"Btrfs";
1001 const WCHAR* fs_name;
1002 ULONG fs_name_len, orig_fs_name_len;
1007 orig_fs_name_len = fs_name_len =
sizeof(ntfs) -
sizeof(
WCHAR);
1010 orig_fs_name_len = fs_name_len =
sizeof(btrfs) -
sizeof(
WCHAR);
1014 orig_fs_name_len = fs_name_len =
sizeof(btrfs) -
sizeof(
WCHAR);
1017 TRACE(
"FileFsAttributeInformation\n");
1037 data->MaximumComponentNameLength = 255;
1038 data->FileSystemNameLength = orig_fs_name_len;
1050 TRACE(
"FileFsDeviceInformation\n");
1073 TRACE(
"FileFsFullSizeInformation\n");
1090 TRACE(
"FileFsObjectIdInformation\n");
1105 TRACE(
"FileFsSizeInformation\n");
1121 bool overflow =
false;
1122 ULONG label_len, orig_label_len;
1124 TRACE(
"FileFsVolumeInformation\n");
1131 ERR(
"utf8_to_utf16 returned %08lx\n",
Status);
1136 orig_label_len = label_len;
1147 TRACE(
"label_len = %lu\n", label_len);
1151 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];
1156 if (label_len > 0) {
1161 ERR(
"utf8_to_utf16 returned %08lx\n",
Status);
1166 TRACE(
"label = %.*S\n", (
int)(label_len /
sizeof(
WCHAR)),
data->VolumeLabel);
1177 #ifdef _MSC_VER // not in mingw yet 1178 case FileFsSectorSizeInformation:
1180 FILE_FS_SECTOR_SIZE_INFORMATION*
data =
Irp->AssociatedIrp.SystemBuffer;
1182 data->LogicalBytesPerSector =
Vcb->superblock.sector_size;
1183 data->PhysicalBytesPerSectorForAtomicity =
Vcb->superblock.sector_size;
1184 data->PhysicalBytesPerSectorForPerformance =
Vcb->superblock.sector_size;
1185 data->FileSystemEffectivePhysicalBytesPerSectorForAtomicity =
Vcb->superblock.sector_size;
1186 data->ByteOffsetForSectorAlignment = 0;
1187 data->ByteOffsetForPartitionAlignment = 0;
1189 data->Flags = SSINFO_FLAGS_ALIGNED_DEVICE | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
1191 if (
Vcb->trim && !
Vcb->options.no_trim)
1192 data->Flags |= SSINFO_FLAGS_TRIM_ENABLED;
1194 BytesCopied =
sizeof(FILE_FS_SECTOR_SIZE_INFORMATION);
1204 WARN(
"unknown FsInformationClass %u\n",
IrpSp->
Parameters.QueryVolume.FsInformationClass);
1209 Irp->IoStatus.Information = 0;
1221 TRACE(
"query volume information returning %08lx\n",
Status);
1249 ERR(
"out of memory\n");
1255 ERR(
"out of memory\n");
1262 ERR(
"out of memory\n");
1270 r->treeholder.address = 0;
1271 r->treeholder.generation =
Vcb->superblock.generation;
1272 r->treeholder.tree =
NULL;
1275 r->received =
false;
1280 r->root_item.num_references = 1;
1281 r->fcbs_version = 0;
1282 r->checked_for_orphans =
true;
1294 ERR(
"insert_tree_item returned %08lx\n",
Status);
1308 ERR(
"out of memory\n");
1320 t->is_unique =
true;
1321 t->uniqueness_determined =
true;
1324 r->treeholder.tree =
t;
1328 t->header.address = 0;
1331 t->header.generation =
Vcb->superblock.generation;
1332 t->header.tree_id =
id;
1333 t->header.num_items = 0;
1334 t->header.level = 0;
1336 t->has_address =
false;
1346 t->has_new_address =
false;
1347 t->updated_extents =
false;
1350 t->list_entry_hash.Flink =
NULL;
1353 Vcb->need_write =
true;
1366 TRACE(
"label = %.*S\n", (
int)(ffli->VolumeLabelLength /
sizeof(
WCHAR)), ffli->VolumeLabel);
1368 vollen = ffli->VolumeLabelLength;
1370 for (
i = 0;
i < ffli->VolumeLabelLength /
sizeof(
WCHAR);
i++) {
1371 if (ffli->VolumeLabel[
i] == 0) {
1372 vollen =
i *
sizeof(
WCHAR);
1374 }
else if (ffli->VolumeLabel[
i] ==
'/' || ffli->VolumeLabel[
i] ==
'\\') {
1405 Vcb->need_write =
true;
1426 TRACE(
"set volume information\n");
1440 if (
Vcb->readonly) {
1445 if (
Vcb->removing ||
Vcb->locked) {
1452 FIXME(
"STUB: FileFsControlInformation\n");
1456 TRACE(
"FileFsLabelInformation\n");
1462 FIXME(
"STUB: FileFsObjectIdInformation\n");
1466 WARN(
"Unrecognized FsInformationClass 0x%x\n",
IrpSp->
Parameters.SetVolume.FsInformationClass);
1472 Irp->IoStatus.Information = 0;
1493 fn.Length =
fn.MaximumLength = 0;
1496 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1500 if (reqlen > 0xffff) {
1501 WARN(
"reqlen was too long for FsRtlNotifyFilterReportChange\n");
1507 ERR(
"out of memory\n");
1516 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1532 if (fileref->fcb->inode_item.st_nlink == 1) {
1549 ERR(
"open_fileref_by_inode returned %08lx\n",
Status);
1554 fn.Length =
fn.MaximumLength = 0;
1557 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1562 if (parfr !=
fcb->
Vcb->root_fileref)
1563 pathlen +=
sizeof(
WCHAR);
1566 WARN(
"pathlen + hl->name.Length was too long for FsRtlNotifyFilterReportChange\n");
1574 ERR(
"out of memory\n");
1581 ERR(
"fileref_get_filename returned %08lx\n",
Status);
1587 if (parfr !=
fcb->
Vcb->root_fileref) {
1588 fn.Buffer[(pathlen /
sizeof(
WCHAR)) - 1] =
'\\';
1642 ERR(
"out of memory\n");
1648 ERR(
"out of memory\n");
1666 #ifdef DEBUG_FCB_REFCOUNTS 1671 #ifdef DEBUG_FCB_REFCOUNTS 1673 WARN(
"fcb %p: refcount now %i\n",
fcb, rc);
1683 fcb->
Vcb->need_write =
true;
1687 if (!fileref->dirty) {
1688 fileref->dirty =
true;
1692 InsertTailList(&fileref->fcb->Vcb->dirty_filerefs, &fileref->list_entry_dirty);
1696 fileref->fcb->Vcb->need_write =
true;
1699 #ifdef DEBUG_FCB_REFCOUNTS 1707 #ifdef DEBUG_FCB_REFCOUNTS 1807 ExFreeToPagedLookasideList(&
fcb->
Vcb->fcb_lookaside,
fcb);
1813 le =
Vcb->all_fcbs.Flink;
1814 while (le != &
Vcb->all_fcbs) {
1826 #if defined(_DEBUG) || defined(DEBUG_FCB_REFCOUNTS) 1829 #ifdef DEBUG_FCB_REFCOUNTS 1830 ERR(
"fileref %p: refcount now %i\n", fr, rc);
1835 ERR(
"fileref %p: refcount now %li\n", fr, rc);
1872 ExFreeToPagedLookasideList(&
Vcb->fileref_lookaside, fr);
1906 TRACE(
"FCB was NULL, returning success\n");
1914 TRACE(
"close called for fcb %p)\n",
fcb);
1928 if (
fcb->
Vcb->running_sends > 0) {
1929 bool send_cancelled =
false;
1935 send_cancelled =
true;
1941 if (send_cancelled) {
1954 if (open_files == 0 &&
fcb->
Vcb->removing) {
1977 if (!
Vcb->removing) {
1979 Vcb->removing =
true;
1983 if (
Vcb->vde &&
Vcb->vde->mounted_device ==
Vcb->devobj)
1984 Vcb->vde->mounted_device =
NULL;
1989 Vcb->Vpb->DeviceObject =
NULL;
1993 if (
Vcb->list_entry.Flink)
1996 if (
Vcb->balance.thread) {
1997 Vcb->balance.paused =
false;
1998 Vcb->balance.stopping =
true;
2003 if (
Vcb->scrub.thread) {
2004 Vcb->scrub.paused =
false;
2005 Vcb->scrub.stopping =
true;
2010 if (
Vcb->running_sends != 0) {
2011 bool send_cancelled =
false;
2015 le =
Vcb->send_ops.Flink;
2016 while (le != &
Vcb->send_ops) {
2019 if (!
send->cancelling) {
2020 send->cancelling =
true;
2021 send_cancelled =
true;
2031 if (send_cancelled) {
2032 while (
Vcb->running_sends != 0) {
2041 WARN(
"registry_mark_volume_unmounted returned %08lx\n",
Status);
2043 for (
i = 0;
i <
Vcb->calcthreads.num_threads;
i++) {
2044 Vcb->calcthreads.threads[
i].quit =
true;
2049 for (
i = 0;
i <
Vcb->calcthreads.num_threads;
i++) {
2067 le =
Vcb->chunks.Flink;
2068 while (le != &
Vcb->chunks) {
2177 if (
Vcb->devobj->AttachedDevice)
2192 ERR(
"excise_extents returned %08lx\n",
Status);
2197 fileref->fcb->Header.AllocationSize.QuadPart = 0;
2198 fileref->fcb->Header.FileSize.QuadPart = 0;
2199 fileref->fcb->Header.ValidDataLength.QuadPart = 0;
2205 ccfs.
FileSize = fileref->fcb->Header.FileSize;
2217 ERR(
"CcSetFileSizes threw exception %08lx\n",
Status);
2222 fileref->fcb->deleted =
true;
2224 le = fileref->children.
Flink;
2225 while (le != &fileref->children) {
2250 if (fileref->deleted) {
2255 if (fileref->fcb->subvol->send_ops > 0) {
2260 fileref->deleted =
true;
2265 TRACE(
"nlink = %u\n", fileref->fcb->inode_item.st_nlink);
2267 if (!fileref->fcb->ads) {
2268 if (fileref->parent->fcb->subvol == fileref->fcb->subvol) {
2273 fileref->fcb->inode_item_changed =
true;
2275 if (fileref->fcb->inode_item.st_nlink > 1 || make_orphan) {
2276 fileref->fcb->inode_item.st_nlink--;
2277 fileref->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2278 fileref->fcb->inode_item.sequence++;
2279 fileref->fcb->inode_item.st_ctime =
now;
2283 ERR(
"delete_fileref_fcb returned %08lx\n",
Status);
2290 le = fileref->fcb->hardlinks.
Flink;
2291 while (le != &fileref->fcb->hardlinks) {
2294 if (hl->
parent == fileref->parent->fcb->inode && hl->
index == fileref->dc->index) {
2310 }
else if (fileref->fcb->subvol->parent == fileref->parent->fcb->subvol->id) {
2311 if (fileref->fcb->subvol->root_item.num_references > 1) {
2312 fileref->fcb->subvol->root_item.num_references--;
2322 InsertTailList(&fileref->fcb->Vcb->drop_roots, &fileref->fcb->subvol->list_entry);
2324 le = fileref->children.
Flink;
2325 while (le != &fileref->children) {
2338 fileref->fcb->deleted =
true;
2345 TRACE(
"delete file %.*S\n", (
int)(fileref->dc->name.Length /
sizeof(
WCHAR)), fileref->dc->name.Buffer);
2350 if (!fileref->fcb->ads)
2355 if (!fileref->oldutf8.Buffer)
2356 fileref->oldutf8 = fileref->dc->utf8;
2360 utf8len = fileref->dc->utf8.Length;
2362 fileref->oldindex = fileref->dc->index;
2375 fileref->parent->fcb->inode_item.transid = fileref->fcb->Vcb->superblock.generation;
2376 fileref->parent->fcb->inode_item.sequence++;
2377 fileref->parent->fcb->inode_item.st_ctime =
now;
2379 if (!fileref->fcb->ads) {
2380 TRACE(
"fileref->parent->fcb->inode_item.st_size (inode %I64x) was %I64x\n", fileref->parent->fcb->inode, fileref->parent->fcb->inode_item.st_size);
2381 fileref->parent->fcb->inode_item.st_size -= utf8len * 2;
2382 TRACE(
"fileref->parent->fcb->inode_item.st_size (inode %I64x) now %I64x\n", fileref->parent->fcb->inode, fileref->parent->fcb->inode_item.st_size);
2383 fileref->parent->fcb->inode_item.st_mtime =
now;
2386 fileref->parent->fcb->inode_item_changed =
true;
2389 if (!fileref->fcb->ads && fileref->parent->dc)
2394 fileref->fcb->subvol->root_item.ctransid = fileref->fcb->Vcb->superblock.generation;
2395 fileref->fcb->subvol->root_item.ctime =
now;
2400 TRACE(
"CcUninitializeCacheMap failed\n");
2424 Irp->IoStatus.Information = 0;
2428 TRACE(
"closing file system\n");
2443 ERR(
"fcb was NULL\n");
2462 TRACE(
"fileref %p, refcount = %li, open_count = %li\n", fileref, fileref ? fileref->
refcount : 0, fileref ? fileref->
open_count : 0);
2482 TRACE(
"unlocking volume\n");
2495 #ifdef DEBUG_FCB_REFCOUNTS 2496 ERR(
"fileref %p: open_count now %i\n", fileref, oc);
2500 if (!
fcb->
Vcb->removing) {
2509 ERR(
"delete_fileref_fcb returned %08lx\n",
Status);
2524 if (!fileref->
fcb->
ads || fileref->
dc) {
2540 ERR(
"delete_fileref returned %08lx\n",
Status);
2570 TRACE(
"flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2594 Irp->IoStatus.Information = 0;
2608 if (
len > 2 &&
val[0] ==
'0' &&
val[1] ==
'x') {
2612 for (
i = 2;
i <
len;
i++) {
2615 if (
val[
i] >=
'0' &&
val[
i] <=
'9')
2616 dosnum |=
val[
i] -
'0';
2617 else if (
val[
i] >=
'a' &&
val[
i] <=
'f')
2618 dosnum |=
val[
i] + 10 -
'a';
2619 else if (
val[
i] >=
'A' &&
val[
i] <=
'F')
2620 dosnum |=
val[
i] + 10 -
'a';
2623 TRACE(
"DOSATTRIB: %08lx\n", dosnum);
2642 if (get_file_attributes_from_xattr(eaval, ealen, &dosnum)) {
2720 ERR(
"IoAllocateIrp failed\n");
2734 if (!
Irp->AssociatedIrp.SystemBuffer) {
2735 ERR(
"out of memory\n");
2745 if (!
Irp->MdlAddress) {
2746 ERR(
"IoAllocateMdl failed\n");
2760 ERR(
"MmProbeAndLockPages threw exception %08lx\n",
Status);
2826 WARN(
"superblock hash was invalid\n");
2839 WARN(
"superblock hash was invalid\n");
2861 ERR(
"out of memory\n");
2866 WARN(
"device was too short to have any superblock\n");
2872 valid_superblocks = 0;
2880 ERR(
"Failed to read superblock %lu: %08lx\n",
i,
Status);
2887 TRACE(
"not a BTRFS volume\n");
2892 TRACE(
"got superblock %lu!\n",
i);
2895 WARN(
"superblock sector size was 0\n");
2897 WARN(
"superblock sector size was not power of 2\n");
2904 valid_superblocks++;
2913 if (valid_superblocks == 0) {
2914 ERR(
"could not find any valid superblocks\n");
2918 TRACE(
"label is %s\n",
Vcb->superblock.label);
2968 ERR(
"out of memory\n");
2974 r->received =
false;
2981 r->fcbs_version = 0;
2982 r->checked_for_orphans =
false;
2989 ERR(
"out of memory\n");
3010 r->lastinode = 0x100;
3021 Vcb->extent_root =
r;
3025 Vcb->chunk_root =
r;
3033 Vcb->checksum_root =
r;
3041 Vcb->space_root =
r;
3045 Vcb->data_reloc_root =
r;
3064 ERR(
"error - find_item returned %08lx\n",
Status);
3081 ERR(
"add_root returned %08lx\n",
Status);
3098 if (!
Vcb->readonly && !
Vcb->data_reloc_root) {
3106 WARN(
"data reloc root doesn't exist, creating it\n");
3111 ERR(
"create_root returned %08lx\n",
Status);
3117 reloc_root->root_item.inode.st_blocks =
Vcb->superblock.node_size;
3119 reloc_root->root_item.inode.st_mode = 040755;
3120 reloc_root->root_item.inode.flags = 0x80000000;
3121 reloc_root->root_item.inode.flags_ro = 0xffffffff;
3123 reloc_root->root_item.bytes_used =
Vcb->superblock.node_size;
3127 ERR(
"out of memory\n");
3145 ERR(
"insert_tree_item returned %08lx\n",
Status);
3153 ERR(
"out of memory\n");
3164 ERR(
"insert_tree_item returned %08lx\n",
Status);
3170 Vcb->need_write =
true;
3199 ERR(
"error - find_item returned %08lx\n",
Status);
3213 ERR(
"add_space_entry returned %08lx\n",
Status);
3233 if (lastaddr < dev->devitem.num_bytes) {
3236 ERR(
"add_space_entry returned %08lx\n",
Status);
3251 le =
Vcb->devices.Flink;
3253 while (le != &
Vcb->devices) {
3273 le =
Vcb->devices.Flink;
3274 while (le != &
Vcb->devices) {
3277 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,
3278 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],
3279 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]);
3298 if (
Vcb->devices_loaded <
Vcb->superblock.num_devices) {
3310 ERR(
"out of memory\n");
3317 dev->devitem.device_uuid = *
uuid;
3319 dev->devitem.num_bytes = vc->
size;
3321 dev->readonly =
dev->seeding;
3323 dev->removable =
false;
3326 dev->num_trim_entries = 0;
3330 Vcb->devices_loaded++;
3344 WARN(
"could not find device with uuid %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
3358 ERR(
"dev_ioctl returned %08lx\n",
Status);
3373 ERR(
"dev_ioctl returned %08lx\n",
Status);
3378 ERR(
"iosb.Information was too short\n");
3402 WARN(
"IOCTL_STORAGE_GET_DEVICE_NUMBER returned %08lx\n",
Status);
3403 dev->disk_num = 0xffffffff;
3404 dev->part_num = 0xffffffff;
3412 dev->readonly =
dev->seeding;
3414 dev->num_trim_entries = 0;
3415 dev->stats_changed =
false;
3418 if (!
dev->readonly) {
3422 dev->readonly =
true;
3428 ERR(
"out of memory\n");
3442 apte, aptelen,
true,
NULL);
3445 TRACE(
"IOCTL_ATA_PASS_THROUGH returned %08lx for IDENTIFY DEVICE\n",
Status);
3450 dev->can_flush =
true;
3451 TRACE(
"FLUSH CACHE supported\n");
3453 TRACE(
"FLUSH CACHE not supported\n");
3458 #ifdef DEBUG_TRIM_EMULATION 3473 TRACE(
"TRIM supported\n");
3475 TRACE(
"TRIM not supported\n");
3493 Vcb->data_flags = 0;
3494 Vcb->metadata_flags = 0;
3495 Vcb->system_flags = 0;
3499 ERR(
"error - find_item returned %08lx\n",
Status);
3514 le =
Vcb->devices.Flink;
3521 if (le !=
Vcb->devices.Flink)
3531 if (!done &&
Vcb->vde) {
3537 if (
Vcb->devices_loaded <
Vcb->superblock.num_devices) {
3549 ERR(
"out of memory\n");
3561 if (
dev->devitem.num_bytes > vc->
size) {
3562 WARN(
"device %I64x: DEV_ITEM says %I64x bytes, but Windows only reports %I64x\n",
tp.
item->
key.
offset,
3563 dev->devitem.num_bytes, vc->
size);
3565 dev->devitem.num_bytes = vc->
size;
3571 Vcb->devices_loaded++;
3581 if (!
Vcb->options.allow_degraded) {
3582 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,
3591 ERR(
"out of memory\n");
3602 Vcb->devices_loaded++;
3618 ERR(
"out of memory\n");
3624 c->used =
c->oldused = 0;
3625 c->cache =
c->old_cache =
NULL;
3627 c->readonly =
false;
3629 c->cache_loaded =
false;
3631 c->space_changed =
false;
3636 if (!
c->chunk_item) {
3637 ERR(
"out of memory\n");
3645 Vcb->data_flags =
c->chunk_item->type;
3648 Vcb->metadata_flags =
c->chunk_item->type;
3651 Vcb->system_flags =
c->chunk_item->type;
3654 if (
c->chunk_item->sub_stripes == 0 ||
c->chunk_item->sub_stripes >
c->chunk_item->num_stripes) {
3655 ERR(
"chunk %I64x: invalid stripes (num_stripes %u, sub_stripes %u)\n",
c->offset,
c->chunk_item->num_stripes,
c->chunk_item->sub_stripes);
3662 if (
c->chunk_item->num_stripes > 0) {
3669 ERR(
"out of memory\n");
3675 for (
i = 0;
i <
c->chunk_item->num_stripes;
i++) {
3677 TRACE(
"device %u = %p\n",
i,
c->devices[
i]);
3679 if (!
c->devices[
i]) {
3680 ERR(
"missing device\n");
3686 if (
c->devices[
i]->readonly)
3690 ERR(
"chunk %I64x: number of stripes is 0\n",
c->offset);
3711 c->last_alloc_set =
false;
3717 c->list_entry_balance.Flink =
NULL;
3727 Vcb->log_to_phys_loaded =
true;
3729 if (
Vcb->data_flags == 0)
3732 if (
Vcb->metadata_flags == 0)
3735 if (
Vcb->system_flags == 0)
3740 Vcb->data_flags =
Vcb->metadata_flags;
3770 TRACE(
"cut out superblock in chunk %I64x\n",
c->offset);
3781 TRACE(
"j = %u, startoffstripe = %u\n",
j, startoffstripe);
3793 TRACE(
"cut out superblock in chunk %I64x\n",
c->offset);
3802 TRACE(
"cutting out %I64x, size %I64x\n",
c->offset + off_start, off_end - off_start);
3812 TRACE(
"cut out superblock in chunk %I64x\n",
c->offset);
3821 TRACE(
"cutting out %I64x, size %I64x\n",
c->offset + off_start, off_end - off_start);
3829 TRACE(
"cut out superblock in chunk %I64x\n",
c->offset);
3855 Vcb->superblock.bytes_used = 0;
3857 while (le != &
Vcb->chunks) {
3861 searchkey.
offset =
c->chunk_item->size;
3865 ERR(
"error - find_item returned %08lx\n",
Status);
3873 c->used =
c->oldused = bgi->
used;
3875 TRACE(
"chunk %I64x has %I64x bytes used\n",
c->offset,
c->used);
3877 Vcb->superblock.bytes_used += bgi->
used;
3879 ERR(
"(%I64x;%I64x,%x,%I64x