📄 fs.h
字号:
*/extern int vfs_create(struct inode *, struct dentry *, int);extern int vfs_mkdir(struct inode *, struct dentry *, int);extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);extern int vfs_symlink(struct inode *, struct dentry *, const char *);extern int vfs_link(struct dentry *, struct inode *, struct dentry *);extern int vfs_rmdir(struct inode *, struct dentry *);extern int vfs_unlink(struct inode *, struct dentry *);extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);/* * File types */#define DT_UNKNOWN 0#define DT_FIFO 1#define DT_CHR 2#define DT_DIR 4#define DT_BLK 6#define DT_REG 8#define DT_LNK 10#define DT_SOCK 12#define DT_WHT 14/* * This is the "filldir" function type, used by readdir() to let * the kernel specify what kind of dirent layout it wants to have. * This allows the kernel to read directories into kernel space or * to have different dirent layouts depending on the binary type. */typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);struct block_device_operations { int (*open) (struct inode *, struct file *); int (*release) (struct inode *, struct file *); int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); int (*check_media_change) (kdev_t); int (*revalidate) (kdev_t); struct module *owner;};/* * NOTE: * read, write, poll, fsync, readv, writev can be called * without the big kernel lock held in all filesystems. */struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); ssize_t (*read) (struct file *, char *, size_t, loff_t *); ssize_t (*write) (struct file *, const char *, size_t, loff_t *); int (*readdir) (struct file *, void *, filldir_t); unsigned int (*poll) (struct file *, struct poll_table_struct *); int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *); int (*release) (struct inode *, struct file *); int (*fsync) (struct file *, struct dentry *, int datasync); int (*fasync) (int, struct file *, int); int (*lock) (struct file *, int, struct file_lock *); ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *); ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *); ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); int (*dmapi_map_event) (struct file *, struct vm_area_struct *, unsigned int);};struct inode_operations { int (*create) (struct inode *,struct dentry *,int); struct dentry * (*lookup) (struct inode *,struct dentry *); int (*link) (struct dentry *,struct inode *,struct dentry *); int (*unlink) (struct inode *,struct dentry *); int (*symlink) (struct inode *,struct dentry *,const char *); int (*mkdir) (struct inode *,struct dentry *,int); int (*rmdir) (struct inode *,struct dentry *); int (*mknod) (struct inode *,struct dentry *,int,int); int (*rename) (struct inode *, struct dentry *, struct inode *, struct dentry *); int (*readlink) (struct dentry *, char *,int); int (*follow_link) (struct dentry *, struct nameidata *); void (*truncate) (struct inode *); int (*permission) (struct inode *, int); int (*revalidate) (struct dentry *); int (*setattr) (struct dentry *, struct iattr *); int (*getattr) (struct dentry *, struct iattr *); int (*setxattr) (struct dentry *, const char *, void *, size_t, int); ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t); ssize_t (*listxattr) (struct dentry *, char *, size_t); int (*removexattr) (struct dentry *, const char *);};struct seq_file;/* * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called * without the big kernel lock held in all filesystems. */struct super_operations { void (*read_inode) (struct inode *); /* reiserfs kludge. reiserfs needs 64 bits of information to ** find an inode. We are using the read_inode2 call to get ** that information. We don't like this, and are waiting on some ** VFS changes for the real solution. ** iget4 calls read_inode2, iff it is defined */ void (*read_inode2) (struct inode *, void *) ; void (*dirty_inode) (struct inode *); void (*write_inode) (struct inode *, int); void (*put_inode) (struct inode *); void (*delete_inode) (struct inode *); void (*put_super) (struct super_block *); void (*write_super) (struct super_block *); int (*sync_fs) (struct super_block *); void (*write_super_lockfs) (struct super_block *); void (*unlockfs) (struct super_block *); int (*statfs) (struct super_block *, struct statfs *); int (*remount_fs) (struct super_block *, int *, char *); void (*clear_inode) (struct inode *); void (*umount_begin) (struct super_block *); /* Following are for knfsd to interact with "interesting" filesystems * Currently just reiserfs, but possibly FAT and others later * * fh_to_dentry is given a filehandle fragement with length, and a type flag * and must return a dentry for the referenced object or, if "parent" is * set, a dentry for the parent of the object. * If a dentry cannot be found, a "root" dentry should be created and * flaged as DCACHE_NFSD_DISCONNECTED. nfsd_iget is an example implementation. * * dentry_to_fh is given a dentry and must generate the filesys specific * part of the file handle. Available length is passed in *lenp and used * length should be returned therein. * If need_parent is set, then dentry_to_fh should encode sufficient information * to find the (current) parent. * dentry_to_fh should return a 1byte "type" which will be passed back in * the fhtype arguement to fh_to_dentry. Type of 0 is reserved. * If filesystem was exportable before the introduction of fh_to_dentry, * types 1 and 2 should be used is that same way as the generic code. * Type 255 means error. * * Lengths are in units of 4bytes, not bytes. */ struct dentry * (*fh_to_dentry)(struct super_block *sb, __u32 *fh, int len, int fhtype, int parent); int (*dentry_to_fh)(struct dentry *, __u32 *fh, int *lenp, int need_parent); int (*show_options)(struct seq_file *, struct vfsmount *); int (*dmapi_mount_event) (struct super_block *, char *);};/* Inode state bits.. */#define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */#define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */#define I_DIRTY_PAGES 4 /* Data-related inode changes pending */#define I_LOCK 8#define I_FREEING 16#define I_CLEAR 32#define I_NEW 64#define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)extern void __mark_inode_dirty(struct inode *, int);static inline void mark_inode_dirty(struct inode *inode){ __mark_inode_dirty(inode, I_DIRTY);}static inline void mark_inode_dirty_sync(struct inode *inode){ __mark_inode_dirty(inode, I_DIRTY_SYNC);}static inline void mark_inode_dirty_pages(struct inode *inode){ __mark_inode_dirty(inode, I_DIRTY_PAGES);}struct dquot_operations { void (*initialize) (struct inode *, short); void (*drop) (struct inode *); int (*alloc_space) (struct inode *, qsize_t, char); int (*alloc_inode) (const struct inode *, unsigned long); void (*free_space) (struct inode *, qsize_t); void (*free_inode) (const struct inode *, unsigned long); int (*transfer) (struct inode *, struct iattr *);};struct file_system_type { const char *name; int fs_flags; struct super_block *(*read_super) (struct super_block *, void *, int); struct module *owner; struct file_system_type * next; struct list_head fs_supers;};#define DECLARE_FSTYPE(var,type,read,flags) \struct file_system_type var = { \ name: type, \ read_super: read, \ fs_flags: flags, \ owner: THIS_MODULE, \}#define DECLARE_FSTYPE_DEV(var,type,read) \ DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)/* Alas, no aliases. Too much hassle with bringing module.h everywhere */#define fops_get(fops) \ (((fops) && (fops)->owner) \ ? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \ : (fops))#define fops_put(fops) \do { \ if ((fops) && (fops)->owner) \ __MOD_DEC_USE_COUNT((fops)->owner); \} while(0)extern int register_filesystem(struct file_system_type *);extern int unregister_filesystem(struct file_system_type *);extern struct vfsmount *kern_mount(struct file_system_type *);extern int may_umount(struct vfsmount *);extern long do_mount(char *, char *, char *, unsigned long, void *);#define kern_umount mntputextern int vfs_statfs(struct super_block *, struct statfs *);/* Return value for VFS lock functions - tells locks.c to lock conventionally * REALLY kosha for root NFS and nfs_lock */ #define LOCK_USE_CLNT 1#define FLOCK_VERIFY_READ 1#define FLOCK_VERIFY_WRITE 2extern int locks_mandatory_locked(struct inode *);extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);/* * Candidates for mandatory locking have the setgid bit set * but no group execute bit - an otherwise meaningless combination. */#define MANDATORY_LOCK(inode) \ (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)static inline int locks_verify_locked(struct inode *inode){ if (MANDATORY_LOCK(inode)) return locks_mandatory_locked(inode); return 0;}static inline int locks_verify_area(int read_write, struct inode *inode, struct file *filp, loff_t offset, size_t count){ if (inode->i_flock && MANDATORY_LOCK(inode)) return locks_mandatory_area(read_write, inode, filp, offset, count); return 0;}static inline int locks_verify_truncate(struct inode *inode, struct file *filp, loff_t size){ if (inode->i_flock && MANDATORY_LOCK(inode)) return locks_mandatory_area( FLOCK_VERIFY_WRITE, inode, filp, size < inode->i_size ? size : inode->i_size, (size < inode->i_size ? inode->i_size - size : size - inode->i_size) ); return 0;}static inline int get_lease(struct inode *inode, unsigned int mode){ if (inode->i_flock) return __get_lease(inode, mode); return 0;}/* fs/open.c */asmlinkage long sys_open(const char *, int, int);asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */extern int do_truncate(struct dentry *, loff_t start);extern struct file *filp_open(const char *, int, int);extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);extern int filp_close(struct file *, fl_owner_t id);extern char * getname(const char *);/* fs/dcache.c */extern void vfs_caches_init(unsigned long);#define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)#define putname(name) kmem_cache_free(names_cachep, (void *)(name))enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);extern int unregister_blkdev(unsigned int, const char *);extern struct block_device *bdget(dev_t);extern int bd_acquire(struct inode *inode);extern void bd_forget(struct inode *inode);extern void bdput(struct block_device *);extern struct char_device *cdget(dev_t);extern void cdput(struct char_device *);extern int blkdev_open(struct inode *, struct file *);extern int blkdev_close(struct inode *, struct file *);extern struct file_operations def_blk_fops;extern struct address_space_operations def_blk_aops;extern struct file_operations def_fifo_fops;extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);extern int blkdev_get(struct block_device *, mode_t, unsigned, int);extern int blkdev_put(struct block_device *, int);/* fs/devices.c */extern const struct block_device_operations *get_blkfops(unsigned int);extern int register_chrdev(unsigned int, const char *, struct file_operations *);extern int unregister_chrdev(unsigned int, const char *);extern int chrdev_open(struct inode *, struct file *);extern const char * bdevname(kdev_t);extern const char * cdevname(kdev_t);extern const char * kdevname(kdev_t);extern void init_special_inode(struct inode *, umode_t, int);/* Invalid inode operations -- fs/bad_inode.c */extern void make_bad_inode(struct inode *);extern int is_bad_inode(struct inode *);extern struct file_operations read_fifo_fops;extern struct file_operations write_fifo_fops;extern struct file_operations rdwr_fifo_fops;extern struct file_operations read_pipe_fops;extern struct file_operations write_pipe_fops;extern struct file_operations rdwr_pipe_fops;extern int fs_may_remount_ro(struct super_block *);extern int FASTCALL(try_to_free_buffers(struct page *, unsigned int));extern void refile_buffer(struct buffer_head * buf);extern void create_empty_buffers(struct page *, kdev_t, unsigned long);extern void end_buffer_io_sync(struct buffer_head *bh, int uptodate);/* reiserfs_writepage needs this */extern void set_buffer_async_io(struct buffer_head *bh) ;#define BUF_CLEAN 0#define BUF_LOCKED 1 /* Buffers scheduled for write */#define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */#define NR_LIST 3static inline void get_bh(struct buffer_head * bh){ atomic_inc(&(bh)->b_count);}static inline void put_bh(struct buffer_head *bh){ smp_mb__before_atomic_dec(); atomic_dec(&bh->b_count);}/* * This is called by bh->b_end_io() handlers when I/O has completed. */static inline void mark_buffer_uptodate(struct buffer_head * bh, int on){ if (on) set_bit(BH_Uptodate, &bh->b_state); else clear_bit(BH_Uptodate, &bh->b_state);}#define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)static inline void __mark_buffer_clean(struct buffer_head *bh){ refile_buffer(bh);}static inline void mark_buffer_clean(struct buffer_head * bh){ if (atomic_set_buffer_clean(bh)) __mark_buffer_clean(bh);}extern void FASTCALL(__mark_dirty(struct buffer_head *bh));extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh));extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));extern void FASTCALL(buffer_insert_inode_queue(struct buffer_head *, struct inode *));extern void FASTCALL(buffer_insert_inode_data_queue(struct buffer_head *, struct inode *));static inline int atomic_set_buffer_dirty(struct buffer_head *bh){ return test_and_set_bit(BH_Dirty, &bh->b_state);}static inline void mark_buffer_async(struct buffer_head * bh, int on){ if (on) set_bit(BH_Async, &bh->b_state); else clear_bit(BH_Async, &bh->b_state);}/* * If an error happens during the make_request, this function * has to be recalled. It marks the buffer as clean and not * uptodate, and it notifys the upper layer about the end * of the I/O. */static inline void buffer_IO_error(struct buffer_head * bh){ mark_buffer_clean(bh); /* * b_end_io has to clear the BH_Uptodate bitflag in the error case! */ bh->b_end_io(bh, 0);}static inline void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode){ mark_buffer_dirty(bh); buffer_insert_inode_queue(bh, inode);}extern void set_buffer_flushtime(struct buffer_head *);extern void balance_dirty(void);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -