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 #define _PATH_DISKTAB "/etc/disktab"
39 #define DISKTAB "/etc/disktab"
40
41
42
43
44
45
46
47
48 #include <machine/disklabel.h>
49
50
51
52
53
54
55 #define MAXMAXPARTITIONS 22
56 #if MAXPARTITIONS > MAXMAXPARTITIONS
57 #warn beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
58 #endif
59
60
61
62
63 #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
64 #define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
65 #define RAW_PART 2
66 #define DISKMINOR(unit, part) \
67 (((unit) * MAXPARTITIONS) + (part))
68 #define MAKEDISKDEV(maj, unit, part) \
69 (makedev((maj), DISKMINOR((unit), (part))))
70 #define DISKLABELDEV(dev) \
71 (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
72
73 #define DISKMAGIC ((u_int32_t)0x82564557)
74
75 #define MAXDISKSIZE 0x1fffffffffffLL
76
77 #ifndef _LOCORE
78 struct disklabel {
79 u_int32_t d_magic;
80 u_int16_t d_type;
81 u_int16_t d_subtype;
82 char d_typename[16];
83
84
85
86
87
88
89
90
91
92 union {
93 char un_d_packname[16];
94 struct {
95 char *un_d_boot0;
96 char *un_d_boot1;
97 } un_b;
98 } d_un;
99 #define d_packname d_un.un_d_packname
100 #define d_boot0 d_un.un_b.un_d_boot0
101 #define d_boot1 d_un.un_b.un_d_boot1
102
103
104 u_int32_t d_secsize;
105 u_int32_t d_nsectors;
106 u_int32_t d_ntracks;
107 u_int32_t d_ncylinders;
108 u_int32_t d_secpercyl;
109 u_int32_t d_secperunit;
110
111
112
113
114
115
116
117 u_int16_t d_sparespertrack;
118 u_int16_t d_sparespercyl;
119
120
121
122
123 u_int32_t d_acylinders;
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 u_int16_t d_rpm;
143 u_int16_t d_interleave;
144 u_int16_t d_trackskew;
145 u_int16_t d_cylskew;
146 u_int32_t d_headswitch;
147 u_int32_t d_trkseek;
148 u_int32_t d_flags;
149 #define NDDATA 5
150 u_int32_t d_drivedata[NDDATA];
151 u_int16_t d_secperunith;
152 u_int16_t d_version;
153 #define NSPARE 4
154 u_int32_t d_spare[NSPARE];
155 u_int32_t d_magic2;
156 u_int16_t d_checksum;
157
158
159 u_int16_t d_npartitions;
160 u_int32_t d_bbsize;
161 u_int32_t d_sbsize;
162 struct partition {
163 u_int32_t p_size;
164 u_int32_t p_offset;
165 u_int16_t p_offseth;
166 u_int16_t p_sizeh;
167 u_int8_t p_fstype;
168 u_int8_t p_fragblock;
169 u_int16_t p_cpg;
170 } d_partitions[MAXPARTITIONS];
171 };
172
173
174 struct __partitionv0 {
175 u_int32_t p_size;
176 u_int32_t p_offset;
177 u_int32_t p_fsize;
178 u_int8_t p_fstype;
179 u_int8_t p_frag;
180 union {
181 u_int16_t cpg;
182 u_int16_t sgs;
183 } __partitionv0_u1;
184 };
185
186 #else
187
188
189
190 .set d_secsize,40
191 .set d_nsectors,44
192 .set d_ntracks,48
193 .set d_ncylinders,52
194 .set d_secpercyl,56
195 .set d_secperunit,60
196 .set d_end_,404
197 #endif
198
199
200 #define DISKLABELV1_FFS_FRAGBLOCK(fsize, frag) \
201 ((fsize) * (frag) == 0 ? 0 : \
202 (((ffs((fsize) * (frag)) - 13) << 3) | (ffs(frag))))
203
204 #define DISKLABELV1_FFS_BSIZE(i) ((i) == 0 ? 0 : (1 << (((i) >> 3) + 12)))
205 #define DISKLABELV1_FFS_FRAG(i) ((i) == 0 ? 0 : (1 << (((i) & 0x07) - 1)))
206 #define DISKLABELV1_FFS_FSIZE(i) (DISKLABELV1_FFS_FRAG(i) == 0 ? 0 : \
207 (DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i)))
208
209 #define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size)
210 #define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset)
211 #define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \
212 (d)->d_secperunit)
213
214 #define DL_SETPSIZE(p, n) do { \
215 daddr64_t x = (n); \
216 (p)->p_sizeh = x >> 32; \
217 (p)->p_size = x; \
218 } while (0)
219 #define DL_SETPOFFSET(p, n) do { \
220 daddr64_t x = (n); \
221 (p)->p_offseth = x >> 32; \
222 (p)->p_offset = x; \
223 } while (0)
224 #define DL_SETDSIZE(d, n) do { \
225 daddr64_t x = (n); \
226 (d)->d_secperunith = x >> 32; \
227 (d)->d_secperunit = x; \
228 } while (0)
229
230
231 #define DTYPE_SMD 1
232 #define DTYPE_MSCP 2
233 #define DTYPE_DEC 3
234 #define DTYPE_SCSI 4
235 #define DTYPE_ESDI 5
236 #define DTYPE_ST506 6
237 #define DTYPE_HPIB 7
238 #define DTYPE_HPFL 8
239 #define DTYPE_FLOPPY 10
240 #define DTYPE_CCD 11
241 #define DTYPE_VND 12
242 #define DTYPE_ATAPI 13
243 #define DTYPE_RAID 14
244
245 #ifdef DKTYPENAMES
246 static char *dktypenames[] = {
247 "unknown",
248 "SMD",
249 "MSCP",
250 "old DEC",
251 "SCSI",
252 "ESDI",
253 "ST506",
254 "HP-IB",
255 "HP-FL",
256 "type 9",
257 "floppy",
258 "ccd",
259 "vnd",
260 "ATAPI",
261 "RAID",
262 NULL
263 };
264 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
265 #endif
266
267
268
269
270
271
272 #define FS_UNUSED 0
273 #define FS_SWAP 1
274 #define FS_V6 2
275 #define FS_V7 3
276 #define FS_SYSV 4
277 #define FS_V71K 5
278 #define FS_V8 6
279 #define FS_BSDFFS 7
280 #define FS_MSDOS 8
281 #define FS_BSDLFS 9
282 #define FS_OTHER 10
283 #define FS_HPFS 11
284 #define FS_ISO9660 12
285 #define FS_BOOT 13
286 #define FS_ADOS 14
287 #define FS_HFS 15
288 #define FS_ADFS 16
289 #define FS_EXT2FS 17
290 #define FS_CCD 18
291 #define FS_RAID 19
292 #define FS_NTFS 20
293 #define FS_UDF 21
294
295 #ifdef DKTYPENAMES
296 static char *fstypenames[] = {
297 "unused",
298 "swap",
299 "Version6",
300 "Version7",
301 "SystemV",
302 "4.1BSD",
303 "Eighth-Edition",
304 "4.2BSD",
305 "MSDOS",
306 "4.4LFS",
307 "unknown",
308 "HPFS",
309 "ISO9660",
310 "boot",
311 "ADOS",
312 "HFS",
313 "ADFS",
314 "ext2fs",
315 "ccd",
316 "RAID",
317 "NTFS",
318 "UDF",
319 NULL
320 };
321
322
323 static char *fstypesnames[] = {
324 "",
325 "",
326 "",
327 "",
328 "",
329 "",
330 "",
331 "ffs",
332 "msdos",
333 "lfs",
334 "",
335 "",
336 "cd9660",
337 "",
338 "ados",
339 "",
340 "",
341 "ext2fs",
342 "",
343 "",
344 "ntfs",
345 "udf",
346 NULL
347 };
348
349 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
350 #endif
351
352
353
354
355 #define D_BADSECT 0x04
356 #define D_VENDOR 0x08
357
358
359
360
361 #define d_smdflags d_drivedata[0]
362 #define D_SSE 0x1
363 #define d_mindist d_drivedata[1]
364 #define d_maxdist d_drivedata[2]
365 #define d_sdist d_drivedata[3]
366
367
368
369
370 #define d_precompcyl d_drivedata[0]
371 #define d_gap3 d_drivedata[1]
372
373
374
375
376 #define d_blind d_drivedata[0]
377
378 #ifndef _LOCORE
379
380
381
382
383
384 struct format_op {
385 char *df_buf;
386 int df_count;
387 daddr64_t df_startblk;
388 int df_reg[8];
389 };
390
391
392
393
394
395 struct partinfo {
396 struct disklabel *disklab;
397 struct partition *part;
398 };
399
400
401 #define DOS_LABELSECTOR 1
402 #define DOSBBSECTOR 0
403 #define DOSPARTOFF 446
404 #define DOSDISKOFF 444
405 #define NDOSPART 4
406 #define DOSACTIVE 0x80
407
408 #define DOSMBR_SIGNATURE (0xaa55)
409 #define DOSMBR_SIGNATURE_OFF (0x1fe)
410
411 struct dos_partition {
412 u_int8_t dp_flag;
413 u_int8_t dp_shd;
414 u_int8_t dp_ssect;
415 u_int8_t dp_scyl;
416 u_int8_t dp_typ;
417 u_int8_t dp_ehd;
418 u_int8_t dp_esect;
419 u_int8_t dp_ecyl;
420 u_int32_t dp_start;
421 u_int32_t dp_size;
422 };
423
424
425 #define DPSECT(s) ((s) & 0x3f)
426 #define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2))
427
428
429 #define DOSPTYP_UNUSED 0x00
430 #define DOSPTYP_FAT12 0x01
431 #define DOSPTYP_FAT16S 0x04
432 #define DOSPTYP_EXTEND 0x05
433 #define DOSPTYP_FAT16B 0x06
434 #define DOSPTYP_FAT32 0x0b
435 #define DOSPTYP_FAT32L 0x0c
436 #define DOSPTYP_FAT16L 0x0e
437 #define DOSPTYP_EXTENDL 0x0f
438 #define DOSPTYP_ONTRACK 0x54
439 #define DOSPTYP_LINUX 0x83
440 #define DOSPTYP_FREEBSD 0xa5
441 #define DOSPTYP_OPENBSD 0xa6
442 #define DOSPTYP_NETBSD 0xa9
443
444 struct dos_mbr {
445 u_int8_t dmbr_boot[DOSPARTOFF];
446 struct dos_partition dmbr_parts[NDOSPART];
447 u_int16_t dmbr_sign;
448 } __packed;
449
450 #ifdef _KERNEL
451 void diskerr(struct buf *, char *, char *, int, int, struct disklabel *);
452 void disksort(struct buf *, struct buf *);
453 u_int dkcksum(struct disklabel *);
454 char *initdisklabel(struct disklabel *);
455 char *checkdisklabel(void *, struct disklabel *);
456 int setdisklabel(struct disklabel *, struct disklabel *, u_int);
457 char *readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
458 int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *);
459 int bounds_check_with_label(struct buf *, struct disklabel *, int);
460 char *readdoslabel(struct buf *, void (*)(struct buf *),
461 struct disklabel *, int *, int);
462 #ifdef CD9660
463 int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
464 struct disklabel *lp);
465 #endif
466 #ifdef UDF
467 int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
468 struct disklabel *lp);
469 #endif
470 #endif
471 #endif
472
473 #if !defined(_KERNEL) && !defined(_LOCORE)
474
475 #include <sys/cdefs.h>
476
477 __BEGIN_DECLS
478 struct disklabel *getdiskbyname(const char *);
479 __END_DECLS
480
481 #endif