-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathfs.c
More file actions
137 lines (119 loc) · 3.39 KB
/
Copy pathfs.c
File metadata and controls
137 lines (119 loc) · 3.39 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include "simplefs.h"
#if SIMPLEFS_AT_LEAST(6, 18, 0)
#include <linux/fs_context.h>
#include <linux/fs_parser.h>
#endif
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#if SIMPLEFS_AT_LEAST(6, 18, 0)
static int simplefs_get_tree(struct fs_context *fc)
{
return get_tree_bdev(fc, simplefs_fill_super);
}
static void simplefs_free_context(struct fs_context *fc)
{
struct simplefs_fs_context *ctx = fc->fs_private;
if (!ctx)
return;
kfree(ctx->journal_path);
kfree(ctx);
}
static const struct fs_context_operations simplefs_context_ops = {
.get_tree = simplefs_get_tree,
.parse_param = simplefs_parse_param,
.free = simplefs_free_context,
};
static int init_simplefs_context(struct fs_context *fc)
{
struct simplefs_fs_context *ctx;
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
if (!ctx)
return -ENOMEM;
fc->fs_private = ctx;
fc->ops = &simplefs_context_ops;
return 0;
}
extern const struct fs_parameter_spec simplefs_param_specs;
#else
/* Mount a simplefs partition */
struct dentry *simplefs_mount(struct file_system_type *fs_type,
int flags,
const char *dev_name,
void *data)
{
struct dentry *dentry =
mount_bdev(fs_type, flags, dev_name, data, simplefs_fill_super);
if (IS_ERR(dentry))
pr_err("'%s' mount failure\n", dev_name);
else
pr_info("'%s' mount success\n", dev_name);
return dentry;
}
#endif
/* Unmount a simplefs partition */
void simplefs_kill_sb(struct super_block *sb)
{
struct simplefs_sb_info *sbi = SIMPLEFS_SB(sb);
#if SIMPLEFS_AT_LEAST(6, 9, 0)
if (sbi->s_journal_bdev_file)
fput(sbi->s_journal_bdev_file);
#elif SIMPLEFS_AT_LEAST(6, 7, 0)
if (sbi->s_journal_bdev_handle)
bdev_release(sbi->s_journal_bdev_handle);
#endif
kill_block_super(sb);
pr_info("unmounted disk\n");
}
static struct file_system_type simplefs_file_system_type = {
.owner = THIS_MODULE,
.name = "simplefs",
#if SIMPLEFS_AT_LEAST(6, 18, 0)
.init_fs_context = init_simplefs_context,
.parameters = &simplefs_param_specs,
#else
.mount = simplefs_mount,
#endif
.kill_sb = simplefs_kill_sb,
.fs_flags = FS_REQUIRES_DEV,
#if SIMPLEFS_LESS_EQUAL(7, 1, 0)
.next = NULL,
#endif
};
static int __init simplefs_init(void)
{
int ret = simplefs_init_inode_cache();
if (ret) {
pr_err("Failed to create inode cache\n");
goto err;
}
ret = register_filesystem(&simplefs_file_system_type);
if (ret) {
pr_err("Failed to register file system\n");
goto err_inode;
}
pr_info("module loaded\n");
return 0;
err_inode:
simplefs_destroy_inode_cache();
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
rcu_barrier();
err:
return ret;
}
static void __exit simplefs_exit(void)
{
int ret = unregister_filesystem(&simplefs_file_system_type);
if (ret)
pr_err("Failed to unregister file system\n");
simplefs_destroy_inode_cache();
/* Only after rcu_barrier() is the memory guaranteed to be freed. */
rcu_barrier();
pr_info("module unloaded\n");
}
module_init(simplefs_init);
module_exit(simplefs_exit);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("National Cheng Kung University, Taiwan");
MODULE_DESCRIPTION("a simple file system");