prtvtoc.c revision 342440ec94087b8c751c580ab9ed6c693d31d418
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1984 AT&T */
/* All Rights Reserved */
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Print a disk partition map (volume table of contents, or VTOC).
*/
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <sys/efi_partition.h>
/*
* Assumes V_NUMPAR must be a power of 2.
*
* for V_NUMPAR = 8, we have
* parttn(x)=(x & 0x07) noparttn(x)=(x & 0x3fff8)
*
* for V_NUMPAR = 16, we have
* parttn(x)=(x & 0x0f) noparttn(x)=(x & 0x3fff0)
*/
/*
* Disk freespace structure.
*/
typedef struct {
} freemap_t;
static int partcmp(const void *, const void *);
static int partcmp64(const void *, const void *);
static int prtvtoc(char *);
char *, char **);
char *, char **);
static void usage(void);
static int warn(char *, char *);
static char *safe_strdup(char *);
/*
* External variables.
*/
extern char *getfullrawname();
/*
* Static variables.
*/
static short fflag; /* Print freespace shell assignments */
static short hflag; /* Omit headers */
static short sflag; /* Omit all but the column header */
static char *progname; /* Last qualifier of arg0 */
int
{
int idx;
++progname;
else
switch (idx) {
case 'f':
++fflag;
break;
case 'h':
++hflag;
break;
case 's':
++sflag;
break;
case 't':
break;
case 'm':
break;
default:
usage();
}
usage();
idx = 0;
return (idx == 0 ? 0 : 1);
}
/*
* findfree(): Find free space on a disk.
*/
static freemap_t *
{
struct extpartition *part;
struct extpartition **list;
exit(1);
}
*list = 0;
else {
}
++freeidx;
}
return (freemap);
}
/*
* findfree64(): Find free space on a disk.
*/
static freemap_t *
{
++part)
*list = 0;
else {
}
++freeidx;
}
return (freemap);
}
/*
* getmntpt()
*
* Get the filesystem mountpoint of each partition on the disk
* from the fstab or mnttab. Returns a pointer to an array of pointers to
* directory names (indexed by partition number).
*/
static char **
{
int idx;
/* read mnttab for partition mountpoints */
} else {
continue;
/*
* Is it from /dev?
*/
continue;
/*
* Is it a character device?
*/
continue;
/*
* device must match input slot and nopartminor
*/
continue;
}
}
return (list);
}
/*
* Look for the disk in the vfstab so that we can report its mount
* point even if it isn't currently mounted.
*/
continue;
continue;
/*
* Is it a character device?
*/
continue;
/*
* device must match input slot and nopartminor
*/
continue;
/*
* use mnttab entry if both tables have entries
*/
continue;
}
return (list);
}
/*
* partcmp(): Qsort() key comparison of partitions by starting sector numbers.
*/
static int
{
}
static int
{
return (1);
return (-1);
else
return (0);
}
/*
* prtvtoc(): Read and print a VTOC.
*/
static int
{
int fd;
int idx;
int geo;
char *name;
int newvtoc = 0;
"internal administrative call (getfullrawname) failed"));
if (geo) {
newvtoc = 1;
} else
}
return (-1);
if (!newvtoc)
else
if (fflag) {
if (!newvtoc)
else
} else {
if (!newvtoc)
else
}
if (newvtoc)
return (0);
}
/*
* putfree():
*
* Print shell assignments for disk free space. FREE_START and FREE_SIZE
* represent the starting block and number of blocks of the first chunk
* of free space. FREE_PART lists the unassigned partitions.
*/
static void
{
int free_count = 0;
free_count++;
(void) printf("FREE_START=%llu FREE_SIZE=%llu FREE_COUNT=%d FREE_PART=",
}
(void) printf("\n");
}
static void
{
int free_count = 0;
free_count++;
(void) printf("FREE_START=%llu FREE_SIZE=%llu FREE_COUNT=%d FREE_PART=",
}
(void) printf("\n");
}
/*
* puttable(): Print a human-readable VTOC.
*/
static void
{
(void) printf(" partition map\n");
(void) printf("*\n* Dimensions:\n");
(void) printf("*\n* Flags:\n");
(void) printf("* 1: unmountable\n");
(void) printf("* 10: read-only\n*\n");
(void) printf("* Unallocated space:\n");
(void) printf("*\tFirst Sector Last\n");
(void) printf("*\tSector Count Sector \n");
do {
(void) printf("* %9llu %9llu %9llu\n",
(void) printf("*\n");
}
}
if (!hflag) {
(void) printf(\
"* First Sector Last\n"
"* Partition Tag Flags Sector Count Sector Mount Directory\n");
}
continue;
(void) printf(" %2u %5u %02x %9llu %9llu %9llu",
(void) printf("\n");
}
}
/*
* puttable(): Print a human-readable VTOC.
*/
static void
char **mtab)
{
(void) printf(" (volume \"%.8s\")",
(void) printf(" partition map\n");
(void) printf("*\n* Dimensions:\n");
(void) printf("* %llu accessible sectors\n",
(void) printf("*\n* Flags:\n");
(void) printf("* 1: unmountable\n");
(void) printf("* 10: read-only\n*\n");
(void) printf("* Unallocated space:\n");
(void) printf("*\tFirst Sector Last\n");
(void) printf("*\tSector Count Sector \n");
do {
(void) printf("* %9llu %9llu %9llu\n",
(void) printf("*\n");
}
}
if (!hflag) {
(void) printf(\
"* First Sector Last\n"
"* Partition Tag Flags Sector Count Sector Mount Directory\n");
}
continue;
(void) printf(" %2u %5u %02x %9llu %9llu %9llu",
(void) printf("\n");
}
}
/*
* readgeom(): Read the disk geometry.
*/
static int
{
char err_string[128];
(void) sprintf(err_string,
"Unable to read Disk geometry errno = 0x%x",
errno);
}
return (0);
}
/*
* readvtoc(): Read a partition map.
*/
static int
{
int retval;
return (0);
switch (retval) {
case (VT_EIO):
case (VT_EINVAL):
case (VT_ERROR):
}
return (retval);
}
/*
* readefi(): Read a partition map.
*/
static int
{
int retval;
return (0);
switch (retval) {
case (VT_EIO):
case (VT_EINVAL):
case (VT_ERROR):
}
return (retval);
}
static char *
safe_strdup(char *str)
{
char *ret;
exit(1);
}
return (ret);
}
/*
* usage(): Print a helpful message and exit.
*/
static void
usage()
{
"rawdisk ...\n", progname);
exit(1);
}
/*
* warn(): Print an error message. Always returns -1.
*/
static int
{
return (-1);
}