diff options
Diffstat (limited to 'disk-utils/mkswap.c')
-rw-r--r-- | disk-utils/mkswap.c | 12 |
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); } |