/*
* 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"
/*LINTLIBRARY*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/sysmacros.h>
#include <sys/fssnap_if.h>
#include "libadm.h"
/*
* Globals:
* getfullrawname - returns a fully-qualified raw device name
* getfullblkname - returns a fully-qualified block device name
*
* These two routines take a device pathname and return corresponding
* the raw or block device name.
*
* First the device name is fully qualified:
* If the device name does not start with a '/' or starts with
* './' then the current working directory is added to the beginning
* of the pathname.
*
* If the device name starts with a '../' then all but the last
* sub-directory of the current working directory is added to the
* the beginning of the pathname.
*
* device that is being asked for then the fully-qualified device name is
* returned.
*
*
* Last standard names are converted. Standard names are those
* with a '/dsk/' for block or '/rdsk/' for raw sub-directory components
* in the device name. Or, the filename component has an 'r' for raw or
* no 'r' for block (e.g., rsd0a <=> sd0a).
*
* Caveat:
* It is assumed that the block and raw devices have the
* same device number, and this is used to verify the conversion
* happened corretly. If this happens not to be true, due to mapping
* of minor numbers or sometheing, then entries can be put in the
*
*
* Return Values:
* null string - When the conversion failed
* null pointer - malloc problems
*
* It is up to the user of these routines to free the memory, of
* the device name or null string returned by these library routines,
* when appropriate by the application.
*/
#define GET_BLK 0
static int test_if_blk(char *, dev_t);
static int test_if_raw(char *, dev_t);
static char *getblkcomplete(char *, struct stat64 *);
static char *getrawcomplete(char *, struct stat64 *);
/*
* getfullname() - Builds a fully qualified pathname.
* This handles . and .. as well.
* NOTE: This is different from realpath(3C) because
* it does not follow links.
*/
static char *
{
char *c;
char *wa;
if (*path == '/')
return (strdup(""));
/* handle . and .. */
/* strip the ./ from the given path */
path += 2;
/* strip the last directory component from cwd */
*c = '\0';
/* strip the ../ from the given path */
path += 3;
}
/*
* Adding 2 takes care of slash and null terminator.
*/
return (NULL);
return (wa);
}
/*
*/
static int
{
/* check if we got a char special file */
return (0);
return (0);
return (0);
return (1);
}
/*
*/
static int
{
/* check if we got a char special file */
return (0);
return (0);
return (0);
return (1);
}
/*
* complete getblkrawname() for blk->raw to handle volmgt devices
*/
static char *
{
char *dp;
char *new_path;
char c;
/* ok, so we either have a bad device or a floppy */
/* try the rfd# form */
return (NULL);
c = *++dp; /* save the 'r' */
*dp++ = c; /* give the 'r' back */
return (new_path);
return (strdup(""));
}
/* try the rdiskette form */
return (NULL);
c = *++dp; /* save the 'r' */
*dp++ = c; /* give the 'r' back */
return (new_path);
return (strdup(""));
}
/* no match found */
return (strdup(""));
}
/*
* complete getfullrawname() for raw->blk to handle volmgt devices
*/
static char *
{
char *dp;
char *new_path;
char c;
/* ok, so we either have a bad device or a floppy */
/* try the fd# form */
/* malloc path for new_path to hold raw */
return (NULL);
c = *++dp; /* save the 'f' */
*dp = c; /* put the 'f' back */
return (new_path);
}
/* try the diskette form */
/* malloc path for new_path to hold raw */
return (NULL);
c = *++dp; /* save at 'd' */
*dp = c; /* put the 'd' back */
return (new_path);
return (strdup(""));
}
/* failed to build raw name, return null string */
return (strdup(""));
}
static char *
{
return (NULL);
if (raw_special)
else
return (NULL);
}
if (raw_special)
return (vp.vfs_fsckdev);
return (vp.vfs_special);
}
/*
* change the device name to a block device name
*/
char *
{
char *dp;
char *new_path;
return (strdup(""));
/*
* Create a fully qualified name.
*/
return (NULL);
if (*cp == '\0')
return (cp);
return (strdup(""));
}
return (cp);
return (strdup(""));
}
}
/*
* We have a raw device name, go find the block name.
*/
/* this is not really possible */
return (strdup(""));
}
dp++;
if (*dp != 'r') {
return (dp);
}
return (NULL);
}
/* fill in the rest of the unraw name */
/* block name was found, return it here */
return (new_path);
}
return (dp);
}
/*
* change the device name to a raw devname
*/
char *
{
char *dp;
char *new_path;
return (strdup(""));
/*
* Create a fully qualified name.
*/
return (NULL);
if (*cp == '\0')
return (cp);
return (strdup(""));
}
return (cp);
return (strdup(""));
}
}
/*
* We have a block device name, go find the raw name.
*/
/* this is not really possible */
return (strdup(""));
}
dp++;
return (NULL);
}
/* fill in the rest of the raw name */
return (new_path);
}
return (dp);
}