f78d8e74fd
A new call to vm lets processes yield a part of their memory to vm, together with an id, getting newly allocated memory in return. vm is allowed to forget about it if it runs out of memory. processes can ask for it back using the same id. (These two operations are normally combined in a single call.) It can be used as a as-big-as-memory-will-allow block cache for filesystems, which is how mfs now uses it.
58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
#include "fs.h"
|
|
#include <fcntl.h>
|
|
#include <assert.h>
|
|
#include <minix/vfsif.h>
|
|
#include <minix/fsctl.h>
|
|
#include "buf.h"
|
|
#include "inode.h"
|
|
|
|
|
|
/*===========================================================================*
|
|
* fs_sync *
|
|
*===========================================================================*/
|
|
PUBLIC int fs_sync()
|
|
{
|
|
/* Perform the sync() system call. Flush all the tables.
|
|
* The order in which the various tables are flushed is critical. The
|
|
* blocks must be flushed last, since rw_inode() leaves its results in
|
|
* the block cache.
|
|
*/
|
|
struct inode *rip;
|
|
struct buf *bp;
|
|
|
|
assert(nr_bufs > 0);
|
|
assert(buf);
|
|
|
|
/* Write all the dirty inodes to the disk. */
|
|
for(rip = &inode[0]; rip < &inode[NR_INODES]; rip++)
|
|
if(rip->i_count > 0 && rip->i_dirt == DIRTY) rw_inode(rip, WRITING);
|
|
|
|
/* Write all the dirty blocks to the disk, one drive at a time. */
|
|
for(bp = &buf[0]; bp < &buf[nr_bufs]; bp++)
|
|
if(bp->b_dev != NO_DEV && bp->b_dirt == DIRTY)
|
|
flushall(bp->b_dev);
|
|
|
|
return(OK); /* sync() can't fail */
|
|
}
|
|
|
|
|
|
/*===========================================================================*
|
|
* fs_flush *
|
|
*===========================================================================*/
|
|
PUBLIC int fs_flush()
|
|
{
|
|
/* Flush the blocks of a device from the cache after writing any dirty blocks
|
|
* to disk.
|
|
*/
|
|
dev_t dev;
|
|
|
|
dev = fs_m_in.REQ_DEV;
|
|
if(dev == fs_dev) return(EBUSY);
|
|
|
|
flushall(dev);
|
|
invalidate(dev);
|
|
|
|
return(OK);
|
|
}
|
|
|