block.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002 The UbixOS Project
00003  All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are
00006 permitted provided that the following conditions are met:
00007 
00008 Redistributions of source code must retain the above copyright notice, this list of
00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010 form must reproduce the above copyright notice, this list of conditions, the following
00011 disclaimer and the list of authors in the documentation and/or other materials provided
00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
00013 contributors may be used to endorse or promote products derived from this software
00014 without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Log$
00027  Revision 1.1.1.1  2006/06/01 12:46:17  reddawg
00028  ubix2
00029 
00030  Revision 1.2  2005/10/12 00:13:37  reddawg
00031  Removed
00032 
00033  Revision 1.1.1.1  2005/09/26 17:24:39  reddawg
00034  no message
00035 
00036  Revision 1.6  2004/08/14 11:23:02  reddawg
00037  Changes
00038 
00039  Revision 1.5  2004/07/23 09:10:06  reddawg
00040  ubixfs: cleaned up some functions played with the caching a bit
00041  vfs:    renamed a bunch of functions
00042  cleaned up a few misc bugs
00043 
00044  Revision 1.4  2004/06/04 10:19:42  reddawg
00045  notes: we compile again, thank g-d anyways i was about to cry
00046 
00047  Revision 1.3  2004/05/19 15:20:06  reddawg
00048  Fixed reference problems due to changes in drive subsystem
00049 
00050  Revision 1.2  2004/04/28 02:22:55  reddawg
00051  This is a fiarly large commit but we are starting to use new driver model
00052  all around
00053 
00054  Revision 1.1.1.1  2004/04/15 12:07:07  reddawg
00055  UbixOS v1.0
00056 
00057  Revision 1.3  2004/04/13 16:36:34  reddawg
00058  Changed our copyright, it is all now under a BSD-Style license
00059 
00060 
00061 
00062  $Id$
00063 
00064 *****************************************************************************************/
00065 
00066 #include <ubixfs/ubixfs.h>
00067 #include <vfs/file.h>
00068 #include <vfs/mount.h>
00069 
00070 
00071 void syncBat(vfs_mountPoint_t *mp) {
00072   struct ubixFSInfo *fsInfo = mp->fsInfo;
00073   mp->device->devInfo->write(mp->device->devInfo->info,fsInfo->blockAllocationTable,mp->diskLabel->partitions[mp->partition].pOffset,mp->diskLabel->partitions[mp->partition].pBatSize);
00074   }
00075 
00076 int freeBlocks(int block,fileDescriptor *fd) {
00077   int i = block;
00078   
00079   struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
00080 
00081   while (i != 0x0) {
00082     block = fsInfo->blockAllocationTable[i].nextBlock;
00083         
00084     fsInfo->blockAllocationTable[i].attributes = 0x0;
00085     fsInfo->blockAllocationTable[i].nextBlock  = 0x0;
00086     
00087     i = block;
00088     }
00089   syncBat(fd->mp);
00090   return(i);
00091   }
00092   
00093 int getFreeBlocks(int count,fileDescriptor *fd) {
00094   uInt32 i = 0x0;
00095   uInt32 x = 0x0;
00096   
00097   struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
00098 
00099   getBlocks:
00100   for (i=1;i < fsInfo->batEntries;i++) {
00101     if (fsInfo->blockAllocationTable[i].attributes == 0x0) {
00102       for (x = 1; x < (uInt32)count; x++) {
00103         if (fsInfo->blockAllocationTable[i + x].attributes != 0x0) {
00104           goto getBlocks;
00105           }
00106         }
00107       for (x = i; x < i+count;x++) {
00108         fsInfo->blockAllocationTable[x].attributes = 0x1;
00109         if ((x+1) == (i+count)) {
00110           fsInfo->blockAllocationTable[x].nextBlock = -1;
00111           }
00112         else {
00113           fsInfo->blockAllocationTable[x].nextBlock  = x+1;
00114           }
00115         }
00116       syncBat(fd->mp);
00117       return(i);
00118       }
00119     }
00120   return(0x0);
00121   }
00122 
00123 /***
00124  END
00125  ***/
00126 

Generated on Sun Dec 3 02:38:05 2006 for UbixOS V2 by  doxygen 1.4.7