Btrfs (Linux): adds tracking of Btrfs data copy counts

Fixes(?) #1941
This commit is contained in:
李通洲
2025-09-05 00:12:37 +08:00
committed by Carter Li
parent aa40366a49
commit b77646f23e
3 changed files with 14 additions and 0 deletions
+1
View File
@@ -9,6 +9,7 @@ typedef struct FFBtrfsDiskUsage
uint64_t used;
const char* type;
bool dup;
uint8_t copies; // 1=single/raid0/raid5/raid6, 2=dup/raid1/raid10, 3=raid1c3, 4=raid1c4
} FFBtrfsDiskUsage;
typedef struct FFBtrfsResult
+12
View File
@@ -81,6 +81,15 @@ static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buff
item->allocation[index].used = ffStrbufToUInt(buffer, 0); \
\
item->allocation[index].dup = faccessat(subfd, #_type "/dup/", F_OK, 0) == 0; \
do { \
uint8_t _copies = 1; \
if (faccessat(subfd, #_type "/raid1c4/", F_OK, 0) == 0) _copies = 4; \
else if (faccessat(subfd, #_type "/raid1c3/", F_OK, 0) == 0) _copies = 3; \
else if (faccessat(subfd, #_type "/raid1/", F_OK, 0) == 0) _copies = 2; \
else if (faccessat(subfd, #_type "/raid10/", F_OK, 0) == 0) _copies = 2; \
else if (item->allocation[index].dup) _copies = 2; /* DUP on single device */ \
item->allocation[index].copies = _copies; \
} while(0); \
\
item->allocation[index].type = #_type;
@@ -90,6 +99,9 @@ static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buff
#undef FF_BTRFS_DETECT_TYPE
if (item->allocation[0].copies > 1) // index 0 = data
item->totalSize /= item->allocation[0].copies;
return NULL;
}
+1
View File
@@ -185,6 +185,7 @@ bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
yyjson_mut_val* item = yyjson_mut_arr_add_obj(doc, allocation);
yyjson_mut_obj_add_str(doc, item, "type", btrfs->allocation[i].type);
yyjson_mut_obj_add_bool(doc, item, "dup", btrfs->allocation[i].dup);
yyjson_mut_obj_add_uint(doc, item, "copies", btrfs->allocation[i].copies);
yyjson_mut_obj_add_uint(doc, item, "used", btrfs->allocation[i].used);
yyjson_mut_obj_add_uint(doc, item, "total", btrfs->allocation[i].total);
}