2 * Copyright (c) 2002 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $
29 #include <sys/types.h>
30 #include <sys/diskmbr.h>
43 static bool show_guid
= false;
44 static bool show_label
= false;
45 static bool show_uuid
= false;
51 "usage: %s [-glu] device ...\n", getprogname());
58 static char *save_name1
/*= NULL*/;
59 static char *save_name2
/*= NULL*/;
64 uuid_addr_lookup(t
, &save_name1
, NULL
);
73 uuid_to_string(t
, &save_name2
, NULL
);
88 printf(" %*s", lbawidth
, "start");
89 printf(" %*s", lbawidth
, "size");
90 printf(" index contents\n");
94 printf(" %*llu", lbawidth
, (long long)m
->map_start
);
95 printf(" %*llu", lbawidth
, (long long)m
->map_size
);
98 if (m
->map_index
!= NOENTRY
)
99 printf("%5d", m
->map_index
);
104 switch (m
->map_type
) {
105 case MAP_TYPE_UNUSED
:
109 if (m
->map_start
!= 0)
113 case MAP_TYPE_PRI_GPT_HDR
:
114 printf("Pri GPT header");
116 case MAP_TYPE_SEC_GPT_HDR
:
117 printf("Sec GPT header");
119 case MAP_TYPE_PRI_GPT_TBL
:
120 printf("Pri GPT table");
122 case MAP_TYPE_SEC_GPT_TBL
:
123 printf("Sec GPT table");
125 case MAP_TYPE_MBR_PART
:
127 if (p
->map_start
!= 0)
131 for (i
= 0; i
< 4; i
++) {
132 start
= le16toh(mbr
->mbr_part
[i
].part_start_hi
);
133 start
= (start
<< 16) +
134 le16toh(mbr
->mbr_part
[i
].part_start_lo
);
135 if (m
->map_start
== p
->map_start
+ start
)
140 printf("[partition not found?]");
142 printf("%d%s", mbr
->mbr_part
[i
].part_typ
,
143 mbr
->mbr_part
[i
].part_flag
== 0x80 ?
147 case MAP_TYPE_GPT_PART
:
152 utf16_to_utf8(ent
->ent_name
));
153 } else if (show_guid
) {
155 le_uuid_dec(&ent
->ent_uuid
, &guid
);
156 uuid_to_string(&guid
, &s
, NULL
);
161 le_uuid_dec(&ent
->ent_type
, &type
);
162 printf("- %s", friendly(&type
));
168 if (mbr
->mbr_part
[0].part_typ
== DOSPTYP_PMBR
&&
169 mbr
->mbr_part
[0].part_flag
== 0x80)
173 printf("Unknown %#x", m
->map_type
);
182 cmd_show(int argc
, char *argv
[])
186 while ((ch
= getopt(argc
, argv
, "glu")) != -1) {
205 while (optind
< argc
) {
206 fd
= gpt_open(argv
[optind
++]);
208 warn("unable to open device '%s'", device_name
);