rc = mnt_context_merge_mflags(cxt);
if (!rc)
rc = evaluate_permissions(cxt);
- if (!rc)
- rc = mnt_context_init_hooksets(cxt);
if (!rc)
rc = fix_optstr(cxt);
if (!rc)
static int hook_prepare_target(struct libmnt_context *cxt, const struct libmnt_hookset *hs, void *data);
-static int hookset_init(struct libmnt_context *cxt, const struct libmnt_hookset *hs)
-{
- DBG(HOOK, ul_debugobj(hs, "init '%s'", hs->name));
-
- return mnt_context_append_hook(cxt, hs,
- MNT_STAGE_PREP_TARGET, NULL, hook_prepare_target);
-}
-
static int hookset_deinit(struct libmnt_context *cxt, const struct libmnt_hookset *hs)
{
void *data = NULL;
return 1;
}
-
static int hook_prepare_target(
struct libmnt_context *cxt,
const struct libmnt_hookset *hs,
return rc;
}
-
const struct libmnt_hookset hookset_mkdir =
{
.name = "__mkdir",
- .init = hookset_init,
+
+ .firststage = MNT_STAGE_PREP_TARGET,
+ .firstcall = hook_prepare_target,
+
.deinit = hookset_deinit
};
unsigned long mountflags;
};
-static int hookset_init(struct libmnt_context *cxt, const struct libmnt_hookset *hs)
-{
-#ifdef UL_HAVE_MOUNT_API
- /* do nothing when __builtin-mount succesfully registred */
- if (mnt_context_has_hook(cxt, &hookset_mount, 0, NULL))
- return 0;
-#endif
-
- DBG(HOOK, ul_debugobj(hs, "init '%s'", hs->name));
-
- /* add very basic callback */
- return mnt_context_append_hook(cxt, hs,
- MNT_STAGE_PREP_OPTIONS, NULL, hook_prepare);
-}
-
static int hookset_deinit(struct libmnt_context *cxt, const struct libmnt_hookset *hs)
{
void *data = NULL;
assert(cxt);
assert(hs == &hookset_mount_legacy);
+#ifdef UL_HAVE_MOUNT_API
+ /* do nothing when __builtin-mount succesfully registred */
+ if (mnt_context_has_hook(cxt, &hookset_mount, 0, NULL))
+ return 0;
+#endif
/* add extra mount(2) calls for each propagation flag */
if (cxt->mountflags & MS_PROPAGATION) {
rc = prepare_propagation(cxt, hs);
return rc;
}
-
const struct libmnt_hookset hookset_mount_legacy =
{
.name = "__legacy-mount",
- .init = hookset_init,
+
+ .firststage = MNT_STAGE_PREP_OPTIONS,
+ .firstcall = hook_prepare,
+
.deinit = hookset_deinit
};
return hsd;
}
-/* initiallize this module */
-static int hookset_init(struct libmnt_context *cxt, const struct libmnt_hookset *hs)
-{
- DBG(HOOK, ul_debugobj(hs, "init '%s'", hs->name));
-
- return mnt_context_append_hook(cxt, hs,
- MNT_STAGE_PREP_TARGET, NULL, hook_prepare_target);
-}
-
/* de-initiallize this module */
static int hookset_deinit(struct libmnt_context *cxt, const struct libmnt_hookset *hs)
{
return rc;
}
-
const struct libmnt_hookset hookset_subdir =
{
.name = "__subdir",
- .init = hookset_init,
+
+ .firststage = MNT_STAGE_PREP_TARGET,
+ .firstcall = hook_prepare_target,
+
.deinit = hookset_deinit
};
[MNT_STAGE_POST] = "post",
};
-int mnt_context_init_hooksets(struct libmnt_context *cxt)
-{
- size_t i;
- int rc = 0;
-
- assert(cxt);
-
- for (i = 0; i < ARRAY_SIZE(hooksets); i++) {
- const struct libmnt_hookset *hs = hooksets[i];
-
- rc = hs->init(cxt, hs);
- if (rc < 0)
- break;
- }
-
- if (rc < 0)
- mnt_context_deinit_hooksets(cxt);
- return rc;
-}
-
int mnt_context_deinit_hooksets(struct libmnt_context *cxt)
{
size_t i;
int mnt_context_call_hooks(struct libmnt_context *cxt, int stage)
{
struct list_head *p, *next;
+ size_t i;
+
+ /* call initial hooks */
+ for (i = 0; i < ARRAY_SIZE(hooksets); i++) {
+ int rc;
+ const struct libmnt_hookset *hs = hooksets[i];
+
+ if (hs->firststage != stage)
+ continue;
+
+ DBG(CXT, ul_debugobj(cxt, "calling %s hook from %s",
+ stagenames[hs->firststage], hs->name));
+
+ rc = hs->firstcall(cxt, hs, NULL);
+ if (rc < 0)
+ return rc;
+ }
+ /* call already active hooks */
list_for_each_safe(p, next, &cxt->hooksets_hooks) {
int rc;
struct hookset_hook *x = list_entry(p, struct hookset_hook, hooks);
struct libmnt_hookset {
const char *name; /* hook set name */
- int (*init)(struct libmnt_context *, const struct libmnt_hookset *); /* initialization function */
+
+ int firststage;
+ int (*firstcall)(struct libmnt_context *, const struct libmnt_hookset *, void *);
+
int (*deinit)(struct libmnt_context *, const struct libmnt_hookset *); /* cleanup function */
};
extern const struct libmnt_hookset hookset_mkdir;
extern const struct libmnt_hookset hookset_subdir;
-
-extern int mnt_context_init_hooksets(struct libmnt_context *cxt);
extern int mnt_context_deinit_hooksets(struct libmnt_context *cxt);
extern const struct libmnt_hookset *mnt_context_get_hookset(struct libmnt_context *cxt, const char *name);