8
This commit is contained in:
parent
c6777ba8c8
commit
dd2f60baea
14
libfs.c
14
libfs.c
@ -33,6 +33,8 @@ MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("you");
|
||||
MODULE_DESCRIPTION("Custom FS with books/authors behavior");
|
||||
|
||||
static int custom_unlink(struct inode *dir, struct dentry *dentry);
|
||||
|
||||
static struct super_block *global_sb;
|
||||
static struct inode *books_inode;
|
||||
static const struct inode_operations fs_dir_iops;
|
||||
@ -108,6 +110,7 @@ static struct inode *get_inode(struct super_block *sb, umode_t mode) {
|
||||
inode->i_ino = get_next_ino();
|
||||
inode->i_sb = sb;
|
||||
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
||||
inode->i_mode = mode;
|
||||
return inode;
|
||||
}
|
||||
|
||||
@ -164,10 +167,10 @@ static struct dentry *books_lookup(struct inode *dir, struct dentry *dentry, uns
|
||||
return NULL; // всегда возвращается NULL в lookup
|
||||
}
|
||||
|
||||
|
||||
static const struct inode_operations books_dir_iops = {
|
||||
.lookup = books_lookup,
|
||||
.create = books_create,
|
||||
.unlink = custom_unlink,
|
||||
};
|
||||
|
||||
static void remove_links_to_inode(struct inode *inode) {
|
||||
@ -422,12 +425,13 @@ static int fill_super(struct super_block *sb, void *data, int silent) {
|
||||
return -ENOMEM;
|
||||
books_inode->i_op = &books_dir_iops;
|
||||
books_inode->i_fop = &simple_dir_operations;
|
||||
books_inode->i_mode = S_IFDIR | 01777;
|
||||
struct dentry *books = d_alloc_name(root_dentry, "books");
|
||||
if (!books)
|
||||
return -ENOMEM;
|
||||
d_add(books, books_inode);
|
||||
inc_nlink(root_inode); // ✅ важно!
|
||||
inc_nlink(books_inode); // ✅ важно!
|
||||
inc_nlink(root_inode);
|
||||
inc_nlink(books_inode);
|
||||
logf("fill_super: books directory instantiated");
|
||||
|
||||
// authors
|
||||
@ -441,8 +445,8 @@ static int fill_super(struct super_block *sb, void *data, int silent) {
|
||||
if (!authors)
|
||||
return -ENOMEM;
|
||||
d_add(authors, authors_inode);
|
||||
inc_nlink(root_inode); // ✅ важно!
|
||||
inc_nlink(authors_inode); // ✅ важно!
|
||||
inc_nlink(root_inode);
|
||||
inc_nlink(authors_inode);
|
||||
logf("fill_super: authors directory instantiated");
|
||||
|
||||
logf("fill_super: books and authors created");
|
||||
|
Loading…
x
Reference in New Issue
Block a user