Search     or:     and:
 LINUX 
 Language 
 Kernel 
 Package 
 Book 
 Test 
 OS 
 Forum 
 iakovlev.org 
      Languages 
      Kernels 
      Packages 
      Books 
      Tests 
      OS 
      Forum 
      Математика 
NEWS
Последние статьи :
  Rust 07.11   
  Go 25.12   
  EXT4 10.11   
  FS benchmark 15.09   
  Сетунь 23.07   
  Trees 25.06   
  Apache 03.02   
  SQL 30.07   
  JFS 10.06   
  B-trees 01.06   
 
TOP 20
 Go Web ...1117 
 Secure Programming for Li...320 
 B-trees...251 
 Ethreal 1...182 
 Advanced Bash Scripting G...174 
 Steve Pate 3...139 
 Стивенс 9...137 
 Ethreal 3...136 
 C++ Faq 3...134 
 Daniel Bovet 2...134 
 Cluster 4...127 
 C++ Patterns 1...125 
 Mod_perl 1...125 
 Robert Love 5...123 
 Advanced Bash Scripting G...122 
 2.6-> Kernel 2.6.19...122 
 Rodriguez 8...121 
 Intel 386...121 
 Rodriguez 3...120 
 B.Blunden 1...119 
 
  01.08.2019 : 2762444 посещений 

www.iakovlev.org

#include < errno.h>
#include < linux/fs.h>
#include < linux/kernel.h>
#include < asm/segment.h>

#define NR_BLK_DEV ((sizeof (rd_blk))/(sizeof (rd_blk[0])))

int block_write(int dev, long * pos, char * buf, int count)
{
	int block = *pos / BLOCK_SIZE;
	int offset = *pos % BLOCK_SIZE;
	int chars;
	int written = 0;
	struct buffer_head * bh;
	register char * p;

	while (count>0) {
		bh = bread(dev,block);
		if (!bh)
			return written?written:-EIO;
		chars = (countb_data;
		offset = 0;
		block++;
		*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(int dev, unsigned long * pos, char * buf, int count)
{
	int block = *pos / BLOCK_SIZE;
	int offset = *pos % BLOCK_SIZE;
	int chars;
	int read = 0;
	struct buffer_head * bh;
	register char * p;

	while (count>0) {
		bh = bread(dev,block);
		if (!bh)
			return read?read:-EIO;
		chars = (countb_data;
		offset = 0;
		block++;
		*pos += chars;
		read += chars;
		count -= chars;
		while (chars-->0)
			put_fs_byte(*(p++),buf++);
		bh->b_dirt = 1;
		brelse(bh);
	}
	return read;
}

extern void rw_hd(int rw, struct buffer_head * bh);

typedef void (*blk_fn)(int rw, struct buffer_head * bh);

static blk_fn rd_blk[]={
	NULL,		/* nodev */
	NULL,		/* dev mem */
	NULL,		/* dev fd */
	rw_hd,		/* dev hd */
	NULL,		/* dev ttyx */
	NULL,		/* dev tty */
	NULL};		/* dev lp */

void ll_rw_block(int rw, struct buffer_head * bh)
{
	blk_fn blk_addr;
	unsigned int major;

	if ((major=MAJOR(bh->b_dev)) >= NR_BLK_DEV || !(blk_addr=rd_blk[major]))
		panic("Trying to read nonexistent block-device");
	blk_addr(rw, bh);
}