ext2文件系统源代码之file.c

来源:互联网 发布:北面和狼爪哪个好 知乎 编辑:程序博客网 时间:2024/05/22 06:46
今天我们继续来看ext2文件系统的另一个比较重要的文件file.c,这个文件比较短,但是却很重要,定义了一些与文件操作有关的结构体,我们来看看吧。
/*作者版权信息 *  linux/fs/ext2/file.c * * Copyright (C) 1992, 1993, 1994, 1995 * Remy Card (card@masi.ibp.fr) * Laboratoire MASI - Institut Blaise Pascal * 巴黎第六大学(法国排名第一) * Universite Pierre et Marie Curie (Paris VI) * *  from *参考了linux/fs/minix/file.c文件 *  linux/fs/minix/file.c * *  Copyright (C) 1991, 1992  Linus Torvalds * *  ext2 fs regular file handling primitives * *  64-bit file support on 64-bit platforms by Jakub Jelinek * (jj@sunsite.ms.mff.cuni.cz) */#include <linux/time.h>#include "ext2.h"#include "xattr.h"#include "acl.h"/*释放文件的资源,这个函数当一个inode被释放的时候被调用,注意,和ext2_open_file函数不一样的是,每当一个函数被打开的时候,ext2_open_file函数都会被调用,但是文件关闭的时候,这个函数并不会调用,只有当这个文件的引用计数为负的时候,才会为调用*/static int ext2_release_file (struct inode * inode, struct file * filp){/*如果这个文件是以可写模式打开的话*/if (filp->f_mode & FMODE_WRITE)/*因为没有人用这个文件了,所以要把所有的预分配的块都释放掉,这个函数在inode.c里定义,我们随后会讲到*/ext2_discard_prealloc (inode);return 0;}/*ext2文件系统里的文件的各项操作的集合 */const struct file_operations ext2_file_operations = {/*读写指针变更*/.llseek= generic_file_llseek,/*ext2的读写函数*/.read= do_sync_read,.write= do_sync_write,/*异步读写函数*/.aio_read= generic_file_aio_read,.aio_write= generic_file_aio_write,/*ioctl的控制函数*/.ioctl= ext2_ioctl,#ifdef CONFIG_COMPAT/*兼容性的ioctl*/.compat_ioctl= ext2_compat_ioctl,#endif/*内存映射*/.mmap= generic_file_mmap,/*文件打开关闭*/.open= generic_file_open,.release= ext2_release_file,.fsync= ext2_sync_file,.sendfile= generic_file_sendfile,.splice_read= generic_file_splice_read,.splice_write= generic_file_splice_write,};#ifdef CONFIG_EXT2_FS_XIP/*如果硬件设备是可以片内执行的,就使用这个函数操作集合*/const struct file_operations ext2_xip_file_operations = {.llseek= generic_file_llseek,.read= xip_file_read,.write= xip_file_write,.ioctl= ext2_ioctl,#ifdef CONFIG_COMPAT.compat_ioctl= ext2_compat_ioctl,#endif.mmap= xip_file_mmap,.open= generic_file_open,.release= ext2_release_file,.fsync= ext2_sync_file,.sendfile= xip_file_sendfile,};#endif/*inode的函数结婚*/const struct inode_operations ext2_file_inode_operations = {.truncate= ext2_truncate,#ifdef CONFIG_EXT2_FS_XATTR/*inode的属性操作*/.setxattr= generic_setxattr,.getxattr= generic_getxattr,.listxattr= ext2_listxattr,.removexattr= generic_removexattr,#endif.setattr= ext2_setattr,.permission= ext2_permission,};

0 0