1 /* $NetBSD: diskutil.c,v 1.3 2007/02/22 05:31:53 thorpej Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
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 #include <lib/libsa/stand.h>
33 #include <lib/libsa/ufs.h>
34 #include <lib/libkern/libkern.h>
36 #include <machine/pdinfo.h>
37 #include <machine/vtoc.h>
38 #include <machine/bfs.h>
43 struct pdinfo_sector pdinfo
;
44 struct vtoc_sector vtoc
;
50 cmd_disklabel(int argc
, char *argp
[], int interactive
)
52 struct ux_partition
*partition
;
58 partition
= vtoc
.partition
;
59 printf("Tag\tFlags\tStart\tCount\n");
60 for (i
= 0; i
< VTOC_MAXPARTITIONS
; i
++, partition
++)
61 printf(" %d %d %d\t%d\t%d\n", i
, partition
->tag
,
62 partition
->flags
, partition
->start_sector
,
69 cmd_ls(int argc
, char *argp
[], int interactive
)
74 printf("ls partition\n");
81 i
= strtoul(argp
[1], 0, 0);
82 if (i
< 0 || i
>= VTOC_MAXPARTITIONS
)
85 if (!device_attach(-1, -1, i
))
105 struct bfs_dirent
*file
;
106 struct bfs_inode
*inode
;
109 if (!DEVICE_CAPABILITY
.disk_enabled
)
112 if (bfs_init(&bfs
) != 0)
115 for (file
= bfs
->dirent
, i
= 0; i
< bfs
->max_dirent
; i
++, file
++) {
116 if (file
->inode
!= 0) {
117 inode
= &bfs
->inode
[file
->inode
- BFS_ROOT_INODE
];
118 printf("%s\t%d (%d-%d)\n", file
->name
,
119 bfs_file_size(inode
), inode
->start_sector
,
128 fstype(int partition
)
130 struct ux_partition
*p
;
135 if (partition
< 0 || partition
>= VTOC_MAXPARTITIONS
)
138 p
= &vtoc
.partition
[partition
];
139 if (p
->tag
== VTOC_TAG_STAND
)
142 if ((p
->flags
& VTOC_FLAG_UNMOUNT
) == 0)
143 return FSTYPE_UFS
; /* possibly */
149 find_partition_start(int partition
, int *sector
)
155 *sector
= pdinfo
.logical_sector
+
156 vtoc
.partition
[partition
].start_sector
;
157 printf("[partition=%d, start sector=%d]", partition
, *sector
);
166 if (!DEVICE_CAPABILITY
.disk_enabled
)
172 if (!pdinfo_sector(0, &pdinfo
)) {
173 printf("no PDINFO\n");
177 if (!vtoc_sector(0, &vtoc
, pdinfo
.logical_sector
)) {