-
Notifications
You must be signed in to change notification settings - Fork 38
/
fs.c
96 lines (76 loc) · 1.89 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
// SPDX-License-Identifier: GPL-2.0
/*
* ouiche_fs - a simple educational filesystem for Linux
*
* Copyright (C) 2018 Redha Gouicem <redha.gouicem@lip6.fr>
*/
#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
#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\n", dev_name);
else
pr_info("'%s' mount success\n", dev_name);
return dentry;
}
/*
* Unmount a ouiche_fs partition
*/
void ouichefs_kill_sb(struct super_block *sb)
{
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 err;
}
ret = register_filesystem(&ouichefs_file_system_type);
if (ret) {
pr_err("register_filesystem() failed\n");
goto err_inode;
}
pr_info("module loaded\n");
return 0;
err_inode:
ouichefs_destroy_inode_cache();
err:
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();
pr_info("module unloaded\n");
}
module_init(ouichefs_init);
module_exit(ouichefs_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Redha Gouicem, <redha.gouicem@rwth-aachen.de>");
MODULE_DESCRIPTION("ouichefs, a simple educational filesystem for Linux");