diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index e036e2cde..48e563181 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -7694,15 +7694,11 @@ unshare_unmount_path(int op, char *path, int flags, boolean_t is_manual) zfs_handle_t *zhp; int ret = 0; struct stat64 statbuf; - struct extmnttab entry; + struct mnttab entry; const char *cmdname = (op == OP_SHARE) ? "unshare" : "unmount"; ino_t path_inode; char *zfs_mntpnt, *entry_mntpnt; - /* - * Search for the given (major,minor) pair in the mount table. - */ - if (getextmntent(path, &entry, &statbuf) != 0) { if (op == OP_SHARE) { (void) fprintf(stderr, gettext("cannot %s '%s': not " diff --git a/cmd/zinject/translate.c b/cmd/zinject/translate.c index 898edd9ed..cd157b592 100644 --- a/cmd/zinject/translate.c +++ b/cmd/zinject/translate.c @@ -85,7 +85,7 @@ static int parse_pathname(const char *inpath, char *dataset, char *relpath, struct stat64 *statbuf) { - struct extmnttab mp; + struct mnttab mp; const char *rel; char fullpath[MAXPATHLEN]; diff --git a/lib/libspl/include/os/freebsd/sys/mnttab.h b/lib/libspl/include/os/freebsd/sys/mnttab.h index 0d47f8e48..ac65b7df5 100644 --- a/lib/libspl/include/os/freebsd/sys/mnttab.h +++ b/lib/libspl/include/os/freebsd/sys/mnttab.h @@ -57,26 +57,11 @@ struct mnttab { char *mnt_mntopts; }; -/* - * NOTE: fields in extmnttab should match struct mnttab till new fields - * are encountered, this allows hasmntopt to work properly when its arg is - * a pointer to an extmnttab struct cast to a mnttab struct pointer. - */ - -struct extmnttab { - char *mnt_special; - char *mnt_mountp; - char *mnt_fstype; - char *mnt_mntopts; - uint_t mnt_major; - uint_t mnt_minor; -}; - struct stat64; struct statfs; extern int _sol_getmntent(FILE *fp, struct mnttab *mp); -extern int getextmntent(const char *path, struct extmnttab *entry, +extern int getextmntent(const char *path, struct mnttab *entry, struct stat64 *statbuf); extern void statfs2mnttab(struct statfs *sfs, struct mnttab *mp); extern char *hasmntopt(struct mnttab *mnt, const char *opt); diff --git a/lib/libspl/include/os/linux/sys/mnttab.h b/lib/libspl/include/os/linux/sys/mnttab.h index d37172748..f6a65636d 100644 --- a/lib/libspl/include/os/linux/sys/mnttab.h +++ b/lib/libspl/include/os/linux/sys/mnttab.h @@ -54,25 +54,10 @@ struct mnttab { char *mnt_mntopts; }; -/* - * NOTE: fields in extmnttab should match struct mnttab till new fields - * are encountered, this allows hasmntopt to work properly when its arg is - * a pointer to an extmnttab struct cast to a mnttab struct pointer. - */ - -struct extmnttab { - char *mnt_special; - char *mnt_mountp; - char *mnt_fstype; - char *mnt_mntopts; - uint_t mnt_major; - uint_t mnt_minor; -}; - struct statfs; extern int _sol_getmntent(FILE *fp, struct mnttab *mp); -extern int getextmntent(const char *path, struct extmnttab *mp, +extern int getextmntent(const char *path, struct mnttab *mp, struct stat64 *statbuf); static inline char *_sol_hasmntopt(struct mnttab *mnt, const char *opt) { diff --git a/lib/libspl/os/freebsd/getextmntent.c b/lib/libspl/os/freebsd/getextmntent.c index baff124b4..07b886123 100644 --- a/lib/libspl/os/freebsd/getextmntent.c +++ b/lib/libspl/os/freebsd/getextmntent.c @@ -40,7 +40,7 @@ #include int -getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) +getextmntent(const char *path, struct mnttab *entry, struct stat64 *statbuf) { struct statfs sfs; @@ -60,6 +60,6 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) zfs_strerror(errno)); return (-1); } - statfs2mnttab(&sfs, (struct mnttab *)entry); + statfs2mnttab(&sfs, entry); return (0); } diff --git a/lib/libspl/os/linux/mnttab.c b/lib/libspl/os/linux/mnttab.c index ee103622c..25fa132ac 100644 --- a/lib/libspl/os/linux/mnttab.c +++ b/lib/libspl/os/linux/mnttab.c @@ -68,7 +68,7 @@ _sol_getmntent(FILE *fp, struct mnttab *mgetp) } static int -getextmntent_impl(FILE *fp, struct extmnttab *mp, uint64_t *mnt_id) +getextmntent_impl(FILE *fp, struct mnttab *mp, uint64_t *mnt_id, dev_t *dev) { int ret; struct stat64 st; @@ -84,19 +84,17 @@ getextmntent_impl(FILE *fp, struct extmnttab *mp, uint64_t *mnt_id) *mnt_id = stx.stx_mnt_id; #endif if (stat64(mp->mnt_mountp, &st) != 0) { - mp->mnt_major = 0; - mp->mnt_minor = 0; + *dev = 0; return (ret); } - mp->mnt_major = major(st.st_dev); - mp->mnt_minor = minor(st.st_dev); + *dev = st.st_dev; } return (ret); } int -getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) +getextmntent(const char *path, struct mnttab *entry, struct stat64 *statbuf) { struct stat64 st; FILE *fp; @@ -104,6 +102,7 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) boolean_t have_mnt_id = B_FALSE; uint64_t target_mnt_id = 0; uint64_t entry_mnt_id; + dev_t dev; #ifdef HAVE_STATX_MNT_ID struct statx stx; #endif @@ -143,12 +142,11 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) */ match = 0; - while (getextmntent_impl(fp, entry, &entry_mnt_id) == 0) { + while (getextmntent_impl(fp, entry, &entry_mnt_id, &dev) == 0) { if (have_mnt_id) { match = (entry_mnt_id == target_mnt_id); } else { - match = makedev(entry->mnt_major, entry->mnt_minor) == - statbuf->st_dev; + match = (dev == statbuf->st_dev); } if (match) break; @@ -161,11 +159,8 @@ getextmntent(const char *path, struct extmnttab *entry, struct stat64 *statbuf) return (-1); } - if (stat64(entry->mnt_mountp, &st) != 0) { - entry->mnt_major = 0; - entry->mnt_minor = 0; + if (stat64(entry->mnt_mountp, &st) != 0) return (-1); - } return (0); } diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 26f5135df..021a1d8a4 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -1171,7 +1171,7 @@ zfs_handle_t * zfs_path_to_zhandle(libzfs_handle_t *hdl, const char *path, zfs_type_t argtype) { struct stat64 statbuf; - struct extmnttab entry; + struct mnttab entry; if (path[0] != '/' && strncmp(path, "./", strlen("./")) != 0) { /*