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.
27 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
32 __RCSID("$NetBSD: show.c,v 1.4 2007/12/28 19:53:10 riz Exp $");
35 #include <sys/types.h>
47 static int show_label
= 0;
48 static int show_uuid
= 0;
50 const char showmsg
[] = "show [-lu] device ...";
57 "usage: %s %s\n", getprogname(), showmsg
);
64 static uuid_t efi_slice
= GPT_ENT_TYPE_EFI
;
65 static uuid_t bios_boot
= GPT_ENT_TYPE_BIOS
;
66 static uuid_t mslinux
= GPT_ENT_TYPE_MS_BASIC_DATA
;
67 static uuid_t freebsd
= GPT_ENT_TYPE_FREEBSD
;
68 static uuid_t hfs
= GPT_ENT_TYPE_APPLE_HFS
;
69 static uuid_t linuxswap
= GPT_ENT_TYPE_LINUX_SWAP
;
70 static uuid_t msr
= GPT_ENT_TYPE_MS_RESERVED
;
71 static uuid_t swap
= GPT_ENT_TYPE_FREEBSD_SWAP
;
72 static uuid_t ufs
= GPT_ENT_TYPE_FREEBSD_UFS
;
73 static uuid_t vinum
= GPT_ENT_TYPE_FREEBSD_VINUM
;
74 static uuid_t nb_swap
= GPT_ENT_TYPE_NETBSD_SWAP
;
75 static uuid_t nb_ufs
= GPT_ENT_TYPE_NETBSD_FFS
;
76 static uuid_t nb_lfs
= GPT_ENT_TYPE_NETBSD_LFS
;
77 static uuid_t nb_raid
= GPT_ENT_TYPE_NETBSD_RAIDFRAME
;
78 static uuid_t nb_ccd
= GPT_ENT_TYPE_NETBSD_CCD
;
79 static uuid_t nb_cgd
= GPT_ENT_TYPE_NETBSD_CGD
;
86 if (uuid_equal(t
, &efi_slice
, NULL
))
87 return ("EFI System");
88 if (uuid_equal(t
, &bios_boot
, NULL
))
90 if (uuid_equal(t
, &nb_swap
, NULL
))
91 return ("NetBSD swap");
92 if (uuid_equal(t
, &nb_ufs
, NULL
))
93 return ("NetBSD UFS/UFS2");
94 if (uuid_equal(t
, &nb_lfs
, NULL
))
95 return ("NetBSD LFS");
96 if (uuid_equal(t
, &nb_raid
, NULL
))
97 return ("NetBSD RAIDFrame component");
98 if (uuid_equal(t
, &nb_ccd
, NULL
))
99 return ("NetBSD ccd component");
100 if (uuid_equal(t
, &nb_cgd
, NULL
))
101 return ("NetBSD Cryptographic Disk");
102 if (uuid_equal(t
, &swap
, NULL
))
103 return ("FreeBSD swap");
104 if (uuid_equal(t
, &ufs
, NULL
))
105 return ("FreeBSD UFS/UFS2");
106 if (uuid_equal(t
, &vinum
, NULL
))
107 return ("FreeBSD vinum");
109 if (uuid_equal(t
, &freebsd
, NULL
))
110 return ("FreeBSD legacy");
111 if (uuid_equal(t
, &mslinux
, NULL
))
112 return ("Linux/Windows");
113 if (uuid_equal(t
, &linuxswap
, NULL
))
114 return ("Linux swap");
115 if (uuid_equal(t
, &msr
, NULL
))
116 return ("Windows reserved");
117 if (uuid_equal(t
, &hfs
, NULL
))
118 return ("Apple HFS");
121 uuid_to_string(t
, &s
, NULL
);
122 strlcpy(buf
, s
, sizeof buf
);
128 show(int fd __unused
)
137 printf(" %*s", lbawidth
, "start");
138 printf(" %*s", lbawidth
, "size");
139 printf(" index contents\n");
143 printf(" %*llu", lbawidth
, (long long)m
->map_start
);
144 printf(" %*llu", lbawidth
, (long long)m
->map_size
);
147 if (m
->map_index
> 0)
148 printf("%5d", m
->map_index
);
153 switch (m
->map_type
) {
155 if (m
->map_start
!= 0)
159 case MAP_TYPE_PRI_GPT_HDR
:
160 printf("Pri GPT header");
162 case MAP_TYPE_SEC_GPT_HDR
:
163 printf("Sec GPT header");
165 case MAP_TYPE_PRI_GPT_TBL
:
166 printf("Pri GPT table");
168 case MAP_TYPE_SEC_GPT_TBL
:
169 printf("Sec GPT table");
171 case MAP_TYPE_MBR_PART
:
173 if (p
->map_start
!= 0)
177 for (i
= 0; i
< 4; i
++) {
178 start
= le16toh(mbr
->mbr_part
[i
].part_start_hi
);
179 start
= (start
<< 16) +
180 le16toh(mbr
->mbr_part
[i
].part_start_lo
);
181 if (m
->map_start
== p
->map_start
+ start
)
184 printf("%d", mbr
->mbr_part
[i
].part_typ
);
186 case MAP_TYPE_GPT_PART
:
191 utf16_to_utf8(ent
->ent_name
));
193 le_uuid_dec(&ent
->ent_type
, &type
);
194 printf("- %s", friendly(&type
));
207 cmd_show(int argc
, char *argv
[])
211 while ((ch
= getopt(argc
, argv
, "lu")) != -1) {
227 while (optind
< argc
) {
228 fd
= gpt_open(argv
[optind
++]);
230 warn("unable to open device '%s'", device_name
);