StupidFS/linux/module.c

91 lines
1.5 KiB
C
Raw Normal View History

2024-05-21 08:56:19 +00:00
/**
* \addtogroup driver
* @{
*/
2024-07-21 09:32:17 +00:00
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/fs.h>
#include <linux/kernel.h>
2024-05-21 08:56:19 +00:00
#include <linux/module.h>
2024-07-21 09:32:17 +00:00
#include "module.h"
2024-05-21 08:56:19 +00:00
/**
* \defgroup linux Linux Kernel Module
* @{
*/
2024-07-21 09:32:17 +00:00
struct dentry *
stpdfs_mount(struct file_system_type *fs_type, int flags,
const char *devname, void *data)
{
struct dentry *dentry;
dentry = mount_bdev(fs_type, flags, devname, data, stpdfs_fill_super);
if (IS_ERR(dentry))
{
pr_err("'%s' mount failure\n", devname);
}
else
{
pr_info("'%s' mount success\n", devname);
}
return (dentry);
}
void
stpdfs_kill_sb(struct super_block *sb)
{
(void)sb;
}
static struct file_system_type stpdfs_file_system_type = {
.owner = THIS_MODULE,
.name = "stupidfs",
.mount = stpdfs_mount,
.kill_sb = stpdfs_kill_sb,
.fs_flags = FS_REQUIRES_DEV,
.next = NULL,
};
2024-05-21 08:56:19 +00:00
static int __init
stpdfs_mod_init(void)
{
2024-07-21 09:32:17 +00:00
int ret;
ret = register_filesystem(&stpdfs_file_system_type);
if (ret != 0)
{
pr_err("Failed to register filesystem\n");
goto err;
}
pr_info("module loaded\n");
return (0);
err:
return (ret);
2024-05-21 08:56:19 +00:00
}
module_init(stpdfs_mod_init);
static void __exit
stpdfs_mod_exit(void)
{
2024-07-21 09:32:17 +00:00
if (unregister_filesystem(&stpdfs_file_system_type) != 0)
{
pr_err("Failed to unregister filesystem\n");
}
pr_info("module unloaded\n");
2024-05-21 08:56:19 +00:00
}
module_exit(stpdfs_mod_exit);
MODULE_LICENSE("CECILL-B or BSD3");
MODULE_AUTHOR("d0p1");
MODULE_DESCRIPTION("Stupid File System");
MODULE_VERSION("1.0");
2024-04-15 09:07:21 +00:00
/** @} @} */