diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-09-01 12:10:30 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-09-01 15:59:54 +0200 |
commit | 91e1ce1a7c84953290ad6406fe92f972c7b6661b (patch) | |
tree | b27b35ad8ae4dea73bc8b52f69d33dc1d47b9ec8 /src | |
parent | cf0dc88da65eb65b630aa72f8db9df4ef3fc3b06 (diff) | |
download | systemd-91e1ce1a7c84953290ad6406fe92f972c7b6661b.tar.gz |
loop-util: move resize partition ioctl call to blockdev-util.[ch]
The other BLKPG calls have wrappers in blockdev-util.[ch], let's place
them all there.
No change in behaviour.
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/blockdev-util.c | 38 | ||||
-rw-r--r-- | src/shared/blockdev-util.h | 1 | ||||
-rw-r--r-- | src/shared/loop-util.c | 18 |
3 files changed, 42 insertions, 15 deletions
diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index 6038591d83..0b2554d4b2 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -427,7 +427,13 @@ int path_get_whole_disk(const char *path, bool backing, dev_t *ret) { return fd_get_whole_disk(fd, backing, ret); } -int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, uint64_t size) { +int block_device_add_partition( + int fd, + const char *name, + int nr, + uint64_t start, + uint64_t size) { + assert(fd >= 0); assert(name); assert(nr > 0); @@ -452,7 +458,11 @@ int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, return RET_NERRNO(ioctl(fd, BLKPG, &ba)); } -int block_device_remove_partition(int fd, const char *name, int nr) { +int block_device_remove_partition( + int fd, + const char *name, + int nr) { + assert(fd >= 0); assert(name); assert(nr > 0); @@ -475,6 +485,30 @@ int block_device_remove_partition(int fd, const char *name, int nr) { return RET_NERRNO(ioctl(fd, BLKPG, &ba)); } +int block_device_resize_partition( + int fd, + int nr, + uint64_t start, + uint64_t size) { + + assert(fd >= 0); + assert(nr > 0); + + struct blkpg_partition bp = { + .pno = nr, + .start = start, + .length = size, + }; + + struct blkpg_ioctl_arg ba = { + .op = BLKPG_RESIZE_PARTITION, + .data = &bp, + .datalen = sizeof(bp), + }; + + return RET_NERRNO(ioctl(fd, BLKPG, &ba)); +} + int block_device_remove_all_partitions(int fd) { struct stat stat; _cleanup_(sd_device_unrefp) sd_device *dev = NULL; diff --git a/src/shared/blockdev-util.h b/src/shared/blockdev-util.h index 8c9401b4a7..2f1f347d09 100644 --- a/src/shared/blockdev-util.h +++ b/src/shared/blockdev-util.h @@ -33,4 +33,5 @@ int path_get_whole_disk(const char *path, bool backing, dev_t *ret); int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, uint64_t size); int block_device_remove_partition(int fd, const char *name, int nr); +int block_device_resize_partition(int fd, int nr, uint64_t start, uint64_t size); int block_device_remove_all_partitions(int fd); diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index ce9a982f02..fd68af4160 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -869,19 +869,11 @@ static int resize_partition(int partition_fd, uint64_t offset, uint64_t size) { if (r < 0) return r; - struct blkpg_partition bp = { - .pno = partno, - .start = offset == UINT64_MAX ? current_offset : offset, - .length = size == UINT64_MAX ? current_size : size, - }; - - struct blkpg_ioctl_arg ba = { - .op = BLKPG_RESIZE_PARTITION, - .data = &bp, - .datalen = sizeof(bp), - }; - - return RET_NERRNO(ioctl(whole_fd, BLKPG, &ba)); + return block_device_resize_partition( + whole_fd, + partno, + offset == UINT64_MAX ? current_offset : offset, + size == UINT64_MAX ? current_size : size); } int loop_device_refresh_size(LoopDevice *d, uint64_t offset, uint64_t size) { |