aboutsummaryrefslogtreecommitdiff
path: root/lib/libufs/type.c
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2007-03-16 03:13:28 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2007-03-16 03:13:28 +0000
commitfa1abc314f0511b52e7f5b16850ac9491ec8a1e5 (patch)
tree76f1bf1db39264cfc165aed7dc268ef1a8bafd78 /lib/libufs/type.c
parentc6c2738201442e9b3b1a4e6ac485dd397f6d91f1 (diff)
downloadsrc-fa1abc314f0511b52e7f5b16850ac9491ec8a1e5.tar.gz
src-fa1abc314f0511b52e7f5b16850ac9491ec8a1e5.zip
The ufs_disk_fillout(3) can take special device name (with or without /dev/
prefix) as an argument and mount point path. At the end it has to find device name file system is stored on, which means when mount point path is given, it tries to look into /etc/fstab and find special device corresponding to the given mount point. This is not perfect, because it doesn't handle the case when file system is mounted by hand and mount point is given as an argument. I found this problem while trying to use snapinfo(8), which passes mount points to the ufs_disk_fillout(3) function, but I had file system mounted manually, so snapinfo(8) was exiting with the error below: ufs_disk_fillout: No such file or directory I modified libufs(3) to handle those arguments (the order is important): 1. special device with /dev/ prefix 2. special device without /dev/ prefix 3. mount point listed in /etc/fstab, directory exists 4. mount point listed in /etc/fstab, directory doesn't exist 5. mount point of a file system mounted by hand
Notes
Notes: svn path=/head/; revision=167625
Diffstat (limited to 'lib/libufs/type.c')
-rw-r--r--lib/libufs/type.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/lib/libufs/type.c b/lib/libufs/type.c
index c88da96baa7c..9b7470a33a84 100644
--- a/lib/libufs/type.c
+++ b/lib/libufs/type.c
@@ -87,24 +87,53 @@ ufs_disk_fillout_blank(struct uufsd *disk, const char *name)
{
struct stat st;
struct fstab *fs;
+ struct statfs sfs;
const char *oname;
char dev[MAXPATHLEN];
- int fd;
+ int fd, ret;
ERROR(disk, NULL);
oname = name;
- fs = getfsfile(name);
- if (fs != NULL)
- name = fs->fs_spec;
-again: if (stat(name, &st) < 0) {
+again: if ((ret = stat(name, &st)) < 0) {
if (*name != '/') {
- if (*name == 'r')
- name++;
snprintf(dev, sizeof(dev), "%s%s", _PATH_DEV, name);
name = dev;
goto again;
}
+ /*
+ * The given object doesn't exist, but don't panic just yet -
+ * it may be still mount point listed in /etc/fstab, but without
+ * existing corresponding directory.
+ */
+ name = oname;
+ }
+ if (ret >= 0 && S_ISCHR(st.st_mode)) {
+ /* This is what we need, do nothing. */
+ ;
+ } else if ((fs = getfsfile(name)) != NULL) {
+ /*
+ * The given mount point is listed in /etc/fstab.
+ * It is possible that someone unmounted file system by hand
+ * and different file system is mounted on this mount point,
+ * but we still prefer /etc/fstab entry, because on the other
+ * hand, there could be /etc/fstab entry for this mount
+ * point, but file system is not mounted yet (eg. noauto) and
+ * statfs(2) will point us at different file system.
+ */
+ name = fs->fs_spec;
+ } else if (ret >= 0 && S_ISDIR(st.st_mode)) {
+ /*
+ * The mount point is not listed in /etc/fstab, so it may be
+ * file system mounted by hand.
+ */
+ if (statfs(name, &sfs) < 0) {
+ ERROR(disk, "could not find special device");
+ return (-1);
+ }
+ strlcpy(dev, sfs.f_mntfromname, sizeof(dev));
+ name = dev;
+ } else {
ERROR(disk, "could not find special device");
return (-1);
}