UbixOS  2.0
block.c
Go to the documentation of this file.
1 /*****************************************************************************************
2  Copyright (c) 2002 The UbixOS Project
3  All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification, are
6 permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions, the following disclaimer and the list of authors. Redistributions in binary
10 form must reproduce the above copyright notice, this list of conditions, the following
11 disclaimer and the list of authors in the documentation and/or other materials provided
12 with the distribution. Neither the name of the UbixOS Project nor the names of its
13 contributors may be used to endorse or promote products derived from this software
14 without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
17 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
23 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26  $Log: block.c,v $
27  Revision 1.2 2006/12/05 14:10:21 reddawg
28  Workign Distro
29 
30  Revision 1.1.1.1 2006/06/01 12:46:17 reddawg
31  ubix2
32 
33  Revision 1.2 2005/10/12 00:13:37 reddawg
34  Removed
35 
36  Revision 1.1.1.1 2005/09/26 17:24:39 reddawg
37  no message
38 
39  Revision 1.6 2004/08/14 11:23:02 reddawg
40  Changes
41 
42  Revision 1.5 2004/07/23 09:10:06 reddawg
43  ubixfs: cleaned up some functions played with the caching a bit
44  vfs: renamed a bunch of functions
45  cleaned up a few misc bugs
46 
47  Revision 1.4 2004/06/04 10:19:42 reddawg
48  notes: we compile again, thank g-d anyways i was about to cry
49 
50  Revision 1.3 2004/05/19 15:20:06 reddawg
51  Fixed reference problems due to changes in drive subsystem
52 
53  Revision 1.2 2004/04/28 02:22:55 reddawg
54  This is a fiarly large commit but we are starting to use new driver model
55  all around
56 
57  Revision 1.1.1.1 2004/04/15 12:07:07 reddawg
58  UbixOS v1.0
59 
60  Revision 1.3 2004/04/13 16:36:34 reddawg
61  Changed our copyright, it is all now under a BSD-Style license
62 
63 
64 
65  $Id: block.c 54 2016-01-11 01:29:55Z reddawg $
66 
67 *****************************************************************************************/
68 
69 #include <ubixfs/ubixfs.h>
70 #include <vfs/file.h>
71 #include <vfs/mount.h>
72 
73 
74 void syncBat(struct vfs_mountPoint *mp) {
75  struct ubixFSInfo *fsInfo = mp->fsInfo;
77  }
78 
79 int freeBlocks(int block,fileDescriptor_t *fd) {
80  int i = block;
81 
82  struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
83 
84  while (i != 0x0) {
85  block = fsInfo->blockAllocationTable[i].nextBlock;
86 
87  fsInfo->blockAllocationTable[i].attributes = 0x0;
88  fsInfo->blockAllocationTable[i].nextBlock = 0x0;
89 
90  i = block;
91  }
92  syncBat(fd->mp);
93  return(i);
94  }
95 
96 int getFreeBlocks(int count,fileDescriptor_t *fd) {
97  uInt32 i = 0x0;
98  uInt32 x = 0x0;
99 
100  struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
101 
102  getBlocks:
103  for (i=1;i < fsInfo->batEntries;i++) {
104  if (fsInfo->blockAllocationTable[i].attributes == 0x0) {
105  for (x = 1; x < (uInt32)count; x++) {
106  if (fsInfo->blockAllocationTable[i + x].attributes != 0x0) {
107  goto getBlocks;
108  }
109  }
110  for (x = i; x < i+count;x++) {
111  fsInfo->blockAllocationTable[x].attributes = 0x1;
112  if ((x+1) == (i+count)) {
113  fsInfo->blockAllocationTable[x].nextBlock = -1;
114  }
115  else {
116  fsInfo->blockAllocationTable[x].nextBlock = x+1;
117  }
118  }
119  syncBat(fd->mp);
120  return(i);
121  }
122  }
123  return(0x0);
124  }
125 
126 /***
127  END
128  ***/
129 
blockAllocationTableEntry::attributes
long attributes
Definition: ubixfs.h:91
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
file.h
fileDescriptor
Definition: file.h:62
ubixFSInfo
Definition: ubixfs.h:125
ubixDiskLabel::partitions
struct ubixDiskLabel::ubixPartitions partitions[16]
vfs_mountPoint::diskLabel
struct ubixDiskLabel * diskLabel
Definition: mount.h:71
ubixDiskLabel::ubixPartitions::pOffset
uInt32 pOffset
Definition: ubixfs.h:74
fileDescriptor::mp
struct vfs_mountPoint * mp
Definition: file.h:65
syncBat
void syncBat(struct vfs_mountPoint *mp)
Definition: block.c:73
vfs_mountPoint
Definition: mount.h:66
freeBlocks
int freeBlocks(int block, fileDescriptor_t *fd)
Definition: block.c:78
getFreeBlocks
int getFreeBlocks(int count, fileDescriptor_t *fd)
Definition: block.c:95
vfs_mountPoint::partition
int partition
Definition: mount.h:73
device_interface::write
int(* write)(void *, void *, uInt32, uInt32)
Definition: device.h:53
ubixfs.h
vfs_mountPoint::fsInfo
void * fsInfo
Definition: mount.h:72
device_interface::info
void * info
Definition: device.h:51
vfs_mountPoint::device
struct device_node * device
Definition: mount.h:70
ubixFSInfo::blockAllocationTable
struct blockAllocationTableEntry * blockAllocationTable
Definition: ubixfs.h:126
ubixFSInfo::batEntries
uInt32 batEntries
Definition: ubixfs.h:128
mount.h
ubixDiskLabel::ubixPartitions::pBatSize
uInt32 pBatSize
Definition: ubixfs.h:76
device_node::devInfo
struct device_interface * devInfo
Definition: device.h:37
blockAllocationTableEntry::nextBlock
long nextBlock
Definition: ubixfs.h:93