mkdtab.c revision 342440ec94087b8c751c580ab9ed6c693d31d418
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <devmgmt.h>
#include <devtab.h>
#include <dirent.h>
#include <libgen.h>
/*
* Designed so it can be run either once at installation time or after
* every reboot. The alias naming scheme used is non-intuitive but
* is consistent with existing conventions and documentation and with
* the device numbering scheme used by the disks command.
* Code borrowed liberally from prtconf, disks and prtvtoc commands.
*/
/*
* make this long enough to start out with.
* there are place we write into putdevcmd
* where we are not testing for overrun.
*/
#define ORIGLEN 1024
struct dpart {
char alias[20];
char *cdevice;
char *bdevice;
};
static int vfsnum;
static char *putdevcmd;
static char cmd[80];
#ifdef att3b2
#endif
static void checkandresize(int);
static char *
{
char *mem;
"%s: can't update device tables:Out of memory\n", cmd);
exit(1);
}
}
/*
* Add device table entry for the floppy drive.
*/
static void
{
"cdevice=/dev/r%s bdevice=/dev/%s desc=\"Floppy Drive\" "
"mountpt=/mnt volume=diskette "
"type=diskette removable=true capacity=2880 "
"2 4096 512 80 2 5 3072 t\"",
exit(1);
}
}
static void
do_fdisks(void)
{
int drive = 1;
return;
}
}
}
}
/*
* hdisk() gets information about the specified hard drive from the vtoc
* and vfstab and adds the disk and partition entries to device.tab. If
* we can't access the raw disk we simply assume it isn't properly configured
* and we add no entries to device.tab.
*/
static void
{
char *cdskpath;
char *bdskpath;
char *mountpoint;
exit(1);
}
drivepfx);
return;
}
/*
* Read volume table of contents.
*/
return;
}
/*
* Begin building the putdev command string that will be
* used to make the entry for this disk.
*/
exit(1);
}
drivepfx);
"cdevice=%s bdevice=%s "
"desc=\"Disk Drive\" type=disk "
"part=true removable=false capacity=%llu dpartlist=",
exit(1);
}
/*
* Build a table of disk partitions we are interested in and finish
* the putdev command string for the disk by adding the dpartlist.
*/
if ((dparttab =
"%s: can't disk partitions table: Out of memory\n", cmd);
exit(1);
}
dpartcnt = 0;
continue;
i);
exit(1);
}
exit(1);
}
if (dpartcnt != 0)
dpartcnt++;
}
/*
* We assemble the rest of the information about the partitions by
* looking in the vfstab.
*/
for (i = 0; i < dpartcnt; i++) {
for (j = 0; j < vfsnum; j++) {
vfstab[j].vfs_special) == 0)
break;
}
if (j < vfsnum) {
/*
* Partition found in vfstab.
*/
mountpoint = "/mnt";
else
"-a %s cdevice=%s bdevice=%s "
"desc=\"Disk Partition\" type=dpart "
"removable=false capacity=%llu dparttype=fs "
mountpoint) >= lastlen) {
"%s: Command too long: %s\n",
exit(1);
}
}
}
}
static void
do_hdisks(void)
{
return;
}
/*
* now know off the 's2'
*/
/*
* And do it!
*/
}
}
}
/*
* Add device table entry for the cartridge tape drive.
*/
static void
{
"desc=\"Tape Drive\" volume=\"tape\" "
"type=ctape removable=true capacity=45539 bufsize=15872 "
exit(1);
}
}
static void
do_tapes(void)
{
return;
}
}
}
}
static void
initialize(void)
{
int i;
char *criteria[5];
char **olddevlist;
/*
* Build a copy of vfstab in memory for later use.
*/
cmd);
exit(1);
}
/*
* Go through the vfstab file once to get the number of entries so
* we can allocate the right amount of contiguous memory.
*/
vfsnum = 0;
vfsnum++;
== NULL) {
"%s: can't update device tables:Out of memory\n", cmd);
exit(1);
}
/*
* Go through the vfstab file one more time to populate our copy in
* memory. We only populate the fields we'll need.
*/
i = 0;
else
else
else
i++;
}
/*
* Now remove all current entries of type disk, dpart, ctape
* and diskette from the device and device group tables.
* Any changes made manually since the last time this command
* was run will be lost. Note that after this we are committed
* to try our best to rebuild the tables (i.e. the command
* should try not to fail completely after this point).
*/
criteria[0] = "type=disk";
_enddevtab(); /* getdev() should do this but doesn't */
perror("malloc");
exit(-1);
}
for (i = 0; olddevlist[i] != (char *)NULL; i++) {
exit(1);
}
}
}
/*
*/
static void
mkdgroups(void)
{
int i;
char *criteria[2];
char **devlist;
criteria[0] = "type=disk";
}
if (i != 0)
criteria[0] = "type=dpart";
}
if (i != 0)
criteria[0] = "type=ctape";
}
if (i != 0)
criteria[0] = "type=diskette";
}
if (i != 0)
}
static void
checkandresize(int size)
{
}
}
/*ARGSUSED*/
int
{
initialize();
/*
* AT&T code looked at the 3B2 EDT here. Since we have a known-good
* /dev directory ( presuming 'disks' has already been run), we simply
* look in the /dev subdirectories.
*/
do_hdisks();
do_fdisks();
do_tapes();
/*
* Update the dgroup.tab file.
*/
mkdgroups();
return (0);
}