@@ -73,35 +73,43 @@ static const char* detectAllocation(FFBtrfsResult* item, int dfd, FFstrbuf* buff
7373 item -> globalReservationUsed = ffStrbufToUInt (buffer , 0 );
7474 item -> globalReservationUsed = item -> globalReservationTotal - item -> globalReservationUsed ;
7575
76- #define FF_BTRFS_DETECT_TYPE (index , _type ) \
77- if (ffReadFileBufferRelative(subfd, #_type "/total_bytes", buffer)) \
78- item->allocation[index].total = ffStrbufToUInt(buffer, 0); \
79- \
80- if (ffReadFileBufferRelative(subfd, #_type "/bytes_used", buffer)) \
81- item->allocation[index].used = ffStrbufToUInt(buffer, 0); \
82- \
83- item->allocation[index].dup = faccessat(subfd, #_type "/dup/", F_OK, 0) == 0; \
76+ #define FF_BTRFS_DETECT_PROFILE (_index , _type , _profile , _copies ) \
77+ else if (faccessat(subfd, _type "/" _profile "/", F_OK, 0) == 0) { \
78+ item->allocation[_index].profile = _profile; \
79+ item->allocation[_index].copies = _copies; \
80+ }
81+
82+ #define FF_BTRFS_DETECT_TYPE (_index , _type ) \
8483 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 ); \
93- \
94- item -> allocation [index ].type = #_type ;
95-
96- FF_BTRFS_DETECT_TYPE (0 , data );
97- FF_BTRFS_DETECT_TYPE (1 , metadata );
98- FF_BTRFS_DETECT_TYPE (2 , system );
84+ item->allocation[_index].type = _type; \
85+ if (ffReadFileBufferRelative(subfd, _type "/total_bytes", buffer)) \
86+ item->allocation[_index].total = ffStrbufToUInt(buffer, 0); \
87+ \
88+ if (ffReadFileBufferRelative(subfd, _type "/bytes_used", buffer)) \
89+ item->allocation[_index].used = ffStrbufToUInt(buffer, 0); \
90+ \
91+ if (false) {} \
92+ FF_BTRFS_DETECT_PROFILE(_index, _type, "single", 1) \
93+ FF_BTRFS_DETECT_PROFILE(_index, _type, "dup", 2) \
94+ FF_BTRFS_DETECT_PROFILE(_index, _type, "raid0", 1) \
95+ FF_BTRFS_DETECT_PROFILE(_index, _type, "raid1", 2) \
96+ FF_BTRFS_DETECT_PROFILE(_index, _type, "raid10", 2) \
97+ FF_BTRFS_DETECT_PROFILE(_index, _type, "raid1c3", 3) \
98+ FF_BTRFS_DETECT_PROFILE(_index, _type, "raid1c4", 4) \
99+ FF_BTRFS_DETECT_PROFILE(_index, _type, "raid5", 1) /* (n-1)/n */ \
100+ FF_BTRFS_DETECT_PROFILE (_index , _type , "raid6" , 1 ) /* (n-2)/n */ \
101+ else { \
102+ item -> allocation [_index ].profile = "unknown" ; \
103+ item -> allocation [_index ].copies = 1 ; \
104+ } \
105+ } while (0 )
106+
107+ FF_BTRFS_DETECT_TYPE (0 , "data" );
108+ FF_BTRFS_DETECT_TYPE (1 , "metadata" );
109+ FF_BTRFS_DETECT_TYPE (2 , "system" );
99110
100111 #undef FF_BTRFS_DETECT_TYPE
101112
102- if (item -> allocation [0 ].copies > 1 ) // index 0 = data
103- item -> totalSize /= item -> allocation [0 ].copies ;
104-
105113 return NULL ;
106114}
107115
0 commit comments