From 2f7450f6cb401f754f298fc8d7c5cdd5b31ade11 Mon Sep 17 00:00:00 2001 From: Samanta Navarro Date: Fri, 13 Jan 2023 11:51:52 +0000 Subject: [PATCH] lib/blkdev: set errno in more cases Applications evaluate errno in case of a -1 return value. Examples within util-linux are fsck.cramfs and mkfs.minix. Set errno more often to offer reasonable error codes to the application and user. Signed-off-by: Samanta Navarro --- lib/blkdev.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/blkdev.c b/lib/blkdev.c index 954de454e6..757f3e818b 100644 --- a/lib/blkdev.c +++ b/lib/blkdev.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -60,8 +61,10 @@ blkdev_find_size (int fd) { uintmax_t high, low = 0; for (high = 1024; blkdev_valid_offset (fd, high); ) { - if (high == UINTMAX_MAX) + if (high == UINTMAX_MAX) { + errno = EFBIG; return -1; + } low = high; @@ -167,8 +170,10 @@ blkdev_get_size(int fd, unsigned long long *bytes) *bytes = st.st_size; return 0; } - if (!S_ISBLK(st.st_mode)) + if (!S_ISBLK(st.st_mode)) { + errno = ENOTBLK; return -1; + } } *bytes = blkdev_find_size(fd); -- 2.47.3