2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A/*
2N/A * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <errno.h>
2N/A#include <string.h>
2N/A#include <devmgmt.h>
2N/A
2N/A/*
2N/A * char *devattr(device, attr)
2N/A *
2N/A * This is a stubbed implementation of devattr(), which was part of
2N/A * the SVR4 OAM device managment stuff which used to be present in
2N/A * libadm. This satisfies an interface needed by SVR4 packaging.
2N/A *
2N/A * devattr was used to search the device table (/etc/device.tab),
2N/A * looking for the device specified by <device> and to find specific
2N/A * attributes of specific devices. See also getvol.c.
2N/A *
2N/A * In this implementation, we emulate a device.tab file in which
2N/A * there is a single line defining "spool"-- the "package spool",
2N/A * which is the directory in /var/spool/pkg. This line looked like
2N/A * this:
2N/A *
2N/A * spool:::/var/spool/pkg:desc="Packaging Spool Directory"
2N/A *
2N/A * Arguments:
2N/A * device Pointer to the character-string that describes the
2N/A * device whose record is to be looked for
2N/A * attr The device's attribute to be looked for
2N/A *
2N/A * Returns: char *
2N/A * A pointer to the character-string containing the value of the
2N/A * attribute <attr> for the device <device>, or (char *) NULL if none
2N/A * was found. If the function returns (char *) NULL and the error was
2N/A * detected by this function, it sets "errno" to indicate the problem.
2N/A *
2N/A * "errno" Values:
2N/A * EPERM Permissions deny reading access of the device-table
2N/A * file
2N/A * ENOENT The specified device-table file could not be found
2N/A * ENODEV Device not found in the device table
2N/A * EINVAL The device does not have that attribute defined
2N/A * ENOMEM No memory available
2N/A */
2N/A
2N/Achar *
2N/Adevattr(char *device, char *attribute)
2N/A{
2N/A char *r = NULL, *rtnval;
2N/A
2N/A if (strcmp(device, "spool") != 0) {
2N/A errno = ENODEV;
2N/A return (NULL);
2N/A }
2N/A
2N/A /* Did they ask for the device alias? */
2N/A if (strcmp(attribute, DTAB_ALIAS) == 0)
2N/A r = "spool";
2N/A
2N/A /*
2N/A * Alias, cdevice, bdevice, and pathname attrs were never returned as
2N/A * NULL (for no apparent reason). "" was used instead. We stick with
2N/A * the scheme here. Other attributes could return NULL.
2N/A */
2N/A if ((strcmp(attribute, DTAB_CDEVICE) == 0) ||
2N/A (strcmp(attribute, DTAB_BDEVICE) == 0)) {
2N/A r = "";
2N/A }
2N/A
2N/A if (strcmp(attribute, DTAB_PATHNAME) == 0)
2N/A r = "/var/spool/pkg";
2N/A
2N/A if (strcmp(attribute, "desc") == 0)
2N/A r = "Packaging Spool Directory";
2N/A
2N/A /* We don't emulate any other attributes */
2N/A if (r == NULL) {
2N/A errno = EINVAL;
2N/A return (NULL);
2N/A }
2N/A
2N/A if ((rtnval = strdup(r)) == NULL) {
2N/A errno = ENOMEM;
2N/A return (NULL);
2N/A }
2N/A return (rtnval);
2N/A}