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]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * scan /dev directory for mountable objects and construct device_allocate
29 * file for allocate....
55 #include <sys/types.h> /* for stat(2), etc. */
57 #include <dirent.h> /* for readdir(3), etc. */
58 #include <unistd.h> /* for readlink(2) */
60 #include <string.h> /* for strcpy(3), etc. */
61 #include <strings.h> /* for bcopy(3C), etc. */
62 #include <stdio.h> /* for perror(3) */
63 #include <stdlib.h> /* for atoi(3) */
67 #include <libdevinfo.h>
70 #include <auth_attr.h>
71 #include <auth_list.h>
72 #include <bsm/devices.h>
73 #include <bsm/devalloc.h>
74 #include <tsol/label.h>
77 #define TEXT_DOMAIN "SUNW_OST_OSCMD"
80 #define MKDEVALLOC "mkdevalloc"
81 #define MKDEVMAPS "mkdevmaps"
83 #define DELTA 5 /* array size delta when full */
84 #define SECLIB "/etc/security/lib"
86 /* "/dev/rst...", "/dev/nrst...", "/dev/rmt/..." */
92 #define DFLT_NTAPE 10 /* size of initial array */
93 #define SIZE_OF_RST 3 /* |rmt| */
94 #define SIZE_OF_NRST 4 /* |nrmt| */
95 #define SIZE_OF_TMP 4 /* |/tmp| */
96 #define SIZE_OF_RMT 8 /* |/dev/rmt| */
97 #define TAPE_CLEAN SECLIB"/st_clean"
99 /* "/dev/audio", "/dev/audioctl", "/dev/sound/..." */
105 #define DFLT_NAUDIO 10 /* size of initial array */
106 #define SIZE_OF_SOUND 10 /* |/dev/sound| */
107 #define AUDIO_CLEAN SECLIB"/audio_clean"
109 /* "/dev/sr", "/dev/nsr", "/dev/dsk/c?t?d0s?", "/dev/rdsk/c?t?d0s?" */
117 #define DFLT_NCD 10 /* size of initial array */
118 #define SIZE_OF_SR 2 /* |sr| */
119 #define SIZE_OF_RSR 3 /* |rsr| */
120 #define SIZE_OF_DSK 8 /* |/dev/dsk| */
121 #define SIZE_OF_RDSK 9 /* |/dev/rdsk| */
122 #define CD_CLEAN SECLIB"/sr_clean"
124 /* "/dev/sr", "/dev/nsr", "/dev/dsk/c?t?d0s?", "/dev/rdsk/c?t?d0s?" */
131 } *rmdisk
, *rmdisk_r
;
132 #define DFLT_RMDISK 10 /* size of initial array */
134 /* "/dev/fd0*", "/dev/rfd0*", "/dev/fd1*", "/dev/rfd1*" */
140 #define DFLT_NFP 10 /* size of initial array */
141 #define SIZE_OF_FD0 3 /* |fd0| */
142 #define SIZE_OF_RFD0 4 /* |rfd0| */
143 #define FLOPPY_CLEAN SECLIB"/fd_clean"
145 static void dotape();
146 static void doaudio();
147 static void dofloppy();
149 static void dormdisk(int);
150 static void initmem();
151 static int expandmem(int, void **, int);
152 static void no_memory(void);
154 int system_labeled
= 0;
161 main(int argc
, char **argv
)
166 (void) setlocale(LC_ALL
, "");
167 (void) textdomain(TEXT_DOMAIN
);
169 if ((progname
= strrchr(argv
[0], '/')) == NULL
)
173 if (strcmp(progname
, MKDEVALLOC
) == 0)
175 else if (strcmp(progname
, MKDEVMAPS
) == 0)
180 system_labeled
= is_system_labeled();
182 if (!system_labeled
) {
184 * is_system_labeled() will return false in case we are
185 * starting before the first reboot after Trusted Extensions
186 * is enabled. Check the setting in /etc/system to see if
187 * TX is enabled (even if not yet booted).
189 if (defopen("/etc/system") == 0) {
190 if (defread("set sys_labeling=1") != NULL
)
193 /* close defaults file */
194 (void) defopen(NULL
);
199 /* test hook: see also devfsadm.c and allocate.c */
200 if (!system_labeled
) {
203 system_labeled
= is_system_labeled_debug(&tx_stat
);
204 if (system_labeled
) {
205 fprintf(stderr
, "/ALLOCATE_FORCE_LABEL is set,\n"
206 "forcing system label on for testing...\n");
211 if (system_labeled
&& do_devalloc
&& (argc
== 2) &&
212 (strcmp(argv
[1], DA_IS_LABELED
) == 0)) {
214 * write device entries to device_allocate and device_maps.
215 * default is to print them on stdout.
220 initmem(); /* initialize memory */
235 struct dirent
*dep
; /* directory entry pointer */
237 char *nm
; /* name/device of special device */
238 char linkvalue
[2048]; /* symlink value */
239 struct stat stat
; /* determine if it's a symlink */
240 int sz
; /* size of symlink value */
241 char *cp
; /* pointer into string */
242 int ntape
; /* max array size */
245 char *dname
, *dtype
, *dclean
;
252 * look for rst* and nrst*
255 if ((dirp
= opendir("/dev")) == NULL
) {
256 perror(gettext("open /dev failure"));
261 while (dep
= readdir(dirp
)) {
262 /* ignore if neither rst* nor nrst* */
263 if (strncmp(dep
->d_name
, "rst", SIZE_OF_RST
) &&
264 strncmp(dep
->d_name
, "nrst", SIZE_OF_NRST
))
267 /* if array full, then expand it */
269 /* will exit(1) if insufficient memory */
270 ntape
= expandmem(i
, (void **)&tape
,
271 sizeof (struct tape
));
274 /* save name (/dev + / + d_name + \0) */
275 nm
= (char *)malloc(SIZE_OF_TMP
+ 1 + strlen(dep
->d_name
) + 1);
278 (void) strcpy(nm
, "/dev/");
279 (void) strcat(nm
, dep
->d_name
);
282 /* ignore if not symbolic link (note i not incremented) */
283 if (lstat(tape
[i
].name
, &stat
) < 0) {
284 perror("stat(2) failed ");
287 if ((stat
.st_mode
& S_IFMT
) != S_IFLNK
)
290 /* get name from symbolic link */
291 if ((sz
= readlink(tape
[i
].name
, linkvalue
,
292 sizeof (linkvalue
))) < 0)
294 nm
= (char *)malloc(sz
+ 1);
297 (void) strncpy(nm
, linkvalue
, sz
);
301 /* get device number */
302 cp
= strrchr(tape
[i
].device
, '/');
303 cp
++; /* advance to device # */
304 (void) sscanf(cp
, "%d", &tape
[i
].number
);
309 (void) closedir(dirp
);
312 * scan /dev/rmt and add entry to table
315 if ((dirp
= opendir("/dev/rmt")) == NULL
) {
316 perror(gettext("open /dev failure"));
320 while (dep
= readdir(dirp
)) {
321 /* skip . .. etc... */
322 if (strncmp(dep
->d_name
, ".", 1) == NULL
)
325 /* if array full, then expand it */
327 /* will exit(1) if insufficient memory */
328 ntape
= expandmem(i
, (void **)&tape
,
329 sizeof (struct tape
));
332 /* save name (/dev/rmt + / + d_name + \0) */
333 nm
= (char *)malloc(SIZE_OF_RMT
+ 1 + strlen(dep
->d_name
) + 1);
336 (void) strcpy(nm
, "/dev/rmt/");
337 (void) strcat(nm
, dep
->d_name
);
340 /* save device name (rmt/ + d_name + \0) */
341 nm
= (char *)malloc(SIZE_OF_TMP
+ strlen(dep
->d_name
) + 1);
344 (void) strcpy(nm
, "rmt/");
345 (void) strcat(nm
, dep
->d_name
);
348 (void) sscanf(dep
->d_name
, "%d", &tape
[i
].number
);
354 (void) closedir(dirp
);
356 /* remove duplicate entries */
357 for (i
= 0; i
< tape_count
- 1; i
++) {
358 for (j
= i
+ 1; j
< tape_count
; j
++) {
359 if (strcmp(tape
[i
].device
, tape
[j
].device
))
365 if (system_labeled
) {
366 dname
= DA_TAPE_NAME
;
367 dtype
= DA_TAPE_TYPE
;
368 dclean
= DA_DEFAULT_TAPE_CLEAN
;
374 for (i
= 0; i
< 8; i
++) {
375 for (j
= 0; j
< tape_count
; j
++) {
376 if (tape
[j
].number
!= i
)
379 (void) da_add_list(&devlist
, tape
[j
].name
, i
,
381 } else if (do_devalloc
) {
382 /* print device_allocate for tape devices */
383 if (system_labeled
) {
384 (void) printf("%s%d%s\\\n",
385 dname
, i
, KV_DELIMITER
);
386 (void) printf("\t%s%s\\\n",
387 DA_TAPE_TYPE
, KV_DELIMITER
);
388 (void) printf("\t%s%s\\\n",
389 DA_RESERVED
, KV_DELIMITER
);
390 (void) printf("\t%s%s\\\n",
391 DA_RESERVED
, KV_DELIMITER
);
392 (void) printf("\t%s%s\\\n",
393 DEFAULT_DEV_ALLOC_AUTH
,
395 (void) printf("\t%s\n\n", dclean
);
398 "st%d;st;reserved;reserved;%s;",
399 i
, DEFAULT_DEV_ALLOC_AUTH
);
400 (void) printf("%s%s\n", SECLIB
,
404 } else if (do_devmaps
) {
405 /* print device_maps for tape devices */
409 if (system_labeled
) {
410 (void) printf("%s%d%s\\\n",
411 dname
, i
, KV_TOKEN_DELIMIT
);
412 (void) printf("\t%s%s\\\n",
413 dtype
, KV_TOKEN_DELIMIT
);
416 (void) printf("st%d:\\\n", i
);
417 (void) printf("\trmt:\\\n");
422 (void) printf("%s", tape
[j
].name
);
425 if (do_devmaps
&& first
) {
426 (void) printf("\n\n");
430 if (do_files
&& tape_count
) {
431 dargs
.rootdir
= NULL
;
432 dargs
.devnames
= NULL
;
433 dargs
.optflag
= DA_ADD
;
434 for (entry
= devlist
.tape
; entry
!= NULL
; entry
= entry
->next
) {
435 dargs
.devinfo
= &(entry
->devinfo
);
436 (void) da_update_device(&dargs
);
445 struct dirent
*dep
; /* directory entry pointer */
447 char *nm
; /* name/device of special device */
448 char linkvalue
[2048]; /* symlink value */
449 struct stat stat
; /* determine if it's a symlink */
450 int sz
; /* size of symlink value */
451 char *cp
; /* pointer into string */
452 int naudio
; /* max array size */
461 naudio
= DFLT_NAUDIO
;
463 if ((dirp
= opendir("/dev")) == NULL
) {
464 perror(gettext("open /dev failure"));
469 while (dep
= readdir(dirp
)) {
470 if (strcmp(dep
->d_name
, "audio") &&
471 strcmp(dep
->d_name
, "audioctl"))
474 /* if array full, then expand it */
476 /* will exit(1) if insufficient memory */
477 naudio
= expandmem(i
, (void **)&audio
,
478 sizeof (struct audio
));
481 /* save name (/dev + 1 + d_name + \0) */
482 nm
= (char *)malloc(SIZE_OF_TMP
+ 1 + strlen(dep
->d_name
) + 1);
485 (void) strcpy(nm
, "/dev/");
486 (void) strcat(nm
, dep
->d_name
);
489 /* ignore if not symbolic link (note i not incremented) */
490 if (lstat(audio
[i
].name
, &stat
) < 0) {
491 perror(gettext("stat(2) failed "));
494 if ((stat
.st_mode
& S_IFMT
) != S_IFLNK
)
497 /* get name from symbolic link */
498 if ((sz
= readlink(audio
[i
].name
, linkvalue
,
499 sizeof (linkvalue
))) < 0)
501 nm
= (char *)malloc(sz
+ 1);
504 (void) strncpy(nm
, linkvalue
, sz
);
506 audio
[i
].device
= nm
;
508 cp
= strrchr(audio
[i
].device
, '/');
509 cp
++; /* advance to device # */
510 (void) sscanf(cp
, "%d", &audio
[i
].number
);
515 (void) closedir(dirp
);
517 if ((dirp
= opendir("/dev/sound")) == NULL
) {
521 while (dep
= readdir(dirp
)) {
522 /* skip . .. etc... */
523 if (strncmp(dep
->d_name
, ".", 1) == NULL
)
526 /* if array full, then expand it */
528 /* will exit(1) if insufficient memory */
529 naudio
= expandmem(i
, (void **)&audio
,
530 sizeof (struct audio
));
533 /* save name (/dev/sound + / + d_name + \0) */
534 nm
= (char *)malloc(SIZE_OF_SOUND
+ 1 +
535 strlen(dep
->d_name
) + 1);
538 (void) strcpy(nm
, "/dev/sound/");
539 (void) strcat(nm
, dep
->d_name
);
542 nm
= (char *)malloc(SIZE_OF_SOUND
+ 1 +
543 strlen(dep
->d_name
) + 1);
546 (void) strcpy(nm
, "/dev/sound/");
547 (void) strcat(nm
, dep
->d_name
);
548 audio
[i
].device
= nm
;
550 (void) sscanf(dep
->d_name
, "%d", &audio
[i
].number
);
555 (void) closedir(dirp
);
560 /* remove duplicate entries */
561 for (i
= 0; i
< audio_count
- 1; i
++) {
562 for (j
= i
+ 1; j
< audio_count
; j
++) {
563 if (strcmp(audio
[i
].device
, audio
[j
].device
))
565 audio
[j
].number
= -1;
569 /* print out device_allocate entries for audio devices */
570 (void) strcpy(dname
, DA_AUDIO_NAME
);
571 slen
= strlen(DA_AUDIO_NAME
);
572 len
= sizeof (dname
) - slen
;
573 dclean
= system_labeled
? DA_DEFAULT_AUDIO_CLEAN
: AUDIO_CLEAN
;
574 for (i
= 0; i
< 8; i
++) {
575 for (j
= 0; j
< audio_count
; j
++) {
576 if (audio
[j
].number
!= i
)
579 (void) snprintf(dname
+slen
, len
, "%d", i
);
581 (void) da_add_list(&devlist
, audio
[j
].name
,
583 } else if (do_devalloc
) {
584 /* print device_allocate for audio devices */
585 if (system_labeled
) {
586 (void) printf("%s%s\\\n",
587 dname
, KV_DELIMITER
);
588 (void) printf("\t%s%s\\\n",
589 DA_AUDIO_TYPE
, KV_DELIMITER
);
590 (void) printf("\t%s%s\\\n",
591 DA_RESERVED
, KV_DELIMITER
);
592 (void) printf("\t%s%s\\\n",
593 DA_RESERVED
, KV_DELIMITER
);
594 (void) printf("\t%s%s\\\n",
595 DEFAULT_DEV_ALLOC_AUTH
,
597 (void) printf("\t%s\n\n", dclean
);
599 (void) printf("audio;audio;");
600 (void) printf("reserved;reserved;%s;",
601 DEFAULT_DEV_ALLOC_AUTH
);
602 (void) printf("%s%s\n", SECLIB
,
606 } else if (do_devmaps
) {
607 /* print device_maps for audio devices */
611 if (system_labeled
) {
612 (void) printf("%s%s\\\n",
613 dname
, KV_TOKEN_DELIMIT
);
614 (void) printf("\t%s%s\\\n",
619 (void) printf("audio:\\\n");
620 (void) printf("\taudio:\\\n");
625 (void) printf("%s", audio
[j
].name
);
628 if (do_devmaps
&& first
) {
629 (void) printf("\n\n");
633 if (do_files
&& audio_count
) {
634 dargs
.rootdir
= NULL
;
635 dargs
.devnames
= NULL
;
636 dargs
.optflag
= DA_ADD
;
637 for (entry
= devlist
.audio
; entry
!= NULL
;
638 entry
= entry
->next
) {
639 dargs
.devinfo
= &(entry
->devinfo
);
640 (void) da_update_device(&dargs
);
649 struct dirent
*dep
; /* directory entry pointer */
651 char *nm
; /* name/device of special device */
652 char linkvalue
[2048]; /* symlink value */
653 struct stat stat
; /* determine if it's a symlink */
654 int sz
; /* size of symlink value */
655 char *cp
; /* pointer into string */
656 int nfp
; /* max array size */
657 int floppy_count
= 0;
659 char *dname
, *dclean
;
666 * look for fd* and rfd*
669 if ((dirp
= opendir("/dev")) == NULL
) {
670 perror(gettext("open /dev failure"));
675 while (dep
= readdir(dirp
)) {
676 /* ignore if neither rst* nor nrst* */
677 if (strncmp(dep
->d_name
, "fd0", SIZE_OF_FD0
) &&
678 strncmp(dep
->d_name
, "rfd0", SIZE_OF_RFD0
) &&
679 strncmp(dep
->d_name
, "fd1", SIZE_OF_FD0
) &&
680 strncmp(dep
->d_name
, "rfd0", SIZE_OF_RFD0
))
683 /* if array full, then expand it */
685 /* will exit(1) if insufficient memory */
686 nfp
= expandmem(i
, (void **)&fp
, sizeof (struct fp
));
689 /* save name (/dev + 1 + d_name + \0) */
690 nm
= (char *)malloc(SIZE_OF_TMP
+ 1 + strlen(dep
->d_name
) + 1);
693 (void) strcpy(nm
, "/dev/");
694 (void) strcat(nm
, dep
->d_name
);
697 /* ignore if not symbolic link (note i not incremented) */
698 if (lstat(fp
[i
].name
, &stat
) < 0) {
699 perror(gettext("stat(2) failed "));
702 if ((stat
.st_mode
&S_IFMT
) != S_IFLNK
)
705 /* get name from symbolic link */
706 if ((sz
= readlink(fp
[i
].name
, linkvalue
,
707 sizeof (linkvalue
))) < 0)
709 nm
= (char *)malloc(sz
+1);
712 (void) strncpy(nm
, linkvalue
, sz
);
716 /* get device number */
717 cp
= strchr(fp
[i
].name
, 'd');
718 cp
++; /* advance to device # */
719 cp
= strchr(cp
, 'd');
720 cp
++; /* advance to device # */
721 (void) sscanf(cp
, "%d", &fp
[i
].number
);
726 (void) closedir(dirp
);
730 /* print out device_allocate entries for floppy devices */
731 if (system_labeled
) {
732 dname
= DA_FLOPPY_NAME
;
733 dclean
= DA_DEFAULT_DISK_CLEAN
;
736 dclean
= FLOPPY_CLEAN
;
738 for (i
= 0; i
< 8; i
++) {
739 for (j
= 0; j
< floppy_count
; j
++) {
740 if (fp
[j
].number
!= i
)
743 (void) da_add_list(&devlist
, fp
[j
].name
, i
,
745 } else if (do_devalloc
) {
746 /* print device_allocate for floppy devices */
747 if (system_labeled
) {
748 (void) printf("%s%d%s\\\n",
749 dname
, i
, KV_DELIMITER
);
750 (void) printf("\t%s%s\\\n",
751 DA_FLOPPY_TYPE
, KV_DELIMITER
);
752 (void) printf("\t%s%s\\\n",
753 DA_RESERVED
, KV_DELIMITER
);
754 (void) printf("\t%s%s\\\n",
755 DA_RESERVED
, KV_DELIMITER
);
756 (void) printf("\t%s%s\\\n",
757 DEFAULT_DEV_ALLOC_AUTH
,
759 (void) printf("\t%s\n\n", dclean
);
762 "fd%d;fd;reserved;reserved;%s;",
763 i
, DEFAULT_DEV_ALLOC_AUTH
);
764 (void) printf("%s%s\n", SECLIB
,
768 } else if (do_devmaps
) {
769 /* print device_maps for floppy devices */
773 if (system_labeled
) {
774 (void) printf("%s%d%s\\\n",
775 dname
, i
, KV_TOKEN_DELIMIT
);
776 (void) printf("\t%s%s\\\n",
781 (void) printf("fd%d:\\\n", i
);
782 (void) printf("\tfd:\\\n");
786 (void) printf("/dev/diskette ");
792 (void) printf("%s", fp
[j
].name
);
795 if (do_devmaps
&& first
) {
796 (void) printf("\n\n");
800 if (do_files
&& floppy_count
) {
801 dargs
.rootdir
= NULL
;
802 dargs
.devnames
= NULL
;
803 dargs
.optflag
= DA_ADD
;
804 for (entry
= devlist
.floppy
; entry
!= NULL
;
805 entry
= entry
->next
) {
806 dargs
.devinfo
= &(entry
->devinfo
);
807 (void) da_update_device(&dargs
);
816 struct dirent
*dep
; /* directory entry pointer */
818 char *nm
; /* name/device of special device */
819 char linkvalue
[2048]; /* symlink value */
820 struct stat stat
; /* determine if it's a symlink */
821 int sz
; /* size of symlink value */
822 char *cp
; /* pointer into string */
823 int id
; /* disk id */
824 int ctrl
; /* disk controller */
825 int ncd
; /* max array size */
828 char *dname
, *dclean
;
835 * look for sr* and rsr*
838 if ((dirp
= opendir("/dev")) == NULL
) {
839 perror(gettext("open /dev failure"));
844 while (dep
= readdir(dirp
)) {
845 /* ignore if neither sr* nor rsr* */
846 if (strncmp(dep
->d_name
, "sr", SIZE_OF_SR
) &&
847 strncmp(dep
->d_name
, "rsr", SIZE_OF_RSR
))
850 /* if array full, then expand it */
852 /* will exit(1) if insufficient memory */
853 ncd
= expandmem(i
, (void **)&cd
, sizeof (struct cd
));
856 /* save name (/dev + / + d_name + \0) */
857 nm
= (char *)malloc(SIZE_OF_TMP
+ 1 + strlen(dep
->d_name
) + 1);
860 (void) strcpy(nm
, "/dev/");
861 (void) strcat(nm
, dep
->d_name
);
864 /* ignore if not symbolic link (note i not incremented) */
865 if (lstat(cd
[i
].name
, &stat
) < 0) {
866 perror(gettext("stat(2) failed "));
869 if ((stat
.st_mode
& S_IFMT
) != S_IFLNK
)
872 /* get name from symbolic link */
873 if ((sz
= readlink(cd
[i
].name
, linkvalue
, sizeof (linkvalue
))) <
877 nm
= (char *)malloc(sz
+ 1);
880 (void) strncpy(nm
, linkvalue
, sz
);
884 cp
= strrchr(cd
[i
].device
, '/');
885 cp
++; /* advance to device # */
886 (void) sscanf(cp
, "c%dt%d", &cd
[i
].controller
, &cd
[i
].number
);
887 cd
[i
].id
= cd
[i
].number
;
893 (void) closedir(dirp
);
896 * scan /dev/dsk for cd devices
899 if ((dirp
= opendir("/dev/dsk")) == NULL
) {
900 perror("gettext(open /dev/dsk failure)");
904 while (dep
= readdir(dirp
)) {
905 /* skip . .. etc... */
906 if (strncmp(dep
->d_name
, ".", 1) == NULL
)
909 /* get device # (disk #) */
910 if (sscanf(dep
->d_name
, "c%dt%d", &ctrl
, &id
) != 2)
913 /* see if this is one of the cd special devices */
914 for (j
= 0; j
< cd_count
; j
++) {
915 if (cd
[j
].number
== id
&& cd
[j
].controller
== ctrl
)
920 /* add new entry to table (/dev/dsk + / + d_name + \0) */
922 /* if array full, then expand it */
924 /* will exit(1) if insufficient memory */
925 ncd
= expandmem(i
, (void **)&cd
, sizeof (struct cd
));
928 nm
= (char *)malloc(SIZE_OF_DSK
+ 1 + strlen(dep
->d_name
) + 1);
931 (void) strcpy(nm
, "/dev/dsk/");
932 (void) strcat(nm
, dep
->d_name
);
944 (void) closedir(dirp
);
947 * scan /dev/rdsk for cd devices
950 if ((dirp
= opendir("/dev/rdsk")) == NULL
) {
951 perror(gettext("open /dev/dsk failure"));
955 while (dep
= readdir(dirp
)) {
956 /* skip . .. etc... */
957 if (strncmp(dep
->d_name
, ".", 1) == NULL
)
960 /* get device # (disk #) */
961 if (sscanf(dep
->d_name
, "c%dt%d", &ctrl
, &id
) != 2)
964 /* see if this is one of the cd special devices */
965 for (j
= 0; j
< cd_count
; j
++) {
966 if (cd
[j
].number
== id
&& cd
[j
].controller
== ctrl
)
971 /* add new entry to table (/dev/rdsk + / + d_name + \0) */
973 /* if array full, then expand it */
975 /* will exit(1) if insufficient memory */
976 ncd
= expandmem(i
, (void **)&cd
, sizeof (struct cd
));
979 nm
= (char *)malloc(SIZE_OF_RDSK
+ 1 + strlen(dep
->d_name
) + 1);
982 (void) strcpy(nm
, "/dev/rdsk/");
983 (void) strcat(nm
, dep
->d_name
);
992 cd
[i
].controller
= ctrl
;
997 (void) closedir(dirp
);
1001 if (system_labeled
) {
1003 dclean
= DA_DEFAULT_DISK_CLEAN
;
1008 for (i
= 0; i
< 8; i
++) {
1009 for (j
= 0; j
< cd_count
; j
++) {
1013 (void) da_add_list(&devlist
, cd
[j
].name
, i
,
1015 } else if (do_devalloc
) {
1016 /* print device_allocate for cd devices */
1017 if (system_labeled
) {
1018 (void) printf("%s%d%s\\\n",
1019 dname
, i
, KV_DELIMITER
);
1020 (void) printf("\t%s%s\\\n",
1021 DA_CD_TYPE
, KV_DELIMITER
);
1022 (void) printf("\t%s%s\\\n",
1023 DA_RESERVED
, KV_DELIMITER
);
1024 (void) printf("\t%s%s\\\n",
1025 DA_RESERVED
, KV_DELIMITER
);
1026 (void) printf("\t%s%s\\\n",
1027 DEFAULT_DEV_ALLOC_AUTH
,
1029 (void) printf("\t%s\n\n", dclean
);
1032 "sr%d;sr;reserved;reserved;%s;",
1033 i
, DEFAULT_DEV_ALLOC_AUTH
);
1034 (void) printf("%s%s\n", SECLIB
,
1038 } else if (do_devmaps
) {
1039 /* print device_maps for cd devices */
1043 if (system_labeled
) {
1044 (void) printf("%s%d%s\\\n",
1045 dname
, i
, KV_TOKEN_DELIMIT
);
1046 (void) printf("\t%s%s\\\n",
1049 (void) printf("\t");
1051 (void) printf("sr%d:\\\n", i
);
1052 (void) printf("\tsr:\\\n");
1053 (void) printf("\t");
1057 (void) printf("%s", cd
[j
].name
);
1060 if (do_devmaps
&& first
) {
1061 (void) printf("\n\n");
1065 if (do_files
&& cd_count
) {
1066 dargs
.rootdir
= NULL
;
1067 dargs
.devnames
= NULL
;
1068 dargs
.optflag
= DA_ADD
;
1069 for (entry
= devlist
.cd
; entry
!= NULL
; entry
= entry
->next
) {
1070 dargs
.devinfo
= &(entry
->devinfo
);
1071 (void) da_update_device(&dargs
);
1079 dormdisk(int cd_count
)
1082 struct dirent
*dep
; /* directory entry pointer */
1084 char *nm
; /* name/device of special device */
1085 int id
; /* disk id */
1086 int ctrl
; /* disk controller */
1087 int nrmdisk
; /* max array size */
1094 char path
[MAXPATHLEN
];
1098 nrmdisk
= DFLT_RMDISK
;
1099 i
= rmdisk_count
= 0;
1102 * scan /dev/dsk for rmdisk devices
1104 if ((dirp
= opendir("/dev/dsk")) == NULL
) {
1105 perror("gettext(open /dev/dsk failure)");
1109 while (dep
= readdir(dirp
)) {
1113 /* skip . .. etc... */
1114 if (strncmp(dep
->d_name
, ".", 1) == NULL
)
1117 /* get device # (disk #) */
1118 if (sscanf(dep
->d_name
, "c%dt%d", &ctrl
, &id
) != 2)
1121 /* see if we've already examined this device */
1122 for (j
= 0; j
< i
; j
++) {
1123 if (id
== rmdisk
[j
].id
&&
1124 ctrl
== rmdisk
[j
].controller
&&
1125 (strcmp(dep
->d_name
, rmdisk
[j
].name
) == 0)) {
1129 if (id
== rmdisk
[j
].id
&& ctrl
!= rmdisk
[j
].controller
)
1131 * c2t0d0s0 is a different rmdisk than c3t0d0s0.
1133 id
= rmdisk
[j
].id
+ 1;
1138 /* ignore if this is a cd */
1139 for (j
= 0; j
< cd_count
; j
++) {
1140 if (id
== cd
[j
].id
&& ctrl
== cd
[j
].controller
) {
1148 /* see if device is removable */
1149 (void) snprintf(path
, sizeof (path
), "%s%s", "/dev/rdsk/",
1151 if ((fd
= open(path
, O_RDONLY
| O_NONBLOCK
)) < 0)
1153 (void) ioctl(fd
, DKIOCREMOVABLE
, &removable
);
1159 * add new entry to table (/dev/dsk + / + d_name + \0)
1160 * if array full, then expand it
1163 /* will exit(1) if insufficient memory */
1164 nrmdisk
= expandmem(i
, (void **)&rmdisk
,
1165 sizeof (struct rmdisk
));
1166 /* When we expand rmdisk, need to expand rmdisk_r */
1167 (void) expandmem(i
, (void **)&rmdisk_r
,
1168 sizeof (struct rmdisk
));
1170 nm
= (char *)malloc(SIZE_OF_DSK
+ 1 + strlen(dep
->d_name
) + 1);
1173 (void) strcpy(nm
, "/dev/dsk/");
1174 (void) strcat(nm
, dep
->d_name
);
1175 rmdisk
[i
].name
= nm
;
1177 rmdisk
[i
].controller
= ctrl
;
1178 rmdisk
[i
].device
= "";
1179 rmdisk
[i
].number
= id
;
1180 rmdisk_r
[i
].name
= strdup(path
);
1185 (void) closedir(dirp
);
1187 for (i
= 0, j
= rmdisk_count
; i
< rmdisk_count
; i
++, j
++) {
1189 /* will exit(1) if insufficient memory */
1190 nrmdisk
= expandmem(j
, (void **)&rmdisk
,
1191 sizeof (struct rmdisk
));
1193 rmdisk
[j
].name
= rmdisk_r
[i
].name
;
1194 rmdisk
[j
].id
= rmdisk
[i
].id
;
1195 rmdisk
[j
].controller
= rmdisk
[i
].controller
;
1196 rmdisk
[j
].device
= rmdisk
[i
].device
;
1197 rmdisk
[j
].number
= rmdisk
[i
].number
;
1201 for (i
= 0; i
< 8; i
++) {
1202 for (j
= 0; j
< rmdisk_count
; j
++) {
1203 if (rmdisk
[j
].id
!= i
)
1206 (void) da_add_list(&devlist
, rmdisk
[j
].name
, i
,
1208 } else if (do_devalloc
) {
1209 /* print device_allocate for rmdisk devices */
1210 (void) printf("%s%d%s\\\n",
1211 DA_RMDISK_NAME
, i
, KV_DELIMITER
);
1212 (void) printf("\t%s%s\\\n",
1213 DA_RMDISK_TYPE
, KV_DELIMITER
);
1214 (void) printf("\t%s%s\\\n",
1215 DA_RESERVED
, KV_DELIMITER
);
1216 (void) printf("\t%s%s\\\n",
1217 DA_RESERVED
, KV_DELIMITER
);
1218 (void) printf("\t%s%s\\\n",
1219 DEFAULT_DEV_ALLOC_AUTH
, KV_DELIMITER
);
1220 (void) printf("\t%s\n", DA_DEFAULT_DISK_CLEAN
);
1222 } else if (do_devmaps
) {
1223 /* print device_maps for rmdisk devices */
1227 (void) printf("%s%d%s\\\n",
1230 (void) printf("\t%s%s\\\n",
1231 DA_RMDISK_TYPE
, KV_TOKEN_DELIMIT
);
1232 (void) printf("\t");
1235 (void) printf("%s", rmdisk
[j
].name
);
1238 if (do_devmaps
&& first
) {
1239 (void) printf("\n\n");
1243 if (do_files
&& rmdisk_count
) {
1244 dargs
.rootdir
= NULL
;
1245 dargs
.devnames
= NULL
;
1246 dargs
.optflag
= DA_ADD
;
1247 for (entry
= devlist
.rmdisk
; entry
!= NULL
;
1248 entry
= entry
->next
) {
1249 dargs
.devinfo
= &(entry
->devinfo
);
1250 (void) da_update_device(&dargs
);
1255 /* set default array sizes */
1259 tape
= (struct tape
*)calloc(DFLT_NTAPE
, sizeof (struct tape
));
1260 audio
= (struct audio
*)calloc(DFLT_NAUDIO
, sizeof (struct audio
));
1261 cd
= (struct cd
*)calloc(DFLT_NCD
, sizeof (struct cd
));
1262 fp
= (struct fp
*)calloc(DFLT_NFP
, sizeof (struct fp
));
1263 if (system_labeled
) {
1264 rmdisk
= (struct rmdisk
*)calloc(DFLT_RMDISK
,
1265 sizeof (struct rmdisk
));
1268 rmdisk_r
= (struct rmdisk
*)calloc(DFLT_RMDISK
,
1269 sizeof (struct rmdisk
));
1270 if (rmdisk_r
== NULL
)
1274 if (tape
== NULL
|| audio
== NULL
|| cd
== NULL
|| fp
== NULL
)
1277 devlist
.audio
= devlist
.cd
= devlist
.floppy
= devlist
.rmdisk
=
1278 devlist
.tape
= NULL
;
1281 /* note n will be # elments in array (and could be 0) */
1283 expandmem(int n
, void **array
, int size
)
1288 /* get new array space (n + DELTA) */
1289 new = (void *)calloc(n
+ DELTA
, size
);
1292 perror("memory allocation failed");
1296 /* copy old array into new space */
1297 bcopy(old
, new, n
* size
);
1299 /* now release old arrary */
1310 (void) fprintf(stderr
, "%s: %s\n", "mkdevalloc",
1311 gettext("out of memory"));