-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsimplefs.h
126 lines (88 loc) · 3.12 KB
/
simplefs.h
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef __FS_SIMPLEFS_H__
#define __FS_SIMPLEFS_H__
/*
* linux/fs/sfs/file.c
*
* Copyright (C) 2013
*/
#include <linux/pagemap.h>
#include <linux/fs.h>
#define SIMPLEFS_ROOT_INO 0
#define SIMPLEFS_SUPER_BNO 0
#define SIMPLEFS_BITMAP_BNO 1
#define SIMPLEFS_BLOCKSIZE 512
#define SIMPLEFS_BLOCKBITS 9
struct simplefs_super {
__le32 s_inode_bitmap_blknr;
__le32 s_inode_blknr;
__le32 s_free_inodes_count;
__le32 s_block_bitmap_blknr;
__le32 s_block_blknr;
__le32 s_free_blocks_count;
};
struct simplefs_super_info {
struct buffer_head *s_sb;
struct buffer_head **s_bitmaps;
struct simplefs_super raw_super;
};
#define SIMPLEFS_BLOCKS_PER_INODE 15
struct simplefs_inode {
__le32 i_size;
__le32 i_time;
__le32 i_mode;
__le32 i_nlink;
__le32 i_data[SIMPLEFS_BLOCKS_PER_INODE];
};
struct simplefs_inode *simplefs_iget_raw(struct super_block *sb,
long ino, struct buffer_head **bh);
struct inode *simplefs_iget(struct super_block *sb, long ino);
void simplefs_truncate(struct inode *inode);
int simplefs_free_inode(struct inode *inode);
int simplefs_get_block(struct inode *inode,
sector_t block, struct buffer_head *bh_result, int create);
int simplefs_sync_inode(struct inode *inode);
static inline int inode_last_bytes(struct inode *inode, unsigned long page_nr) {
unsigned last_bytes = PAGE_CACHE_SIZE;
if (page_nr == (inode->i_size >> PAGE_CACHE_SHIFT))
last_bytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
return last_bytes;
}
static inline unsigned long inode_pages(struct inode *inode) {
return (inode->i_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
}
void simplefs_put_page(struct page *page);
struct page *simplefs_get_page(struct inode *dir, unsigned long n);
struct simplefs_dentry *simplefs_find_dentry(struct inode *inode,
struct dentry *dentry, struct page **rs_page);
int simplefs_insert_dentry(struct dentry *dentry, struct inode *inode);
int simplefs_delete_dentry(struct simplefs_dentry *de, struct page *page);
#define SIMPLEFS_NAME_LEN 20
#define SIMPLEFS_DENTRY_UNUSED 0x01
#define SIMPLEFS_DENTRY_INUSED 0x02
struct simplefs_dentry {
__le32 inode;
__le32 flags;
char name[SIMPLEFS_NAME_LEN];
};
#define SIMPLEFS_DENTRY_SIZE sizeof(struct simplefs_dentry)
#define SIMPLEFS_INODES_PER_BLOCK (SIMPLEFS_BLOCKSIZE / sizeof(struct simplefs_inode))
#define SIMPLEFS_DENTRYS_PER_BLOCK (SIMPLEFS_BLOCKSIZE / sizeof(struct simplefs_dentry))
/* bitmap.c */
struct buffer_head *bitmap_load(struct super_block *sb, sector_t block);
long bitmap_alloc_inode(struct super_block *sb);
void bitmap_free_inode(struct super_block *sb, long ino);
long bitmap_alloc_block(struct super_block *sb);
void bitmap_free_block(struct super_block *sb, long bno);
/*
* Inodes and files operations
*/
/* dir.c */
extern const struct file_operations simplefs_dir_operations;
extern const struct inode_operations simplefs_dir_inode_operations;
/* file.c */
extern const struct file_operations simplefs_file_operations;
extern const struct inode_operations simplefs_file_inode_operations;
/* inode.c */
extern const struct address_space_operations simplefs_aops;
#endif /* __FS_SIMPLEFS_H__ */