Lines Matching refs:h

88 static int	fstyp_ident_all(struct fstyp_handle *h, const char **ident);
89 static int fstyp_ident_one(struct fstyp_handle *h, const char *fsname,
91 static fstyp_module_t *fstyp_find_module_by_name(struct fstyp_handle *h,
93 static int fstyp_init_module(struct fstyp_handle *h,
95 static void fstyp_fini_module(struct fstyp_handle *h,
97 static int fstyp_init_all_modules(struct fstyp_handle *h);
98 static void fstyp_fini_all_modules(struct fstyp_handle *h);
99 static int fstyp_load_module(struct fstyp_handle *h,
101 static void fstyp_unload_module(struct fstyp_handle *h,
111 struct fstyp_handle *h; in fstyp_init() local
114 if ((h = calloc(1, sizeof (struct fstyp_handle))) == NULL) { in fstyp_init()
118 ((h->module_dir = strdup(module_dir)) == NULL)) { in fstyp_init()
119 free(h); in fstyp_init()
123 h->fd = fd; in fstyp_init()
124 h->offset = offset; in fstyp_init()
125 h->libfs_dir = (char *)default_libfs_dir; in fstyp_init()
127 if ((h->name_max = pathconf(h->libfs_dir, _PC_NAME_MAX)) < 0) { in fstyp_init()
128 h->name_max = MAXNAMELEN; in fstyp_init()
130 h->name_max++; in fstyp_init()
132 if (h->module_dir == NULL) { in fstyp_init()
133 error = fstyp_init_all_modules(h); in fstyp_init()
135 error = fstyp_init_module(h, h->module_dir, "", NULL); in fstyp_init()
138 fstyp_fini(h); in fstyp_init()
142 *handle = h; in fstyp_init()
147 fstyp_fini(struct fstyp_handle *h) in fstyp_fini() argument
149 if (h != NULL) { in fstyp_fini()
150 fstyp_fini_all_modules(h); in fstyp_fini()
151 if (h->module_dir != NULL) { in fstyp_fini()
152 free(h->module_dir); in fstyp_fini()
154 free(h); in fstyp_fini()
163 fstyp_ident(struct fstyp_handle *h, const char *fsname, const char **ident) in fstyp_ident() argument
166 return (fstyp_ident_all(h, ident)); in fstyp_ident()
168 return (fstyp_ident_one(h, fsname, ident)); in fstyp_ident()
176 fstyp_ident_all(struct fstyp_handle *h, const char **ident) in fstyp_ident_all() argument
180 if (h->ident != NULL) { in fstyp_ident_all()
181 *ident = &h->ident->fsname[0]; in fstyp_ident_all()
185 for (mp = h->modules; mp != NULL; mp = mp->next) { in fstyp_ident_all()
186 if ((fstyp_load_module(h, mp) == 0) && in fstyp_ident_all()
188 if (h->ident != NULL) { in fstyp_ident_all()
189 h->ident = NULL; in fstyp_ident_all()
193 h->ident = mp; in fstyp_ident_all()
206 fstyp_ident_one(struct fstyp_handle *h, const char *fsname, const char **ident) in fstyp_ident_one() argument
211 if (h->ident != NULL) { in fstyp_ident_one()
212 if (strcmp(h->ident->fsname, fsname) == 0) { in fstyp_ident_one()
223 if (h->module_dir == NULL) { in fstyp_ident_one()
224 mp = fstyp_find_module_by_name(h, fsname); in fstyp_ident_one()
226 mp = h->modules; in fstyp_ident_one()
232 if (((error = fstyp_load_module(h, mp)) == 0) && in fstyp_ident_one()
234 h->ident = mp; in fstyp_ident_one()
245 fstyp_get_attr(struct fstyp_handle *h, nvlist_t **attr) in fstyp_get_attr() argument
247 fstyp_module_t *mp = h->ident; in fstyp_get_attr()
260 fstyp_dump(struct fstyp_handle *h, FILE *fout, FILE *ferr) in fstyp_dump() argument
262 fstyp_module_t *mp = h->ident; in fstyp_dump()
277 fstyp_strerror(struct fstyp_handle *h, int error) in fstyp_strerror() argument
340 fstyp_find_module_by_name(struct fstyp_handle *h, const char *fsname) in fstyp_find_module_by_name() argument
344 for (mp = h->modules; mp != NULL; mp = mp->next) { in fstyp_find_module_by_name()
357 fstyp_init_module(struct fstyp_handle *h, char *mdir, char *fsname, in fstyp_init_module() argument
365 if ((mp = fstyp_find_module_by_name(h, fsname)) != NULL) { in fstyp_init_module()
373 if ((pathname = calloc(1, h->name_max)) == NULL) { in fstyp_init_module()
378 (void) snprintf(pathname, h->name_max, "%s/fstyp.so.%d", mdir, in fstyp_init_module()
393 if (h->modules_tail == NULL) { in fstyp_init_module()
394 h->modules = h->modules_tail = mp; in fstyp_init_module()
396 h->modules_tail->next = mp; in fstyp_init_module()
397 h->modules_tail = mp; in fstyp_init_module()
410 fstyp_fini_module(struct fstyp_handle *h, fstyp_module_t *mp) in fstyp_fini_module() argument
412 if (h->ident == mp) { in fstyp_fini_module()
413 h->ident = NULL; in fstyp_fini_module()
415 fstyp_unload_module(h, mp); in fstyp_fini_module()
426 fstyp_init_all_modules(struct fstyp_handle *h) in fstyp_init_all_modules() argument
432 if ((mdir = calloc(1, h->name_max)) == NULL) { in fstyp_init_all_modules()
435 dp = dp_mem = calloc(1, sizeof (struct dirent) + h->name_max + 1); in fstyp_init_all_modules()
439 if ((dirp = opendir(h->libfs_dir)) == NULL) { in fstyp_init_all_modules()
449 (void) snprintf(mdir, h->name_max, in fstyp_init_all_modules()
450 "%s/%s", h->libfs_dir, dp->d_name); in fstyp_init_all_modules()
451 (void) fstyp_init_module(h, mdir, dp->d_name, NULL); in fstyp_init_all_modules()
461 fstyp_fini_all_modules(struct fstyp_handle *h) in fstyp_fini_all_modules() argument
465 for (mp = h->modules; mp != NULL; mp = mp_next) { in fstyp_fini_all_modules()
467 fstyp_fini_module(h, mp); in fstyp_fini_all_modules()
469 h->modules = h->modules_tail = h->ident = NULL; in fstyp_fini_all_modules()
477 fstyp_load_module(struct fstyp_handle *h, fstyp_module_t *mp) in fstyp_load_module() argument
504 fstyp_unload_module(h, mp); in fstyp_load_module()
508 error = mp->ops.fstyp_init(h->fd, h->offset, &mp->mod_handle); in fstyp_load_module()
510 fstyp_unload_module(h, mp); in fstyp_load_module()
519 fstyp_unload_module(struct fstyp_handle *h, fstyp_module_t *mp) in fstyp_unload_module() argument