]>
Commit | Line | Data |
---|---|---|
5545a732 JR |
1 | - mkswap "works" without warning on a mounted device |
2 | ||
3 | --- util-linux-2.13-pre6/disk-utils/mkswap.c.kzak 2006-10-12 11:33:50.000000000 +0200 | |
4 | +++ util-linux-2.13-pre6/disk-utils/mkswap.c 2006-10-12 11:36:08.000000000 +0200 | |
5 | @@ -36,6 +36,7 @@ | |
6 | #include <string.h> | |
7 | #include <fcntl.h> | |
8 | #include <stdlib.h> | |
9 | +#include <mntent.h> | |
10 | #include <sys/ioctl.h> /* for _IO */ | |
11 | #include <sys/utsname.h> | |
12 | #include <sys/stat.h> | |
13 | @@ -485,6 +486,29 @@ | |
14 | return (c >= '1' && c <= '9'); | |
15 | } | |
16 | ||
17 | + | |
18 | +/* | |
19 | + * Check to make certain that our new filesystem won't be created on | |
20 | + * an already mounted partition. Code adapted from mke2fs, Copyright | |
21 | + * (C) 1994 Theodore Ts'o. Also licensed under GPL. | |
22 | + * (C) 2006 Karel Zak -- port to mkswap | |
23 | + */ | |
24 | +static int | |
25 | +check_mount(void) { | |
26 | + FILE * f; | |
27 | + struct mntent * mnt; | |
28 | + | |
29 | + if ((f = setmntent (MOUNTED, "r")) == NULL) | |
30 | + return 0; | |
31 | + while ((mnt = getmntent (f)) != NULL) | |
32 | + if (strcmp (device_name, mnt->mnt_fsname) == 0) | |
33 | + break; | |
34 | + endmntent (f); | |
35 | + if (!mnt) | |
36 | + return 0; | |
37 | + return 1; | |
38 | +} | |
39 | + | |
40 | int | |
41 | main(int argc, char ** argv) { | |
42 | struct stat statbuf; | |
43 | @@ -648,8 +672,19 @@ | |
44 | /* Want a block device. Probably not /dev/hda or /dev/hdb. */ | |
45 | if (!S_ISBLK(statbuf.st_mode)) | |
46 | check=0; | |
47 | - else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) | |
48 | - die(_("Will not try to make swapdevice on '%s'")); | |
49 | + else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) { | |
50 | + fprintf(stderr, | |
51 | + _("%s: error: " | |
52 | + "will not try to make swapdevice on '%s'\n"), | |
53 | + program_name, device_name); | |
54 | + exit(1); | |
55 | + } else if (check_mount()) { | |
56 | + fprintf(stderr, | |
57 | + _("%s: error: " | |
58 | + "%s is mounted; will not make swapspace.\n"), | |
59 | + program_name, device_name); | |
60 | + exit(1); | |
61 | + } | |
62 | ||
63 | #ifdef __sparc__ | |
64 | if (!force && version == 0) { |