/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <libintl.h>
#include <errno.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <dlfcn.h>
#include <link.h>
#include <libnvpair.h>
#include <libfstyp.h>
#include <libfstyp_module.h>
/* default module directory */
#ifndef TEXT_DOMAIN
#endif
typedef struct fstyp_ops {
} fstyp_ops_t;
typedef struct fstyp_module {
struct fstyp_handle {
fstyp_module_t *ident; /* identified module */
int fd;
long name_max;
};
#define NELEM(a) sizeof (a) / sizeof (*(a))
/* local functions */
static int fstyp_ident_all(struct fstyp_handle *h, const char **ident);
const char **ident);
const char *fsname);
static int fstyp_init_module(struct fstyp_handle *h,
static void fstyp_fini_module(struct fstyp_handle *h,
fstyp_module_t *mp);
static int fstyp_init_all_modules(struct fstyp_handle *h);
static void fstyp_fini_all_modules(struct fstyp_handle *h);
static int fstyp_load_module(struct fstyp_handle *h,
fstyp_module_t *mp);
static void fstyp_unload_module(struct fstyp_handle *h,
fstyp_module_t *);
/*
* Locate and initialize all modules.
* If 'module_dir' is specified, only initialize module from this dir.
*/
int
{
struct fstyp_handle *h;
int error;
return (FSTYP_ERR_NOMEM);
}
if ((module_dir != NULL) &&
free(h);
return (FSTYP_ERR_NOMEM);
}
h->libfs_dir = (char *)default_libfs_dir;
h->name_max = MAXNAMELEN;
}
h->name_max++;
if (h->module_dir == NULL) {
error = fstyp_init_all_modules(h);
} else {
}
if (error != 0) {
fstyp_fini(h);
return (error);
}
*handle = h;
return (0);
}
void
{
if (h != NULL) {
if (h->module_dir != NULL) {
free(h->module_dir);
}
free(h);
}
}
/*
* Identify the filesystem, return result in 'ident'.
* If 'fsname' is specified, only attempt that filesystem.
*/
int
{
return (fstyp_ident_all(h, ident));
} else {
return (fstyp_ident_one(h, fsname, ident));
}
}
/*
* use all modules for identification
*/
static int
{
if (h->ident != NULL) {
*ident = &h->ident->fsname[0];
return (0);
}
if ((fstyp_load_module(h, mp) == 0) &&
if (h->ident != NULL) {
h->ident = NULL;
*ident = NULL;
return (FSTYP_ERR_MULT_MATCH);
} else {
h->ident = mp;
return (0);
}
}
}
return (FSTYP_ERR_NO_MATCH);
}
/*
* use only the specified module for identification
*/
static int
{
if (h->ident != NULL) {
*ident = (char *)fsname;
return (0);
} else {
return (FSTYP_ERR_NO_MATCH);
}
}
return (FSTYP_ERR_NAME_TOO_LONG);
}
if (h->module_dir == NULL) {
} else {
}
return (FSTYP_ERR_MOD_NOT_FOUND);
}
h->ident = mp;
*ident = (char *)fsname;
return (0);
}
return (error);
}
/*
* Get the list of fs attributes.
*/
int
{
return (FSTYP_ERR_NO_MATCH);
}
}
/*
* Dump free-form filesystem information.
*/
int
{
return (FSTYP_ERR_NO_MATCH);
}
return (FSTYP_ERR_NOP);
}
}
/* ARGSUSED */
const char *
{
char *str;
switch (error) {
case FSTYP_ERR_OK:
break;
case FSTYP_ERR_NO_MATCH:
break;
case FSTYP_ERR_MULT_MATCH:
break;
case FSTYP_ERR_HANDLE:
break;
case FSTYP_ERR_OFFSET:
break;
case FSTYP_ERR_NO_PARTITION:
break;
case FSTYP_ERR_NOP:
break;
case FSTYP_ERR_DEV_OPEN:
break;
case FSTYP_ERR_IO:
break;
case FSTYP_ERR_NOMEM:
break;
case FSTYP_ERR_MOD_NOT_FOUND:
break;
case FSTYP_ERR_MOD_DIR_OPEN:
break;
case FSTYP_ERR_MOD_OPEN:
break;
case FSTYP_ERR_MOD_VERSION:
break;
case FSTYP_ERR_MOD_INVALID:
break;
case FSTYP_ERR_NAME_TOO_LONG:
break;
default:
break;
}
return (str);
}
static fstyp_module_t *
{
return (mp);
}
}
return (NULL);
}
/*
* Allocate and initialize module structure. Do not load just yet.
* A pointer to the existing module is returned, if such is found.
*/
static int
{
char *pathname;
/* if it's already inited, just return the pointer */
}
return (0);
}
/* allocate pathname buffer */
return (FSTYP_ERR_NOMEM);
}
/* locate module */
return (FSTYP_ERR_MOD_NOT_FOUND);
}
return (FSTYP_ERR_NOMEM);
}
/* append to list */
if (h->modules_tail == NULL) {
} else {
h->modules_tail = mp;
}
}
return (0);
}
/*
* Free module resources. NOTE: this does not update the module list.
*/
static void
{
if (h->ident == mp) {
h->ident = NULL;
}
fstyp_unload_module(h, mp);
}
}
/*
* Look for .so's and save them in the list.
*/
static int
{
char *mdir;
return (FSTYP_ERR_NOMEM);
}
return (FSTYP_ERR_NOMEM);
}
return (FSTYP_ERR_MOD_DIR_OPEN);
}
continue;
}
}
return (0);
}
static void
{
fstyp_fini_module(h, mp);
}
}
/*
* Load the .so module.
*/
static int
{
int error;
return (0);
}
return (FSTYP_ERR_MOD_OPEN);
}
fstyp_unload_module(h, mp);
return (FSTYP_ERR_MOD_INVALID);
}
if (error != 0) {
fstyp_unload_module(h, mp);
return (error);
}
return (0);
}
/*ARGSUSED*/
static void
{
}
}
}