2 * realpath.c - realpath() aware of device mapper
3 * Originated from the util-linux project.
24 /* If there is no realpath() on the system, provide a dummy one. */
26 char *ntfs_realpath(const char *path
, char *resolved_path
)
28 strncpy(resolved_path
, path
, PATH_MAX
);
29 resolved_path
[PATH_MAX
] = '\0';
38 * Converts private "dm-N" names to "/dev/mapper/<name>"
40 * Since 2.6.29 (patch 784aae735d9b0bba3f8b9faef4c8b30df3bf0128) kernel sysfs
41 * provides the real DM device names in /sys/block/<ptname>/dm/name
44 canonicalize_dm_name(const char *ptname
, char *canonical
)
48 char path
[MAPPERNAMELTH
+ 24];
49 char name
[MAPPERNAMELTH
+ 16];
52 snprintf(path
, sizeof(path
), "/sys/block/%s/dm/name", ptname
);
53 if (!(f
= fopen(path
, "r")))
56 /* read "<name>\n" from sysfs */
57 if (fgets(name
, sizeof(name
), f
) && (sz
= strlen(name
)) > 1) {
59 snprintf(path
, sizeof(path
), "/dev/mapper/%s", name
);
60 res
= strcpy(canonical
, path
);
67 * Canonicalize a device path
69 * Workaround from "basinilya" for fixing device mapper paths.
71 * Background (Phillip Susi, 2011-04-09)
72 * - ntfs-3g canonicalizes the device name so that if you mount with
73 * /dev/mapper/foo, the device name listed in mtab is /dev/dm-n,
74 * so you can not umount /dev/mapper/foo
75 * - umount won't even recognize and translate /dev/dm-n to the mount
76 * point, apparently because of the '-' involved. Editing mtab and
77 * removing the '-' allows you to umount /dev/dmn successfully.
79 * This code restores the devmapper name after canonicalization,
80 * until a proper fix is implemented.
83 char *ntfs_realpath_canonicalize(const char *path
, char *canonical
)
90 if (!ntfs_realpath(path
, canonical
))
93 p
= strrchr(canonical
, '/');
94 if (p
&& strncmp(p
, "/dm-", 4) == 0 && isdigit(*(p
+ 4))) {
95 p
= canonicalize_dm_name(p
+1, canonical
);