2009-10-01 16:00:27 +02:00
|
|
|
/* The file system maintains a buffer cache to reduce the number of disk
|
|
|
|
* accesses needed. Whenever a read or write to the disk is done, a check is
|
|
|
|
* first made to see if the block is in the cache. This file manages the
|
|
|
|
* cache.
|
|
|
|
*
|
|
|
|
* The entry points into this file are:
|
|
|
|
* get_block: request to fetch a block for reading or writing from cache
|
|
|
|
* put_block: return a block previously requested with get_block
|
|
|
|
*
|
|
|
|
* Private functions:
|
|
|
|
* read_block: read physically the block
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "inc.h"
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/u64.h>
|
2011-11-09 14:29:12 +01:00
|
|
|
#include <minix/bdev.h>
|
2009-10-01 16:00:27 +02:00
|
|
|
#include "buf.h"
|
|
|
|
|
|
|
|
FORWARD _PROTOTYPE(int read_block, (struct buf *));
|
|
|
|
|
|
|
|
PUBLIC struct buf *bp_to_pickup = buf; /* This is a pointer to the next node in the
|
|
|
|
* buffer cache to pick up*/
|
|
|
|
|
- Introduce support for sticky bit.
- Revise VFS-FS protocol and update VFS/MFS/ISOFS accordingly.
- Clean up MFS by removing old, dead code (backwards compatibility is broken by
the new VFS-FS protocol, anyway) and rewrite other parts. Also, make sure all
functions have proper banners and prototypes.
- VFS should always provide a (syntactically) valid path to the FS; no need for
the FS to do sanity checks when leaving/entering mount points.
- Fix several bugs in MFS:
- Several path lookup bugs in MFS.
- A link can be too big for the path buffer.
- A mountpoint can become inaccessible when the creation of a new inode
fails, because the inode already exists and is a mountpoint.
- Introduce support for supplemental groups.
- Add test 46 to test supplemental group functionality (and removed obsolete
suppl. tests from test 2).
- Clean up VFS (not everything is done yet).
- ISOFS now opens device read-only. This makes the -r flag in the mount command
unnecessary (but will still report to be mounted read-write).
- Introduce PipeFS. PipeFS is a new FS that handles all anonymous and
named pipes. However, named pipes still reside on the (M)FS, as they are part
of the file system on disk. To make this work VFS now has a concept of
'mapped' inodes, which causes read, write, truncate and stat requests to be
redirected to the mapped FS, and all other requests to the original FS.
2009-12-20 21:27:14 +01:00
|
|
|
|
2009-10-01 16:00:27 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_block *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC struct buf *get_block(block)
|
|
|
|
register block_t block; /* which block is wanted? */
|
|
|
|
{
|
|
|
|
register struct buf *bp, *free_bp;
|
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
free_bp = NULL;
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
/* Find if the block is already loaded */
|
|
|
|
for (bp = &buf[0]; bp < &buf[NR_BUFS]; bp++)
|
|
|
|
if (bp->b_blocknr == block) {
|
|
|
|
/* Block found. Increment count and return it */
|
|
|
|
bp->b_count++;
|
|
|
|
return bp;
|
|
|
|
} else
|
|
|
|
if (bp == bp_to_pickup) {
|
|
|
|
if (bp->b_count == 0)
|
|
|
|
free_bp = bp;
|
|
|
|
else /* Increment the node to pickup */
|
|
|
|
if (bp_to_pickup < &buf[NR_BUFS] - 1)
|
|
|
|
bp_to_pickup++;
|
|
|
|
else
|
|
|
|
bp_to_pickup = buf;
|
|
|
|
}
|
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
if (free_bp == NULL &&
|
2009-10-01 16:00:27 +02:00
|
|
|
bp_to_pickup == buf &&
|
|
|
|
bp_to_pickup->b_count == 0)
|
|
|
|
free_bp = bp_to_pickup;
|
|
|
|
|
2010-05-10 15:26:00 +02:00
|
|
|
if (free_bp != NULL) {
|
2009-10-01 16:00:27 +02:00
|
|
|
/* Set fields of data structure */
|
|
|
|
free_bp->b_blocknr = block;
|
2010-05-10 15:26:00 +02:00
|
|
|
if (read_block(free_bp) != OK) return NULL;
|
2009-10-01 16:00:27 +02:00
|
|
|
free_bp->b_count = 1;
|
|
|
|
|
|
|
|
if (bp_to_pickup < &buf[NR_BUFS] - 1)
|
|
|
|
bp_to_pickup++;
|
|
|
|
else
|
|
|
|
bp_to_pickup = buf;
|
|
|
|
|
|
|
|
return free_bp;
|
|
|
|
} else {
|
2010-05-10 15:26:00 +02:00
|
|
|
/* No free blocks. Return NULL */
|
|
|
|
return NULL;
|
2009-10-01 16:00:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* put_block *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC void put_block(bp)
|
|
|
|
register struct buf *bp; /* pointer to the buffer to be released */
|
|
|
|
{
|
2010-05-10 15:26:00 +02:00
|
|
|
if (bp == NULL) return; /* it is easier to check here than in caller */
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
bp->b_count--; /* there is one use fewer now */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* read_block *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int read_block(bp)
|
|
|
|
register struct buf *bp; /* buffer pointer */
|
|
|
|
{
|
2011-11-09 14:29:12 +01:00
|
|
|
int r;
|
2009-10-01 16:00:27 +02:00
|
|
|
u64_t pos;
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
vir_bytes block_size;
|
2009-10-01 16:00:27 +02:00
|
|
|
|
|
|
|
block_size = v_pri.logical_block_size_l; /* The block size is indicated by
|
|
|
|
* the superblock */
|
|
|
|
|
|
|
|
|
|
|
|
pos = mul64u(bp->b_blocknr, block_size); /* get absolute position */
|
2011-11-09 14:29:12 +01:00
|
|
|
r = bdev_read(fs_dev, pos, bp->b_data, block_size, BDEV_NOFLAGS);
|
Split block/character protocols and libdriver
This patch separates the character and block driver communication
protocols. The old character protocol remains the same, but a new
block protocol is introduced. The libdriver library is replaced by
two new libraries: libchardriver and libblockdriver. Their exposed
API, and drivers that use them, have been updated accordingly.
Together, libbdev and libblockdriver now completely abstract away
the message format used by the block protocol. As the memory driver
is both a character and a block device driver, it now implements its
own message loop.
The most important semantic change made to the block protocol is that
it is no longer possible to return both partial results and an error
for a single transfer. This simplifies the interaction between the
caller and the driver, as the I/O vector no longer needs to be copied
back. Also, drivers are now no longer supposed to decide based on the
layout of the I/O vector when a transfer should be cut short. Put
simply, transfers are now supposed to either succeed completely, or
result in an error.
After this patch, the state of the various pieces is as follows:
- block protocol: stable
- libbdev API: stable for synchronous communication
- libblockdriver API: needs slight revision (the drvlib/partition API
in particular; the threading API will also change shortly)
- character protocol: needs cleanup
- libchardriver API: needs cleanup accordingly
- driver restarts: largely unsupported until endpoint changes are
reintroduced
As a side effect, this patch eliminates several bugs, hacks, and gcc
-Wall and -W warnings all over the place. It probably introduces a
few new ones, too.
Update warning: this patch changes the protocol between MFS and disk
drivers, so in order to use old/new images, the MFS from the ramdisk
must be used to mount all file systems.
2011-11-22 13:27:53 +01:00
|
|
|
if (r != (ssize_t) block_size) {
|
|
|
|
if (r == OK) r = END_OF_FILE;
|
|
|
|
else printf("ISOFS(%d) I/O error on device %d/%d, block %u\n",
|
2009-10-01 16:00:27 +02:00
|
|
|
SELF_E, (fs_dev>>MAJOR)&BYTE, (fs_dev>>MINOR)&BYTE,
|
|
|
|
bp->b_blocknr);
|
|
|
|
|
|
|
|
rdwt_err = r;
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|