#include <string.h>
#include <minix/endpoint.h>
#include <sys/stat.h>
+#include <sys/param.h>
#include <sys/types.h>
#include "buf.h"
#include "inode.h"
* new pathname.
*/
- block_t blink; /* block containing link text */
size_t llen; /* length of link */
size_t slen; /* length of suffix */
struct buf *bp; /* buffer containing link text */
if (llen >= MAX_FAST_SYMLINK_LENGTH) {
/* normal symlink */
- if ((blink = read_map(rip, (off_t) 0)) == NO_BLOCK)
+ if(!(bp = get_block_map(rip, 0)))
return(EIO);
- bp = get_block(rip->i_dev, blink, NORMAL);
sp = b_data(bp);
} else {
/* fast symlink, stored in inode */
mode_t bits;
off_t pos;
unsigned new_slots;
- block_t b;
int extended = 0;
int required_space = 0;
int string_len = 0;
}
for (; pos < ldir_ptr->i_size; pos += ldir_ptr->i_sp->s_block_size) {
- b = read_map(ldir_ptr, pos); /* get block number */
-
/* Since directories don't have holes, 'b' cannot be NO_BLOCK. */
- bp = get_block(ldir_ptr->i_dev, b, NORMAL); /* get a dir block */
- prev_dp = NULL; /* New block - new first dentry, so no prev. */
-
- if (bp == NO_BLOCK)
+ if(!(bp = get_block_map(ldir_ptr,
+ rounddown(pos, ldir_ptr->i_sp->s_block_size))))
panic("get_block returned NO_BLOCK");
- assert(bp != NULL);
+
+ prev_dp = NULL; /* New block - new first dentry, so no prev. */
/* Search a directory block.
* Note, we set prev_dp at the end of the loop.
/* 'flag' is LOOK_UP */
*numb = (ino_t) conv4(le_CPU, dp->d_ino);
}
+ assert(lmfs_dev(bp) != NO_DEV);
put_block(bp, DIRECTORY_BLOCK);
return(r);
}
}
/* The whole block has been searched or ENTER has a free slot. */
+ assert(lmfs_dev(bp) != NO_DEV);
if (e_hit) break; /* e_hit set if ENTER can be performed now */
put_block(bp, DIRECTORY_BLOCK); /* otherwise, continue searching dir */
}
#include "inode.h"
#include "super.h"
#include <minix/vfsif.h>
+#include <sys/param.h>
#include <assert.h>
#include <sys/param.h>
int n, block_spec;
block_t b;
dev_t dev;
+ ino_t ino = VMC_NO_INODE;
+ u64_t ino_off = rounddown(position, block_size);
/* rw_flag:
* READING: read from FS, copy to user
} else {
if (ex64hi(position) != 0)
panic("rw_chunk: position too high");
- b = read_map(rip, (off_t) ex64lo(position));
+ b = read_map(rip, (off_t) ex64lo(position), 0);
dev = rip->i_dev;
+ ino = rip->i_num;
+ assert(ino != VMC_NO_INODE);
}
if (!block_spec && b == NO_BLOCK) {
n = (chunk == block_size ? NO_READ : NORMAL);
if (!block_spec && off == 0 && (off_t) ex64lo(position) >= rip->i_size)
n = NO_READ;
- bp = get_block(dev, b, n);
+ if(block_spec) {
+ assert(ino == VMC_NO_INODE);
+ bp = get_block(dev, b, n);
+ } else {
+ assert(ino != VMC_NO_INODE);
+ assert(!(ino_off % block_size));
+ bp = lmfs_get_block_ino(dev, b, n, ino, ino_off);
+ }
}
/* In all cases, bp now points to a valid buffer. */
/*===========================================================================*
* read_map *
*===========================================================================*/
-block_t read_map(rip, position)
+block_t read_map(rip, position, opportunistic)
register struct inode *rip; /* ptr to inode to map from */
off_t position; /* position in file whose blk wanted */
+int opportunistic;
{
/* Given an inode and a position within the corresponding file, locate the
* block number in which that position is to be found and return it.
static long doub_ind_s;
static long triple_ind_s;
static long out_range_s;
+ int iomode = NORMAL;
+
+ if(opportunistic) iomode = PREFETCH;
if (first_time) {
addr_in_block = rip->i_sp->s_block_size / BLOCK_ADDRESS_BYTES;
excess = excess % addr_in_block2;
}
if (b == NO_BLOCK) return(NO_BLOCK);
- bp = get_block(rip->i_dev, b, NORMAL); /* get double indirect block */
+ bp = get_block(rip->i_dev, b, iomode); /* get double indirect block */
+ if(opportunistic && lmfs_dev(bp) == NO_DEV) {
+ put_block(bp, INDIRECT_BLOCK);
+ return NO_BLOCK;
+ }
ASSERT(lmfs_dev(bp) != NO_DEV);
ASSERT(lmfs_dev(bp) == rip->i_dev);
index = excess / addr_in_block;
index = excess % addr_in_block; /* index into single ind blk */
}
if (b == NO_BLOCK) return(NO_BLOCK);
- bp = get_block(rip->i_dev, b, NORMAL);
+ bp = get_block(rip->i_dev, b, iomode); /* get single indirect block */
+ if(opportunistic && lmfs_dev(bp) == NO_DEV) {
+ put_block(bp, INDIRECT_BLOCK);
+ return NO_BLOCK;
+ }
+
ASSERT(lmfs_dev(bp) != NO_DEV);
ASSERT(lmfs_dev(bp) == rip->i_dev);
b = rd_indir(bp, index);
return(b);
}
+struct buf *get_block_map(register struct inode *rip, u64_t position)
+{
+ block_t b = read_map(rip, position, 0); /* get block number */
+ int block_size = get_block_size(rip->i_dev);
+ if(b == NO_BLOCK)
+ return NULL;
+ position = rounddown(position, block_size);
+ assert(rip->i_num != VMC_NO_INODE);
+ return lmfs_get_block_ino(rip->i_dev, b, NORMAL, rip->i_num, position);
+}
/*===========================================================================*
* rd_indir *
rip = rdahed_inode; /* pointer to inode to read ahead from */
block_size = get_block_size(rip->i_dev);
rdahed_inode = NULL; /* turn off read ahead */
- if ( (b = read_map(rip, rdahedpos)) == NO_BLOCK) return; /* at EOF */
+ if ( (b = read_map(rip, rdahedpos, 1)) == NO_BLOCK) return; /* at EOF */
assert(rdahedpos >= 0); /* So we can safely cast it to unsigned below */
struct buf *bp = NULL;
static unsigned int readqsize = 0;
static struct buf **read_q = NULL;
+ u64_t position_running;
if(readqsize != nr_bufs) {
if(readqsize > 0) {
else
dev = rip->i_dev;
+ assert(dev != NO_DEV);
block_size = get_block_size(dev);
block = baseblock;
- bp = get_block(dev, block, PREFETCH);
+
+ fragment = position % block_size;
+ position -= fragment;
+ position_running = position;
+ bytes_ahead += fragment;
+ blocks_ahead = (bytes_ahead + block_size - 1) / block_size;
+
+ if(block_spec)
+ bp = get_block(dev, block, PREFETCH);
+ else
+ bp = lmfs_get_block_ino(dev, block, PREFETCH, rip->i_num, position);
+
+
assert(bp != NULL);
if (lmfs_dev(bp) != NO_DEV) return(bp);
* indirect blocks (but don't call read_map!).
*/
- fragment = rem64u(position, block_size);
- position = sub64u(position, fragment);
- bytes_ahead += fragment;
-
- blocks_ahead = (bytes_ahead + block_size - 1) / block_size;
-
if (block_spec && rip->i_size == 0) {
blocks_left = (block_t) NR_IOREQS;
} else {
/* Acquire block buffers. */
for (;;) {
+ block_t thisblock;
read_q[read_q_size++] = bp;
if (--blocks_ahead == 0) break;
if (lmfs_bufs_in_use() >= nr_bufs - 4) break;
block++;
+ position_running += block_size;
- bp = get_block(dev, block, PREFETCH);
+ if(!block_spec &&
+ (thisblock = read_map(rip, (off_t) ex64lo(position_running), 1)) != NO_BLOCK) {
+ bp = lmfs_get_block_ino(dev, thisblock, PREFETCH, rip->i_num, position_running);
+ } else {
+ bp = get_block(dev, block, PREFETCH);
+ }
if (lmfs_dev(bp) != NO_DEV) {
/* Oops, block already in the cache, get out. */
put_block(bp, FULL_DATA_BLOCK);
}
}
lmfs_rw_scattered(dev, read_q, read_q_size, READING);
- return(get_block(dev, baseblock, NORMAL));
+
+ if(block_spec)
+ return get_block(dev, baseblock, NORMAL);
+ return(lmfs_get_block_ino(dev, baseblock, NORMAL, rip->i_num, position));
}
int o, r, done;
unsigned int block_size, len, reclen;
ino_t ino;
- block_t b;
cp_grant_id_t gid;
size_t size, tmpbuf_off, userbuf_off;
off_t pos, off, block_pos, new_pos, ent_pos;
for (; block_pos < rip->i_size; block_pos += block_size) {
off_t temp_pos = block_pos;
- b = read_map(rip, block_pos); /* get block number */
- /* Since directories don't have holes, 'b' cannot be NO_BLOCK. */
- bp = get_block(rip->i_dev, b, NORMAL); /* get a dir block */
+ /* Since directories don't have holes, 'bp' cannot be NULL. */
+ bp = get_block_map(rip, block_pos); /* get a dir block */
+ assert(bp != NULL);
assert(bp != NULL);
/* Search a directory block. */