summaryrefslogtreecommitdiffstats
path: root/disk-utils/fdformat.c
diff options
context:
space:
mode:
authorSami Kerola2015-10-31 19:34:36 +0100
committerSami Kerola2015-11-22 21:56:38 +0100
commitf5320b483c0a25be1481df221665f4d18add4a1a (patch)
tree9532e4618a39be29284da08c461defdf0f19f870 /disk-utils/fdformat.c
parentmkswap: fix block device open race (diff)
downloadkernel-qcow2-util-linux-f5320b483c0a25be1481df221665f4d18add4a1a.tar.gz
kernel-qcow2-util-linux-f5320b483c0a25be1481df221665f4d18add4a1a.tar.xz
kernel-qcow2-util-linux-f5320b483c0a25be1481df221665f4d18add4a1a.zip
fdformat: fix block device open race
This fix makes fdformat also to detect if block device is busy, and warn if the device is misaligned. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'disk-utils/fdformat.c')
-rw-r--r--disk-utils/fdformat.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/disk-utils/fdformat.c b/disk-utils/fdformat.c
index e7d43da8f..66e1bb90d 100644
--- a/disk-utils/fdformat.c
+++ b/disk-utils/fdformat.c
@@ -12,6 +12,7 @@
#include <unistd.h>
#include "c.h"
+#include "blkdev.h"
#include "strutils.h"
#include "closestream.h"
#include "nls.h"
@@ -221,10 +222,7 @@ int main(int argc, char **argv)
if (!S_ISBLK(st.st_mode))
/* do not test major - perhaps this was an USB floppy */
errx(EXIT_FAILURE, _("%s: not a block device"), argv[0]);
- if (access(argv[0], W_OK) < 0)
- err(EXIT_FAILURE, _("cannot access file %s"), argv[0]);
-
- ctrl = open(argv[0], O_RDWR);
+ ctrl = open_blkdev_or_file(&st, argv[0], O_RDWR);
if (ctrl < 0)
err(EXIT_FAILURE, _("cannot open %s"), argv[0]);
if (ioctl(ctrl, FDGETPRM, (long) &param) < 0)