devfsadm_impl.h revision 3c4226f98775d47a05fa88f9f72479f1a250eaa5
/*
* 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
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _DEVFSADM_IMPL_H
#define _DEVFSADM_IMPL_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <dlfcn.h>
#include <stdarg.h>
#include <fcntl.h>
#include <locale.h>
#include <libintl.h>
#include <ctype.h>
#include <signal.h>
#include <deflt.h>
#include <ftw.h>
#include <sys/instance.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/int_types.h>
#include <limits.h>
#include <strings.h>
#include <devfsadm.h>
#include <libdevinfo.h>
#include <sys/devinfo_impl.h>
#include <libgen.h>
#include <door.h>
#include <syslog.h>
#include <libsysevent.h>
#include <thread.h>
#include <message.h>
#include <librcm.h>
#include <libzonecfg.h>
#include <device_info.h>
#ifndef DEBUG
#define NDEBUG 1
#else
#endif
#include <assert.h>
#define DEV_LOCK_FILE ".devfsadm_dev.lock"
#define DAEMON_LOCK_FILE ".devfsadm_daemon.lock"
#define DEV "/dev"
#define DEV_LEN 4
#define DEVICES "/devices"
#define DEVICES_LEN 8
#define MODULE_DIRS "/usr/lib/devfsadm/linkmod"
#define ALIASFILE "/etc/driver_aliases"
#define NAME_TO_MAJOR "/etc/name_to_major"
#define RECONFIG_BOOT "_INIT_RECONFIG"
#define PID_STR_LEN 10
#define EXTRA_PRIVS "/etc/security/extra_privs"
#define DEV_POLICY "/etc/security/device_policy"
#define LDEV_FILE "/etc/logindevperm"
#define DEVFSADM_DEFAULT_FILE "/etc/default/devfsadm"
#define MINOR_FINI_TIMEOUT_DEFAULT 2
#define FORCE_CALL_MINOR_FINI 10
#define ZONE_REG_DOOR ".zone_reg_door"
enum zreg_op {
ZONE_REG = 1,
ZONE_UNREG = 2
};
enum zreg_err {
ZONE_SUCCESS = 0,
ZONE_ERR_NOZONE = 1,
ZONE_ERR_DOOR = 2,
ZONE_ERR_REPOSITORY = 3,
ZONE_ERR_NOLIB = 4
};
struct zreg {
char zreg_zonename[ZONENAME_MAX];
enum zreg_err zreg_error;
int zreg_errno;
};
#define DRVCONFIG "drvconfig"
#define DEVFSADM "devfsadm"
#define DEVFSADMD "devfsadmd"
#define DEVLINKS "devlinks"
#define TAPES "tapes"
#define AUDLINKS "audlinks"
#define PORTS "ports"
#define DISKS "disks"
#define MAX_IDLE_DELAY 5
#define MAX_DELAY 30
#define NAME 0x01
#define ADDR 0x03
#define MINOR 0x04
#define COUNTER 0x05
#define CONSTANT 0x06
#define TYPE 0x07
#define TYPE_S "type"
#define ADDR_S "addr"
#define ADDR_S_LEN 4
#define MINOR_S "minor"
#define MINOR_S_LEN 5
#define NAME_S "name"
#define TAB '\t'
#define NEWLINE '\n'
#define MAX_DEVLINK_LINE 4028
#define INTEGER 0
#define LETTER 1
#define MAX_PERM_LINE 256
#define MAX_LDEV_LINE 256
#define LDEV_DELIMS " \t\n"
#define LDEV_DRVLIST_DELIMS "="
#define LDEV_DRV_DELIMS ", \t\n"
#define LDEV_DEV_DELIM ":"
#define LDEV_DRVLIST_NAME "driver"
#define TYPE_LINK 0x00
#define TYPE_DEVICES 0x01
#define CREATE_LINK 0x01
#define READ_LINK 0x02
#define CREATE_NODE 0x01
#define READ_NODE 0x02
#define DCA_CREATE_LINK 0x01
#define DCA_FREE_LIST 0x02
#define DCA_LOAD_DRV 0x04
#define DCA_CHECK_TYPE 0x10
#define DCA_NOTIFY_RCM 0x20
#define DCA_FLUSH_PATHINST 0x40
#define DCA_HOT_PLUG 0x80
#define CACHE_STATE 0x0
#define SYNC_STATE 0x1
#define MODULE_ACTIVE 0x01
#define MAX_SLEEP 120
#define DEVLINKTAB_FILE "/etc/devlink.tab"
#define MODULE_SUFFIX ".so"
#define MINOR_INIT "minor_init"
#define MINOR_FINI "minor_fini"
#define _DEVFSADM_CREATE_REG "_devfsadm_create_reg"
#define _DEVFSADM_REMOVE_REG "_devfsadm_remove_reg"
#define NUM_EV_STR 4
#define EV_TYPE 0
#define EV_CLASS 1
#define EV_PATH_NAME 2
#define EV_MINOR_NAME 3
/* add new debug level and meanings here */
#define DEVLINK_MID "devfsadm:devlink"
#define MODLOAD_MID "devfsadm:modload"
#define INITFINI_MID "devfsadm:initfini"
#define EVENT_MID "devfsadm:event"
#define REMOVE_MID "devfsadm:remove"
#define LOCK_MID "devfsadm:lock"
#define PATH2INST_MID "devfsadm:path2inst"
#define CACHE_MID "devfsadm:cache"
#define BUILDCACHE_MID "devfsadm:buildcache"
#define RECURSEDEV_MID "devfsadm:recursedev"
#define INSTSYNC_MID "devfsadm:instsync"
#define FILES_MID "devfsadm:files"
#define ENUM_MID "devfsadm:enum"
#define LINKCACHE_MID "devfsadm:linkcache"
#define ADDREMCACHE_MID "devfsadm:addremcache"
#define MALLOC_MID "devfsadm:malloc"
#define ZONE_MID "devfsadm:zone"
#define ALL_MID "all"
typedef struct recurse_dev {
void (*fcn)(char *, void *);
void *data;
typedef struct link {
char *devlink; /* without ".../dev/" prefix */
char *contents; /* without "../devices" prefix */
} link_t;
typedef struct linkhead {
char *dir_re;
} linkhead_t;
typedef struct link_list {
int type;
char *constant;
int arg;
} link_list_t;
typedef struct selector_list {
int key;
char *val;
int arg;
struct selector_list *next;
typedef struct devlinktab_list {
int line_number;
char *selector_pattern;
char *p_link_pattern;
char *s_link_pattern;
struct devlinktab_list *next;
typedef struct module {
char *name;
void *dlhandle;
int (*minor_init)();
int (*minor_fini)();
int flags;
} module_t;
typedef struct create_list {
struct create_list *next;
struct minor {
};
struct mlist {
};
typedef struct remove_list {
struct remove_list *next;
typedef struct cleanup_data {
int flags;
char *phypath;
typedef struct n2m {
char *driver;
} n2m_t;
/* structures for devfsadm_enumerate() */
typedef struct numeral {
char *id;
char *full_path;
int rule_index;
char *cmp_str;
} numeral_t;
typedef struct numeral_set {
int re_count;
char **re;
struct numeral_set *next;
typedef struct temp {
int integer;
} temp_t;
typedef struct driver_alias {
char *driver_name;
char *alias_name;
struct driver_alias *next;
struct driver_list {
char driver_name[MAXNAMELEN];
struct driver_list *next;
};
struct login_dev {
char *ldev_console;
int ldev_perms;
char *ldev_device;
struct driver_list *ldev_driver_list;
};
#define MAX_DEV_NAME_COUNT 100
struct devlink_cb_arg {
char *dev_names[MAX_DEV_NAME_COUNT];
char *link_contents[MAX_DEV_NAME_COUNT];
int count;
int rv;
};
struct dca_impl {
char *dci_root;
char *dci_minor;
char *dci_driver;
void *dci_arg;
int dci_error;
int dci_flags;
};
struct zone_devinfo {
struct zone_devinfo *zone_next;
char *zone_path;
char *zone_name;
};
/* RCM related */
struct rcm_eventq {
struct rcm_eventq *next;
};
static int devfsadm_enumerate_int_start(char *devfs_path,
static void startup_cache_sync_thread(void);
static void pre_and_post_cleanup(int flags);
static void hot_cleanup(char *, char *, char *, char *, int);
static void devfsadm_exit(int status);
static void rm_link_from_cache(char *devlink);
static void rm_all_links_from_cache();
static void instance_flush_thread(void);
static void rm_parent_dir_if_empty(char *path);
void devfsadm_err_print(char *message, ...);
static void invalidate_enumerate_cache(void);
static pid_t enter_dev_lock(void);
static void exit_dev_lock(void);
static pid_t enter_daemon_lock(void);
static void exit_daemon_lock(void);
static int alias(char *, char *);
static int devfsadm_copy(void);
static void flush_path_to_inst(void);
static void detachfromtty(void);
static void read_minor_perm_file(void);
static void read_driver_aliases_file(void);
static void load_modules(void);
static void unload_modules(void);
static void devfs_instance_mod(void);
static void add_minor_pathname(char *, char *, char *);
char **devfs_path, int dangle);
static int load_n2m_table(char *filename);
static int get_stat_info(char *, struct stat *);
static void daemon_update(void);
static void usage(void);
static void process_devinfo_tree(void);
static void call_minor_fini_thread(void *arg);
static void read_devlinktab_file(void);
int devfsadm_noupdate(void);
const char *devfsadm_root_path(void);
char **s_link);
int nrules);
int subexp);
static void add_verbose_id(char *mid);
static void delete_zone(struct zone_devinfo *z);
static void zlist_deleteall_unlocked(void);
static int register_all_zones(void);
static int zone_pathcheck(char *checkpath);
static int rcm_init(void);
static void lock_dev(void);
static void unlock_dev(int flag);
static void free_dev_names(struct devlink_cb_arg *x);
int load_devpolicy(void);
static void load_dev_acl(void);
static void load_minor_perm_file(void);
static void (*librcm_free_handle)(rcm_handle_t *);
rcm_info_t *);
static nvlist_t *build_event_attributes(char *, char *, char *,
di_node_t, char *, int);
static void build_and_log_event(char *, char *, char *, di_node_t);
static void read_logindevperm_file(void);
static void set_logindev_perms(char *devlink);
/* convenient short hands */
#define vprint devfsadm_print
#define err_print devfsadm_errprint
#define TRUE 1
#define FALSE 0
#ifdef __cplusplus
}
#endif
#endif /* _DEVFSADM_IMPL_H */