-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfs_mod.c
117 lines (93 loc) · 1.98 KB
/
mfs_mod.c
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
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include "mfs_super.h"
#include "mfs_client.h"
/**
* -------------------------------------
* File system kernel module
* -------------------------------------
*/
/**
* This describes the filesystem (1 per filesystem shared amoung all mount)
*/
/**
* Called by vfs when mount syscall has been raised
*/
static struct dentry *mfs_mod_mount(struct file_system_type *fst, int flags,
const char *dev_name, void *data)
{
struct mfs_client *clt;
struct super_block *sb = NULL;
int err;
clt = kzalloc(sizeof(*clt), GFP_KERNEL);
if(clt == NULL) {
err = -ENOMEM;
goto error;
}
sb = sget(fst, NULL, mfs_super_set, flags, clt);
if(IS_ERR(sb)) {
err = PTR_ERR(sb);
goto free_client;
}
err = mfs_super_fill(sb, flags, data);
if(err != 0)
goto release_sb;
mfs_client_set_sb(clt, sb);
err = mfs_client_init_session(clt, dev_name, data);
if(err != 0)
goto release_sb;
/**
* Get reference to superblock
*/
return dget(sb->s_root);
release_sb:
deactivate_locked_super(sb);
return ERR_PTR(err);
free_client:
kfree(clt);
error:
return ERR_PTR(err);
}
/**
* Called by vfs to kill super block (umount)
*/
static void mfs_mod_kill_super(struct super_block *s)
{
struct mfs_client *clt = (struct mfs_client *)s->s_fs_info;
kill_litter_super(s);
mfs_client_close_session(clt);
kfree(clt);
}
static struct file_system_type mfstype = {
.owner = THIS_MODULE,
.name = "mfs",
.mount = mfs_mod_mount,
.kill_sb = mfs_mod_kill_super,
};
/**
* Typical kernel module functions
*/
/**
* MODULE_ALIAS for module autoloading
*/
MODULE_ALIAS_FS("mfs");
/**
* Module initialization
*/
static int __init mfs_mod_init(void)
{
return register_filesystem(&mfstype);
}
/**
* Module Exit
*/
static void __exit mfs_mod_exit(void)
{
unregister_filesystem(&mfstype);
}
module_init(mfs_mod_init);
module_exit(mfs_mod_exit);
MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Remi Pommarel");