⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 block_dev.c

📁 早期linux0.95内核的源代码
💻 C
字号:
/* *  linux/fs/block_dev.c * *  (C) 1991  Linus Torvalds */#include <errno.h>#include <linux/sched.h>#include <linux/kernel.h>#include <asm/segment.h>#include <asm/system.h>extern int *blk_size[];int block_write(struct inode * inode, struct file * filp, char * buf, int count){	int block = filp->f_pos >> BLOCK_SIZE_BITS;	int offset = filp->f_pos & (BLOCK_SIZE-1);	int chars;	int written = 0;	int size;	unsigned int dev;	struct buffer_head * bh;	register char * p;	dev = inode->i_rdev;	if (blk_size[MAJOR(dev)])		size = blk_size[MAJOR(dev)][MINOR(dev)];	else		size = 0x7fffffff;	while (count>0) {		if (block >= size)			return written;		chars = BLOCK_SIZE - offset;		if (chars > count)			chars=count;		if (chars == BLOCK_SIZE)			bh = getblk(dev,block);		else			bh = breada(dev,block,block+1,block+2,-1);		block++;		if (!bh)			return written?written:-EIO;		p = offset + bh->b_data;		offset = 0;		filp->f_pos += chars;		written += chars;		count -= chars;		while (chars-->0)			*(p++) = get_fs_byte(buf++);		bh->b_dirt = 1;		brelse(bh);	}	return written;}int block_read(struct inode * inode, struct file * filp, char * buf, int count){	unsigned int block = filp->f_pos >> BLOCK_SIZE_BITS;	unsigned int offset = filp->f_pos & (BLOCK_SIZE-1);	unsigned int chars;	unsigned int size;	unsigned int dev;	int read = 0;	struct buffer_head * bh;	register char * p;	dev = inode->i_rdev;	if (blk_size[MAJOR(dev)])		size = blk_size[MAJOR(dev)][MINOR(dev)];	else		size = 0x7fffffff;	while (count>0) {		if (block >= size)			return read;		chars = BLOCK_SIZE-offset;		if (chars > count)			chars = count;		if (!(bh = breada(dev,block,block+1,block+2,-1)))			return read?read:-EIO;		block++;		p = offset + bh->b_data;		offset = 0;		filp->f_pos += chars;		read += chars;		count -= chars;		while (chars-->0)			put_fs_byte(*(p++),buf++);		brelse(bh);	}	return read;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -