2
* Permission is hereby granted, free of charge, to any person obtaining a copy
3
* of this software and associated documentation files (the "Software"), to
4
* deal in the Software without restriction, including without limitation the
5
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6
* sell copies of the Software, and to permit persons to whom the Software is
7
* furnished to do so, subject to the following conditions:
9
* The above copyright notice and this permission notice shall be included in
10
* all copies or substantial portions of the Software.
12
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
* DEALINGS IN THE SOFTWARE.
20
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
21
* Use is subject to license terms.
32
#include "fsimage_plugin.h"
33
#include "fsimage_priv.h"
35
static fsi_plugin_t *plugins;
38
fsip_fs_set_data(fsi_t *fsi, void *data)
44
fsip_file_alloc(fsi_t *fsi, void *data)
46
fsi_file_t *ffi = malloc(sizeof (fsi_file_t));
50
bzero(ffi, sizeof (fsi_file_t));
58
fsip_file_free(fsi_file_t *ffi)
64
fsip_fs(fsi_file_t *ffi)
70
fsip_fs_offset(fsi_t *fsi)
76
fsip_fs_data(fsi_t *fsi)
82
fsip_file_data(fsi_file_t *ffi)
84
return (ffi->ff_data);
87
static int init_plugin(const char *lib)
89
fsi_plugin_init_t init;
90
fsi_plugin_t *fp = malloc(sizeof (fsi_plugin_t));
95
bzero(fp, sizeof (fsi_plugin_t));
97
if ((fp->fp_dlh = dlopen(lib, RTLD_LAZY | RTLD_LOCAL)) == NULL) {
102
init = dlsym(fp->fp_dlh, "fsi_init_plugin");
107
fp->fp_ops = init(FSIMAGE_PLUGIN_VERSION, fp, &fp->fp_name);
108
if (fp->fp_ops == NULL ||
109
fp->fp_ops->fpo_version > FSIMAGE_PLUGIN_VERSION)
112
fp->fp_next = plugins;
117
(void) dlclose(fp->fp_dlh);
122
static int load_plugins(void)
124
const char *fsdir = getenv("FSIMAGE_FSDIR");
125
const char *isadir = "";
126
struct dirent *dp = NULL;
134
#if defined(FSIMAGE_FSDIR)
136
fsdir = FSIMAGE_FSDIR;
137
#elif defined(__sun__)
139
fsdir = "/usr/lib/fs";
141
if (sizeof(void *) == 8)
143
#elif defined(__ia64__)
145
fsdir = "/usr/lib/fs";
148
if (sizeof(void *) == 8)
149
fsdir = "/usr/lib64/fs";
151
fsdir = "/usr/lib/fs";
155
if ((name_max = pathconf(fsdir, _PC_NAME_MAX)) == -1)
158
if ((tmp = malloc(name_max + 1)) == NULL)
161
if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL)
164
if ((dir = opendir(fsdir)) == NULL)
167
bzero(dp, sizeof (struct dirent) + name_max + 1);
169
while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) {
170
if (strcmp(dpp->d_name, ".") == 0)
172
if (strcmp(dpp->d_name, "..") == 0)
175
(void) snprintf(tmp, name_max, "%s/%s/%sfsimage.so", fsdir,
176
dpp->d_name, isadir);
178
if (init_plugin(tmp) != 0)
187
(void) closedir(dir);
194
int find_plugin(fsi_t *fsi, const char *path, const char *options)
199
if (plugins == NULL && (ret = load_plugins()) != 0)
202
for (fp = plugins; fp != NULL; fp = fp->fp_next) {
204
if (fp->fp_ops->fpo_mount(fsi, path, options) == 0)