Assumes ioctl() failed only if it returns -1.

This happens when dealing with btrfs.
This commit is contained in:
Andrea Mazzoleni 2013-09-24 22:27:41 +02:00
parent 4eee6b9c4a
commit 73c16ffd88
2 changed files with 4 additions and 5 deletions

View file

@ -4,8 +4,7 @@ SnapRAID HISTORY
4.1 2013/9
==========
* If the underline filesystem doesn't support the FIEMAP command,
automatically fallback to use FIBMAP and then the inode number for sorting
files.
automatically fallback to use FIBMAP for sorting files.
* Fixes the import of content files from previous version of SnapRAID that
are the result of an incomplete sync.
* Added a new -C, --gen-conf option to generate a dummy configuration

6
unix.c
View file

@ -141,14 +141,14 @@ int filephy(const char* path, struct stat* st, uint64_t* physical)
}
/* first try with FIEMAP */
/* if works for ext2, ext3, ext4, xfs */
/* if works for ext2, ext3, ext4, xfs, btrfs */
memset(&fm, 0, sizeof(fm));
fm.fiemap.fm_start = 0;
fm.fiemap.fm_length = ~0ULL;
fm.fiemap.fm_flags = FIEMAP_FLAG_SYNC; /* required to ensure that just created files report a valid address and not 0 */
fm.fiemap.fm_extent_count = 1; /* we are interested only at the first block */
if (ioctl(f, FS_IOC_FIEMAP, &fm) == 0) {
if (ioctl(f, FS_IOC_FIEMAP, &fm) != -1) {
*physical = fm.fiemap.fm_extents[0].fe_physical;
if (close(f) == -1)
return -1;
@ -167,7 +167,7 @@ int filephy(const char* path, struct stat* st, uint64_t* physical)
/* it works for jfs, reiserfs, ntfs-3g */
/* in exfat it always returns 0, that it's anyway better than the fake inodes */
blknum = 0; /* first block */
if (ioctl(f, FIBMAP, &blknum) == 0) {
if (ioctl(f, FIBMAP, &blknum) != -1) {
*physical = blknum;
if (close(f) == -1)
return -1;