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
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include "lint.h"
2N/A#include <sys/types.h>
2N/A#include <sys/mkdev.h>
2N/A#include <errno.h>
2N/A
2N/A/*
2N/A * Create a formatted device number
2N/A */
2N/Adev_t
2N/A__makedev(const int version, const major_t majdev, const minor_t mindev)
2N/A{
2N/A dev_t devnum;
2N/A switch (version) {
2N/A case OLDDEV:
2N/A if (majdev > OMAXMAJ || mindev > OMAXMIN) {
2N/A errno = EINVAL;
2N/A return ((o_dev_t)NODEV);
2N/A }
2N/A devnum = ((majdev << ONBITSMINOR) | mindev);
2N/A break;
2N/A
2N/A case NEWDEV:
2N/A#if MAXMAJ != 0xfffffffful /* assumes major_t == uint32_t */
2N/A if (majdev > MAXMAJ) {
2N/A errno = EINVAL;
2N/A return (NODEV);
2N/A }
2N/A#endif
2N/A#if MAXMIN != 0xfffffffful /* assumes minor_t == uint32_t */
2N/A if (mindev > MAXMIN) {
2N/A errno = EINVAL;
2N/A return (NODEV);
2N/A }
2N/A#endif
2N/A if ((devnum = (((dev_t)majdev << NBITSMINOR) |
2N/A mindev)) == NODEV) {
2N/A errno = EINVAL;
2N/A return (NODEV);
2N/A }
2N/A break;
2N/A
2N/A default:
2N/A errno = EINVAL;
2N/A return (NODEV);
2N/A }
2N/A
2N/A return (devnum);
2N/A}
2N/A
2N/A/*
2N/A * Return major number part of formatted device number
2N/A */
2N/Amajor_t
2N/A__major(const int version, const dev_t devnum)
2N/A{
2N/A major_t maj;
2N/A
2N/A switch (version) {
2N/A case OLDDEV:
2N/A maj = (devnum >> ONBITSMINOR);
2N/A if (devnum == NODEV || maj > OMAXMAJ) {
2N/A errno = EINVAL;
2N/A return ((major_t)NODEV);
2N/A }
2N/A break;
2N/A
2N/A case NEWDEV:
2N/A maj = (devnum >> NBITSMINOR);
2N/A if (devnum == NODEV) {
2N/A errno = EINVAL;
2N/A return ((major_t)NODEV);
2N/A }
2N/A#if MAXMAJ != 0xfffffffful /* assumes major_t == uint32_t */
2N/A if (maj > MAXMAJ) {
2N/A errno = EINVAL;
2N/A return ((major_t)NODEV);
2N/A }
2N/A#endif
2N/A break;
2N/A
2N/A default:
2N/A errno = EINVAL;
2N/A return ((major_t)NODEV);
2N/A }
2N/A
2N/A return (maj);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Return minor number part of formatted device number
2N/A */
2N/Aminor_t
2N/A__minor(const int version, const dev_t devnum)
2N/A{
2N/A switch (version) {
2N/A case OLDDEV:
2N/A if (devnum == NODEV) {
2N/A errno = EINVAL;
2N/A return ((minor_t)NODEV);
2N/A }
2N/A return (devnum & OMAXMIN);
2N/A
2N/A case NEWDEV:
2N/A if (devnum == NODEV) {
2N/A errno = EINVAL;
2N/A return ((minor_t)NODEV);
2N/A }
2N/A return (devnum & MAXMIN);
2N/A
2N/A default:
2N/A errno = EINVAL;
2N/A return ((minor_t)NODEV);
2N/A }
2N/A}