xref: /illumos-gate/usr/src/cmd/modload/addrem.h (revision b2d74f53)
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 (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
24  */
25 
26 #ifndef _CMD_MODLOAD_ADDREM_H
27 #define	_CMD_MODLOAD_ADDREM_H
28 
29 #include <sys/modctl.h>
30 #include <device_info.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /* defines for add_drv.c, update_drv.c, and rem_drv.c */
37 
38 #define	SUCCESS	0
39 #define	FAILURE -1
40 #define	NOERR	0
41 #define	ERROR	-1
42 #define	UNIQUE	-2
43 #define	NOT_UNIQUE -3
44 #define	NONE_FOUND -4
45 
46 #define	MAX_CMD_LINE	256
47 #define	MAX_N2M_ALIAS_LINE	FILENAME_MAX + FILENAME_MAX + 1
48 #define	MAXLEN_NAM_TO_MAJ_ENT	FILENAME_MAX + MAX_STR_MAJOR + 1
49 #define	OPT_LEN		128
50 #define	CADDR_HEX_STR	16
51 #define	UINT_STR	10
52 #define	MODLINE_ENT_MAX	(4 * UINT_STR) + CADDR_HEX_STR + MODMAXNAMELEN
53 #define	MAX_STR_MAJOR	UINT_STR
54 #define	STR_LONG	10
55 #define	PERM_STR	4
56 #define	MAX_PERM_ENTRY	(2 * STR_LONG) + PERM_STR + (2 * FILENAME_MAX) + 1
57 #define	MAX_DBFILE_ENTRY	MAX_PERM_ENTRY
58 
59 #define	CLEAN_MINOR_PERM	0x00000001
60 #define	CLEAN_DRV_ALIAS		0x00000002
61 #define	CLEAN_NAM_MAJ		0x00000004
62 #define	CLEAN_DRV_CLASSES	0x00000010
63 #define	CLEAN_DEV_POLICY	0x00000020
64 #define	CLEAN_DRV_PRIV		0x00000040
65 #define	CLEAN_ALL		(CLEAN_MINOR_PERM | CLEAN_DRV_ALIAS | \
66 				CLEAN_NAM_MAJ | CLEAN_DRV_CLASSES | \
67 				CLEAN_DEV_POLICY | CLEAN_DRV_PRIV)
68 
69 /* add_drv/rem_drv database files */
70 #define	DRIVER_ALIAS	"/etc/driver_aliases"
71 #define	DRIVER_CLASSES	"/etc/driver_classes"
72 #define	MINOR_PERM	"/etc/minor_perm"
73 #define	NAM_TO_MAJ	"/etc/name_to_major"
74 #define	REM_NAM_TO_MAJ	"/etc/rem_name_to_major"
75 
76 #define	ADD_REM_LOCK	"/var/run/AdDrEm.lck"
77 
78 #if defined(__x86)
79 #define	DRVDIR64	"amd64"
80 #elif defined(__sparc)
81 #define	DRVDIR64	"sparcv9"
82 #endif
83 
84 /* pointers to add_drv/rem_drv database files */
85 extern char *driver_aliases;
86 extern char *driver_classes;
87 extern char *minor_perm;
88 extern char *name_to_major;
89 extern char *rem_name_to_major;
90 extern char *device_policy;
91 extern char *extra_privs;
92 
93 /* devfs root string */
94 extern char *devfs_root;
95 
96 /* module path searching structure */
97 struct drvmod_dir {
98 	char direc[FILENAME_MAX + 1];
99 	struct drvmod_dir *next;
100 };
101 
102 extern struct drvmod_dir *moddir;
103 
104 /* names of things: directories, commands, files */
105 #define	KERNEL_DRV	"/kernel/drv"
106 #define	USR_KERNEL_DRV	"/usr/kernel/drv"
107 #define	DRVCONFIG_PATH	"/usr/sbin/drvconfig"
108 #define	DRVCONFIG	"drvconfig"
109 #define	DEVFSADM_PATH	"/usr/sbin/devfsadm"
110 #define	DEVFSADM	"devfsadm"
111 #define	DEVFS_ROOT	"/devices"
112 #define	RECONFIGURE	"/reconfigure"
113 #define	MODUNLOAD_PATH	"/usr/sbin/modunload"
114 
115 extern void log_minorperm_error(minorperm_err_t, int);
116 extern void remove_entry(int, char *);
117 extern char *get_next_entry(char *, char *);
118 extern char *get_perm_entry(char *, char *);
119 extern int check_perms_aliases(int, int);
120 extern int check_name_to_major(int);
121 extern void enter_lock(void);
122 extern void err_exit(void) __NORETURN;
123 extern void exit_unlock(void);
124 extern char *get_entry(char *, char *, char, int);
125 extern int build_filenames(char *);
126 extern int append_to_file(char *, char *, char *, char, char *, int);
127 extern int append_to_minor_perm(char *, char *, char *);
128 extern int get_major_no(char *, char *);
129 extern int get_driver_name(int, char *, char *);
130 extern int delete_entry(char *, char *, char *, char *);
131 extern int check_space_within_quote(char *);
132 extern void list_entry(char *, char *, char *);
133 extern int update_minor_entry(char *, char *);
134 extern int check_perm_opts(char *);
135 extern int update_name_to_major(char *, major_t *, int);
136 extern int do_the_update(char *, char *);
137 extern int fill_n2m_array(char *, char **, int *);
138 extern int aliases_unique(char *);
139 extern int aliases_exist(char *);
140 extern int aliases_paths_exist(char *);
141 extern int update_driver_aliases(char *, char *);
142 extern int unique_driver_name(char *, char *, int *);
143 extern int unique_drv_alias(char *);
144 extern int check_duplicate_driver_alias(char *, char *);
145 extern int trim_duplicate_aliases(char *, char *, char **);
146 extern int get_max_major(char *);
147 extern void get_modid(char *, int *);
148 extern int config_driver(char *, major_t, char *, char *, int, int);
149 extern int unconfig_driver(char *, major_t, char *, int);
150 extern void load_driver(char *, int);
151 extern int create_reconfig(char *);
152 extern void cleanup_moddir(void);
153 
154 /* drvsubr.c */
155 #define	XEND	".XXXXXX"
156 #define	MAXMODPATHS	1024
157 
158 /* module path list separators */
159 #define	MOD_SEP	" :"
160 #define	DIR_SEP "/"
161 
162 /* [un]config_driver flags */
163 #define	CONFIG_DRV_VERBOSE	0x01		/* verbose */
164 #define	CONFIG_DRV_FORCE	0x02		/* unconfig even if in use */
165 #define	CONFIG_DRV_UPDATE_ONLY	0x04		/* -u update only */
166 
167 #ifdef	__cplusplus
168 }
169 #endif
170 
171 #endif /* _CMD_MODLOAD_ADDREM_H */
172