[functional-tests] Move get-dev-size to C code

Saves forking blockdev
This commit is contained in:
Joe Thornber
2017-12-15 15:35:24 +00:00
parent 8d26c3729f
commit 0dc237c356
3 changed files with 69 additions and 43 deletions

View File

@ -1,5 +1,6 @@
#include <linux/dm-ioctl.h>
#include <linux/kdev_t.h>
#include <linux/fs.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
@ -596,4 +597,18 @@ int dm_message(struct dm_interface *dmi, const char *name, uint64_t sector,
return r;
}
int get_dev_size(const char *path, uint64_t *sectors)
{
int r, fd;
fd = open(path, O_RDONLY);
if (fd < 0)
return -EINVAL;
r = ioctl(fd, BLKGETSIZE64, sectors);
(*sectors) /= 512;
close(fd);
return r;
}
//----------------------------------------------------------------