up_write(&task->mm->mmap_sem);
}
+struct dentry *dentry_get(const char *path)
+{
+ struct dentry *d;
+ struct path st_path;
+
+ if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) {
+ pr_err("failed to lookup dentry for path %s!\n", path);
+ return NULL;
+ }
+
+ d = st_path.dentry;
+ dget(d);
+ path_put(&st_path);
+
+ return d;
+}
+EXPORT_SYMBOL_GPL(dentry_get);
+
+void dentry_put(struct dentry *d)
+{
+ dput(d);
+}
+EXPORT_SYMBOL_GPL(dentry_put);
+
+
/**
* @brief Get dentry struct by path
*
*/
struct dentry *dentry_by_path(const char *path)
{
- struct dentry *dentry;
-#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
- struct path st_path;
- if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) {
-#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
- struct nameidata nd;
- if (path_lookup(path, LOOKUP_FOLLOW, &nd) != 0) {
-#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
- printk("failed to lookup dentry for path %s!\n", path);
- return NULL;
- }
+ struct dentry *d;
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
- dentry = nd.dentry;
- path_release(&nd);
-#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38)
- dentry = nd.path.dentry;
- path_put(&nd.path);
-#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
- dentry = st_path.dentry;
- path_put(&st_path);
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */
- return dentry;
+ d = dentry_get(path);
+ if (d)
+ dput(d);
+
+ return d;
}
EXPORT_SYMBOL_GPL(dentry_by_path);
/* FIXME: create and use get_dentry() and put_dentry() */
struct dentry *dentry_by_path(const char *path);
+struct dentry *dentry_get(const char *path);
+void dentry_put(struct dentry *d);
struct pf_group *get_pf_group_by_dentry(struct dentry *dentry, void *priv);
struct pf_group *get_pf_group_by_tgid(pid_t tgid, void *priv);