【发布时间】:2014-05-30 07:40:48
【问题描述】:
我曾经做过一些oo编程。现在我正在阅读 C 中的 linux 内核代码。 我发现:
struct super_block {
...
...
unsigned long s_flags; /* mount flags */
unsigned long s_magic; /* filesystem's magic number */
struct dentry *s_root; /* directory mount point */
struct rw_semaphore s_umount; /* unmount semaphore */
...
...
}
struct dentry {
...
...
struct dentry_operations *d_op; /* dentry operations table */
struct super_block *d_sb; /* superblock of file */
unsigned int d_flags; /* dentry flags */
int d_mounted; /* is this a mount point? */
void *d_fsdata; /* filesystem-specific data */
...
...
};
我们可以看到 super_block 结构体有一个 struct dentry 属性,而 struct dentry 有一个 super_block 属性。它会导致循环依赖吗?非常感谢
如果是,内存管理是如何工作的?例如,如果一个 dentry 对象被删除,super_block 将指向一个无效的位置。我的意思是如何管理他们的生命周期。
【问题讨论】:
-
数据结构包含循环没有问题。只需要知道哪个部分拥有,哪个部分只是引用。如果这不明确,可能会变得很困难。
标签: c linux kernel superblock