partition.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <fcntl.h>
#include <libdevinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#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;
return (libdiskmgt_empty_desc_array(errp));
}
/* allocate the array for the descriptors */
sizeof (descriptor_t *));
if (partitions == NULL) {
return (NULL);
}
#ifdef i386
{
/* convert part. name (e.g. c0d0p0) */
int len;
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 < FD_NUMPART; i++) {
break;
}
}
/* no active solaris part., try to get the first solaris part. */
if (i >= FD_NUMPART) {
for (i = 0; i < FD_NUMPART; i++) {
break;
}
}
}
if (i < FD_NUMPART) {
/* we found a solaris partition to use */
char part_name[MAXPATHLEN];
if (conv_flag) {
/* convert part. name (e.g. c0d0p0) */
pname, i);
} else {
}
/* the media name comes from the slice desc. */
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 < FD_NUMPART; i++) {
char part_name[MAXPATHLEN];
if (conv_flag) {
/* convert part. name (e.g. c0d0p0) */
pname, i);
} else {
}
/* 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);
}
/*
* A partition descriptor points to a disk, the name is the partition number
* and the secondary name is the media name.
*/
int
{
int error;
dp = cache_get_disklist();
char pname[MAXPATHLEN];
int i;
char mname[MAXPATHLEN];
int conv_flag = 0;
#ifdef i386
/* convert part. name (e.g. c0d0p0) */
int len;
conv_flag = 1;
}
#endif
mname[0] = 0;
for (i = 0; i < FD_NUMPART; i++) {
char part_name[MAXPATHLEN];
if (conv_flag) {
/* convert part. name (e.g. c0d0p0) */
"%s%d", pname, i);
} else {
"%d", i);
}
&error);
if (error != 0) {
return (error);
}
}
}
}
}
return (0);
}
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++;
}
return (ENODEV);
}
/* we found the partition */
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (ENOMEM);
}
return (0);
}
static int
{
int fd;
char bootsect[512];
int i;
/* Can't use drive_open_disk since we need the partition dev name. */
return (ENODEV);
}
/* First make sure media is inserted and spun up. */
#ifdef i386
/* XXX Work around bug 4725434 */
#endif
return (ENODEV);
#ifdef i386
}
#endif
}
return (ENOTTY);
}
return (ENODEV);
}
return (ENODEV);
}
return (ENOTTY);
}
for (i = 0; i < FD_NUMPART; i++) {
}
}
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 < FD_NUMPART; i++) {
active = 1;
break;
}
}
if (!active) {
/* Check if this is the first solaris partition. */
for (i = 0; i < FD_NUMPART; i++) {
break;
}
}
if (i < FD_NUMPART && i == pnum) {
return (1);
}
}
}
return (0);
}
static int
{
char rmmedia_devpath[MAXPATHLEN];
sizeof (rmmedia_devpath))) {
int fd;
if (rmmedia_devpath[0] == 0) {
/* removable but no media */
return (-1);
}
return (-1);
}
return (-1);
}
/* opened, is device, so done */
}
return (fd);
/* disk w/ slices so handle the directory */
int dfd;
#ifdef _LP64
#endif
/* each device file in the dir represents a slice */
return (-1);
}
/* out of memory */
return (-1);
}
#ifdef _LP64
#else
#endif
char slice_path[MAXPATHLEN];
continue;
}
continue;
}
/* opened, is device, so done */
}
return (dfd);
}
/* not a device, keep looking */
}
/* did not find a device under the rmmedia_path */
}
/* didn't find a device under volume management control */
return (-1);
}
/*
* Not removable media under volume management control so just open the
* first devpath.
*/
#ifdef sparc
}
#else
/* On intel we need to open partition device (e.g. c0d0p0). */
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);
}