libbb: add xfstat function
function old new delta xfstat - 25 +25 mkfs_ext2_main 2421 2423 +2 mkfs_reiser_main 1197 1194 -3 next 312 307 -5 ar_main 533 522 -11 mkfs_minix_main 2938 2924 -14 mkfs_vfat_main 1511 1495 -16 writeTarFile 272 255 -17 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/6 up/down: 27/-66) Total: -39 bytes Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
@@ -221,7 +221,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
// open the device, check the device is a block device
|
||||
xmove_fd(xopen(argv[0], O_WRONLY), fd);
|
||||
fstat(fd, &st);
|
||||
xfstat(fd, &st, argv[0]);
|
||||
if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_F))
|
||||
bb_error_msg_and_die("%s: not a block device", argv[0]);
|
||||
|
||||
|
@@ -686,8 +686,7 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg_and_die("can't format mounted filesystem");
|
||||
|
||||
xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
|
||||
if (fstat(dev_fd, &statbuf) < 0)
|
||||
bb_error_msg_and_die("can't stat '%s'", G.device_name);
|
||||
xfstat(dev_fd, &statbuf, G.device_name);
|
||||
if (!S_ISBLK(statbuf.st_mode))
|
||||
opt &= ~1; // clear -c (check)
|
||||
|
||||
|
@@ -168,9 +168,9 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
// check the device is a block device
|
||||
fd = xopen(argv[0], O_WRONLY | O_EXCL);
|
||||
fstat(fd, &st);
|
||||
xfstat(fd, &st, argv[0]);
|
||||
if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_f))
|
||||
bb_error_msg_and_die("not a block device");
|
||||
bb_error_msg_and_die("%s: not a block device", argv[0]);
|
||||
|
||||
// check if it is mounted
|
||||
// N.B. what if we format a file? find_mount_point will return false negative since
|
||||
|
@@ -245,8 +245,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
|
||||
volume_id = time(NULL);
|
||||
|
||||
dev = xopen(device_name, O_RDWR);
|
||||
if (fstat(dev, &st) < 0)
|
||||
bb_simple_perror_msg_and_die(device_name);
|
||||
xfstat(dev, &st, device_name);
|
||||
|
||||
//
|
||||
// Get image size and sector size
|
||||
|
@@ -15,8 +15,7 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
|
||||
if (!is_selinux_enabled())
|
||||
return;
|
||||
|
||||
if (fstat(fd, &stbuf) < 0)
|
||||
bb_perror_msg_and_die("fstat failed");
|
||||
xfstat(fd, &stbuf, argv[0]);
|
||||
if (S_ISREG(stbuf.st_mode)) {
|
||||
security_context_t newcon;
|
||||
security_context_t oldcon = NULL;
|
||||
|
Reference in New Issue
Block a user