UbixOS  2.0
directory.c
Go to the documentation of this file.
1 /*****************************************************************************************
2  Copyright (c) 2002-2004 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  $Id: directory.c 79 2016-01-11 16:21:27Z reddawg $
27 
28 *****************************************************************************************/
29 
30 #include <ubixfs/ubixfs.h>
31 #include <vfs/file.h>
32 #include <vfs/mount.h>
33 #include <lib/kmalloc.h>
34 #include <lib/kprintf.h>
35 #include <string.h>
36 
37 static dirList_t dirList = 0x0;
38 
40 ubixFSLoadDir(char *data) {
41  dirList_t tmpDir = 0x0;
42 
43  tmpDir = (dirList_t)kmalloc(sizeof(struct directoryList));
44 
45  sprintf(tmpDir->dirName,"%s",data);
46 
47  if (0x0 == dirList) {
48  dirList = tmpDir;
49  }
50  else {
51  tmpDir->next = dirList;
52  tmpDir->prev = 0x0;
53  dirList->prev = tmpDir;
54  dirList = tmpDir;
55  }
56 
57  if (!strcmp(":",data)) {
58  tmpDir->dirCache = (char *)kmalloc(0x4000);
59  }
60 
61  return(tmpDir);
62  }
63 
64 int
66  uInt32 i = 0x0;
67  uInt32 entries = 0x0;
68  struct directoryEntry *tmp = 0x0;
69 
70  tmp = (struct directoryEntry *)kmalloc(fd->size);
71 
72  readUbixFS(fd,(char *)tmp,fd->offset,fd->size);
73  entries = fd->size/sizeof(struct directoryEntry);
74  for (i=0;(tmp[i].attributes != 0x0) && (i < entries);i++);
75 
76  if (i == entries) {
77  tmp = (struct directoryEntry *)kmalloc(0x1000);
78  i = 0x0;
79  }
80  else {
81  fd->offset = 0x0;
82  }
83  memcpy(&tmp[i],dir,sizeof(struct directoryEntry));
84 
85  if (writeUbixFS(fd,(char *)tmp,fd->offset,fd->size) == 0x0) {
86  kprintf("Error Creating Directory\n");
87  }
88 
89  return(0x0);
90  }
91 
92 int
93 ubixFSmkDir(char *directory,fileDescriptor_t *fd) {
94  int block = 0x0;
95 
96  struct directoryEntry *dir = 0x0;
97  struct directoryEntry *entry = 0x0;
98  struct ubixFSInfo *fsInfo = fd->mp->fsInfo;
99 
100  //kprintf("Creating Directory: %s",directory);
101 
102  block = getFreeBlocks(1,fd);
103  if (block != 0x0) {
105  entry = (struct directoryEntry *)kmalloc(sizeof(struct directoryEntry));
106 
107  entry->startCluster = block;
108  entry->size = UBIXFS_BLOCKSIZE_BYTES;
109  entry->attributes = typeDirectory;
110  entry->permissions = 0xEAA;
111  sprintf(entry->fileName, directory);
112 
113  //dir->attributes = typeDirectory;
114  //sprintf(dir->fileName,"Test Entry");
115 
116  fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,
117  dir,
119  blockSize);
120  addDirEntry(entry,fd);
121  kfree(dir);
122  kfree(entry);
123  }
124 
125  return(0x0);
126  }
127 
128 /***
129  $Log: directory.c,v $
130  Revision 1.1.1.1 2006/06/01 12:46:17 reddawg
131  ubix2
132 
133  Revision 1.2 2005/10/12 00:13:37 reddawg
134  Removed
135 
136  Revision 1.1.1.1 2005/09/26 17:24:41 reddawg
137  no message
138 
139  Revision 1.12 2004/08/14 11:23:02 reddawg
140  Changes
141 
142  Revision 1.11 2004/08/01 17:58:39 flameshadow
143  chg: fixed string allocation bug in ubixfs_cacheNew()
144 
145  Revision 1.10 2004/07/23 09:10:06 reddawg
146  ubixfs: cleaned up some functions played with the caching a bit
147  vfs: renamed a bunch of functions
148  cleaned up a few misc bugs
149 
150  Revision 1.9 2004/07/16 20:17:29 flameshadow
151  chg: broke the ufs stuff
152  chg: changed vfsRegisterFS() to accept a fileSystem struct
153  chg: modified calls to vfsRegisterFS() to pass fileSystem struct
154 
155  Revision 1.8 2004/06/29 03:59:47 reddawg
156  Fixed a few issues with subdirectories they are working much better now
157 
158  Revision 1.7 2004/06/28 23:12:58 reddawg
159  file format now container:/path/to/file
160 
161  Revision 1.6 2004/06/04 13:20:22 reddawg
162  ubixFSmkDir(): played with it a bit to see if it still worked
163 
164  Revision 1.5 2004/06/04 10:19:42 reddawg
165  notes: we compile again, thank g-d anyways i was about to cry
166 
167  Revision 1.4 2004/05/19 15:20:06 reddawg
168  Fixed reference problems due to changes in drive subsystem
169 
170  Revision 1.3 2004/05/19 04:07:43 reddawg
171  kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been
172 
173  Revision 1.2 2004/04/28 02:22:55 reddawg
174  This is a fiarly large commit but we are starting to use new driver model
175  all around
176 
177  Revision 1.1.1.1 2004/04/15 12:07:07 reddawg
178  UbixOS v1.0
179 
180  Revision 1.6 2004/04/13 16:36:34 reddawg
181  Changed our copyright, it is all now under a BSD-Style license
182 
183  END
184  ***/
directoryList::dirCache
char * dirCache
Definition: ubixfs.h:55
typeDirectory
#define typeDirectory
Definition: ubixfs.h:49
directoryList::next
struct directoryList * next
Definition: ubixfs.h:57
dirList_t
struct directoryList * dirList_t
Definition: ubixfs.h:61
directoryEntry::permissions
uInt16 permissions
Definition: ubixfs.h:106
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
file.h
string.h
fileDescriptor::offset
off_t offset
Definition: file.h:69
directoryEntry::fileName
char fileName[256]
Definition: ubixfs.h:107
fileDescriptor
Definition: file.h:62
ubixFSInfo
Definition: ubixfs.h:125
kfree
void kfree(void *baseAddr)
Definition: kmalloc.c:342
strcmp
int strcmp(const char *str1, const char *str2)
directoryList::dirName
char dirName[256]
Definition: ubixfs.h:54
directoryList::prev
struct directoryList * prev
Definition: ubixfs.h:58
directoryEntry::attributes
uInt16 attributes
Definition: ubixfs.h:105
directoryEntry
Definition: ubixfs.h:98
ubixDiskLabel::partitions
struct ubixDiskLabel::ubixPartitions partitions[16]
vfs_mountPoint::diskLabel
struct ubixDiskLabel * diskLabel
Definition: mount.h:71
blockSize
#define blockSize
Definition: ubixfs.h:43
ubixDiskLabel::ubixPartitions::pOffset
uInt32 pOffset
Definition: ubixfs.h:74
directoryList
Definition: ubixfs.h:53
writeUbixFS
int writeUbixFS(fileDescriptor_t *fd, char *data, long offset, long size)
Definition: ubixfs.c:229
ubixFSmkDir
int ubixFSmkDir(char *directory, fileDescriptor_t *fd)
Definition: directory.c:92
memcpy
void * memcpy(const void *dst, const void *src, size_t length)
fileDescriptor::mp
struct vfs_mountPoint * mp
Definition: file.h:65
sprintf
int sprintf(char *buf, const char *fmt,...)
Definition: kprintf.c:278
kprintf.h
readUbixFS
int readUbixFS(fileDescriptor_t *fd, char *data, uInt32 offset, long size)
Definition: ubixfs.c:192
UBIXFS_BLOCKSIZE_BYTES
#define UBIXFS_BLOCKSIZE_BYTES
Definition: ubixfs.h:38
directoryEntry::startCluster
uInt32 startCluster
Definition: ubixfs.h:99
getFreeBlocks
int getFreeBlocks(int count, fileDescriptor_t *fd)
Definition: block.c:95
vfs_mountPoint::partition
int partition
Definition: mount.h:73
blockAllocationTableEntry::realSector
long realSector
Definition: ubixfs.h:92
device_interface::write
int(* write)(void *, void *, uInt32, uInt32)
Definition: device.h:53
ubixFSLoadDir
dirList_t ubixFSLoadDir(char *data)
Definition: directory.c:39
ubixfs.h
vfs_mountPoint::fsInfo
void * fsInfo
Definition: mount.h:72
addDirEntry
int addDirEntry(struct directoryEntry *dir, fileDescriptor_t *fd)
Definition: directory.c:64
device_interface::info
void * info
Definition: device.h:51
vfs_mountPoint::device
struct device_node * device
Definition: mount.h:70
kmalloc
void * kmalloc(uInt32 len)
Definition: kmalloc.c:241
ubixFSInfo::blockAllocationTable
struct blockAllocationTableEntry * blockAllocationTable
Definition: ubixfs.h:126
mount.h
device_node::devInfo
struct device_interface * devInfo
Definition: device.h:37
directoryEntry::size
uInt32 size
Definition: ubixfs.h:100
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
fileDescriptor::size
uint32_t size
Definition: file.h:70
kmalloc.h