Print this page
4833 Remove volrmmount
4845 rm(u)mount don't always print mount/unmount errors
4846 HAL partition names don't match real parition names
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/rmformat/rmf_misc.c
          +++ new/usr/src/cmd/rmformat/rmf_misc.c
↓ open down ↓ 9 lines elided ↑ open up ↑
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20      - */
  21      -
  22      -/*
       20 + *
       21 + *
  23   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   23   * Use is subject to license terms.
       24 + *
       25 + * Copyright 2014 Andrew Stormont.
  25   26   */
  26   27  
  27   28  /*
  28   29   * rmf_misc.c :
  29   30   *      Miscelleneous routines for rmformat.
  30   31   */
  31   32  
  32   33  #include <sys/types.h>
  33   34  #include <stdio.h>
  34   35  #include <sys/mnttab.h>
↓ open down ↓ 45 lines elided ↑ open up ↑
  80   81  
  81   82  /*
  82   83   * ON-private functions from libvolmgt
  83   84   */
  84   85  int     _dev_mounted(char *path);
  85   86  
  86   87  /*
  87   88   * Function prototypes.
  88   89   */
  89   90  static int              my_umount(char *mountp);
  90      -static int              my_volrmmount(char *real_name);
  91   91  static int              vol_name_to_dev_node(char *vname, char *found);
  92   92  static int              vol_lookup(char *supplied, char *found);
  93   93  static device_t         *get_device(char *user_supplied, char *node);
  94   94  static char             *get_physical_name(char *path);
  95   95  static int              lookup_device(char *supplied, char *found);
  96   96  static void             fini_device(device_t *dev);
  97   97  static int              is_cd(char *node);
  98   98  void                    *my_zalloc(size_t size);
  99   99  void                    err_msg(char *fmt, ...);
 100  100  int                     inquiry(int fd, uchar_t *inq);
↓ open down ↓ 115 lines elided ↑ open up ↑
 216  216          wp->sm_passwd_len = len;
 217  217          (void) strncpy(wp->sm_passwd, passwd, wp->sm_passwd_len);
 218  218          wp->sm_version = SMWP_STATE_V_1;
 219  219  
 220  220          /* Restore echoing.  */
 221  221          if (echo_off)
 222  222                  (void) tcsetattr(fileno(in), TCSAFLUSH, &tio);
 223  223  
 224  224  }
 225  225  
 226      -int32_t
 227      -check_and_unmount_vold(char *device_name, int32_t flag)
 228      -{
 229      -        char *real_name;
 230      -        char *nm;
 231      -        char tmp_path_name[PATH_MAX];
 232      -        struct stat stat_buf;
 233      -        int32_t ret_val = 0;
 234      -        struct  mnttab  *mntp;
 235      -        FILE    *fp;
 236      -        int nl;
 237      -
 238      -        DPRINTF1("Device name %s\n", device_name);
 239      -
 240      -        if (volmgt_running() == 0) {
 241      -                DPRINTF("Vold not running\n");
 242      -                return (0);
 243      -        }
 244      -        if ((nm = volmgt_symname(device_name)) == NULL) {
 245      -                DPRINTF("path not managed\n");
 246      -                real_name = media_findname(device_name);
 247      -        } else {
 248      -                DPRINTF1("path managed as %s\n", nm);
 249      -                real_name = media_findname(nm);
 250      -                DPRINTF1("real name %s\n", real_name);
 251      -        }
 252      -
 253      -        if (real_name == NULL)
 254      -                return (-1);
 255      -
 256      -        /*
 257      -         * To find out whether the device has been mounted by
 258      -         * volume manager...
 259      -         *
 260      -         * Convert the real name to a block device address.
 261      -         * Do a partial match with the mnttab entries.
 262      -         * Make sure the match is in the beginning to avoid if
 263      -         * anybody puts a label similiar to volume manager path names.
 264      -         * Then use "volrmmount -e <dev_name>" if -U flag is set.
 265      -         */
 266      -
 267      -        nl = strlen("/vol/dev/");
 268      -
 269      -        if (strncmp(real_name, "/vol/dev/", nl) != 0)
 270      -                        return (0);
 271      -        if (real_name[nl] == 'r') {
 272      -                (void) snprintf(tmp_path_name, PATH_MAX, "%s%s", "/vol/dev/",
 273      -                    &real_name[nl + 1]);
 274      -        } else {
 275      -                (void) snprintf(tmp_path_name, PATH_MAX, "%s", real_name);
 276      -        }
 277      -        DPRINTF1("%s \n", tmp_path_name);
 278      -        ret_val = stat(tmp_path_name, &stat_buf);
 279      -        if (ret_val < 0) {
 280      -                PERROR("Could not stat");
 281      -                return (-1);
 282      -        }
 283      -
 284      -        fp = fopen("/etc/mnttab", "r");
 285      -
 286      -        if (fp == NULL) {
 287      -                PERROR("Could not open /etc/mnttab");
 288      -                return (-1);
 289      -        }
 290      -
 291      -        mntp = (struct mnttab *)malloc(sizeof (struct mnttab));
 292      -        if (mntp == NULL) {
 293      -                PERROR("malloc failed");
 294      -                (void) fclose(fp);
 295      -                return (-1);
 296      -        }
 297      -        errno = 0;
 298      -        while (getmntent(fp, mntp) == 0) {
 299      -                if (errno != 0) {
 300      -                        PERROR("Error with mnttab");
 301      -                        (void) fclose(fp);
 302      -                        return (-1);
 303      -                }
 304      -                /* Is it a probable entry? */
 305      -                DPRINTF1(" %s \n", mntp->mnt_special);
 306      -                if (strstr(mntp->mnt_special, tmp_path_name) !=
 307      -                    mntp->mnt_special) {
 308      -                        /* Skip to next entry */
 309      -                        continue;
 310      -                } else {
 311      -                        DPRINTF1("Found!! %s\n", mntp->mnt_special);
 312      -                        ret_val = 1;
 313      -                        break;
 314      -                }
 315      -        }
 316      -
 317      -        if (ret_val == 1) {
 318      -                if (flag) {
 319      -                        if (my_volrmmount(real_name) < 0) {
 320      -                                ret_val = -1;
 321      -                        }
 322      -                } else {
 323      -                        ret_val = -1;
 324      -                }
 325      -        }
 326      -        (void) fclose(fp);
 327      -        free(mntp);
 328      -        return (ret_val);
 329      -}
 330      -
 331  226  /*
 332  227   * This routine checks if a device has mounted partitions. The
 333  228   * device name is assumed to be /dev/rdsk/cNtNdNsN. So, this can
 334  229   * be used for SCSI and PCMCIA cards.
 335  230   * Returns
 336  231   *       0 : if not mounted
 337  232   *       1 : if successfully unmounted
 338  233   *      -1 : Any error or umount failed
 339  234   */
 340  235  
↓ open down ↓ 719 lines elided ↑ open up ↑
1060  955                  if (WIFEXITED(rval)) {
1061  956                          if (WEXITSTATUS(rval) == 0) {
1062  957                                  DPRINTF("umount : Success\n");
1063  958                                  return (1);
1064  959                          }
1065  960                  }
1066  961          }
1067  962          return (-1);
1068  963  }
1069  964  
1070      -static int
1071      -my_volrmmount(char *real_name)
1072      -{
1073      -        int pid, rval;
1074      -
1075      -        /* Turn on the privileges. */
1076      -        (void) __priv_bracket(PRIV_ON);
1077      -
1078      -        pid = fork();
1079      -
1080      -        /* Turn off the privileges. */
1081      -        (void) __priv_bracket(PRIV_OFF);
1082      -
1083      -        /* create a child to unmount the path */
1084      -        if (pid < 0) {
1085      -                PERROR("fork failed");
1086      -                exit(0);
1087      -        }
1088      -
1089      -        if (pid == 0) {
1090      -                /* the child */
1091      -                /* get rid of those nasty err messages */
1092      -                DPRINTF1("call_unmount_prog: calling %s \n",
1093      -                    "/usr/bin/volrmmount");
1094      -
1095      -                /* Turn on the privileges. */
1096      -                (void) __priv_bracket(PRIV_ON);
1097      -                if (execl("/usr/bin/volrmmount", "/usr/bin/volrmmount", "-e",
1098      -                    real_name, NULL) < 0) {
1099      -                        PERROR("volrmmount exec failed");
1100      -                        /* Turn off the privileges */
1101      -                        (void) __priv_bracket(PRIV_OFF);
1102      -                        exit(-1);
1103      -                }
1104      -        } else if (waitpid(pid, &rval, 0) == pid) {
1105      -                if (WIFEXITED(rval)) {
1106      -                        if (WEXITSTATUS(rval) == 0) {
1107      -                                DPRINTF("volrmmount: Success\n");
1108      -                                return (1);
1109      -                        }
1110      -                }
1111      -        }
1112      -        return (-1);
1113      -}
1114      -
1115  965  int
1116  966  find_device(int defer, char *tmpstr)
1117  967  {
1118  968          DIR *dir;
1119  969          struct dirent *dirent;
1120  970          char sdev[PATH_MAX], dev[PATH_MAX], *pname;
1121  971          device_t *t_dev;
1122  972          int removable = 0;
1123  973          int device_type = 0;
1124  974          int hotpluggable = 0;
↓ open down ↓ 28 lines elided ↑ open up ↑
1153 1003  #endif
1154 1004                  if (!lookup_device(sdev, dev)) {
1155 1005                          continue;
1156 1006                  }
1157 1007                  if ((t_dev = get_device(NULL, dev)) == NULL) {
1158 1008                          continue;
1159 1009                  }
1160 1010                  total_devices_found++;
1161 1011  
1162 1012                  if ((!defer) && !found) {
1163      -                        char *sn, *tmpbuf;
     1013 +                        char *sn, *tmpbuf = NULL;
1164 1014                          /*
1165 1015                           * dev_name is an optional command line input.
1166 1016                           */
1167 1017                          if (dev_name) {
1168 1018                                  if (strstr(dirent->d_name, tmpstr)) {
1169 1019                                          found = 1;
1170 1020                                  } else if (!vol_running) {
1171 1021                                          continue;
1172 1022                                  }
1173 1023                          }
↓ open down ↓ 918 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX