[文件系统] 一个简单文件系统的实现(8)
普通文件操作(在file.c中定义),只需要实现一个gt_sync_file
const struct file_operations gt_file_operations ={
.llseek =generic_file_llseek,
.read =do_sync_read,
.write =do_sync_write,
.aio_read =generic_file_aio_read,
.aio_write =generic_file_aio_write,
.mmap =generic_file_mmap,
.open =generic_file_open,
.fsync =gt_sync_file,
};
来看看gt_sync_file(在file.c中定义)
int gt_sync_file(struct file *file,struct dentry *dentry,int datasync){
struct inode *inode =dentry->d_inode;
int err,ret;
ret=sync_mapping_buffers(inode->i_mapping);
if(!(inode->i_state&I_DIRTY))
return ret;
if(datasync && !(inode->i_state&I_DIRTY_DATASYNC))
return ret;
err=gt_sync_inode(inode);
if(ret==)
ret=err;
return ret;
}
函数调用gt_sync_inode(在inode.c中定义)
int gt_sync_inode(struct inode *inode){
int ret=;
struct buffer_head *bh;
bh=gt_update_inode(inode);//获取到磁盘索引节点所在的缓冲区
if(bh && buffer_dirty(bh)){//如果为脏,则同步
sync_dirty_buffer(bh);
if(buffer_req(bh)&&!buffer_uptodate(bh)){
printk("IO error syncing gt inode\n");
ret=-1;
}
}else if(!bh)
ret=-1;
brelse(bh);
return ret;
}
文章来源CU社区:[文件系统] 一个简单文件系统的实现
相关文章