Blob Blame History Raw
diff -up ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.am.735862 ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.am
--- ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.am.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.am	2011-09-07 11:29:41.094904121 -0400
@@ -29,6 +29,7 @@ headers = \
 	ntfstime.h	\
 	object_id.h	\
 	param.h	\
+	realpath.h	\
 	reparse.h	\
 	runlist.h	\
 	security.h	\
diff -up ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.in.735862 ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.in
--- ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.in.735862	2011-09-07 11:43:57.988150244 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/Makefile.in	2011-09-07 11:44:24.589929042 -0400
@@ -50,13 +50,13 @@ am__noinst_HEADERS_DIST = acls.h attrib.
 	bootsect.h cache.h collate.h compat.h compress.h debug.h \
 	device.h device_io.h dir.h efs.h endians.h index.h inode.h \
 	layout.h lcnalloc.h logfile.h logging.h mft.h misc.h mst.h \
-	ntfstime.h object_id.h param.h reparse.h runlist.h security.h \
+	ntfstime.h object_id.h param.h realpath.h reparse.h runlist.h security.h \
 	support.h types.h unistr.h volume.h xattrs.h
 am__ntfs3ginclude_HEADERS_DIST = acls.h attrib.h attrlist.h bitmap.h \
 	bootsect.h cache.h collate.h compat.h compress.h debug.h \
 	device.h device_io.h dir.h efs.h endians.h index.h inode.h \
 	layout.h lcnalloc.h logfile.h logging.h mft.h misc.h mst.h \
-	ntfstime.h object_id.h param.h reparse.h runlist.h security.h \
+	ntfstime.h object_id.h param.h realpath.h reparse.h runlist.h security.h \
 	support.h types.h unistr.h volume.h xattrs.h
 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 am__vpath_adj = case $$p in \
@@ -235,6 +235,7 @@ headers = \
 	ntfstime.h	\
 	object_id.h	\
 	param.h	\
+	realpath.h	\
 	reparse.h	\
 	runlist.h	\
 	security.h	\
diff -up ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/param.h.735862 ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/param.h
--- ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/param.h.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/param.h	2011-09-07 11:29:41.094904121 -0400
@@ -63,6 +63,11 @@ enum {
 
 #define XATTRMAPPINGFILE ".NTFS-3G/XattrMapping" /* default mapping file */
 
+/*
+ *		Parameters for path canonicalization
+ */
+
+#define MAPPERNAMELTH 256
 
 /*
  *		Permission checking modes for high level and low level
diff -up ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/realpath.h.735862 ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/realpath.h
--- ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/realpath.h.735862	2011-09-07 11:29:41.095904112 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/include/ntfs-3g/realpath.h	2011-09-07 11:29:41.095904112 -0400
@@ -0,0 +1,24 @@
+/*
+ * realpath.h - realpath() aware of device mapper
+ */
+
+#ifndef REALPATH_H
+#define REALPATH_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_REALPATH
+#define ntfs_realpath realpath
+#else
+extern char *ntfs_realpath(const char *path, char *resolved_path);
+#endif
+
+#ifdef linux
+extern char *ntfs_realpath_canonicalize(const char *path, char *resolved_path);
+#else
+#define ntfs_realpath_canonicalize ntfs_realpath
+#endif
+
+#endif /* REALPATH_H */
diff -up ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.am.735862 ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.am
--- ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.am.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.am	2011-09-07 11:29:41.095904112 -0400
@@ -40,6 +40,7 @@ libntfs_3g_la_SOURCES =	\
 	misc.c 		\
 	mst.c 		\
 	object_id.c 	\
+	realpath.c 	\
 	reparse.c 	\
 	runlist.c 	\
 	security.c 	\
diff -up ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.in.735862 ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.in
--- ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.in.735862	2011-09-07 11:31:09.332081855 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/Makefile.in	2011-09-07 11:42:42.627801947 -0400
@@ -62,7 +62,7 @@ LTLIBRARIES = $(lib_LTLIBRARIES) $(noins
 am__libntfs_3g_la_SOURCES_DIST = acls.c attrib.c attrlist.c bitmap.c \
 	bootsect.c cache.c collate.c compat.c compress.c debug.c \
 	device.c dir.c efs.c index.c inode.c lcnalloc.c logfile.c \
-	logging.c mft.c misc.c mst.c object_id.c reparse.c runlist.c \
+	logging.c mft.c misc.c mst.c object_id.c realpath.c reparse.c runlist.c \
 	security.c unistr.c volume.c xattrs.c win32_io.c unix_io.c
 @NTFS_DEVICE_DEFAULT_IO_OPS_TRUE@@WINDOWS_TRUE@am__objects_1 = libntfs_3g_la-win32_io.lo
 @NTFS_DEVICE_DEFAULT_IO_OPS_TRUE@@WINDOWS_FALSE@am__objects_2 = libntfs_3g_la-unix_io.lo
@@ -77,7 +77,7 @@ am_libntfs_3g_la_OBJECTS = libntfs_3g_la
 	libntfs_3g_la-lcnalloc.lo libntfs_3g_la-logfile.lo \
 	libntfs_3g_la-logging.lo libntfs_3g_la-mft.lo \
 	libntfs_3g_la-misc.lo libntfs_3g_la-mst.lo \
-	libntfs_3g_la-object_id.lo libntfs_3g_la-reparse.lo \
+	libntfs_3g_la-object_id.lo libntfs_3g_la-realpath.lo libntfs_3g_la-reparse.lo \
 	libntfs_3g_la-runlist.lo libntfs_3g_la-security.lo \
 	libntfs_3g_la-unistr.lo libntfs_3g_la-volume.lo \
 	libntfs_3g_la-xattrs.lo $(am__objects_1) $(am__objects_2)
@@ -253,7 +253,7 @@ libntfs_3g_la_LDFLAGS = -version-info $(
 libntfs_3g_la_SOURCES = acls.c attrib.c attrlist.c bitmap.c bootsect.c \
 	cache.c collate.c compat.c compress.c debug.c device.c dir.c \
 	efs.c index.c inode.c lcnalloc.c logfile.c logging.c mft.c \
-	misc.c mst.c object_id.c reparse.c runlist.c security.c \
+	misc.c mst.c object_id.c realpath.c reparse.c runlist.c security.c \
 	unistr.c volume.c xattrs.c $(am__append_1) $(am__append_2)
 all: all-am
 
@@ -386,6 +386,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-misc.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-mst.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-object_id.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-realpath.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-reparse.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-runlist.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libntfs_3g_la-security.Plo@am__quote@
@@ -570,6 +571,13 @@ libntfs_3g_la-object_id.lo: object_id.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-object_id.lo `test -f 'object_id.c' || echo '$(srcdir)/'`object_id.c
 
+libntfs_3g_la-realpath.lo: realpath.c
+@am__fastdepCC_TRUE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-realpath.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-realpath.Tpo -c -o libntfs_3g_la-realpath.lo `test -f 'realpath.c' || echo '$(srcdir)/'`realpath.c
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/libntfs_3g_la-realpath.Tpo $(DEPDIR)/libntfs_3g_la-realpath.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='realpath.c' object='libntfs_3g_la-realpath.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -c -o libntfs_3g_la-realpath.lo `test -f 'realpath.c' || echo '$(srcdir)/'`realpath.c
+
 libntfs_3g_la-reparse.lo: reparse.c
 @am__fastdepCC_TRUE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libntfs_3g_la_CFLAGS) $(CFLAGS) -MT libntfs_3g_la-reparse.lo -MD -MP -MF $(DEPDIR)/libntfs_3g_la-reparse.Tpo -c -o libntfs_3g_la-reparse.lo `test -f 'reparse.c' || echo '$(srcdir)/'`reparse.c
 @am__fastdepCC_TRUE@	mv -f $(DEPDIR)/libntfs_3g_la-reparse.Tpo $(DEPDIR)/libntfs_3g_la-reparse.Plo
diff -up ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/realpath.c.735862 ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/realpath.c
--- ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/realpath.c.735862	2011-09-07 11:29:41.095904112 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/realpath.c	2011-09-07 11:29:41.095904112 -0400
@@ -0,0 +1,103 @@
+/*
+ * realpath.c - realpath() aware of device mapper
+ * Originated from the util-linux project.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+#ifdef HAVE_CTYPE_H
+#include <ctype.h>
+#endif
+
+#include "param.h"
+#include "realpath.h"
+
+/* If there is no realpath() on the system, provide a dummy one. */
+#ifndef HAVE_REALPATH
+char *ntfs_realpath(const char *path, char *resolved_path)
+{
+       strncpy(resolved_path, path, PATH_MAX);
+       resolved_path[PATH_MAX] = '\0';
+       return resolved_path;
+}
+#endif
+
+
+#ifdef linux
+
+/*
+ * Converts private "dm-N" names to "/dev/mapper/<name>"
+ *
+ * Since 2.6.29 (patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128) kernel sysfs
+ * provides the real DM device names in /sys/block/<ptname>/dm/name
+ */
+static char *
+canonicalize_dm_name(const char *ptname, char *canonical)
+{
+	FILE	*f;
+	size_t	sz;
+	char	path[MAPPERNAMELTH + 24];
+	char	name[MAPPERNAMELTH + 16];
+	char	*res = NULL;
+
+	snprintf(path, sizeof(path), "/sys/block/%s/dm/name", ptname);
+	if (!(f = fopen(path, "r")))
+		return NULL;
+
+	/* read "<name>\n" from sysfs */
+	if (fgets(name, sizeof(name), f) && (sz = strlen(name)) > 1) {
+		name[sz - 1] = '\0';
+		snprintf(path, sizeof(path), "/dev/mapper/%s", name);
+		res = strcpy(canonical, path);
+	}
+	fclose(f);
+	return res;
+}
+
+/*
+ *		Canonicalize a device path
+ *
+ *	Workaround from "basinilya" for fixing device mapper paths.
+ *
+ *  Background (Phillip Susi, 2011-04-09)
+ *	- ntfs-3g canonicalizes the device name so that if you mount with
+ *	  /dev/mapper/foo, the device name listed in mtab is /dev/dm-n,
+ *	  so you can not umount /dev/mapper/foo
+ *	- umount won't even recognize and translate /dev/dm-n to the mount
+ *	  point, apparently because of the '-' involved. Editing mtab and
+ *	  removing the '-' allows you to umount /dev/dmn successfully.
+ *
+ *	This code restores the devmapper name after canonicalization,
+ *	until a proper fix is implemented.
+ */
+
+char *ntfs_realpath_canonicalize(const char *path, char *canonical)
+{
+	char *p;
+
+	if (path == NULL)
+		return NULL;
+
+	if (!ntfs_realpath(path, canonical))
+		return NULL;
+
+	p = strrchr(canonical, '/');
+	if (p && strncmp(p, "/dm-", 4) == 0 && isdigit(*(p + 4))) {
+		p = canonicalize_dm_name(p+1, canonical);
+		if (p)
+			return p;
+	}
+
+	return canonical;
+}
+
+#endif
diff -up ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/volume.c.735862 ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/volume.c
--- ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/volume.c.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/libntfs-3g/volume.c	2011-09-07 11:29:41.095904112 -0400
@@ -67,6 +67,7 @@
 #include "dir.h"
 #include "logging.h"
 #include "cache.h"
+#include "realpath.h"
 #include "misc.h"
 
 const char *ntfs_home = 
@@ -1359,18 +1360,6 @@ int ntfs_umount(ntfs_volume *vol, const 
 
 #ifdef HAVE_MNTENT_H
 
-#ifndef HAVE_REALPATH
-/**
- * realpath - If there is no realpath on the system
- */
-static char *realpath(const char *path, char *resolved_path)
-{
-	strncpy(resolved_path, path, PATH_MAX);
-	resolved_path[PATH_MAX] = '\0';
-	return resolved_path;
-}
-#endif
-
 /**
  * ntfs_mntent_check - desc
  *
@@ -1394,7 +1383,7 @@ static int ntfs_mntent_check(const char 
 		err = errno;
 		goto exit;
 	}
-	if (!realpath(file, real_file)) {
+	if (!ntfs_realpath_canonicalize(file, real_file)) {
 		err = errno;
 		goto exit;
 	}
@@ -1403,7 +1392,7 @@ static int ntfs_mntent_check(const char 
 		goto exit;
 	}
 	while ((mnt = getmntent(f))) {
-		if (!realpath(mnt->mnt_fsname, real_fsname))
+		if (!ntfs_realpath_canonicalize(mnt->mnt_fsname, real_fsname))
 			continue;
 		if (!strcmp(real_file, real_fsname))
 			break;
diff -up ntfs-3g_ntfsprogs-2011.4.12/src/lowntfs-3g.c.735862 ntfs-3g_ntfsprogs-2011.4.12/src/lowntfs-3g.c
--- ntfs-3g_ntfsprogs-2011.4.12/src/lowntfs-3g.c.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/src/lowntfs-3g.c	2011-09-07 11:29:41.096904103 -0400
@@ -3457,16 +3457,6 @@ static void usage(void)
 			EXEC_NAME, ntfs_home);
 }
 
-#ifndef HAVE_REALPATH
-/* If there is no realpath() on the system, provide a dummy one. */
-static char *realpath(const char *path, char *resolved_path)
-{
-	strncpy(resolved_path, path, PATH_MAX);
-	resolved_path[PATH_MAX] = '\0';
-	return resolved_path;
-}
-#endif
-
 #if defined(linux) || defined(__uClinux__)
 
 static const char *dev_fuse_msg =
@@ -3668,6 +3658,9 @@ static void setup_logging(char *parsed_o
 	ctx->seccache = (struct PERMISSIONS_CACHE*)NULL;
 
 	ntfs_log_info("Version %s %s %d\n", VERSION, FUSE_TYPE, fuse_version());
+	if (strcmp(opts.arg_device,opts.device))
+		ntfs_log_info("Requested device %s canonicalized as %s\n",
+				opts.arg_device,opts.device);
 	ntfs_log_info("Mounted %s (%s, label \"%s\", NTFS %d.%d)\n",
 			opts.device, (ctx->ro) ? "Read-Only" : "Read-Write",
 			ctx->vol->vol_name, ctx->vol->major_ver,
diff -up ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g.c.735862 ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g.c
--- ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g.c.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g.c	2011-09-07 11:29:41.098904085 -0400
@@ -3372,16 +3372,6 @@ static void usage(void)
 			EXEC_NAME, ntfs_home);
 }
 
-#ifndef HAVE_REALPATH
-/* If there is no realpath() on the system, provide a dummy one. */
-static char *realpath(const char *path, char *resolved_path)
-{
-	strncpy(resolved_path, path, PATH_MAX);
-	resolved_path[PATH_MAX] = '\0';
-	return resolved_path;
-}
-#endif
-
 #if defined(linux) || defined(__uClinux__)
 
 static const char *dev_fuse_msg =
@@ -3588,6 +3578,9 @@ static void setup_logging(char *parsed_o
 	ctx->seccache = (struct PERMISSIONS_CACHE*)NULL;
 
 	ntfs_log_info("Version %s %s %d\n", VERSION, FUSE_TYPE, fuse_version());
+	if (strcmp(opts.arg_device,opts.device))
+		ntfs_log_info("Requested device %s canonicalized as %s\n",
+				opts.arg_device,opts.device);
 	ntfs_log_info("Mounted %s (%s, label \"%s\", NTFS %d.%d)\n",
 			opts.device, (ctx->ro) ? "Read-Only" : "Read-Write",
 			ctx->vol->vol_name, ctx->vol->major_ver,
diff -up ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.c.735862 ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.c
--- ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.c.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.c	2011-09-07 11:29:41.098904085 -0400
@@ -43,6 +43,7 @@
 #include "security.h"
 #include "xattrs.h"
 #include "ntfs-3g_common.h"
+#include "realpath.h"
 #include "misc.h"
 
 const char xattr_ntfs_3g[] = "ntfs-3g.";
@@ -507,7 +508,9 @@ int ntfs_parse_options(struct ntfs_optio
 					return -1;
 				
 				/* Canonicalize device name (mtab, etc) */
-				if (!realpath(optarg, popts->device)) {
+				popts->arg_device = optarg;
+				if (!ntfs_realpath_canonicalize(optarg,
+						popts->device)) {
 					ntfs_log_perror("%s: Failed to access "
 					     "volume '%s'", EXEC_NAME, optarg);
 					free(popts->device);
diff -up ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.h.735862 ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.h
--- ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.h.735862	2011-04-10 14:04:41.000000000 -0400
+++ ntfs-3g_ntfsprogs-2011.4.12/src/ntfs-3g_common.h	2011-09-07 11:29:41.098904085 -0400
@@ -29,6 +29,7 @@ struct ntfs_options {
         char    *mnt_point;     /* Mount point */    
         char    *options;       /* Mount options */  
         char    *device;        /* Device to mount */
+	char	*arg_device;	/* Device requested in argv */
 } ;
 
 typedef enum {