Linux内核文件系统 free_inode函数

本文详细介绍了Linux内核0.11版本中free_inode函数的实现,主要关注了两个关键部分的解释:检查inode位图是否存在以及清除inode对应的位。通过分析inode的编号和位图的关系,解释了如何定位并释放inode。
摘要由CSDN通过智能技术生成


此函数为Linux 内核 0.11版本中的,目录为Linux/fs/bitmap.c  源代码如下:


107 void free_inode(struct m_inode * inode)
108 {
109     struct super_block * sb;
110     struct buffer_head * bh;
111 
112     if (!inode)
113         return;
114     if (!inode->i_dev) {
115         memset(inode,0,sizeof(*inode));
116         return;
117     }
118     if (inode->i_count>1) {
119         printk("trying to free inode with count=%d\n",inode->i_count);
120         panic("free_inode");
121     }
122     if (inode->i_nlinks)
123         panic("trying to free inode with links");
124     if (

pstore_unlink函数是一个在Linux内核中用于删除pstore文件的函数。它的作用是将pstore文件从文件系统中删除,并且删除与文件相关联的pstore记录。 pstore_unlink函数的源代码如下: ``` static int pstore_unlink(struct inode *inode, struct dentry *dentry) { int err; struct pstore_info *psi = inode->i_private; err = mutex_lock_interruptible(&psi->lock); if (err) return err; err = simple_unlink(d_inode(psi->pstore_fs), dentry); if (!err) { struct pstore_record *record; record = pstore_find_record(psi, dentry->d_name.name); if (record) { pstore_free_record(psi, record); } } mutex_unlock(&psi->lock); return err; } ``` 该函数首先获取了与pstore文件相关联的pstore_info结构体(psi),然后使用该结构体上的互斥锁(psi->lock)来保护并发删除文件。接着,它调用simple_unlink函数来删除文件。如果该操作成功,它会调用pstore_find_record函数来查找与文件相关联的pstore记录。如果找到了该记录,它会调用pstore_free_record函数来释放该记录。 pstore_find_record函数的作用是在pstore记录中查找与指定文件名相对应的记录。它的源代码如下: ``` static struct pstore_record * pstore_find_record(struct pstore_info *psi, const char *name) { struct pstore_record *record; list_for_each_entry(record, &psi->records_list, list) { if (strcmp(record->name, name) == 0) return record; } return NULL; } ``` 该函数首先遍历了与pstore_info结构体相关联的pstore记录列表(psi->records_list),并在其中查找与指定文件名相对应的记录。如果找到了该记录,则返回该记录的指针;否则,返回NULL。 pstore_free_record函数的作用是释放与指定记录相关联的内存。它的源代码如下: ``` static void pstore_free_record(struct pstore_info *psi, struct pstore_record *record) { list_del_init(&record->list); kfree(record->name); kfree(record->buf); kfree(record); psi->records_count--; } ``` 该函数首先从相关联的pstore记录列表(psi->record_list)中删除指定的记录(record),并释放记录相关联的内存。最后,它更新psi->records_count计数器,以反映当前pstore记录的数量。 总之,pstore_unlink函数是一个用于删除pstore文件的重要函数,它的实现依赖于pstore_info结构体、互斥锁、pstore记录以及一些辅助函数(如pstore_find_record和pstore_free_record)。在Linux内核中,pstore_unlink函数被广泛应用于Linux的pstore机制中,以实现删除pstore文件的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值