From 5a02eb13ee8c80dc753cbe65f0ccc0c72d2e696e Mon Sep 17 00:00:00 2001 From: Junichi Uekawa Date: Mon, 10 Jul 2023 21:14:56 +0900 Subject: [PATCH] iterate according to review comments. --- misc-utils/fincore.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/misc-utils/fincore.c b/misc-utils/fincore.c index e8dfef2353..c92d10b544 100644 --- a/misc-utils/fincore.c +++ b/misc-utils/fincore.c @@ -246,16 +246,21 @@ static int fincore_name(struct fincore_control *ctl, return -errno; } - if (S_ISBLK(sb.st_mode) || S_ISREG(sb.st_mode)) { - if (blkdev_get_size(fd, size) == 0) - rc = fincore_fd(ctl, fd, name, *size, count_incore); - else + if (S_ISBLK(sb.st_mode)) { + rc = blkdev_get_size(fd, size); + if (rc) warn(_("failed ioctl to get size: %s"), name); + } else if (S_ISREG(sb.st_mode)) { + *size = sb.st_size; } else { rc = 1; /* ignore things like symlinks * and directories*/ } + if (!rc) { + rc = fincore_fd(ctl, fd, name, *size, count_incore); + } + close (fd); return rc; } -- 2.47.3