tools/llvm: Do not build with symbols
[minix3.git] / usr.sbin / installboot / fstypes.c
blob1b77f974fc5de0056d36bc1506944486323546cb
1 /* $NetBSD: fstypes.c,v 1.13 2010/01/14 16:27:49 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Fredette and Luke Mewburn.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #if HAVE_NBTOOL_CONFIG_H
33 #include "nbtool_config.h"
34 #endif
36 #include <sys/cdefs.h>
37 #if !defined(__lint)
38 __RCSID("$NetBSD: fstypes.c,v 1.13 2010/01/14 16:27:49 tsutsui Exp $");
39 #endif /* !__lint */
41 #include <sys/types.h>
43 #include <assert.h>
44 #include <err.h>
45 #include <stdio.h>
47 #include "installboot.h"
49 struct ib_fs fstypes[] = {
50 #ifndef NO_STAGE2
51 { .name = "ffs", .match = ffs_match, .findstage2 = ffs_findstage2 },
52 { .name = "raid", .match = raid_match, .findstage2 = ffs_findstage2 },
53 { .name = "raw", .match = raw_match, .findstage2 = raw_findstage2 },
54 #endif
55 { .name = NULL, }
58 #ifndef NO_STAGE2
59 int
60 hardcode_stage2(ib_params *params, uint32_t *maxblk, ib_block *blocks)
62 struct stat s2sb;
63 uint32_t nblk, i;
65 assert(params != NULL);
66 assert(params->stage2 != NULL);
67 assert(maxblk != NULL);
68 assert(blocks != NULL);
69 assert((params->flags & IB_STAGE2START) != 0);
70 assert(params->fstype != NULL);
71 assert(params->fstype->blocksize != 0);
73 if (stat(params->stage2, &s2sb) == -1) {
74 warn("Examining `%s'", params->stage2);
75 return (0);
77 if (!S_ISREG(s2sb.st_mode)) {
78 warnx("`%s' must be a regular file", params->stage2);
79 return (0);
82 nblk = s2sb.st_size / params->fstype->blocksize;
83 if (s2sb.st_size % params->fstype->blocksize != 0)
84 nblk++;
85 #if 0
86 fprintf(stderr, "for %s got size %lld blksize %u blocks %u\n",
87 params->stage2, s2sb.st_size, params->fstype->blocksize, nblk);
88 #endif
89 if (nblk > *maxblk) {
90 warnx("Secondary bootstrap `%s' has too many blocks "
91 "(calculated %u, maximum %u)",
92 params->stage2, nblk, *maxblk);
93 return (0);
96 for (i = 0; i < nblk; i++) {
97 blocks[i].block = params->s2start +
98 i * (params->fstype->blocksize / params->sectorsize);
99 blocks[i].blocksize = params->fstype->blocksize;
101 *maxblk = nblk;
103 return (1);
108 raw_match(ib_params *params)
111 assert(params != NULL);
112 assert(params->fstype != NULL);
114 params->fstype->blocksize = 8192; // XXX: hardcode
115 return (1); /* can always write to a "raw" file system */
119 raw_findstage2(ib_params *params, uint32_t *maxblk, ib_block *blocks)
122 assert(params != NULL);
123 assert(params->stage2 != NULL);
124 assert(maxblk != NULL);
125 assert(blocks != NULL);
127 if ((params->flags & IB_STAGE2START) == 0) {
128 warnx("Need `-B bno' for raw file systems");
129 return (0);
131 return (hardcode_stage2(params, maxblk, blocks));
133 #endif