/* $NetBSD: newfs_msdos.c,v 1.4 1999/07/26 00:28:57 cgd Exp $ */ /* * Copyright (c) 1997 Christos Zoulas * Copyright (c) 1995, 1996 Joerg Wunsch * * All rights reserved. * * This program is free software. * * 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 DEVELOPERS ``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 DEVELOPERS 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. */ /* * Create an MS-DOS (FAT) file system. * * Id: mkdosfs.c,v 1.4 1997/02/22 16:06:38 peter Exp */ #include #ifndef lint __RCSID("$NetBSD: newfs_msdos.c,v 1.4 1999/07/26 00:28:57 cgd Exp $"); #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include /* From msdosfs */ #include #include #include #include "bootcode.h" struct descrip { /* our database key */ unsigned kilobytes; /* MSDOS 3.3 BPB fields */ u_short sectsiz; u_char clustsiz; u_short ressecs; u_char fatcnt; u_short rootsiz; u_short totsecs; u_char media; u_short fatsize; u_short trksecs; u_short headcnt; u_short hidnsec; /* MSDOS 4 BPB extensions */ u_long ext_totsecs; u_short ext_physdrv; u_char ext_extboot; char ext_label[11]; char ext_fsysid[8]; }; static struct descrip table[] = { /* NB: must be sorted, starting with the largest format! */ /* * KB sec cls res fat rot tot med fsz spt hds hid * tot phs ebt label fsysid */ { 1440, 512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2, 0, 0, 0, 0, "4.4BSD ", "FAT12 " }, { 1200, 512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2, 0, 0, 0, 0, "4.4BSD ", "FAT12 " }, { 720, 512, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2, 0, 0, 0, 0, "4.4BSD ", "FAT12 " }, { 360, 512, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2, 0, 0, 0, 0, "4.4BSD ", "FAT12 " }, { 0, 0, 0, 0, 0, 0, 0, 0x00, 0, 0, 0, 0, 0, 0, 0, " ", " " } }; struct fat { u_int8_t media; /* the media descriptor again */ u_int8_t padded; /* always 0xff */ u_int8_t contents[1]; /* the `1' is a placeholder only */ }; int main __P((int, char *[])); static void usage __P((void)); static size_t findformat __P((int)); static void setup_boot_sector_from_template __P((union bootsector *, struct descrip *)); static void usage() { extern char *__progname; (void) fprintf(stderr, "Usage: %s [-f ] [-L