2008年05月06日

symlink.c:

C:
  1. /*
  2.  *  linux/fs//symlink.c
  3.  *
  4.  * Only fast symlinks left here - the rest is done by generic code. AV, 1999
  5.  *
  6.  * Copyright (C) 1992, 1993, 1994, 1995
  7.  * Remy Card (card@masi.ibp.fr)
  8.  * Laboratoire MASI - Institut Blaise Pascal
  9.  * Universite Pierre et Marie Curie (Paris VI)
  10.  *
  11.  *  from
  12.  *
  13.  *  linux/fs/minix/symlink.c
  14.  *
  15.  *  Copyright (C) 1991, 1992  Linus Torvalds
  16.  *
  17.  *   symlink handling code
  18.  */
  19.  
  20. #include ".h"
  21. #include "xattr.h"
  22. #include <linux /namei.h>
  23.  
  24. static void *ext2_follow_link(struct dentry *dentry, struct nameidata *nd)
  25. {
  26.         struct ext2_inode_info *ei = EXT2_I(dentry->d_inode);
  27.         nd_set_link(nd, (char *)ei->i_data);
  28.         return NULL;
  29. }
  30. //ext2_follow_link()函数用于搜索符号连接所在的目标文件
  31.  
  32. const struct inode_operations ext2_symlink_inode_operations = {
  33.         .readlink       = generic_readlink,
  34.         .follow_link    = page_follow_link_light,
  35.         .put_link       = page_put_link,
  36. #ifdef CONFIG_EXT2_FS_XATTR
  37.         .setxattr       = generic_setxattr,
  38.         .getxattr       = generic_getxattr,
  39.         .listxattr      = ext2_listxattr,
  40.         .removexattr    = generic_removexattr,
  41. #endif
  42. };
  43. //ext2_symlink_inode_operations定义了上层(VFS)符号连接操作在文件系统这一层中的具体实现函数
  44.  
  45. const struct inode_operations ext2_fast_symlink_inode_operations = {
  46.         .readlink       = generic_readlink,
  47.         .follow_link    = ext2_follow_link,
  48. #ifdef CONFIG_EXT2_FS_XATTR
  49.         .setxattr       = generic_setxattr,
  50.         .getxattr       = generic_getxattr,
  51.         .listxattr      = ext2_listxattr,
  52.         .removexattr    = generic_removexattr,
  53. #endif
  54. };
  55. //ext2_fast_symlink_inode_operations应该是为了向下兼容2.4内核使用的符号连接操作函数

fsync.c:

C:
  1. /*
  2.  *  linux/fs//fsync.c
  3.  *
  4.  *  Copyright (C) 1993  Stephen Tweedie (sct@dcs.ed.ac.uk)
  5.  *  from
  6.  *  Copyright (C) 1992  Remy Card (card@masi.ibp.fr)
  7.  *                      Laboratoire MASI - Institut Blaise Pascal
  8.  *                      Universite Pierre et Marie Curie (Paris VI)
  9.  *  from
  10.  *  linux/fs/minix/truncate.c   Copyright (C) 1991, 1992  Linus Torvalds
  11.  *
  12.  *  ext2fs fsync primitive
  13.  *
  14.  *  Big-endian to little-endian byte-swapping/bitmaps by
  15.  *        David S. Miller (davem@caip.rutgers.edu), 1995
  16.  *
  17.  *  Removed unnecessary code duplication for little endian machines
  18.  *  and excessive __inline__s.
  19.  *        Andi Kleen, 1997
  20.  *
  21.  * Major simplications and cleanup - we only need to do the metadata, because
  22.  * we can depend on generic_block_fdatasync() to sync the data blocks.
  23.  */
  24.  
  25. #include ".h"
  26. #include </linux><linux /buffer_head.h>          /* for sync_mapping_buffers() */
  27.  
  28.  
  29. /*
  30.  *      File may be NULL when we are called. Perhaps we shouldn't
  31.  *      even pass file to fsync ?
  32.  */
  33.  
  34. int ext2_sync_file(struct file *file, struct dentry *dentry, int datasync)
  35. {
  36.         struct inode *inode = dentry->d_inode;
  37.         int err;
  38.         int ret;
  39.  
  40.         ret = sync_mapping_buffers(inode->i_mapping);
  41.         if (!(inode->i_state & I_DIRTY))
  42.                 return ret;
  43.         if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
  44.                 return ret;
  45.  
  46.         err = ext2_sync_inode(inode);
  47.         if (ret == 0)
  48.                 ret = err;
  49.         return ret;
  50. }
  51. //ext2_sync_file函数对文件进行同步,它只检查inode中的脏数据,通过对ext2_sync_inode调用把数据写入硬盘
  52. //sync_mapping_buffers作用是写出地址空间所有间接的blocks

标签 :

发表评论

在下面加入你的评论,或者 trackback 从你的博客站点。 订阅本文的评论。

:

:

:

« Ext2文件系统源代码分析(2)
» 烦……