2002-07-19 07:55:07 +04:00
|
|
|
#include "swapFileManager.h"
|
2002-07-25 05:27:00 +04:00
|
|
|
#include <stdio.h>
|
2002-07-19 07:55:07 +04:00
|
|
|
|
|
|
|
swapFileManager::swapFileManager(void)
|
|
|
|
{
|
2002-07-25 05:27:00 +04:00
|
|
|
swapFile = open("/boot/var/tmp/OBOS_swap",O_RDWR );
|
2002-07-19 07:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void swapFileManager::write_block(vnode node,void *loc,unsigned long size)
|
|
|
|
{
|
2002-07-30 04:29:00 +04:00
|
|
|
printf ("swapFileManager::write_block: writing, node.fd = %d, node.offset = %d\n",node.fd, node.offset);
|
2002-07-19 07:55:07 +04:00
|
|
|
lseek(node.fd,SEEK_SET,node.offset);
|
|
|
|
write(node.fd,loc,size);
|
2002-07-30 04:29:00 +04:00
|
|
|
node.valid=true;
|
2002-07-19 07:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void swapFileManager::read_block(vnode node,void *loc,unsigned long size)
|
|
|
|
{
|
2002-07-30 04:29:00 +04:00
|
|
|
printf ("swapFileManager::read_block: reading, node.fd = %d, node.offset = %d\n",node.fd, node.offset);
|
2002-07-19 07:55:07 +04:00
|
|
|
lseek(node.fd,SEEK_SET,node.offset);
|
2002-07-30 04:29:00 +04:00
|
|
|
if (node.valid==false)
|
|
|
|
return; // Do nothing. This prevents "garbage" data on disk from being read in...
|
2002-07-19 07:55:07 +04:00
|
|
|
read(node.fd,loc,size);
|
|
|
|
}
|
|
|
|
|
|
|
|
vnode swapFileManager::findNode(void)
|
|
|
|
{
|
2002-07-30 04:29:00 +04:00
|
|
|
printf ("swapFileManager::findNode: Finding a new node for you, Master\n");
|
2002-07-19 07:55:07 +04:00
|
|
|
vnode tmp;
|
|
|
|
tmp.fd=swapFile;
|
|
|
|
tmp.offset=maxNode+=PAGE_SIZE; // Can't ever free, swap file grows forever... :-(
|
2002-07-30 04:29:00 +04:00
|
|
|
tmp.valid=false;
|
2002-07-19 07:55:07 +04:00
|
|
|
return tmp;
|
|
|
|
}
|