mirror of
https://github.com/AltraMayor/f3.git
synced 2025-09-13 00:56:05 -04:00
f3probe: fix a (supposed) race condition
Although I (Michel) am not 100% sure, the kernel seemed to be allowing reads to get data from an internal cache in the kernel; the condition is tricky to reproduce, and trickier to be sure since fake drives are not reliable or preditable. The results seems more stable with this patch, though.
This commit is contained in:
parent
bf550a0ce9
commit
cedb3f17d2
11
libdevs.c
11
libdevs.c
@ -444,15 +444,22 @@ static int bdev_write_blocks(struct device *dev, const char *buf,
|
||||
size_t length = (last_pos - first_pos + 1) << block_order;
|
||||
off_t offset = first_pos << block_order;
|
||||
off_t off_ret = lseek(bdev->fd, offset, SEEK_SET);
|
||||
int rc;
|
||||
if (off_ret < 0)
|
||||
return - errno;
|
||||
assert(off_ret == offset);
|
||||
return write_all(bdev->fd, buf, length);
|
||||
rc = write_all(bdev->fd, buf, length);
|
||||
if (rc)
|
||||
return rc;
|
||||
rc = fsync(bdev->fd);
|
||||
if (rc)
|
||||
return rc;
|
||||
return posix_fadvise(bdev->fd, 0, 0, POSIX_FADV_DONTNEED);
|
||||
}
|
||||
|
||||
static inline int bdev_open(const char *filename)
|
||||
{
|
||||
return open(filename, O_RDWR | O_DIRECT | O_SYNC);
|
||||
return open(filename, O_RDWR | O_DIRECT);
|
||||
}
|
||||
|
||||
static struct udev_device *map_dev_to_usb_dev(struct udev_device *dev)
|
||||
|
Loading…
x
Reference in New Issue
Block a user