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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/mkdev.h>
39 #include <sys/types.h>
41 #include <sys/param.h>
42 #include "volmgt_private.h"
45 * arc approved interface
46 * - can not be modified without approval from an arc
52 * volmgt_running: check to see if volume management is running.
58 * TRUE if volume management is running, FALSE if not.
72 * arc approved interface
73 * - can not be modified without approval from an arc
79 * volmgt_inuse: check to see if volume management is currently
80 * managing a particular device.
83 * path - the name of the device in /dev. For example,
87 * TRUE if volume management is managing the device, FALSE if not.
94 volmgt_inuse(char *path
)
101 * arc approved interface
102 * - can not be modified without approval from an arc
108 * volmgt_check: have volume management look at its devices to check
109 * for media having arrived. Since volume management can't
110 * automatically check all types of devices, this function is provided
111 * to allow applications to cause the check to happen automatically.
114 * path - the name of the device in /dev. For example,
115 * /dev/rdiskette. If path is NULL, all "checkable" devices are
119 * TRUE if media was found in the device, FALSE if not.
122 * volume management must be running.
126 volmgt_check(char *path
)
133 * arc approved interface
134 * - can not be modified without approval from an arc
140 * volmgt_ownspath: check to see if the given path is contained in
141 * the volume management name space.
144 * path - string containing the path.
147 * TRUE if the path is owned by volume management, FALSE if not.
148 * Will return FALSE if volume management isn't running.
155 volmgt_ownspath(char *path
)
162 * arc approved interface
163 * - can not be modified without approval from an arc
169 * volmgt_root: return the root of where the volume management
170 * name space is mounted.
176 * Returns a pointer to a static string containing the path to the
177 * volume management root (e.g. "/vol").
178 * Will return NULL if volume management isn't running.
186 static const char *vold_root
= "/dev";
193 * arc approved interface
194 * - can not be modified without approval from an arc
200 * volmgt_symname: Returns the volume management symbolic name
201 * for a given device. If an application wants to determine
202 * what the symbolic name (e.g. "floppy0") for the /dev/rdiskette
203 * device would be, this is the function to use.
206 * path - a string containing the /dev device name. For example,
207 * "/dev/diskette" or "/dev/rdiskette".
209 * Note: must be a block- or char-spcl device, and have a non-zero
210 * st_rdev (real device) stat() value.
213 * pointer to a string containing the symbolic name.
215 * NULL indicates that volume management isn't managing that device.
217 * The string must be free(3)'d.
224 volmgt_symname(char *path
)
231 * arc approved interface
232 * - can not be modified without approval from an arc
238 * volmgt_symdev: Returns the device given the volume management
239 * symbolic name. If an application wants to determine
240 * what the device associated with a particular symbolic name
241 * might be, this is the function to use.
244 * path - a string containing the symbolic device name. For example,
245 * "cdrom0" or "floppy0".
248 * pointer to a string containing the /dev name.
250 * NULL indicates that volume management isn't managing that device.
252 * The string must be free(3)'d.
259 volmgt_symdev(char *symname
)
266 * arc approved interface
267 * - can not be modified without approval from an arc
273 * volmgt_feat_enabled: check to see if a volume management feature
277 * feat_str - a string containing the feature to be checked for
280 * return non-zero if the specified feature is available in
281 * volume management, else return zero
289 * the following is a lit of the "feature" available in volmgt
291 * this list is meant to be updated when new features (that users may
292 * want to use) are added to volmgt
294 * note: feature strings added should be all lower case, and spaces are
297 * (see psarc/1995/138 for more info)
299 static char *volmgt_feat_list
[] = {
300 #ifdef DIRECT_DEV_ACCESS_WORKING
301 "direct-dev-access", /* access through /dev co-exists */
303 "floppy-summit-interfaces", /* volmgt_{acquire,release} */
309 volmgt_feature_enabled(char *feat_str
)
314 * arc approved interface
315 * - can not be modified without approval from an arc
321 * volmgt_acquire: try to acquire the volmgt advisory device reservation
322 * for a specific device.
325 * dev - a device name to attempt reserving. This string can be:
326 * - a full path name to a device
327 * - a symbolic device name (e.g. floppy0)
329 * id - a reservation string that hopefully describes the application
330 * making this reservation.
332 * pid - a pointer to a pid_t type. If this argument is not NULL
333 * and the requested device is already reserved, the process
334 * id of the reservation owner will be returned in this
337 * ovr - an override indicator. If set to non-zero, the caller requests
338 * that this reservation be made unconditionally.
340 * err - the address of a pointer to a string which is to receive the
341 * id argument used when the current device was reserved. This
342 * is only used when the current reservation attempt fails due
343 * to an already existing reservation for this device.
346 * A non-zero indicator if successful.
348 * A zero indicator if unsuccessful. If errno is EBUSY, then the err
349 * argument will be set to point to the string that the process currently
350 * holding the reservation supplied when reserving the device. It is up
351 * to the caller to release the storage occupied by the string via
352 * free(3C) when no longer needed.
359 volmgt_acquire(char *dev
, char *id
, int ovr
, char **err
, pid_t
*pidp
)
366 * arc approved interface
367 * - can not be modified without approval from an arc
373 * volmgt_release: try to release the volmgt advisory device reservation
374 * for a specific device.
377 * dev - a device name to attempt reserving. This string can be:
378 * - a full path name to a device
379 * - a symbolic device name (e.g. floppy0)
382 * A non-zero indicator if successful
383 * A zero indicator if unsuccessful
389 volmgt_release(char *dev
)
396 * returns the "value" of the attribute.
397 * If the attribute is boolean and is TRUE,
398 * "true" is returned. If the boolean is
399 * FALSE, NULL is returned. If the attribute
400 * doesn't exist, NULL is returned. The pointer
401 * returned by media_getattr has been malloc'd and
402 * it is the callers responsibility to free it.
405 * arc approved interface
406 * - can not be modified without approval from an arc
412 * media_getattr: returns the value for an attribute for a piece of
416 * path - Path to the media in /vol. Can be the block or character
419 * attr - name of the attribute.
422 * returns NULL or a pointer to a string that contains the value for
423 * the requested attribute.
426 * - the media doesn't exist
427 * - there is no more space for malloc(3)
428 * - the attribute doesn't exist for the named media
429 * - the attribute is a boolean and is FALSE
431 * the pointer to the string must be free'd with free(3).
434 * volume management (vold) must be running.
438 media_getattr(char *vol_path
, char *attr
)
445 * sets the attribute "attr" to value "value".
447 * If value == "" the flag is
448 * considered to be a TRUE boolean.
450 * If value == 0, it is considered to be a FALSE boolean.
451 * returns TRUE on success, FALSE on failure.
453 * Can fail for reasons of permission, or if you
454 * write a read-only attribute.
458 * arc approved interface
459 * - can not be modified without approval from an arc
465 * media_setattr: set an attribute for a piece of media to a
469 * path - Path to the media in /vol. Can be the block or character
472 * attr - name of the attribute.
474 * value - value of the attribute. If value == "", the flag is
475 * considered to be a boolean that is TRUE. If value == 0, it
476 * is considered to be a FALSE boolean.
479 * TRUE on success, FALSE for failure.
482 * - don't have permission to set the attribute because caller
483 * is not the owner of the media and attribute is a "system"
486 * - don't have permission to set the attribute because the
487 * attribute is a "system" attribute and is read-only.
490 * volume management must be running.
494 media_setattr(char *vol_path
, char *attr
, char *value
)
501 * Returns the "id" of a volume. If the returned value
502 * & VOLID_TMP, the volume is temporary and this value
503 * cannot be relied upon across reboots.
506 * arc approved interface
507 * - can not be modified without approval from an arc
513 * media_getid: return the "id" of a piece of media.
516 * path - Path to the media in /vol. Can be the block or character
519 * returns a u_longlong_t that is the "id" of the volume.
522 * volume management must be running.
525 media_getid(char *vol_path
)
530 * arc approved interface (pending)
531 * - can not be modified without approval from an arc
537 * media_findname: try to come up with the character device when
538 * provided with a starting point. This interface provides the
539 * application programmer to provide "user friendly" names and
540 * easily determine the "/vol" name.
543 * start - a string describing a device. This string can be:
544 * - a full path name to a device (insures it's a
545 * character device by using getfullrawname()).
546 * - a full path name to a volume management media name
547 * with partitions (will return the lowest numbered
549 * - the name of a piece of media (e.g. "fred").
550 * - a symbolic device name (e.g. floppy0, cdrom0, etc)
551 * - a name like "floppy" or "cdrom". Will pick the lowest
552 * numbered device with media in it.
555 * A pointer to a string that contains the character device
556 * most appropriate to the "start" argument.
558 * NULL indicates that we were unable to find media based on "start".
560 * The string must be free(3)'d.
567 media_findname(char *start
)
570 * Eventually should implement using HAL interfaces.
571 * In the short term however, return NULL for aliases,
572 * and self for absolute pathnames.
574 if (start
[0] == '/') {
575 return (strdup(start
));
587 * "old" aliases -- used to be used when vold wasn't running
589 static struct alias device_aliases
[] = {
590 { "fd", "/dev/rdiskette" },
591 { "fd0", "/dev/rdiskette" },
592 { "fd1", "/dev/rdiskette1" },
593 { "diskette", "/dev/rdiskette" },
594 { "diskette0", "/dev/rdiskette0" },
595 { "diskette1", "/dev/rdiskette1" },
596 { "rdiskette", "/dev/rdiskette" },
597 { "rdiskette0", "/dev/rdiskette0" },
598 { "rdiskette1", "/dev/rdiskette1" },
599 { "floppy", "/dev/rdiskette" },
600 { "floppy0", "/dev/rdiskette0" },
601 { "floppy1", "/dev/rdiskette1" },
609 * This is an ON Consolidation Private interface.
613 _media_oldaliases(char *start
)
619 for (s
= device_aliases
; s
->alias
!= NULL
; s
++) {
620 if (strcmp(start
, s
->alias
) == 0) {
621 res
= strdup(s
->name
);
631 * This is an ON Consolidation Private interface.
633 * Print out the aliases available to the program user. Changes
634 * depending in whether volume management is running.
637 _media_printaliases(void)