From: Ben Gras Date: Thu, 22 Dec 2011 21:51:26 +0000 (+0100) Subject: netbsd fsck driver import X-Git-Tag: v3.2.0~157 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/soc.html?a=commitdiff_plain;h=4d4057d8a2cac606f1af23617ce97ebf520ebc73;p=minix.git netbsd fsck driver import . fsck driver parses /etc/fstab and invokes sub-fscks . further simplifies fs handling in rc --- diff --git a/Makefile b/Makefile index 120c700f2..916c3c356 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,7 @@ elf-libraries: includes commands: includes libraries $(MAKE) -C commands all $(MAKE) -C bin all + $(MAKE) -C sbin all $(MAKE) -C usr.bin all $(MAKE) -C libexec all $(MAKE) -C usr.sbin all @@ -68,6 +69,7 @@ dep-all: $(MAKE) CC=cc -C boot dependall $(MAKE) -C commands dependall $(MAKE) -C bin dependall + $(MAKE) -C sbin dependall $(MAKE) -C usr.bin dependall $(MAKE) -C libexec dependall $(MAKE) -C usr.sbin dependall @@ -85,6 +87,7 @@ all: $(MAKE) CC=cc -C boot all $(MAKE) -C commands all $(MAKE) -C bin all + $(MAKE) -C sbin all $(MAKE) -C usr.bin all $(MAKE) -C libexec all $(MAKE) -C usr.sbin all @@ -96,6 +99,7 @@ install: $(MAKE) -C man install makedb $(MAKE) -C commands install $(MAKE) -C bin install + $(MAKE) -C sbin install $(MAKE) -C usr.bin install $(MAKE) -C usr.sbin install $(MAKE) -C servers install @@ -106,6 +110,7 @@ clean: mkfiles $(MAKE) -C boot clean $(MAKE) -C commands clean $(MAKE) -C bin clean + $(MAKE) -C sbin clean $(MAKE) -C usr.bin clean $(MAKE) -C libexec clean $(MAKE) -C usr.sbin clean @@ -118,6 +123,7 @@ cleandepend: mkfiles $(MAKE) -C boot cleandepend $(MAKE) -C commands cleandepend $(MAKE) -C bin cleandepend + $(MAKE) -C sbin cleandepend $(MAKE) -C usr.bin cleandepend $(MAKE) -C libexec cleandepend $(MAKE) -C usr.sbin cleandepend diff --git a/commands/fsck.mfs/Makefile b/commands/fsck.mfs/Makefile index 33e033fe0..7200c6970 100644 --- a/commands/fsck.mfs/Makefile +++ b/commands/fsck.mfs/Makefile @@ -1,6 +1,7 @@ +FSCK= ${NETBSDSRCDIR}/sbin/fsck PROG= fsck.mfs SRCS= fsck.c -CPPFLAGS+= -I${MINIXSRCDIR}/servers +CPPFLAGS+= -I${MINIXSRCDIR}/servers -I${FSCK} BINDIR= /sbin MAN= diff --git a/commands/fsck.mfs/fsck.c b/commands/fsck.mfs/fsck.c index 852a6fdea..6c1d57e21 100644 --- a/commands/fsck.mfs/fsck.c +++ b/commands/fsck.mfs/fsck.c @@ -58,6 +58,8 @@ #include #include +#include "exitvalues.h" + #undef N_DATA unsigned int fs_version = 2, block_size = 0; @@ -238,7 +240,7 @@ void fatal(s) char *s; { printf("%s\nfatal\n", s); - exit(-1); + exit(FSCK_EXIT_CHECK_FAILED); } /* Test for end of line. */ @@ -267,7 +269,7 @@ char *question; return(1); } fflush(stdout); - if ((c = answerchar = getchar()) == 'q' || c == 'Q') exit(1); + if ((c = answerchar = getchar()) == 'q' || c == 'Q') exit(FSCK_EXIT_CHECK_FAILED); if(c == 'A') { automatic = 1; c = 'y'; } while (!eoln(c)) c = getchar(); yes = !(answerchar == 'n' || answerchar == 'N'); @@ -551,7 +553,7 @@ void lsuper() if(sb.s_flags & MFSFLAG_CLEAN) printf("CLEAN "); else printf("DIRTY "); printf("\n"); } while (yes("Do you want to try again")); - if (repair) exit(0); + if (repair) exit(FSCK_EXIT_OK); } /* Get the super block from either disk or user. Do some initial checks. */ @@ -1589,6 +1591,7 @@ char *f, **clist, **ilist, **zlist; /* If we were told to repair the FS, and the user never stopped us from * doing it, and the FS wasn't marked clean, we can mark the FS as clean. + * If we were stopped from repairing, tell user about it. */ if(repair && !(sb.s_flags & MFSFLAG_CLEAN)) { if(notrepaired) { @@ -1609,13 +1612,14 @@ int argc; char **argv; { register char **clist = 0, **ilist = 0, **zlist = 0; + int badflag = 0; register devgiven = 0; register char *arg; if ((1 << BITSHIFT) != 8 * sizeof(bitchunk_t)) { printf("Fsck was compiled with the wrong BITSHIFT!\n"); - exit(1); + exit(FSCK_EXIT_CHECK_FAILED); } sync(); @@ -1641,6 +1645,7 @@ char **argv; case 'f': break; default: printf("%s: unknown flag '%s'\n", prog, arg); + badflag = 1; } else { chkdev(arg, clist, ilist, zlist); @@ -1649,9 +1654,9 @@ char **argv; zlist = 0; devgiven = 1; } - if (!devgiven) { + if (!devgiven || badflag) { printf("Usage: fsck [-dyfpacilrsz] file\n"); - exit(1); + exit(FSCK_EXIT_USAGE); } return(0); } diff --git a/commands/mkfs.mfs/mkfs.c b/commands/mkfs.mfs/mkfs.c index 750aa2e24..0d5b184c1 100644 --- a/commands/mkfs.mfs/mkfs.c +++ b/commands/mkfs.mfs/mkfs.c @@ -381,36 +381,20 @@ printf("testb = 0x%x 0x%x 0x%x\n", testb[0], testb[1], testb[block_size-1]); block_t sizeup(device) char *device; { - int fd; - struct partition entry; + u64_t bytes, resize; block_t d; - struct stat st; - unsigned int rem; - u64_t resize; + u32_t rem; - - if ((fd = open(device, O_RDONLY)) == -1) { - if (errno != ENOENT) - perror("sizeup open"); + if(minix_sizeup(device, &bytes) < 0) { + perror("sizeup"); return 0; } - if (ioctl(fd, DIOCGETP, &entry) == -1) { - perror("sizeup ioctl"); - if(fstat(fd, &st) < 0) { - perror("fstat"); - entry.size = cvu64(0); - } else { - fprintf(stderr, "used fstat instead\n"); - entry.size = cvu64(st.st_size); - } - } - close(fd); - d = div64u(entry.size, block_size); - rem = rem64u(entry.size, block_size); + d = div64u(bytes, block_size); + rem = rem64u(bytes, block_size); resize = add64u(mul64u(d, block_size), rem); - if(cmp64(resize, entry.size) != 0) { + if(cmp64(resize, bytes) != 0) { d = ULONG_MAX; fprintf(stderr, "mkfs: truncating FS at %lu blocks\n", d); } diff --git a/common/include/arch/i386/Makefile.inc b/common/include/arch/i386/Makefile.inc index be3cd8728..83ae0f157 100644 --- a/common/include/arch/i386/Makefile.inc +++ b/common/include/arch/i386/Makefile.inc @@ -4,5 +4,6 @@ INCS+= archtypes.h bios.h cmos.h cpu.h diskparm.h fpu.h int86.h \ interrupt.h memory.h multiboot.h partition.h \ pci.h pci_amd.h pci_intel.h pci_sis.h pci_via.h \ - ports.h stackframe.h vm.h elf.h elf_machdep.h + ports.h stackframe.h vm.h elf.h elf_machdep.h mutex.h \ + disklabel.h diff --git a/common/include/arch/i386/disklabel.h b/common/include/arch/i386/disklabel.h new file mode 100644 index 000000000..e7d5246bc --- /dev/null +++ b/common/include/arch/i386/disklabel.h @@ -0,0 +1,75 @@ +/* $NetBSD: disklabel.h,v 1.16 2011/08/30 12:39:55 bouyer Exp $ */ + +/* + * Copyright (c) 1994 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _I386_DISKLABEL_H_ +#define _I386_DISKLABEL_H_ + +#define LABELUSESMBR 1 /* use MBR partitionning */ +#define LABELSECTOR 1 /* sector containing label */ +#define LABELOFFSET 0 /* offset of label in sector */ +#define MAXPARTITIONS 16 /* number of partitions */ +#define OLDMAXPARTITIONS 8 /* number of partitions before 1.6 */ +#define RAW_PART 3 /* raw partition: XX?d (XXX) */ + +/* + * We use the highest bit of the minor number for the partition number. + * This maintains backward compatibility with device nodes created before + * MAXPARTITIONS was increased. + */ +#define __I386_MAXDISKS ((1 << 20) / MAXPARTITIONS) +#define DISKUNIT(dev) ((minor(dev) / OLDMAXPARTITIONS) % __I386_MAXDISKS) +#define DISKPART(dev) ((minor(dev) % OLDMAXPARTITIONS) + \ + ((minor(dev) / (__I386_MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS)) +#define DISKMINOR(unit, part) \ + (((unit) * OLDMAXPARTITIONS) + ((part) % OLDMAXPARTITIONS) + \ + ((part) / OLDMAXPARTITIONS) * (__I386_MAXDISKS * OLDMAXPARTITIONS)) + +/* Pull in MBR partition definitions. */ +#if HAVE_NBTOOL_CONFIG_H +#include +#else +#include +#endif /* HAVE_NBTOOL_CONFIG_H */ + +#ifndef __ASSEMBLER__ +#if HAVE_NBTOOL_CONFIG_H +#include +#else +#include +#endif /* HAVE_NBTOOL_CONFIG_H */ +struct cpu_disklabel { +#define __HAVE_DISKLABEL_DKBAD + struct dkbad bad; +}; +#endif + +#endif /* _I386_DISKLABEL_H_ */ diff --git a/common/include/arch/i386/mutex.h b/common/include/arch/i386/mutex.h new file mode 100644 index 000000000..ade5aeab1 --- /dev/null +++ b/common/include/arch/i386/mutex.h @@ -0,0 +1,3 @@ +/* $NetBSD: mutex.h,v 1.2 2007/02/09 21:55:05 ad Exp $ */ + +#include diff --git a/common/include/sys/Makefile.inc b/common/include/sys/Makefile.inc index 1dd24da7b..b058fb6aa 100644 --- a/common/include/sys/Makefile.inc +++ b/common/include/sys/Makefile.inc @@ -5,5 +5,7 @@ INCS+= elf32.h elf64.h elf_common.h elf_generic.h \ ioc_block.h ioc_fbd.h ioc_file.h ioc_tape.h ioc_disk.h \ ioc_memory.h ioc_sound.h ioc_tty.h \ - kbdio.h mtio.h svrctl.h video.h vm.h procfs.h elf_core.h exec_elf.h + kbdio.h mtio.h svrctl.h video.h vm.h procfs.h elf_core.h exec_elf.h \ + disk.h dkio.h ioccom.h mutex.h iostat.h disklabel.h bootblock.h \ + dkbad.h diff --git a/common/include/sys/bootblock.h b/common/include/sys/bootblock.h new file mode 100644 index 000000000..cdc29d803 --- /dev/null +++ b/common/include/sys/bootblock.h @@ -0,0 +1,1442 @@ +/* $NetBSD: bootblock.h,v 1.52 2011/01/06 01:08:48 jakllsch Exp $ */ + +/*- + * Copyright (c) 2002-2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/*- + * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo, + * Michael L. Finch, Bradley A. Grantham, and + * Lawrence A. Kesteloot + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Alice Group. + * 4. The names of the Alice Group or any of its members may not be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/* + * Copyright (c) 1994, 1999 Christopher G. Demetriou + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Christopher G. Demetriou + * for the NetBSD Project. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Copyright (c) 1994 Rolf Grossmann + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Rolf Grossmann. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_BOOTBLOCK_H +#define _SYS_BOOTBLOCK_H + +#if !defined(__ASSEMBLER__) +#include +#if defined(_KERNEL) || defined(_STANDALONE) +#include +#else +#include +#endif +#endif /* !defined(__ASSEMBLER__) */ + +/* ------------------------------------------ + * MBR (Master Boot Record) -- + * definitions for systems that use MBRs + */ + +/* + * Layout of boot records: + * + * Byte range Use Description + * ---------- --- ----------- + * + * 0 - 2 FMP JMP xxx, NOP + * 3 - 10 FP OEM Name + * + * 11 - 61 FMP FAT12/16 BPB + * Whilst not strictly necessary for MBR, + * GRUB reserves this area + * + * 11 - 89 P FAT32 BPB + * (are we ever going to boot off this?) + * + * + * 62 - 217 FMP Boot code + * + * 90 - 217 P FAT32 boot code + * + * 218 - 223 M Win95b/98/me "drive time" + * http://www.geocities.com/thestarman3/asm/mbr/95BMEMBR.htm#MYST + * only changed if all 6 bytes are 0 + * + * 224 - 436 FMP boot code (continued) + * + * 437 - 439 M WinNT/2K/XP MBR "boot language" + * http://www.geocities.com/thestarman3/asm/mbr/Win2kmbr.htm + * not needed by us + * + * 400 - 439 MP NetBSD: mbr_bootsel + * + * 424 - 439 M NetBSD: bootptn_guid (in GPT PMBR only) + * + * 440 - 443 M WinNT/2K/XP Drive Serial Number (NT DSN) + * http://www.geocities.com/thestarman3/asm/mbr/Win2kmbr.htm + * + * 444 - 445 FMP bootcode or unused + * NetBSD: mbr_bootsel_magic + * + * 446 - 509 M partition table + * + * 510 - 511 FMP magic number (0xAA55) + * + * Use: + * ---- + * F Floppy boot sector + * M Master Boot Record + * P Partition Boot record + * + */ + +/* + * MBR (Master Boot Record) + */ +#define MBR_BBSECTOR 0 /* MBR relative sector # */ +#define MBR_BPB_OFFSET 11 /* offsetof(mbr_sector, mbr_bpb) */ +#define MBR_BOOTCODE_OFFSET 90 /* offsetof(mbr_sector, mbr_bootcode) */ +#define MBR_BS_OFFSET 400 /* offsetof(mbr_sector, mbr_bootsel) */ +#define MBR_BS_OLD_OFFSET 404 /* where mbr_bootsel used to be */ +#define MBR_GPT_GUID_OFFSET 424 /* location of partition GUID to boot */ +#define MBR_GPT_GUID_DEFAULT /* default uninitialized GUID */ \ + {0xeee69d04,0x02f4,0x11e0,0x8f,0x5d,{0x00,0xe0,0x81,0x52,0x9a,0x6b}} +#define MBR_DSN_OFFSET 440 /* offsetof(mbr_sector, mbr_dsn) */ +#define MBR_BS_MAGIC_OFFSET 444 /* offsetof(mbr_sector, mbr_bootsel_magic) */ +#define MBR_PART_OFFSET 446 /* offsetof(mbr_sector, mbr_part[0]) */ +#define MBR_MAGIC_OFFSET 510 /* offsetof(mbr_sector, mbr_magic) */ +#define MBR_MAGIC 0xaa55 /* MBR magic number */ +#define MBR_BS_MAGIC 0xb5e1 /* mbr_bootsel magic number */ +#define MBR_PART_COUNT 4 /* Number of partitions in MBR */ +#define MBR_BS_PARTNAMESIZE 8 /* Size of name mbr_bootsel nametab */ + /* (excluding trailing NUL) */ + + /* values for mbr_partition.mbrp_flag */ +#define MBR_PFLAG_ACTIVE 0x80 /* The active partition */ + + /* values for mbr_partition.mbrp_type */ +#define MBR_PTYPE_UNUSED 0x00 /* Unused */ +#define MBR_PTYPE_FAT12 0x01 /* 12-bit FAT */ +#define MBR_PTYPE_XENIX_ROOT 0x02 /* XENIX / */ +#define MBR_PTYPE_XENIX_USR 0x03 /* XENIX /usr */ +#define MBR_PTYPE_FAT16S 0x04 /* 16-bit FAT, less than 32M */ +#define MBR_PTYPE_EXT 0x05 /* extended partition */ +#define MBR_PTYPE_FAT16B 0x06 /* 16-bit FAT, more than 32M */ +#define MBR_PTYPE_NTFS 0x07 /* OS/2 HPFS, NTFS, QNX2, Adv. UNIX */ +#define MBR_PTYPE_DELL 0x08 /* AIX or os, or etc. */ +#define MBR_PTYPE_AIX_BOOT 0x09 /* AIX boot partition or Coherent */ +#define MBR_PTYPE_OS2_BOOT 0x0a /* O/2 boot manager or Coherent swap */ +#define MBR_PTYPE_FAT32 0x0b /* 32-bit FAT */ +#define MBR_PTYPE_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */ +#define MBR_PTYPE_7XXX 0x0d /* 7XXX, LBA-mapped */ +#define MBR_PTYPE_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */ +#define MBR_PTYPE_EXT_LBA 0x0f /* extended partition, LBA-mapped */ +#define MBR_PTYPE_OPUS 0x10 /* OPUS */ +#define MBR_PTYPE_OS2_DOS12 0x11 /* OS/2 DOS 12-bit FAT */ +#define MBR_PTYPE_COMPAQ_DIAG 0x12 /* Compaq diagnostics */ +#define MBR_PTYPE_OS2_DOS16S 0x14 /* OS/2 DOS 16-bit FAT <32M */ +#define MBR_PTYPE_OS2_DOS16B 0x16 /* OS/2 DOS 16-bit FAT >=32M */ +#define MBR_PTYPE_OS2_IFS 0x17 /* OS/2 hidden IFS */ +#define MBR_PTYPE_AST_SWAP 0x18 /* AST Windows swapfile */ +#define MBR_PTYPE_WILLOWTECH 0x19 /* Willowtech Photon coS */ +#define MBR_PTYPE_HID_FAT32 0x1b /* hidden win95 fat 32 */ +#define MBR_PTYPE_HID_FAT32_LBA 0x1c /* hidden win95 fat 32 lba */ +#define MBR_PTYPE_HID_FAT16_LBA 0x1d /* hidden win95 fat 16 lba */ +#define MBR_PTYPE_WILLOWSOFT 0x20 /* Willowsoft OFS1 */ +#define MBR_PTYPE_RESERVED_x21 0x21 /* reserved */ +#define MBR_PTYPE_RESERVED_x23 0x23 /* reserved */ +#define MBR_PTYPE_RESERVED_x24 0x24 /* NEC DOS */ +#define MBR_PTYPE_RESERVED_x26 0x26 /* reserved */ +#define MBR_PTYPE_RESERVED_x31 0x31 /* reserved */ +#define MBR_PTYPE_NOS 0x32 /* Alien Internet Services NOS */ +#define MBR_PTYPE_RESERVED_x33 0x33 /* reserved */ +#define MBR_PTYPE_RESERVED_x34 0x34 /* reserved */ +#define MBR_PTYPE_OS2_JFS 0x35 /* JFS on OS2 */ +#define MBR_PTYPE_RESERVED_x36 0x36 /* reserved */ +#define MBR_PTYPE_THEOS 0x38 /* Theos */ +#define MBR_PTYPE_PLAN9 0x39 /* Plan 9, or Theos spanned */ +#define MBR_PTYPE_THEOS_4GB 0x3a /* Theos ver 4 4gb partition */ +#define MBR_PTYPE_THEOS_EXT 0x3b /* Theos ve 4 extended partition */ +#define MBR_PTYPE_PMRECOVERY 0x3c /* PartitionMagic recovery */ +#define MBR_PTYPE_HID_NETWARE 0x3d /* Hidden Netware */ +#define MBR_PTYPE_VENIX 0x40 /* VENIX 286 or LynxOS */ +#define MBR_PTYPE_PREP 0x41 /* PReP */ +#define MBR_PTYPE_DRDOS_LSWAP 0x42 /* linux swap sharing DRDOS disk */ +#define MBR_PTYPE_DRDOS_LINUX 0x43 /* linux sharing DRDOS disk */ +#define MBR_PTYPE_GOBACK 0x44 /* GoBack change utility */ +#define MBR_PTYPE_BOOT_US 0x45 /* Boot US Boot manager */ +#define MBR_PTYPE_EUMEL_x46 0x46 /* EUMEL/Elan or Ergos 3 */ +#define MBR_PTYPE_EUMEL_x47 0x47 /* EUMEL/Elan or Ergos 3 */ +#define MBR_PTYPE_EUMEL_x48 0x48 /* EUMEL/Elan or Ergos 3 */ +#define MBR_PTYPE_ALFS_THIN 0x4a /* ALFX/THIN filesystem for DOS */ +#define MBR_PTYPE_OBERON 0x4c /* Oberon partition */ +#define MBR_PTYPE_QNX4X 0x4d /* QNX4.x */ +#define MBR_PTYPE_QNX4X_2 0x4e /* QNX4.x 2nd part */ +#define MBR_PTYPE_QNX4X_3 0x4f /* QNX4.x 3rd part */ +#define MBR_PTYPE_DM 0x50 /* DM (disk manager) */ +#define MBR_PTYPE_DM6_AUX1 0x51 /* DM6 Aux1 (or Novell) */ +#define MBR_PTYPE_CPM 0x52 /* CP/M or Microport SysV/AT */ +#define MBR_PTYPE_DM6_AUX3 0x53 /* DM6 Aux3 */ +#define MBR_PTYPE_DM6_DDO 0x54 /* DM6 DDO */ +#define MBR_PTYPE_EZDRIVE 0x55 /* EZ-Drive (disk manager) */ +#define MBR_PTYPE_GOLDEN_BOW 0x56 /* Golden Bow (disk manager) */ +#define MBR_PTYPE_DRIVE_PRO 0x57 /* Drive PRO */ +#define MBR_PTYPE_PRIAM_EDISK 0x5c /* Priam Edisk (disk manager) */ +#define MBR_PTYPE_SPEEDSTOR 0x61 /* SpeedStor */ +#define MBR_PTYPE_HURD 0x63 /* GNU HURD or Mach or Sys V/386 */ +#define MBR_PTYPE_NOVELL_2XX 0x64 /* Novell Netware 2.xx or Speedstore */ +#define MBR_PTYPE_NOVELL_3XX 0x65 /* Novell Netware 3.xx */ +#define MBR_PTYPE_NOVELL_386 0x66 /* Novell 386 Netware */ +#define MBR_PTYPE_NOVELL_x67 0x67 /* Novell */ +#define MBR_PTYPE_NOVELL_x68 0x68 /* Novell */ +#define MBR_PTYPE_NOVELL_x69 0x69 /* Novell */ +#define MBR_PTYPE_DISKSECURE 0x70 /* DiskSecure Multi-Boot */ +#define MBR_PTYPE_RESERVED_x71 0x71 /* reserved */ +#define MBR_PTYPE_RESERVED_x73 0x73 /* reserved */ +#define MBR_PTYPE_RESERVED_x74 0x74 /* reserved */ +#define MBR_PTYPE_PCIX 0x75 /* PC/IX */ +#define MBR_PTYPE_RESERVED_x76 0x76 /* reserved */ +#define MBR_PTYPE_M2FS_M2CS 0x77 /* M2FS/M2CS partition */ +#define MBR_PTYPE_XOSL_FS 0x78 /* XOSL boot loader filesystem */ +#define MBR_PTYPE_MINIX_14A 0x80 /* MINIX until 1.4a */ +#define MBR_PTYPE_MINIX_14B 0x81 /* MINIX since 1.4b */ +#define MBR_PTYPE_LNXSWAP 0x82 /* Linux swap or Solaris */ +#define MBR_PTYPE_LNXEXT2 0x83 /* Linux native */ +#define MBR_PTYPE_OS2_C 0x84 /* OS/2 hidden C: drive */ +#define MBR_PTYPE_EXT_LNX 0x85 /* Linux extended partition */ +#define MBR_PTYPE_NTFATVOL 0x86 /* NT FAT volume set */ +#define MBR_PTYPE_NTFSVOL 0x87 /* NTFS volume set or HPFS mirrored */ +#define MBR_PTYPE_LNX_KERNEL 0x8a /* Linux Kernel AiR-BOOT partition */ +#define MBR_PTYPE_FT_FAT32 0x8b /* Legacy Fault tolerant FAT32 */ +#define MBR_PTYPE_FT_FAT32_EXT 0x8c /* Legacy Fault tolerant FAT32 ext */ +#define MBR_PTYPE_HID_FR_FD_12 0x8d /* Hidden free FDISK FAT12 */ +#define MBR_PTYPE_LNX_LVM 0x8e /* Linux Logical Volume Manager */ +#define MBR_PTYPE_HID_FR_FD_16 0x90 /* Hidden free FDISK FAT16 */ +#define MBR_PTYPE_HID_FR_FD_EXT 0x91 /* Hidden free FDISK DOS EXT */ +#define MBR_PTYPE_HID_FR_FD_16B 0x92 /* Hidden free FDISK FAT16 Big */ +#define MBR_PTYPE_AMOEBA_FS 0x93 /* Amoeba filesystem */ +#define MBR_PTYPE_AMOEBA_BAD 0x94 /* Amoeba bad block table */ +#define MBR_PTYPE_MIT_EXOPC 0x95 /* MIT EXOPC native partitions */ +#define MBR_PTYPE_HID_FR_FD_32 0x97 /* Hidden free FDISK FAT32 */ +#define MBR_PTYPE_DATALIGHT 0x98 /* Datalight ROM-DOS Super-Boot */ +#define MBR_PTYPE_MYLEX 0x99 /* Mylex EISA SCSI */ +#define MBR_PTYPE_HID_FR_FD_16L 0x9a /* Hidden free FDISK FAT16 LBA */ +#define MBR_PTYPE_HID_FR_FD_EXL 0x9b /* Hidden free FDISK EXT LBA */ +#define MBR_PTYPE_BSDI 0x9f /* BSDI? */ +#define MBR_PTYPE_IBM_HIB 0xa0 /* IBM Thinkpad hibernation */ +#define MBR_PTYPE_HP_VOL_xA1 0xa1 /* HP Volume expansion (SpeedStor) */ +#define MBR_PTYPE_HP_VOL_xA3 0xa3 /* HP Volume expansion (SpeedStor) */ +#define MBR_PTYPE_HP_VOL_xA4 0xa4 /* HP Volume expansion (SpeedStor) */ +#define MBR_PTYPE_386BSD 0xa5 /* 386BSD partition type */ +#define MBR_PTYPE_OPENBSD 0xa6 /* OpenBSD partition type */ +#define MBR_PTYPE_NEXTSTEP_486 0xa7 /* NeXTSTEP 486 */ +#define MBR_PTYPE_APPLE_UFS 0xa8 /* Apple UFS */ +#define MBR_PTYPE_NETBSD 0xa9 /* NetBSD partition type */ +#define MBR_PTYPE_OLIVETTI 0xaa /* Olivetty Fat12 1.44MB Service part */ +#define MBR_PTYPE_APPLE_BOOT 0xab /* Apple Boot */ +#define MBR_PTYPE_SHAG_OS 0xae /* SHAG OS filesystem */ +#define MBR_PTYPE_APPLE_HFS 0xaf /* Apple HFS */ +#define MBR_PTYPE_BOOTSTAR_DUM 0xb0 /* BootStar Dummy */ +#define MBR_PTYPE_RESERVED_xB1 0xb1 /* reserved */ +#define MBR_PTYPE_RESERVED_xB3 0xb3 /* reserved */ +#define MBR_PTYPE_RESERVED_xB4 0xb4 /* reserved */ +#define MBR_PTYPE_RESERVED_xB6 0xb6 /* reserved */ +#define MBR_PTYPE_BSDI_386 0xb7 /* BSDI BSD/386 filesystem */ +#define MBR_PTYPE_BSDI_SWAP 0xb8 /* BSDI BSD/386 swap */ +#define MBR_PTYPE_BOOT_WIZARD 0xbb /* Boot Wizard Hidden */ +#define MBR_PTYPE_SOLARIS_8 0xbe /* Solaris 8 partition type */ +#define MBR_PTYPE_SOLARIS 0xbf /* Solaris partition type */ +#define MBR_PTYPE_CTOS 0xc0 /* CTOS */ +#define MBR_PTYPE_DRDOS_FAT12 0xc1 /* DRDOS/sec (FAT-12) */ +#define MBR_PTYPE_HID_LNX 0xc2 /* Hidden Linux */ +#define MBR_PTYPE_HID_LNX_SWAP 0xc3 /* Hidden Linux swap */ +#define MBR_PTYPE_DRDOS_FAT16S 0xc4 /* DRDOS/sec (FAT-16, < 32M) */ +#define MBR_PTYPE_DRDOS_EXT 0xc5 /* DRDOS/sec (EXT) */ +#define MBR_PTYPE_DRDOS_FAT16B 0xc6 /* DRDOS/sec (FAT-16, >= 32M) */ +#define MBR_PTYPE_SYRINX 0xc7 /* Syrinx (Cyrnix?) or HPFS disabled */ +#define MBR_PTYPE_DRDOS_8_xC8 0xc8 /* Reserved for DR-DOS 8.0+ */ +#define MBR_PTYPE_DRDOS_8_xC9 0xc9 /* Reserved for DR-DOS 8.0+ */ +#define MBR_PTYPE_DRDOS_8_xCA 0xca /* Reserved for DR-DOS 8.0+ */ +#define MBR_PTYPE_DRDOS_74_CHS 0xcb /* DR-DOS 7.04+ Secured FAT32 CHS */ +#define MBR_PTYPE_DRDOS_74_LBA 0xcc /* DR-DOS 7.04+ Secured FAT32 LBA */ +#define MBR_PTYPE_CTOS_MEMDUMP 0xcd /* CTOS Memdump */ +#define MBR_PTYPE_DRDOS_74_16X 0xce /* DR-DOS 7.04+ FAT16X LBA */ +#define MBR_PTYPE_DRDOS_74_EXT 0xcf /* DR-DOS 7.04+ EXT LBA */ +#define MBR_PTYPE_REAL32 0xd0 /* REAL/32 secure big partition */ +#define MBR_PTYPE_MDOS_FAT12 0xd1 /* Old Multiuser DOS FAT12 */ +#define MBR_PTYPE_MDOS_FAT16S 0xd4 /* Old Multiuser DOS FAT16 Small */ +#define MBR_PTYPE_MDOS_EXT 0xd5 /* Old Multiuser DOS Extended */ +#define MBR_PTYPE_MDOS_FAT16B 0xd6 /* Old Multiuser DOS FAT16 Big */ +#define MBR_PTYPE_CPM_86 0xd8 /* CP/M 86 */ +#define MBR_PTYPE_CONCURRENT 0xdb /* CP/M or Concurrent CP/M */ +#define MBR_PTYPE_HID_CTOS_MEM 0xdd /* Hidden CTOS Memdump */ +#define MBR_PTYPE_DELL_UTIL 0xde /* Dell PowerEdge Server utilities */ +#define MBR_PTYPE_DGUX_VIRTUAL 0xdf /* DG/UX virtual disk manager */ +#define MBR_PTYPE_STMICROELEC 0xe0 /* STMicroelectronics ST AVFS */ +#define MBR_PTYPE_DOS_ACCESS 0xe1 /* DOS access or SpeedStor 12-bit */ +#define MBR_PTYPE_STORDIM 0xe3 /* DOS R/O or Storage Dimensions */ +#define MBR_PTYPE_SPEEDSTOR_16S 0xe4 /* SpeedStor 16-bit FAT < 1024 cyl. */ +#define MBR_PTYPE_RESERVED_xE5 0xe5 /* reserved */ +#define MBR_PTYPE_RESERVED_xE6 0xe6 /* reserved */ +#define MBR_PTYPE_BEOS 0xeb /* BeOS */ +#define MBR_PTYPE_PMBR 0xee /* GPT Protective MBR */ +#define MBR_PTYPE_EFI 0xef /* EFI system partition */ +#define MBR_PTYPE_LNX_PA_RISC 0xf0 /* Linux PA-RISC boot loader */ +#define MBR_PTYPE_SPEEDSTOR_X 0xf1 /* SpeedStor or Storage Dimensions */ +#define MBR_PTYPE_DOS33_SEC 0xf2 /* DOS 3.3+ Secondary */ +#define MBR_PTYPE_RESERVED_xF3 0xf3 /* reserved */ +#define MBR_PTYPE_SPEEDSTOR_L 0xf4 /* SpeedStor large partition */ +#define MBR_PTYPE_PROLOGUE 0xf5 /* Prologue multi-volumen partition */ +#define MBR_PTYPE_RESERVED_xF6 0xf6 /* reserved */ +#define MBR_PTYPE_PCACHE 0xf9 /* pCache: ext2/ext3 persistent cache */ +#define MBR_PTYPE_BOCHS 0xfa /* Bochs x86 emulator */ +#define MBR_PTYPE_VMWARE 0xfb /* VMware File System */ +#define MBR_PTYPE_VMWARE_SWAP 0xfc /* VMware Swap */ +#define MBR_PTYPE_LNX_RAID 0xfd /* Linux RAID partition persistent sb */ +#define MBR_PTYPE_LANSTEP 0xfe /* LANstep or IBM PS/2 IML */ +#define MBR_PTYPE_XENIX_BAD 0xff /* Xenix Bad Block Table */ + +#ifdef MBRPTYPENAMES +static const struct mbr_ptype { + int id; + const char *name; +} mbr_ptypes[] = { + { MBR_PTYPE_UNUSED, "" }, + { MBR_PTYPE_FAT12, "Primary DOS with 12 bit FAT" }, + { MBR_PTYPE_XENIX_ROOT, "XENIX / filesystem" }, + { MBR_PTYPE_XENIX_USR, "XENIX /usr filesystem" }, + { MBR_PTYPE_FAT16S, "Primary DOS with 16 bit FAT <32M" }, + { MBR_PTYPE_EXT, "Extended partition" }, + { MBR_PTYPE_FAT16B, "Primary 'big' DOS, 16-bit FAT (> 32MB)" }, + { MBR_PTYPE_NTFS, "NTFS, OS/2 HPFS, QNX2 or Advanced UNIX" }, + { MBR_PTYPE_DELL, "AIX filesystem or OS/2 (thru v1.3) or DELL " + "multiple drives or Commodore DOS or SplitDrive" }, + { MBR_PTYPE_AIX_BOOT, "AIX boot partition or Coherent" }, + { MBR_PTYPE_OS2_BOOT, "OS/2 Boot Manager or Coherent swap or OPUS" }, + { MBR_PTYPE_FAT32, "Primary DOS with 32 bit FAT" }, + { MBR_PTYPE_FAT32L, "Primary DOS with 32 bit FAT - LBA" }, + { MBR_PTYPE_7XXX, "Type 7??? - LBA" }, + { MBR_PTYPE_FAT16L, "DOS (16-bit FAT) - LBA" }, + { MBR_PTYPE_EXT_LBA, "Ext. partition - LBA" }, + { MBR_PTYPE_OPUS, "OPUS" }, + { MBR_PTYPE_OS2_DOS12, "OS/2 BM: hidden DOS 12-bit FAT" }, + { MBR_PTYPE_COMPAQ_DIAG, "Compaq diagnostics" }, + { MBR_PTYPE_OS2_DOS16S, "OS/2 BM: hidden DOS 16-bit FAT <32M " + "or Novell DOS 7.0 bug" }, + { MBR_PTYPE_OS2_DOS16B, "OS/2 BM: hidden DOS 16-bit FAT >=32M" }, + { MBR_PTYPE_OS2_IFS, "OS/2 BM: hidden IFS" }, + { MBR_PTYPE_AST_SWAP, "AST Windows swapfile" }, + { MBR_PTYPE_WILLOWTECH, "Willowtech Photon coS" }, + { MBR_PTYPE_HID_FAT32, "hidden Windows/95 FAT32" }, + { MBR_PTYPE_HID_FAT32_LBA, "hidden Windows/95 FAT32 LBA" }, + { MBR_PTYPE_HID_FAT16_LBA, "hidden Windows/95 FAT16 LBA" }, + { MBR_PTYPE_WILLOWSOFT, "Willowsoft OFS1" }, + { MBR_PTYPE_RESERVED_x21, "reserved" }, + { MBR_PTYPE_RESERVED_x23, "reserved" }, + { MBR_PTYPE_RESERVED_x24, "NEC DOS"}, + { MBR_PTYPE_RESERVED_x26, "reserved" }, + { MBR_PTYPE_RESERVED_x31, "reserved" }, + { MBR_PTYPE_NOS, "Alien Internet Services NOS" }, + { MBR_PTYPE_RESERVED_x33, "reserved" }, + { MBR_PTYPE_RESERVED_x34, "reserved" }, + { MBR_PTYPE_OS2_JFS, "JFS on OS2" }, + { MBR_PTYPE_RESERVED_x36, "reserved" }, + { MBR_PTYPE_THEOS, "Theos" }, + { MBR_PTYPE_PLAN9, "Plan 9" }, + { MBR_PTYPE_PLAN9, "Plan 9, or Theos spanned" }, + { MBR_PTYPE_THEOS_4GB, "Theos ver 4 4gb partition" }, + { MBR_PTYPE_THEOS_EXT, "Theos ve 4 extended partition" }, + { MBR_PTYPE_PMRECOVERY, "PartitionMagic recovery" }, + { MBR_PTYPE_HID_NETWARE, "Hidden Netware" }, + { MBR_PTYPE_VENIX, "VENIX 286 or LynxOS" }, + { MBR_PTYPE_PREP, "Linux/MINIX (sharing disk with DRDOS) " + "or Personal RISC boot" }, + { MBR_PTYPE_DRDOS_LSWAP, "SFS or Linux swap " + "(sharing disk with DRDOS)" }, + { MBR_PTYPE_DRDOS_LINUX, "Linux native (sharing disk with DRDOS)" }, + { MBR_PTYPE_GOBACK, "GoBack change utility" }, + { MBR_PTYPE_BOOT_US, "Boot US Boot manager" }, + { MBR_PTYPE_EUMEL_x46, "EUMEL/Elan or Ergos 3" }, + { MBR_PTYPE_EUMEL_x47, "EUMEL/Elan or Ergos 3" }, + { MBR_PTYPE_EUMEL_x48, "EUMEL/Elan or Ergos 3" }, + { MBR_PTYPE_ALFS_THIN, "ALFX/THIN filesystem for DOS" }, + { MBR_PTYPE_OBERON, "Oberon partition" }, + { MBR_PTYPE_QNX4X, "QNX4.x" }, + { MBR_PTYPE_QNX4X_2, "QNX4.x 2nd part" }, + { MBR_PTYPE_QNX4X_3, "QNX4.x 3rd part" }, + { MBR_PTYPE_DM, "DM (disk manager)" }, + { MBR_PTYPE_DM6_AUX1, "DM6 Aux1 (or Novell)" }, + { MBR_PTYPE_CPM, "CP/M or Microport SysV/AT" }, + { MBR_PTYPE_DM6_AUX3, "DM6 Aux3" }, + { MBR_PTYPE_DM6_DDO, "DM6 DDO" }, + { MBR_PTYPE_EZDRIVE, "EZ-Drive (disk manager)" }, + { MBR_PTYPE_GOLDEN_BOW, "Golden Bow (disk manager)" }, + { MBR_PTYPE_DRIVE_PRO, "Drive PRO" }, + { MBR_PTYPE_PRIAM_EDISK, "Priam Edisk (disk manager)" }, + { MBR_PTYPE_SPEEDSTOR, "SpeedStor" }, + { MBR_PTYPE_HURD, "GNU HURD or Mach or Sys V/386 " + "(such as ISC UNIX) or MtXinu" }, + { MBR_PTYPE_NOVELL_2XX, "Novell Netware 2.xx or Speedstore" }, + { MBR_PTYPE_NOVELL_3XX, "Novell Netware 3.xx" }, + { MBR_PTYPE_NOVELL_386, "Novell 386 Netware" }, + { MBR_PTYPE_NOVELL_x67, "Novell" }, + { MBR_PTYPE_NOVELL_x68, "Novell" }, + { MBR_PTYPE_NOVELL_x69, "Novell" }, + { MBR_PTYPE_DISKSECURE, "DiskSecure Multi-Boot" }, + { MBR_PTYPE_RESERVED_x71, "reserved" }, + { MBR_PTYPE_RESERVED_x73, "reserved" }, + { MBR_PTYPE_RESERVED_x74, "reserved" }, + { MBR_PTYPE_PCIX, "PC/IX" }, + { MBR_PTYPE_RESERVED_x76, "reserved" }, + { MBR_PTYPE_M2FS_M2CS, "M2FS/M2CS partition" }, + { MBR_PTYPE_XOSL_FS, "XOSL boot loader filesystem" }, + { MBR_PTYPE_MINIX_14A, "MINIX until 1.4a" }, + { MBR_PTYPE_MINIX_14B, "MINIX since 1.4b, early Linux, Mitac dmgr" }, + { MBR_PTYPE_LNXSWAP, "Linux swap or Prime or Solaris" }, + { MBR_PTYPE_LNXEXT2, "Linux native" }, + { MBR_PTYPE_OS2_C, "OS/2 hidden C: drive" }, + { MBR_PTYPE_EXT_LNX, "Linux extended" }, + { MBR_PTYPE_NTFATVOL, "NT FAT volume set" }, + { MBR_PTYPE_NTFSVOL, "NTFS volume set or HPFS mirrored" }, + { MBR_PTYPE_LNX_KERNEL, "Linux Kernel AiR-BOOT partition" }, + { MBR_PTYPE_FT_FAT32, "Legacy Fault tolerant FAT32" }, + { MBR_PTYPE_FT_FAT32_EXT, "Legacy Fault tolerant FAT32 ext" }, + { MBR_PTYPE_HID_FR_FD_12, "Hidden free FDISK FAT12" }, + { MBR_PTYPE_LNX_LVM, "Linux Logical Volume Manager" }, + { MBR_PTYPE_HID_FR_FD_16, "Hidden free FDISK FAT16" }, + { MBR_PTYPE_HID_FR_FD_EXT, "Hidden free FDISK DOS EXT" }, + { MBR_PTYPE_HID_FR_FD_16L, "Hidden free FDISK FAT16 Large" }, + { MBR_PTYPE_AMOEBA_FS, "Amoeba filesystem" }, + { MBR_PTYPE_AMOEBA_BAD, "Amoeba bad block table" }, + { MBR_PTYPE_MIT_EXOPC, "MIT EXOPC native partitions" }, + { MBR_PTYPE_HID_FR_FD_32, "Hidden free FDISK FAT32" }, + { MBR_PTYPE_DATALIGHT, "Datalight ROM-DOS Super-Boot" }, + { MBR_PTYPE_MYLEX, "Mylex EISA SCSI" }, + { MBR_PTYPE_HID_FR_FD_16L, "Hidden free FDISK FAT16 LBA" }, + { MBR_PTYPE_HID_FR_FD_EXL, "Hidden free FDISK EXT LBA" }, + { MBR_PTYPE_BSDI, "BSDI?" }, + { MBR_PTYPE_IBM_HIB, "IBM Thinkpad hibernation" }, + { MBR_PTYPE_HP_VOL_xA1, "HP Volume expansion (SpeedStor)" }, + { MBR_PTYPE_HP_VOL_xA3, "HP Volume expansion (SpeedStor)" }, + { MBR_PTYPE_HP_VOL_xA4, "HP Volume expansion (SpeedStor)" }, + { MBR_PTYPE_386BSD, "FreeBSD or 386BSD or old NetBSD" }, + { MBR_PTYPE_OPENBSD, "OpenBSD" }, + { MBR_PTYPE_NEXTSTEP_486, "NeXTSTEP 486" }, + { MBR_PTYPE_APPLE_UFS, "Apple UFS" }, + { MBR_PTYPE_NETBSD, "NetBSD" }, + { MBR_PTYPE_OLIVETTI, "Olivetty Fat12 1.44MB Service part" }, + { MBR_PTYPE_SHAG_OS, "SHAG OS filesystem" }, + { MBR_PTYPE_BOOTSTAR_DUM, "BootStar Dummy" }, + { MBR_PTYPE_BOOT_WIZARD, "Boot Wizard Hidden" }, + { MBR_PTYPE_APPLE_BOOT, "Apple Boot" }, + { MBR_PTYPE_APPLE_HFS, "Apple HFS" }, + { MBR_PTYPE_RESERVED_xB6, "reserved" }, + { MBR_PTYPE_RESERVED_xB6, "reserved" }, + { MBR_PTYPE_RESERVED_xB6, "reserved" }, + { MBR_PTYPE_RESERVED_xB6, "reserved" }, + { MBR_PTYPE_BSDI_386, "BSDI BSD/386 filesystem" }, + { MBR_PTYPE_BSDI_SWAP, "BSDI BSD/386 swap" }, + { MBR_PTYPE_SOLARIS_8, "Solaris 8 boot partition" }, + { MBR_PTYPE_SOLARIS, "Solaris boot partition" }, + { MBR_PTYPE_CTOS, "CTOS" }, + { MBR_PTYPE_DRDOS_FAT12, "DRDOS/sec (FAT-12)" }, + { MBR_PTYPE_HID_LNX, "Hidden Linux" }, + { MBR_PTYPE_HID_LNX_SWAP, "Hidden Linux Swap" }, + { MBR_PTYPE_DRDOS_FAT16S, "DRDOS/sec (FAT-16, < 32M)" }, + { MBR_PTYPE_DRDOS_EXT, "DRDOS/sec (EXT)" }, + { MBR_PTYPE_DRDOS_FAT16B, "DRDOS/sec (FAT-16, >= 32M)" }, + { MBR_PTYPE_SYRINX, "Syrinx (Cyrnix?) or HPFS disabled" }, + { MBR_PTYPE_DRDOS_8_xC8, "Reserved for DR-DOS 8.0+" }, + { MBR_PTYPE_DRDOS_8_xC9, "Reserved for DR-DOS 8.0+" }, + { MBR_PTYPE_DRDOS_8_xCA, "Reserved for DR-DOS 8.0+" }, + { MBR_PTYPE_DRDOS_74_CHS, "DR-DOS 7.04+ Secured FAT32 CHS" }, + { MBR_PTYPE_DRDOS_74_LBA, "DR-DOS 7.04+ Secured FAT32 LBA" }, + { MBR_PTYPE_CTOS_MEMDUMP, "CTOS Memdump" }, + { MBR_PTYPE_DRDOS_74_16X, "DR-DOS 7.04+ FAT16X LBA" }, + { MBR_PTYPE_DRDOS_74_EXT, "DR-DOS 7.04+ EXT LBA" }, + { MBR_PTYPE_REAL32, "REAL/32 secure big partition" }, + { MBR_PTYPE_MDOS_FAT12, "Old Multiuser DOS FAT12" }, + { MBR_PTYPE_MDOS_FAT16S, "Old Multiuser DOS FAT16 Small" }, + { MBR_PTYPE_MDOS_EXT, "Old Multiuser DOS Extended" }, + { MBR_PTYPE_MDOS_FAT16B, "Old Multiuser DOS FAT16 Big" }, + { MBR_PTYPE_CPM_86, "CP/M 86" }, + { MBR_PTYPE_CONCURRENT, "CP/M or Concurrent CP/M or Concurrent DOS " + "or CTOS" }, + { MBR_PTYPE_HID_CTOS_MEM, "Hidden CTOS Memdump" }, + { MBR_PTYPE_DELL_UTIL, "Dell PowerEdge Server utilities" }, + { MBR_PTYPE_DGUX_VIRTUAL, "DG/UX virtual disk manager" }, + { MBR_PTYPE_STMICROELEC, "STMicroelectronics ST AVFS" }, + { MBR_PTYPE_DOS_ACCESS, "DOS access or SpeedStor 12-bit FAT " + "extended partition" }, + { MBR_PTYPE_STORDIM, "DOS R/O or SpeedStor or Storage Dimensions" }, + { MBR_PTYPE_SPEEDSTOR_16S, "SpeedStor 16-bit FAT extended partition " + "< 1024 cyl." }, + { MBR_PTYPE_RESERVED_xE5, "reserved" }, + { MBR_PTYPE_RESERVED_xE6, "reserved" }, + { MBR_PTYPE_BEOS, "BeOS" }, + { MBR_PTYPE_PMBR, "GPT Protective MBR" }, + { MBR_PTYPE_EFI, "EFI system partition" }, + { MBR_PTYPE_LNX_PA_RISC, "Linux PA-RISC boot loader" }, + { MBR_PTYPE_SPEEDSTOR_X, "SpeedStor or Storage Dimensions" }, + { MBR_PTYPE_DOS33_SEC, "DOS 3.3+ Secondary" }, + { MBR_PTYPE_RESERVED_xF3, "reserved" }, + { MBR_PTYPE_SPEEDSTOR_L, "SpeedStor large partition or " + "Storage Dimensions" }, + { MBR_PTYPE_PROLOGUE, "Prologue multi-volumen partition" }, + { MBR_PTYPE_RESERVED_xF6, "reserved" }, + { MBR_PTYPE_PCACHE, "pCache: ext2/ext3 persistent cache" }, + { MBR_PTYPE_BOCHS, "Bochs x86 emulator" }, + { MBR_PTYPE_VMWARE, "VMware File System" }, + { MBR_PTYPE_VMWARE_SWAP, "VMware Swap" }, + { MBR_PTYPE_LNX_RAID, "Linux RAID partition persistent sb" }, + { MBR_PTYPE_LANSTEP, "SpeedStor >1024 cyl. or LANstep " + "or IBM PS/2 IML" }, + { MBR_PTYPE_XENIX_BAD, "Xenix Bad Block Table" }, +}; +#endif + +#define MBR_PSECT(s) ((s) & 0x3f) +#define MBR_PCYL(c, s) ((c) + (((s) & 0xc0) << 2)) + +#define MBR_IS_EXTENDED(x) ((x) == MBR_PTYPE_EXT || \ + (x) == MBR_PTYPE_EXT_LBA || \ + (x) == MBR_PTYPE_EXT_LNX) + + /* values for mbr_bootsel.mbrbs_flags */ +#define MBR_BS_ACTIVE 0x01 /* Bootselector active (or code present) */ +#define MBR_BS_EXTINT13 0x02 /* Set by fdisk if LBA needed (deprecated) */ +#define MBR_BS_READ_LBA 0x04 /* Force LBA reads (deprecated) */ +#define MBR_BS_EXTLBA 0x08 /* Extended ptn capable (LBA reads) */ +#define MBR_BS_ASCII 0x10 /* Bootselect code needs ascii key code */ +/* This is always set, the bootsel is located using the magic number... */ +#define MBR_BS_NEWMBR 0x80 /* New bootsel at offset 440 */ + +#if !defined(__ASSEMBLER__) /* { */ + +/* + * (x86) BIOS Parameter Block for FAT12 + */ +struct mbr_bpbFAT12 { + uint16_t bpbBytesPerSec; /* bytes per sector */ + uint8_t bpbSecPerClust; /* sectors per cluster */ + uint16_t bpbResSectors; /* number of reserved sectors */ + uint8_t bpbFATs; /* number of FATs */ + uint16_t bpbRootDirEnts; /* number of root directory entries */ + uint16_t bpbSectors; /* total number of sectors */ + uint8_t bpbMedia; /* media descriptor */ + uint16_t bpbFATsecs; /* number of sectors per FAT */ + uint16_t bpbSecPerTrack; /* sectors per track */ + uint16_t bpbHeads; /* number of heads */ + uint16_t bpbHiddenSecs; /* # of hidden sectors */ +} __packed; + +/* + * (x86) BIOS Parameter Block for FAT16 + */ +struct mbr_bpbFAT16 { + uint16_t bpbBytesPerSec; /* bytes per sector */ + uint8_t bpbSecPerClust; /* sectors per cluster */ + uint16_t bpbResSectors; /* number of reserved sectors */ + uint8_t bpbFATs; /* number of FATs */ + uint16_t bpbRootDirEnts; /* number of root directory entries */ + uint16_t bpbSectors; /* total number of sectors */ + uint8_t bpbMedia; /* media descriptor */ + uint16_t bpbFATsecs; /* number of sectors per FAT */ + uint16_t bpbSecPerTrack; /* sectors per track */ + uint16_t bpbHeads; /* number of heads */ + uint32_t bpbHiddenSecs; /* # of hidden sectors */ + uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ + uint8_t bsDrvNum; /* Int 0x13 drive number (e.g. 0x80) */ + uint8_t bsReserved1; /* Reserved; set to 0 */ + uint8_t bsBootSig; /* 0x29 if next 3 fields are present */ + uint8_t bsVolID[4]; /* Volume serial number */ + uint8_t bsVolLab[11]; /* Volume label */ + uint8_t bsFileSysType[8]; + /* "FAT12 ", "FAT16 ", "FAT " */ +} __packed; + +/* + * (x86) BIOS Parameter Block for FAT32 + */ +struct mbr_bpbFAT32 { + uint16_t bpbBytesPerSec; /* bytes per sector */ + uint8_t bpbSecPerClust; /* sectors per cluster */ + uint16_t bpbResSectors; /* number of reserved sectors */ + uint8_t bpbFATs; /* number of FATs */ + uint16_t bpbRootDirEnts; /* number of root directory entries */ + uint16_t bpbSectors; /* total number of sectors */ + uint8_t bpbMedia; /* media descriptor */ + uint16_t bpbFATsecs; /* number of sectors per FAT */ + uint16_t bpbSecPerTrack; /* sectors per track */ + uint16_t bpbHeads; /* number of heads */ + uint32_t bpbHiddenSecs; /* # of hidden sectors */ + uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ + uint32_t bpbBigFATsecs; /* like bpbFATsecs for FAT32 */ + uint16_t bpbExtFlags; /* extended flags: */ +#define MBR_FAT32_FATNUM 0x0F /* mask for numbering active FAT */ +#define MBR_FAT32_FATMIRROR 0x80 /* FAT is mirrored (as previously) */ + uint16_t bpbFSVers; /* filesystem version */ +#define MBR_FAT32_FSVERS 0 /* currently only 0 is understood */ + uint32_t bpbRootClust; /* start cluster for root directory */ + uint16_t bpbFSInfo; /* filesystem info structure sector */ + uint16_t bpbBackup; /* backup boot sector */ + uint8_t bsReserved[12]; /* Reserved for future expansion */ + uint8_t bsDrvNum; /* Int 0x13 drive number (e.g. 0x80) */ + uint8_t bsReserved1; /* Reserved; set to 0 */ + uint8_t bsBootSig; /* 0x29 if next 3 fields are present */ + uint8_t bsVolID[4]; /* Volume serial number */ + uint8_t bsVolLab[11]; /* Volume label */ + uint8_t bsFileSysType[8]; /* "FAT32 " */ +} __packed; + +/* + * (x86) MBR boot selector + */ +struct mbr_bootsel { + uint8_t mbrbs_defkey; + uint8_t mbrbs_flags; + uint16_t mbrbs_timeo; + char mbrbs_nametab[MBR_PART_COUNT][MBR_BS_PARTNAMESIZE + 1]; +} __packed; + +/* + * MBR partition + */ +struct mbr_partition { + uint8_t mbrp_flag; /* MBR partition flags */ + uint8_t mbrp_shd; /* Starting head */ + uint8_t mbrp_ssect; /* Starting sector */ + uint8_t mbrp_scyl; /* Starting cylinder */ + uint8_t mbrp_type; /* Partition type (see below) */ + uint8_t mbrp_ehd; /* End head */ + uint8_t mbrp_esect; /* End sector */ + uint8_t mbrp_ecyl; /* End cylinder */ + uint32_t mbrp_start; /* Absolute starting sector number */ + uint32_t mbrp_size; /* Partition size in sectors */ +} __packed; + +int xlat_mbr_fstype(int); /* in sys/lib/libkern/xlat_mbr_fstype.c */ + +/* + * MBR boot sector. + * This is used by both the MBR (Master Boot Record) in sector 0 of the disk + * and the PBR (Partition Boot Record) in sector 0 of an MBR partition. + */ +struct mbr_sector { + /* Jump instruction to boot code. */ + /* Usually 0xE9nnnn or 0xEBnn90 */ + uint8_t mbr_jmpboot[3]; + /* OEM name and version */ + uint8_t mbr_oemname[8]; + union { /* BIOS Parameter Block */ + struct mbr_bpbFAT12 bpb12; + struct mbr_bpbFAT16 bpb16; + struct mbr_bpbFAT32 bpb32; + } mbr_bpb; + /* Boot code */ + uint8_t mbr_bootcode[310]; + /* Config for /usr/mdec/mbr_bootsel */ + struct mbr_bootsel mbr_bootsel; + /* NT Drive Serial Number */ + uint32_t mbr_dsn; + /* mbr_bootsel magic */ + uint16_t mbr_bootsel_magic; + /* MBR partition table */ + struct mbr_partition mbr_parts[MBR_PART_COUNT]; + /* MBR magic (0xaa55) */ + uint16_t mbr_magic; +} __packed; + +#endif /* !defined(__ASSEMBLER__) */ /* } */ + + +/* ------------------------------------------ + * shared -- + * definitions shared by many platforms + */ + +#if !defined(__ASSEMBLER__) /* { */ + + /* Maximum # of blocks in bbi_block_table, each bbi_block_size long */ +#define SHARED_BBINFO_MAXBLOCKS 118 /* so sizeof(shared_bbinfo) == 512 */ + +struct shared_bbinfo { + uint8_t bbi_magic[32]; + int32_t bbi_block_size; + int32_t bbi_block_count; + int32_t bbi_block_table[SHARED_BBINFO_MAXBLOCKS]; +}; + +/* ------------------------------------------ + * alpha -- + * Alpha (disk, but also tape) Boot Block. + * + * See Section (III) 3.6.1 of the Alpha Architecture Reference Manual. + */ + +struct alpha_boot_block { + uint64_t bb_data[63]; /* data (disklabel, also as below) */ + uint64_t bb_cksum; /* checksum of the boot block, + * taken as uint64_t's + */ +}; +#define bb_secsize bb_data[60] /* secondary size (blocks) */ +#define bb_secstart bb_data[61] /* secondary start (blocks) */ +#define bb_flags bb_data[62] /* unknown flags (set to zero) */ + +#define ALPHA_BOOT_BLOCK_OFFSET 0 /* offset of boot block. */ +#define ALPHA_BOOT_BLOCK_BLOCKSIZE 512 /* block size for sector + * size/start, and for boot + * block itself. + */ + +#define ALPHA_BOOT_BLOCK_CKSUM(bb,cksum) \ + do { \ + const struct alpha_boot_block *_bb = (bb); \ + uint64_t _cksum; \ + size_t _i; \ + \ + _cksum = 0; \ + for (_i = 0; \ + _i < (sizeof _bb->bb_data / sizeof _bb->bb_data[0]); \ + _i++) \ + _cksum += le64toh(_bb->bb_data[_i]); \ + *(cksum) = htole64(_cksum); \ + } while (/*CONSTCOND*/ 0) + +/* ------------------------------------------ + * apple -- + * Apple computers boot block related information + */ + +/* + * Driver Descriptor Map, from Inside Macintosh: Devices, SCSI Manager + * pp 12-13. The driver descriptor map always resides on physical block 0. + */ +struct apple_drvr_descriptor { + uint32_t descBlock; /* first block of driver */ + uint16_t descSize; /* driver size in blocks */ + uint16_t descType; /* system type */ +}; + +/* + * system types; Apple reserves 0-15 + */ +#define APPLE_DRVR_TYPE_MACINTOSH 1 + +#define APPLE_DRVR_MAP_MAGIC 0x4552 +#define APPLE_DRVR_MAP_MAX_DESCRIPTORS 61 + +struct apple_drvr_map { + uint16_t sbSig; /* map signature */ + uint16_t sbBlockSize; /* block size of device */ + uint32_t sbBlkCount; /* number of blocks on device */ + uint16_t sbDevType; /* (used internally by ROM) */ + uint16_t sbDevID; /* (used internally by ROM) */ + uint32_t sbData; /* (used internally by ROM) */ + uint16_t sbDrvrCount; /* number of driver descriptors */ + struct apple_drvr_descriptor sb_dd[APPLE_DRVR_MAP_MAX_DESCRIPTORS]; + uint16_t pad[3]; +} __packed; + +/* + * Partition map structure from Inside Macintosh: Devices, SCSI Manager + * pp. 13-14. The partition map always begins on physical block 1. + * + * With the exception of block 0, all blocks on the disk must belong to + * exactly one partition. The partition map itself belongs to a partition + * of type `APPLE_PARTITION_MAP', and is not limited in size by anything + * other than available disk space. The partition map is not necessarily + * the first partition listed. + */ +#define APPLE_PART_MAP_ENTRY_MAGIC 0x504d + +struct apple_part_map_entry { + uint16_t pmSig; /* partition signature */ + uint16_t pmSigPad; /* (reserved) */ + uint32_t pmMapBlkCnt; /* number of blocks in partition map */ + uint32_t pmPyPartStart; /* first physical block of partition */ + uint32_t pmPartBlkCnt; /* number of blocks in partition */ + uint8_t pmPartName[32]; /* partition name */ + uint8_t pmPartType[32]; /* partition type */ + uint32_t pmLgDataStart; /* first logical block of data area */ + uint32_t pmDataCnt; /* number of blocks in data area */ + uint32_t pmPartStatus; /* partition status information */ + uint32_t pmLgBootStart; /* first logical block of boot code */ + uint32_t pmBootSize; /* size of boot code, in bytes */ + uint32_t pmBootLoad; /* boot code load address */ + uint32_t pmBootLoad2; /* (reserved) */ + uint32_t pmBootEntry; /* boot code entry point */ + uint32_t pmBootEntry2; /* (reserved) */ + uint32_t pmBootCksum; /* boot code checksum */ + int8_t pmProcessor[16]; /* processor type (e.g. "68020") */ + uint8_t pmBootArgs[128]; /* A/UX boot arguments */ + uint8_t pad[248]; /* pad to end of block */ +}; + +#define APPLE_PART_TYPE_DRIVER "APPLE_DRIVER" +#define APPLE_PART_TYPE_DRIVER43 "APPLE_DRIVER43" +#define APPLE_PART_TYPE_DRIVERATA "APPLE_DRIVER_ATA" +#define APPLE_PART_TYPE_DRIVERIOKIT "APPLE_DRIVER_IOKIT" +#define APPLE_PART_TYPE_FWDRIVER "APPLE_FWDRIVER" +#define APPLE_PART_TYPE_FWB_COMPONENT "FWB DRIVER COMPONENTS" +#define APPLE_PART_TYPE_FREE "APPLE_FREE" +#define APPLE_PART_TYPE_MAC "APPLE_HFS" +#define APPLE_PART_TYPE_NETBSD "NETBSD" +#define APPLE_PART_TYPE_NBSD_PPCBOOT "NETBSD/MACPPC" +#define APPLE_PART_TYPE_NBSD_68KBOOT "NETBSD/MAC68K" +#define APPLE_PART_TYPE_PATCHES "APPLE_PATCHES" +#define APPLE_PART_TYPE_PARTMAP "APPLE_PARTITION_MAP" +#define APPLE_PART_TYPE_PATCHES "APPLE_PATCHES" +#define APPLE_PART_TYPE_SCRATCH "APPLE_SCRATCH" +#define APPLE_PART_TYPE_UNIX "APPLE_UNIX_SVR2" + +/* + * "pmBootArgs" for APPLE_UNIX_SVR2 partition. + * NetBSD/mac68k only uses Magic, Cluster, Type, and Flags. + */ +struct apple_blockzeroblock { + uint32_t bzbMagic; + uint8_t bzbCluster; + uint8_t bzbType; + uint16_t bzbBadBlockInode; + uint16_t bzbFlags; + uint16_t bzbReserved; + uint32_t bzbCreationTime; + uint32_t bzbMountTime; + uint32_t bzbUMountTime; +}; + +#define APPLE_BZB_MAGIC 0xABADBABE +#define APPLE_BZB_TYPEFS 1 +#define APPLE_BZB_TYPESWAP 3 +#define APPLE_BZB_ROOTFS 0x8000 +#define APPLE_BZB_USRFS 0x4000 + +/* ------------------------------------------ + * ews4800mips + * + */ + +#define EWS4800MIPS_BBINFO_MAGIC "NetBSD/ews4800mips 20040611" +#define EWS4800MIPS_BOOT_BLOCK_OFFSET 0 +#define EWS4800MIPS_BOOT_BLOCK_BLOCKSIZE 512 +#define EWS4800MIPS_BOOT_BLOCK_MAX_SIZE (512 * 8) + +/* ------------------------------------------ + * hp300 + * + */ + +/* volume header for "LIF" format volumes */ + +struct hp300_lifvol { + int16_t vol_id; + char vol_label[6]; + int32_t vol_addr; + int16_t vol_oct; + int16_t vol_dummy; + int32_t vol_dirsize; + int16_t vol_version; + int16_t vol_zero; + int32_t vol_huh1; + int32_t vol_huh2; + int32_t vol_length; +}; + +/* LIF directory entry format */ + +struct hp300_lifdir { + char dir_name[10]; + int16_t dir_type; + int32_t dir_addr; + int32_t dir_length; + char dir_toc[6]; + int16_t dir_flag; + int32_t dir_exec; +}; + +/* load header for boot rom */ +struct hp300_load { + int32_t address; + int32_t count; +}; + +#define HP300_VOL_ID -32768 +#define HP300_VOL_OCT 4096 +#define HP300_DIR_TYPE -5822 +#define HP300_DIR_FLAG 0x8001 /* dont ask me! */ +#define HP300_SECTSIZE 256 + + +/* ------------------------------------------ + * hp700 + * + */ + +/* + * volume header for "LIF" format volumes + */ +struct hp700_lifvol { + uint16_t vol_id; + uint8_t vol_label[6]; + uint32_t vol_addr; + uint16_t vol_oct; + uint16_t vol_dummy; + + uint32_t vol_dirsize; + uint16_t vol_version; + uint16_t vol_zero; + uint32_t vol_number; + uint32_t vol_lastvol; + + uint32_t vol_length; + uint8_t vol_toc[6]; + uint8_t vol_dummy1[198]; + + uint32_t ipl_addr; + uint32_t ipl_size; + uint32_t ipl_entry; + + uint32_t vol_dummy2; +}; + +struct hp700_lifdir { + uint8_t dir_name[10]; + uint16_t dir_type; + uint32_t dir_addr; + uint32_t dir_length; + uint8_t dir_toc[6]; + uint16_t dir_flag; + uint32_t dir_implement; +}; + +struct hp700_lifload { + int address; + int count; +}; + +#define HP700_LIF_VOL_ID 0x8000 +#define HP700_LIF_VOL_OCT 0x1000 +#define HP700_LIF_DIR_SWAP 0x5243 +#define HP700_LIF_DIR_FS 0xcd38 +#define HP700_LIF_DIR_IOMAP 0xcd60 +#define HP700_LIF_DIR_HPUX 0xcd80 +#define HP700_LIF_DIR_ISL 0xce00 +#define HP700_LIF_DIR_PAD 0xcffe +#define HP700_LIF_DIR_AUTO 0xcfff +#define HP700_LIF_DIR_EST 0xd001 +#define HP700_LIF_DIR_TYPE 0xe942 + +#define HP700_LIF_DIR_FLAG 0x8001 /* dont ask me! */ +#define HP700_LIF_SECTSIZE 256 + +#define HP700_LIF_NUMDIR 8 + +#define HP700_LIF_VOLSTART 0 +#define HP700_LIF_VOLSIZE sizeof(struct hp700_lifvol) +#define HP700_LIF_DIRSTART 2048 +#define HP700_LIF_DIRSIZE (HP700_LIF_NUMDIR * sizeof(struct hp700_lifdir)) +#define HP700_LIF_FILESTART 4096 + +#define hp700_btolifs(b) (((b) + (HP700_LIF_SECTSIZE - 1)) / HP700_LIF_SECTSIZE) +#define hp700_lifstob(s) ((s) * HP700_LIF_SECTSIZE) +#define hp700_lifstodb(s) ((s) * HP700_LIF_SECTSIZE / DEV_BSIZE) + + +/* ------------------------------------------ + * x86 + * + */ + +/* + * Parameters for NetBSD /boot written to start of pbr code by installboot + */ + +struct x86_boot_params { + uint32_t bp_length; /* length of patchable data */ + uint32_t bp_flags; + uint32_t bp_timeout; /* boot timeout in seconds */ + uint32_t bp_consdev; + uint32_t bp_conspeed; + uint8_t bp_password[16]; /* md5 hash of password */ + char bp_keymap[64]; /* keyboard translation map */ + uint32_t bp_consaddr; /* ioaddr for console */ +}; + +#endif /* !defined(__ASSEMBLER__) */ /* } */ + +#define X86_BOOT_MAGIC(n) ('x' << 24 | 0x86b << 12 | 'm' << 4 | (n)) +#define X86_BOOT_MAGIC_1 X86_BOOT_MAGIC(1) /* pbr.S */ +#define X86_BOOT_MAGIC_2 X86_BOOT_MAGIC(2) /* bootxx.S */ +#define X86_BOOT_MAGIC_PXE X86_BOOT_MAGIC(3) /* start_pxe.S */ +#define X86_BOOT_MAGIC_FAT X86_BOOT_MAGIC(4) /* fatboot.S */ +#define X86_MBR_GPT_MAGIC 0xedb88320 /* gpt.S */ + + /* values for bp_flags */ +#define X86_BP_FLAGS_RESET_VIDEO 1 +#define X86_BP_FLAGS_PASSWORD 2 +#define X86_BP_FLAGS_NOMODULES 4 +#define X86_BP_FLAGS_NOBOOTCONF 8 +#define X86_BP_FLAGS_LBA64VALID 0x10 + + /* values for bp_consdev */ +#define X86_BP_CONSDEV_PC 0 +#define X86_BP_CONSDEV_COM0 1 +#define X86_BP_CONSDEV_COM1 2 +#define X86_BP_CONSDEV_COM2 3 +#define X86_BP_CONSDEV_COM3 4 +#define X86_BP_CONSDEV_COM0KBD 5 +#define X86_BP_CONSDEV_COM1KBD 6 +#define X86_BP_CONSDEV_COM2KBD 7 +#define X86_BP_CONSDEV_COM3KBD 8 + +/* ------------------------------------------ + * landisk + */ + +#if !defined(__ASSEMBLER__) /* { */ + +/* + * Parameters for NetBSD /boot written to start of pbr code by installboot + */ +struct landisk_boot_params { + uint32_t bp_length; /* length of patchable data */ + uint32_t bp_flags; + uint32_t bp_timeout; /* boot timeout in seconds */ + uint32_t bp_consdev; + uint32_t bp_conspeed; +}; + +#endif /* !defined(__ASSEMBLER__) */ /* } */ + +#define LANDISK_BOOT_MAGIC_1 0x20031125 +#define LANDISK_BOOT_MAGIC_2 0x20041110 + +#if !defined(__ASSEMBLER__) /* { */ + +/* ------------------------------------------ + * macppc + */ + +#define MACPPC_BOOT_BLOCK_OFFSET 2048 +#define MACPPC_BOOT_BLOCK_BLOCKSIZE 512 +#define MACPPC_BOOT_BLOCK_MAX_SIZE 2048 /* XXX: could be up to 6144 */ + /* Magic string -- 32 bytes long (including the NUL) */ +#define MACPPC_BBINFO_MAGIC "NetBSD/macppc bootxx 20020515" + +/* ------------------------------------------ + * news68k, newsmips + */ + +#define NEWS_BOOT_BLOCK_LABELOFFSET 64 /* XXX from */ +#define NEWS_BOOT_BLOCK_OFFSET 0 +#define NEWS_BOOT_BLOCK_BLOCKSIZE 512 +#define NEWS_BOOT_BLOCK_MAX_SIZE (512 * 16) + + /* Magic string -- 32 bytes long (including the NUL) */ +#define NEWS68K_BBINFO_MAGIC "NetBSD/news68k bootxx 20020518" +#define NEWSMIPS_BBINFO_MAGIC "NetBSD/newsmips bootxx 20020518" + +/* ------------------------------------------ + * next68k + */ + +#define NEXT68K_LABEL_MAXPARTITIONS 8 /* number of partitions in next68k_disklabel */ +#define NEXT68K_LABEL_CPULBLLEN 24 +#define NEXT68K_LABEL_MAXDNMLEN 24 +#define NEXT68K_LABEL_MAXTYPLEN 24 +#define NEXT68K_LABEL_MAXBFLEN 24 +#define NEXT68K_LABEL_MAXHNLEN 32 +#define NEXT68K_LABEL_MAXMPTLEN 16 +#define NEXT68K_LABEL_MAXFSTLEN 8 +#define NEXT68K_LABEL_NBAD 1670 /* sized to make label ~= 8KB */ + +struct next68k_partition { + int32_t cp_offset; /* starting sector */ + int32_t cp_size; /* number of sectors in partition */ + int16_t cp_bsize; /* block size in bytes */ + int16_t cp_fsize; /* filesystem basic fragment size */ + char cp_opt; /* optimization type: 's'pace/'t'ime */ + char cp_pad1; + int16_t cp_cpg; /* filesystem cylinders per group */ + int16_t cp_density; /* bytes per inode density */ + int8_t cp_minfree; /* minfree (%) */ + int8_t cp_newfs; /* run newfs during init */ + char cp_mountpt[NEXT68K_LABEL_MAXMPTLEN]; + /* default/standard mount point */ + int8_t cp_automnt; /* auto-mount when inserted */ + char cp_type[NEXT68K_LABEL_MAXFSTLEN]; /* file system type name */ + char cp_pad2; +} __packed; + +/* The disklabel the way it is on the disk */ +struct next68k_disklabel { + int32_t cd_version; /* label version */ + int32_t cd_label_blkno; /* block # of this label */ + int32_t cd_size; /* size of media area (sectors) */ + char cd_label[NEXT68K_LABEL_CPULBLLEN]; /* disk name (label) */ + uint32_t cd_flags; /* flags */ + uint32_t cd_tag; /* volume tag */ + char cd_name[NEXT68K_LABEL_MAXDNMLEN]; /* drive (hardware) name */ + char cd_type[NEXT68K_LABEL_MAXTYPLEN]; /* drive type */ + int32_t cd_secsize; /* # of bytes per sector */ + int32_t cd_ntracks; /* # of tracks per cylinder */ + int32_t cd_nsectors; /* # of data sectors per track */ + int32_t cd_ncylinders; /* # of data cylinders per unit */ + int32_t cd_rpm; /* rotational speed */ + int16_t cd_front; /* # of sectors in "front porch" */ + int16_t cd_back; /* # of sectors in "back porch" */ + int16_t cd_ngroups; /* # of alt groups */ + int16_t cd_ag_size; /* alt group size (sectors) */ + int16_t cd_ag_alts; /* alternate sectors / alt group */ + int16_t cd_ag_off; /* sector offset to first alternate */ + int32_t cd_boot_blkno[2]; /* boot program locations */ + char cd_kernel[NEXT68K_LABEL_MAXBFLEN]; /* default kernel name */ + char cd_hostname[NEXT68K_LABEL_MAXHNLEN]; + /* host name (usu. where disk was labeled) */ + char cd_rootpartition; /* root partition letter e.g. 'a' */ + char cd_rwpartition; /* r/w partition letter e.g. 'b' */ + struct next68k_partition cd_partitions[NEXT68K_LABEL_MAXPARTITIONS]; + + union { + uint16_t CD_v3_checksum; /* label version 3 checksum */ + int32_t CD_bad[NEXT68K_LABEL_NBAD]; + /* block number that is bad */ + } cd_un; + uint16_t cd_checksum; /* label version 1 or 2 checksum */ +} __packed; + +#define NEXT68K_LABEL_cd_checksum cd_checksum +#define NEXT68K_LABEL_cd_v3_checksum cd_un.CD_v3_checksum +#define NEXT68K_LABEL_cd_bad cd_un.CD_bad + +#define NEXT68K_LABEL_SECTOR 0 /* sector containing label */ +#define NEXT68K_LABEL_OFFSET 0 /* offset of label in sector */ +#define NEXT68K_LABEL_SIZE 8192 /* size of label */ +#define NEXT68K_LABEL_CD_V1 0x4e655854 /* version #1: "NeXT" */ +#define NEXT68K_LABEL_CD_V2 0x646c5632 /* version #2: "dlV2" */ +#define NEXT68K_LABEL_CD_V3 0x646c5633 /* version #3: "dlV3" */ +#define NEXT68K_LABEL_DEFAULTFRONTPORCH (160 * 2) +#define NEXT68K_LABEL_DEFAULTBOOT0_1 (32 * 2) +#define NEXT68K_LABEL_DEFAULTBOOT0_2 (96 * 2) + +/* ------------------------------------------ + * pmax -- + * PMAX (DECstation / MIPS) boot block information + */ + +/* + * If mode is 0, there is just one sequence of blocks and one Dec_BootMap + * is used. If mode is 1, there are multiple sequences of blocks + * and multiple Dec_BootMaps are used, the last with numBlocks = 0. + */ +struct pmax_boot_map { + int32_t num_blocks; /* Number of blocks to read. */ + int32_t start_block; /* Starting block on disk. */ +}; + +/* + * This is the structure of a disk or tape boot block. The boot_map + * can either be a single boot count and start block (contiguous mode) + * or a list of up to 61 (to fill a 512 byte sector) block count and + * start block pairs. Under NetBSD, contiguous mode is always used. + */ +struct pmax_boot_block { + uint8_t pad[8]; + int32_t magic; /* PMAX_BOOT_MAGIC */ + int32_t mode; /* Mode for boot info. */ + uint32_t load_addr; /* Address to start loading. */ + uint32_t exec_addr; /* Address to start execing. */ + struct pmax_boot_map map[61]; /* boot program section(s). */ +} __packed; + +#define PMAX_BOOT_MAGIC 0x0002757a +#define PMAX_BOOTMODE_CONTIGUOUS 0 +#define PMAX_BOOTMODE_SCATTERED 1 + +#define PMAX_BOOT_BLOCK_OFFSET 0 +#define PMAX_BOOT_BLOCK_BLOCKSIZE 512 + + +/* ------------------------------------------ + * sgimips + */ + +/* + * Some IRIX man pages refer to the size being a multiple of whole cylinders. + * Later ones only refer to the size being "typically" 2MB. IRIX fx(1) + * uses a default drive geometry if one can't be determined, suggesting + * that "whole cylinder" multiples are not required. + */ + +#define SGI_BOOT_BLOCK_SIZE_VOLHDR 3135 +#define SGI_BOOT_BLOCK_MAGIC 0xbe5a941 +#define SGI_BOOT_BLOCK_MAXPARTITIONS 16 +#define SGI_BOOT_BLOCK_MAXVOLDIRS 15 +#define SGI_BOOT_BLOCK_BLOCKSIZE 512 + +/* + * SGI partition conventions: + * + * Partition 0 - root + * Partition 1 - swap + * Partition 6 - usr + * Partition 7 - volume body + * Partition 8 - volume header + * Partition 10 - whole disk + */ + +struct sgi_boot_devparms { + uint8_t dp_skew; + uint8_t dp_gap1; + uint8_t dp_gap2; + uint8_t dp_spares_cyl; + uint16_t dp_cyls; + uint16_t dp_shd0; + uint16_t dp_trks0; + uint8_t dp_ctq_depth; + uint8_t dp_cylshi; + uint16_t dp_unused; + uint16_t dp_secs; + uint16_t dp_secbytes; + uint16_t dp_interleave; + uint32_t dp_flags; + uint32_t dp_datarate; + uint32_t dp_nretries; + uint32_t dp_mspw; + uint16_t dp_xgap1; + uint16_t dp_xsync; + uint16_t dp_xrdly; + uint16_t dp_xgap2; + uint16_t dp_xrgate; + uint16_t dp_xwcont; +} __packed; + +struct sgi_boot_block { + uint32_t magic; + int16_t root; + int16_t swap; + char bootfile[16]; + struct sgi_boot_devparms dp; + struct { + char name[8]; + int32_t block; + int32_t bytes; + } voldir[SGI_BOOT_BLOCK_MAXVOLDIRS]; + struct { + int32_t blocks; + int32_t first; + int32_t type; + } partitions[SGI_BOOT_BLOCK_MAXPARTITIONS]; + int32_t checksum; + int32_t _pad; +} __packed; + +#define SGI_PTYPE_VOLHDR 0 +#define SGI_PTYPE_TRKREPL 1 +#define SGI_PTYPE_SECREPL 2 +#define SGI_PTYPE_RAW 3 +#define SGI_PTYPE_BSD 4 +#define SGI_PTYPE_SYSV 5 +#define SGI_PTYPE_VOLUME 6 +#define SGI_PTYPE_EFS 7 +#define SGI_PTYPE_LVOL 8 +#define SGI_PTYPE_RLVOL 9 +#define SGI_PTYPE_XFS 10 +#define SGI_PTYPE_XFSLOG 11 +#define SGI_PTYPE_XLV 12 +#define SGI_PTYPE_XVM 13 + +/* ------------------------------------------ + * sparc + */ + +#define SPARC_BOOT_BLOCK_OFFSET 512 +#define SPARC_BOOT_BLOCK_BLOCKSIZE 512 +#define SPARC_BOOT_BLOCK_MAX_SIZE (512 * 15) + /* Magic string -- 32 bytes long (including the NUL) */ +#define SPARC_BBINFO_MAGIC "NetBSD/sparc bootxx 20020515" + + +/* ------------------------------------------ + * sparc64 + */ + +#define SPARC64_BOOT_BLOCK_OFFSET 512 +#define SPARC64_BOOT_BLOCK_BLOCKSIZE 512 +#define SPARC64_BOOT_BLOCK_MAX_SIZE (512 * 15) + + +/* ------------------------------------------ + * sun68k (sun2, sun3) + */ + +#define SUN68K_BOOT_BLOCK_OFFSET 512 +#define SUN68K_BOOT_BLOCK_BLOCKSIZE 512 +#define SUN68K_BOOT_BLOCK_MAX_SIZE (512 * 15) + /* Magic string -- 32 bytes long (including the NUL) */ +#define SUN68K_BBINFO_MAGIC "NetBSD/sun68k bootxx 20020515" + + +/* ------------------------------------------ + * vax -- + * VAX boot block information + */ + +struct vax_boot_block { +/* Note that these don't overlap any of the pmax boot block */ + uint8_t pad0[2]; + uint8_t bb_id_offset; /* offset in words to id (magic1)*/ + uint8_t bb_mbone; /* must be one */ + uint16_t bb_lbn_hi; /* lbn (hi word) of bootstrap */ + uint16_t bb_lbn_low; /* lbn (low word) of bootstrap */ + uint8_t pad1[332]; + + /* The rest of these fields are identification area and describe + * the secondary block for uVAX VMB. + */ + uint8_t bb_magic1; /* magic number */ + uint8_t bb_mbz1; /* must be zero */ + uint8_t bb_pad1; /* any value */ + uint8_t bb_sum1; /* ~(magic1 + mbz1 + pad1) */ + + uint8_t bb_mbz2; /* must be zero */ + uint8_t bb_volinfo; /* volinfo */ + uint8_t bb_pad2a; /* any value */ + uint8_t bb_pad2b; /* any value */ + + uint32_t bb_size; /* size in blocks of bootstrap */ + uint32_t bb_load; /* load offset to bootstrap */ + uint32_t bb_entry; /* byte offset in bootstrap */ + uint32_t bb_sum3; /* sum of previous 3 fields */ + + /* The rest is unused. + */ + uint8_t pad2[148]; +} __packed; + +#define VAX_BOOT_MAGIC1 0x18 /* size of BB info? */ +#define VAX_BOOT_VOLINFO_NONE 0x00 /* no special info */ +#define VAX_BOOT_VOLINFO_SS 0x01 /* single sided */ +#define VAX_BOOT_VOLINFO_DS 0x81 /* double sided */ + +#define VAX_BOOT_SIZE 15 /* 15 blocks */ +#define VAX_BOOT_LOAD 0 /* no load offset */ +#define VAX_BOOT_ENTRY 0x200 /* one block in */ + +#define VAX_BOOT_BLOCK_OFFSET 0 +#define VAX_BOOT_BLOCK_BLOCKSIZE 512 + + +/* ------------------------------------------ + * x68k + */ + +#define X68K_BOOT_BLOCK_OFFSET 0 +#define X68K_BOOT_BLOCK_BLOCKSIZE 512 +#define X68K_BOOT_BLOCK_MAX_SIZE (512 * 16) + /* Magic string -- 32 bytes long (including the NUL) */ +#define X68K_BBINFO_MAGIC "NetBSD/x68k bootxx 20020601" + +#endif /* !defined(__ASSEMBLER__) */ /* } */ + +#endif /* !_SYS_BOOTBLOCK_H */ diff --git a/common/include/sys/disk.h b/common/include/sys/disk.h new file mode 100644 index 000000000..985f8e719 --- /dev/null +++ b/common/include/sys/disk.h @@ -0,0 +1,538 @@ +/* $NetBSD: disk.h,v 1.55 2011/11/13 22:07:00 christos Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * This software was developed by the Computer Systems Engineering group + * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and + * contributed to Berkeley. + * + * All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Lawrence Berkeley Laboratories. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL) + * + * @(#)disk.h 8.2 (Berkeley) 1/9/95 + */ + +#ifndef _SYS_DISK_H_ +#define _SYS_DISK_H_ + +/* + * Disk device structures. + */ + +#ifdef _KERNEL +#include +#endif +#include +#include +#include +#include +#include + +#include + +struct buf; +struct disk; +struct disklabel; +struct cpu_disklabel; +struct lwp; +struct vnode; + +/* + * Disk information dictionary. + * + * This contains general infomation for disk devices. + * + * + * type + * ... + * geometry + * + * + * + * + * + * rpm + * ... + * sector-interleave + * ... + * track-skew + * ... + * cylinder-skew + * ... + * head-switch-usecs + * ... + * track-seek-usecs + * ... + * removable + * + * ecc + * + * bad-sector-forwarding + * + * ramdisk + * + * back-to-back-transfers + * + * + * + * smd-skip-sectoring + * + * + * smd-mindist + * ... + * smd-maxdist + * ... + * smd-sdist + * ... + * + * + * + * st506-precompcyl + * ... + * st506-gap3 + * ... + * + * + * + * + * + * + * + */ + +/* + * dkwedge_info: + * + * Information needed to configure (or query configuration of) a + * disk wedge. + */ +struct dkwedge_info { + char dkw_devname[16];/* device-style name (e.g. "dk0") */ + uint8_t dkw_wname[128]; /* wedge name (Unicode, UTF-8) */ + char dkw_parent[16]; /* parent disk device name */ + daddr_t dkw_offset; /* LBA offset of wedge in parent */ + uint64_t dkw_size; /* size of wedge in blocks */ + char dkw_ptype[32]; /* partition type string */ +}; + +/* + * dkwedge_list: + * + * Structure used to query a list of wedges. + */ +struct dkwedge_list { + void *dkwl_buf; /* storage for dkwedge_info array */ + size_t dkwl_bufsize; /* size of that buffer */ + u_int dkwl_nwedges; /* total number of wedges */ + u_int dkwl_ncopied; /* number actually copied */ +}; + +#ifdef _KERNEL +/* + * dkwedge_discovery_method: + * + * Structure used to describe partition map parsing schemes + * used for wedge autodiscovery. + */ +struct dkwedge_discovery_method { + /* link in wedge driver's list */ + LIST_ENTRY(dkwedge_discovery_method) ddm_list; + const char *ddm_name; /* name of this method */ + int ddm_priority; /* search priority */ + int (*ddm_discover)(struct disk *, struct vnode *); +}; + +#define DKWEDGE_DISCOVERY_METHOD_DECL(name, prio, discover) \ +static struct dkwedge_discovery_method name ## _ddm = { \ + { NULL, NULL }, \ + #name, \ + prio, \ + discover \ +}; \ +__link_set_add_data(dkwedge_methods, name ## _ddm) +#endif /* _KERNEL */ + +/* Some common partition types */ +#define DKW_PTYPE_UNKNOWN "" +#define DKW_PTYPE_UNUSED "unused" +#define DKW_PTYPE_SWAP "swap" +#define DKW_PTYPE_V6 "v6" +#define DKW_PTYPE_V7 "v7" +#define DKW_PTYPE_SYSV "sysv" +#define DKW_PTYPE_V71K "v71k" +#define DKW_PTYPE_V8 "v8" +#define DKW_PTYPE_FFS "ffs" +#define DKW_PTYPE_FAT "msdos" +#define DKW_PTYPE_LFS "lfs" +#define DKW_PTYPE_OTHER "other" +#define DKW_PTYPE_HPFS "hpfs" +#define DKW_PTYPE_ISO9660 "cd9660" +#define DKW_PTYPE_BOOT "boot" +#define DKW_PTYPE_AMIGADOS "ados" +#define DKW_PTYPE_HFS "hfs" +#define DKW_PTYPE_FILECORE "filecore" +#define DKW_PTYPE_EXT2FS "ext2fs" +#define DKW_PTYPE_NTFS "ntfs" +#define DKW_PTYPE_RAIDFRAME "raidframe" +#define DKW_PTYPE_CCD "ccd" +#define DKW_PTYPE_JFS2 "jfs2" +#define DKW_PTYPE_APPLEUFS "appleufs" +#define DKW_PTYPE_VINUM "vinum" +#define DKW_PTYPE_UDF "udf" +#define DKW_PTYPE_APPLEHFS "hfs" +#define DKW_PTYPE_SYSVBFS "sysvbfs" +#define DKW_PTYPE_EFS "efs" +#define DKW_PTYPE_NILFS "nilfs" +#define DKW_PTYPE_CGD "cgd" + +/* + * Disk geometry dictionary. + * + * NOTE: Not all geometry information is relevant for every kind of disk. + * + * + * sectors-per-unit + * ... + * sector-size + * ... + * sectors-per-track + * ... + * tracks-per-cylinder + * ... + * cylinders-per-unit + * ... + * physical-cylinders-per-unit + * ... + * spare-sectors-per-track + * ... + * spare-sectors-per-cylinder + * ... + * alternative-cylinders + * ... + * + * NOTE: Not all geometry information is relevant for every kind of disk. + */ + +struct disk_geom { + int64_t dg_secperunit; /* # of data sectors per unit */ + uint32_t dg_secsize; /* # of bytes per sector */ + uint32_t dg_nsectors; /* # of data sectors per track */ + uint32_t dg_ntracks; /* # of tracks per cylinder */ + uint32_t dg_ncylinders; /* # of data cylinders per unit */ + uint32_t dg_secpercyl; /* # of data sectors per cylinder */ + uint32_t dg_pcylinders; /* # of physical cylinders per unit */ + + /* + * Spares (bad sector replacements) below are not counted in + * dg_nsectors or dg_secpercyl. Spare sectors are assumed to + * be physical sectors which occupy space at the end of each + * track and/or cylinder. + */ + uint32_t dg_sparespertrack; + uint32_t dg_sparespercyl; + /* + * Alternative cylinders include maintenance, replacement, + * configuration description areas, etc. + */ + uint32_t dg_acylinders; +}; + +/* + * Disk partition dictionary. + * + * A partition is represented as a dictionary containing generic partition + * properties (such as starting block and block count), as well as information + * that is specific to individual partition map formats. + * + * + * start-block + * ... + * block-count + * ... + * + * type + * ... + * + * name + * ... + * + * + * gpt-type-guid + * ... + * gpt-partition-guid + * ... + * gpt-platform-required + * + * + * + * bsd44-partition-type + * ... + * bsd44-fs-fragment-size + * ... + * bsd44-iso9660-session-offset + * ... + * bsd44-ffs-cylinders-per-group + * ... + * bsd44-lfs-segment-shift + * ... + * + * + * next-block-size + * ... + * next-fs-fragment-size + * ... + * next-fs-optimization + * ... + * next-fs-cylinders-per-group + * ... + * next-bytes-per-inode-density + * ... + * next-minfree-percentage + * ... + * next-run-newfs-during-init + * + * next-mount-point + * ... + * next-automount + * + * next-partition-type + * ... + * + * + * mbr-start-head + * ... + * mbr-start-sector + * ... + * mbr-start-cylinder + * ... + * mbr-partition-type + * ... + * mbr-end-head + * ... + * mbr-end-sector + * ... + * mbr-end-cylinder + * ... + * mbr-active-partition + * + * + * + * apple-partition-type + * ... + * + * + * + * riscix-partition-type + * ... + * + * + * mips-partition-type + * ... + * + * + * + * + * + * + * vtoc-tag + * ... + * vtoc-unmount + * + * vtoc-read-only + * + * + * vtoc-timestamp + * ... + * + * + * + * + * + */ + +struct disk { + TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ + const char *dk_name; /* disk name */ + prop_dictionary_t dk_info; /* reference to disk-info dictionary */ + int dk_bopenmask; /* block devices open */ + int dk_copenmask; /* character devices open */ + int dk_openmask; /* composite (bopen|copen) */ + int dk_state; /* label state ### */ + int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ + int dk_byteshift; /* shift to convert bytes to blks */ + + /* + * Metrics data; note that some metrics may have no meaning + * on certain types of disks. + */ + struct io_stats *dk_stats; + + const struct dkdriver *dk_driver; /* pointer to driver */ + + /* + * Information required to be the parent of a disk wedge. + */ + kmutex_t dk_rawlock; /* lock on these fields */ + u_int dk_rawopens; /* # of openes of rawvp */ + struct vnode *dk_rawvp; /* vnode for the RAW_PART bdev */ + + kmutex_t dk_openlock; /* lock on these and openmask */ + u_int dk_nwedges; /* # of configured wedges */ + /* all wedges on this disk */ + LIST_HEAD(, dkwedge_softc) dk_wedges; + + /* + * Disk label information. Storage for the in-core disk label + * must be dynamically allocated, otherwise the size of this + * structure becomes machine-dependent. + */ + daddr_t dk_labelsector; /* sector containing label */ + struct disklabel *dk_label; /* label */ + struct cpu_disklabel *dk_cpulabel; +}; + +struct dkdriver { + void (*d_strategy)(struct buf *); + void (*d_minphys)(struct buf *); +#ifdef notyet + int (*d_open)(dev_t, int, int, struct proc *); + int (*d_close)(dev_t, int, int, struct proc *); + int (*d_ioctl)(dev_t, u_long, void *, int, struct proc *); + int (*d_dump)(dev_t); + void (*d_start)(struct buf *, daddr_t); + int (*d_mklabel)(struct disk *); +#endif +}; + +/* states */ +#define DK_CLOSED 0 /* drive is closed */ +#define DK_WANTOPEN 1 /* drive being opened */ +#define DK_WANTOPENRAW 2 /* drive being opened */ +#define DK_RDLABEL 3 /* label being read */ +#define DK_OPEN 4 /* label read, drive open */ +#define DK_OPENRAW 5 /* open without label */ + +/* + * Bad sector lists per fixed disk + */ +struct disk_badsectors { + SLIST_ENTRY(disk_badsectors) dbs_next; + daddr_t dbs_min; /* min. sector number */ + daddr_t dbs_max; /* max. sector number */ + struct timeval dbs_failedat; /* first failure at */ +}; + +struct disk_badsecinfo { + uint32_t dbsi_bufsize; /* size of region pointed to */ + uint32_t dbsi_skip; /* how many to skip past */ + uint32_t dbsi_copied; /* how many got copied back */ + uint32_t dbsi_left; /* remaining to copy */ + void * dbsi_buffer; /* region to copy disk_badsectors to */ +}; + +#define DK_STRATEGYNAMELEN 32 +struct disk_strategy { + char dks_name[DK_STRATEGYNAMELEN]; /* name of strategy */ + char *dks_param; /* notyet; should be NULL */ + size_t dks_paramlen; /* notyet; should be 0 */ +}; + +#define DK_BSIZE2BLKSHIFT(b) ((ffs((b) / DEV_BSIZE)) - 1) +#define DK_BSIZE2BYTESHIFT(b) (ffs((b)) - 1) + +#ifdef _KERNEL +extern int disk_count; /* number of disks in global disklist */ + +struct proc; + +void disk_attach(struct disk *); +int disk_begindetach(struct disk *, int (*)(device_t), device_t, int); +void disk_detach(struct disk *); +void disk_init(struct disk *, const char *, const struct dkdriver *); +void disk_destroy(struct disk *); +void disk_busy(struct disk *); +void disk_unbusy(struct disk *, long, int); +bool disk_isbusy(struct disk *); +void disk_blocksize(struct disk *, int); +struct disk *disk_find(const char *); +int disk_ioctl(struct disk *, u_long, void *, int, struct lwp *); + +void dkwedge_init(void); +int dkwedge_add(struct dkwedge_info *); +int dkwedge_del(struct dkwedge_info *); +void dkwedge_delall(struct disk *); +int dkwedge_list(struct disk *, struct dkwedge_list *, struct lwp *); +void dkwedge_discover(struct disk *); +void dkwedge_set_bootwedge(device_t, daddr_t, uint64_t); +int dkwedge_read(struct disk *, struct vnode *, daddr_t, void *, size_t); +device_t dkwedge_find_by_wname(const char *); +void dkwedge_print_wnames(void); +#endif + +#endif /* _SYS_DISK_H_ */ diff --git a/common/include/sys/disklabel.h b/common/include/sys/disklabel.h new file mode 100644 index 000000000..ff424ea6f --- /dev/null +++ b/common/include/sys/disklabel.h @@ -0,0 +1,475 @@ +/* $NetBSD: disklabel.h,v 1.111 2011/11/13 22:19:09 christos Exp $ */ + +/* + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_DISKLABEL_H_ +#define _SYS_DISKLABEL_H_ + +/* + * We need for __HAVE_OLD_DISKLABEL + */ +#ifndef _LOCORE +#include +#endif + +/* + * Each disk has a label which includes information about the hardware + * disk geometry, filesystem partitions, and drive specific information. + * The location of the label, as well as the number of partitions the + * label can describe and the number of the "whole disk" (raw) + * paritition are machine dependent. + */ +#if HAVE_NBTOOL_CONFIG_H +#include +#else +#include +#endif /* HAVE_NBTOOL_CONFIG_H */ + +/* + * The absolute maximum number of disk partitions allowed. + * This is the maximum value of MAXPARTITIONS for which 'struct disklabel' + * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware. + */ +#define MAXMAXPARTITIONS 22 +#if MAXPARTITIONS > MAXMAXPARTITIONS +#warning beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS +#endif + +/* + * Ports can switch their MAXPARTITIONS once, as follows: + * + * - define OLDMAXPARTITIONS in as the old number + * - define MAXPARTITIONS as the new number + * - define DISKUNIT, DISKPART and DISKMINOR macros in + * as appropriate for the port (see the i386 one for an example). + * - define __HAVE_OLD_DISKLABEL in + */ + +#if defined(_KERNEL) && defined(__HAVE_OLD_DISKLABEL) && \ + (MAXPARTITIONS < OLDMAXPARTITIONS) +#error "can only grow disklabel size" +#endif + + +/* + * Translate between device numbers and major/disk unit/disk partition. + */ +#ifndef __HAVE_OLD_DISKLABEL +#if !HAVE_NBTOOL_CONFIG_H +#define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS) +#define DISKPART(dev) (minor(dev) % MAXPARTITIONS) +#define DISKMINOR(unit, part) \ + (((unit) * MAXPARTITIONS) + (part)) +#endif /* !HAVE_NBTOOL_CONFIG_H */ +#endif +#define MAKEDISKDEV(maj, unit, part) \ + (makedev((maj), DISKMINOR((unit), (part)))) + +#define DISKMAGIC ((uint32_t)0x82564557) /* The disk magic number */ + +#ifndef _LOCORE +struct disklabel { + uint32_t d_magic; /* the magic number */ + uint16_t d_type; /* drive type */ + uint16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + + /* + * d_packname contains the pack identifier and is returned when + * the disklabel is read off the disk or in-core copy. + * d_boot0 and d_boot1 are the (optional) names of the + * primary (block 0) and secondary (block 1-15) bootstraps + * as found in /usr/mdec. These are returned when using + * getdiskbyname(3) to retrieve the values from /etc/disktab. + */ + union { + char un_d_packname[16]; /* pack identifier */ + struct { + char *un_d_boot0; /* primary bootstrap name */ + char *un_d_boot1; /* secondary bootstrap name */ + } un_b; + uint64_t un_d_pad; /* force 8 byte alignment */ + } d_un; +#define d_packname d_un.un_d_packname +#define d_boot0 d_un.un_b.un_d_boot0 +#define d_boot1 d_un.un_b.un_d_boot1 + + /* disk geometry: */ + uint32_t d_secsize; /* # of bytes per sector */ + uint32_t d_nsectors; /* # of data sectors per track */ + uint32_t d_ntracks; /* # of tracks per cylinder */ + uint32_t d_ncylinders; /* # of data cylinders per unit */ + uint32_t d_secpercyl; /* # of data sectors per cylinder */ + uint32_t d_secperunit; /* # of data sectors per unit */ + + /* + * Spares (bad sector replacements) below are not counted in + * d_nsectors or d_secpercyl. Spare sectors are assumed to + * be physical sectors which occupy space at the end of each + * track and/or cylinder. + */ + uint16_t d_sparespertrack; /* # of spare sectors per track */ + uint16_t d_sparespercyl; /* # of spare sectors per cylinder */ + /* + * Alternative cylinders include maintenance, replacement, + * configuration description areas, etc. + */ + uint32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + /* + * d_interleave, d_trackskew and d_cylskew describe perturbations + * in the media format used to compensate for a slow controller. + * Interleave is physical sector interleave, set up by the + * formatter or controller when formatting. When interleaving is + * in use, logically adjacent sectors are not physically + * contiguous, but instead are separated by some number of + * sectors. It is specified as the ratio of physical sectors + * traversed per logical sector. Thus an interleave of 1:1 + * implies contiguous layout, while 2:1 implies that logical + * sector 0 is separated by one sector from logical sector 1. + * d_trackskew is the offset of sector 0 on track N relative to + * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew + * is the offset of sector 0 on cylinder N relative to sector 0 + * on cylinder N-1. + */ + uint16_t d_rpm; /* rotational speed */ + uint16_t d_interleave; /* hardware sector interleave */ + uint16_t d_trackskew; /* sector 0 skew, per track */ + uint16_t d_cylskew; /* sector 0 skew, per cylinder */ + uint32_t d_headswitch; /* head switch time, usec */ + uint32_t d_trkseek; /* track-to-track seek, usec */ + uint32_t d_flags; /* generic flags */ +#define NDDATA 5 + uint32_t d_drivedata[NDDATA]; /* drive-type specific information */ +#define NSPARE 5 + uint32_t d_spare[NSPARE]; /* reserved for future use */ + uint32_t d_magic2; /* the magic number (again) */ + uint16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + uint16_t d_npartitions; /* number of partitions in following */ + uint32_t d_bbsize; /* size of boot area at sn0, bytes */ + uint32_t d_sbsize; /* max size of fs superblock, bytes */ + struct partition { /* the partition table */ + uint32_t p_size; /* number of sectors in partition */ + uint32_t p_offset; /* starting sector */ + union { + uint32_t fsize; /* FFS, ADOS: + filesystem basic fragment size */ + uint32_t cdsession; /* ISO9660: session offset */ + } __partition_u2; +#define p_fsize __partition_u2.fsize +#define p_cdsession __partition_u2.cdsession + uint8_t p_fstype; /* filesystem type, see below */ + uint8_t p_frag; /* filesystem fragments per block */ + union { + uint16_t cpg; /* UFS: FS cylinders per group */ + uint16_t sgs; /* LFS: FS segment shift */ + } __partition_u1; +#define p_cpg __partition_u1.cpg +#define p_sgs __partition_u1.sgs + } d_partitions[MAXPARTITIONS]; /* actually may be more */ +}; + +#if defined(__HAVE_OLD_DISKLABEL) && !HAVE_NBTOOL_CONFIG_H +/* + * Same as above, but with OLDMAXPARTITIONS partitions. For use in + * the old DIOC* ioctl calls. + */ +struct olddisklabel { + uint32_t d_magic; + uint16_t d_type; + uint16_t d_subtype; + char d_typename[16]; + union { + char un_d_packname[16]; + struct { + char *un_d_boot0; + char *un_d_boot1; + } un_b; + } d_un; + uint32_t d_secsize; + uint32_t d_nsectors; + uint32_t d_ntracks; + uint32_t d_ncylinders; + uint32_t d_secpercyl; + uint32_t d_secperunit; + uint16_t d_sparespertrack; + uint16_t d_sparespercyl; + uint32_t d_acylinders; + uint16_t d_rpm; + uint16_t d_interleave; + uint16_t d_trackskew; + uint16_t d_cylskew; + uint32_t d_headswitch; + uint32_t d_trkseek; + uint32_t d_flags; + uint32_t d_drivedata[NDDATA]; + uint32_t d_spare[NSPARE]; + uint32_t d_magic2; + uint16_t d_checksum; + uint16_t d_npartitions; + uint32_t d_bbsize; + uint32_t d_sbsize; + struct opartition { + uint32_t p_size; + uint32_t p_offset; + union { + uint32_t fsize; + uint32_t cdsession; + } __partition_u2; + uint8_t p_fstype; + uint8_t p_frag; + union { + uint16_t cpg; + uint16_t sgs; + } __partition_u1; + } d_partitions[OLDMAXPARTITIONS]; +}; +#endif /* __HAVE_OLD_DISKLABEL */ +#else /* _LOCORE */ + /* + * offsets for asm boot files. + */ + .set d_secsize,40 + .set d_nsectors,44 + .set d_ntracks,48 + .set d_ncylinders,52 + .set d_secpercyl,56 + .set d_secperunit,60 + .set d_end_,276 /* size of disk label */ +#endif /* _LOCORE */ + +/* + * We normally use C99 initialisers (just in case the lists below are out + * of sequence, or have gaps), but lint doesn't grok them. + * Maybe some host compilers don't either, but many have for quite some time. + */ + +#ifndef lint +#define ARRAY_INIT(element,value) [element]=value +#else +#define ARRAY_INIT(element,value) value +#endif + +/* Use pre-processor magic to get all the parameters one one line... */ + +/* d_type values: */ +#define DKTYPE_DEFN(x) \ +x(UNKNOWN, 0, "unknown") \ +x(SMD, 1, "SMD") /* SMD, XSMD; VAX hp/up */ \ +x(MSCP, 2, "MSCP") /* MSCP */ \ +x(DEC, 3, "old DEC") /* other DEC (rk, rl) */ \ +x(SCSI, 4, "SCSI") /* SCSI */ \ +x(ESDI, 5, "ESDI") /* ESDI interface */ \ +x(ST506, 6, "ST506") /* ST506 etc. */ \ +x(HPIB, 7, "HP-IB") /* CS/80 on HP-IB */ \ +x(HPFL, 8, "HP-FL") /* HP Fiber-link */ \ +x(TYPE_9, 9, "type 9") \ +x(FLOPPY, 10, "floppy") /* floppy */ \ +x(CCD, 11, "ccd") /* concatenated disk device */ \ +x(VND, 12, "vnd") /* uvnode pseudo-disk */ \ +x(ATAPI, 13, "ATAPI") /* ATAPI */ \ +x(RAID, 14, "RAID") /* RAIDframe */ \ +x(LD, 15, "ld") /* logical disk */ \ +x(JFS2, 16, "jfs") /* IBM JFS2 */ \ +x(CGD, 17, "cgd") /* cryptographic pseudo-disk */ \ +x(VINUM, 18, "vinum") /* vinum volume */ \ +x(FLASH, 19, "flash") /* flash memory devices */ \ +x(DM, 20, "dm") /* device-mapper pseudo-disk devices */\ +x(RUMPD, 21, "rumpd") /* rump virtual disk */ \ + +#ifndef _LOCORE +#define DKTYPE_NUMS(tag, number, name) __CONCAT(DTYPE_,tag=number), +#ifndef DKTYPE_ENUMNAME +#define DKTYPE_ENUMNAME +#endif +enum DKTYPE_ENUMNAME { DKTYPE_DEFN(DKTYPE_NUMS) DKMAXTYPES }; +#undef DKTYPE_NUMS +#endif + +#ifdef DKTYPENAMES +#define DKTYPE_NAMES(tag, number, name) ARRAY_INIT(number,name), +static const char *const dktypenames[] = { DKTYPE_DEFN(DKTYPE_NAMES) NULL }; +#undef DKTYPE_NAMES +#endif + +/* + * Partition type names, numbers, label-names, fsck prog, and mount prog + */ +#define FSTYPE_DEFN(x) \ +x(UNUSED, 0, "unused", NULL, NULL) /* unused */ \ +x(SWAP, 1, "swap", NULL, NULL) /* swap */ \ +x(V6, 2, "Version 6", NULL, NULL) /* Sixth Edition */ \ +x(V7, 3, "Version 7", "v7fs", "v7fs") /* Seventh Edition */ \ +x(SYSV, 4, "System V", NULL, NULL) /* System V */ \ +x(V71K, 5, "4.1BSD", NULL, NULL) /* V7, 1K blocks (4.1, 2.9) */ \ +x(V8, 6, "Eighth Edition",NULL, NULL) /* Eighth Edition, 4K blocks */ \ +x(BSDFFS, 7, "4.2BSD", "ffs", "ffs") /* 4.2BSD fast file system */ \ +x(MSDOS, 8, "MSDOS", "msdos", "msdos") /* MSDOS file system */ \ +x(BSDLFS, 9, "4.4LFS", "lfs", "lfs") /* 4.4BSD log-structured FS */ \ +x(OTHER, 10, "unknown", NULL, NULL) /* in use, unknown/unsupported */\ +x(HPFS, 11, "HPFS", NULL, NULL) /* OS/2 high-performance FS */ \ +x(ISO9660, 12, "ISO9660", NULL, "cd9660")/* ISO 9660, normally CD-ROM */ \ +x(BOOT, 13, "boot", NULL, NULL) /* bootstrap code in partition */\ +x(ADOS, 14, "ADOS", NULL, "ados") /* AmigaDOS fast file system */ \ +x(HFS, 15, "HFS", NULL, NULL) /* Macintosh HFS */ \ +x(FILECORE,16, "FILECORE", NULL, "filecore")/* Acorn Filecore FS */ \ +x(EX2FS, 17, "Linux Ext2","ext2fs","ext2fs")/* Linux Extended 2 FS */ \ +x(NTFS, 18, "NTFS", NULL, "ntfs") /* Windows/NT file system */ \ +x(RAID, 19, "RAID", NULL, NULL) /* RAIDframe component */ \ +x(CCD, 20, "ccd", NULL, NULL) /* concatenated disk component */\ +x(JFS2, 21, "jfs", NULL, NULL) /* IBM JFS2 */ \ +x(APPLEUFS,22, "Apple UFS", "ffs", "ffs") /* Apple UFS */ \ +/* XXX this is not the same as FreeBSD. How to solve? */ \ +x(VINUM, 23, "vinum", NULL, NULL) /* Vinum */ \ +x(UDF, 24, "UDF", NULL, "udf") /* UDF */ \ +x(SYSVBFS, 25, "SysVBFS", NULL, "sysvbfs")/* System V boot file system */ \ +x(EFS, 26, "EFS", NULL, "efs") /* SGI's Extent Filesystem */ \ +x(NILFS, 27, "NiLFS", NULL, "nilfs") /* NTT's NiLFS(2) */ \ +x(CGD, 28, "cgd", NULL, NULL) /* Cryptographic disk */ + + +#ifndef _LOCORE +#define FS_TYPENUMS(tag, number, name, fsck, mount) __CONCAT(FS_,tag=number), +#ifndef FSTYPE_ENUMNAME +#define FSTYPE_ENUMNAME +#endif +enum FSTYPE_ENUMNAME { FSTYPE_DEFN(FS_TYPENUMS) FSMAXTYPES }; +#undef FS_TYPENUMS +#endif + +#ifdef FSTYPENAMES +#define FS_TYPENAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,name), +static const char *const fstypenames[] = { FSTYPE_DEFN(FS_TYPENAMES) NULL }; +#undef FS_TYPENAMES +#endif + +#ifdef FSCKNAMES +/* These are the names MOUNT_XXX from */ +#define FS_FSCKNAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,fsck), +static const char *const fscknames[] = { FSTYPE_DEFN(FS_FSCKNAMES) NULL }; +#undef FS_FSCKNAMES +#define FSMAXNAMES FSMAXTYPES +#endif + +#ifdef MOUNTNAMES +/* These are the names MOUNT_XXX from */ +#define FS_MOUNTNAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,mount), +static const char *const mountnames[] = { FSTYPE_DEFN(FS_MOUNTNAMES) NULL }; +#undef FS_MOUNTNAMES +#define FSMAXMOUNTNAMES FSMAXTYPES +#endif + +/* + * flags shared by various drives: + */ +#define D_REMOVABLE 0x01 /* removable media */ +#define D_ECC 0x02 /* supports ECC */ +#define D_BADSECT 0x04 /* supports bad sector forw. */ +#define D_RAMDISK 0x08 /* disk emulator */ +#define D_CHAIN 0x10 /* can do back-back transfers */ +#define D_SCSI_MMC 0x20 /* SCSI MMC sessioned media */ + +/* + * Drive data for SMD. + */ +#define d_smdflags d_drivedata[0] +#define D_SSE 0x1 /* supports skip sectoring */ +#define d_mindist d_drivedata[1] +#define d_maxdist d_drivedata[2] +#define d_sdist d_drivedata[3] + +/* + * Drive data for ST506. + */ +#define d_precompcyl d_drivedata[0] +#define d_gap3 d_drivedata[1] /* used only when formatting */ + +/* + * Drive data for SCSI. + */ +#define d_blind d_drivedata[0] + +#ifndef _LOCORE +/* + * Structure used to perform a format or other raw operation, + * returning data and/or register values. Register identification + * and format are device- and driver-dependent. Currently unused. + */ +struct format_op { + char *df_buf; + int df_count; /* value-result */ + daddr_t df_startblk; + int df_reg[8]; /* result */ +}; + +#ifdef _KERNEL +/* + * Structure used internally to retrieve information about a partition + * on a disk. + */ +struct partinfo { + struct disklabel *disklab; + struct partition *part; +}; + +struct disk; + +int disk_read_sectors(void (*)(struct buf *), const struct disklabel *, + struct buf *, unsigned int, int); +void diskerr(const struct buf *, const char *, const char *, int, + int, const struct disklabel *); +u_int dkcksum(struct disklabel *); +u_int dkcksum_sized(struct disklabel *, size_t); +int setdisklabel(struct disklabel *, struct disklabel *, u_long, + struct cpu_disklabel *); +const char *readdisklabel(dev_t, void (*)(struct buf *), + struct disklabel *, struct cpu_disklabel *); +int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *, + struct cpu_disklabel *); +const char *convertdisklabel(struct disklabel *, void (*)(struct buf *), + struct buf *, uint32_t); +int bounds_check_with_label(struct disk *, struct buf *, int); +int bounds_check_with_mediasize(struct buf *, int, uint64_t); +const char *getfstypename(int); +#endif +#endif /* _LOCORE */ + +#if !defined(_KERNEL) && !defined(_LOCORE) + +#include + +#endif + +#endif /* !_SYS_DISKLABEL_H_ */ diff --git a/common/include/sys/dkbad.h b/common/include/sys/dkbad.h new file mode 100644 index 000000000..af0ed28f8 --- /dev/null +++ b/common/include/sys/dkbad.h @@ -0,0 +1,82 @@ +/* $NetBSD: dkbad.h,v 1.15 2005/12/26 18:41:36 perry Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)dkbad.h 8.2 (Berkeley) 7/10/94 + */ + +#ifndef _SYS_DKBAD_H_ +#define _SYS_DKBAD_H_ + +/* + * Definitions needed to perform bad sector revectoring ala DEC STD 144. + * + * The bad sector information is located in the first 5 even numbered + * sectors of the last track of the disk pack. There are five identical + * copies of the information, described by the dkbad structure. + * + * Replacement sectors are allocated starting with the first sector before + * the bad sector information and working backwards towards the beginning of + * the disk. A maximum of 126 bad sectors are supported. The position of + * the bad sector in the bad sector table determines which replacement sector + * it corresponds to. + * + * The bad sector information and replacement sectors are conventionally + * only accessible through the 'c' file system partition of the disk. If + * that partition is used for a file system, the user is responsible for + * making sure that it does not overlap the bad sector information or any + * replacement sectors. + */ +#define NBT_BAD 126 + +struct dkbad { + int32_t bt_csn; /* cartridge serial number */ + uint16_t bt_mbz; /* unused; should be 0 */ + uint16_t bt_flag; /* -1 => alignment cartridge */ + struct bt_bad { + uint16_t bt_cyl; /* cylinder number of bad sector */ + uint16_t bt_trksec; /* track and sector number */ + } bt_bad[NBT_BAD]; +}; + +/* + * An indicator that the bad block handling is available. This is used + * to conditionally enable code that performs badblock re-mapping. + */ +#define HAS_BAD144_HANDLING + +#define ECC 0 +#define SSE 1 +#define BSE 2 +#define CONT 3 + +#ifdef _KERNEL +int isbad(struct dkbad *, int, int, int); +#endif +#endif /* _SYS_DKBAD_H_ */ diff --git a/common/include/sys/dkio.h b/common/include/sys/dkio.h new file mode 100644 index 000000000..ca0ae7f41 --- /dev/null +++ b/common/include/sys/dkio.h @@ -0,0 +1,112 @@ +/* $NetBSD: dkio.h,v 1.17 2011/01/18 19:52:24 matt Exp $ */ + +/* + * Copyright (c) 1987, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SYS_DKIO_H_ +#define _SYS_DKIO_H_ + +#include +#include + +/* + * Disk-specific ioctls. + */ + /* get and set disklabel; DIOCGPART used internally */ +#define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */ +#define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ +#define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ + +#ifdef _KERNEL +#define DIOCGDINFO32 (DIOCGDINFO - (sizeof(uint32_t) << IOCPARM_SHIFT)) +#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ +#endif + +#if defined(__HAVE_OLD_DISKLABEL) && defined(_KERNEL) +#define ODIOCGDINFO _IOR('d', 101, struct olddisklabel)/* get */ +#define ODIOCSDINFO _IOW('d', 102, struct olddisklabel)/* set */ +#define ODIOCWDINFO _IOW('d', 103, struct olddisklabel)/* set, update dk */ +#endif + +/* do format operation, read or write */ +#define DIOCRFORMAT _IOWR('d', 105, struct format_op) +#define DIOCWFORMAT _IOWR('d', 106, struct format_op) + +#define DIOCSSTEP _IOW('d', 107, int) /* set step rate */ +#define DIOCSRETRIES _IOW('d', 108, int) /* set # of retries */ +#define DIOCKLABEL _IOW('d', 119, int) /* keep/drop label on close? */ +#define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ + +#define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */ +#define DIOCEJECT _IOW('d', 112, int) /* eject removable disk */ +#define ODIOCEJECT _IO('d', 112) /* eject removable disk */ +#define DIOCLOCK _IOW('d', 113, int) /* lock/unlock pack */ + + /* get default label, clear label */ +#define DIOCGDEFLABEL _IOR('d', 114, struct disklabel) +#define DIOCCLRLABEL _IO('d', 115) + +#if defined(__HAVE_OLD_DISKLABEL) && defined(_KERNEL) +#define ODIOCGDEFLABEL _IOR('d', 114, struct olddisklabel) +#endif + + /* disk cache enable/disable */ +#define DIOCGCACHE _IOR('d', 116, int) /* get cache enables */ +#define DIOCSCACHE _IOW('d', 117, int) /* set cache enables */ + +#define DKCACHE_READ 0x000001 /* read cache enabled */ +#define DKCACHE_WRITE 0x000002 /* write(back) cache enabled */ +#define DKCACHE_RCHANGE 0x000100 /* read enable is changeable */ +#define DKCACHE_WCHANGE 0x000200 /* write enable is changeable */ +#define DKCACHE_SAVE 0x010000 /* cache parameters are savable/save them */ + + /* sync disk cache */ +#define DIOCCACHESYNC _IOW('d', 118, int) /* sync cache (force?) */ + + /* bad sector list */ +#define DIOCBSLIST _IOWR('d', 119, struct disk_badsecinfo) /* get list */ +#define DIOCBSFLUSH _IO('d', 120) /* flush list */ + + /* wedges */ +#define DIOCAWEDGE _IOWR('d', 121, struct dkwedge_info) /* add wedge */ +#define DIOCGWEDGEINFO _IOR('d', 122, struct dkwedge_info) /* get wedge inf */ +#define DIOCDWEDGE _IOW('d', 123, struct dkwedge_info) /* del wedge */ +#define DIOCLWEDGES _IOWR('d', 124, struct dkwedge_list) /* list wedges */ + + /* disk buffer queue strategy */ +#define DIOCGSTRATEGY _IOR('d', 125, struct disk_strategy) +#define DIOCSSTRATEGY _IOW('d', 126, struct disk_strategy) + + /* get disk-info dictionary */ +#define DIOCGDISKINFO _IOR('d', 127, struct plistref) + + +#define DIOCTUR _IOR('d', 128, int) /* test unit ready */ + +#endif /* _SYS_DKIO_H_ */ diff --git a/common/include/sys/ioccom.h b/common/include/sys/ioccom.h new file mode 100644 index 000000000..3cd8174c2 --- /dev/null +++ b/common/include/sys/ioccom.h @@ -0,0 +1,75 @@ +/* $NetBSD: ioccom.h,v 1.11 2011/10/19 10:53:12 yamt Exp $ */ + +/*- + * Copyright (c) 1982, 1986, 1990, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)ioccom.h 8.3 (Berkeley) 1/9/95 + */ + +#ifndef _SYS_IOCCOM_H_ +#define _SYS_IOCCOM_H_ + +/* + * Ioctl's have the command encoded in the lower word, and the size of + * any in or out parameters in the upper word. The high 3 bits of the + * upper word are used to encode the in/out status of the parameter. + * + * 31 29 28 16 15 8 7 0 + * +---------------------------------------------------------------+ + * | I/O | Parameter Length | Command Group | Command | + * +---------------------------------------------------------------+ + */ +#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ +#define IOCPARM_SHIFT 16 +#define IOCGROUP_SHIFT 8 +#define IOCPARM_LEN(x) (((x) >> IOCPARM_SHIFT) & IOCPARM_MASK) +#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << IOCPARM_SHIFT)) +#define IOCGROUP(x) (((x) >> IOCGROUP_SHIFT) & 0xff) + +#define IOCPARM_MAX NBPG /* max size of ioctl args, mult. of NBPG */ + /* no parameters */ +#define IOC_VOID (unsigned long)0x20000000 + /* copy parameters out */ +#define IOC_OUT (unsigned long)0x40000000 + /* copy parameters in */ +#define IOC_IN (unsigned long)0x80000000 + /* copy parameters in and out */ +#define IOC_INOUT (IOC_IN|IOC_OUT) + /* mask for IN/OUT/VOID */ +#define IOC_DIRMASK (unsigned long)0xe0000000 + +#define _IOC(inout, group, num, len) \ + ((inout) | (((len) & IOCPARM_MASK) << IOCPARM_SHIFT) | \ + ((group) << IOCGROUP_SHIFT) | (num)) +#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0) +#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t)) +#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t)) +/* this should be _IORW, but stdio got there first */ +#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) + +#endif /* !_SYS_IOCCOM_H_ */ diff --git a/common/include/sys/iostat.h b/common/include/sys/iostat.h new file mode 100644 index 000000000..48fbfd80a --- /dev/null +++ b/common/include/sys/iostat.h @@ -0,0 +1,108 @@ +/* $NetBSD: iostat.h,v 1.10 2009/04/04 07:30:09 ad Exp $ */ + +/*- + * Copyright (c) 1996, 1997, 2004, 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_IOSTAT_H_ +#define _SYS_IOSTAT_H_ + +/* + * Disk device structures. + */ + +#include +#include + +#define IOSTATNAMELEN 16 + +/* types of drives we can have */ +#define IOSTAT_DISK 0 +#define IOSTAT_TAPE 1 +#define IOSTAT_NFS 2 + +/* The following structure is 64-bit alignment safe */ +struct io_sysctl { + char name[IOSTATNAMELEN]; + int32_t busy; + int32_t type; + u_int64_t xfer; + u_int64_t seek; + u_int64_t bytes; + u_int32_t attachtime_sec; + u_int32_t attachtime_usec; + u_int32_t timestamp_sec; + u_int32_t timestamp_usec; + u_int32_t time_sec; + u_int32_t time_usec; + /* New separate read/write stats */ + u_int64_t rxfer; + u_int64_t rbytes; + u_int64_t wxfer; + u_int64_t wbytes; +}; + +/* + * Structure for keeping the in-kernel drive stats - these are linked + * together in drivelist. + */ + +struct io_stats { + char io_name[IOSTATNAMELEN]; /* device name */ + void *io_parent; /* pointer to what we are attached to */ + int io_type; /* type of device the state belong to */ + int io_busy; /* busy counter */ + u_int64_t io_rxfer; /* total number of read transfers */ + u_int64_t io_wxfer; /* total number of write transfers */ + u_int64_t io_seek; /* total independent seek operations */ + u_int64_t io_rbytes; /* total bytes read */ + u_int64_t io_wbytes; /* total bytes written */ + struct timeval io_attachtime; /* time disk was attached */ + struct timeval io_timestamp; /* timestamp of last unbusy */ + struct timeval io_time; /* total time spent busy */ + TAILQ_ENTRY(io_stats) io_link; +}; + +/* + * drivelist_head is defined here so that user-land has access to it. + */ +TAILQ_HEAD(iostatlist_head, io_stats); /* the iostatlist is a TAILQ */ + +#ifdef _KERNEL +void iostat_init(void); +void iostat_busy(struct io_stats *); +void iostat_unbusy(struct io_stats *, long, int); +bool iostat_isbusy(struct io_stats *); +struct io_stats *iostat_find(const char *); +struct io_stats *iostat_alloc(int32_t, void *, const char *); +void iostat_free(struct io_stats *); +void iostat_seek(struct io_stats *); +#endif + +#endif /* _SYS_IOSTAT_H_ */ diff --git a/common/include/sys/mutex.h b/common/include/sys/mutex.h new file mode 100644 index 000000000..d802ad9d0 --- /dev/null +++ b/common/include/sys/mutex.h @@ -0,0 +1,216 @@ +/* $NetBSD: mutex.h,v 1.20 2010/02/08 09:54:27 skrll Exp $ */ + +/*- + * Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe and Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_MUTEX_H_ +#define _SYS_MUTEX_H_ + +/* + * There are 2 types of mutexes: + * + * * Adaptive -- If the lock is already held, the thread attempting + * to acquire the lock determines if the thread that holds it is + * currently running. If so, it spins, else it sleeps. + * + * * Spin -- If the lock is already held, the thread attempting to + * acquire the lock spins. The IPL will be raised on entry. + * + * Machine dependent code must provide the following: + * + * struct mutex + * The actual mutex structure. This structure is mostly + * opaque to machine-independent code; most access are done + * through macros. However, machine-independent code must + * be able to access the following members: + * + * uintptr_t mtx_owner + * ipl_cookie_t mtx_ipl + * __cpu_simple_lock_t mtx_lock + * + * If an architecture can be considered 'simple' (no interlock required in + * the MP case, or no MP) it need only define __HAVE_SIMPLE_MUTEXES and + * provide the following: + * + * struct mutex + * + * [additionally:] + * volatile integer mtx_id + * + * MUTEX_RECEIVE(mtx) + * Post a load fence after acquiring the mutex, if necessary. + * + * MUTEX_GIVE(mtx) + * Post a load/store fence after releasing the mutex, if + * necessary. + * + * MUTEX_CAS(ptr, old, new) + * Perform an atomic "compare and swap" operation and + * evaluate to true or false according to the success + * + * Otherwise, the following must be defined: + * + * MUTEX_INITIALIZE_SPIN(mtx, dodebug, minipl) + * Initialize a spin mutex. + * + * MUTEX_INITIALIZE_ADAPTIVE(mtx, dodebug) + * Initialize an adaptive mutex. + * + * MUTEX_DESTROY(mtx) + * Tear down a mutex. + * + * MUTEX_ADAPTIVE_P(mtx) + * Evaluates to true if the mutex is an adaptive mutex. + * + * MUTEX_SPIN_P(mtx) + * Evaluates to true if the mutex is a spin mutex. + * + * MUTEX_OWNER(owner) + * Returns the owner of the adaptive mutex (LWP address). + * + * MUTEX_OWNED(owner) + * Returns non-zero if an adaptive mutex is currently + * held by an LWP. + * + * MUTEX_HAS_WAITERS(mtx) + * Returns true if the mutex has waiters. + * + * MUTEX_SET_WAITERS(mtx) + * Mark the mutex has having waiters. + * + * MUTEX_ACQUIRE(mtx, owner) + * Try to acquire an adaptive mutex such that: + * if (lock held OR waiters) + * return 0; + * else + * return 1; + * Must be MP/interrupt atomic. + * + * MUTEX_RELEASE(mtx) + * Release the lock and clear the "has waiters" indication. + * Must be interrupt atomic, need not be MP safe. + * + * MUTEX_DEBUG_P(mtx) + * Evaluates to true if the mutex is initialized with + * dodebug==true. Only used in the LOCKDEBUG case. + * + * Machine dependent code may optionally provide stubs for the following + * functions to implement the easy (unlocked / no waiters) cases. If + * these stubs are provided, __HAVE_MUTEX_STUBS should be defined. + * + * mutex_enter() + * mutex_exit() + * + * Two additional stubs may be implemented that handle only the spinlock + * case, primarily for the scheduler. __HAVE_SPIN_MUTEX_STUBS should be + * defined if these are provided: + * + * mutex_spin_enter() + * mutex_spin_exit() + */ + +#if defined(_KERNEL_OPT) +#include "opt_lockdebug.h" +#endif + +#if !defined(_KERNEL) +#include +#include +#endif + +typedef enum kmutex_type_t { + MUTEX_SPIN = 0, /* To get a spin mutex at IPL_NONE */ + MUTEX_ADAPTIVE = 1, /* For porting code written for Solaris */ + MUTEX_DEFAULT = 2, /* The only native, endorsed type */ + MUTEX_DRIVER = 3, /* For porting code written for Solaris */ + MUTEX_NODEBUG = 4 /* Disables LOCKDEBUG; use with care */ +} kmutex_type_t; + +typedef struct kmutex kmutex_t; + +#if defined(__MUTEX_PRIVATE) + +#define MUTEX_THREAD ((uintptr_t)-16L) + +#define MUTEX_BIT_SPIN 0x01 +#define MUTEX_BIT_WAITERS 0x02 + +#if defined(LOCKDEBUG) +#define MUTEX_BIT_NODEBUG 0x04 /* LOCKDEBUG disabled */ +#else +#define MUTEX_BIT_NODEBUG 0x00 /* do nothing */ +#endif /* LOCKDEBUG */ + +#define MUTEX_SPIN_IPL(mtx) ((mtx)->mtx_ipl) +#define MUTEX_SPIN_OLDSPL(ci) ((ci)->ci_mtx_oldspl) + +void mutex_vector_enter(kmutex_t *); +void mutex_vector_exit(kmutex_t *); +void mutex_spin_retry(kmutex_t *); +void mutex_wakeup(kmutex_t *); + +#endif /* __MUTEX_PRIVATE */ + +#ifdef _KERNEL +#include +#endif + +#include + +/* + * Return true if no spin mutexes are held by the current CPU. + */ +#ifndef MUTEX_NO_SPIN_ACTIVE_P +#define MUTEX_NO_SPIN_ACTIVE_P(ci) ((ci)->ci_mtx_count == 0) +#endif + +#ifdef _KERNEL + +void mutex_init(kmutex_t *, kmutex_type_t, int); +void mutex_destroy(kmutex_t *); + +void mutex_enter(kmutex_t *); +void mutex_exit(kmutex_t *); + +void mutex_spin_enter(kmutex_t *); +void mutex_spin_exit(kmutex_t *); + +int mutex_tryenter(kmutex_t *); + +int mutex_owned(kmutex_t *); +lwp_t *mutex_owner(kmutex_t *); + +void mutex_obj_init(void); +kmutex_t *mutex_obj_alloc(kmutex_type_t, int); +void mutex_obj_hold(kmutex_t *); +bool mutex_obj_free(kmutex_t *); + +#endif /* _KERNEL */ + +#endif /* _SYS_MUTEX_H_ */ diff --git a/etc/mtree/minix.tree b/etc/mtree/minix.tree index 329abe152..64e6511e3 100644 --- a/etc/mtree/minix.tree +++ b/etc/mtree/minix.tree @@ -71,6 +71,13 @@ 755 root operator /usr/include/rpcsvc 755 root operator /usr/include/ssp 755 root operator /usr/include/sys +755 root operator /usr/include/ufs +755 root operator /usr/include/ufs/chfs +755 root operator /usr/include/ufs/ext2fs +755 root operator /usr/include/ufs/ffs +755 root operator /usr/include/ufs/lfs +755 root operator /usr/include/ufs/mfs +755 root operator /usr/include/ufs/ufs 700 root operator /usr/preserve 755 root operator /usr/run 755 root operator /usr/share diff --git a/etc/rc b/etc/rc index 80d22804e..804320c54 100755 --- a/etc/rc +++ b/etc/rc @@ -114,8 +114,10 @@ start) # options for fsck. default is -r, which prompts the user for repairs. fsckopts="`sysenv fsckopts`" - if [ ! "$fsckopts" ] - then fsckopts=-r + optname=fsckopts + fsckopts=-p + if sysenv $optname >/dev/null + then fsckopts="`sysenv $optname`" fi if [ "`sysenv debug_fkeys`" != 0 ] @@ -160,7 +162,8 @@ start) read <$FSTAB fstabline if [ "$fstabline" = "# Poor man's File System Table." ] then mountfstab_poorman # Old minix /etc/fstab - else mountfstab $fflag -o"$fsckopts" $FSTAB + else fsck -x / $fflag $fsckopts + mountfstab $FSTAB fi fi diff --git a/etc/rc.subr.minix b/etc/rc.subr.minix index 963b51ad9..4a46c611d 100755 --- a/etc/rc.subr.minix +++ b/etc/rc.subr.minix @@ -1,21 +1,6 @@ mountfstab() { - fsck_opts="" - fflag="-p" - - while getopts "fo:" opt - do case $opt - in f) fflag="-f" - ;; - o) fsck_opts="$OPTARG" - ;; - *) echo "mountfstab: odd" - return 1 - ;; - esac - done - shift `expr $OPTIND - 1` fstabfile="$1" @@ -37,23 +22,13 @@ mountfstab() # This line's parameters dev="$1"; mp="$2"; fstype="$3" - # Don't fsck / as it's already mounted + # Don't mount / as it's already mounted if [ "$mp" = "/" ]; then continue; fi # Sanity checks if [ ! -b $dev ]; then echo "$dev missing"; continue; fi if [ ! -d $mp ]; then echo "$mp missing"; continue; fi - # Do fsck if necessary or requested - if [ -n "$fflag" ] - then fsck.$fstype $fflag $fsck_opts $dev - fi - - # Skip the actual mount for /, it's already mounted - if [ "$mp" = / ] - then continue - fi - # Do actual mount command mount -t $fstype $dev $mp done diff --git a/lib/Makefile b/lib/Makefile index 8657b7964..8908ea14b 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -20,7 +20,7 @@ SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libblockdriver libchardriver \ libnetdriver libedit ${LIBM_DIR} libsys libtimers ${LIBUTIL_DIR} \ libl libhgfs libz libfetch libvtreefs libaudiodriver libmthread \ libexec libdevman libusb ${LIBMINLIB_DIR} ${LIBASYN_DIR} \ - libddekit libminixfs libbdev + libddekit libminixfs libbdev .if defined(NBSD_LIBC) && (${NBSD_LIBC} != "no") SUBDIR+= libelf libminc libcrypt libterminfo libcurses libvassert libutil \ diff --git a/lib/libc/other/Makefile.inc b/lib/libc/other/Makefile.inc index 69fe50893..025374faa 100644 --- a/lib/libc/other/Makefile.inc +++ b/lib/libc/other/Makefile.inc @@ -94,6 +94,7 @@ SRCS+= \ setmode.c \ settimeofday.c \ shquote.c \ + sizeup.c \ stderr.c \ strcasestr.c \ strdup.c \ diff --git a/lib/libc/other/sizeup.c b/lib/libc/other/sizeup.c new file mode 100644 index 000000000..ea843075a --- /dev/null +++ b/lib/libc/other/sizeup.c @@ -0,0 +1,52 @@ +#include +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/*================================================================ + * minix_sizeup - determine device size + *===============================================================*/ +int minix_sizeup(device, bytes) +char *device; +u64_t *bytes; +{ + int fd; + struct partition entry; + struct stat st; + + if ((fd = open(device, O_RDONLY)) == -1) { + if (errno != ENOENT) + perror("sizeup open"); + return -1; + } + if (ioctl(fd, DIOCGETP, &entry) == -1) { + perror("sizeup ioctl"); + if(fstat(fd, &st) < 0) { + perror("fstat"); + entry.size = cvu64(0); + } else { + entry.size = cvu64(st.st_size); + } + } + close(fd); + *bytes = entry.size; + return 0; +} diff --git a/lib/libutil/opendisk.c b/lib/libutil/opendisk.c index f4f4b9141..de924e4e5 100644 --- a/lib/libutil/opendisk.c +++ b/lib/libutil/opendisk.c @@ -61,14 +61,17 @@ __opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked, return (-1); } +#ifndef __minix rawpart = getrawpartition(); if (rawpart < 0) return (-1); /* sysctl(3) in getrawpartition sets errno */ +#endif f = ofn(buf, flags, 0); if (f != -1 || errno != ENOENT) return (f); +#ifndef __minix snprintf(buf, buflen, "%s%c", path, 'a' + rawpart); f = ofn(buf, flags, 0); if (f != -1 || errno != ENOENT) @@ -85,6 +88,7 @@ __opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked, snprintf(buf, buflen, "%s%s%s%c", _PATH_DEV, iscooked ? "" : "r", path, 'a' + rawpart); f = ofn(buf, flags, 0); +#endif return (f); } diff --git a/lib/nbsd_libc/sys-minix/Makefile.inc b/lib/nbsd_libc/sys-minix/Makefile.inc index 33bf63a5b..317eef5c7 100644 --- a/lib/nbsd_libc/sys-minix/Makefile.inc +++ b/lib/nbsd_libc/sys-minix/Makefile.inc @@ -16,7 +16,7 @@ SRCS+= accept.c access.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \ vectorio.c shutdown.c sigaction.c sigpending.c sigreturn.c sigsuspend.c\ sigprocmask.c socket.c socketpair.c stat.c statvfs.c symlink.c \ sync.c syscall.c sysuname.c truncate.c umask.c unlink.c write.c \ - _exit.c _ucontext.c environ.c __getcwd.c vfork.c + _exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c # Minix specific syscalls. SRCS+= cprofile.c lseek64.c sprofile.c _mcontext.c diff --git a/lib/nbsd_libc/sys-minix/sizeup.c b/lib/nbsd_libc/sys-minix/sizeup.c new file mode 100644 index 000000000..ea843075a --- /dev/null +++ b/lib/nbsd_libc/sys-minix/sizeup.c @@ -0,0 +1,52 @@ +#include +#include "namespace.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/*================================================================ + * minix_sizeup - determine device size + *===============================================================*/ +int minix_sizeup(device, bytes) +char *device; +u64_t *bytes; +{ + int fd; + struct partition entry; + struct stat st; + + if ((fd = open(device, O_RDONLY)) == -1) { + if (errno != ENOENT) + perror("sizeup open"); + return -1; + } + if (ioctl(fd, DIOCGETP, &entry) == -1) { + perror("sizeup ioctl"); + if(fstat(fd, &st) < 0) { + perror("fstat"); + entry.size = cvu64(0); + } else { + entry.size = cvu64(st.st_size); + } + } + close(fd); + *bytes = entry.size; + return 0; +} diff --git a/man/man1/Makefile b/man/man1/Makefile index f1276d25c..5ee7f2d22 100644 --- a/man/man1/Makefile +++ b/man/man1/Makefile @@ -7,7 +7,7 @@ MAN= acd.1 anm.1 ar.1 ash.1 asize.1 at.1 banner.1 basename.1 \ dumpcore.1 echo.1 ed.1 eject.1 elvis.1 elvrec.1 \ env.1 expand.1 expr.1 factor.1 file.1 \ finger.1 flexdoc.1 fmt.1 fold.1 format.1 fortune.1 \ - fsck.1 head.1 host.1 hostaddr.1 ifdef.1 \ + fsck.mfs.1 head.1 host.1 hostaddr.1 ifdef.1 \ install.1 isodir.1 isoinfo.1 isoread.1 join.1 kill.1 \ last.1 leave.1 loadfont.1 loadkeys.1 logger.1 login.1 \ look.1 lp.1 ls.1 lspci.1 M.1 mail.1 \ diff --git a/man/man1/fsck.1 b/man/man1/fsck.mfs.1 similarity index 100% rename from man/man1/fsck.1 rename to man/man1/fsck.mfs.1 diff --git a/nbsd_include/arch/i386/include/param.h b/nbsd_include/arch/i386/include/param.h index 4a42fa9a9..fa6114c51 100644 --- a/nbsd_include/arch/i386/include/param.h +++ b/nbsd_include/arch/i386/include/param.h @@ -66,6 +66,9 @@ #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */ #endif +#define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ +#define DEV_BSIZE (1 << DEV_BSHIFT) + /* * Mach derived conversion macros */ diff --git a/nbsd_include/arch/x86/include/Makefile b/nbsd_include/arch/x86/include/Makefile index c568c8e9b..b3e09b337 100644 --- a/nbsd_include/arch/x86/include/Makefile +++ b/nbsd_include/arch/x86/include/Makefile @@ -5,6 +5,7 @@ INCSDIR=/usr/include/x86 INCS= float.h \ ieee.h \ ieeefp.h \ - math.h + math.h \ + mutex.h .include diff --git a/nbsd_include/arch/x86/include/mutex.h b/nbsd_include/arch/x86/include/mutex.h new file mode 100644 index 000000000..d3c6a2d10 --- /dev/null +++ b/nbsd_include/arch/x86/include/mutex.h @@ -0,0 +1,80 @@ +/* $NetBSD: mutex.h,v 1.6 2009/04/24 17:49:51 ad Exp $ */ + +/*- + * Copyright (c) 2002, 2006, 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe and Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _X86_MUTEX_H_ +#define _X86_MUTEX_H_ + +struct kmutex { + union { + volatile uintptr_t mtxa_owner; +#ifdef __MUTEX_PRIVATE + struct { + volatile uint8_t mtxs_dummy; + ipl_cookie_t mtxs_ipl; + __cpu_simple_lock_t mtxs_lock; + volatile uint8_t mtxs_unused; + } s; +#endif + } u; +}; + +#ifdef __MUTEX_PRIVATE + +#define mtx_owner u.mtxa_owner +#define mtx_ipl u.s.mtxs_ipl +#define mtx_lock u.s.mtxs_lock + +#define __HAVE_MUTEX_STUBS 1 +#define __HAVE_SPIN_MUTEX_STUBS 1 +#define __HAVE_SIMPLE_MUTEXES 1 + +/* + * MUTEX_RECEIVE: technically, no memory barrier is required + * as 'ret' implies a load fence. However we need this to + * handle a bug with some Opteron revisions. See patch.c, + * lock_stubs.S. + */ +#define MUTEX_RECEIVE(mtx) membar_consumer() + +/* + * MUTEX_GIVE: no memory barrier required, as _lock_cas() will take care of it. + */ +#define MUTEX_GIVE(mtx) /* nothing */ + +#define MUTEX_CAS(p, o, n) \ + (_atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o)) + +unsigned long _atomic_cas_ulong(volatile unsigned long *, + unsigned long, unsigned long); + +#endif /* __MUTEX_PRIVATE */ + +#endif /* _X86_MUTEX_H_ */ diff --git a/nbsd_include/sys/mount.h b/nbsd_include/sys/mount.h index 5abe7e093..4dce2f119 100644 --- a/nbsd_include/sys/mount.h +++ b/nbsd_include/sys/mount.h @@ -1,6 +1,43 @@ #ifndef _SYS_MOUNT_H #define _SYS_MOUNT_H_ +/* + * File system types. + */ +#define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */ +#define MOUNT_UFS MOUNT_FFS /* for compatibility */ +#define MOUNT_NFS "nfs" /* Network Filesystem */ +#define MOUNT_MFS "mfs" /* Memory Filesystem */ +#define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */ +#define MOUNT_LFS "lfs" /* Log-based Filesystem */ +#define MOUNT_FDESC "fdesc" /* File Descriptor Filesystem */ +#define MOUNT_NULL "null" /* Minimal Filesystem Layer */ +#define MOUNT_OVERLAY "overlay" /* Minimal Overlay Filesystem Layer */ +#define MOUNT_UMAP "umap" /* User/Group Identifier Remapping Filesystem */ +#define MOUNT_KERNFS "kernfs" /* Kernel Information Filesystem */ +#define MOUNT_PROCFS "procfs" /* /proc Filesystem */ +#define MOUNT_AFS "afs" /* Andrew Filesystem */ +#define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */ +#define MOUNT_UNION "union" /* Union (translucent) Filesystem */ +#define MOUNT_ADOSFS "adosfs" /* AmigaDOS Filesystem */ +#define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */ +#define MOUNT_CFS "coda" /* Coda Filesystem */ +#define MOUNT_CODA MOUNT_CFS /* Coda Filesystem */ +#define MOUNT_FILECORE "filecore" /* Acorn Filecore Filesystem */ +#define MOUNT_NTFS "ntfs" /* Windows/NT Filesystem */ +#define MOUNT_SMBFS "smbfs" /* CIFS (SMB) */ +#define MOUNT_PTYFS "ptyfs" /* Pseudo tty filesystem */ +#define MOUNT_TMPFS "tmpfs" /* Efficient memory file-system */ +#define MOUNT_UDF "udf" /* UDF CD/DVD filesystem */ +#define MOUNT_SYSVBFS "sysvbfs" /* System V Boot Filesystem */ +#define MOUNT_PUFFS "puffs" /* Pass-to-Userspace filesystem */ +#define MOUNT_HFS "hfs" /* Apple HFS+ Filesystem */ +#define MOUNT_EFS "efs" /* SGI's Extent Filesystem */ +#define MOUNT_ZFS "zfs" /* Sun ZFS */ +#define MOUNT_NILFS "nilfs" /* NTT's NiLFS(2) logging file system */ +#define MOUNT_RUMPFS "rumpfs" /* rump virtual file system */ +#define MOUNT_V7FS "v7fs" /* 7th Edition of Unix Filesystem */ + #include #include diff --git a/sbin/Makefile b/sbin/Makefile new file mode 100644 index 000000000..0b8c6276a --- /dev/null +++ b/sbin/Makefile @@ -0,0 +1,7 @@ +# Makefile for bin + +.include + +SUBDIR= fsck + +.include diff --git a/sbin/Makefile.inc b/sbin/Makefile.inc new file mode 100644 index 000000000..9fd04f1bb --- /dev/null +++ b/sbin/Makefile.inc @@ -0,0 +1,6 @@ +.include + +CPPFLAGS+= -D_NETBSD_SOURCE + +BINDIR?=/sbin + diff --git a/sbin/fsck/Makefile b/sbin/fsck/Makefile new file mode 100644 index 000000000..87d57f7a9 --- /dev/null +++ b/sbin/fsck/Makefile @@ -0,0 +1,13 @@ +# $NetBSD: Makefile,v 1.18 2009/06/05 21:52:31 haad Exp $ + +PROG= fsck +SRCS= fsck.c fsutil.c preen.c +MAN= fsck.8 + +LDADD+=-lutil +DPADD+=${LIBUTIL} + +LDADD+=-lprop +DPADD+=${LIBPROP} + +.include diff --git a/sbin/fsck/exitvalues.h b/sbin/fsck/exitvalues.h new file mode 100644 index 000000000..732cbed26 --- /dev/null +++ b/sbin/fsck/exitvalues.h @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#define FSCK_EXIT_OK 0 +#define FSCK_EXIT_USAGE 1 +#define FSCK_EXIT_UNRESOLVED 2 +#define FSCK_EXIT_ROOT_CHANGED 4 +#define FSCK_EXIT_CHECK_FAILED 8 +#define FSCK_EXIT_SIGNALLED 12 diff --git a/sbin/fsck/fsck.8 b/sbin/fsck/fsck.8 new file mode 100644 index 000000000..f4a7a2f1d --- /dev/null +++ b/sbin/fsck/fsck.8 @@ -0,0 +1,176 @@ +.\" $NetBSD: fsck.8,v 1.38 2011/04/28 12:16:10 wiz Exp $ +.\" +.\" Copyright (c) 1996 Christos Zoulas. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd February 17, 2010 +.Dt FSCK 8 +.Os +.Sh NAME +.Nm fsck +.Nd file system consistency check and interactive repair +.Sh SYNOPSIS +.Nm +.Op Fl dfnPpqvy +.Op Fl l Ar maxparallel +.Op Fl T Ar fstype:fsoptions +.Op Fl t Ar fstype +.Op Fl x Ar mountpoint +.Op special | node ... +.Sh DESCRIPTION +The +.Nm +command invokes file system-specific programs to check +the special devices listed in the +.Xr fstab 5 +file or in the command line for consistency. +.Pp +It is normally used in the script +.Pa /etc/rc +during automatic reboot. +If no file systems are specified, and +.Dq preen +mode is enabled ( +.Fl p +option) +.Nm +reads the table +.Pa /etc/fstab +to determine which file systems to check, in what order. +Only partitions in fstab that are mounted ``rw,'' ``rq'' or ``ro'' +and that have non-zero pass number are checked. +File systems with pass number 1 (normally just the root file system) +are checked one at a time. +When pass 1 completes, all remaining file systems are checked, +running one process per disk drive. +By default, file systems which are already mounted read-write are not checked. +The disk drive containing each file system is inferred from the longest prefix +of the device name that ends in a digit; the remaining characters are assumed +to be the partition designator. +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl d +Debugging mode. +Just print the commands without executing them. +.It Fl f +Force checking of file systems, even when they are marked clean (for file +systems that support this), or when they are mounted read-write. +.It Fl l Ar maxparallel +Limit the number of parallel checks to the number specified in +the following argument. +By default, the limit is the number of disks, running one process per disk. +If a smaller limit is given, the disks are checked round-robin, +one file system at a time. +.It Fl n +Causes +.Nm +to assume no as the answer to all operator questions, except "CONTINUE?". +.It Fl P +Display a progress meter for each file system check. +This option also disables parallel checking. +Note that progress meters are not supported by all file system types. +.It Fl p +Enter preen mode. +In preen mode, +.Nm +will check all file systems listed in +.Pa /etc/fstab +according to their pass number, and will make minor repairs without +human intervention. +.It Fl q +Quiet mode, do not output any messages for clean filesystems. +.It Fl T Ar fstype:fsoptions +List of comma separated file system specific options for the specified +file system type, in the same format as +.Xr mount 8 . +.It Fl t Ar fstype +Invoke +.Nm +only for the comma separated list of file system types. +If the list starts with +.Dq no +then invoke +.Nm +for the file system types that are not specified in the list. +.It Fl v +Print the commands before executing them. +.It Fl x Ar mountpoint +Exclude the filesystem which has a +.Ar mountpoint +the same as in +.Pa /etc/fstab . +Used only in +.Dq preen +mode. +.It Fl y +Causes +.Nm +to assume yes +as the answer to all operator questions. +.El +.Sh FILES +.Bl -tag -width /etc/fstab -compact +.It Pa /etc/fstab +file system table +.El +.Sh EXIT STATUS +.Nm +exits with +.Dv 0 +on success. +Any major problems will cause +.Nm +to exit with the following non-zero +.Xr exit 3 +codes, so as to alert any invoking program or script that human +intervention is required. +.Bl -tag -width XXXX +.It Dv 1 +Usage problem. +.It Dv 2 +Unresolved errors while checking the filesystem. +Re-running +.Nm +on the filesystem(s) is required. +.It Dv 4 +The root filesystem was changed in the process of checking, and updating the +mount was unsuccessful. +A reboot (without sync) is required. +.It Dv 8 +The filesystem check has failed, and a subsequent check is required +that will require human intervention. +.It Dv 12 +.Nm +exited because of the result of a signal (usually +.Dv SIGINT +or +.Dv SIGQUIT +from the terminal). +.El +.Sh SEE ALSO +.Xr fstab 5 , +.Xr fsck_ext2fs 8 , +.Xr fsck_ffs 8 , +.Xr fsck_lfs 8 , +.Xr fsck_msdos 8 , +.Xr mount 8 diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c new file mode 100644 index 000000000..4bf0296e0 --- /dev/null +++ b/sbin/fsck/fsck.c @@ -0,0 +1,604 @@ +/* $NetBSD: fsck.c,v 1.49 2010/02/24 13:56:07 hannken Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. All rights reserved. + * Copyright (c) 1980, 1989, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * From: @(#)mount.c 8.19 (Berkeley) 4/19/94 + * From: NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp + * + */ + +#include +#ifndef lint +__RCSID("$NetBSD: fsck.c,v 1.49 2010/02/24 13:56:07 hannken Exp $"); +#endif /* not lint */ + +#include +#include +#include +#include +#define FSTYPENAMES +#define FSCKNAMES +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "pathnames.h" +#include "fsutil.h" +#include "exitvalues.h" + +static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST; + +TAILQ_HEAD(fstypelist, entry) opthead, selhead, omhead; + +struct entry { + char *type; + char *options; + TAILQ_ENTRY(entry) entries; +}; + +static int maxrun = 0; +static char *options = NULL; +static int flags = 0; + +static int checkfs(const char *, const char *, const char *, void *, pid_t *); +static int selected(const char *); +static int omitted(const char *); +static void addoption(char *); +static const char *getoptions(const char *); +static void addentry(struct fstypelist *, const char *, const char *); +static void maketypelist(char *); +static void catopt(char **, const char *); +static void mangle(char *, int *, const char ** volatile *, int *); +static const char *getfslab(const char *); +static void usage(void); +static void *isok(struct fstab *); + +int +main(int argc, char *argv[]) +{ + struct fstab *fs; + int i, rval; + const char *vfstype = NULL; + char globopt[3]; + int ret = FSCK_EXIT_OK; + + globopt[0] = '-'; + globopt[2] = '\0'; + + TAILQ_INIT(&selhead); + TAILQ_INIT(&opthead); + TAILQ_INIT(&omhead); + + while ((i = getopt(argc, argv, "dfl:nPpqT:t:vx:y")) != -1) { + switch (i) { + case 'd': + flags |= CHECK_DEBUG; + continue; + + case 'f': + flags |= CHECK_FORCE; + break; + + case 'n': + flags |= CHECK_NOFIX; + break; + + case 'p': + flags |= CHECK_PREEN; + break; + + case 'P': + flags |= CHECK_PROGRESS; + break; + + case 'q': + break; + + case 'l': + maxrun = atoi(optarg); + continue; + + case 'T': + if (*optarg) + addoption(optarg); + continue; + + case 't': + if (TAILQ_FIRST(&selhead) != NULL) + errx(1, "only one -t option may be specified."); + + maketypelist(optarg); + vfstype = optarg; + continue; + + case 'v': + flags |= CHECK_VERBOSE; + continue; + + case 'x': + addentry(&omhead, optarg, ""); + continue; + + case 'y': + break; + + case '?': + default: + usage(); + /* NOTREACHED */ + } + + /* Pass option to fsck_xxxfs */ + globopt[1] = i; + catopt(&options, globopt); + } + + /* Don't do progress meters if we're debugging. */ + if (flags & CHECK_DEBUG) + flags &= ~CHECK_PROGRESS; + + /* + * If progress meters are being used, force max parallel to 1 + * so the progress meter outputs don't interfere with one another. + */ + if (flags & CHECK_PROGRESS) + maxrun = 1; + + argc -= optind; + argv += optind; + + if (argc == 0) + return checkfstab(flags, maxrun, isok, checkfs); + +#define BADTYPE(type) \ + (strcmp(type, FSTAB_RO) && \ + strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) + + + for (; argc--; argv++) { + const char *spec, *type, *cp; + char device[MAXPATHLEN]; + + spec = *argv; + cp = strrchr(spec, '/'); + if (cp == 0) { + (void)snprintf(device, sizeof(device), "%s%s", + _PATH_DEV, spec); + spec = device; + } + if ((fs = getfsfile(spec)) == NULL && + (fs = getfsspec(spec)) == NULL) { + if (vfstype == NULL) + vfstype = getfslab(spec); + type = vfstype; + } + else { + spec = fs->fs_spec; + type = fs->fs_vfstype; + if (BADTYPE(fs->fs_type)) + errx(FSCK_EXIT_CHECK_FAILED, + "%s has unknown file system type.", + spec); + } + + rval = checkfs(type, blockcheck(spec), *argv, NULL, NULL); + if (rval > ret) + ret = rval; + } + + return ret; +} + + +static void * +isok(struct fstab *fs) +{ + + if (fs->fs_passno == 0) + return NULL; + + if (BADTYPE(fs->fs_type)) + return NULL; + + if (!selected(fs->fs_vfstype)) + return NULL; + + if (omitted(fs->fs_file)) + return NULL; + + return fs; +} + + +static int +checkfs(const char *vfst, const char *spec, const char *mntpt, void *auxarg, + pid_t *pidp) +{ + /* List of directories containing fsck_xxx subcommands. */ + static const char *edirs[] = { +#ifdef RESCUEDIR + RESCUEDIR, +#endif + _PATH_SBIN, + _PATH_USRSBIN, +#ifdef __minix + "/usr/pkg/sbin/", +#endif + NULL + }; + const char ** volatile argv, **edir; + const char * volatile vfstype = vfst; + pid_t pid; + int argc, i, status, maxargc; + char *optb; + char *volatile optbuf; + char execname[MAXPATHLEN + 1], execbase1[MAXPATHLEN], execbase2[MAXPATHLEN]; + const char *extra = getoptions(vfstype); + + if (!strcmp(vfstype, "ufs")) + vfstype = MOUNT_UFS; + + optb = NULL; + if (options) + catopt(&optb, options); + if (extra) + catopt(&optb, extra); + optbuf = optb; + + maxargc = 64; + argv = emalloc(sizeof(char *) * maxargc); + + (void) snprintf(execbase1, sizeof(execbase1), "fsck_%s", vfstype); + (void) snprintf(execbase2, sizeof(execbase2), "fsck.%s", vfstype); + argc = 0; + argv[argc++] = execbase1; + if (optbuf) + mangle(optbuf, &argc, &argv, &maxargc); + argv[argc++] = spec; + argv[argc] = NULL; + + if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) { + (void)printf("start %s %swait", mntpt, + pidp ? "no" : ""); + for (i = 0; i < argc; i++) + (void)printf(" %s", argv[i]); + (void)printf("\n"); + } + + switch (pid = vfork()) { + case -1: /* Error. */ + warn("vfork"); + if (optbuf) + free(optbuf); + free(argv); + return FSCK_EXIT_CHECK_FAILED; + + case 0: /* Child. */ +#ifndef __minix + if ((flags & CHECK_FORCE) == 0) { + struct statvfs sfs; + + /* + * if mntpt is a mountpoint of a mounted file + * system and it's mounted read-write, skip it + * unless -f is given. + */ + if ((statvfs(mntpt, &sfs) == 0) && + (strcmp(mntpt, sfs.f_mntonname) == 0) && + ((sfs.f_flag & MNT_RDONLY) == 0)) { + printf( + "%s: file system is mounted read-write on %s; not checking\n", + spec, mntpt); + if ((flags & CHECK_PREEN) && auxarg != NULL) + _exit(FSCK_EXIT_OK); /* fsck -p */ + else + _exit(FSCK_EXIT_CHECK_FAILED); /* fsck [[-p] ...] */ + } + } +#endif + + if (flags & CHECK_DEBUG) + _exit(FSCK_EXIT_OK); + + /* Go find an executable. */ + edir = edirs; + do { + (void)snprintf(execname, + sizeof(execname), "%s/%s", *edir, execbase1); + execv(execname, (char * const *)__UNCONST(argv)); + if (errno != ENOENT) { + if (spec) + warn("exec %s for %s", execname, spec); + else + warn("exec %s", execname); + } + (void)snprintf(execname, + sizeof(execname), "%s/%s", *edir, execbase2); + execv(execname, (char * const *)__UNCONST(argv)); + if (errno != ENOENT) { + if (spec) + warn("exec %s for %s", execname, spec); + else + warn("exec %s", execname); + } + } while (*++edir != NULL); + + if (errno == ENOENT) { + if (spec) + warn("exec %s for %s", execname, spec); + else + warn("exec %s", execname); + } + _exit(FSCK_EXIT_CHECK_FAILED); + /* NOTREACHED */ + + default: /* Parent. */ + if (optbuf) + free(optbuf); + free(argv); + + if (pidp) { + *pidp = pid; + return FSCK_EXIT_OK; + } + + if (waitpid(pid, &status, 0) < 0) { + warn("waitpid"); + return FSCK_EXIT_CHECK_FAILED; + } + + if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) + return WEXITSTATUS(status); + } + else if (WIFSIGNALED(status)) { + warnx("%s: %s", spec, strsignal(WTERMSIG(status))); + return FSCK_EXIT_CHECK_FAILED; + } + break; + } + + return FSCK_EXIT_OK; +} + + +static int +selected(const char *type) +{ + struct entry *e; + + /* If no type specified, it's always selected. */ + TAILQ_FOREACH(e, &selhead, entries) + if (!strcmp(e->type, type)) + return which == IN_LIST ? 1 : 0; + + return which == IN_LIST ? 0 : 1; +} + + +static int +omitted(const char *mountedon) +{ + struct entry *e; + + /* If no type specified, it's always selected. */ + TAILQ_FOREACH(e, &omhead, entries) + if (!strcmp(e->type, mountedon)) + return 1; + + return 0; +} + + +static const char * +getoptions(const char *type) +{ + struct entry *e; + + TAILQ_FOREACH(e, &opthead, entries) + if (!strcmp(e->type, type)) + return e->options; + return ""; +} + + +static void +addoption(char *optstr) +{ + char *newoptions; + struct entry *e; + + if ((newoptions = strchr(optstr, ':')) == NULL) + errx(1, "Invalid option string"); + + *newoptions++ = '\0'; + + TAILQ_FOREACH(e, &opthead, entries) + if (!strcmp(e->type, optstr)) { + catopt(&e->options, newoptions); + return; + } + addentry(&opthead, optstr, newoptions); +} + + +static void +addentry(struct fstypelist *list, const char *type, const char *opts) +{ + struct entry *e; + + e = emalloc(sizeof(struct entry)); + e->type = estrdup(type); + e->options = estrdup(opts); + TAILQ_INSERT_TAIL(list, e, entries); +} + + +static void +maketypelist(char *fslist) +{ + char *ptr; + + if ((fslist == NULL) || (fslist[0] == '\0')) + errx(1, "empty type list"); + + if (fslist[0] == 'n' && fslist[1] == 'o') { + fslist += 2; + which = NOT_IN_LIST; + } + else + which = IN_LIST; + + while ((ptr = strsep(&fslist, ",")) != NULL) + addentry(&selhead, ptr, ""); + +} + + +static void +catopt(char **sp, const char *o) +{ + char *s; + size_t i, j; + + s = *sp; + if (s) { + i = strlen(s); + j = i + 1 + strlen(o) + 1; + s = erealloc(s, j); + (void)snprintf(s + i, j, ",%s", o); + } else + s = estrdup(o); + *sp = s; +} + + +static void +mangle(char *opts, int *argcp, const char ** volatile *argvp, int *maxargcp) +{ + char *p, *s; + int argc, maxargc; + const char **argv; + + argc = *argcp; + argv = *argvp; + maxargc = *maxargcp; + + for (s = opts; (p = strsep(&s, ",")) != NULL;) { + /* Always leave space for one more argument and the NULL. */ + if (argc >= maxargc - 3) { + maxargc <<= 1; + argv = erealloc(argv, maxargc * sizeof(char *)); + } + if (*p != '\0') { + if (*p == '-') { + argv[argc++] = p; + p = strchr(p, '='); + if (p) { + *p = '\0'; + argv[argc++] = p+1; + } + } else { + argv[argc++] = "-o"; + argv[argc++] = p; + } + } + } + + *argcp = argc; + *argvp = argv; + *maxargcp = maxargc; +} + +static const char * +getfslab(const char *str) +{ + static struct dkwedge_info dkw; + struct disklabel dl; + int fd; + char p; + const char *vfstype; + u_char t; + + /* deduce the file system type from the disk label */ + if ((fd = open(str, O_RDONLY)) == -1) + err(1, "cannot open `%s'", str); + + /* First check to see if it's a wedge. */ + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0) { + /* Yup, this is easy. */ + (void) close(fd); + return (dkw.dkw_ptype); + } + + if (ioctl(fd, DIOCGDINFO, &dl) == -1) + err(1, "cannot get disklabel for `%s'", str); + + (void) close(fd); + + p = str[strlen(str) - 1]; + + if ((p - 'a') >= dl.d_npartitions) + errx(1, "partition `%s' is not defined on disk", str); + + if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES) + errx(1, "partition `%s' is not of a legal vfstype", + str); + + if ((vfstype = fscknames[t]) == NULL) + errx(1, "vfstype `%s' on partition `%s' is not supported", + fstypenames[t], str); + + return vfstype; +} + + +static void +usage(void) +{ + static const char common[] = + "[-dfnPpqvy] [-x excludemount] [-l maxparallel] [-T fstype:fsoptions]\n\t\t[-t fstype]"; + + (void)fprintf(stderr, "usage: %s %s [special|node]...\n", + getprogname(), common); + exit(FSCK_EXIT_USAGE); +} diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c new file mode 100644 index 000000000..b249a3ea8 --- /dev/null +++ b/sbin/fsck/fsutil.c @@ -0,0 +1,306 @@ +/* $NetBSD: fsutil.c,v 1.20 2011/06/09 19:57:50 christos Exp $ */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +__RCSID("$NetBSD: fsutil.c,v 1.20 2011/06/09 19:57:50 christos Exp $"); +#endif /* not lint */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "fsutil.h" +#include "exitvalues.h" + +static const char *dev = NULL; +static int hot = 0; +static int preen = 0; +int quiet; +#define F_ERROR 0x80000000 + +void +setcdevname(const char *cd, int pr) +{ + + dev = cd; + preen = pr; +} + +const char * +cdevname(void) +{ + + return dev; +} + +int +hotroot(void) +{ + + return hot; +} + +/*VARARGS*/ +void +errexit(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + (void) vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, "\n"); + exit(FSCK_EXIT_CHECK_FAILED); +} + +void +vmsg(int fatal, const char *fmt, va_list ap) +{ + int serr = fatal & F_ERROR; + int serrno = errno; + fatal &= ~F_ERROR; + + if (!fatal && preen) + (void)printf("%s: ", dev); + if (quiet && !preen) { + (void)printf("** %s (vmsg)\n", dev); + quiet = 0; + } + + (void) vprintf(fmt, ap); + if (serr) + printf(" (%s)", strerror(serrno)); + + if (fatal && preen) + (void) printf("\n"); + + if (fatal && preen) { + (void) printf( + "%s: UNEXPECTED INCONSISTENCY; RUN %s MANUALLY.\n", + dev, getprogname()); + exit(FSCK_EXIT_CHECK_FAILED); + } +} + +/*VARARGS*/ +void +pfatal(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vmsg(1, fmt, ap); + va_end(ap); +} + +/*VARARGS*/ +void +pwarn(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vmsg(0, fmt, ap); + va_end(ap); +} + +void +perr(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vmsg(1 | F_ERROR, fmt, ap); + va_end(ap); +} + +void +panic(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vmsg(1, fmt, ap); + va_end(ap); + exit(FSCK_EXIT_CHECK_FAILED); +} + +const char * +unrawname(const char *name) +{ + static char unrawbuf[MAXPATHLEN]; + const char *dp; + struct stat stb; + + if ((dp = strrchr(name, '/')) == 0) + return (name); + if (stat(name, &stb) < 0) + return (name); + if (!S_ISCHR(stb.st_mode)) + return (name); + if (dp[1] != 'r') + return (name); + (void)snprintf(unrawbuf, sizeof(unrawbuf), "%.*s/%s", + (int)(dp - name), name, dp + 2); + return (unrawbuf); +} + +const char * +rawname(const char *name) +{ + static char rawbuf[MAXPATHLEN]; + const char *dp; + + if ((dp = strrchr(name, '/')) == 0) + return (0); + (void)snprintf(rawbuf, sizeof(rawbuf), "%.*s/r%s", + (int)(dp - name), name, dp + 1); + return (rawbuf); +} + +const char * +blockcheck(const char *origname) +{ +#ifdef __minix + return origname; +#else + struct stat stslash, stblock, stchar; + const char *newname, *raw; + struct fstab *fsp; + int retried = 0; + + hot = 0; + if (stat("/", &stslash) < 0) { + perr("Can't stat `/'"); + return (origname); + } + newname = origname; +retry: + if (stat(newname, &stblock) < 0) { + perr("Can't stat `%s'", newname); + return (origname); + } + if (S_ISBLK(stblock.st_mode)) { + if (stslash.st_dev == stblock.st_rdev) + hot++; + raw = strdup(newname); + raw = rawname(newname); + if (stat(raw, &stchar) < 0) { + perr("Can't stat `%s'", raw); + return (origname); + } + if (S_ISCHR(stchar.st_mode)) { + return (raw); + } else { + printf("%s is not a character device\n", raw); + return (origname); + } + } else if (S_ISCHR(stblock.st_mode) && !retried) { + newname = unrawname(newname); + retried++; + goto retry; + } else if ((fsp = getfsfile(newname)) != 0 && !retried) { + newname = fsp->fs_spec; + retried++; + goto retry; + } + /* + * Not a block or character device, just return name and + * let the user decide whether to use it. + */ + return (origname); +#endif +} + +const char * +print_mtime(time_t t) +{ + static char b[128]; + char *p = ctime(&t); + if (p != NULL) + (void)snprintf(b, sizeof(b), "%12.12s %4.4s ", &p[4], &p[20]); + else + (void)snprintf(b, sizeof(b), "%lld ", (long long)t); + return b; +} + + +void +catch(int n) +{ + if (ckfinish) (*ckfinish)(0); + _exit(FSCK_EXIT_SIGNALLED); +} + +/* + * When preening, allow a single quit to signal + * a special exit after filesystem checks complete + * so that reboot sequence may be interrupted. + */ +void +catchquit(int n) +{ + static const char msg[] = + "returning to single-user after filesystem check\n"; + int serrno = errno; + + (void)write(STDOUT_FILENO, msg, sizeof(msg) - 1); + returntosingle = 1; + (void)signal(SIGQUIT, SIG_DFL); + errno = serrno; +} + +/* + * Ignore a single quit signal; wait and flush just in case. + * Used by child processes in preen. + */ +void +voidquit(int n) +{ + int serrno = errno; + + sleep(1); + (void)signal(SIGQUIT, SIG_IGN); + (void)signal(SIGQUIT, SIG_DFL); + errno = serrno; +} diff --git a/sbin/fsck/fsutil.h b/sbin/fsck/fsutil.h new file mode 100644 index 000000000..cc3f0c3bf --- /dev/null +++ b/sbin/fsck/fsutil.h @@ -0,0 +1,65 @@ +/* $NetBSD: fsutil.h,v 1.17 2011/06/09 21:23:29 christos Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +void errexit(const char *, ...) + __attribute__((__noreturn__,__format__(__printf__,1,2))); +void pfatal(const char *, ...) + __attribute__((__format__(__printf__,1,2))); +void pwarn(const char *, ...) + __attribute__((__format__(__printf__,1,2))); +void perr(const char *, ...) + __attribute__((__format__(__printf__,1,2))); +void panic(const char *, ...) + __attribute__((__noreturn__,__format__(__printf__,1,2))); +void vmsg(int, const char *, va_list) + __attribute__((__format__(__printf__,2,0))); +const char *rawname(const char *); +const char *unrawname(const char *); +const char *blockcheck(const char *); +const char *cdevname(void); +void setcdevname(const char *, int); +int hotroot(void); +const char *print_mtime(time_t); + +#define CHECK_PREEN 1 +#define CHECK_VERBOSE 2 +#define CHECK_DEBUG 4 +#define CHECK_FORCE 8 +#define CHECK_PROGRESS 16 +#define CHECK_NOFIX 32 + +struct fstab; +int checkfstab(int, int, void *(*)(struct fstab *), + int (*) (const char *, const char *, const char *, void *, pid_t *)); + +void (*ckfinish)(int); +volatile sig_atomic_t returntosingle; +void catch(int); +void catchquit(int); +void voidquit(int); diff --git a/sbin/fsck/partutil.c b/sbin/fsck/partutil.c new file mode 100644 index 000000000..4d626619a --- /dev/null +++ b/sbin/fsck/partutil.c @@ -0,0 +1,205 @@ +/* $NetBSD: partutil.c,v 1.10 2010/03/06 00:30:54 christos Exp $ */ + +/*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__RCSID("$NetBSD: partutil.c,v 1.10 2010/03/06 00:30:54 christos Exp $"); + +#include +#include +#include +#include +#include + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "partutil.h" + +/* + * Convert disklabel geometry info to disk_geom. + */ +static void +label2geom(struct disk_geom *geo, const struct disklabel *lp) +{ + geo->dg_secperunit = lp->d_secperunit; + geo->dg_secsize = lp->d_secsize; + geo->dg_nsectors = lp->d_nsectors; + geo->dg_ntracks = lp->d_ntracks; + geo->dg_ncylinders = lp->d_ncylinders; + geo->dg_secpercyl = lp->d_secpercyl; + geo->dg_pcylinders = lp->d_ncylinders; + geo->dg_sparespertrack = lp->d_sparespertrack; + geo->dg_sparespercyl = lp->d_sparespercyl; + geo->dg_acylinders = lp->d_acylinders; +} + +/* + * Set what we need to know about disk geometry. + */ +static void +dict2geom(struct disk_geom *geo, prop_dictionary_t dict) +{ + (void)memset(geo, 0, sizeof(struct disk_geom)); + prop_dictionary_get_int64(dict, "sectors-per-unit", + &geo->dg_secperunit); + prop_dictionary_get_uint32(dict, "sector-size", &geo->dg_secsize); + prop_dictionary_get_uint32(dict, "sectors-per-track", + &geo->dg_nsectors); + prop_dictionary_get_uint32(dict, "tracks-per-cylinder", + &geo->dg_ntracks); + prop_dictionary_get_uint32(dict, "cylinders-per-unit", + &geo->dg_ncylinders); +} + + +static void +part2wedge(struct dkwedge_info *dkw, const struct disklabel *lp, const char *s) +{ + struct stat sb; + const struct partition *pp; + int ptn; + + (void)memset(dkw, 0, sizeof(*dkw)); + if (stat(s, &sb) == -1) + return; + + ptn = strchr(s, '\0')[-1] - 'a'; + if ((unsigned)ptn >= lp->d_npartitions || + (devminor_t)ptn != DISKPART(sb.st_rdev)) + return; + + pp = &lp->d_partitions[ptn]; + dkw->dkw_offset = pp->p_offset; + dkw->dkw_size = pp->p_size; + dkw->dkw_parent[0] = '*'; + switch (pp->p_fstype) { + default: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_UNKNOWN); + break; + case FS_UNUSED: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_UNUSED); + break; + case FS_SWAP: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_SWAP); + break; + case FS_BSDFFS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_FFS); + break; + case FS_BSDLFS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_LFS); + break; + case FS_EX2FS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_EXT2FS); + break; + case FS_ISO9660: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_ISO9660); + break; + case FS_ADOS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_AMIGADOS); + break; + case FS_HFS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_APPLEHFS); + break; + case FS_MSDOS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_FAT); + break; + case FS_FILECORE: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_FILECORE); + break; + case FS_APPLEUFS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_APPLEUFS); + break; + case FS_NTFS: + (void)strcpy(dkw->dkw_ptype, DKW_PTYPE_NTFS); + break; + } +} + +int +getdiskinfo(const char *s, int fd, const char *dt, struct disk_geom *geo, + struct dkwedge_info *dkw) +{ + struct disklabel lab; + struct disklabel *lp = &lab; + prop_dictionary_t disk_dict, geom_dict; + + if (dt) { +#ifdef __minix + errx(1, "minix doesn't know about disk types (%s)", dt); +#else + lp = getdiskbyname(dt); + if (lp == NULL) + errx(1, "unknown disk type `%s'", dt); +#endif + } + + /* Get disk description dictionary */ +#ifndef __minix + if (prop_dictionary_recv_ioctl(fd, DIOCGDISKINFO, &disk_dict)) { +#else + if (-1) { +#endif + /* + * Ask for disklabel if DIOCGDISKINFO failed. This is + * compatibility call and can be removed when all devices + * will support DIOCGDISKINFO. + * cgd, ccd pseudo disk drives doesn't support DIOCGDDISKINFO + */ + if (ioctl(fd, DIOCGDINFO, lp) == -1) { + warn("DIOCGDINFO on %s failed", s); + return -1; + } + label2geom(geo, lp); + } else { + geom_dict = prop_dictionary_get(disk_dict, "geometry"); + dict2geom(geo, geom_dict); + } + + /* Get info about partition/wedge */ + if (ioctl(fd, DIOCGWEDGEINFO, dkw) == -1) { + if (ioctl(fd, DIOCGDINFO, lp) == -1) + err(1, "Please implement DIOCGWEDGEINFO or " + "DIOCGDINFO for disk device %s", s); + + part2wedge(dkw, lp, s); + } + + return 0; +} diff --git a/sbin/fsck/partutil.h b/sbin/fsck/partutil.h new file mode 100644 index 000000000..189339dbf --- /dev/null +++ b/sbin/fsck/partutil.h @@ -0,0 +1,39 @@ +/* $NetBSD: partutil.h,v 1.2 2008/04/28 20:23:08 martin Exp $ */ + +/*- + * Copyright (c) 2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _PARTUTIL_H_ +#define _PARTUTIL_H_ + +__BEGIN_DECLS +int getdiskinfo(const char *, int, const char *, + struct disk_geom *, struct dkwedge_info *); +__END_DECLS + +#endif /* _PARTUTIL_H_ */ diff --git a/sbin/fsck/pathnames.h b/sbin/fsck/pathnames.h new file mode 100644 index 000000000..a7847467e --- /dev/null +++ b/sbin/fsck/pathnames.h @@ -0,0 +1,28 @@ +/* $NetBSD: pathnames.h,v 1.2 2009/10/21 01:07:46 snj Exp $ */ + +/* + * Copyright (c) 1996 Christos Zoulas. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define _PATH_SBIN "/sbin" +#define _PATH_USRSBIN "/usr/sbin" diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c new file mode 100644 index 000000000..0b8d1685a --- /dev/null +++ b/sbin/fsck/preen.c @@ -0,0 +1,363 @@ +/* $NetBSD: preen.c,v 1.30 2008/02/23 21:41:47 christos Exp $ */ + +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)preen.c 8.5 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: preen.c,v 1.30 2008/02/23 21:41:47 christos Exp $"); +#endif +#endif /* not lint */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fsutil.h" +#include "exitvalues.h" + +struct partentry { + TAILQ_ENTRY(partentry) p_entries; + char *p_devname; /* device name */ + char *p_mntpt; /* mount point */ + char *p_type; /* file system type */ + void *p_auxarg; /* auxiliary argument */ +}; + +TAILQ_HEAD(part, partentry) badh; + +struct diskentry { + TAILQ_ENTRY(diskentry) d_entries; + char *d_name; /* disk base name */ + TAILQ_HEAD(prt, partentry) d_part; /* list of partitions on disk */ + int d_pid; /* 0 or pid of fsck proc */ +}; + +TAILQ_HEAD(diskinfo, diskentry) diskh; + +static int nrun = 0, ndisks = 0; + +static struct diskentry *finddisk(const char *); +static void addpart(const char *, const char *, const char *, void *); +static int startdisk(struct diskentry *, + int (*)(const char *, const char *, const char *, void *, pid_t *)); +static void printpart(void); + +int +checkfstab(int flags, int maxrun, void *(*docheck)(struct fstab *), + int (*checkit)(const char *, const char *, const char *, void *, pid_t *)) +{ + struct fstab *fs; + struct diskentry *d, *nextdisk; + struct partentry *p; + int ret, pid, retcode, passno, sumstatus, status; + void *auxarg; + const char *name; + int error = FSCK_EXIT_OK; + + TAILQ_INIT(&badh); + TAILQ_INIT(&diskh); + + sumstatus = FSCK_EXIT_OK; + + for (passno = 1; passno <= 2; passno++) { + if (setfsent() == 0) { + warnx("Can't open checklist file: %s", _PATH_FSTAB); + return FSCK_EXIT_CHECK_FAILED; + } + while ((fs = getfsent()) != 0) { + if ((auxarg = (*docheck)(fs)) == NULL) + continue; + + name = blockcheck(fs->fs_spec); + if (flags & CHECK_DEBUG) + printf("pass %d, name %s\n", passno, name); + + if ((flags & CHECK_PREEN) == 0 || + (passno == 1 && fs->fs_passno == 1)) { + if (name == NULL) { + if (flags & CHECK_PREEN) + return FSCK_EXIT_CHECK_FAILED; + else + continue; + } + sumstatus = (*checkit)(fs->fs_vfstype, + name, fs->fs_file, auxarg, NULL); + + if (sumstatus) { + if ((flags & CHECK_NOFIX) == 0) + return sumstatus; + else if (error < sumstatus) + error = sumstatus; + } + } else if (passno == 2 && fs->fs_passno > 1) { + if (name == NULL) { + (void) fprintf(stderr, + "BAD DISK NAME %s\n", fs->fs_spec); + sumstatus = FSCK_EXIT_CHECK_FAILED; + continue; + } + addpart(fs->fs_vfstype, name, fs->fs_file, + auxarg); + } + } + if ((flags & CHECK_PREEN) == 0) + return error; + } + + if (flags & CHECK_DEBUG) + printpart(); + + if (flags & CHECK_PREEN) { + if (maxrun == 0) + maxrun = ndisks; + if (maxrun > ndisks) + maxrun = ndisks; + nextdisk = TAILQ_FIRST(&diskh); + for (passno = 0; passno < maxrun; ++passno) { + if ((ret = startdisk(nextdisk, checkit)) != 0) { + if ((flags & CHECK_NOFIX) == 0) + return ret; + else if (error < ret) + error = ret; + } + nextdisk = TAILQ_NEXT(nextdisk, d_entries); + } + + while ((pid = wait(&status)) != -1) { + TAILQ_FOREACH(d, &diskh, d_entries) + if (d->d_pid == pid) + break; + + if (d == NULL) { + warnx("Unknown pid %d", pid); + continue; + } + + + if (WIFEXITED(status)) + retcode = WEXITSTATUS(status); + else + retcode = 0; + + p = TAILQ_FIRST(&d->d_part); + + if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) + (void) printf("done %s: %s (%s) = 0x%x\n", + p->p_type, p->p_devname, p->p_mntpt, + status); + + if (WIFSIGNALED(status)) { + (void) fprintf(stderr, + "%s: %s (%s): EXITED WITH SIGNAL %d\n", + p->p_type, p->p_devname, p->p_mntpt, + WTERMSIG(status)); + retcode = FSCK_EXIT_SIGNALLED; + } + + TAILQ_REMOVE(&d->d_part, p, p_entries); + + if (retcode != 0) { + TAILQ_INSERT_TAIL(&badh, p, p_entries); + sumstatus |= retcode; + } else { + free(p->p_type); + free(p->p_devname); + free(p); + } + d->d_pid = 0; + nrun--; + + if (TAILQ_FIRST(&d->d_part) == NULL) + ndisks--; + + if (nextdisk == NULL) { + if (TAILQ_FIRST(&d->d_part) != NULL) { + if ((ret = startdisk(d, checkit)) != 0) + { + if ((flags & CHECK_NOFIX) == 0) + return ret; + else if (error < ret) + error = ret; + } + } + } else if (nrun < maxrun && nrun < ndisks) { + for ( ;; ) { + nextdisk = TAILQ_NEXT(nextdisk, + d_entries); + if (nextdisk == NULL) + nextdisk = TAILQ_FIRST(&diskh); + if (TAILQ_FIRST(&nextdisk->d_part) + != NULL && nextdisk->d_pid == 0) + break; + } + if ((ret = startdisk(nextdisk, checkit)) != 0) + { + if ((flags & CHECK_NOFIX) == 0) + return ret; + else if (error < ret) + error = ret; + } + } + } + } + if (sumstatus) { + p = TAILQ_FIRST(&badh); + if (p == NULL) + return sumstatus; + + (void) fprintf(stderr, + "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t", + TAILQ_NEXT(p, p_entries) ? "S" : "", + "UNEXPECTED INCONSISTENCY:"); + + TAILQ_FOREACH(p, &badh, p_entries) + (void) fprintf(stderr, + "%s: %s (%s)%s", p->p_type, p->p_devname, + p->p_mntpt, TAILQ_NEXT(p, p_entries) ? ", " : "\n"); + + return sumstatus; + } + (void) endfsent(); + return error; +} + + +static struct diskentry * +finddisk(const char *name) +{ + const char *p; + size_t len, dlen; + struct diskentry *d; + char buf[MAXPATHLEN]; + struct dkwedge_info dkw; + int fd; + +#ifndef __minix + if ((fd = opendisk(name, O_RDONLY, buf, sizeof(buf), 0)) != -1) { + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) + name = dkw.dkw_parent; + (void)close(fd); + } +#endif + + for (dlen = len = strlen(name), p = name + len - 1; p >= name; --p) + if (isdigit((unsigned char)*p)) { + len = p - name + 1; + break; + } + if (p < name) + len = dlen; + + TAILQ_FOREACH(d, &diskh, d_entries) + if (strncmp(d->d_name, name, len) == 0 && d->d_name[len] == 0) + return d; + + d = emalloc(sizeof(*d)); + d->d_name = estrdup(name); + d->d_name[len] = '\0'; + TAILQ_INIT(&d->d_part); + d->d_pid = 0; + + TAILQ_INSERT_TAIL(&diskh, d, d_entries); + ndisks++; + + return d; +} + + +static void +printpart(void) +{ + struct diskentry *d; + struct partentry *p; + + TAILQ_FOREACH(d, &diskh, d_entries) { + (void) printf("disk %s:", d->d_name); + TAILQ_FOREACH(p, &d->d_part, p_entries) + (void) printf(" %s", p->p_devname); + (void) printf("\n"); + } +} + + +static void +addpart(const char *type, const char *dev, const char *mntpt, void *auxarg) +{ + struct diskentry *d = finddisk(dev); + struct partentry *p; + + TAILQ_FOREACH(p, &d->d_part, p_entries) + if (strcmp(p->p_devname, dev) == 0) { + warnx("%s in fstab more than once!", dev); + return; + } + + p = emalloc(sizeof(*p)); + p->p_devname = estrdup(dev); + p->p_mntpt = estrdup(mntpt); + p->p_type = estrdup(type); + p->p_auxarg = auxarg; + + TAILQ_INSERT_TAIL(&d->d_part, p, p_entries); +} + + +static int +startdisk(struct diskentry *d, + int (*checkit)(const char *, const char *, const char *, void *, pid_t *)) +{ + struct partentry *p = TAILQ_FIRST(&d->d_part); + int rv; + + while ((rv = (*checkit)(p->p_type, p->p_devname, p->p_mntpt, + p->p_auxarg, &d->d_pid)) != 0 && nrun > 0) + sleep(10); + + if (rv == 0) + nrun++; + + return rv; +} diff --git a/sbin/fsck/progress.c b/sbin/fsck/progress.c new file mode 100644 index 000000000..9c137a06d --- /dev/null +++ b/sbin/fsck/progress.c @@ -0,0 +1,168 @@ +/* $NetBSD: progress.c,v 1.5 2009/04/11 06:48:36 lukem Exp $ */ + +/*- + * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn; by Chris Gilbert; and by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SMALL +#include +__RCSID("$NetBSD: progress.c,v 1.5 2009/04/11 06:48:36 lukem Exp $"); + +/* + * File system independent fsck progress bar routines. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "progress.h" + +static size_t ttywidth = 80; + +static int progress_onoff; +static int progress_lowlim; +static int progress_highlim; + +#define BUFLEFT (sizeof(buf) - len) + +void +progress_switch(int onoff) +{ + progress_onoff = onoff; +} + +void +progress_init(void) +{ + progress_setrange(0, 100); +} + +/* Set both low and high limit. */ +void +progress_setrange(int lowlim, int highlim) +{ + progress_lowlim = lowlim; + progress_highlim = highlim; +} + +/* Previous high limit becomes new low limit; set new high limit. */ +void +progress_sethighlim(int highlim) +{ + progress_setrange(progress_highlim, highlim); +} + +/* + * Display a progress bar, assuming that current/total represents a + * percentage in the range [progress_lowlim .. progress_highlim]. + */ +void +progress_bar(const char *dev, const char *label, off_t current, off_t total) +{ + static int lastpercentage = -1; + char buf[256]; + int len, percentage; + int barlength; + int i; + int lengthextras; + +#define BAROVERHEAD 10 /* non-* portion of progress bar */ + + /* + * stars should contain at least sizeof(buf) - BAROVERHEAD + * entries. + */ + static const char stars[] = +"*****************************************************************************" +"*****************************************************************************" +"*****************************************************************************"; + + if (progress_onoff == 0) + return; + + len = 0; + lengthextras = strlen(dev) + (label != NULL ? strlen(label) : 0); + percentage = progress_lowlim + + (current * (progress_highlim - progress_lowlim)) / total; + percentage = MAX(percentage, 0); + percentage = MIN(percentage, 100); + + if (percentage == lastpercentage) + return; + lastpercentage = percentage; + + len += snprintf(buf + len, BUFLEFT, "%s: ", dev); + if (label != NULL) + len += snprintf(buf + len, BUFLEFT, "%s ", label); + + barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD - lengthextras; + if (barlength > 0) { + i = barlength * percentage / 100; + len += snprintf(buf + len, BUFLEFT, + "|%.*s%*s| ", i, stars, barlength - i, ""); + } + len += snprintf(buf + len, BUFLEFT, "%3d%%\r", percentage); + write(fileno(stdout), buf, len); +} + +void +progress_done(void) +{ + char buf[256]; + int len; + + if (progress_onoff == 0) + return; + + len = MIN(sizeof(buf) - 2, ttywidth); + memset(buf, ' ', len); + buf[len] = '\r'; + buf[len + 1] = '\0'; + write(fileno(stdout), buf, len + 1); +} + +void +progress_ttywidth(int a) +{ + struct winsize winsize; + int oerrno = errno; + + if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1 && + winsize.ws_col != 0) + ttywidth = winsize.ws_col; + else + ttywidth = 80; + errno = oerrno; +} + +#endif /* ! SMALL */ diff --git a/sbin/fsck/progress.h b/sbin/fsck/progress.h new file mode 100644 index 000000000..d17c5e557 --- /dev/null +++ b/sbin/fsck/progress.h @@ -0,0 +1,42 @@ +/* $NetBSD: progress.h,v 1.3 2008/04/28 20:23:08 martin Exp $ */ + +/*- + * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn; by Chris Gilbert; and by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * File system independent fsck progress bar routines. + */ + +void progress_init(void); +void progress_setrange(int, int); +void progress_sethighlim(int); +void progress_switch(int); +void progress_ttywidth(int); +void progress_bar(const char *, const char *, off_t, off_t); +void progress_done(void); diff --git a/tools/nbsd_ports b/tools/nbsd_ports index b8e43afae..ea4d61148 100644 --- a/tools/nbsd_ports +++ b/tools/nbsd_ports @@ -1,4 +1,11 @@ -common/lib/libprop src/common/lib/libprop +common/lib/libprop src/common/lib/libprop +nbsd_include/ufs src/sys/ufs +sbin/newfs_ext2fs src/sbin/newfs_ext2fs +sbin/fsck_ext2fs src/sbin/fsck_ext2fs +lib/libprop src/lib/libprop +common/include/arch/x86 src/sys/arch/x86/include +common/include/arch/i386 src/sys/arch/i386/include +common/include src/common/include common/lib/libc src/common/lib/libc lib/nbsd_libc src/lib/libc lib/nbsd_libm src/lib/libm @@ -10,6 +17,7 @@ common/lib/libutil src/common/lib/libutil lib/libbz2 src/lib/libbz2 nbsd_include src/include bin/mkdir src/bin/mkdir +usr.sbin/fsck src/usr.sbin/fsck usr.bin/chpass src/usr.bin/chpass usr.bin/m4 src/usr.bin/m4 usr.bin/indent src/usr.bin/indent