Skip to content

Commit b77646f

Browse files
committed
Btrfs (Linux): adds tracking of Btrfs data copy counts
Fixes(?) #1941
1 parent aa40366 commit b77646f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/detection/btrfs/btrfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ typedef struct FFBtrfsDiskUsage
99
uint64_t used;
1010
const char* type;
1111
bool dup;
12+
uint8_t copies; // 1=single/raid0/raid5/raid6, 2=dup/raid1/raid10, 3=raid1c3, 4=raid1c4
1213
} FFBtrfsDiskUsage;
1314

1415
typedef struct FFBtrfsResult

src/detection/btrfs/btrfs_linux.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buff
8181
item->allocation[index].used = ffStrbufToUInt(buffer, 0); \
8282
\
8383
item->allocation[index].dup = faccessat(subfd, #_type "/dup/", F_OK, 0) == 0; \
84+
do { \
85+
uint8_t _copies = 1; \
86+
if (faccessat(subfd, #_type "/raid1c4/", F_OK, 0) == 0) _copies = 4; \
87+
else if (faccessat(subfd, #_type "/raid1c3/", F_OK, 0) == 0) _copies = 3; \
88+
else if (faccessat(subfd, #_type "/raid1/", F_OK, 0) == 0) _copies = 2; \
89+
else if (faccessat(subfd, #_type "/raid10/", F_OK, 0) == 0) _copies = 2; \
90+
else if (item->allocation[index].dup) _copies = 2; /* DUP on single device */ \
91+
item->allocation[index].copies = _copies; \
92+
} while(0); \
8493
\
8594
item->allocation[index].type = #_type;
8695

@@ -90,6 +99,9 @@ static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buff
9099

91100
#undef FF_BTRFS_DETECT_TYPE
92101

102+
if (item->allocation[0].copies > 1) // index 0 = data
103+
item->totalSize /= item->allocation[0].copies;
104+
93105
return NULL;
94106
}
95107

src/modules/btrfs/btrfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ bool ffGenerateBtrfsJsonResult(FF_MAYBE_UNUSED FFBtrfsOptions* options, yyjson_m
185185
yyjson_mut_val* item = yyjson_mut_arr_add_obj(doc, allocation);
186186
yyjson_mut_obj_add_str(doc, item, "type", btrfs->allocation[i].type);
187187
yyjson_mut_obj_add_bool(doc, item, "dup", btrfs->allocation[i].dup);
188+
yyjson_mut_obj_add_uint(doc, item, "copies", btrfs->allocation[i].copies);
188189
yyjson_mut_obj_add_uint(doc, item, "used", btrfs->allocation[i].used);
189190
yyjson_mut_obj_add_uint(doc, item, "total", btrfs->allocation[i].total);
190191
}

0 commit comments

Comments
 (0)