fstyp.c revision ca29f3da510ba7f712a40977b04aeceda9b70b95
/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <libintl.h>
#include <locale.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <dirent.h>
#include <dlfcn.h>
#include <libfstyp.h>
#define FSTYP_LIBFS_DIR "/usr/lib/fs"
static const char *getmodfsname();
static char *getexecpathname();
static void
usage(void)
{
exit(1);
}
int
{
int fd = -1;
int c;
int aflag = 0;
int vflag = 0;
int indent = 0;
char *devpath;
int dos_num;
fstyp_handle_t h = NULL;
const char *modfsname;
const char *fsname;
int error = FSTYP_ERR_NO_MATCH;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'a':
aflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
usage();
break;
}
}
if (argc != 1) {
usage();
}
modfsname = getmodfsname();
/*
* Open device, find partition offset if requested
*/
}
goto out;
}
if (is_dos) {
goto out;
}
}
/*
* Use libfstyp to identify filesystem
*/
goto out;
}
fstyp_fini(h);
h = NULL;
goto out;
}
/*
* Output additional info if requested
*/
if (vflag) {
}
goto out;
}
}
out:
if (error != 0) {
fstyp_strerror(h, error));
}
if (h != NULL) {
fstyp_fini(h);
}
if (fd >= 0) {
}
}
return (error);
}
\
}
\
for (i = 0; i < count; i++) { \
} \
}
static void
{
return;
}
switch (nvpair_type(elem)) {
case DATA_TYPE_BOOLEAN_VALUE:
break;
case DATA_TYPE_BYTE:
break;
case DATA_TYPE_INT8:
break;
case DATA_TYPE_UINT8:
break;
case DATA_TYPE_INT16:
break;
case DATA_TYPE_UINT16:
break;
case DATA_TYPE_INT32:
break;
case DATA_TYPE_UINT32:
break;
case DATA_TYPE_INT64:
break;
case DATA_TYPE_UINT64:
break;
case DATA_TYPE_STRING:
break;
case DATA_TYPE_BYTE_ARRAY:
break;
case DATA_TYPE_INT8_ARRAY:
break;
case DATA_TYPE_UINT8_ARRAY:
break;
case DATA_TYPE_INT16_ARRAY:
break;
case DATA_TYPE_UINT16_ARRAY:
break;
case DATA_TYPE_INT32_ARRAY:
break;
case DATA_TYPE_UINT32_ARRAY:
break;
case DATA_TYPE_INT64_ARRAY:
break;
case DATA_TYPE_UINT64_ARRAY:
"%llu");
break;
case DATA_TYPE_STRING_ARRAY:
break;
case DATA_TYPE_NVLIST:
nvpair_name(elem));
break;
case DATA_TYPE_NVLIST_ARRAY:
(void) nvpair_value_nvlist_array(elem,
&nvlist_array_value, &count);
for (i = 0; i < count; i++) {
nvpair_name(elem), i);
}
break;
default:
}
}
}
/*
* return that fsname; otherwise return NULL.
*/
static const char *
{
char *path;
char *p;
int len;
return (NULL);
}
*p = '\0';
*p++ = '\0';
(void) strlcpy(fsname_buf, p,
sizeof (fsname_buf));
fsname = fsname_buf;
}
}
}
return (fsname);
}
/*
* Return executable's absolute pathname
*/
static char *
{
const char *execname;
char *cwd;
char *path;
char *rpath;
goto out;
}
execname = getexecname();
if (execname[0] == '/') {
} else {
}
}
out:
}
}
return (rpath);
}
/*
* Separates dos notation device spec into device and drive number
*/
static boolean_t
{
char *p;
return (B_FALSE);
}
return (B_FALSE);
}
p[0] = '\0';
p[0] = ':';
}
static boolean_t
{
}
static boolean_t
{
}
struct part_find_s {
int num;
int count;
int systid;
int r_systid;
int r_relsect;
int r_numsect;
};
enum { WALK_CONTINUE, WALK_TERMINATE };
/*
* Walk partition tables and invoke a callback for each.
*/
static void
int (*f)(void *, int, int, int), void *arg)
{
int bufsize = 1024;
int relsect;
int ext = 0;
int systid;
int i;
break;
}
break;
}
for (i = 0; i < FD_NUMPART; i++) {
if (systid == 0) {
continue;
}
if (ext++ == 0) {
} else {
}
}
return;
}
}
}
}
static int
{
struct part_find_s *p = arg;
if (is_dos_drive(systid)) {
return (WALK_TERMINATE);
}
}
return (WALK_CONTINUE);
}
/*
* Given a dos drive number, return its relative offset in the drive.
*/
static boolean_t
{
struct part_find_s p = { 0, 0, 0, 0, 0, 0 };
/*
* It is possible that the media we are dealing with can have different
* sector size than the default 512 bytes. Query the driver and check
* whether the media has different sector size.
*/
else
if (num > 0) {
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* libfstyp identification failed: as a last resort, try to
*/
static void
{
char *lib_dir = FSTYP_LIBFS_DIR;
char *path;
long name_max;
int error;
if (vflag) {
arg1 = "-v";
} else {
}
return;
}
goto out;
}
continue;
}
/* it's legacy if there's no libfstyp module for it */
if (error != FSTYP_ERR_MOD_NOT_FOUND) {
if (error == 0) {
fstyp_fini(h);
}
continue;
}
/* file must exist and be executable */
continue;
}
exit(0);
}
}
out:
}
}
}
static int
{
int status = 1;
if (pid < 0) {
return (1);
} else if (pid == 0) {
/* child */
exit(1);
}
/* parent */
return (status);
}