partition.c revision 2
/*
* 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
*/
/*
*/
#include <fcntl.h>
#include <libdevinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#include <libfdisk.h>
#endif
#include "libdiskmgt.h"
#include "disks_private.h"
#include "partition.h"
#ifdef sparc
#else
#endif
int opath_len);
descriptor_t **
int *errp)
{
return (NULL);
}
switch (type) {
case DM_MEDIA:
case DM_SLICE:
if (*errp != 0) {
return (NULL);
}
return (libdiskmgt_empty_desc_array(errp));
}
}
return (NULL);
}
/*
* For a media desc. we just get all the partitions, but for a slice desc.
* we just get the active solaris partition.
*/
descriptor_t **
{
int pos;
int i;
char pname[MAXPATHLEN];
int conv_flag = 0;
int len;
#endif
return (libdiskmgt_empty_desc_array(errp));
}
/* allocate the array for the descriptors */
sizeof (descriptor_t *));
if (partitions == NULL) {
return (NULL);
}
/* convert part. name (e.g. c0d0p1) */
conv_flag = 1;
}
#endif
/*
* If this is a slice desc. we need the first active solaris partition
* and if there isn't one then we need the first solaris partition.
*/
for (i = 0; i < TOTAL_NUMPART; i++) {
break;
}
}
/*
* no active solaris part.,*try to get the first solaris part.
*/
if (i >= TOTAL_NUMPART) {
for (i = 0; i < TOTAL_NUMPART; i++) {
break;
}
}
}
if (i < TOTAL_NUMPART) {
/* we found a solaris partition to use */
char part_name[MAXPATHLEN];
if (conv_flag) {
/* convert part. name (e.g. c0d0p1) */
} else {
"%d", i+1);
}
/* the media name comes from the slice desc. */
errp);
if (*errp != 0) {
return (NULL);
}
return (partitions);
}
return (libdiskmgt_empty_desc_array(errp));
}
/* Must be for media, so get all the parts. */
pos = 0;
for (i = 0; i < TOTAL_NUMPART; i++) {
char part_name[MAXPATHLEN];
/*
* Process the descriptors and modify the cxdxpx
* format so that it refers to the fdisk partition
* number and not to the physical disk. This is
* achieved by i+1, where i is the number of the
* physical disk partition.
*/
if (conv_flag) {
/* convert part. name (e.g. c0d0p1) */
} else {
"%d", i+1);
}
/* the media name comes from the media desc. */
if (*errp != 0) {
return (NULL);
}
pos++;
}
}
*errp = 0;
return (partitions);
}
nvlist_t *
{
return (NULL);
}
return (NULL);
}
return (NULL);
}
}
return (attrs);
}
/*
* Look for the partition by the partition number (which is not too useful).
*/
{
int i;
if (*errp != 0) {
return (NULL);
}
for (i = 0; partitions[i]; i++) {
partition = partitions[i];
} else {
/* clean up the unused descriptors */
}
}
}
return (partition);
}
/* ARGSUSED */
descriptor_t **
{
}
char *
{
}
/* ARGSUSED */
nvlist_t *
{
/* There are no stat types defined for partitions */
return (NULL);
}
/* ARGSUSED */
int
{
#ifdef sparc
/* on sparc, only removable media can have fdisk parts. */
return (0);
}
#endif
/*
* We assume the caller already made sure media was inserted and
* spun up.
*/
return (0);
}
return (1);
}
/*
* partition_make_descriptors
*
* A partition descriptor points to a disk, the name is the partition number
* and the secondary name is the media name. The iparts parameter returned
* by the get_parts function contains the structures of all of the identified
* partitions found on each disk on a system. These are processed into an array
* of descriptors. A descriptor contains all of the information about a
* specific partition.
*
* Parameters: none
*
* Returns: 0 on success
* Error value on failure
*
*/
int
{
int error = 0;
int locked;
dp = cache_get_disklist();
char pname[MAXPATHLEN];
int i;
char mname[MAXPATHLEN];
int conv_flag = 0;
/* convert part. name (e.g. c0d0p1) */
int len;
conv_flag = 1;
}
#endif
mname[0] = 0;
/*
* Process the descriptors and modify the cxdxpx
* format so that it refers to the fdisk partition
* number and not to the physical disk. This is
* achieved by i+1, where i is the number of the
* physical disk partition.
*/
for (i = 0; i < TOTAL_NUMPART; i++) {
char part_name[MAXPATHLEN];
if (conv_flag) {
/*
* convert partition name
* (e.g. c0d0p1)
*/
sizeof (part_name),
} else {
sizeof (part_name),
"%d", i+1);
}
if (error != 0)
break;
}
}
}
}
return (error);
}
static int
{
char *p;
int part_num;
/*
* We already made sure the media was loaded and ready in the
* get_parts call within partition_get_attributes.
*/
if (p == NULL) {
} else {
p++;
}
if (part_num > TOTAL_NUMPART ||
return (ENODEV);
}
/*
* A partition has been found. Determine what type of
* partition it is: logical, extended, or primary.
* Collect the information for the partition.
*/
if (part_num > FD_NUMPART) {
DM_LOGICAL) != 0) {
return (ENOMEM);
}
DM_EXTENDED) != 0) {
return (ENOMEM);
}
} else {
DM_PRIMARY) != 0) {
return (ENOMEM);
}
}
#endif
#ifdef sparc
DM_PRIMARY) != 0) {
return (ENOMEM);
}
#endif
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (0);
}
/*
* get_parts
* Discovers the primary, extended, and logical partitions that have
* been created on a disk. get_parts loops through the partitions,
* collects the information on each partition and stores it in a
* partition table.
*
* Parameters;
* disk -The disk device to be evaluated for partitions
* iparts -The structure that holds information about
* the partitions
* opath -The device path
* opath_len -Buffer size used with opath
* Returns:
* 0 on Successful completion
* Error Value on failure
*
*/
static int
{
int fd;
char bootsect[512];
int i;
int j, ret;
char *device; /* name of fixed disk drive */
#endif
/* Can't use drive_open_disk since we need the partition dev name. */
return (ENODEV);
}
/* First make sure media is inserted and spun up. */
return (ENODEV);
}
return (ENOTTY);
}
return (ENODEV);
}
return (ENODEV);
}
return (ENOTTY);
}
/*
* Initialize the memory space to clear unknown garbage
* that might create confusing results.
*/
for (i = 0; i < TOTAL_NUMPART; i++) {
}
/*
* Check to see if a valid partition exists. If a valid partition
* exists, check to see if it is an extended partition.
* If an extended partition exists, collect the logical partition
* data.
*/
for (i = 0; i < FD_NUMPART; i++) {
continue;
continue;
continue;
FDISK_READ_DISK)) != FDISK_SUCCESS) {
switch (ret) {
/*
* The first 2 error cases indicate that
* there is no Solaris logical partition,
* which is a valid condition,
* so iterating through the disk continues.
* Any other error cases indicate there is
* a potential problem with the disk, so
* don't continue iterating through the disk
* and return an error.
*/
case FDISK_EBADLOGDRIVE:
case FDISK_ENOLOGDRIVE:
libfdisk_fini(&epp);
continue;
case FDISK_EBADMAGIC:
libfdisk_fini(&epp);
return (ENOTTY);
default:
libfdisk_fini(&epp);
return (ENODEV);
}
}
/*
* Collect logical drive information
*/
}
/* free the device and the epp memory. */
libfdisk_fini(&epp);
#endif
}
return (0);
}
/* return 1 if the partition descriptor is still valid, 0 if not. */
static int
{
/* First verify the media name for removable media */
char mname[MAXPATHLEN];
return (0);
}
if (mname[0] == 0) {
} else {
}
}
/*
* We could verify the partition is still there but this is kind of
* expensive and other code down the line will do that (e.g. see
* get_attrs).
*/
return (1);
}
/*
* Return 1 if partition has slices, 0 if not.
*/
static int
{
int pnum;
int i;
char *p;
return (0);
}
if (p == NULL) {
} else {
p++;
}
/*
* Slices are associated with the active solaris partition or if there
* is no active solaris partition, then the first solaris partition.
*/
*errp = 0;
return (1);
} else {
int active = 0;
/* Check if there are no active solaris partitions. */
for (i = 0; i < TOTAL_NUMPART; i++) {
active = 1;
break;
}
}
if (!active) {
/* Check if this is the first solaris partition. */
for (i = 0; i < TOTAL_NUMPART; i++) {
break;
}
}
if (i < TOTAL_NUMPART && i == pnum) {
return (1);
}
}
}
return (0);
}
static int
{
/*
* Just open the first devpath.
*/
#ifdef sparc
}
#else
/* On intel we need to open partition device (e.g. c0d0p1). */
char part_dev[MAXPATHLEN];
char *p;
sizeof (part_dev));
if (p == NULL) {
if (p != NULL) {
*p = 'p';
}
} else {
char *ps;
*p = 0;
*ps = 'p';
}
*p = '/';
}
}
#endif
}
return (-1);
}