xref: /titanic_44/usr/src/cmd/modload/addrem.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _CMD_MODLOAD_ADDREM_H
28 #define	_CMD_MODLOAD_ADDREM_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/modctl.h>
33 #include <device_info.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /* defines for add_drv.c, update_drv.c, and rem_drv.c */
40 
41 #define	SUCCESS	0
42 #define	FAILURE -1
43 #define	NOERR	0
44 #define	ERROR	-1
45 #define	UNIQUE	-2
46 #define	NOT_UNIQUE -3
47 #define	NONE_FOUND -4
48 
49 #define	MAX_CMD_LINE	256
50 #define	MAX_N2M_ALIAS_LINE	FILENAME_MAX + FILENAME_MAX + 1
51 #define	MAXLEN_NAM_TO_MAJ_ENT 	FILENAME_MAX + MAX_STR_MAJOR + 1
52 #define	OPT_LEN		128
53 #define	CADDR_HEX_STR	16
54 #define	UINT_STR	10
55 #define	MODLINE_ENT_MAX	(4 * UINT_STR) + CADDR_HEX_STR + MODMAXNAMELEN
56 #define	MAX_STR_MAJOR	UINT_STR
57 #define	STR_LONG	10
58 #define	PERM_STR	4
59 #define	MAX_PERM_ENTRY	(2 * STR_LONG) + PERM_STR + (2 * FILENAME_MAX) + 1
60 #define	MAX_DBFILE_ENTRY	MAX_PERM_ENTRY
61 
62 #define	CLEAN_MINOR_PERM	0x00000001
63 #define	CLEAN_DRV_ALIAS		0x00000002
64 #define	CLEAN_NAM_MAJ		0x00000004
65 #define	CLEAN_DRV_CLASSES	0x00000010
66 #define	CLEAN_DEV_POLICY	0x00000020
67 #define	CLEAN_DRV_PRIV		0x00000040
68 #define	CLEAN_ALL		(CLEAN_MINOR_PERM | CLEAN_DRV_ALIAS | \
69 				CLEAN_NAM_MAJ | CLEAN_DRV_CLASSES | \
70 				CLEAN_DEV_POLICY | CLEAN_DRV_PRIV)
71 
72 /* add_drv/rem_drv database files */
73 #define	DRIVER_ALIAS	"/etc/driver_aliases"
74 #define	DRIVER_CLASSES	"/etc/driver_classes"
75 #define	MINOR_PERM	"/etc/minor_perm"
76 #define	NAM_TO_MAJ	"/etc/name_to_major"
77 #define	REM_NAM_TO_MAJ	"/etc/rem_name_to_major"
78 
79 #define	ADD_REM_LOCK	"/tmp/AdDrEm.lck"
80 #define	TMPHOLD		"/etc/TmPhOlD"
81 
82 #if defined(__x86)
83 #define	DRVDIR64	"amd64"
84 #elif defined(__sparc)
85 #define	DRVDIR64	"sparcv9"
86 #endif
87 
88 /* pointers to add_drv/rem_drv database files */
89 char *driver_aliases;
90 char *driver_classes;
91 char *minor_perm;
92 char *name_to_major;
93 char *rem_name_to_major;
94 char *device_policy;
95 char *extra_privs;
96 
97 /* devfs root string */
98 char *devfs_root;
99 
100 /* module path searching structure */
101 struct drvmod_dir {
102 	char direc[FILENAME_MAX + 1];
103 	struct drvmod_dir *next;
104 };
105 
106 struct drvmod_dir *moddir;
107 
108 /* names of things: directories, commands, files */
109 #define	KERNEL_DRV	"/kernel/drv"
110 #define	USR_KERNEL_DRV	"/usr/kernel/drv"
111 #define	DRVCONFIG_PATH	"/usr/sbin/drvconfig"
112 #define	DRVCONFIG	"drvconfig"
113 #define	DEVFSADM_PATH	"/usr/sbin/devfsadm"
114 #define	DEVFSADM	"devfsadm"
115 #define	DEVFS_ROOT	"/devices"
116 #define	RECONFIGURE	"/reconfigure"
117 #define	MODUNLOAD_PATH	"/usr/sbin/modunload"
118 
119 extern void log_minorperm_error(minorperm_err_t, int);
120 extern void remove_entry(int, char *);
121 extern char *get_next_entry(char *, char *);
122 extern char *get_perm_entry(char *, char *);
123 extern int check_perms_aliases(int, int);
124 extern int check_name_to_major(int);
125 extern void enter_lock(void);
126 extern void err_exit(void);
127 extern void exit_unlock(void);
128 extern char *get_entry(char *, char *, char);
129 extern int build_filenames(char *);
130 extern int append_to_file(char *, char *, char *, char, char *);
131 extern int get_major_no(char *, char *);
132 extern int get_driver_name(int, char *, char *);
133 extern int delete_entry(char *, char *, char *, char *);
134 extern int check_space_within_quote(char *);
135 extern void list_entry(char *, char *, char *);
136 extern int update_minor_entry(char *, char *);
137 extern int check_perm_opts(char *);
138 extern int update_name_to_major(char *, major_t *, int);
139 extern int do_the_update(char *, char *);
140 extern int fill_n2m_array(char *, char **, int *);
141 extern int aliases_unique(char *);
142 extern int update_driver_aliases(char *, char *);
143 extern int unique_driver_name(char *, char *, int *);
144 extern int unique_drv_alias(char *);
145 extern int get_max_major(char *);
146 extern void get_modid(char *, int *);
147 extern int config_driver(char *, major_t, char *, char *, int, int);
148 extern void load_driver(char *, int);
149 extern int create_reconfig(char *);
150 extern void cleanup_moddir(void);
151 
152 /* drvsubr.c */
153 #define	XEND	".XXXXXX"
154 #define	MAXMODPATHS	1024
155 
156 /* module path list separators */
157 #define	MOD_SEP	" :"
158 #define	DIR_SEP "/"
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif /* _CMD_MODLOAD_ADDREM_H */
165