资源简介
麻雀虽小五脏俱全 linux内核较早的源码 值得学习
代码片段和文件信息
/*
* linux/fs/bitmap.c
*
* (C) 1991 Linus Torvalds
*/
/* bitmap.c contains the code that handles the inode and block bitmaps */
#include
#include
#include
#define clear_block(addr) \
__asm__(“cld\n\t“ \
“rep\n\t“ \
“stosl“ \
::“a“ (0)“c“ (BLOCK_SIZE/4)“D“ ((long) (addr)):“cx““di“)
#define set_bit(nraddr) ({\
register int res __asm__(“ax“); \
__asm__ __volatile__(“btsl %2%3\n\tsetb %%al“: \
“=a“ (res):“0“ (0)“r“ (nr)“m“ (*(addr))); \
res;})
#define clear_bit(nraddr) ({\
register int res __asm__(“ax“); \
__asm__ __volatile__(“btrl %2%3\n\tsetnb %%al“: \
“=a“ (res):“0“ (0)“r“ (nr)“m“ (*(addr))); \
res;})
#define find_first_zero(addr) ({ \
int __res; \
__asm__(“cld\n“ \
“1:\tlodsl\n\t“ \
“notl %%eax\n\t“ \
“bsfl %%eax%%edx\n\t“ \
“je 2f\n\t“ \
“addl %%edx%%ecx\n\t“ \
“jmp 3f\n“ \
“2:\taddl $32%%ecx\n\t“ \
“cmpl $8192%%ecx\n\t“ \
“jl 1b\n“ \
“3:“ \
:“=c“ (__res):“c“ (0)“S“ (addr):“ax““dx““si“); \
__res;})
int free_block(int dev int block)
{
struct super_block * sb;
struct buffer_head * bh;
if (!(sb = get_super(dev)))
panic(“trying to free block on nonexistent device“);
if (block < sb->s_firstdatazone || block >= sb->s_nzones)
panic(“trying to free block not in datazone“);
bh = get_hash_table(devblock);
if (bh) {
if (bh->b_count > 1) {
brelse(bh);
return 0;
}
bh->b_dirt=0;
bh->b_uptodate=0;
if (bh->b_count)
brelse(bh);
}
block -= sb->s_firstdatazone - 1 ;
if (clear_bit(block&8191sb->s_zmap[block/8192]->b_data)) {
printk(“block (%04x:%d) “devblock+sb->s_firstdatazone-1);
printk(“free_block: bit already cleared\n“);
}
sb->s_zmap[block/8192]->b_dirt = 1;
return 1;
}
int new_block(int dev)
{
struct buffer_head * bh;
struct super_block * sb;
int ij;
if (!(sb = get_super(dev)))
panic(“trying to get new block from nonexistant device“);
j = 8192;
for (i=0 ; i<8 ; i++)
if (bh=sb->s_zmap[i])
if ((j=find_first_zero(bh->b_data))<8192)
break;
if (i>=8 || !bh || j>=8192)
return 0;
if (set_bit(jbh->b_data))
panic(“new_block: bit already set“);
bh->b_dirt = 1;
j += i*8192 + sb->s_firstdatazone-1;
if (j >= sb->s_nzones)
return 0;
if (!(bh=getblk(devj)))
panic(“new_block: cannot get block“);
if (bh->b_count != 1)
panic(“new block: count is != 1“);
clear_block(bh->b_data);
bh->b_uptodate = 1;
bh->b_dirt = 1;
brelse(bh);
return j;
}
void free_inode(struct m_inode * inode)
{
struct super_block * sb;
struct buffer_head * bh;
if (!inode)
return;
if (!inode->i_dev) {
memset(inode0sizeof(*inode));
return;
}
if (inode->i_count>1) {
printk(“trying to free inode with count=%d\n“inode->i_count);
panic(“free_inode“);
}
if (inode->i_nlinks)
panic(“trying to free inode with links“);
if (!(sb = get_super(inode->i_dev)))
panic(“trying to free inode on nonexistent device“);
if (inode->i_num < 1 || inode->i_num > sb->s_ninodes)
panic(“trying to free inode 0 or nonexistant inode“);
相关资源
- 剖析Linux系统下基于NUMA构建的服务
- linux SPI设备注册和驱动小结
- 周立功PCI CAN卡LINUX驱动ubuntu16.04内核
- 实现Windows与Linux两系统间自由切换
- 在双引导Linux系统上实现OS自动切换
- 如何删除Linux系统后找回Windows的启动
- Linux命令详解,循序渐进Linux
- Linux系统文件命令精通指南(下)
- Linux系统命令及Shell脚本实践指南
- RK3308 LINUX开发者指南(1).pdf
- S3C4510 开发板中uCLinux系统开发
- 嵌入式操作系统的解析
- Linux点阵字库和字库生成器.rar
- Linux-UNIX系统编程手册上、下册中文版
- 基于ARM的电子相册源码含动态库可运
- PSFTP.EXE 工具
- 如何实现Linux与windows文件互传
- Linux内核函数Start_kernel()的功能
- 一只老鸟的嵌入式ARM学习心得
- cximage的linux版本源码
- yaf-2.1.17.tgz
- IBM eServer xSeries 445 EXP400在Linux下的双
- 如何在本地无光驱软驱时通过PXE远程
- Linux操作系统下配置无密码的RSH访问
- 如何利用mdadm在Linux中配置RAID
- db2 v9.5 linux 许可证
- linux telnet服务安装包
- SUSE Linux Enterprise——助力曙光高
- 运行LINUX的中高端HP INTEGRITY服务器
- lsoflist open files命令
评论
共有 条评论