Changes by: mattjf
Update of /cvsroot/linux-ntfs/linux-ntfs/libntfs
In directory usw-pr-cvs1:/tmp/cvs-serv23740/libntfs
Modified Files:
volume.c
Log Message:
Code cleanup.
Removed check_mount() and added a generic ntfs_check_if_mounted()
function to the library
Better error checking
Index: volume.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/libntfs/volume.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -U2 -r1.32 -r1.33
--- volume.c 22 Apr 2002 10:34:31 -0000 1.32
+++ volume.c 23 Apr 2002 08:25:41 -0000 1.33
@@ -27,4 +27,7 @@
#include <unistd.h>
#include <errno.h>
+#include <mntent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include "volume.h"
@@ -596,2 +599,41 @@
}
+
+
+/**
+ * ntfs_check_if_mounted - check if an ntfs volume is currently mounted
+ * @dev: device to check
+ *
+ * First ntfs_check_if_mounted() will verify if the device is a valid
+ * block device. If it is not, errno will be set to ENODEV and it will return
+ * -1 (error).
+ *
+ * If the device is currently mounted, ntfs_check_if_mounted() will return
+ * +1.
+ *
+ **/
+int ntfs_check_if_mounted(const char *dev)
+{
+ FILE *m_f;
+ struct stat sbuf;
+ struct mntent *mnt;
+
+ /* First verify we are dealing with a valid block device. */
+ if (stat(dev, &sbuf) == -1) {
+ errno = ENODEV;
+ return -1;
+ }
+
+ if (!(m_f = setmntent(MOUNTED, "r")))
+ return -errno;
+ while ((mnt = getmntent(m_f)))
+ if (!strcmp(dev, mnt->mnt_fsname))
+ break;
+ endmntent(m_f);
+ if (!mnt)
+ return 0;
+ else
+ return 1;
+
+
+}
|