1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <dirent.h>
29 #include <fcntl.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <limits.h>
33 #include <unistd.h>
34 #include <sys/mkdev.h>
35 #include <volmgt.h>
36 #include <ctype.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/param.h>
40 #include "volmgt_private.h"
41
42 /*
43 * arc approved interface
44 * - can not be modified without approval from an arc
45 *
46 * committment level:
47 * public
48 *
49 * description:
50 * volmgt_running: check to see if volume management is running.
51 *
52 * arguments:
53 * none.
54 *
55 * return value(s):
56 * TRUE if volume management is running, FALSE if not.
57 *
58 * preconditions:
59 * none.
60 */
61 int
volmgt_running(void)62 volmgt_running(void)
63 {
64 /* vold is dead */
65 return (FALSE);
66 }
67
68
69 /*
70 * arc approved interface
71 * - can not be modified without approval from an arc
72 *
73 * committment level:
74 * public
75 *
76 * description:
77 * volmgt_inuse: check to see if volume management is currently
78 * managing a particular device.
79 *
80 * arguments:
81 * path - the name of the device in /dev. For example,
82 * "/dev/rdiskette".
83 *
84 * return value(s):
85 * TRUE if volume management is managing the device, FALSE if not.
86 *
87 * preconditions:
88 * none.
89 */
90 /* ARGSUSED */
91 int
volmgt_inuse(char * path)92 volmgt_inuse(char *path)
93 {
94 return (FALSE);
95 }
96
97
98 /*
99 * arc approved interface
100 * - can not be modified without approval from an arc
101 *
102 * committment level:
103 * public
104 *
105 * description:
106 * volmgt_check: have volume management look at its devices to check
107 * for media having arrived. Since volume management can't
108 * automatically check all types of devices, this function is provided
109 * to allow applications to cause the check to happen automatically.
110 *
111 * arguments:
112 * path - the name of the device in /dev. For example,
113 * /dev/rdiskette. If path is NULL, all "checkable" devices are
114 * checked.
115 *
116 * return value(s):
117 * TRUE if media was found in the device, FALSE if not.
118 *
119 * preconditions:
120 * volume management must be running.
121 */
122 /* ARGSUSED */
123 int
volmgt_check(char * path)124 volmgt_check(char *path)
125 {
126 return (FALSE);
127 }
128
129
130 /*
131 * arc approved interface
132 * - can not be modified without approval from an arc
133 *
134 * committment level:
135 * public
136 *
137 * description:
138 * volmgt_ownspath: check to see if the given path is contained in
139 * the volume management name space.
140 *
141 * arguments:
142 * path - string containing the path.
143 *
144 * return value(s):
145 * TRUE if the path is owned by volume management, FALSE if not.
146 * Will return FALSE if volume management isn't running.
147 *
148 * preconditions:
149 * none.
150 */
151 /* ARGSUSED */
152 int
volmgt_ownspath(char * path)153 volmgt_ownspath(char *path)
154 {
155 return (FALSE);
156 }
157
158
159 /*
160 * arc approved interface
161 * - can not be modified without approval from an arc
162 *
163 * committment level:
164 * public
165 *
166 * description:
167 * volmgt_root: return the root of where the volume management
168 * name space is mounted.
169 *
170 * arguments:
171 * none.
172 *
173 * return value(s):
174 * Returns a pointer to a static string containing the path to the
175 * volume management root (e.g. "/vol").
176 * Will return NULL if volume management isn't running.
177 *
178 * preconditions:
179 * none.
180 */
181 const char *
volmgt_root(void)182 volmgt_root(void)
183 {
184 static const char *vold_root = "/dev";
185
186 return (vold_root);
187 }
188
189
190 /*
191 * arc approved interface
192 * - can not be modified without approval from an arc
193 *
194 * committment level:
195 * public
196 *
197 * description:
198 * volmgt_symname: Returns the volume management symbolic name
199 * for a given device. If an application wants to determine
200 * what the symbolic name (e.g. "floppy0") for the /dev/rdiskette
201 * device would be, this is the function to use.
202 *
203 * arguments:
204 * path - a string containing the /dev device name. For example,
205 * "/dev/diskette" or "/dev/rdiskette".
206 *
207 * Note: must be a block- or char-spcl device, and have a non-zero
208 * st_rdev (real device) stat() value.
209 *
210 * return value(s):
211 * pointer to a string containing the symbolic name.
212 *
213 * NULL indicates that volume management isn't managing that device.
214 *
215 * The string must be free(3)'d.
216 *
217 * preconditions:
218 * none.
219 */
220 /* ARGSUSED */
221 char *
volmgt_symname(char * path)222 volmgt_symname(char *path)
223 {
224 return (NULL);
225 }
226
227
228 /*
229 * arc approved interface
230 * - can not be modified without approval from an arc
231 *
232 * committment level:
233 * public
234 *
235 * description:
236 * volmgt_symdev: Returns the device given the volume management
237 * symbolic name. If an application wants to determine
238 * what the device associated with a particular symbolic name
239 * might be, this is the function to use.
240 *
241 * arguments:
242 * path - a string containing the symbolic device name. For example,
243 * "cdrom0" or "floppy0".
244 *
245 * return value(s):
246 * pointer to a string containing the /dev name.
247 *
248 * NULL indicates that volume management isn't managing that device.
249 *
250 * The string must be free(3)'d.
251 *
252 * preconditions:
253 * none.
254 */
255 /* ARGSUSED */
256 char *
volmgt_symdev(char * symname)257 volmgt_symdev(char *symname)
258 {
259 return (NULL);
260 }
261
262
263 /*
264 * arc approved interface
265 * - can not be modified without approval from an arc
266 *
267 * committment level:
268 * public
269 *
270 * description:
271 * volmgt_feat_enabled: check to see if a volume management feature
272 * is available
273 *
274 * arguments:
275 * feat_str - a string containing the feature to be checked for
276 *
277 * return value(s):
278 * return non-zero if the specified feature is available in
279 * volume management, else return zero
280 *
281 * preconditions:
282 * none.
283 */
284
285
286 /*
287 * the following is a lit of the "feature" available in volmgt
288 *
289 * this list is meant to be updated when new features (that users may
290 * want to use) are added to volmgt
291 *
292 * note: feature strings added should be all lower case, and spaces are
293 * discouraged
294 *
295 * (see psarc/1995/138 for more info)
296 */
297 static char *volmgt_feat_list[] = {
298 #ifdef DIRECT_DEV_ACCESS_WORKING
299 "direct-dev-access", /* access through /dev co-exists */
300 #endif
301 "floppy-summit-interfaces", /* volmgt_{acquire,release} */
302 NULL
303 };
304
305
306 int
volmgt_feature_enabled(char * feat_str)307 volmgt_feature_enabled(char *feat_str)
308 {
309 return (0);
310 }
311 /*
312 * arc approved interface
313 * - can not be modified without approval from an arc
314 *
315 * committment level:
316 * uncommitted
317 *
318 * description:
319 * volmgt_acquire: try to acquire the volmgt advisory device reservation
320 * for a specific device.
321 *
322 * arguments:
323 * dev - a device name to attempt reserving. This string can be:
324 * - a full path name to a device
325 * - a symbolic device name (e.g. floppy0)
326 *
327 * id - a reservation string that hopefully describes the application
328 * making this reservation.
329 *
330 * pid - a pointer to a pid_t type. If this argument is not NULL
331 * and the requested device is already reserved, the process
332 * id of the reservation owner will be returned in this
333 * location.
334 *
335 * ovr - an override indicator. If set to non-zero, the caller requests
336 * that this reservation be made unconditionally.
337 *
338 * err - the address of a pointer to a string which is to receive the
339 * id argument used when the current device was reserved. This
340 * is only used when the current reservation attempt fails due
341 * to an already existing reservation for this device.
342 *
343 * return value(s):
344 * A non-zero indicator if successful.
345 *
346 * A zero indicator if unsuccessful. If errno is EBUSY, then the err
347 * argument will be set to point to the string that the process currently
348 * holding the reservation supplied when reserving the device. It is up
349 * to the caller to release the storage occupied by the string via
350 * free(3C) when no longer needed.
351 *
352 * preconditions:
353 * none
354 */
355 /* ARGSUSED */
356 int
volmgt_acquire(char * dev,char * id,int ovr,char ** err,pid_t * pidp)357 volmgt_acquire(char *dev, char *id, int ovr, char **err, pid_t *pidp)
358 {
359 return (0);
360 }
361
362
363 /*
364 * arc approved interface
365 * - can not be modified without approval from an arc
366 *
367 * committment level:
368 * uncommitted
369 *
370 * description:
371 * volmgt_release: try to release the volmgt advisory device reservation
372 * for a specific device.
373 *
374 * arguments:
375 * dev - a device name to attempt reserving. This string can be:
376 * - a full path name to a device
377 * - a symbolic device name (e.g. floppy0)
378 *
379 * return value(s):
380 * A non-zero indicator if successful
381 * A zero indicator if unsuccessful
382 *
383 * preconditions:
384 * none
385 */
386 int
volmgt_release(char * dev)387 volmgt_release(char *dev)
388 {
389 return (0);
390 }
391
392
393 /*
394 * returns the "value" of the attribute.
395 * If the attribute is boolean and is TRUE,
396 * "true" is returned. If the boolean is
397 * FALSE, NULL is returned. If the attribute
398 * doesn't exist, NULL is returned. The pointer
399 * returned by media_getattr has been malloc'd and
400 * it is the callers responsibility to free it.
401 */
402 /*
403 * arc approved interface
404 * - can not be modified without approval from an arc
405 *
406 * committment level:
407 * public
408 *
409 * description:
410 * media_getattr: returns the value for an attribute for a piece of
411 * removable media.
412 *
413 * arguments:
414 * path - Path to the media in /vol. Can be the block or character
415 * device.
416 *
417 * attr - name of the attribute.
418 *
419 * return value(s):
420 * returns NULL or a pointer to a string that contains the value for
421 * the requested attribute.
422 *
423 * NULL can mean:
424 * - the media doesn't exist
425 * - there is no more space for malloc(3)
426 * - the attribute doesn't exist for the named media
427 * - the attribute is a boolean and is FALSE
428 *
429 * the pointer to the string must be free'd with free(3).
430 *
431 * preconditions:
432 * volume management (vold) must be running.
433 */
434 /* ARGSUSED */
435 char *
media_getattr(char * vol_path,char * attr)436 media_getattr(char *vol_path, char *attr)
437 {
438 return (NULL);
439 }
440
441
442 /*
443 * sets the attribute "attr" to value "value".
444 *
445 * If value == "" the flag is
446 * considered to be a TRUE boolean.
447 *
448 * If value == 0, it is considered to be a FALSE boolean.
449 * returns TRUE on success, FALSE on failure.
450 *
451 * Can fail for reasons of permission, or if you
452 * write a read-only attribute.
453 */
454
455 /*
456 * arc approved interface
457 * - can not be modified without approval from an arc
458 *
459 * committment level:
460 * public
461 *
462 * description:
463 * media_setattr: set an attribute for a piece of media to a
464 * particular value.
465 *
466 * arguments:
467 * path - Path to the media in /vol. Can be the block or character
468 * device.
469 *
470 * attr - name of the attribute.
471 *
472 * value - value of the attribute. If value == "", the flag is
473 * considered to be a boolean that is TRUE. If value == 0, it
474 * is considered to be a FALSE boolean.
475 *
476 * return value(s):
477 * TRUE on success, FALSE for failure.
478 *
479 * Can fail because:
480 * - don't have permission to set the attribute because caller
481 * is not the owner of the media and attribute is a "system"
482 * attribute.
483 *
484 * - don't have permission to set the attribute because the
485 * attribute is a "system" attribute and is read-only.
486 *
487 * preconditions:
488 * volume management must be running.
489 */
490 /* ARGSUSED */
491 int
media_setattr(char * vol_path,char * attr,char * value)492 media_setattr(char *vol_path, char *attr, char *value)
493 {
494 return (FALSE);
495 }
496
497
498 /*
499 * Returns the "id" of a volume. If the returned value
500 * & VOLID_TMP, the volume is temporary and this value
501 * cannot be relied upon across reboots.
502 */
503 /*
504 * arc approved interface
505 * - can not be modified without approval from an arc
506 *
507 * committment level:
508 * public
509 *
510 * description:
511 * media_getid: return the "id" of a piece of media.
512 *
513 * arguments:
514 * path - Path to the media in /vol. Can be the block or character
515 * device.
516 * return value(s):
517 * returns a u_longlong_t that is the "id" of the volume.
518 *
519 * preconditions:
520 * volume management must be running.
521 */
522 u_longlong_t
media_getid(char * vol_path)523 media_getid(char *vol_path)
524 {
525 return (0);
526 }
527 /*
528 * arc approved interface (pending)
529 * - can not be modified without approval from an arc
530 *
531 * committment level:
532 * public
533 *
534 * description:
535 * media_findname: try to come up with the character device when
536 * provided with a starting point. This interface provides the
537 * application programmer to provide "user friendly" names and
538 * easily determine the "/vol" name.
539 *
540 * arguments:
541 * start - a string describing a device. This string can be:
542 * - a full path name to a device (insures it's a
543 * character device by using getfullrawname()).
544 * - a full path name to a volume management media name
545 * with partitions (will return the lowest numbered
546 * raw partition.
547 * - the name of a piece of media (e.g. "fred").
548 * - a symbolic device name (e.g. floppy0, cdrom0, etc)
549 * - a name like "floppy" or "cdrom". Will pick the lowest
550 * numbered device with media in it.
551 *
552 * return value(s):
553 * A pointer to a string that contains the character device
554 * most appropriate to the "start" argument.
555 *
556 * NULL indicates that we were unable to find media based on "start".
557 *
558 * The string must be free(3)'d.
559 *
560 * preconditions:
561 * none.
562 */
563 /* ARGSUSED */
564 char *
media_findname(char * start)565 media_findname(char *start)
566 {
567 /*
568 * Eventually should implement using HAL interfaces.
569 * In the short term however, return NULL for aliases,
570 * and self for absolute pathnames.
571 */
572 if (start[0] == '/') {
573 return (strdup(start));
574 } else {
575 return (NULL);
576 }
577 }
578
579 struct alias {
580 char *alias;
581 char *name;
582 };
583
584 /*
585 * "old" aliases -- used to be used when vold wasn't running
586 */
587 static struct alias device_aliases[] = {
588 { "fd", "/dev/rdiskette" },
589 { "fd0", "/dev/rdiskette" },
590 { "fd1", "/dev/rdiskette1" },
591 { "diskette", "/dev/rdiskette" },
592 { "diskette0", "/dev/rdiskette0" },
593 { "diskette1", "/dev/rdiskette1" },
594 { "rdiskette", "/dev/rdiskette" },
595 { "rdiskette0", "/dev/rdiskette0" },
596 { "rdiskette1", "/dev/rdiskette1" },
597 { "floppy", "/dev/rdiskette" },
598 { "floppy0", "/dev/rdiskette0" },
599 { "floppy1", "/dev/rdiskette1" },
600 { "cd", "cdrom0" },
601 { "cd0", "cdrom0" },
602 { "cd1", "cdrom1" },
603 { NULL, NULL }
604 };
605
606 /*
607 * This is an ON Consolidation Private interface.
608 */
609 /* ARGSUSED */
610 char *
_media_oldaliases(char * start)611 _media_oldaliases(char *start)
612 {
613 struct alias *s;
614 char *p;
615 char *res = NULL;
616
617 for (s = device_aliases; s->alias != NULL; s++) {
618 if (strcmp(start, s->alias) == 0) {
619 res = strdup(s->name);
620 break;
621 }
622 }
623
624 return (res);
625 }
626
627
628 /*
629 * This is an ON Consolidation Private interface.
630 *
631 * Print out the aliases available to the program user. Changes
632 * depending in whether volume management is running.
633 */
634 void
_media_printaliases(void)635 _media_printaliases(void)
636 {
637 }
638