2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Copyright (c) 1983, 1987, 1993
36 * The Regents of the University of California. All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 * $DragonFly: src/lib/libc/gen/disktab.c,v 1.11 2007/06/17 23:50:13 dillon Exp $
68 * @(#)disklabel.c 8.2 (Berkeley) 5/3/95
69 * $FreeBSD: src/lib/libc/gen/disklabel.c,v 1.9.2.1 2001/03/05 08:40:47 obrien
72 #include <sys/param.h>
74 #include <sys/disklabel.h>
75 #include <sys/dtype.h>
76 #include <vfs/ufs/dinode.h>
77 #include <vfs/ufs/fs.h>
86 static int gettype (const char *, const char **);
89 getdisktabbyname(const char *name
)
91 static struct disktab dtab
;
92 struct disktab
*dt
= &dtab
;
93 struct dt_partition
*pp
;
95 char *db_array
[2] = { _PATH_DISKTAB
, 0 };
96 char *cp
, *cq
; /* can't be register */
97 char p
, max
, psize
[3], pbsize
[3],
98 pfsize
[3], poffset
[3], ptype
[3];
101 if (cgetent(&buf
, db_array
, (char *)name
) < 0)
104 bzero(dt
, sizeof(*dt
));
110 while (cq
< dt
->d_typename
+ sizeof(dt
->d_typename
) - 1 &&
111 (*cq
= *cp
) && *cq
!= '|' && *cq
!= ':')
115 #define getnumdflt(field, dname, dflt) \
116 { long f; (field) = (cgetnum(buf, dname, &f) == -1) ? (dflt) : f; }
118 getnumdflt(dt
->d_media_blksize
, "se", DEV_BSIZE
);
119 getnumdflt(dt
->d_nheads
, "nt", 0);
120 getnumdflt(dt
->d_secpertrack
, "ns", 0);
121 getnumdflt(dt
->d_ncylinders
, "nc", 0);
123 if (cgetstr(buf
, "dt", &cq
) > 0)
124 dt
->d_typeid
= gettype(cq
, dktypenames
);
126 getnumdflt(dt
->d_typeid
, "dt", 0);
127 getnumdflt(dt
->d_secpercyl
, "sc", dt
->d_secpertrack
* dt
->d_nheads
);
128 getnumdflt(dt
->d_media_blocks
, "su", dt
->d_secpercyl
* dt
->d_ncylinders
);
129 getnumdflt(dt
->d_rpm
, "rm", 3600);
130 getnumdflt(dt
->d_interleave
, "il", 1);
131 getnumdflt(dt
->d_trackskew
, "sk", 0);
132 getnumdflt(dt
->d_cylskew
, "cs", 0);
133 getnumdflt(dt
->d_headswitch
, "hs", 0);
134 getnumdflt(dt
->d_trkseek
, "ts", 0);
135 getnumdflt(dt
->d_bbsize
, "bs", BBSIZE
);
136 getnumdflt(dt
->d_sbsize
, "sb", SBSIZE
);
138 strcpy(pbsize
, "bx");
139 strcpy(pfsize
, "fx");
140 strcpy(poffset
, "ox");
143 pp
= &dt
->d_partitions
[0];
144 for (p
= 'a'; p
< 'a' + MAXDTPARTITIONS
; p
++, pp
++) {
146 psize
[1] = pbsize
[1] = pfsize
[1] = poffset
[1] = ptype
[1] = p
;
147 if (cgetnum(buf
, psize
, &l
) == -1) {
151 cgetnum(buf
, poffset
, &l
);
153 getnumdflt(pp
->p_fsize
, pfsize
, 0);
157 if (cgetnum(buf
, pbsize
, &bsize
) == 0)
158 pp
->p_frag
= bsize
/ pp
->p_fsize
;
162 getnumdflt(pp
->p_fstype
, ptype
, 0);
163 if (pp
->p_fstype
== 0 && cgetstr(buf
, ptype
, &cq
) > 0) {
164 pp
->p_fstype
= gettype(cq
, fstypenames
);
165 snprintf(pp
->p_fstypestr
,
166 sizeof(pp
->p_fstypestr
), "%s", cq
);
167 } else if (pp
->p_fstype
>= 0 &&
168 pp
->p_fstype
< FSMAXTYPES
) {
169 snprintf(pp
->p_fstypestr
,
170 sizeof(pp
->p_fstypestr
), "%s",
171 fstypenames
[pp
->p_fstype
]);
176 dt
->d_npartitions
= max
+ 1 - 'a';
179 dx
= dt
->d_drivedata
;
180 for (p
= '0'; p
< '0' + NDDATA
; p
++, dx
++) {
182 getnumdflt(*dx
, psize
, 0);
184 dp
->d_magic
= DISKMAGIC
;
185 dp
->d_magic2
= DISKMAGIC
;
192 gettype(const char *t
, const char **names
)
196 for (nm
= names
; *nm
; nm
++)
197 if (strcasecmp(t
, *nm
) == 0)
199 if (isdigit((unsigned char)*t
))