代码拉取完成,页面将自动刷新
From 133b4a5c330369c1401559129e3e6ca396542759 Mon Sep 17 00:00:00 2001
From: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
Date: Mon, 30 Dec 2024 11:41:03 +0000
Subject: [PATCH] myminix
Signed-off-by: ChenXiaoSong <chenxiaosong@chenxiaosong.com>
---
Makefile | 14 ++++++++--
dir.c | 2 ++
file.c | 2 ++
inode.c | 38 +++++----------------------
itree_common.c | 70 +++++++++++++++++++++++++-------------------------
itree_v1.c | 2 ++
itree_v2.c | 2 ++
minix.h | 23 ++++++++++++++++-
8 files changed, 84 insertions(+), 69 deletions(-)
diff --git a/Makefile b/Makefile
index a2d3ab5..1b45e25 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,16 @@
# Makefile for the Linux minix filesystem routines.
#
-obj-$(CONFIG_MINIX_FS) += minix.o
+obj-m += myminix.o
+
+myminix-objs := main.o bitmap.o itree_v1.o itree_v2.o namei.o inode.o file.o dir.o
+
+KDIR := /root/code/linux/x86_64-build/
+PWD := $(shell pwd)
+
+all:
+ $(MAKE) -C $(KDIR) M=$(PWD) modules
+
+clean:
+ $(MAKE) -C $(KDIR) M=$(PWD) clean
-minix-objs := bitmap.o itree_v1.o itree_v2.o namei.o inode.o file.o dir.o
diff --git a/dir.c b/dir.c
index dd2a425..daee459 100644
--- a/dir.c
+++ b/dir.c
@@ -14,6 +14,8 @@
#include <linux/highmem.h>
#include <linux/swap.h>
+#define DBG_FACILITY MINIX_DEBUG_DIR
+
typedef struct minix_dir_entry minix_dirent;
typedef struct minix3_dir_entry minix3_dirent;
diff --git a/file.c b/file.c
index 906d192..e687371 100644
--- a/file.c
+++ b/file.c
@@ -9,6 +9,8 @@
#include "minix.h"
+#define DBG_FACILITY MINIX_DEBUG_FILE
+
/*
* We have mostly NULLs here: the current defaults are OK for
* the minix filesystem.
diff --git a/inode.c b/inode.c
index f007e38..aeaba0b 100644
--- a/inode.c
+++ b/inode.c
@@ -22,6 +22,8 @@
#include <linux/writeback.h>
#include <linux/fs_context.h>
+#define DBG_FACILITY MINIX_DEBUG_INODE
+
static int minix_write_inode(struct inode *inode,
struct writeback_control *wbc);
static int minix_statfs(struct dentry *dentry, struct kstatfs *buf);
@@ -82,7 +84,7 @@ static void init_once(void *foo)
inode_init_once(&ei->vfs_inode);
}
-static int __init init_inodecache(void)
+int __init minix_init_inodecache(void)
{
minix_inode_cachep = kmem_cache_create("minix_inode_cache",
sizeof(struct minix_inode_info),
@@ -94,7 +96,7 @@ static int __init init_inodecache(void)
return 0;
}
-static void destroy_inodecache(void)
+void minix_destroy_inodecache(void)
{
/*
* Make sure all delayed rcu free inodes are flushed before we
@@ -698,38 +700,12 @@ void minix_truncate(struct inode * inode)
V2_minix_truncate(inode);
}
-static struct file_system_type minix_fs_type = {
+struct file_system_type minix_fs_type = {
.owner = THIS_MODULE,
- .name = "minix",
+ .name = "myminix",
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
.init_fs_context = minix_init_fs_context,
};
-MODULE_ALIAS_FS("minix");
-
-static int __init init_minix_fs(void)
-{
- int err = init_inodecache();
- if (err)
- goto out1;
- err = register_filesystem(&minix_fs_type);
- if (err)
- goto out;
- return 0;
-out:
- destroy_inodecache();
-out1:
- return err;
-}
-
-static void __exit exit_minix_fs(void)
-{
- unregister_filesystem(&minix_fs_type);
- destroy_inodecache();
-}
-
-module_init(init_minix_fs)
-module_exit(exit_minix_fs)
-MODULE_DESCRIPTION("Minix file system");
-MODULE_LICENSE("GPL");
+MODULE_ALIAS_FS("myminix");
diff --git a/itree_common.c b/itree_common.c
index dad131e..4f28ad1 100644
--- a/itree_common.c
+++ b/itree_common.c
@@ -2,22 +2,22 @@
/* Generic part */
typedef struct {
- block_t *p;
- block_t key;
- struct buffer_head *bh;
+ block_t *ind_key_p;
+ block_t ind_key;
+ struct buffer_head *ind_bh;
} Indirect;
static DEFINE_RWLOCK(pointers_lock);
static inline void add_chain(Indirect *p, struct buffer_head *bh, block_t *v)
{
- p->key = *(p->p = v);
- p->bh = bh;
+ p->ind_key = *(p->ind_key_p = v);
+ p->ind_bh = bh;
}
static inline int verify_chain(Indirect *from, Indirect *to)
{
- while (from <= to && from->key == *from->p)
+ while (from <= to && from->ind_key == *from->ind_key_p)
from++;
return (from > to);
}
@@ -40,10 +40,10 @@ static inline Indirect *get_branch(struct inode *inode,
*err = 0;
/* i_data is not going away, no lock needed */
add_chain (chain, NULL, i_data(inode) + *offsets);
- if (!p->key)
+ if (!p->ind_key)
goto no_block;
while (--depth) {
- bh = sb_bread(sb, block_to_cpu(p->key));
+ bh = sb_bread(sb, block_to_cpu(p->ind_key));
if (!bh)
goto failure;
read_lock(&pointers_lock);
@@ -51,7 +51,7 @@ static inline Indirect *get_branch(struct inode *inode,
goto changed;
add_chain(++p, bh, (block_t *)bh->b_data + *++offsets);
read_unlock(&pointers_lock);
- if (!p->key)
+ if (!p->ind_key)
goto no_block;
}
return NULL;
@@ -77,14 +77,14 @@ static int alloc_branch(struct inode *inode,
int parent = minix_new_block(inode);
int err = -ENOSPC;
- branch[0].key = cpu_to_block(parent);
+ branch[0].ind_key = cpu_to_block(parent);
if (parent) for (n = 1; n < num; n++) {
struct buffer_head *bh;
/* Allocate the next block */
int nr = minix_new_block(inode);
if (!nr)
break;
- branch[n].key = cpu_to_block(nr);
+ branch[n].ind_key = cpu_to_block(nr);
bh = sb_getblk(inode->i_sb, parent);
if (!bh) {
minix_free_block(inode, nr);
@@ -93,9 +93,9 @@ static int alloc_branch(struct inode *inode,
}
lock_buffer(bh);
memset(bh->b_data, 0, bh->b_size);
- branch[n].bh = bh;
- branch[n].p = (block_t*) bh->b_data + offsets[n];
- *branch[n].p = branch[n].key;
+ branch[n].ind_bh = bh;
+ branch[n].ind_key_p = (block_t*) bh->b_data + offsets[n];
+ *branch[n].ind_key_p = branch[n].ind_key;
set_buffer_uptodate(bh);
unlock_buffer(bh);
mark_buffer_dirty_inode(bh, inode);
@@ -106,9 +106,9 @@ static int alloc_branch(struct inode *inode,
/* Allocation failed, free what we already allocated */
for (i = 1; i < n; i++)
- bforget(branch[i].bh);
+ bforget(branch[i].ind_bh);
for (i = 0; i < n; i++)
- minix_free_block(inode, block_to_cpu(branch[i].key));
+ minix_free_block(inode, block_to_cpu(branch[i].ind_key));
return err;
}
@@ -122,10 +122,10 @@ static inline int splice_branch(struct inode *inode,
write_lock(&pointers_lock);
/* Verify that place we are splicing to is still there and vacant */
- if (!verify_chain(chain, where-1) || *where->p)
+ if (!verify_chain(chain, where-1) || *where->ind_key_p)
goto changed;
- *where->p = where->key;
+ *where->ind_key_p = where->ind_key;
write_unlock(&pointers_lock);
@@ -134,8 +134,8 @@ static inline int splice_branch(struct inode *inode,
inode_set_ctime_current(inode);
/* had we spliced it onto indirect block? */
- if (where->bh)
- mark_buffer_dirty_inode(where->bh, inode);
+ if (where->ind_bh)
+ mark_buffer_dirty_inode(where->ind_bh, inode);
mark_inode_dirty(inode);
return 0;
@@ -143,9 +143,9 @@ static inline int splice_branch(struct inode *inode,
changed:
write_unlock(&pointers_lock);
for (i = 1; i < num; i++)
- bforget(where[i].bh);
+ bforget(where[i].ind_bh);
for (i = 0; i < num; i++)
- minix_free_block(inode, block_to_cpu(where[i].key));
+ minix_free_block(inode, block_to_cpu(where[i].ind_key));
return -EAGAIN;
}
@@ -168,7 +168,7 @@ reread:
/* Simplest case - block found, no allocation needed */
if (!partial) {
got_it:
- map_bh(bh, inode->i_sb, block_to_cpu(chain[depth-1].key));
+ map_bh(bh, inode->i_sb, block_to_cpu(chain[depth-1].ind_key));
/* Clean up and exit */
partial = chain+depth-1; /* the whole chain */
goto cleanup;
@@ -178,7 +178,7 @@ got_it:
if (!create || err == -EIO) {
cleanup:
while (partial > chain) {
- brelse(partial->bh);
+ brelse(partial->ind_bh);
partial--;
}
out:
@@ -206,7 +206,7 @@ out:
changed:
while (partial > chain) {
- brelse(partial->bh);
+ brelse(partial->ind_bh);
partial--;
}
goto reread;
@@ -237,23 +237,23 @@ static Indirect *find_shared(struct inode *inode,
write_lock(&pointers_lock);
if (!partial)
partial = chain + k-1;
- if (!partial->key && *partial->p) {
+ if (!partial->ind_key && *partial->ind_key_p) {
write_unlock(&pointers_lock);
goto no_top;
}
- for (p=partial;p>chain && all_zeroes((block_t*)p->bh->b_data,p->p);p--)
+ for (p=partial;p>chain && all_zeroes((block_t*)p->ind_bh->b_data,p->ind_key_p);p--)
;
if (p == chain + k - 1 && p > chain) {
- p->p--;
+ p->ind_key_p--;
} else {
- *top = *p->p;
- *p->p = 0;
+ *top = *p->ind_key_p;
+ *p->ind_key_p = 0;
}
write_unlock(&pointers_lock);
while(partial > p)
{
- brelse(partial->bh);
+ brelse(partial->ind_bh);
partial--;
}
no_top:
@@ -328,15 +328,15 @@ static inline void truncate (struct inode * inode)
if (partial == chain)
mark_inode_dirty(inode);
else
- mark_buffer_dirty_inode(partial->bh, inode);
+ mark_buffer_dirty_inode(partial->ind_bh, inode);
free_branches(inode, &nr, &nr+1, (chain+n-1) - partial);
}
/* Clear the ends of indirect blocks on the shared branch */
while (partial > chain) {
- free_branches(inode, partial->p + 1, block_end(partial->bh),
+ free_branches(inode, partial->ind_key_p + 1, block_end(partial->ind_bh),
(chain+n-1) - partial);
- mark_buffer_dirty_inode(partial->bh, inode);
- brelse (partial->bh);
+ mark_buffer_dirty_inode(partial->ind_bh, inode);
+ brelse (partial->ind_bh);
partial--;
}
do_indirects:
diff --git a/itree_v1.c b/itree_v1.c
index 1fed906..fdd1033 100644
--- a/itree_v1.c
+++ b/itree_v1.c
@@ -3,6 +3,8 @@
#include <linux/slab.h>
#include "minix.h"
+#define DBG_FACILITY MINIX_DEBUG_ITREE
+
enum {DEPTH = 3, DIRECT = 7}; /* Only double indirect */
typedef u16 block_t; /* 16 bit, host order */
diff --git a/itree_v2.c b/itree_v2.c
index 9d00f31..223d119 100644
--- a/itree_v2.c
+++ b/itree_v2.c
@@ -2,6 +2,8 @@
#include <linux/buffer_head.h>
#include "minix.h"
+#define DBG_FACILITY MINIX_DEBUG_ITREE
+
enum {DIRECT = 7, DEPTH = 4}; /* Have triple indirect */
typedef u32 block_t; /* 32 bit, host order */
diff --git a/minix.h b/minix.h
index d54273c..1240382 100644
--- a/minix.h
+++ b/minix.h
@@ -4,7 +4,24 @@
#include <linux/fs.h>
#include <linux/pagemap.h>
-#include <linux/minix_fs.h>
+#include "minix_fs.h"
+
+extern int minix_debug_types;
+
+#define MINIX_DEBUG_MAIN BIT(0)
+#define MINIX_DEBUG_ITREE BIT(1)
+#define MINIX_DEBUG_INODE BIT(2)
+#define MINIX_DEBUG_FILE BIT(3)
+#define MINIX_DEBUG_DIR BIT(4)
+#define MINIX_DEBUG_ALL (MINIX_DEBUG_MAIN | MINIX_DEBUG_ITREE | \
+ MINIX_DEBUG_INODE | MINIX_DEBUG_FILE | \
+ MINIX_DEBUG_DIR)
+
+#define minix_debug(type, fmt, ...) \
+ do { \
+ if (minix_debug_types & type) \
+ pr_info("[%s:%d] " fmt, __func__, __LINE__, ##__VA_ARGS__); \
+ } while (0)
#define INODE_VERSION(inode) minix_sb(inode->i_sb)->s_version
#define MINIX_V1 0x0001 /* original minix fs */
@@ -94,6 +111,10 @@ static inline unsigned minix_blocks_needed(unsigned bits, unsigned blocksize)
return DIV_ROUND_UP(bits, blocksize * 8);
}
+extern struct file_system_type minix_fs_type;
+extern int __init minix_init_inodecache(void);
+extern void minix_destroy_inodecache(void);
+
#if defined(CONFIG_MINIX_FS_NATIVE_ENDIAN) && \
defined(CONFIG_MINIX_FS_BIG_ENDIAN_16BIT_INDEXED)
--
2.34.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。