Print this page
574 Minor issues in usr/src/cmd/format/startup.c


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*


  22  * Copyright (c) 2011 Gary Mills
  23  *
  24  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
  25  */
  26 
  27 /*
  28  * This file contains the code to perform program startup.  This
  29  * includes reading the data file and the search for disks.
  30  */
  31 #include "global.h"
  32 
  33 #include <ctype.h>
  34 #include <stdlib.h>
  35 #include <unistd.h>
  36 #include <string.h>
  37 #include <strings.h>
  38 #include <fcntl.h>
  39 #include <errno.h>
  40 #include <memory.h>
  41 #include <dirent.h>


2945                             canonicalize_name(t, arglist[i]);
2946                             if (strncmp(s, t, strlen(t)) == 0)
2947                                 break;
2948                         }
2949                         if (i != diskno)
2950                                 continue;
2951                 }
2952                 (void) strcpy(arglist[diskno], *disklist);
2953                 diskno++;
2954         }
2955         arglist[diskno] = NULL;
2956 }
2957 
2958 #define DISK_PREFIX     "/dev/rdsk/"
2959 
2960 /*
2961  * This Function checks if the non-conventional name is a a link to
2962  * one of the conventional whole disk name.
2963  */
2964 static int
2965 name_represents_wholedisk(name)
2966 char    *name;
2967 {
2968         char    symname[MAXPATHLEN];
2969         char    localname[MAXPATHLEN];
2970         char    *nameptr;


2971 


2972 
2973         (void) memset(symname, 0, MAXPATHLEN);
2974         (void) memset(localname, 0, MAXPATHLEN);
2975         (void) strcpy(localname, name);
2976 
2977         while (readlink(localname, symname, MAXPATHLEN) != -1) {
2978                 nameptr = symname;
2979                 if (strncmp(symname, DISK_PREFIX, strlen(DISK_PREFIX)) == 0)
2980                         nameptr += strlen(DISK_PREFIX);
2981                 if (conventional_name(nameptr)) {
2982                         if (whole_disk_name(nameptr))
2983                                 return (0);
2984                         else
2985                                 return (1);
2986                 }
2987                 (void) strcpy(localname, symname);
2988                 (void) memset(symname, 0, MAXPATHLEN);
2989         }
2990         return (0);
2991 }


   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2012 Nexenta System Inc.
  23  *
  24  * Copyright (c) 2011 Gary Mills
  25  *
  26  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
  27  */
  28 
  29 /*
  30  * This file contains the code to perform program startup.  This
  31  * includes reading the data file and the search for disks.
  32  */
  33 #include "global.h"
  34 
  35 #include <ctype.h>
  36 #include <stdlib.h>
  37 #include <unistd.h>
  38 #include <string.h>
  39 #include <strings.h>
  40 #include <fcntl.h>
  41 #include <errno.h>
  42 #include <memory.h>
  43 #include <dirent.h>


2947                             canonicalize_name(t, arglist[i]);
2948                             if (strncmp(s, t, strlen(t)) == 0)
2949                                 break;
2950                         }
2951                         if (i != diskno)
2952                                 continue;
2953                 }
2954                 (void) strcpy(arglist[diskno], *disklist);
2955                 diskno++;
2956         }
2957         arglist[diskno] = NULL;
2958 }
2959 
2960 #define DISK_PREFIX     "/dev/rdsk/"
2961 
2962 /*
2963  * This Function checks if the non-conventional name is a a link to
2964  * one of the conventional whole disk name.
2965  */
2966 static int
2967 name_represents_wholedisk(char  *name)

2968 {
2969         char    symname[MAXPATHLEN];
2970         char    localname[MAXPATHLEN];
2971         char    *nameptr;
2972         ssize_t symname_size;
2973         size_t disk_prefix_len = strlen(DISK_PREFIX);
2974 
2975         if (strlcpy(localname, name, MAXPATHLEN) >= MAXPATHLEN)
2976                 return (1);     /* buffer overflow, reject this name */
2977 
2978         while ((symname_size = readlink(localname, symname, MAXPATHLEN - 1)) != -1) {
2979                 symname[symname_size] = '\0';



2980                 nameptr = symname;
2981                 if (strncmp(symname, DISK_PREFIX, disk_prefix_len) == 0)
2982                         nameptr += disk_prefix_len;
2983                 if (conventional_name(nameptr))
2984                         return (!whole_disk_name(nameptr));




2985                 (void) strcpy(localname, symname);

2986         }
2987         return (0);
2988 }