From mboxrd@z Thu Jan 1 00:00:00 1970 From: rohara@sourceware.org Date: 10 Jul 2007 18:21:28 -0000 Subject: [Cluster-devel] cluster/gfs2/mkfs main_mkfs.c Message-ID: <20070710182128.30552.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Changes by: rohara at sourceware.org 2007-07-10 18:21:28 Modified files: gfs2/mkfs : main_mkfs.c Log message: BZ 240584 - Check to see if device is mounted before creating filesystem. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/gfs2/mkfs/main_mkfs.c.diff?cvsroot=cluster&r1=1.14&r2=1.15 --- cluster/gfs2/mkfs/main_mkfs.c 2007/06/06 15:19:56 1.14 +++ cluster/gfs2/mkfs/main_mkfs.c 2007/07/10 18:21:28 1.15 @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "libgfs2.h" @@ -283,6 +284,38 @@ } /** + * check_mount - check to see if device is mounted + * @device: the device to create the filesystem on + * + */ + +void check_mount(char *device) +{ + struct mntent *mnt; + FILE *fp; + + if ((fp = setmntent("/proc/mounts", "r")) == NULL) { + die("error opening /proc/mounts"); + } + + while ((mnt = getmntent(fp)) != NULL) { + if (strcmp(device, mnt->mnt_fsname) == 0) { + printf("cannot create filesystem: "); + printf("%s appears to be mounted\n", device); + break; + } + } + + endmntent(fp); + + if (fp != NULL) { + exit(EXIT_FAILURE); + } + + return; +} + +/** * print_results - print out summary information * @sdp: the command line * @@ -357,6 +390,8 @@ verify_arguments(sdp); + check_mount(sdp->device_name); + sdp->device_fd = open(sdp->device_name, O_RDWR); if (sdp->device_fd < 0) die("can't open device %s: %s\n",