mkdevmaps.c revision 7883e825152992a0f20c3f52f7c4bb902a56205c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* scan /dev directory for mountable objects and construct device_maps
* file for allocate....
*
* devices are:
* tape (cartridge)
* audio
* floppy
* CD
*/
#include <dirent.h> /* for readdir(3), etc. */
#include <unistd.h> /* for readlink(2) */
#include <string.h> /* for strcpy(3), etc. */
#include <strings.h> /* for bcopy(3C), etc. */
#include <stdio.h> /* for perror(3) */
#include <stdlib.h> /* for atoi(3) */
#include <locale.h>
#include <libintl.h>
#ifndef TEXT_DOMAIN
#define TEXT_DOMAIN "SUNW_OST_OSCMD"
#endif
struct tape {
char *name;
char *device;
int number;
} *tape;
struct audio {
char *name;
char *device;
int number;
} *audio;
struct cd {
char *name;
char *device;
int id;
int number;
int controller;
} *cd;
struct fp {
char *name;
char *device;
int number;
} *fp;
static void dotape();
static void doaudio();
static void dofloppy();
static void docd();
static void initmem();
static int expandmem(int, void **, int);
static void no_memory(void);
int
main(void)
{
(void) textdomain(TEXT_DOMAIN);
initmem(); /* initialize memory */
dotape(); /* do tape */
doaudio(); /* do audio */
dofloppy(); /* do floppy */
docd(); /* do cd */
return (0);
}
static void
dotape()
{
int i, j, n;
int sz; /* size of symlink value */
char *cp; /* pointer into string */
int first = 0; /* kludge to put space between entries */
int ntape; /* max array size */
ntape = DFLT_NTAPE;
/*
* look for rst* and nrst*
*/
perror("open /dev failure");
exit(1);
}
i = 0;
/* ignore if neither rst* nor nrst* */
continue;
/* if array full, then expand it */
if (i == ntape) {
/* will exit(1) if insufficient memory */
sizeof (struct tape));
}
/* save name (/dev + / + d_naem + \0) */
no_memory();
/* ignore if not symbolic link (note i not incremented) */
exit(1);
}
continue;
/* get name from symbolic link */
< 0)
continue;
no_memory();
/* get device number */
cp++; /* advance to device # */
i++;
}
/*
*/
exit(1);
}
/* skip . .. etc... */
continue;
/* if array full, then expand it */
if (i == ntape) {
/* will exit(1) if insufficient memory */
sizeof (struct tape));
}
no_memory();
/* save device name (rmt/ + d_name + \0) */
no_memory();
i++;
}
n = i;
/* remove duplicate entries */
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
continue;
}
}
/* print out device_maps entries for tape devices */
for (i = 0; i < 8; i++) {
for (j = 0; j < n; j++) {
continue;
if (first)
(void) printf(" ");
else {
(void) printf("st%d:\\\n", i);
(void) printf("\trmt:\\\n");
(void) printf("\t");
first++;
}
}
if (first) {
(void) printf(":\\\n\n");
first = 0;
}
}
}
static void
doaudio()
{
int i, j, n;
int sz; /* size of symlink value */
char *cp; /* pointer into string */
int first = 0; /* kludge to put space between entries */
int naudio; /* max array size */
exit(1);
}
i = 0;
continue;
/* if array full, then expand it */
if (i == naudio) {
/* will exit(1) if insufficient memory */
sizeof (struct audio));
}
/* save name (/dev + / + d_name + \0) */
no_memory();
/* ignore if not symbolic link (note i not incremented) */
exit(1);
}
continue;
/* get name from symbolic link */
sizeof (linkvalue))) < 0)
continue;
no_memory();
cp++; /* advance to device # */
i++;
}
goto skip;
}
/* skip . .. etc... */
continue;
/* if array full, then expand it */
if (i == naudio) {
/* will exit(1) if insufficient memory */
sizeof (struct audio));
}
no_memory();
no_memory();
i++;
}
skip:
n = i;
/* remove duplicate entries */
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
continue;
}
}
/* print out device_maps entries for tape devices */
for (i = 0; i < 8; i++) {
for (j = 0; j < n; j++) {
continue;
if (first)
(void) printf(" ");
else {
(void) printf("audio:\\\n");
(void) printf("\taudio:\\\n");
(void) printf("\t");
first++;
}
}
if (first) {
(void) printf(":\\\n\n");
first = 0;
}
}
}
static void
dofloppy()
{
int i, j, n;
int sz; /* size of symlink value */
char *cp; /* pointer into string */
int first = 0; /* kludge to put space between entries */
int nfp; /* max array size */
/*
* look for fd0* and rfd0*
*/
exit(1);
}
i = 0;
/* ignore if neither rst* nor nrst* */
continue;
/* if array full, then expand it */
if (i == nfp) {
/* will exit(1) if insufficient memory */
}
/* save name (/dev + / + d_name + \0) */
no_memory();
/* ignore if not symbolic link (note i not incremented) */
exit(1);
}
continue;
/* get name from symbolic link */
< 0)
continue;
no_memory();
/* get device number */
cp++; /* advance to device # */
cp++; /* advance to device # */
i++;
}
n = i;
/* print out device_maps entries for floppy devices */
for (i = 0; i < 8; i++) {
for (j = 0; j < n; j++) {
continue;
if (first)
(void) printf(" ");
else {
(void) printf("fd%d:\\\n", i);
(void) printf("\tfd:\\\n");
(void) printf("\t");
if (i == 0)
first++;
}
}
if (first) {
(void) printf(":\\\n\n");
first = 0;
}
}
}
static void
docd()
{
int i, j, n;
int sz; /* size of symlink value */
char *cp; /* pointer into string */
int first = 0; /* kludge to put space between entries */
int id; /* disk id */
int ctrl; /* disk controller */
int ncd; /* max array size */
/*
* look for sr* and rsr*
*/
exit(1);
}
i = 0;
/* ignore if neither sr* nor rsr* */
continue;
/* if array full, then expand it */
if (i == ncd) {
/* will exit(1) if insufficient memory */
}
/* save name (/dev + / + d_name + \0) */
no_memory();
/* save id # */
else
/* ignore if not symbolic link (note i not incremented) */
exit(1);
}
continue;
/* get name from symbolic link */
sizeof (linkvalue))) < 0)
continue;
no_memory();
cp++; /* advance to device # */
i++;
}
n = i;
/*
*/
exit(1);
}
/* skip . .. etc... */
continue;
/* get device # (disk #) */
continue;
/* see if this is one of the cd special devices */
for (j = 0; j < n; j++) {
goto found;
}
continue;
/* if array full, then expand it */
if (i == ncd) {
/* will exit(1) if insufficient memory */
}
no_memory();
i++;
}
/*
*/
exit(1);
}
/* skip . .. etc... */
continue;
/* get device # (disk #) */
continue;
/* see if this is one of the cd special devices */
for (j = 0; j < n; j++) {
goto found1;
}
continue;
/* if array full, then expand it */
if (i == ncd) {
/* will exit(1) if insufficient memory */
}
no_memory();
i++;
}
n = i;
/* print out device_maps entries for tape devices */
for (i = 0; i < 8; i++) {
for (j = 0; j < n; j++) {
continue;
if (first)
(void) printf(" ");
else {
(void) printf("sr%d:\\\n", i);
(void) printf("\tsr:\\\n");
(void) printf("\t");
first++;
}
}
if (first) {
(void) printf(":\\\n\n");
first = 0;
}
}
}
/* set default array sizes */
static void
initmem()
{
no_memory();
}
/* note n will be # elments in `array' */
static int
{
void *new;
/* get new array space (n + DELTA) */
perror("memory allocation failed");
exit(1);
}
/* copy old array into new space */
/* now release old arrary */
return (n + DELTA);
}
static void
no_memory(void)
{
gettext("out of memory"));
exit(1);
/* NOT REACHED */
}