kernel: pkg_observer: fix pre-4.12 kernel compilation issue (#182)
* Linux 4.12+ void fsnotify_init_mark(struct fsnotify_mark *mark, struct fsnotify_group *group) * Linux <4.12 void fsnotify_init_mark(struct fsnotify_mark *mark, void (*free_mark)(struct fsnotify_mark *mark)) Tested-by: koyufox <koyufox@gmail.com> Signed-off-by: Faris <rissu.ntk@gmail.com>
This commit is contained in:
@@ -46,57 +46,58 @@ static int ksu_handle_inode_event(struct fsnotify_mark *mark, u32 mask,
|
|||||||
#else
|
#else
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
|
||||||
static int ksu_handle_event(struct fsnotify_group *group,
|
static int ksu_handle_event(struct fsnotify_group *group,
|
||||||
struct inode *inode, u32 mask, const void *data, int data_type,
|
struct inode *inode, u32 mask, const void *data, int data_type,
|
||||||
const struct qstr *file_name, u32 cookie,
|
const struct qstr *file_name, u32 cookie,
|
||||||
struct fsnotify_iter_info *iter_info)
|
struct fsnotify_iter_info *iter_info)
|
||||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
|
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
|
||||||
static int ksu_handle_event(struct fsnotify_group *group,
|
static int ksu_handle_event(struct fsnotify_group *group,
|
||||||
struct inode *inode, u32 mask, const void *data, int data_type,
|
struct inode *inode, u32 mask, const void *data, int data_type,
|
||||||
const unsigned char *file_name, u32 cookie,
|
const unsigned char *file_name, u32 cookie,
|
||||||
struct fsnotify_iter_info *iter_info)
|
struct fsnotify_iter_info *iter_info)
|
||||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
||||||
static int ksu_handle_event(struct fsnotify_group *group,
|
static int ksu_handle_event(struct fsnotify_group *group,
|
||||||
struct inode *inode, struct fsnotify_mark *inode_mark,
|
struct inode *inode, struct fsnotify_mark *inode_mark,
|
||||||
struct fsnotify_mark *vfsmount_mark,
|
struct fsnotify_mark *vfsmount_mark,
|
||||||
u32 mask, const void *data, int data_type,
|
u32 mask, const void *data, int data_type,
|
||||||
const unsigned char *file_name, u32 cookie,
|
const unsigned char *file_name, u32 cookie,
|
||||||
struct fsnotify_iter_info *iter_info)
|
struct fsnotify_iter_info *iter_info)
|
||||||
#else
|
#else
|
||||||
static int ksu_handle_event(struct fsnotify_group *group,
|
static int ksu_handle_event(struct fsnotify_group *group,
|
||||||
struct inode *inode,
|
struct inode *inode,
|
||||||
struct fsnotify_mark *inode_mark,
|
struct fsnotify_mark *inode_mark,
|
||||||
struct fsnotify_mark *vfsmount_mark,
|
struct fsnotify_mark *vfsmount_mark,
|
||||||
u32 mask, void *data, int data_type,
|
u32 mask, void *data, int data_type,
|
||||||
const unsigned char *file_name, u32 cookie)
|
const unsigned char *file_name, u32 cookie)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (!file_name)
|
if (!file_name)
|
||||||
return 0;
|
return 0;
|
||||||
if (mask & FS_ISDIR)
|
if (mask & FS_ISDIR)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 2, 0)
|
||||||
if (file_name->len == 13 &&
|
if (file_name->len == 13 &&
|
||||||
!memcmp(file_name->name, "packages.list", 13)) {
|
!memcmp(file_name->name, "packages.list", 13)) {
|
||||||
#else
|
#else
|
||||||
if (strlen(file_name) == 13 &&
|
if (strlen(file_name) == 13 &&
|
||||||
!memcmp(file_name, "packages.list", 13)) {
|
!memcmp(file_name, "packages.list", 13)) {
|
||||||
#endif
|
#endif
|
||||||
pr_info("packages.list detected: %d\n", mask);
|
pr_info("packages.list detected: %d\n", mask);
|
||||||
track_throne();
|
track_throne();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const struct fsnotify_ops ksu_ops = {
|
static const struct fsnotify_ops ksu_ops = {
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0)
|
||||||
.handle_inode_event = ksu_handle_inode_event,
|
.handle_inode_event = ksu_handle_inode_event,
|
||||||
#else
|
#else
|
||||||
.handle_event = ksu_handle_event,
|
.handle_event = ksu_handle_event,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
||||||
static int add_mark_on_inode(struct inode *inode, u32 mask,
|
static int add_mark_on_inode(struct inode *inode, u32 mask,
|
||||||
struct fsnotify_mark **out)
|
struct fsnotify_mark **out)
|
||||||
{
|
{
|
||||||
@@ -109,24 +110,43 @@ static int add_mark_on_inode(struct inode *inode, u32 mask,
|
|||||||
fsnotify_init_mark(m, g);
|
fsnotify_init_mark(m, g);
|
||||||
m->mask = mask;
|
m->mask = mask;
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
|
if (fsnotify_add_inode_mark(m, inode, 0)) {
|
||||||
if (fsnotify_add_inode_mark(m, inode, 0)) {
|
fsnotify_put_mark(m);
|
||||||
fsnotify_put_mark(m);
|
return -EINVAL;
|
||||||
return -EINVAL;
|
}
|
||||||
}
|
|
||||||
#else /* TODO: Need more tests on k4.4 and k4.9! */
|
|
||||||
mutex_lock(&g->mark_mutex);
|
|
||||||
if (fsnotify_add_inode_mark(m, g, inode, 0)) {
|
|
||||||
fsnotify_put_mark(m);
|
|
||||||
mutex_unlock(&g->mark_mutex);
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
mutex_unlock(&g->mark_mutex);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*out = m;
|
*out = m;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static void ksu_free_mark(struct fsnotify_mark *ksu_mark)
|
||||||
|
{
|
||||||
|
if (ksu_mark)
|
||||||
|
kfree(ksu_mark);
|
||||||
|
}
|
||||||
|
static int add_mark_on_inode(struct inode *inode, u32 mask,
|
||||||
|
struct fsnotify_mark **out)
|
||||||
|
{
|
||||||
|
struct fsnotify_mark *ksu_mark;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ksu_mark = kzalloc(sizeof(*ksu_mark), GFP_KERNEL);
|
||||||
|
if (!ksu_mark)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
fsnotify_init_mark(ksu_mark, ksu_free_mark);
|
||||||
|
ksu_mark->mask = mask;
|
||||||
|
|
||||||
|
ret = fsnotify_add_mark(ksu_mark, g, inode, NULL, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
fsnotify_put_mark(ksu_mark);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = ksu_mark;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* LINUX_VERSION_CODE >= 4.12 */
|
||||||
|
|
||||||
static int watch_one_dir(struct watch_dir *wd)
|
static int watch_one_dir(struct watch_dir *wd)
|
||||||
{
|
{
|
||||||
@@ -167,8 +187,10 @@ static void unwatch_one_dir(struct watch_dir *wd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct watch_dir g_watch = { .path = "/data/system",
|
static struct watch_dir g_watch = {
|
||||||
.mask = MASK_SYSTEM };
|
.path = "/data/system",
|
||||||
|
.mask = MASK_SYSTEM
|
||||||
|
};
|
||||||
|
|
||||||
int ksu_observer_init(void)
|
int ksu_observer_init(void)
|
||||||
{
|
{
|
||||||
@@ -183,7 +205,7 @@ int ksu_observer_init(void)
|
|||||||
return PTR_ERR(g);
|
return PTR_ERR(g);
|
||||||
|
|
||||||
ret = watch_one_dir(&g_watch);
|
ret = watch_one_dir(&g_watch);
|
||||||
pr_info("observer init done\n");
|
pr_info("%s done.\n", __func__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,5 +213,5 @@ void ksu_observer_exit(void)
|
|||||||
{
|
{
|
||||||
unwatch_one_dir(&g_watch);
|
unwatch_one_dir(&g_watch);
|
||||||
fsnotify_put_group(g);
|
fsnotify_put_group(g);
|
||||||
pr_info("observer exit done\n");
|
pr_info("%s: done.\n", __func__);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user