# 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: block_8c-source.html,v $
    00026  Revision 1.7  2006/12/15 17:47:04  reddawg
    00026  Updates
    00026
    00027  Revision 1.2  2006/12/05 14:10:21  reddawg
    00028  Workign Distro
    00029
    00030  Revision 1.1.1.1  2006/06/01 12:46:17  reddawg
    00031  ubix2
    00032
    00033  Revision 1.2  2005/10/12 00:13:37  reddawg
    00034  Removed
    00035
    00036  Revision 1.1.1.1  2005/09/26 17:24:39  reddawg
    00037  no message
    00038
    00039  Revision 1.6  2004/08/14 11:23:02  reddawg
    00040  Changes
    00041
    00042  Revision 1.5  2004/07/23 09:10:06  reddawg
    00043  ubixfs: cleaned up some functions played with the caching a bit
    00044  vfs:    renamed a bunch of functions
    00045  cleaned up a few misc bugs
    00046
    00047  Revision 1.4  2004/06/04 10:19:42  reddawg
    00048  notes: we compile again, thank g-d anyways i was about to cry
    00049
    00050  Revision 1.3  2004/05/19 15:20:06  reddawg
    00051  Fixed reference problems due to changes in drive subsystem
    00052
    00053  Revision 1.2  2004/04/28 02:22:55  reddawg
    00054  This is a fiarly large commit but we are starting to use new driver model
    00055  all around
    00056
    00057  Revision 1.1.1.1  2004/04/15 12:07:07  reddawg
    00058  UbixOS v1.0
    00059
    00060  Revision 1.3  2004/04/13 16:36:34  reddawg
    00061  Changed our copyright, it is all now under a BSD-Style license
    00062
    00063
    00064
    00065  $Id: block_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00066
    00067 *****************************************************************************************/
    00068
    00069 #include <ubixfs/ubixfs.h>
    00070 #include <vfs/file.h>
    00071 #include <vfs/mount.h>
    00072
    00073
    00074 void syncBat(struct vfs_mountPoint *mp) {
    00075   struct ubixFSInfo *fsInfo = mp->fsInfo;
    00076   mp->device->devInfo->write(mp->device->devInfo->info,fsInfo->blockAllocationTable,mp->diskLabel->partitions[mp->partition].pOffset,mp->diskLabel->partitions[mp->partition].pBatSize);
    00077   }
    00078
    00079 int freeBlocks(int block,fileDescriptor *fd) {
    00080   int i = block;
    00081
    00082   struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
    00083
    00084   while (i != 0x0) {
    00085     block = fsInfo->blockAllocationTable[i].nextBlock;
    00086
    00087     fsInfo->blockAllocationTable[i].attributes = 0x0;
    00088     fsInfo->blockAllocationTable[i].nextBlock  = 0x0;
    00089
    00090     i = block;
    00091     }
    00092   syncBat(fd->mp);
    00093   return(i);
    00094   }
    00095
    00096 int getFreeBlocks(int count,fileDescriptor *fd) {
    00097   uInt32 i = 0x0;
    00098   uInt32 x = 0x0;
    00099
    00100   struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
    00101
    00102   getBlocks:
    00103   for (i=1;i < fsInfo->batEntries;i++) {
    00104     if (fsInfo->blockAllocationTable[i].attributes == 0x0) {
    00105       for (x = 1; x < (uInt32)count; x++) {
    00106         if (fsInfo->blockAllocationTable[i + x].attributes != 0x0) {
    00107           goto getBlocks;
    00108           }
    00109         }
    00110       for (x = i; x < i+count;x++) {
    00111         fsInfo->blockAllocationTable[x].attributes = 0x1;
    00112         if ((x+1) == (i+count)) {
    00113           fsInfo->blockAllocationTable[x].nextBlock = -1;
    00114           }
    00115         else {
    00116           fsInfo->blockAllocationTable[x].nextBlock  = x+1;
    00117           }
    00118         }
    00119       syncBat(fd->mp);
    00120       return(i);
    00121       }
    00122     }
    00123   return(0x0);
    00124   }
    00125
    00126 /***
    00127  END
    00128  ***/
    00129