免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2493 | 回复: 3
打印 上一主题 下一主题

求教:关于inode节点 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-11 20:54 |只看该作者 |倒序浏览
今天看到fs,发现在2.4.0(情景分析的代码)中,inode是用 u 来解释不同的文件系统:
  1. 387struct inode {
  2. 388        struct list_head        i_hash;
  3. 389        struct list_head        i_list;
  4. 390        struct list_head        i_dentry;

  5. 。。。。

  6. 433        union {
  7. 434                struct minix_inode_info         minix_i;
  8. 435                struct ext2_inode_info          ext2_i;
  9. 436                struct hpfs_inode_info          hpfs_i;
  10. 437                struct ntfs_inode_info          ntfs_i;
  11. 438                struct msdos_inode_info         msdos_i;
  12. 439                struct umsdos_inode_info        umsdos_i;
  13. 440                struct iso_inode_info           isofs_i;
  14. 441                struct nfs_inode_info           nfs_i;
  15. 442                struct sysv_inode_info          sysv_i;
  16. 443                struct affs_inode_info          affs_i;
  17. 444                struct ufs_inode_info           ufs_i;
  18. 445                struct efs_inode_info           efs_i;
  19. 446                struct romfs_inode_info         romfs_i;
  20. 447                struct shmem_inode_info         shmem_i;
  21. 448                struct coda_inode_info          coda_i;
  22. 449                struct smb_inode_info           smbfs_i;
  23. 450                struct hfs_inode_info           hfs_i;
  24. 451                struct adfs_inode_info          adfs_i;
  25. 452                struct qnx4_inode_info          qnx4_i;
  26. 453                struct bfs_inode_info           bfs_i;
  27. 454                struct udf_inode_info           udf_i;
  28. 455                struct ncp_inode_info           ncpfs_i;
  29. 456                struct proc_inode_info          proc_i;
  30. 457                struct socket                   socket_i;
  31. 458                struct usbdev_inode_info        usbdev_i;
  32. 459                void                            *generic_ip;
  33. 460        } u;
  34. 461};
复制代码


在《深入理解Linux内核》(2.6.11)中的inode没有了"u",那这里是怎么向上面一样找到各个文件系统的?

到了2.6.23版本的内核中,inode中:
  1. 533 struct inode {
  2. 534     struct hlist_node   i_hash;
  3. 535     struct list_head    i_list;
  4. 536     struct list_head    i_sb_list;
  5. 537     struct list_head    i_dentry;

  6. 597     void            *i_private; /* fs or device private pointer */
  7. 598 };
复制代码

这个i_private应该就是指向向上面2.4.0的"u"的信息吧?(猜测)

请问i_private指向哪里阿?

论坛徽章:
0
2 [报告]
发表于 2009-03-17 19:40 |只看该作者
yes, your guess is right

let's take a look at yaffs2 (as a case):

#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
    struct nameidata *n)
#else
static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
#endif
{
yaffs_Object *obj;
struct inode *inode = NULL; /* NCB 2.5/2.6 needs NULL here */
yaffs_Device *dev = yaffs_InodeToObject(dir)->myDev;
yaffs_GrossLock(dev);
T(YAFFS_TRACE_OS,
  ("yaffs_lookup for %d:%s\n",
  yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
     dentry->d_name.name);
obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
/* Can't hold gross lock when calling yaffs_get_inode() */
yaffs_GrossUnlock(dev);
if (obj) {
  T(YAFFS_TRACE_OS,
   ("yaffs_lookup found %d\n", obj->objectId));
  inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
  if (inode) {
   T(YAFFS_TRACE_OS,
    ("yaffs_loookup dentry \n");
/* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
* d_add even if NULL inode */
#if 0
   /*dget(dentry); // try to solve directory bug */
   d_add(dentry, inode);
   /* return dentry; */
   return NULL;
#endif
  }
} else {
  T(YAFFS_TRACE_OS, ("yaffs_lookup not found\n");
}
/* added NCB for 2.5/6 compatability - forces add even if inode is
* NULL which creates dentry hash */
d_add(dentry, inode);
return NULL;
}

where yaffs_InodeToObject defines as following:
#define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
#define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private)

concisely, inode->"i_private" pointers to "yaffs_Object"

any question else?

论坛徽章:
0
3 [报告]
发表于 2009-03-17 19:41 |只看该作者
btw, yaffs_Object defines as:

struct yaffs_ObjectStruct {
__u8 deleted:1;  /* This should only apply to unlinked files. */
__u8 softDeleted:1; /* it has also been soft deleted */
__u8 unlinked:1; /* An unlinked file. The file should be in the unlinked directory.*/
__u8 fake:1;  /* A fake object has no presence on NAND. */
__u8 renameAllowed:1; /* Some objects are not allowed to be renamed. */
__u8 unlinkAllowed:1;
__u8 dirty:1;  /* the object needs to be written to flash */
__u8 valid:1;  /* When the file system is being loaded up, this
     * object might be created before the data
     * is available (ie. file data records appear before the header).
     */
__u8 lazyLoaded:1; /* This object has been lazy loaded and is missing some detail */
__u8 deferedFree:1; /* For Linux kernel. Object is removed from NAND, but is
     * still in the inode cache. Free of object is defered.
     * until the inode is released.
     */
__u8 beingCreated:1; /* This object is still being created so skip some checks. */
__u8 serial;  /* serial number of chunk in NAND. Cached here */
__u16 sum;  /* sum of the name to speed searching */
struct yaffs_DeviceStruct *myDev;       /* The device I'm on */
struct ylist_head hashLink;     /* list of objects in this hash bucket */
struct ylist_head hardLinks;    /* all the equivalent hard linked objects */
/* directory structure stuff */
/* also used for linking up the free list */
struct yaffs_ObjectStruct *parent;
struct ylist_head siblings;
/* Where's my object header in NAND? */
int hdrChunk;
int nDataChunks; /* Number of data chunks attached to the file. */
__u32 objectId;  /* the object id value */
__u32 yst_mode;
#ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
YCHAR shortName[YAFFS_SHORT_NAME_LENGTH + 1];
#endif
#ifndef __KERNEL__
__u32 inUse;
#endif
#ifdef CONFIG_YAFFS_WINCE
__u32 win_ctime[2];
__u32 win_mtime[2];
__u32 win_atime[2];
#else
__u32 yst_uid;
__u32 yst_gid;
__u32 yst_atime;
__u32 yst_mtime;
__u32 yst_ctime;
#endif
__u32 yst_rdev;
#ifdef __KERNEL__
struct inode *myInode;
#endif
yaffs_ObjectType variantType;
yaffs_ObjectVariant variant;
};

论坛徽章:
0
4 [报告]
发表于 2009-03-18 18:03 |只看该作者
Other FS (such as jffs2) have a better solution:

// jffs2 inode
struct jffs2_inode_info {
    /* We need an internal mutex similar to inode->i_mutex.
       Unfortunately, we can't used the existing one, because
       either the GC would deadlock, or we'd have to release it
       before letting GC proceed. Or we'd have to put ugliness
       into the GC code so it didn't attempt to obtain the i_mutex
       for the inode(s) which are already locked */
    struct mutex sem;

    /* The highest (datanode) version number used for this ino */
    uint32_t highest_version;

    /* List of data fragments which make up the file */
    struct rb_root fragtree;

    // <skipped>

    uint16_t flags;
    uint8_t usercompr;
    struct inode vfs_inode;
#ifdef CONFIG_JFFS2_FS_POSIX_ACL
    struct posix_acl *i_acl_access;
    struct posix_acl *i_acl_default;
#endif
};


static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
                   struct nameidata *nd)
{
    struct jffs2_inode_info *dir_f;
    struct jffs2_sb_info *c;
    struct jffs2_full_dirent *fd = NULL, *fd_list;
    uint32_t ino = 0;
    struct inode *inode = NULL;

    D1(printk(KERN_DEBUG "jffs2_lookup()\n"));

    if (target->d_name.len > JFFS2_MAX_NAME_LEN)
        return ERR_PTR(-ENAMETOOLONG);

    dir_f = JFFS2_INODE_INFO(dir_i);
    c = JFFS2_SB_INFO(dir_i->i_sb);

    mutex_lock(&dir_f->sem);

    /* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
    for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) {
        if (fd_list->nhash == target->d_name.hash &&
            (!fd || fd_list->version > fd->version) &&
            strlen(fd_list->name) == target->d_name.len &&
            !strncmp(fd_list->name, target->d_name.name, target->d_name.len)) {
            fd = fd_list;
        }
    }
    if (fd)
        ino = fd->ino;
    mutex_unlock(&dir_f->sem);
    if (ino) {
        inode = jffs2_iget(dir_i->i_sb, ino);
        if (IS_ERR(inode)) {
            printk(KERN_WARNING "iget() failed for ino #%u\n", ino);
            return ERR_CAST(inode);
        }
    }

    return d_splice_alias(inode, target);
}

#define JFFS2_INODE_INFO(i) (list_entry(i, struct jffs2_inode_info, vfs_inode))
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP