📄 fs.h
字号:
#ifndef _FS_H
#define _FS_H
#include "../jffs/jffstypes.h"
#define NR_OPEN 16
#define BLOCK_SIZE 1024
#define BLOCK_SIZE_BITS 10
#define FMODE_READ 1
#define FMODE_WRITE 2
#ifndef NULL
#define NULL ((void *) 0)
#endif
#define NIL_FILP ((struct file *)0)
#define SEL_IN 1
#define SEL_OUT 2
#define SEL_EX 4
/*
* These are the fs-independent mount-flags: up to 16 flags are supported
*/
#define MS_RDONLY 1 /* Mount read-only */
#define MS_NOSUID 2 /* Ignore suid and sgid bits */
#define MS_NODEV 4 /* Disallow access to device special files */
#define MS_NOEXEC 8 /* Disallow program execution */
#define MS_SYNCHRONOUS 16 /* Writes are synced at once */
#define MS_REMOUNT 32 /* Alter flags of a mounted FS */
#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
#define S_WRITE 128 /* Write on file/directory/symlink */
#define S_APPEND 256 /* Append-only file */
#define S_IMMUTABLE 512 /* Immutable file */
#define MS_NOATIME 1024 /* Do not update access times. */
#define S_BAD_INODE 2048 /* Marker for unreadable inodes */
#define S_ZERO_WR 4096 /* Device accepts 0 length writes */
/*
* Flags that can be altered by MS_REMOUNT
*/
#define MS_RMT_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME)
/*
* Magic mount flag number. Has to be or-ed to the flag values.
*/
#define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
#define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
/*
* Note that read-only etc flags are inode-specific: setting some file-system
* flags just means all the inodes inherit those flags by default. It might be
* possible to override it selectively if you really wanted to with some
* ioctl() that is not currently implemented.
*
* Exception: MS_RDONLY is always applied to the entire file system.
*/
#define IS_RDONLY(inode) (((inode)->i_sb) && ((inode)->i_sb->s_flags & MS_RDONLY))
#define IS_NOSUID(inode) ((inode)->i_flags & MS_NOSUID)
#define IS_NODEV(inode) ((inode)->i_flags & MS_NODEV)
#define IS_NOEXEC(inode) ((inode)->i_flags & MS_NOEXEC)
#define IS_SYNC(inode) ((inode)->i_flags & MS_SYNCHRONOUS)
#define IS_MANDLOCK(inode) ((inode)->i_flags & MS_MANDLOCK)
#define IS_WRITABLE(inode) ((inode)->i_flags & S_WRITE)
#define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
#define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
#define IS_NOATIME(inode) ((inode)->i_flags & MS_NOATIME)
#define IS_ZERO_WR(inode) ((inode)->i_flags & S_ZERO_WR)
typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t);
struct iattr {
unsigned int ia_valid;
umode_t ia_mode;
uid_t ia_uid;
gid_t ia_gid;
off_t ia_size;
time_t ia_atime;
time_t ia_mtime;
time_t ia_ctime;
};
struct statfs {
long f_type;
long f_bsize;
long f_blocks;
long f_bfree;
long f_bavail;
long f_files;
long f_ffree;
/*__kernel_fsid_t f_fsid;*/
long f_namelen;
long f_spare[6];
};
struct super_operations {
void (*read_inode) (struct inode *);
int (*notify_change) (struct inode *, struct iattr *);
void (*write_inode) (struct inode *);
void (*put_inode) (struct inode *);
void (*put_super) (struct super_block *);
void (*write_super) (struct super_block *);
void (*statfs) (struct super_block *, struct statfs *, int);
int (*remount_fs) (struct super_block *, int *, char *);
};
struct file_system_type {
struct super_block *(*read_super) (struct super_block *, void *, int);
const char *name;
int requires_dev;
struct file_system_type * next;
};
struct super_block {
kdev_t s_dev;
unsigned long s_blocksize;
unsigned char s_blocksize_bits;
unsigned char s_lock;
unsigned char s_rd_only;
unsigned char s_dirt;
struct file_system_type *s_type;
struct super_operations *s_op;
/*struct dquot_operations *dq_op;*/
unsigned long s_flags;
unsigned long s_magic;
unsigned long s_time;
struct inode * s_covered;
struct inode * s_mounted;
/*struct wait_queue * s_wait;TODO*/
union {
unsigned char i_ip_pad[40];
void *generic_sbp;
} u;
};
/*站位声明*/
struct vm_area_struct{
long pad;
};
typedef struct select_table_struct {
int nr;
void *entry;
} select_table;
struct file_operations {
int (*lseek) (struct inode *, struct file *, off_t, int);
int (*read) (struct inode *, struct file *, char *, int);
int (*write) (struct inode *, struct file *, const char *, int);
int (*readdir) (struct inode *, struct file *, void *, filldir_t);
int (*select) (struct inode *, struct file *, int, select_table *);
int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
int (*mmap) (struct inode *, struct file *, struct vm_area_struct *);
int (*open) (struct inode *, struct file *);
void (*release) (struct inode *, struct file *);
int (*fsync) (struct inode *, struct file *);
int (*fasync) (struct inode *, struct file *, int);
int (*check_media_change) (kdev_t dev);
int (*revalidate) (kdev_t dev);
};
struct inode_operations {
struct file_operations * default_file_ops;
int (*create) (struct inode *,const char *,int,int,struct inode **);
int (*lookup) (struct inode *,const char *,int,struct inode **);
int (*link) (struct inode *,struct inode *,const char *,int);
int (*unlink) (struct inode *,const char *,int);
int (*symlink) (struct inode *,const char *,int,const char *);
int (*mkdir) (struct inode *,const char *,int,int);
int (*rmdir) (struct inode *,const char *,int);
int (*mknod) (struct inode *,const char *,int,int,int);
int (*rename) (struct inode *,const char *,int,struct inode *,const char *,int, int);
int (*readlink) (struct inode *,char *,int);
int (*follow_link) (struct inode *,struct inode *,int,int,struct inode **);
int (*readpage) (struct inode *, struct page *);
int (*writepage) (struct inode *, struct page *);
int (*bmap) (struct inode *,int);
void (*truncate) (struct inode *);
int (*permission) (struct inode *, int);
int (*smap) (struct inode *,int);
};
struct inode {
kdev_t i_dev;
unsigned long i_ino;
umode_t i_mode;
nlink_t i_nlink;
uid_t i_uid;
gid_t i_gid;
kdev_t i_rdev;
off_t i_size;
time_t i_atime;
time_t i_mtime;
time_t i_ctime;
unsigned long i_blksize;
unsigned long i_blocks;
unsigned long i_version;
unsigned long i_nrpages;
/*struct semaphore i_sem;*/
struct inode_operations *i_op;
struct super_block *i_sb;
/*struct wait_queue *i_wait;
struct file_lock *i_flock;
struct page *i_pages;
struct dquot *i_dquot[MAXQUOTAS];*/
struct inode *i_next, *i_prev;
struct inode *i_hash_next, *i_hash_prev;
struct inode *i_bound_to, *i_bound_by;
struct inode *i_mount;
unsigned long i_count; /* needs to be > (address_space * tasks)>>pagebits */
unsigned short i_flags;
unsigned short i_writecount;
unsigned char i_lock;
unsigned char i_dirt;
unsigned char i_pipe;
unsigned char i_sock;
unsigned char i_seek;
unsigned char i_update;
unsigned char i_condemned;
union {
unsigned char i_ip_pad[100];
void * generic_ip;
} u;
};
struct file {
mode_t f_mode;
loff_t f_pos;
unsigned short f_flags;
unsigned short f_count;
unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
struct file *f_next, *f_prev;
/*struct fown_struct f_owner;*/
struct inode * f_inode;
struct file_operations * f_op;
unsigned long f_version;
void *private_data; /* needed for tty driver, and maybe others */
};
/*来自sched.h*/
struct fs_struct {
int count;
unsigned short umask;
struct inode * root, * pwd;
};
extern struct file files_fd[NR_OPEN]; /*静态分配空间*/
extern struct fs_struct current_fs;
extern int current_fd; /*指向打开的文件槽*/
struct inode * iget(struct super_block * sb,int nr);
void iput(struct inode * inode);
unsigned long find_next_zero_bit(void *addr, unsigned long size, unsigned long offset);
struct file * fget(unsigned long fd);
void fput(struct file *file, struct inode *inode);
#define GFP_KERNEL 0
void *kmalloc(unsigned long size, char x);
void kfree( void *p );
struct inode * get_empty_inode(void);
int open_namei(const char * pathname, int flag, int mode,
struct inode ** res_inode, struct inode * base);
int mf_open(char * filename,int flags,int mode);
int mf_close(unsigned int fd);
int mf_readdir(unsigned int fd, void * dirent, unsigned int count);
int mf_mkdir(const char * pathname, int mode);
long mf_lseek(unsigned int fd, off_t offset, unsigned int origin);
int mf_read(unsigned int fd,char * buf,int count);
int mf_write(unsigned int fd,char * buf,unsigned int count);
int mf_unlink(const char * pathname); //文件删除
int mf_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg); //取文件长度
int mf_eof(unsigned int fd);
int mf_rename(const char * oldname, const char * newname, int must_be_dir);
#endif /*_FS_H*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -