-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.c
107 lines (84 loc) · 2.08 KB
/
fs.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
// SPDX-License-Identifier: GPL-2.0
/*
* ouiche_fs - a simple educational filesystem for Linux
*
* Copyright (C) 2018 Redha Gouicem <[email protected]>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include "ouichefs.h"
/*
* Mount a ouiche_fs partition
*/
struct dentry *ouichefs_mount(struct file_system_type *fs_type, int flags,
const char *dev_name, void *data)
{
struct dentry *dentry = NULL;
dentry = mount_bdev(fs_type, flags, dev_name, data,
ouichefs_fill_super);
if (IS_ERR(dentry))
pr_err("'%s' mount failure (err : %ld)\n", dev_name, IS_ERR_VALUE(dentry));
else
pr_info("'%s' mount success\n", dev_name);
return dentry;
}
/*
* Unmount a ouiche_fs partition
*/
void ouichefs_kill_sb(struct super_block *sb)
{
// do not dedup if there was an error on mount
if(!IS_ERR(sb->s_bdev))
dedup_umount(sb);
else
pr_info("No dedup\n");
kill_block_super(sb);
pr_info("unmounted disk\n");
}
static struct file_system_type ouichefs_file_system_type = {
.owner = THIS_MODULE,
.name = "ouichefs",
.mount = ouichefs_mount,
.kill_sb = ouichefs_kill_sb,
.fs_flags = FS_REQUIRES_DEV,
.next = NULL,
};
static int __init ouichefs_init(void)
{
int ret;
ret = ouichefs_init_inode_cache();
if (ret) {
pr_err("inode cache creation failed\n");
goto end;
}
ret = hash_init();
if (ret) {
pr_err("hash api initialization failed\n");
goto end;
}
ret = register_filesystem(&ouichefs_file_system_type);
if (ret) {
pr_err("register_filesystem() failed\n");
goto end;
}
pr_info("module loaded\n");
end:
return ret;
}
static void __exit ouichefs_exit(void)
{
int ret;
ret = unregister_filesystem(&ouichefs_file_system_type);
if (ret)
pr_err("unregister_filesystem() failed\n");
ouichefs_destroy_inode_cache();
hash_exit();
pr_info("module unloaded\n");
}
module_init(ouichefs_init);
module_exit(ouichefs_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Redha Gouicem, <[email protected]>");
MODULE_DESCRIPTION("ouichefs, a simple educational filesystem for Linux");