4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Two output fields under the -i option will always be
32 * output as zero, since they are not supported by Sun:
33 * Software version, and
35 * AT&T filled these 2 fields with data from their "pdsector",
36 * which Sun doesn't support per se.
45 #include <sys/types.h>
48 #include <sys/efi_partition.h>
50 #include <sys/mkdev.h>
57 * Standard I/O file descriptors.
59 #define STDOUT 1 /* Standard output */
60 #define STDERR 2 /* Standard error */
62 static void partinfo(int fd
, char *device
);
63 static void devinfo(struct dk_geom
*geom
, int fd
, char *device
);
64 static int readvtoc(int fd
, char *name
, struct extvtoc
*vtoc
);
65 static int warn(char *what
, char *why
);
66 static void usage(void);
69 main(int argc
, char **argv
)
72 int errflg
, iflg
, pflg
, fd
, c
;
78 while ((c
= getopt(argc
, argv
, "i:p:")) != EOF
) {
98 if ((optind
> argc
) || (optind
== 1) || (pflg
&& iflg
))
101 if ((fd
= open(device
, O_RDONLY
)) < 0) {
102 (void) fprintf(stderr
, "devinfo: %s: %s\n",
103 device
, strerror(errno
));
108 if (ioctl(fd
, DKIOCGGEOM
, &geom
) == -1) {
109 if (errno
== ENOTSUP
) {
111 "This operation is not supported on EFI labeled devices");
114 "Unable to read Disk geometry");
119 devinfo(&geom
, fd
, device
);
122 partinfo(fd
, device
);
128 partinfo(int fd
, char *device
)
134 struct stat64 statbuf
;
135 struct extvtoc vtdata
;
138 i
= stat64(device
, &statbuf
);
141 maj
= major(statbuf
.st_rdev
);
142 min
= minor(statbuf
.st_rdev
);
144 if ((slice
= readvtoc(fd
, device
, &vtdata
)) >= 0) {
146 (void) printf("%s\t%0lx\t%0lx\t%llu\t%llu\t%x\t%x\n",
148 vtdata
.v_part
[slice
].p_start
,
149 vtdata
.v_part
[slice
].p_size
,
150 vtdata
.v_part
[slice
].p_flag
,
151 vtdata
.v_part
[slice
].p_tag
);
152 } else if ((slice
== VT_ENOTSUP
) &&
153 (slice
= efi_alloc_and_read(fd
, &efi
)) >= 0) {
154 (void) printf("%s\t%lx\t%lx\t%lld\t%lld\t%hx\t%hx\n",
156 efi
->efi_parts
[slice
].p_start
,
157 efi
->efi_parts
[slice
].p_size
,
158 efi
->efi_parts
[slice
].p_flag
,
159 efi
->efi_parts
[slice
].p_tag
);
166 devinfo(struct dk_geom
*geom
, int fd
, char *device
)
169 unsigned int nopartitions
, sectorcyl
, bytes
;
170 struct extvtoc vtdata
;
172 * unsigned int version = 0;
173 * unsigned int driveid = 0;
180 if (readvtoc(fd
, device
, &vtdata
) < 0)
182 sectorcyl
= geom
->dkg_nhead
* geom
->dkg_nsect
;
183 bytes
= vtdata
.v_sectorsz
;
185 * these are not supported by Sun.
187 * driveid = osect0->newsect0.pdinfo.driveid;
188 * version = osect0->newsect0.pdinfo.version;
190 for (i
= 0; i
< V_NUMPAR
; i
++) {
191 if (vtdata
.v_part
[i
].p_size
!= 0x00)
195 * (void) printf("%s %0x %0x %d %d %d\n",
196 * device, version, driveid, sectorcyl, bytes, nopartitions);
198 (void) printf("%s %0x %0x %d %d %d\n",
199 device
, 0, 0, sectorcyl
, bytes
, nopartitions
);
206 * Read a partition map.
209 readvtoc(int fd
, char *name
, struct extvtoc
*vtoc
)
213 retval
= read_extvtoc(fd
, vtoc
);
217 return (warn(name
, strerror(errno
)));
219 return (warn(name
, "I/O error accessing VTOC"));
221 return (warn(name
, "Invalid field in VTOC"));
231 * Print an error message. Always returns -1.
234 warn(char *what
, char *why
)
236 static char myname
[] = "devinfo";
237 static char between
[] = ": ";
238 static char after
[] = "\n";
240 (void) write(STDERR
, myname
, (uint_t
)strlen(myname
));
241 (void) write(STDERR
, between
, (uint_t
)strlen(between
));
242 (void) write(STDERR
, what
, (uint_t
)strlen(what
));
243 (void) write(STDERR
, between
, (uint_t
)strlen(between
));
244 (void) write(STDERR
, why
, (uint_t
)strlen(why
));
245 (void) write(STDERR
, after
, (uint_t
)strlen(after
));
252 (void) fprintf(stderr
, "Usage: devinfo -p device\n"
253 " devinfo -i device \n");