2002-07-19 07:55:07 +04:00
|
|
|
#include "swapFileManager.h"
|
2002-07-25 05:27:00 +04:00
|
|
|
#include <stdio.h>
|
2002-07-30 05:39:50 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2002-08-28 05:34:19 +04:00
|
|
|
#include <new.h>
|
2002-08-27 00:14:54 +04:00
|
|
|
#include <vnodePool.h>
|
2002-09-05 07:26:02 +04:00
|
|
|
#include "vmHeaderBlock.h"
|
2002-08-27 00:14:54 +04:00
|
|
|
|
2002-09-05 07:26:02 +04:00
|
|
|
extern vmHeaderBlock *vmBlock;
|
2002-07-19 07:55:07 +04:00
|
|
|
|
|
|
|
swapFileManager::swapFileManager(void)
|
|
|
|
{
|
2002-07-30 05:39:50 +04:00
|
|
|
swapFile = open("/boot/var/tmp/OBOS_swap",O_RDWR|O_CREAT,0x777 );
|
|
|
|
if (swapFile==-1)
|
2002-09-16 07:14:44 +04:00
|
|
|
error ("swapfileManager::swapFileManger: swapfile not opened, errno = %ul, %s\n",errno,strerror(errno));
|
2002-08-07 07:21:02 +04:00
|
|
|
lockFreeList=create_sem(1,"SwapFile Free List Semaphore"); // Should have team name in it.
|
2002-07-19 07:55:07 +04:00
|
|
|
}
|
|
|
|
|
2002-08-07 07:21:02 +04:00
|
|
|
vnode &swapFileManager::findNode(void)
|
2002-07-19 07:55:07 +04:00
|
|
|
{
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("swapFileManager::findNode: Entering findNode \n");
|
2002-08-07 07:21:02 +04:00
|
|
|
//swapFileFreeList.dump();
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("swapFileManager::findNode: Finding a new node for you, Master: ");
|
2002-08-07 07:21:02 +04:00
|
|
|
vnode *newNode;
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("locking in sfm\n");
|
2002-10-03 07:42:59 +04:00
|
|
|
lock();
|
2002-08-26 07:12:35 +04:00
|
|
|
newNode=reinterpret_cast<vnode *>(swapFileFreeList.next());
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("unlocking in sfm\n");
|
2002-10-03 07:42:59 +04:00
|
|
|
unlock();
|
2002-08-26 07:12:35 +04:00
|
|
|
if (!newNode)
|
2002-08-07 07:21:02 +04:00
|
|
|
{
|
2002-09-05 07:26:02 +04:00
|
|
|
newNode=new (vmBlock->vnodePool->get()) vnode;
|
2002-08-07 07:21:02 +04:00
|
|
|
newNode->fd=swapFile;
|
|
|
|
newNode->offset=maxNode+=PAGE_SIZE;
|
2002-09-16 07:14:44 +04:00
|
|
|
//error (" New One: %d\n",newNode->offset);
|
2002-08-07 07:21:02 +04:00
|
|
|
}
|
2002-08-26 07:12:35 +04:00
|
|
|
newNode->valid=false;
|
2002-09-16 07:14:44 +04:00
|
|
|
newNode->count=1;
|
|
|
|
//error ("swapFileManager::findNode: swapFileFreeList is now: ");
|
2002-08-07 07:21:02 +04:00
|
|
|
//swapFileFreeList.dump();
|
|
|
|
return *newNode;
|
2002-07-19 07:55:07 +04:00
|
|
|
}
|
2002-07-31 06:20:33 +04:00
|
|
|
|
2002-08-07 07:21:02 +04:00
|
|
|
void swapFileManager::freeVNode(vnode &v)
|
2002-07-31 06:20:33 +04:00
|
|
|
{
|
2002-10-03 07:42:59 +04:00
|
|
|
if ( atomic_add(&v.count,-1)==1)
|
2002-08-26 07:12:35 +04:00
|
|
|
{
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("locking in sfm\n");
|
2002-10-03 07:42:59 +04:00
|
|
|
lock();
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("swapFileManager::freeNode: Starting Freeing a new node for you, Master: offset:%d\n",v.offset);
|
2002-08-26 07:12:35 +04:00
|
|
|
v.valid=false;
|
|
|
|
swapFileFreeList.add(&v);
|
2002-09-16 07:14:44 +04:00
|
|
|
//error ("unlocking in sfm\n");
|
2002-10-03 07:42:59 +04:00
|
|
|
unlock();
|
2002-08-26 07:12:35 +04:00
|
|
|
}
|
2002-07-31 06:20:33 +04:00
|
|
|
}
|