1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* Copyright (c) 1996, 1998, 1999 University of Utah and the Flux Group.
* All rights reserved.
*
* This file is part of the Flux OSKit. The OSKit is free software, also known
* as "open source;" you can redistribute it and/or modify it under the terms
* of the GNU General Public License (GPL), version 2, as published by the Free
* Software Foundation (FSF). To explore alternate licensing terms, contact
* the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
*
* The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
* received a copy of the GPL along with the OSKit; see the file COPYING. If
* not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
*/
/*
* This is provided to allow the use of FreeBSD-style slices, which allow
* a disklable to be inside a DOS partition.
* compatabiluty-slice support?
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <oskit/diskpart/diskpart.h>
/*
* This code is based on the diskpart_lookup_bsd_compat rountine
*
* name is a NULL-terminated ASCII string indicating the partition.
* It is essentially the device name without the drive name part.
* The FreeBSD slice name `sd0s1e' would just be `s1e'
*
* If a slice name is given, it is used.
* Otherwise, a partition is first assumed to be inside of the
* (first) BSD slice, if one exists.
*/
struct diskpart *
diskpart_lookup_bsd_string(struct diskpart *array, const char *name)
{
struct diskpart *partptr;
const char *nname;
int num;
/* null pointer */
if (name == NULL) {
return(NULL);
}
nname=name;
partptr=array;
/* If no partition then return the whole disk */
if (nname[0] == 0)
return(partptr);
/* is it a slice specification? ('s' followed by int) */
if ((tolower(nname[0]) == 's') && (isdigit(nname[1]))) {
nname++; /* skip past the s */
num = atoi(nname); /* get the slice number */
if (num > partptr->nsubs) {
return(NULL);
} else {
if (num>0)
partptr = &partptr->subs[num-1];
else
return(NULL); /* Slice 0 is no good */
}
while (isdigit(nname[0]))
nname++;
/* If no partition then return the whole `slice' */
if (nname[0] == 0)
return(partptr);
} else { /* check first for BSD partition (if any) */
int i;
for (i = 0; i < array[0].nsubs; i++)
if (partptr[0].subs[i].type == DISKPART_BSD) {
partptr=&partptr->subs[i];
break;
}
/* I could check for VTOC aliasing too ... */
}
/* find the partition (in slice, if specified, or aliased to BSD */
if (isalpha(nname[0])) {
num = tolower(nname[0]) - 'a';
if (num > partptr->nsubs) {
return(NULL);
} else {
partptr = &partptr->subs[num];
}
} else { /* bad name */
return(NULL);
}
return(partptr);
}
|