summaryrefslogtreecommitdiffstats
path: root/disk-utils/mkswap.c
diff options
context:
space:
mode:
authorMatthias Koenig2007-07-18 16:15:46 +0200
committerKarel Zak2007-07-27 13:39:29 +0200
commit2018629905d3d881ff3fddf76552b6e79091f2b8 (patch)
treef51632da5d7c7a47a83ec77f94174dd265ecd7ed /disk-utils/mkswap.c
parentremove hardcoded package name from some utils (diff)
downloadkernel-qcow2-util-linux-2018629905d3d881ff3fddf76552b6e79091f2b8.tar.gz
kernel-qcow2-util-linux-2018629905d3d881ff3fddf76552b6e79091f2b8.tar.xz
kernel-qcow2-util-linux-2018629905d3d881ff3fddf76552b6e79091f2b8.zip
disk-utils: let mkfs tools open with O_EXCL
Let mkswap, mkfs.bfs, mkfs.minix open with O_EXCL if used on block devices to prevent writing to the device even if they are busy (mounted). Unfortunately, O_EXCL has zero effect for 2.4 kernels where in-kernel code doesn't use O_EXCL-like access locks. (Tested on RHEL3.) Signed-off-by: Matthias Koenig <mkoenig@suse.de> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r--disk-utils/mkswap.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 1fd1f185b..6af1ff7bb 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -640,8 +640,16 @@ main(int argc, char ** argv) {
usage();
}
- DEV = open(device_name,O_RDWR);
- if (DEV < 0 || fstat(DEV, &statbuf) < 0) {
+ if (stat(device_name, &statbuf) < 0) {
+ perror(device_name);
+ exit(EXIT_FAILURE);
+ }
+ if (S_ISBLK(statbuf.st_mode))
+ DEV = open(device_name, O_RDWR | O_EXCL);
+ else
+ DEV = open(device_name, O_RDWR);
+
+ if (DEV < 0) {
perror(device_name);
exit(1);
}