main.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 (c) 1999-2000 by Sun Microsystems, Inc.
* All rights reserved.
*
* lofiadm - administer lofi(7d). Very simple, add and remove file<->device
* associations, and display status. All the ioctls are private between
* lofi and lofiadm, and so are very simple - device information is
* communicated via a minor number.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <fcntl.h>
#include <locale.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stropts.h>
#include "utils.h"
static const char USAGE[] =
"Usage: %s -a file [ device ]\n"
" %s -d file | device \n"
" %s [ device | file ]\n";
static const char *pname;
static int addflag = 0;
static int deleteflag = 0;
static int errflag = 0;
#define FORMAT "%-20s %s\n"
/*
* Print the list of all the mappings. Including a header.
*/
static void
print_mappings(int fd)
{
struct lofi_ioctl li;
int minor;
int maxminor;
perror("ioctl");
}
continue;
perror("ioctl");
break;
}
}
}
static void
usage(void)
{
}
/*
* Translate a lofi device name to a minor number. We might be asked
* to do this when there is no association (such as when the user specifies
* a particular device), so we can only look at the string.
*/
static int
name_to_minor(const char *devicename)
{
int minor;
return (minor);
}
return (minor);
}
return (0);
}
/*
* This might be the first time we've used this minor number. If so,
* it might also be that the /dev links are in the process of being created
* by devfsadmd (or that they'll be created "soon"). We cannot return
* until they're there or the invoker of lofiadm might try to use them
* and not find them. This can happen if a shell script is running on
* an MP.
*/
static void
{
int cursleep;
cursleep = 0;
continue;
}
return;
}
/* one last try */
}
}
}
/*
* Add a device association. If devicename is NULL, let the driver
* pick a device.
*/
static void
{
struct lofi_ioctl li;
int minor;
if (devicename == NULL) {
/* pick one */
if (minor == -1) {
}
/* print one picked */
return;
}
/* use device we were given */
if (minor == 0) {
}
}
}
/*
* Remove an association. Delete by device name if non-NULL, or by
* filename otherwise.
*/
static void
{
struct lofi_ioctl li;
if (devicename == NULL) {
/* delete by filename */
}
return;
}
/* delete by device */
}
}
}
static void
{
struct lofi_ioctl li;
if (devicename == NULL) {
/* given filename, print devicename */
}
return;
}
/* given devicename, print filename */
}
}
}
int
{
int lfd;
int c;
int error;
const char *devicename = NULL;
int openflag;
int minor;
int fd = -1;
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'a':
addflag = 1;
if (fd == -1) {
}
if (error == -1) {
"block, or character device\n"),
filename);
"of %d\n"),
}
if (minor != 0) {
" on itself\n"), devicename);
}
/* optional device */
optind++;
}
break;
case 'd':
deleteflag = 1;
if (minor != 0)
devicename = optarg;
else
break;
case '?':
default:
errflag = 1;
break;
}
}
usage();
case 0: /* no more args */
break;
case 1: /* one arg without options means print the association */
if (addflag || deleteflag)
usage();
if (minor != 0)
else
break;
default:
usage();
break;
}
/*
* Here, we know the arguments are correct, the filename is an
* absolute path, it exists and is a regular file. We don't yet
* know that the device name is ok or not.
*/
/*
* Now to the real work.
*/
if (addflag || deleteflag)
else
if (lfd == -1) {
die("you do not have permission to perform "
"that operation.\n");
} else {
}
/*NOTREACHED*/
}
if (addflag)
else if (deleteflag)
else if (filename || devicename)
else
return (E_SUCCESS);
}