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/rmvolmgr/rmm_common.c
          +++ new/usr/src/cmd/rmvolmgr/rmm_common.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      -/*
       20 + *
       21 + *
  22   22   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + *
       25 + * Copyright 2014 Andrew Stormont.
  24   26   */
  25   27  
  26   28  #include <stdio.h>
  27   29  #include <errno.h>
  28   30  #include <string.h>
  29   31  #include <strings.h>
  30   32  #include <stdarg.h>
  31   33  #include <fcntl.h>
  32   34  #include <libintl.h>
  33   35  #include <stdlib.h>
↓ open down ↓ 766 lines elided ↑ open up ↑
 800  802  static boolean_t
 801  803  rmm_action_one(LibHalContext *hal_ctx, const char *name, action_t action,
 802  804      const char *dev, const char *udi, LibHalVolume *v,
 803  805      char **opts, int num_opts, char *mountpoint)
 804  806  {
 805  807          char            dev_str[MAXPATHLEN];
 806  808          char            *mountp;
 807  809          DBusError       error;
 808  810          boolean_t       ret = B_FALSE;
 809  811  
      812 +        dprintf("rmm_action_one %s %s\n", name, action_strings[action]);
      813 +
 810  814          if (strcmp(name, dev) == 0) {
 811  815                  (void) snprintf(dev_str, sizeof (dev_str), name);
 812  816          } else {
 813  817                  (void) snprintf(dev_str, sizeof (dev_str), "%s %s", name, dev);
 814  818          }
 815  819  
 816  820          dbus_error_init(&error);
 817  821  
 818  822          switch (action) {
 819  823          case EJECT:
 820  824                  ret = rmm_hal_eject(hal_ctx, udi, &error);
 821  825                  break;
 822  826          case INSERT:
 823  827          case REMOUNT:
 824      -                if (libhal_volume_is_mounted(v)) {
 825      -                        goto done;
 826      -                }
 827  828                  ret = rmm_hal_mount(hal_ctx, udi,
 828  829                      opts, num_opts, mountpoint, &error);
 829  830                  break;
 830  831          case UNMOUNT:
 831      -                if (!libhal_volume_is_mounted(v)) {
 832      -                        goto done;
 833      -                }
 834  832                  ret = rmm_hal_unmount(hal_ctx, udi, &error);
 835  833                  break;
 836  834          case CLOSETRAY:
 837  835                  ret = rmm_hal_closetray(hal_ctx, udi, &error);
 838  836                  break;
 839  837          }
 840  838  
 841  839          if (!ret) {
 842  840                  (void) fprintf(stderr, gettext("%s of %s failed: %s\n"),
 843  841                      action_strings[action], dev_str, rmm_strerror(&error, -1));
↓ open down ↓ 68 lines elided ↑ open up ↑
 912  910          }
 913  911  
 914  912          /*
 915  913           * For those drives that do not require media eject,
 916  914           * EJECT turns into UNMOUNT.
 917  915           */
 918  916          if ((action == EJECT) && !libhal_drive_requires_eject(d)) {
 919  917                  action = UNMOUNT;
 920  918          }
 921  919  
      920 +        /*
      921 +         * We can't mount or unmount a drive that has no volumes.
      922 +         * Either the media isn't inserted or it's not formatted
      923 +         */
      924 +        if (volumes == NULL && (action != EJECT && action != CLOSETRAY)) {
      925 +                (void) fprintf(stderr, libhal_drive_requires_eject(d) ? 
      926 +                    gettext("no volumes in '%s' to %s\n") :
      927 +                    gettext("no volumes on '%s' to %s\n"),
      928 +                    name, action_strings[action]);
      929 +                goto out;
      930 +        }
      931 +
 922  932          /* per drive action */
 923  933          if ((action == EJECT) || (action == CLOSETRAY)) {
 924  934                  ret = rmm_action_one(hal_ctx, name, action, d_dev, d_udi, NULL,
 925  935                      opts, num_opts, NULL);
 926  936  
 927  937                  if (!ret || (action == CLOSETRAY)) {
 928  938                          goto out;
 929  939                  }
 930  940          }
 931  941  
↓ open down ↓ 23 lines elided ↑ open up ↑
 955  965                  if (ret) {
 956  966                          (void) vold_postprocess(hal_ctx, udi, aap);
 957  967                  }
 958  968  
 959  969                  if (aap == &aa_local) {
 960  970                          rmm_volume_aa_free(aap);
 961  971                  }
 962  972          }
 963  973  
 964  974  out:
 965      -        rmm_volumes_free(volumes);
 966      -        libhal_drive_free(d);
      975 +        if (volumes != NULL)
      976 +                rmm_volumes_free(volumes);
      977 +        if (d != NULL)
      978 +                libhal_drive_free(d);
 967  979  
 968  980          return (ret);
 969  981  }
 970  982  
 971  983  
 972  984  /*
 973  985   * rescan by name
 974  986   * if name is NULL, rescan all drives
 975  987   */
 976  988  boolean_t
↓ open down ↓ 436 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX