mirror of
https://github.com/amadvance/snapraid.git
synced 2026-12-05 06:10:13 -05:00
Avoid to use gcc extensions when allocating the fiemap
This commit is contained in:
parent
ffbbc71bd4
commit
ba18fdaf07
1 changed files with 14 additions and 12 deletions
|
|
@ -768,10 +768,8 @@ int filephy(const char* path, uint64_t size, uint64_t* physical)
|
||||||
/* In Linux get the real physical address of the file */
|
/* In Linux get the real physical address of the file */
|
||||||
/* Note that FIEMAP doesn't require root permission */
|
/* Note that FIEMAP doesn't require root permission */
|
||||||
int f;
|
int f;
|
||||||
struct {
|
struct fiemap* fiemap;
|
||||||
struct fiemap fiemap;
|
size_t fiemap_size;
|
||||||
struct fiemap_extent extent;
|
|
||||||
} fm;
|
|
||||||
unsigned int blknum;
|
unsigned int blknum;
|
||||||
|
|
||||||
f = open(path, O_RDONLY);
|
f = open(path, O_RDONLY);
|
||||||
|
|
@ -781,15 +779,17 @@ int filephy(const char* path, uint64_t size, uint64_t* physical)
|
||||||
|
|
||||||
/* first try with FIEMAP */
|
/* first try with FIEMAP */
|
||||||
/* if works for ext2, ext3, ext4, xfs, btrfs */
|
/* if works for ext2, ext3, ext4, xfs, btrfs */
|
||||||
memset(&fm, 0, sizeof(fm));
|
fiemap_size = sizeof(struct fiemap) + sizeof(struct fiemap_extent);
|
||||||
fm.fiemap.fm_start = 0;
|
fiemap = malloc_nofail(fiemap_size);
|
||||||
fm.fiemap.fm_length = ~0ULL;
|
memset(fiemap, 0, fiemap_size);
|
||||||
fm.fiemap.fm_flags = FIEMAP_FLAG_SYNC; /* required to ensure that just created files report a valid address and not 0 */
|
fiemap->fm_start = 0;
|
||||||
fm.fiemap.fm_extent_count = 1; /* we are interested only at the first block */
|
fiemap->fm_length = ~0ULL;
|
||||||
|
fiemap->fm_flags = FIEMAP_FLAG_SYNC; /* required to ensure that just created files report a valid address and not 0 */
|
||||||
|
fiemap->fm_extent_count = 1; /* we are interested only at the first block */
|
||||||
|
|
||||||
if (ioctl(f, FS_IOC_FIEMAP, &fm) != -1) {
|
if (ioctl(f, FS_IOC_FIEMAP, fiemap) != -1) {
|
||||||
uint32_t flags = fm.fiemap.fm_extents[0].fe_flags;
|
uint32_t flags = fiemap->fm_extents[0].fe_flags;
|
||||||
uint64_t offset = fm.fiemap.fm_extents[0].fe_physical;
|
uint64_t offset = fiemap->fm_extents[0].fe_physical;
|
||||||
|
|
||||||
/* check some condition for validating the offset */
|
/* check some condition for validating the offset */
|
||||||
if (flags & FIEMAP_EXTENT_DATA_INLINE) {
|
if (flags & FIEMAP_EXTENT_DATA_INLINE) {
|
||||||
|
|
@ -812,6 +812,8 @@ int filephy(const char* path, uint64_t size, uint64_t* physical)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(fiemap);
|
||||||
|
|
||||||
/* if the file is empty, FIBMAP doesn't work, and we don't even try to use it */
|
/* if the file is empty, FIBMAP doesn't work, and we don't even try to use it */
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
*physical = FILEPHY_WITHOUT_OFFSET;
|
*physical = FILEPHY_WITHOUT_OFFSET;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue