-
Notifications
You must be signed in to change notification settings - Fork 813
Expand file tree
/
Copy pathdevfsadm.c
More file actions
8787 lines (7626 loc) · 209 KB
/
devfsadm.c
File metadata and controls
8787 lines (7626 loc) · 209 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright 2016 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2019, Joyent, Inc.
*/
/*
* Devfsadm replaces drvconfig, audlinks, disks, tapes, ports, devlinks
* as a general purpose device administrative utility. It creates
* devices special files in /devices and logical links in /dev, and
* coordinates updates to /etc/path_to_instance with the kernel. It
* operates in both command line mode to handle user or script invoked
* reconfiguration updates, and operates in daemon mode to handle dynamic
* reconfiguration for hotplugging support.
*/
#include <string.h>
#include <deflt.h>
#include <tsol/label.h>
#include <bsm/devices.h>
#include <bsm/devalloc.h>
#include <utime.h>
#include <sys/param.h>
#include <bsm/libbsm.h>
#include <zone.h>
#include "devfsadm_impl.h"
/* externs from devalloc.c */
extern void _reset_devalloc(int);
extern void _update_devalloc_db(devlist_t *, int, int, char *, char *);
extern int _da_check_for_usb(char *, char *);
/* create or remove nodes or links. unset with -n */
static int file_mods = TRUE;
/* cleanup mode. Set with -C */
static int cleanup = FALSE;
/* devlinks -d compatibility */
static int devlinks_debug = FALSE;
/* flag to check if system is labeled */
int system_labeled = FALSE;
/* flag to enable/disable device allocation with -e/-d */
static int devalloc_flag = 0;
/* flag that indicates if device allocation is on or not */
static int devalloc_is_on = 0;
/* flag to update device allocation database for this device type */
static int update_devdb = 0;
/*
* devices to be deallocated with -d :
* audio, floppy, cd, floppy, tape, rmdisk.
*/
static char *devalloc_list[10] = {DDI_NT_AUDIO, DDI_NT_CD, DDI_NT_CD_CHAN,
DDI_NT_FD, DDI_NT_TAPE, DDI_NT_BLOCK_CHAN,
DDI_NT_UGEN, DDI_NT_USB_ATTACHMENT_POINT,
DDI_NT_SCSI_NEXUS, NULL};
/* list of allocatable devices */
static devlist_t devlist;
/* load a single driver only. set with -i */
static int single_drv = FALSE;
static char *driver = NULL;
/* attempt to load drivers or defer attach nodes */
static int load_attach_drv = TRUE;
/* reload all driver.conf files */
static int update_all_drivers = FALSE;
/* set if invoked via /usr/lib/devfsadm/devfsadmd */
static int daemon_mode = FALSE;
/* set if event_handler triggered */
int event_driven = FALSE;
/* output directed to syslog during daemon mode if set */
static int logflag = FALSE;
/* build links in /dev. -x to turn off */
static int build_dev = TRUE;
/* build nodes in /devices. -y to turn off */
static int build_devices = TRUE;
/* -z to turn off */
static int flush_path_to_inst_enable = TRUE;
/* variables used for path_to_inst flushing */
static int inst_count = 0;
static mutex_t count_lock;
static cond_t cv;
/* variables for minor_fini thread */
static mutex_t minor_fini_mutex;
static int minor_fini_canceled = TRUE;
static int minor_fini_delayed = FALSE;
static cond_t minor_fini_cv;
static int minor_fini_timeout = MINOR_FINI_TIMEOUT_DEFAULT;
/* single-threads /dev modification */
static sema_t dev_sema;
/* the program we were invoked as; ie argv[0] */
static char *prog;
/* pointers to create/remove link lists */
static create_list_t *create_head = NULL;
static remove_list_t *remove_head = NULL;
/* supports the class -c option */
static char **classes = NULL;
static int num_classes = 0;
/* used with verbose option -v or -V */
static int num_verbose = 0;
static char **verbose = NULL;
static struct mperm *minor_perms = NULL;
static driver_alias_t *driver_aliases = NULL;
/* set if -r alternate root given */
static char *root_dir = "";
/* /devices or <rootdir>/devices */
static char *devices_dir = DEVICES;
/* /dev or <rootdir>/dev */
static char *dev_dir = DEV;
/* /etc/dev or <rootdir>/etc/dev */
static char *etc_dev_dir = ETCDEV;
/*
* writable root (for lock files and doors during install).
* This is also root dir for /dev attr dir during install.
*/
static char *attr_root = NULL;
/* /etc/path_to_inst unless -p used */
static char *inst_file = INSTANCE_FILE;
/* /usr/lib/devfsadm/linkmods unless -l used */
static char *module_dirs = MODULE_DIRS;
/* default uid/gid used if /etc/minor_perm entry not found */
static uid_t root_uid;
static gid_t sys_gid;
/* /etc/devlink.tab unless devlinks -t used */
static char *devlinktab_file = NULL;
/* File and data structure to reserve enumerate IDs */
static char *enumerate_file = ENUMERATE_RESERVED;
static enumerate_file_t *enumerate_reserved = NULL;
/* set if /dev link is new. speeds up rm_stale_links */
static int linknew = TRUE;
/* variables for devlink.tab compat processing */
static devlinktab_list_t *devlinktab_list = NULL;
static unsigned int devlinktab_line = 0;
/* cache head for devfsadm_enumerate*() functions */
static numeral_set_t *head_numeral_set = NULL;
/* list list of devfsadm modules */
static module_t *module_head = NULL;
/* name_to_major list used in utility function */
static n2m_t *n2m_list = NULL;
/* cache of some links used for performance */
static linkhead_t *headlinkhead = NULL;
/* locking variables to prevent multiples writes to /dev */
static int hold_dev_lock = FALSE;
static int hold_daemon_lock = FALSE;
static int dev_lock_fd;
static int daemon_lock_fd;
static char dev_lockfile[PATH_MAX + 1];
static char daemon_lockfile[PATH_MAX + 1];
/* last devinfo node/minor processed. used for performance */
static di_node_t lnode;
static di_minor_t lminor;
static char lphy_path[PATH_MAX + 1] = {""};
/* Globals used by the link database */
static di_devlink_handle_t devlink_cache;
static int update_database = FALSE;
/* Globals used to set logindev perms */
static struct login_dev *login_dev_cache = NULL;
static int login_dev_enable = FALSE;
/* Global to use devinfo snapshot cache */
static int use_snapshot_cache = FALSE;
/* Global for no-further-processing hash */
static item_t **nfp_hash;
static mutex_t nfp_mutex = DEFAULTMUTEX;
/*
* Directories not removed even when empty. They are packaged, or may
* be referred to from a non-global zone. The dirs must be listed in
* canonical form i.e. without leading "/dev/"
*/
static char *sticky_dirs[] =
{"dsk", "rdsk", "term", "lofi", "rlofi", NULL};
/* Devname globals */
static int lookup_door_fd = -1;
static char *lookup_door_path;
static void load_dev_acl(void);
static void update_drvconf(major_t, int);
static void check_reconfig_state(void);
static int s_stat(const char *, struct stat *);
static int is_blank(char *);
/* sysevent queue related globals */
static mutex_t syseventq_mutex = DEFAULTMUTEX;
static syseventq_t *syseventq_front;
static syseventq_t *syseventq_back;
static void process_syseventq();
static di_node_t devi_root_node = DI_NODE_NIL;
int
main(int argc, char *argv[])
{
struct passwd *pw;
struct group *gp;
pid_t pid;
(void) setlocale(LC_ALL, "");
(void) textdomain(TEXT_DOMAIN);
if ((prog = strrchr(argv[0], '/')) == NULL) {
prog = argv[0];
} else {
prog++;
}
if (getuid() != 0) {
err_print(MUST_BE_ROOT);
devfsadm_exit(1);
/*NOTREACHED*/
}
if (getzoneid() != GLOBAL_ZONEID) {
err_print(MUST_BE_GLOBAL_ZONE);
devfsadm_exit(1);
}
/*
* Close all files except stdin/stdout/stderr
*/
closefrom(3);
if ((pw = getpwnam(DEFAULT_DEV_USER)) != NULL) {
root_uid = pw->pw_uid;
} else {
err_print(CANT_FIND_USER, DEFAULT_DEV_USER);
root_uid = (uid_t)0; /* assume 0 is root */
}
/* the default group is sys */
if ((gp = getgrnam(DEFAULT_DEV_GROUP)) != NULL) {
sys_gid = gp->gr_gid;
} else {
err_print(CANT_FIND_GROUP, DEFAULT_DEV_GROUP);
sys_gid = (gid_t)3; /* assume 3 is sys */
}
(void) umask(0);
system_labeled = is_system_labeled();
if (system_labeled == FALSE) {
/*
* is_system_labeled() will return false in case we are
* starting before the first reboot after Trusted Extensions
* is enabled. Check the setting in /etc/system to see if
* TX is enabled (even if not yet booted).
*/
if (defopen("/etc/system") == 0) {
if (defread("set sys_labeling=1") != NULL)
system_labeled = TRUE;
/* close defaults file */
(void) defopen(NULL);
}
}
/*
* Check if device allocation is enabled.
*/
devalloc_is_on = (da_is_on() == 1) ? 1 : 0;
#ifdef DEBUG
if (system_labeled == FALSE) {
struct stat tx_stat;
/* test hook: see also mkdevalloc.c and allocate.c */
system_labeled = is_system_labeled_debug(&tx_stat);
}
#endif
parse_args(argc, argv);
(void) sema_init(&dev_sema, 1, USYNC_THREAD, NULL);
/* Initialize device allocation list */
devlist.audio = devlist.cd = devlist.floppy = devlist.tape =
devlist.rmdisk = NULL;
if (daemon_mode == TRUE) {
/*
* Build /dev and /devices before daemonizing if
* reconfig booting and daemon invoked with alternate
* root. This is to support install.
*/
if (getenv(RECONFIG_BOOT) != NULL && root_dir[0] != '\0') {
vprint(INFO_MID, CONFIGURING);
load_dev_acl();
update_drvconf((major_t)-1, 0);
process_devinfo_tree();
(void) modctl(MODSETMINIROOT);
}
/*
* fork before detaching from tty in order to print error
* message if unable to acquire file lock. locks not preserved
* across forks. Even under debug we want to fork so that
* when executed at boot we don't hang.
*/
if (fork() != 0) {
devfsadm_exit(0);
/*NOTREACHED*/
}
/* set directory to / so it coredumps there */
if (chdir("/") == -1) {
err_print(CHROOT_FAILED, strerror(errno));
}
/* only one daemon can run at a time */
if ((pid = enter_daemon_lock()) == getpid()) {
detachfromtty();
(void) cond_init(&cv, USYNC_THREAD, 0);
(void) mutex_init(&count_lock, USYNC_THREAD, 0);
if (thr_create(NULL, 0,
(void *(*)(void *))instance_flush_thread,
NULL, THR_DETACHED, NULL) != 0) {
err_print(CANT_CREATE_THREAD, "daemon",
strerror(errno));
devfsadm_exit(1);
/*NOTREACHED*/
}
/* start the minor_fini_thread */
(void) mutex_init(&minor_fini_mutex, USYNC_THREAD, 0);
(void) cond_init(&minor_fini_cv, USYNC_THREAD, 0);
if (thr_create(NULL, 0, minor_fini_thread,
NULL, THR_DETACHED, NULL)) {
err_print(CANT_CREATE_THREAD, "minor_fini",
strerror(errno));
devfsadm_exit(1);
/*NOTREACHED*/
}
/*
* logindevperms need only be set
* in daemon mode and when root dir is "/".
*/
if (root_dir[0] == '\0')
login_dev_enable = TRUE;
daemon_update();
devfsadm_exit(0);
/*NOTREACHED*/
} else {
err_print(DAEMON_RUNNING, pid);
devfsadm_exit(1);
/*NOTREACHED*/
}
} else {
/* not a daemon, so just build /dev and /devices */
/*
* If turning off device allocation, load the
* minor_perm file because process_devinfo_tree() will
* need this in order to reset the permissions of the
* device files.
*/
if (devalloc_flag == DA_OFF) {
read_minor_perm_file();
}
process_devinfo_tree();
if (devalloc_flag != 0)
/* Enable/disable device allocation */
_reset_devalloc(devalloc_flag);
}
return (0);
}
static void
update_drvconf(major_t major, int flags)
{
if (modctl(MODLOADDRVCONF, major, flags) != 0)
err_print(gettext("update_drvconf failed for major %d\n"),
major);
}
static void
load_dev_acl()
{
if (load_devpolicy() != 0)
err_print(gettext("device policy load failed\n"));
load_minor_perm_file();
}
/*
* As devfsadm is run early in boot to provide the kernel with
* minor_perm info, we might as well check for reconfig at the
* same time to avoid running devfsadm twice. This gets invoked
* earlier than the env variable RECONFIG_BOOT is set up.
*/
static void
check_reconfig_state()
{
struct stat sb;
if (s_stat("/reconfigure", &sb) == 0) {
(void) modctl(MODDEVNAME, MODDEVNAME_RECONFIG, 0);
}
}
static void
modctl_sysavail()
{
/*
* Inform /dev that system is available, that
* implicit reconfig can now be performed.
*/
(void) modctl(MODDEVNAME, MODDEVNAME_SYSAVAIL, 0);
}
static void
set_lock_root(void)
{
struct stat sb;
char *lock_root;
size_t len;
lock_root = attr_root ? attr_root : root_dir;
len = strlen(lock_root) + strlen(ETCDEV) + 1;
etc_dev_dir = s_malloc(len);
(void) snprintf(etc_dev_dir, len, "%s%s", lock_root, ETCDEV);
if (s_stat(etc_dev_dir, &sb) != 0) {
s_mkdirp(etc_dev_dir, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
} else if (!S_ISDIR(sb.st_mode)) {
err_print(NOT_DIR, etc_dev_dir);
devfsadm_exit(1);
/*NOTREACHED*/
}
}
/*
* Parse arguments for all 6 programs handled from devfsadm.
*/
static void
parse_args(int argc, char *argv[])
{
char opt;
char get_linkcompat_opts = FALSE;
char *compat_class;
int num_aliases = 0;
int len;
int retval;
int config = TRUE;
int bind = FALSE;
int force_flag = FALSE;
struct aliases *ap = NULL;
struct aliases *a_head = NULL;
struct aliases *a_tail = NULL;
struct modconfig mc;
(void) bzero(&mc, sizeof (mc));
if (strcmp(prog, DISKS) == 0) {
compat_class = "disk";
get_linkcompat_opts = TRUE;
} else if (strcmp(prog, TAPES) == 0) {
compat_class = "tape";
get_linkcompat_opts = TRUE;
} else if (strcmp(prog, PORTS) == 0) {
compat_class = "port";
get_linkcompat_opts = TRUE;
} else if (strcmp(prog, AUDLINKS) == 0) {
compat_class = "audio";
get_linkcompat_opts = TRUE;
} else if (strcmp(prog, DEVLINKS) == 0) {
devlinktab_file = DEVLINKTAB_FILE;
build_devices = FALSE;
load_attach_drv = FALSE;
while ((opt = getopt(argc, argv, "dnr:st:vV:")) != EOF) {
switch (opt) {
case 'd':
file_mods = FALSE;
flush_path_to_inst_enable = FALSE;
devlinks_debug = TRUE;
break;
case 'n':
/* prevent driver loading and deferred attach */
load_attach_drv = FALSE;
break;
case 'r':
set_root_devices_dev_dir(optarg);
if (zone_pathcheck(root_dir) !=
DEVFSADM_SUCCESS)
devfsadm_exit(1);
/*NOTREACHED*/
break;
case 's':
/*
* suppress. don't create/remove links/nodes
* useful with -v or -V
*/
file_mods = FALSE;
flush_path_to_inst_enable = FALSE;
break;
case 't':
/* supply a non-default table file */
devlinktab_file = optarg;
break;
case 'v':
/* documented verbose flag */
add_verbose_id(VERBOSE_MID);
break;
case 'V':
/* undocumented for extra verbose levels */
add_verbose_id(optarg);
break;
default:
usage();
break;
}
}
if (optind < argc) {
usage();
}
} else if (strcmp(prog, DRVCONFIG) == 0) {
int update_only = 0;
build_dev = FALSE;
while ((opt =
getopt(argc, argv, "a:bc:dfi:m:np:R:r:suvV:x")) != EOF) {
switch (opt) {
case 'a':
ap = calloc(sizeof (struct aliases), 1);
ap->a_name = dequote(optarg);
len = strlen(ap->a_name) + 1;
if (len > MAXMODCONFNAME) {
err_print(ALIAS_TOO_LONG,
MAXMODCONFNAME, ap->a_name);
devfsadm_exit(1);
/*NOTREACHED*/
}
ap->a_len = len;
if (a_tail == NULL) {
a_head = ap;
} else {
a_tail->a_next = ap;
}
a_tail = ap;
num_aliases++;
bind = TRUE;
break;
case 'b':
bind = TRUE;
break;
case 'c':
(void) strcpy(mc.drvclass, optarg);
break;
case 'd':
/*
* need to keep for compatibility, but
* do nothing.
*/
break;
case 'f':
force_flag = TRUE;
break;
case 'i':
single_drv = TRUE;
(void) strcpy(mc.drvname, optarg);
driver = s_strdup(optarg);
break;
case 'm':
mc.major = atoi(optarg);
break;
case 'n':
/* prevent driver loading and deferred attach */
load_attach_drv = FALSE;
break;
case 'p':
/* specify alternate path_to_inst file */
inst_file = s_strdup(optarg);
break;
case 'R':
/*
* Private flag for suninstall to populate
* device information on the installed root.
*/
root_dir = s_strdup(optarg);
if (zone_pathcheck(root_dir) !=
DEVFSADM_SUCCESS)
devfsadm_exit(devfsadm_copy());
/*NOTREACHED*/
break;
case 'r':
devices_dir = s_strdup(optarg);
if (zone_pathcheck(devices_dir) !=
DEVFSADM_SUCCESS)
devfsadm_exit(1);
/*NOTREACHED*/
break;
case 's':
/*
* suppress. don't create nodes
* useful with -v or -V
*/
file_mods = FALSE;
flush_path_to_inst_enable = FALSE;
break;
case 'u':
/*
* Invoked via update_drv(8) to update
* the kernel's driver/alias binding
* when removing one or more aliases.
*/
config = FALSE;
break;
case 'v':
/* documented verbose flag */
add_verbose_id(VERBOSE_MID);
break;
case 'V':
/* undocumented for extra verbose levels */
add_verbose_id(optarg);
break;
case 'x':
update_only = 1;
break;
default:
usage();
}
}
if (optind < argc) {
usage();
}
if (bind == TRUE) {
if ((mc.major == -1) || (mc.drvname[0] == '\0')) {
err_print(MAJOR_AND_B_FLAG);
devfsadm_exit(1);
/*NOTREACHED*/
}
mc.flags = 0;
if (force_flag)
mc.flags |= MOD_UNBIND_OVERRIDE;
if (update_only)
mc.flags |= MOD_ADDMAJBIND_UPDATE;
mc.num_aliases = num_aliases;
mc.ap = a_head;
retval = modctl((config == TRUE) ? MODADDMAJBIND :
MODREMDRVALIAS, NULL, (caddr_t)&mc);
if (retval < 0) {
err_print((config == TRUE) ? MODCTL_ADDMAJBIND :
MODCTL_REMMAJBIND);
}
devfsadm_exit(retval);
/*NOTREACHED*/
}
} else if ((strcmp(prog, DEVFSADM) == 0) ||
(strcmp(prog, DEVFSADMD) == 0)) {
char *zonename = NULL;
int init_drvconf = 0;
int init_perm = 0;
int public_mode = 0;
int init_sysavail = 0;
if (strcmp(prog, DEVFSADMD) == 0) {
daemon_mode = TRUE;
}
devlinktab_file = DEVLINKTAB_FILE;
while ((opt = getopt(argc, argv,
"a:Cc:deIi:l:np:PR:r:sSt:uvV:x:")) != EOF) {
if (opt == 'I' || opt == 'P' || opt == 'S') {
if (public_mode)
usage();
} else {
if (init_perm || init_drvconf || init_sysavail)
usage();
public_mode = 1;
}
switch (opt) {
case 'a':
attr_root = s_strdup(optarg);
break;
case 'C':
cleanup = TRUE;
break;
case 'c':
num_classes++;
classes = s_realloc(classes,
num_classes * sizeof (char *));
classes[num_classes - 1] = optarg;
break;
case 'd':
if (daemon_mode == FALSE) {
/*
* Device allocation to be disabled.
*/
devalloc_flag = DA_OFF;
build_dev = FALSE;
}
break;
case 'e':
if (daemon_mode == FALSE) {
/*
* Device allocation to be enabled.
*/
devalloc_flag = DA_ON;
build_dev = FALSE;
}
break;
case 'I': /* update kernel driver.conf cache */
if (daemon_mode == TRUE)
usage();
init_drvconf = 1;
break;
case 'i':
single_drv = TRUE;
driver = s_strdup(optarg);
break;
case 'l':
/* specify an alternate module load path */
module_dirs = s_strdup(optarg);
break;
case 'n':
/* prevent driver loading and deferred attach */
load_attach_drv = FALSE;
break;
case 'p':
/* specify alternate path_to_inst file */
inst_file = s_strdup(optarg);
break;
case 'P':
if (daemon_mode == TRUE)
usage();
/* load minor_perm and device_policy */
init_perm = 1;
break;
case 'R':
/*
* Private flag for suninstall to populate
* device information on the installed root.
*/
root_dir = s_strdup(optarg);
devfsadm_exit(devfsadm_copy());
/*NOTREACHED*/
break;
case 'r':
set_root_devices_dev_dir(optarg);
break;
case 's':
/*
* suppress. don't create/remove links/nodes
* useful with -v or -V
*/
file_mods = FALSE;
flush_path_to_inst_enable = FALSE;
break;
case 'S':
if (daemon_mode == TRUE)
usage();
init_sysavail = 1;
break;
case 't':
devlinktab_file = optarg;
break;
case 'u': /* complete configuration after */
/* adding a driver update-only */
if (daemon_mode == TRUE)
usage();
update_all_drivers = TRUE;
break;
case 'v':
/* documented verbose flag */
add_verbose_id(VERBOSE_MID);
break;
case 'V':
/* undocumented: specify verbose lvl */
add_verbose_id(optarg);
break;
case 'x':
/*
* x is the "private switch" option. The
* goal is to not suck up all the other
* option letters.
*/
if (strcmp(optarg, "update_devlinksdb") == 0) {
update_database = TRUE;
} else if (strcmp(optarg, "no_dev") == 0) {
/* don't build /dev */
build_dev = FALSE;
} else if (strcmp(optarg, "no_devices") == 0) {
/* don't build /devices */
build_devices = FALSE;
} else if (strcmp(optarg, "no_p2i") == 0) {
/* don't flush path_to_inst */
flush_path_to_inst_enable = FALSE;
} else if (strcmp(optarg, "use_dicache") == 0) {
use_snapshot_cache = TRUE;
} else {
usage();
}
break;
default:
usage();
break;
}
}
if (optind < argc) {
usage();
}
/*
* We're not in zone mode; Check to see if the rootpath
* collides with any zonepaths.
*/
if (zonename == NULL) {
if (zone_pathcheck(root_dir) != DEVFSADM_SUCCESS)
devfsadm_exit(1);
/*NOTREACHED*/
}
if (init_drvconf || init_perm || init_sysavail) {
/*
* Load minor perm before force-loading drivers
* so the correct permissions are picked up.
*/
if (init_perm) {
check_reconfig_state();
load_dev_acl();
}
if (init_drvconf)
update_drvconf((major_t)-1, 0);
if (init_sysavail)
modctl_sysavail();
devfsadm_exit(0);
/*NOTREACHED*/
}
}
if (get_linkcompat_opts == TRUE) {
build_devices = FALSE;
load_attach_drv = FALSE;
num_classes++;
classes = s_realloc(classes, num_classes *
sizeof (char *));
classes[num_classes - 1] = compat_class;
while ((opt = getopt(argc, argv, "Cnr:svV:")) != EOF) {
switch (opt) {
case 'C':
cleanup = TRUE;
break;
case 'n':
/* prevent driver loading or deferred attach */
load_attach_drv = FALSE;
break;
case 'r':
set_root_devices_dev_dir(optarg);
if (zone_pathcheck(root_dir) !=
DEVFSADM_SUCCESS)
devfsadm_exit(1);
/*NOTREACHED*/
break;
case 's':
/* suppress. don't create/remove links/nodes */
/* useful with -v or -V */
file_mods = FALSE;
flush_path_to_inst_enable = FALSE;
break;
case 'v':
/* documented verbose flag */
add_verbose_id(VERBOSE_MID);
break;
case 'V':
/* undocumented for extra verbose levels */
add_verbose_id(optarg);
break;
default:
usage();
}
}
if (optind < argc) {
usage();
}
}
set_lock_root();
}
void
usage(void)
{
if (strcmp(prog, DEVLINKS) == 0) {
err_print(DEVLINKS_USAGE);
} else if (strcmp(prog, DRVCONFIG) == 0) {
err_print(DRVCONFIG_USAGE);
} else if ((strcmp(prog, DEVFSADM) == 0) ||
(strcmp(prog, DEVFSADMD) == 0)) {
err_print(DEVFSADM_USAGE);
} else {
err_print(COMPAT_LINK_USAGE);
}
devfsadm_exit(1);
/*NOTREACHED*/
}
static void
devi_tree_walk(struct dca_impl *dcip, int flags, char *ev_subclass)
{
char *msg, *name;
struct mlist mlist = {0};
di_node_t node;
vprint(CHATTY_MID, "devi_tree_walk: root=%s, minor=%s, driver=%s,"
" error=%d, flags=%u\n", dcip->dci_root,
dcip->dci_minor ? dcip->dci_minor : "<NULL>",
dcip->dci_driver ? dcip->dci_driver : "<NULL>", dcip->dci_error,
dcip->dci_flags);
assert(dcip->dci_root);
if (dcip->dci_flags & DCA_LOAD_DRV) {
node = di_init_driver(dcip->dci_driver, flags);
msg = DRIVER_FAILURE;
name = dcip->dci_driver;