dev = inode->i_rdev;
blocksize = BLOCK_SIZE;
if (blksize_size[MAJOR(dEv)] && blksize_size[MAJOR(dev)][MINOR(dev)])
blocksize = blksize_size[MAJOR(dev)][MINOR(dev)];
i = blocksize;
blocksize_bits = 0;
while (i != 1) {
blocksize_bits++;
i »= 1;
}
offset = filp->f_pos;
if (blk_size[MAJOR(dev)])
size = (loff_t) blk_size[MAJOR(dev)][MINOR(dev)] « BLOCK_SIZE_BITS;
else
size = INT_MAX;
blocks_per_cluster = PAGE_SIZE / blocksize;
if (offset > size)
left = 0;
/* size - offset might not fit into left, so check explicitly. */
else if (size - offset > INT_MAX)
left = INT_MAX;
else
left = size - offset;
if (left > count)
left = count;
if (left <= 0)
return 0;
read = 0;
block = offset » blocksize_bits;
offset &= blocksize-1;
size »= blocksize_bits;
rblocks = blocks = (left + offset + blocksize - 1) » blocksize_bits;
bhb = bhe = buflist;
if (filp->f_reada) {
if (blocks < read_ahead[MAJOR(dev)] / (blocksize » 9))
blocks = read_ahead[MAJOR(dev)] / (blocksize » 9);
excess = (block + blocks)
% blocks_per_cluster;
if ( blocks > excess )
blocks -= excess;
if (rblocks > blocks)
blocks = rblocks;
}
if (block + blocks > size)
blocks = size - block;
/* We do this in a two stage process. We first try to request as many blocks as we can, then we wait for the first one to complete, and then we try to wrap up as many as are actually done. This routine is rather generic, in that it can be used in a filesystem by substituting the appropriate function in for getblk.
This routine is optimized to make maximum use of the various buffers and caches. */
do {
bhrequest = 0;
uptodate = 1;
while (blocks) {
-blocks;
#if 1
if((block % blocks_per_cluster) == 0){
for(i=0; i<blocks_per_cluster; i++) cluster_list[i] = block+i;
generate_cluster(dev, cluster_list, blocksize);
}
#endif
*bhb = getblk(dev, block++, blocksize);
if (*bhb && !buffer_uptodate(*bhb)) {
uptodate = 0;
bhreq[bhrequest++] = *bhb;
}
if (++bhb == &buflist[NBUF])
bhb = buflist;
/* If the block we have on hand is uptodate, go ahead
and complete processing. */
if (uptodate)
break;
if (bhb == bhe)
break;
}
/* Now request them all */
if (bhrequest) {
ll_rw_block(READ, bhrequest, bhreq);
refill_freelist(blocksize);
}
do { /* Finish off all I/O that has actually completed */
if (*bhe) {
wait_on_buffer(*bhe);
if (!buffer_uptodate(*bhe)) { /* read error? */
brelse(*bhe);
if (++bhe == &buflist[NBUF])
bhe = buflist;
left = 0;
break;
}
}
if (left < blocksize - offset)
chars = left;
else
chars = blocksize - offset;
filp->f_pos += chars;
left -= chars;
read += chars;
if (*bhe) {
copy_to_user(buf,offset+(*bhe)->b_data,chars);
brelse(*bhe);
buf += chars;
} else {
while (chars- > 0)
put_user(0,buf++);
}
offset = 0;
if (++bhe == &buflist[NBUF])
bhe = buflist;
} while (left > 0 && bhe != bhb && (!*bhe || !buffer_locked(*bhe)));
} while (left > 0);
/* Release the read-ahead blocks */
while (bhe != bhb) {
brelse(*bhe);
if (++bhe == &buflist[NBUF])
bhe = buflist;
};
if (!read)
return -EIO;
filp->f_reada = 1;
return read;
}