xref: /illumos-gate/usr/src/cmd/modload/addrem.h (revision b2d74f53)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5f4da9be0Scth  * Common Development and Distribution License (the "License").
6f4da9be0Scth  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2273cf56abSMita Solanky  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
23e4a991ebSAndy Fiddaman  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _CMD_MODLOAD_ADDREM_H
277c478bd9Sstevel@tonic-gate #define	_CMD_MODLOAD_ADDREM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
307c478bd9Sstevel@tonic-gate #include <device_info.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /* defines for add_drv.c, update_drv.c, and rem_drv.c */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	SUCCESS	0
397c478bd9Sstevel@tonic-gate #define	FAILURE -1
407c478bd9Sstevel@tonic-gate #define	NOERR	0
417c478bd9Sstevel@tonic-gate #define	ERROR	-1
427c478bd9Sstevel@tonic-gate #define	UNIQUE	-2
437c478bd9Sstevel@tonic-gate #define	NOT_UNIQUE -3
447c478bd9Sstevel@tonic-gate #define	NONE_FOUND -4
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #define	MAX_CMD_LINE	256
477c478bd9Sstevel@tonic-gate #define	MAX_N2M_ALIAS_LINE	FILENAME_MAX + FILENAME_MAX + 1
48e4a991ebSAndy Fiddaman #define	MAXLEN_NAM_TO_MAJ_ENT	FILENAME_MAX + MAX_STR_MAJOR + 1
497c478bd9Sstevel@tonic-gate #define	OPT_LEN		128
507c478bd9Sstevel@tonic-gate #define	CADDR_HEX_STR	16
517c478bd9Sstevel@tonic-gate #define	UINT_STR	10
527c478bd9Sstevel@tonic-gate #define	MODLINE_ENT_MAX	(4 * UINT_STR) + CADDR_HEX_STR + MODMAXNAMELEN
537c478bd9Sstevel@tonic-gate #define	MAX_STR_MAJOR	UINT_STR
547c478bd9Sstevel@tonic-gate #define	STR_LONG	10
557c478bd9Sstevel@tonic-gate #define	PERM_STR	4
567c478bd9Sstevel@tonic-gate #define	MAX_PERM_ENTRY	(2 * STR_LONG) + PERM_STR + (2 * FILENAME_MAX) + 1
577c478bd9Sstevel@tonic-gate #define	MAX_DBFILE_ENTRY	MAX_PERM_ENTRY
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #define	CLEAN_MINOR_PERM	0x00000001
607c478bd9Sstevel@tonic-gate #define	CLEAN_DRV_ALIAS		0x00000002
617c478bd9Sstevel@tonic-gate #define	CLEAN_NAM_MAJ		0x00000004
627c478bd9Sstevel@tonic-gate #define	CLEAN_DRV_CLASSES	0x00000010
637c478bd9Sstevel@tonic-gate #define	CLEAN_DEV_POLICY	0x00000020
647c478bd9Sstevel@tonic-gate #define	CLEAN_DRV_PRIV		0x00000040
657c478bd9Sstevel@tonic-gate #define	CLEAN_ALL		(CLEAN_MINOR_PERM | CLEAN_DRV_ALIAS | \
667c478bd9Sstevel@tonic-gate 				CLEAN_NAM_MAJ | CLEAN_DRV_CLASSES | \
677c478bd9Sstevel@tonic-gate 				CLEAN_DEV_POLICY | CLEAN_DRV_PRIV)
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /* add_drv/rem_drv database files */
707c478bd9Sstevel@tonic-gate #define	DRIVER_ALIAS	"/etc/driver_aliases"
717c478bd9Sstevel@tonic-gate #define	DRIVER_CLASSES	"/etc/driver_classes"
727c478bd9Sstevel@tonic-gate #define	MINOR_PERM	"/etc/minor_perm"
737c478bd9Sstevel@tonic-gate #define	NAM_TO_MAJ	"/etc/name_to_major"
747c478bd9Sstevel@tonic-gate #define	REM_NAM_TO_MAJ	"/etc/rem_name_to_major"
757c478bd9Sstevel@tonic-gate 
7673cf56abSMita Solanky #define	ADD_REM_LOCK	"/var/run/AdDrEm.lck"
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #if defined(__x86)
797c478bd9Sstevel@tonic-gate #define	DRVDIR64	"amd64"
807c478bd9Sstevel@tonic-gate #elif defined(__sparc)
817c478bd9Sstevel@tonic-gate #define	DRVDIR64	"sparcv9"
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate /* pointers to add_drv/rem_drv database files */
85*b2d74f53SToomas Soome extern char *driver_aliases;
86*b2d74f53SToomas Soome extern char *driver_classes;
87*b2d74f53SToomas Soome extern char *minor_perm;
88*b2d74f53SToomas Soome extern char *name_to_major;
89*b2d74f53SToomas Soome extern char *rem_name_to_major;
90*b2d74f53SToomas Soome extern char *device_policy;
91*b2d74f53SToomas Soome extern char *extra_privs;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* devfs root string */
94*b2d74f53SToomas Soome extern char *devfs_root;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /* module path searching structure */
977c478bd9Sstevel@tonic-gate struct drvmod_dir {
987c478bd9Sstevel@tonic-gate 	char direc[FILENAME_MAX + 1];
997c478bd9Sstevel@tonic-gate 	struct drvmod_dir *next;
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate 
102*b2d74f53SToomas Soome extern struct drvmod_dir *moddir;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /* names of things: directories, commands, files */
1057c478bd9Sstevel@tonic-gate #define	KERNEL_DRV	"/kernel/drv"
1067c478bd9Sstevel@tonic-gate #define	USR_KERNEL_DRV	"/usr/kernel/drv"
1077c478bd9Sstevel@tonic-gate #define	DRVCONFIG_PATH	"/usr/sbin/drvconfig"
1087c478bd9Sstevel@tonic-gate #define	DRVCONFIG	"drvconfig"
1097c478bd9Sstevel@tonic-gate #define	DEVFSADM_PATH	"/usr/sbin/devfsadm"
1107c478bd9Sstevel@tonic-gate #define	DEVFSADM	"devfsadm"
1117c478bd9Sstevel@tonic-gate #define	DEVFS_ROOT	"/devices"
1127c478bd9Sstevel@tonic-gate #define	RECONFIGURE	"/reconfigure"
1137c478bd9Sstevel@tonic-gate #define	MODUNLOAD_PATH	"/usr/sbin/modunload"
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate extern void log_minorperm_error(minorperm_err_t, int);
1167c478bd9Sstevel@tonic-gate extern void remove_entry(int, char *);
1177c478bd9Sstevel@tonic-gate extern char *get_next_entry(char *, char *);
1187c478bd9Sstevel@tonic-gate extern char *get_perm_entry(char *, char *);
1197c478bd9Sstevel@tonic-gate extern int check_perms_aliases(int, int);
1207c478bd9Sstevel@tonic-gate extern int check_name_to_major(int);
1217c478bd9Sstevel@tonic-gate extern void enter_lock(void);
122e4a991ebSAndy Fiddaman extern void err_exit(void) __NORETURN;
1237c478bd9Sstevel@tonic-gate extern void exit_unlock(void);
124f4da9be0Scth extern char *get_entry(char *, char *, char, int);
1257c478bd9Sstevel@tonic-gate extern int build_filenames(char *);
126f4da9be0Scth extern int append_to_file(char *, char *, char *, char, char *, int);
1273c0ea289SJerry Gilliam extern int append_to_minor_perm(char *, char *, char *);
1287c478bd9Sstevel@tonic-gate extern int get_major_no(char *, char *);
1297c478bd9Sstevel@tonic-gate extern int get_driver_name(int, char *, char *);
1307c478bd9Sstevel@tonic-gate extern int delete_entry(char *, char *, char *, char *);
1317c478bd9Sstevel@tonic-gate extern int check_space_within_quote(char *);
1327c478bd9Sstevel@tonic-gate extern void list_entry(char *, char *, char *);
1337c478bd9Sstevel@tonic-gate extern int update_minor_entry(char *, char *);
1347c478bd9Sstevel@tonic-gate extern int check_perm_opts(char *);
1357c478bd9Sstevel@tonic-gate extern int update_name_to_major(char *, major_t *, int);
1367c478bd9Sstevel@tonic-gate extern int do_the_update(char *, char *);
1377c478bd9Sstevel@tonic-gate extern int fill_n2m_array(char *, char **, int *);
1387c478bd9Sstevel@tonic-gate extern int aliases_unique(char *);
1392e107de7SJerry Gilliam extern int aliases_exist(char *);
140f4da9be0Scth extern int aliases_paths_exist(char *);
1417c478bd9Sstevel@tonic-gate extern int update_driver_aliases(char *, char *);
1427c478bd9Sstevel@tonic-gate extern int unique_driver_name(char *, char *, int *);
1437c478bd9Sstevel@tonic-gate extern int unique_drv_alias(char *);
1440013e2d3SJerry Gilliam extern int check_duplicate_driver_alias(char *, char *);
1450013e2d3SJerry Gilliam extern int trim_duplicate_aliases(char *, char *, char **);
1467c478bd9Sstevel@tonic-gate extern int get_max_major(char *);
1477c478bd9Sstevel@tonic-gate extern void get_modid(char *, int *);
1487c478bd9Sstevel@tonic-gate extern int config_driver(char *, major_t, char *, char *, int, int);
149c9cc1492SJerry Gilliam extern int unconfig_driver(char *, major_t, char *, int);
1507c478bd9Sstevel@tonic-gate extern void load_driver(char *, int);
1517c478bd9Sstevel@tonic-gate extern int create_reconfig(char *);
1527c478bd9Sstevel@tonic-gate extern void cleanup_moddir(void);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /* drvsubr.c */
1557c478bd9Sstevel@tonic-gate #define	XEND	".XXXXXX"
1567c478bd9Sstevel@tonic-gate #define	MAXMODPATHS	1024
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /* module path list separators */
1597c478bd9Sstevel@tonic-gate #define	MOD_SEP	" :"
1607c478bd9Sstevel@tonic-gate #define	DIR_SEP "/"
1617c478bd9Sstevel@tonic-gate 
162c9cc1492SJerry Gilliam /* [un]config_driver flags */
163c9cc1492SJerry Gilliam #define	CONFIG_DRV_VERBOSE	0x01		/* verbose */
164c9cc1492SJerry Gilliam #define	CONFIG_DRV_FORCE	0x02		/* unconfig even if in use */
165c9cc1492SJerry Gilliam #define	CONFIG_DRV_UPDATE_ONLY	0x04		/* -u update only */
166c9cc1492SJerry Gilliam 
1677c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate #endif
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #endif /* _CMD_MODLOAD_ADDREM_H */
172