1 /* $NetBSD: fstypes.c,v 1.13 2010/01/14 16:27:49 tsutsui Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
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
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"
36 #include <sys/cdefs.h>
38 __RCSID("$NetBSD: fstypes.c,v 1.13 2010/01/14 16:27:49 tsutsui Exp $");
41 #include <sys/types.h>
47 #include "installboot.h"
49 struct ib_fs fstypes
[] = {
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
},
60 hardcode_stage2(ib_params
*params
, uint32_t *maxblk
, ib_block
*blocks
)
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
);
77 if (!S_ISREG(s2sb
.st_mode
)) {
78 warnx("`%s' must be a regular file", params
->stage2
);
82 nblk
= s2sb
.st_size
/ params
->fstype
->blocksize
;
83 if (s2sb
.st_size
% params
->fstype
->blocksize
!= 0)
86 fprintf(stderr
, "for %s got size %lld blksize %u blocks %u\n",
87 params
->stage2
, s2sb
.st_size
, params
->fstype
->blocksize
, nblk
);
90 warnx("Secondary bootstrap `%s' has too many blocks "
91 "(calculated %u, maximum %u)",
92 params
->stage2
, nblk
, *maxblk
);
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
;
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");
131 return (hardcode_stage2(params
, maxblk
, blocks
));