Hi Rob, here's a patch to tidy up & simplify the error handling in blkdiscard.
Patrick
From 0534f028a41c64baabb984c562569a34dc9cd571 Mon Sep 17 00:00:00 2001 From: Patrick Oppenlander <patrick.oppenlan...@gmail.com> Date: Tue, 14 Apr 2020 15:17:18 +1000 Subject: [PATCH] blkdiscard: use xioctl & error_exit After list discussion [1] switch to using xioctl & error_exit instead of cleaning up fd. For now, leave CFG_TOYBOX_FREE as it is a helpful reminder of what would need to be cleaned up to support MAYFORK. 1. http://lists.landley.net/pipermail/toybox-landley.net/2020-April/011634.html --- toys/pending/blkdiscard.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/toys/pending/blkdiscard.c b/toys/pending/blkdiscard.c index 1f0c09cd..13c48700 100644 --- a/toys/pending/blkdiscard.c +++ b/toys/pending/blkdiscard.c @@ -56,23 +56,16 @@ void blkdiscard_main(void) if (FLAG(l)) len = atolx_range(TT.length, 0, LLONG_MAX); else { - if (ioctl(fd, BLKGETSIZE64, &len) < 0) { - perror_msg("ioctl %x", (int)BLKGETSIZE64); - goto out; - } + xioctl(fd, BLKGETSIZE64, &len); len -= off; } - if (FLAG(s) && FLAG(z)) { - error_msg("secure and zeroout are mutually exclusive"); - goto out; - } + if (FLAG(s) && FLAG(z)) + error_exit("secure and zeroout are mutually exclusive"); if (FLAG(s)) req = BLKSECDISCARD; if (FLAG(z)) req = BLKZEROOUT; - if (ioctl(fd, req, (uint64_t[]){off, len}) < 0) - perror_msg("ioctl %x", req); + xioctl(fd, req, (uint64_t[]){off, len}); -out: if (CFG_TOYBOX_FREE) close(fd); } -- 2.26.0
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net