Print this page
*** NO COMMENTS ***


  58 #include <rpcsvc/mount.h>
  59 #include <errno.h>
  60 #include <locale.h>
  61 #include <fslib.h>
  62 #include <priv.h>
  63 #include <tsol/label.h>
  64 #include "replica.h"
  65 
  66 #define RET_OK  0
  67 #define RET_ERR 32
  68 
  69 #ifdef __STDC__
  70 static void pr_err(const char *fmt, ...);
  71 #else
  72 static void pr_err(char *fmt, va_dcl);
  73 #endif
  74 static  void    usage();
  75 static  int     nfs_unmount(char *, int);
  76 static  void    inform_server(char *, char *, bool_t);
  77 static  struct extmnttab *mnttab_find();
  78 extern int __clnt_bindresvport();
  79 
  80 static  int is_v4_mount(struct extmnttab *);
  81 
  82 static char *myname;
  83 static char typename[64];
  84 
  85 int
  86 main(int argc, char *argv[])
  87 {
  88         extern int optind;
  89         int c;
  90         int umnt_flag = 0;
  91 
  92         (void) setlocale(LC_ALL, "");
  93 
  94 #if !defined(TEXT_DOMAIN)
  95 #define TEXT_DOMAIN "SYS_TEST"
  96 #endif
  97         (void) textdomain(TEXT_DOMAIN);
  98 
  99         myname = strrchr(argv[0], '/');
 100         myname = myname ? myname+1 : argv[0];
 101         (void) sprintf(typename, "nfs %s", myname);
 102         argv[0] = typename;
 103 
 104         /*
 105          * Set options
 106          */
 107         while ((c = getopt(argc, argv, "f")) != EOF) {
 108                 switch (c) {
 109                 case 'f':
 110                         umnt_flag |= MS_FORCE; /* forced unmount is desired */
 111                         break;
 112                 default:
 113                         usage();
 114                         exit(RET_ERR);
 115                 }
 116         }
 117         if (argc - optind != 1) {
 118                 usage();
 119                 exit(RET_ERR);
 120         }
 121 


 137          */
 138         return (nfs_unmount(argv[optind], umnt_flag));
 139 }
 140 
 141 static void
 142 pr_err(const char *fmt, ...)
 143 {
 144         va_list ap;
 145 
 146         va_start(ap, fmt);
 147         (void) fprintf(stderr, "%s: ", typename);
 148         (void) vfprintf(stderr, fmt, ap);
 149         (void) fflush(stderr);
 150         va_end(ap);
 151 }
 152 
 153 static void
 154 usage()
 155 {
 156         (void) fprintf(stderr,
 157             gettext("Usage: nfs umount [-o opts] {server:path | dir}\n"));
 158         exit(RET_ERR);
 159 }
 160 
 161 static int
 162 nfs_unmount(char *pathname, int umnt_flag)
 163 {
 164         struct extmnttab *mntp;
 165         bool_t quick = FALSE;
 166         int is_v4 = FALSE;
 167 
 168         mntp = mnttab_find(pathname);
 169         if (mntp) {
 170                 pathname = mntp->mnt_mountp;
 171         }
 172 
 173         if (mntp)
 174                 is_v4 = is_v4_mount(mntp);
 175 
 176         /* Forced unmount will almost always be successful */
 177         if (umount2(pathname, umnt_flag) < 0) {


 209         char *dirname;
 210 {
 211         FILE *fp;
 212         struct extmnttab mnt;
 213         struct extmnttab *res = NULL;
 214 
 215         fp = fopen(MNTTAB, "r");
 216         if (fp == NULL) {
 217                 pr_err("%s: %s\n", MNTTAB, strerror(errno));
 218                 return (NULL);
 219         }
 220         while (getextmntent(fp, &mnt, sizeof (struct extmnttab)) == 0) {
 221                 if (strcmp(mnt.mnt_mountp, dirname) == 0 ||
 222                     strcmp(mnt.mnt_special, dirname) == 0) {
 223                         if (res)
 224                                 fsfreemnttab(res);
 225                         res = fsdupmnttab(&mnt);
 226                 }
 227         }
 228 
 229         fclose(fp);
 230         return (res);
 231 }
 232 
 233 /*
 234  * If quick is TRUE, it will try to inform server quickly
 235  * as possible.
 236  */
 237 static void
 238 inform_server(char *string, char *opts, bool_t quick)
 239 {
 240         struct timeval timeout;
 241         CLIENT *cl;
 242         enum clnt_stat rpc_stat;
 243         struct replica *list;
 244         int i, n;
 245         char *p = NULL;
 246         static struct timeval create_timeout = {5, 0};
 247         static struct timeval *timep;
 248 
 249         list = parse_replica(string, &n);


 344                          */
 345                         vers = MOUNTVERS3;
 346                         goto retry;
 347                 }
 348                 if (rpc_stat != RPC_SUCCESS)
 349                         pr_err("%s\n", clnt_sperror(cl, "unmount"));
 350         }
 351 
 352         free_replica(list, n);
 353 }
 354 
 355 /*
 356  * This function's behavior is taken from nfsstat.
 357  * Trying to determine what NFS version was used for the mount.
 358  */
 359 int
 360 is_v4_mount(struct extmnttab *mntp)
 361 {
 362         kstat_ctl_t *kc = NULL;         /* libkstat cookie */
 363         kstat_t *ksp;
 364         ulong_t fsid;
 365         struct mntinfo_kstat mik;
 366 
 367         if (mntp == NULL)
 368                 return (FALSE);
 369 
 370         if ((kc = kstat_open()) == NULL)
 371                 return (FALSE);
 372 
 373         for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
 374                 if (ksp->ks_type != KSTAT_TYPE_RAW)
 375                         continue;
 376                 if (strcmp(ksp->ks_module, "nfs") != 0)
 377                         continue;
 378                 if (strcmp(ksp->ks_name, "mntinfo") != 0)
 379                         continue;
 380                 if (mntp->mnt_minor != ksp->ks_instance)
 381                         continue;
 382 
 383                 if (kstat_read(kc, ksp, &mik) == -1)
 384                         continue;


  58 #include <rpcsvc/mount.h>
  59 #include <errno.h>
  60 #include <locale.h>
  61 #include <fslib.h>
  62 #include <priv.h>
  63 #include <tsol/label.h>
  64 #include "replica.h"
  65 
  66 #define RET_OK  0
  67 #define RET_ERR 32
  68 
  69 #ifdef __STDC__
  70 static void pr_err(const char *fmt, ...);
  71 #else
  72 static void pr_err(char *fmt, va_dcl);
  73 #endif
  74 static  void    usage();
  75 static  int     nfs_unmount(char *, int);
  76 static  void    inform_server(char *, char *, bool_t);
  77 static  struct extmnttab *mnttab_find();
  78 extern int __clnt_bindresvport(CLIENT *);
  79 
  80 static  int is_v4_mount(struct extmnttab *);
  81 
  82 static char *myname;
  83 static char typename[64];
  84 
  85 int
  86 main(int argc, char *argv[])
  87 {
  88         extern int optind;
  89         int c;
  90         int umnt_flag = 0;
  91 
  92         (void) setlocale(LC_ALL, "");
  93 
  94 #if !defined(TEXT_DOMAIN)
  95 #define TEXT_DOMAIN "SYS_TEST"
  96 #endif
  97         (void) textdomain(TEXT_DOMAIN);
  98 
  99         myname = strrchr(argv[0], '/');
 100         myname = myname ? myname+1 : argv[0];
 101         (void) snprintf(typename, sizeof (typename), "nfs %s", myname);
 102         argv[0] = typename;
 103 
 104         /*
 105          * Set options
 106          */
 107         while ((c = getopt(argc, argv, "f")) != EOF) {
 108                 switch (c) {
 109                 case 'f':
 110                         umnt_flag |= MS_FORCE; /* forced unmount is desired */
 111                         break;
 112                 default:
 113                         usage();
 114                         exit(RET_ERR);
 115                 }
 116         }
 117         if (argc - optind != 1) {
 118                 usage();
 119                 exit(RET_ERR);
 120         }
 121 


 137          */
 138         return (nfs_unmount(argv[optind], umnt_flag));
 139 }
 140 
 141 static void
 142 pr_err(const char *fmt, ...)
 143 {
 144         va_list ap;
 145 
 146         va_start(ap, fmt);
 147         (void) fprintf(stderr, "%s: ", typename);
 148         (void) vfprintf(stderr, fmt, ap);
 149         (void) fflush(stderr);
 150         va_end(ap);
 151 }
 152 
 153 static void
 154 usage()
 155 {
 156         (void) fprintf(stderr,
 157             gettext("Usage: nfs umount [-f] {server:path | dir}\n"));
 158         exit(RET_ERR);
 159 }
 160 
 161 static int
 162 nfs_unmount(char *pathname, int umnt_flag)
 163 {
 164         struct extmnttab *mntp;
 165         bool_t quick = FALSE;
 166         int is_v4 = FALSE;
 167 
 168         mntp = mnttab_find(pathname);
 169         if (mntp) {
 170                 pathname = mntp->mnt_mountp;
 171         }
 172 
 173         if (mntp)
 174                 is_v4 = is_v4_mount(mntp);
 175 
 176         /* Forced unmount will almost always be successful */
 177         if (umount2(pathname, umnt_flag) < 0) {


 209         char *dirname;
 210 {
 211         FILE *fp;
 212         struct extmnttab mnt;
 213         struct extmnttab *res = NULL;
 214 
 215         fp = fopen(MNTTAB, "r");
 216         if (fp == NULL) {
 217                 pr_err("%s: %s\n", MNTTAB, strerror(errno));
 218                 return (NULL);
 219         }
 220         while (getextmntent(fp, &mnt, sizeof (struct extmnttab)) == 0) {
 221                 if (strcmp(mnt.mnt_mountp, dirname) == 0 ||
 222                     strcmp(mnt.mnt_special, dirname) == 0) {
 223                         if (res)
 224                                 fsfreemnttab(res);
 225                         res = fsdupmnttab(&mnt);
 226                 }
 227         }
 228 
 229         (void) fclose(fp);
 230         return (res);
 231 }
 232 
 233 /*
 234  * If quick is TRUE, it will try to inform server quickly
 235  * as possible.
 236  */
 237 static void
 238 inform_server(char *string, char *opts, bool_t quick)
 239 {
 240         struct timeval timeout;
 241         CLIENT *cl;
 242         enum clnt_stat rpc_stat;
 243         struct replica *list;
 244         int i, n;
 245         char *p = NULL;
 246         static struct timeval create_timeout = {5, 0};
 247         static struct timeval *timep;
 248 
 249         list = parse_replica(string, &n);


 344                          */
 345                         vers = MOUNTVERS3;
 346                         goto retry;
 347                 }
 348                 if (rpc_stat != RPC_SUCCESS)
 349                         pr_err("%s\n", clnt_sperror(cl, "unmount"));
 350         }
 351 
 352         free_replica(list, n);
 353 }
 354 
 355 /*
 356  * This function's behavior is taken from nfsstat.
 357  * Trying to determine what NFS version was used for the mount.
 358  */
 359 int
 360 is_v4_mount(struct extmnttab *mntp)
 361 {
 362         kstat_ctl_t *kc = NULL;         /* libkstat cookie */
 363         kstat_t *ksp;

 364         struct mntinfo_kstat mik;
 365 
 366         if (mntp == NULL)
 367                 return (FALSE);
 368 
 369         if ((kc = kstat_open()) == NULL)
 370                 return (FALSE);
 371 
 372         for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
 373                 if (ksp->ks_type != KSTAT_TYPE_RAW)
 374                         continue;
 375                 if (strcmp(ksp->ks_module, "nfs") != 0)
 376                         continue;
 377                 if (strcmp(ksp->ks_name, "mntinfo") != 0)
 378                         continue;
 379                 if (mntp->mnt_minor != ksp->ks_instance)
 380                         continue;
 381 
 382                 if (kstat_read(kc, ksp, &mik) == -1)
 383                         continue;