Print this page
4833 Remove volrmmount
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>

@@ -15,15 +15,16 @@
  * If applicable, add the following below this CDDL HEADER, with the
  * fields enclosed by brackets "[]" replaced with your own identifying
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
- */
-
-/*
+ *
+ *
  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright 2014 Andrew Stormont.
  */
 
 /*
  * rmf_misc.c :
  *      Miscelleneous routines for rmformat.

@@ -85,11 +86,10 @@
 
 /*
  * Function prototypes.
  */
 static int              my_umount(char *mountp);
-static int              my_volrmmount(char *real_name);
 static int              vol_name_to_dev_node(char *vname, char *found);
 static int              vol_lookup(char *supplied, char *found);
 static device_t         *get_device(char *user_supplied, char *node);
 static char             *get_physical_name(char *path);
 static int              lookup_device(char *supplied, char *found);

@@ -221,115 +221,10 @@
         if (echo_off)
                 (void) tcsetattr(fileno(in), TCSAFLUSH, &tio);
 
 }
 
-int32_t
-check_and_unmount_vold(char *device_name, int32_t flag)
-{
-        char *real_name;
-        char *nm;
-        char tmp_path_name[PATH_MAX];
-        struct stat stat_buf;
-        int32_t ret_val = 0;
-        struct  mnttab  *mntp;
-        FILE    *fp;
-        int nl;
-
-        DPRINTF1("Device name %s\n", device_name);
-
-        if (volmgt_running() == 0) {
-                DPRINTF("Vold not running\n");
-                return (0);
-        }
-        if ((nm = volmgt_symname(device_name)) == NULL) {
-                DPRINTF("path not managed\n");
-                real_name = media_findname(device_name);
-        } else {
-                DPRINTF1("path managed as %s\n", nm);
-                real_name = media_findname(nm);
-                DPRINTF1("real name %s\n", real_name);
-        }
-
-        if (real_name == NULL)
-                return (-1);
-
-        /*
-         * To find out whether the device has been mounted by
-         * volume manager...
-         *
-         * Convert the real name to a block device address.
-         * Do a partial match with the mnttab entries.
-         * Make sure the match is in the beginning to avoid if
-         * anybody puts a label similiar to volume manager path names.
-         * Then use "volrmmount -e <dev_name>" if -U flag is set.
-         */
-
-        nl = strlen("/vol/dev/");
-
-        if (strncmp(real_name, "/vol/dev/", nl) != 0)
-                        return (0);
-        if (real_name[nl] == 'r') {
-                (void) snprintf(tmp_path_name, PATH_MAX, "%s%s", "/vol/dev/",
-                    &real_name[nl + 1]);
-        } else {
-                (void) snprintf(tmp_path_name, PATH_MAX, "%s", real_name);
-        }
-        DPRINTF1("%s \n", tmp_path_name);
-        ret_val = stat(tmp_path_name, &stat_buf);
-        if (ret_val < 0) {
-                PERROR("Could not stat");
-                return (-1);
-        }
-
-        fp = fopen("/etc/mnttab", "r");
-
-        if (fp == NULL) {
-                PERROR("Could not open /etc/mnttab");
-                return (-1);
-        }
-
-        mntp = (struct mnttab *)malloc(sizeof (struct mnttab));
-        if (mntp == NULL) {
-                PERROR("malloc failed");
-                (void) fclose(fp);
-                return (-1);
-        }
-        errno = 0;
-        while (getmntent(fp, mntp) == 0) {
-                if (errno != 0) {
-                        PERROR("Error with mnttab");
-                        (void) fclose(fp);
-                        return (-1);
-                }
-                /* Is it a probable entry? */
-                DPRINTF1(" %s \n", mntp->mnt_special);
-                if (strstr(mntp->mnt_special, tmp_path_name) !=
-                    mntp->mnt_special) {
-                        /* Skip to next entry */
-                        continue;
-                } else {
-                        DPRINTF1("Found!! %s\n", mntp->mnt_special);
-                        ret_val = 1;
-                        break;
-                }
-        }
-
-        if (ret_val == 1) {
-                if (flag) {
-                        if (my_volrmmount(real_name) < 0) {
-                                ret_val = -1;
-                        }
-                } else {
-                        ret_val = -1;
-                }
-        }
-        (void) fclose(fp);
-        free(mntp);
-        return (ret_val);
-}
-
 /*
  * This routine checks if a device has mounted partitions. The
  * device name is assumed to be /dev/rdsk/cNtNdNsN. So, this can
  * be used for SCSI and PCMCIA cards.
  * Returns

@@ -1065,55 +960,10 @@
                 }
         }
         return (-1);
 }
 
-static int
-my_volrmmount(char *real_name)
-{
-        int pid, rval;
-
-        /* Turn on the privileges. */
-        (void) __priv_bracket(PRIV_ON);
-
-        pid = fork();
-
-        /* Turn off the privileges. */
-        (void) __priv_bracket(PRIV_OFF);
-
-        /* create a child to unmount the path */
-        if (pid < 0) {
-                PERROR("fork failed");
-                exit(0);
-        }
-
-        if (pid == 0) {
-                /* the child */
-                /* get rid of those nasty err messages */
-                DPRINTF1("call_unmount_prog: calling %s \n",
-                    "/usr/bin/volrmmount");
-
-                /* Turn on the privileges. */
-                (void) __priv_bracket(PRIV_ON);
-                if (execl("/usr/bin/volrmmount", "/usr/bin/volrmmount", "-e",
-                    real_name, NULL) < 0) {
-                        PERROR("volrmmount exec failed");
-                        /* Turn off the privileges */
-                        (void) __priv_bracket(PRIV_OFF);
-                        exit(-1);
-                }
-        } else if (waitpid(pid, &rval, 0) == pid) {
-                if (WIFEXITED(rval)) {
-                        if (WEXITSTATUS(rval) == 0) {
-                                DPRINTF("volrmmount: Success\n");
-                                return (1);
-                        }
-                }
-        }
-        return (-1);
-}
-
 int
 find_device(int defer, char *tmpstr)
 {
         DIR *dir;
         struct dirent *dirent;

@@ -1158,11 +1008,11 @@
                         continue;
                 }
                 total_devices_found++;
 
                 if ((!defer) && !found) {
-                        char *sn, *tmpbuf;
+                        char *sn, *tmpbuf = NULL;
                         /*
                          * dev_name is an optional command line input.
                          */
                         if (dev_name) {
                                 if (strstr(dirent->d_name, tmpstr)) {