kbd: use a better get_key method
[thunix.git] / include / fs.h
blob497519c2742124703c2c81be69bbd421f863b0af
1 #ifndef FS_H
2 #define FS_H
4 #include <stdint.h>
6 #define FS_DEBUG //printk
8 #define MAX_NAME_LEN 255
10 #define BLOCK_SIZE(fs) (1 << (fs)->block_shift)
11 #define SECTOR_SIZE(fs) (1 << (fs)->sector_shift)
13 /* namei: path lookup flags */
14 #define LOOKUP_PARENT 0x1
15 #define LOOKUP_CREATE 0x2
17 #define TFS_FILE 0x1
18 #define TFS_DIR 0x2
19 #define IS_DIR(dir) ((dir)->i_mode == TFS_DIR)
21 #define MAX_CWD_LEN 255
23 struct fs {
24 char *name;
25 void *sb; /* The fs-specific information */
26 int sector_shift;
27 int block_shift;
29 uint32_t offset; /* Disk offset as sectors */
31 char cwd[MAX_CWD_LEN];
32 struct inode *pwd;
33 struct inode *root;
36 struct fs_type {
37 void * (*mount)(void);
38 int (*get_blk_shift)(void *);
41 #define SEEK_SET 0
42 #define SEEK_CUR 1
43 #define SEEK_END 2
46 struct file {
47 struct inode * inode;
48 struct fs * fs;
49 uint32_t offset;
51 struct file_operations *f_op;
54 /*
55 * The inode structure of VFS layer
57 struct inode {
58 int i_mode; /* FILE or DIR */
59 uint32_t i_size;
60 uint32_t i_ino; /* Inode number */
61 uint32_t i_atime; /* Access time */
62 uint32_t i_mtime; /* Modify time */
63 uint32_t i_ctime; /* Create time */
64 uint32_t i_dtime; /* Delete time */
65 uint32_t * i_data; /* The block address array where the file stores */
66 uint32_t i_flags;
68 int i_blksize;
70 struct fs * i_fs;
72 /* Operations */
73 struct inode_operations * i_op;
74 struct file_operations * i_fop;
77 struct inode_operations {
78 struct inode * (*iget) (const char *, struct inode *);
79 struct inode * (*iget_root)(struct fs *fs);
80 struct inode * (*iget_by_inr)(int);
81 int (*iwrite) (struct inode *);
83 int (*mkdir)(struct inode *, const char *);
84 int (*rmdir)(struct inode *, const char *);
85 int (*unlink)(struct inode *, const char *);
86 struct inode *(*mknod)(struct inode *, const char *, int);
89 struct dirent;
91 struct file_operations {
92 int (*read) (struct file *, void *, int);
93 int (*write) (struct file *, void *, int);
94 void (*close) (struct file *);
95 struct dirent * (*readdir)(struct file *);
98 extern struct fs * current_root_fs;
100 static inline struct fs * root_fs(void)
102 return current_root_fs;
105 extern uint8_t fds[];
106 extern struct file *files[];
109 * Functions
112 /* inode.c */
113 struct inode *new_inode(int, int);
114 void free_inode(struct inode *);
115 struct inode * iget(const char *, struct inode *);
117 /* file.c */
118 int sys_open(const char *, uint32_t);
119 int sys_read(int, void *, int);
120 int sys_write(int, void *, int);
121 int sys_close(int);
122 int sys_lseek(int, int, int);
124 /* namei.c */
125 struct inode *namei(const char *, uint32_t);
126 struct inode *namei_parent(const char *);
127 int sys_mkdir(const char *);
128 int sys_rmdir(const char *);
129 int sys_chdir(const char *);
130 int sys_getcwd(char *, int);
131 int sys_unlink(const char *);
133 /* exec.c */
134 int sys_execve(const char *, char **);
136 /* fslib.c */
137 const char *get_base_name(const char *);
139 /* super.c */
140 struct fs *fs_init(void);
143 #endif /* fs.h */