2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A#include <dirent.h>
2N/A#include <fcntl.h>
2N/A#include <string.h>
2N/A#include <errno.h>
2N/A#include <limits.h>
2N/A#include <unistd.h>
2N/A#include <sys/mkdev.h>
2N/A#include <volmgt.h>
2N/A#include <ctype.h>
2N/A#include <sys/types.h>
2N/A#include <sys/stat.h>
2N/A#include <sys/param.h>
2N/A#include "volmgt_private.h"
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_running: check to see if volume management is running.
2N/A *
2N/A * arguments:
2N/A * none.
2N/A *
2N/A * return value(s):
2N/A * TRUE if volume management is running, FALSE if not.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/Aint
2N/Avolmgt_running(void)
2N/A{
2N/A /* vold is dead */
2N/A return (FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_inuse: check to see if volume management is currently
2N/A * managing a particular device.
2N/A *
2N/A * arguments:
2N/A * path - the name of the device in /dev. For example,
2N/A * "/dev/rdiskette".
2N/A *
2N/A * return value(s):
2N/A * TRUE if volume management is managing the device, FALSE if not.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Avolmgt_inuse(char *path)
2N/A{
2N/A return (FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_check: have volume management look at its devices to check
2N/A * for media having arrived. Since volume management can't
2N/A * automatically check all types of devices, this function is provided
2N/A * to allow applications to cause the check to happen automatically.
2N/A *
2N/A * arguments:
2N/A * path - the name of the device in /dev. For example,
2N/A * /dev/rdiskette. If path is NULL, all "checkable" devices are
2N/A * checked.
2N/A *
2N/A * return value(s):
2N/A * TRUE if media was found in the device, FALSE if not.
2N/A *
2N/A * preconditions:
2N/A * volume management must be running.
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Avolmgt_check(char *path)
2N/A{
2N/A return (FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_ownspath: check to see if the given path is contained in
2N/A * the volume management name space.
2N/A *
2N/A * arguments:
2N/A * path - string containing the path.
2N/A *
2N/A * return value(s):
2N/A * TRUE if the path is owned by volume management, FALSE if not.
2N/A * Will return FALSE if volume management isn't running.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Avolmgt_ownspath(char *path)
2N/A{
2N/A return (FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_root: return the root of where the volume management
2N/A * name space is mounted.
2N/A *
2N/A * arguments:
2N/A * none.
2N/A *
2N/A * return value(s):
2N/A * Returns a pointer to a static string containing the path to the
2N/A * volume management root (e.g. "/vol").
2N/A * Will return NULL if volume management isn't running.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/Aconst char *
2N/Avolmgt_root(void)
2N/A{
2N/A static const char *vold_root = "/dev";
2N/A
2N/A return (vold_root);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_symname: Returns the volume management symbolic name
2N/A * for a given device. If an application wants to determine
2N/A * what the symbolic name (e.g. "floppy0") for the /dev/rdiskette
2N/A * device would be, this is the function to use.
2N/A *
2N/A * arguments:
2N/A * path - a string containing the /dev device name. For example,
2N/A * "/dev/diskette" or "/dev/rdiskette".
2N/A *
2N/A * Note: must be a block- or char-spcl device, and have a non-zero
2N/A * st_rdev (real device) stat() value.
2N/A *
2N/A * return value(s):
2N/A * pointer to a string containing the symbolic name.
2N/A *
2N/A * NULL indicates that volume management isn't managing that device.
2N/A *
2N/A * The string must be free(3)'d.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/A/* ARGSUSED */
2N/Achar *
2N/Avolmgt_symname(char *path)
2N/A{
2N/A return (NULL);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_symdev: Returns the device given the volume management
2N/A * symbolic name. If an application wants to determine
2N/A * what the device associated with a particular symbolic name
2N/A * might be, this is the function to use.
2N/A *
2N/A * arguments:
2N/A * path - a string containing the symbolic device name. For example,
2N/A * "cdrom0" or "floppy0".
2N/A *
2N/A * return value(s):
2N/A * pointer to a string containing the /dev name.
2N/A *
2N/A * NULL indicates that volume management isn't managing that device.
2N/A *
2N/A * The string must be free(3)'d.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/A/* ARGSUSED */
2N/Achar *
2N/Avolmgt_symdev(char *symname)
2N/A{
2N/A return (NULL);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * volmgt_feat_enabled: check to see if a volume management feature
2N/A * is available
2N/A *
2N/A * arguments:
2N/A * feat_str - a string containing the feature to be checked for
2N/A *
2N/A * return value(s):
2N/A * return non-zero if the specified feature is available in
2N/A * volume management, else return zero
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/A
2N/A
2N/A/*
2N/A * the following is a lit of the "feature" available in volmgt
2N/A *
2N/A * this list is meant to be updated when new features (that users may
2N/A * want to use) are added to volmgt
2N/A *
2N/A * note: feature strings added should be all lower case, and spaces are
2N/A * discouraged
2N/A *
2N/A * (see psarc/1995/138 for more info)
2N/A */
2N/Astatic char *volmgt_feat_list[] = {
2N/A#ifdef DIRECT_DEV_ACCESS_WORKING
2N/A "direct-dev-access", /* access through /dev co-exists */
2N/A#endif
2N/A "floppy-summit-interfaces", /* volmgt_{acquire,release} */
2N/A NULL
2N/A};
2N/A
2N/A
2N/Aint
2N/Avolmgt_feature_enabled(char *feat_str)
2N/A{
2N/A return (0);
2N/A}
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * uncommitted
2N/A *
2N/A * description:
2N/A * volmgt_acquire: try to acquire the volmgt advisory device reservation
2N/A * for a specific device.
2N/A *
2N/A * arguments:
2N/A * dev - a device name to attempt reserving. This string can be:
2N/A * - a full path name to a device
2N/A * - a symbolic device name (e.g. floppy0)
2N/A *
2N/A * id - a reservation string that hopefully describes the application
2N/A * making this reservation.
2N/A *
2N/A * pid - a pointer to a pid_t type. If this argument is not NULL
2N/A * and the requested device is already reserved, the process
2N/A * id of the reservation owner will be returned in this
2N/A * location.
2N/A *
2N/A * ovr - an override indicator. If set to non-zero, the caller requests
2N/A * that this reservation be made unconditionally.
2N/A *
2N/A * err - the address of a pointer to a string which is to receive the
2N/A * id argument used when the current device was reserved. This
2N/A * is only used when the current reservation attempt fails due
2N/A * to an already existing reservation for this device.
2N/A *
2N/A * return value(s):
2N/A * A non-zero indicator if successful.
2N/A *
2N/A * A zero indicator if unsuccessful. If errno is EBUSY, then the err
2N/A * argument will be set to point to the string that the process currently
2N/A * holding the reservation supplied when reserving the device. It is up
2N/A * to the caller to release the storage occupied by the string via
2N/A * free(3C) when no longer needed.
2N/A *
2N/A * preconditions:
2N/A * none
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Avolmgt_acquire(char *dev, char *id, int ovr, char **err, pid_t *pidp)
2N/A{
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * uncommitted
2N/A *
2N/A * description:
2N/A * volmgt_release: try to release the volmgt advisory device reservation
2N/A * for a specific device.
2N/A *
2N/A * arguments:
2N/A * dev - a device name to attempt reserving. This string can be:
2N/A * - a full path name to a device
2N/A * - a symbolic device name (e.g. floppy0)
2N/A *
2N/A * return value(s):
2N/A * A non-zero indicator if successful
2N/A * A zero indicator if unsuccessful
2N/A *
2N/A * preconditions:
2N/A * none
2N/A */
2N/Aint
2N/Avolmgt_release(char *dev)
2N/A{
2N/A return (0);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * returns the "value" of the attribute.
2N/A * If the attribute is boolean and is TRUE,
2N/A * "true" is returned. If the boolean is
2N/A * FALSE, NULL is returned. If the attribute
2N/A * doesn't exist, NULL is returned. The pointer
2N/A * returned by media_getattr has been malloc'd and
2N/A * it is the callers responsibility to free it.
2N/A */
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * media_getattr: returns the value for an attribute for a piece of
2N/A * removable media.
2N/A *
2N/A * arguments:
2N/A * path - Path to the media in /vol. Can be the block or character
2N/A * device.
2N/A *
2N/A * attr - name of the attribute.
2N/A *
2N/A * return value(s):
2N/A * returns NULL or a pointer to a string that contains the value for
2N/A * the requested attribute.
2N/A *
2N/A * NULL can mean:
2N/A * - the media doesn't exist
2N/A * - there is no more space for malloc(3)
2N/A * - the attribute doesn't exist for the named media
2N/A * - the attribute is a boolean and is FALSE
2N/A *
2N/A * the pointer to the string must be free'd with free(3).
2N/A *
2N/A * preconditions:
2N/A * volume management (vold) must be running.
2N/A */
2N/A/* ARGSUSED */
2N/Achar *
2N/Amedia_getattr(char *vol_path, char *attr)
2N/A{
2N/A return (NULL);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * sets the attribute "attr" to value "value".
2N/A *
2N/A * If value == "" the flag is
2N/A * considered to be a TRUE boolean.
2N/A *
2N/A * If value == 0, it is considered to be a FALSE boolean.
2N/A * returns TRUE on success, FALSE on failure.
2N/A *
2N/A * Can fail for reasons of permission, or if you
2N/A * write a read-only attribute.
2N/A */
2N/A
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * media_setattr: set an attribute for a piece of media to a
2N/A * particular value.
2N/A *
2N/A * arguments:
2N/A * path - Path to the media in /vol. Can be the block or character
2N/A * device.
2N/A *
2N/A * attr - name of the attribute.
2N/A *
2N/A * value - value of the attribute. If value == "", the flag is
2N/A * considered to be a boolean that is TRUE. If value == 0, it
2N/A * is considered to be a FALSE boolean.
2N/A *
2N/A * return value(s):
2N/A * TRUE on success, FALSE for failure.
2N/A *
2N/A * Can fail because:
2N/A * - don't have permission to set the attribute because caller
2N/A * is not the owner of the media and attribute is a "system"
2N/A * attribute.
2N/A *
2N/A * - don't have permission to set the attribute because the
2N/A * attribute is a "system" attribute and is read-only.
2N/A *
2N/A * preconditions:
2N/A * volume management must be running.
2N/A */
2N/A/* ARGSUSED */
2N/Aint
2N/Amedia_setattr(char *vol_path, char *attr, char *value)
2N/A{
2N/A return (FALSE);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Returns the "id" of a volume. If the returned value
2N/A * & VOLID_TMP, the volume is temporary and this value
2N/A * cannot be relied upon across reboots.
2N/A */
2N/A/*
2N/A * arc approved interface
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * media_getid: return the "id" of a piece of media.
2N/A *
2N/A * arguments:
2N/A * path - Path to the media in /vol. Can be the block or character
2N/A * device.
2N/A * return value(s):
2N/A * returns a u_longlong_t that is the "id" of the volume.
2N/A *
2N/A * preconditions:
2N/A * volume management must be running.
2N/A */
2N/Au_longlong_t
2N/Amedia_getid(char *vol_path)
2N/A{
2N/A return (0);
2N/A}
2N/A/*
2N/A * arc approved interface (pending)
2N/A * - can not be modified without approval from an arc
2N/A *
2N/A * committment level:
2N/A * public
2N/A *
2N/A * description:
2N/A * media_findname: try to come up with the character device when
2N/A * provided with a starting point. This interface provides the
2N/A * application programmer to provide "user friendly" names and
2N/A * easily determine the "/vol" name.
2N/A *
2N/A * arguments:
2N/A * start - a string describing a device. This string can be:
2N/A * - a full path name to a device (insures it's a
2N/A * character device by using getfullrawname()).
2N/A * - a full path name to a volume management media name
2N/A * with partitions (will return the lowest numbered
2N/A * raw partition.
2N/A * - the name of a piece of media (e.g. "fred").
2N/A * - a symbolic device name (e.g. floppy0, cdrom0, etc)
2N/A * - a name like "floppy" or "cdrom". Will pick the lowest
2N/A * numbered device with media in it.
2N/A *
2N/A * return value(s):
2N/A * A pointer to a string that contains the character device
2N/A * most appropriate to the "start" argument.
2N/A *
2N/A * NULL indicates that we were unable to find media based on "start".
2N/A *
2N/A * The string must be free(3)'d.
2N/A *
2N/A * preconditions:
2N/A * none.
2N/A */
2N/A/* ARGSUSED */
2N/Achar *
2N/Amedia_findname(char *start)
2N/A{
2N/A /*
2N/A * Eventually should implement using HAL interfaces.
2N/A * In the short term however, return NULL for aliases,
2N/A * and self for absolute pathnames.
2N/A */
2N/A if (start[0] == '/') {
2N/A return (strdup(start));
2N/A } else {
2N/A return (NULL);
2N/A }
2N/A}
2N/A
2N/Astruct alias {
2N/A char *alias;
2N/A char *name;
2N/A};
2N/A
2N/A/*
2N/A * "old" aliases -- used to be used when vold wasn't running
2N/A */
2N/Astatic struct alias device_aliases[] = {
2N/A { "fd", "/dev/rdiskette" },
2N/A { "fd0", "/dev/rdiskette" },
2N/A { "fd1", "/dev/rdiskette1" },
2N/A { "diskette", "/dev/rdiskette" },
2N/A { "diskette0", "/dev/rdiskette0" },
2N/A { "diskette1", "/dev/rdiskette1" },
2N/A { "rdiskette", "/dev/rdiskette" },
2N/A { "rdiskette0", "/dev/rdiskette0" },
2N/A { "rdiskette1", "/dev/rdiskette1" },
2N/A { "floppy", "/dev/rdiskette" },
2N/A { "floppy0", "/dev/rdiskette0" },
2N/A { "floppy1", "/dev/rdiskette1" },
2N/A { "cd", "cdrom0" },
2N/A { "cd0", "cdrom0" },
2N/A { "cd1", "cdrom1" },
2N/A { NULL, NULL }
2N/A};
2N/A
2N/A/*
2N/A * This is an ON Consolidation Private interface.
2N/A */
2N/A/* ARGSUSED */
2N/Achar *
2N/A_media_oldaliases(char *start)
2N/A{
2N/A struct alias *s;
2N/A char *p;
2N/A char *res = NULL;
2N/A
2N/A for (s = device_aliases; s->alias != NULL; s++) {
2N/A if (strcmp(start, s->alias) == 0) {
2N/A res = strdup(s->name);
2N/A break;
2N/A }
2N/A }
2N/A
2N/A return (res);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * This is an ON Consolidation Private interface.
2N/A *
2N/A * Print out the aliases available to the program user. Changes
2N/A * depending in whether volume management is running.
2N/A */
2N/Avoid
2N/A_media_printaliases(void)
2N/A{
2N/A}