Print this page
4846 HAL partition names don't match real partition names
   1 /*
   2  *
   3  * fsutils.c : filesystem utilities
   4  *
   5  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   6  * Use is subject to license terms.
   7  *


   8  * Licensed under the Academic Free License version 2.1
   9  *
  10  */
  11 
  12 #ifdef HAVE_CONFIG_H
  13 #include <config.h>
  14 #endif
  15 
  16 #include <stdio.h>
  17 #include <sys/types.h>
  18 #include <sys/scsi/impl/uscsi.h>
  19 #include <string.h>
  20 #include <strings.h>
  21 #include <ctype.h>
  22 #include <unistd.h>
  23 #include <stdlib.h>
  24 #include <errno.h>
  25 #include <fcntl.h>
  26 #include <sys/dkio.h>
  27 #include <libintl.h>
  28 #include <sys/dktp/fdisk.h>
  29 #include <sys/fs/pc_label.h>
  30 
  31 #include <libhal.h>
  32 #include "fsutils.h"
  33 
  34 /*
  35  * Separates dos notation device spec into device and drive number


  36  */
  37 boolean_t
  38 dos_to_dev(char *path, char **devpath, int *num)
  39 {
  40         char *p;


  41 
  42         if ((p = strrchr(path, ':')) == NULL) {
  43                 return (B_FALSE);


  44         }
  45         if ((*num = atoi(p + 1)) == 0) {



  46                 return (B_FALSE);
  47         }
  48         p[0] = '\0';
  49         *devpath = strdup(path);
  50         p[0] = ':';
  51         return (*devpath != NULL);
  52 }
  53 
  54 char *
  55 get_slice_name(char *devlink)
  56 {
  57         char    *part, *slice, *disk;
  58         char    *s = NULL;
  59         char    *p;
  60 
  61         if ((p = strstr(devlink, "/lofi/")) != 0) {
  62                 return (p + sizeof ("/lofi/") - 1);
  63         }
  64 
  65         part = strrchr(devlink, 'p');
  66         slice = strrchr(devlink, 's');
  67         disk = strrchr(devlink, 'd');
  68 
  69         if ((part != NULL) && (part > slice) && (part > disk)) {
  70                 s = part;
  71         } else if ((slice != NULL) && (slice > disk)) {


   1 /*
   2  *
   3  * fsutils.c : filesystem utilities
   4  *
   5  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
   6  * Use is subject to license terms.
   7  *
   8  * Copyright 2014 Andrew Stormont.
   9  *
  10  * Licensed under the Academic Free License version 2.1
  11  *
  12  */
  13 
  14 #ifdef HAVE_CONFIG_H
  15 #include <config.h>
  16 #endif
  17 
  18 #include <stdio.h>
  19 #include <sys/types.h>
  20 #include <sys/scsi/impl/uscsi.h>
  21 #include <string.h>
  22 #include <strings.h>
  23 #include <ctype.h>
  24 #include <unistd.h>
  25 #include <stdlib.h>
  26 #include <errno.h>
  27 #include <fcntl.h>
  28 #include <sys/dkio.h>
  29 #include <libintl.h>
  30 #include <sys/dktp/fdisk.h>
  31 #include <sys/fs/pc_label.h>
  32 
  33 #include <libhal.h>
  34 #include "fsutils.h"
  35 
  36 /*
  37  * Separates dos notation device spec into device and drive number
  38  *     pN partition names are rewritten to point to p0
  39  *     :N partition names are dropped
  40  */
  41 boolean_t
  42 dos_to_dev(char *path, char **devpath, int *num)
  43 {
  44         int i;
  45         char *buf;
  46         boolean_t found = B_FALSE;
  47 
  48         for (i = strlen(path); i > 0; i--) {
  49                 if (path[i] == 'p' || path[i] == ':') {
  50                         found = B_TRUE;
  51                         break;
  52                 }
  53         }
  54 
  55         if (found == B_FALSE || (*num = atoi(path + i + 1)) == 0 ||
  56             (buf = strdup(path)) == NULL) {
  57                 return (B_FALSE);
  58         }
  59 
  60         (void) strcpy(buf + i, path[i] == 'p' ? "p0" : "");
  61         *devpath = buf;
  62         return (B_TRUE);
  63 }
  64 
  65 char *
  66 get_slice_name(char *devlink)
  67 {
  68         char    *part, *slice, *disk;
  69         char    *s = NULL;
  70         char    *p;
  71 
  72         if ((p = strstr(devlink, "/lofi/")) != 0) {
  73                 return (p + sizeof ("/lofi/") - 1);
  74         }
  75 
  76         part = strrchr(devlink, 'p');
  77         slice = strrchr(devlink, 's');
  78         disk = strrchr(devlink, 'd');
  79 
  80         if ((part != NULL) && (part > slice) && (part > disk)) {
  81                 s = part;
  82         } else if ((slice != NULL) && (slice > disk)) {