From: Samanta Navarro Date: Fri, 13 Jan 2023 11:51:52 +0000 (+0000) Subject: lib/blkdev: set errno in more cases X-Git-Tag: v2.39-rc1~160^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f7450f6cb401f754f298fc8d7c5cdd5b31ade11;p=thirdparty%2Futil-linux.git 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 --- 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);