summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorGoldwyn Rodrigues <rgoldwyn@gmail.com>2008-04-01 10:36:46 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2008-04-01 10:36:46 -0400
commitc2c5e3e7e533b1b03ba68723ef8ab7274d07148a (patch)
tree1b5527cebdc3ae994e385bd57d5de0019312048c /mkfs.c
parentad67cd73b7c1ab043f0c27570750f6d2becd7f03 (diff)
check if partition is mounted before mkfs
This saves from the blunder of formatting a live mounted filesystem. This can be extended to get the mount flags of the filesystem mounted. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@gmail.com>
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/mkfs.c b/mkfs.c
index 49f73083..8d7530f2 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -197,6 +197,15 @@ int main(int ac, char **av)
print_usage();
file = av[optind++];
+ ret = check_mounted(file);
+ if (ret < 0) {
+ fprintf(stderr, "error checking %s mount status\n", file);
+ exit(1);
+ }
+ if (ret == 1) {
+ fprintf(stderr, "%s is mounted\n", file);
+ exit(1);
+ }
ac--;
fd = open(file, O_RDWR);
if (fd < 0) {
@@ -241,6 +250,16 @@ int main(int ac, char **av)
zero_end = 1;
while(ac-- > 0) {
file = av[optind++];
+ ret = check_mounted(file);
+ if (ret < 0) {
+ fprintf(stderr, "error checking %s mount status\n",
+ file);
+ exit(1);
+ }
+ if (ret == 1) {
+ fprintf(stderr, "%s is mounted\n", file);
+ exit(1);
+ }
fd = open(file, O_RDWR);
if (fd < 0) {
fprintf(stderr, "unable to open %s\n", file);