sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libvolmgt / common / volmgt.c
blob9a2bb3b847ac310d5b02967c39e2129335e0c729
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <stdio.h>
29 #include <string.h>
30 #include <dirent.h>
31 #include <fcntl.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <limits.h>
35 #include <unistd.h>
36 #include <sys/mkdev.h>
37 #include <volmgt.h>
38 #include <ctype.h>
39 #include <sys/types.h>
40 #include <sys/stat.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
48 * committment level:
49 * public
51 * description:
52 * volmgt_running: check to see if volume management is running.
54 * arguments:
55 * none.
57 * return value(s):
58 * TRUE if volume management is running, FALSE if not.
60 * preconditions:
61 * none.
63 int
64 volmgt_running(void)
66 /* vold is dead */
67 return (FALSE);
72 * arc approved interface
73 * - can not be modified without approval from an arc
75 * committment level:
76 * public
78 * description:
79 * volmgt_inuse: check to see if volume management is currently
80 * managing a particular device.
82 * arguments:
83 * path - the name of the device in /dev. For example,
84 * "/dev/rdiskette".
86 * return value(s):
87 * TRUE if volume management is managing the device, FALSE if not.
89 * preconditions:
90 * none.
92 /* ARGSUSED */
93 int
94 volmgt_inuse(char *path)
96 return (FALSE);
101 * arc approved interface
102 * - can not be modified without approval from an arc
104 * committment level:
105 * public
107 * description:
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.
113 * arguments:
114 * path - the name of the device in /dev. For example,
115 * /dev/rdiskette. If path is NULL, all "checkable" devices are
116 * checked.
118 * return value(s):
119 * TRUE if media was found in the device, FALSE if not.
121 * preconditions:
122 * volume management must be running.
124 /* ARGSUSED */
126 volmgt_check(char *path)
128 return (FALSE);
133 * arc approved interface
134 * - can not be modified without approval from an arc
136 * committment level:
137 * public
139 * description:
140 * volmgt_ownspath: check to see if the given path is contained in
141 * the volume management name space.
143 * arguments:
144 * path - string containing the path.
146 * return value(s):
147 * TRUE if the path is owned by volume management, FALSE if not.
148 * Will return FALSE if volume management isn't running.
150 * preconditions:
151 * none.
153 /* ARGSUSED */
155 volmgt_ownspath(char *path)
157 return (FALSE);
162 * arc approved interface
163 * - can not be modified without approval from an arc
165 * committment level:
166 * public
168 * description:
169 * volmgt_root: return the root of where the volume management
170 * name space is mounted.
172 * arguments:
173 * none.
175 * return value(s):
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.
180 * preconditions:
181 * none.
183 const char *
184 volmgt_root(void)
186 static const char *vold_root = "/dev";
188 return (vold_root);
193 * arc approved interface
194 * - can not be modified without approval from an arc
196 * committment level:
197 * public
199 * description:
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.
205 * arguments:
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.
212 * return value(s):
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.
219 * preconditions:
220 * none.
222 /* ARGSUSED */
223 char *
224 volmgt_symname(char *path)
226 return (NULL);
231 * arc approved interface
232 * - can not be modified without approval from an arc
234 * committment level:
235 * public
237 * description:
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.
243 * arguments:
244 * path - a string containing the symbolic device name. For example,
245 * "cdrom0" or "floppy0".
247 * return value(s):
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.
254 * preconditions:
255 * none.
257 /* ARGSUSED */
258 char *
259 volmgt_symdev(char *symname)
261 return (NULL);
266 * arc approved interface
267 * - can not be modified without approval from an arc
269 * committment level:
270 * public
272 * description:
273 * volmgt_feat_enabled: check to see if a volume management feature
274 * is available
276 * arguments:
277 * feat_str - a string containing the feature to be checked for
279 * return value(s):
280 * return non-zero if the specified feature is available in
281 * volume management, else return zero
283 * preconditions:
284 * none.
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
295 * discouraged
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 */
302 #endif
303 "floppy-summit-interfaces", /* volmgt_{acquire,release} */
304 NULL
309 volmgt_feature_enabled(char *feat_str)
311 return (0);
314 * arc approved interface
315 * - can not be modified without approval from an arc
317 * committment level:
318 * uncommitted
320 * description:
321 * volmgt_acquire: try to acquire the volmgt advisory device reservation
322 * for a specific device.
324 * arguments:
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
335 * location.
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.
345 * return value(s):
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.
354 * preconditions:
355 * none
357 /* ARGSUSED */
359 volmgt_acquire(char *dev, char *id, int ovr, char **err, pid_t *pidp)
361 return (0);
366 * arc approved interface
367 * - can not be modified without approval from an arc
369 * committment level:
370 * uncommitted
372 * description:
373 * volmgt_release: try to release the volmgt advisory device reservation
374 * for a specific device.
376 * arguments:
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)
381 * return value(s):
382 * A non-zero indicator if successful
383 * A zero indicator if unsuccessful
385 * preconditions:
386 * none
389 volmgt_release(char *dev)
391 return (0);
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
408 * committment level:
409 * public
411 * description:
412 * media_getattr: returns the value for an attribute for a piece of
413 * removable media.
415 * arguments:
416 * path - Path to the media in /vol. Can be the block or character
417 * device.
419 * attr - name of the attribute.
421 * return value(s):
422 * returns NULL or a pointer to a string that contains the value for
423 * the requested attribute.
425 * NULL can mean:
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).
433 * preconditions:
434 * volume management (vold) must be running.
436 /* ARGSUSED */
437 char *
438 media_getattr(char *vol_path, char *attr)
440 return (NULL);
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
461 * committment level:
462 * public
464 * description:
465 * media_setattr: set an attribute for a piece of media to a
466 * particular value.
468 * arguments:
469 * path - Path to the media in /vol. Can be the block or character
470 * device.
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.
478 * return value(s):
479 * TRUE on success, FALSE for failure.
481 * Can fail because:
482 * - don't have permission to set the attribute because caller
483 * is not the owner of the media and attribute is a "system"
484 * attribute.
486 * - don't have permission to set the attribute because the
487 * attribute is a "system" attribute and is read-only.
489 * preconditions:
490 * volume management must be running.
492 /* ARGSUSED */
494 media_setattr(char *vol_path, char *attr, char *value)
496 return (FALSE);
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
509 * committment level:
510 * public
512 * description:
513 * media_getid: return the "id" of a piece of media.
515 * arguments:
516 * path - Path to the media in /vol. Can be the block or character
517 * device.
518 * return value(s):
519 * returns a u_longlong_t that is the "id" of the volume.
521 * preconditions:
522 * volume management must be running.
524 u_longlong_t
525 media_getid(char *vol_path)
527 return (0);
530 * arc approved interface (pending)
531 * - can not be modified without approval from an arc
533 * committment level:
534 * public
536 * description:
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.
542 * arguments:
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
548 * raw partition.
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.
554 * return value(s):
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.
562 * preconditions:
563 * none.
565 /* ARGSUSED */
566 char *
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));
576 } else {
577 return (NULL);
581 struct alias {
582 char *alias;
583 char *name;
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" },
602 { "cd", "cdrom0" },
603 { "cd0", "cdrom0" },
604 { "cd1", "cdrom1" },
605 { NULL, NULL }
609 * This is an ON Consolidation Private interface.
611 /* ARGSUSED */
612 char *
613 _media_oldaliases(char *start)
615 struct alias *s;
616 char *p;
617 char *res = NULL;
619 for (s = device_aliases; s->alias != NULL; s++) {
620 if (strcmp(start, s->alias) == 0) {
621 res = strdup(s->name);
622 break;
626 return (res);
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.
636 void
637 _media_printaliases(void)