45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * CDDL HEADER START
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * The contents of this file are subject to the terms of the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Common Development and Distribution License (the "License").
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * You may not use this file except in compliance with the License.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * See the License for the specific language governing permissions
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * and limitations under the License.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * When distributing Covered Code, include this CDDL HEADER in each
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * If applicable, add the following below this CDDL HEADER, with the
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * fields enclosed by brackets "[]" replaced with your own identifying
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * information: Portions Copyright [yyyy] [name of copyright owner]
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * CDDL HEADER END
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Use is subject to license terms.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Device allocation related work.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcelstatic char *_update_dev(deventry_t *, int, const char *, char *, char *);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpkstatic int _make_db();
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * _da_check_for_usb
6e670f775b235d8a831689ffdf4a8f17bbba6b7caj * returns 1 if device pointed by 'link' is a removable hotplugged disk,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * else returns 0.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk char *p = NULL;
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (0);
6e670f775b235d8a831689ffdf4a8f17bbba6b7caj return (1);
6e670f775b235d8a831689ffdf4a8f17bbba6b7caj return (0);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * _reset_devalloc
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * If device allocation is being turned on, creates device_allocate
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * device_maps if they do not exist.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Puts DEVICE_ALLOCATION=ON/OFF in device_allocate to indicate if
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * device allocation is on/off.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk else if ((action == DA_OFF) && (open(DEVALLOC, O_RDONLY) == -1))
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * _make_db
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * execs /usr/sbin/mkdevalloc to create device_allocate and
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * device_maps.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk switch (pid) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (1);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk if (execl(MKDEVALLOC, MKDEVALLOC, DA_IS_LABELED, NULL) == -1)
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk for (;;) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return (1);
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk return ((WIFEXITED(status) == 0) ? 1 : WEXITSTATUS(status));
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * _update_devalloc_db
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * Forms allocatable device entries to be written to device_allocate and
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk * device_maps.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * Or finds the correct entry to remove, and removes it.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * Note: devname is a /devices link in the REMOVE case.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk/* ARGSUSED */
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk_update_devalloc_db(devlist_t *devlist, int devflag, int action, char *devname,
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk for (i = 0; i < DA_COUNT; i++) {
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk switch (i) {
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel nickname = _update_dev(NULL, action, typestring, NULL,
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * Not reached as of now, could be reached if devfsadm is
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * enhanced to clean up devalloc database more thoroughly.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * Will not reliably match for event-driven removes
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk for (entry = dentry; entry != NULL; entry = entry->next) {
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel (void) _update_dev(entry, action, NULL, devname, NULL);
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * _update_dev: Update device_allocate and/or device_maps files
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * If adding a device:
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * dentry: A linked list of allocatable devices
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * action: DA_ADD or DA_REMOVE
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * devtype: type of device linked list to update on removal
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * devname: short name (i.e. rmdisk5, cdrom0) of device if known
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * rm_link: name of real /device from hot_cleanup
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * If the action is ADD or if the action is triggered by an event
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * from syseventd, read the files FIRST and treat their data as
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * more-accurate than the dentry list, adjusting dentry contents if needed.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * For DA_ADD, try to add each device in the list to the files.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * If the action is DA_REMOVE and not a hotplug remove, adjust the files
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * as indicated by the linked list.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * If we successfully remove a device from the files, returns
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * a char * to strdup'd devname of the device removed.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * The caller is responsible for freeing the return value.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * NULL for all other cases, both success and failure.
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcelstatic char *
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel_update_dev(deventry_t *dentry, int action, const char *devtype, char *devname,
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * Add Events do not have enough information to overrride the
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * existing file contents.
45916cd2fec6e79bca5dee0421bd39e3c2910d1ejpk for (entry = dentry; entry != NULL; entry = entry->next) {
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * da_update_device will fill in entry devname if
7e3e5701c73b753fb9dd17a0cbe0568b4cdda39eJan Parcel * event_driven is true and device is in the file