hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright 2018 Google LLC
 */
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/module.h>
 
#include <uapi/linux/incrementalfs.h>
 
#include "vfs.h"
 
#define INCFS_NODE_FEATURES "features"
 
static struct file_system_type incfs_fs_type = {
   .owner = THIS_MODULE,
   .name = INCFS_NAME,
   .mount = incfs_mount_fs,
   .kill_sb = incfs_kill_sb,
   .fs_flags = 0
};
 
static struct kobject *sysfs_root, *featurefs_root;
 
static ssize_t corefs_show(struct kobject *kobj,
             struct kobj_attribute *attr, char *buff)
{
   return snprintf(buff, PAGE_SIZE, "supported\n");
}
 
static struct kobj_attribute corefs_attr = __ATTR_RO(corefs);
 
static ssize_t mounter_context_for_backing_rw_show(struct kobject *kobj,
             struct kobj_attribute *attr, char *buff)
{
   return snprintf(buff, PAGE_SIZE, "supported\n");
}
 
static struct kobj_attribute mounter_context_for_backing_rw_attr =
   __ATTR_RO(mounter_context_for_backing_rw);
 
static struct attribute *attributes[] = {
   &corefs_attr.attr,
   &mounter_context_for_backing_rw_attr.attr,
   NULL,
};
 
static const struct attribute_group attr_group = {
   .attrs = attributes,
};
 
static int __init init_sysfs(void)
{
   int res = 0;
 
   sysfs_root = kobject_create_and_add(INCFS_NAME, fs_kobj);
   if (!sysfs_root)
       return -ENOMEM;
 
   featurefs_root = kobject_create_and_add(INCFS_NODE_FEATURES,
                       sysfs_root);
   if (!featurefs_root)
       return -ENOMEM;
 
   res = sysfs_create_group(featurefs_root, &attr_group);
   if (res) {
       kobject_put(sysfs_root);
       sysfs_root = NULL;
   }
   return res;
}
 
static void cleanup_sysfs(void)
{
   if (featurefs_root) {
       sysfs_remove_group(featurefs_root, &attr_group);
       kobject_put(featurefs_root);
       featurefs_root = NULL;
   }
 
   if (sysfs_root) {
       kobject_put(sysfs_root);
       sysfs_root = NULL;
   }
}
 
static int __init init_incfs_module(void)
{
   int err = 0;
 
   err = init_sysfs();
   if (err)
       return err;
 
   err = register_filesystem(&incfs_fs_type);
   if (err)
       cleanup_sysfs();
 
   return err;
}
 
static void __exit cleanup_incfs_module(void)
{
   cleanup_sysfs();
   unregister_filesystem(&incfs_fs_type);
}
 
module_init(init_incfs_module);
module_exit(cleanup_incfs_module);
 
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Eugene Zemtsov <ezemtsov@google.com>");
MODULE_DESCRIPTION("Incremental File System");