directory.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2004 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  $Id: directory_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
00027 
00028 *****************************************************************************************/
00029 
00030 #include <ubixfs/ubixfs.h>
00031 #include <vfs/file.h>
00032 #include <vfs/mount.h>
00033 #include <ubixos/types.h>
00034 #include <lib/kmalloc.h>
00035 #include <lib/kprintf.h>
00036 #include <lib/string.h>
00037 
00038 static dirList_t dirList = 0x0;
00039 
00040 dirList_t 
00041 ubixFSLoadDir(char *data) {
00042   dirList_t tmpDir = 0x0;
00043 
00044   tmpDir = (dirList_t)kmalloc(sizeof(struct directoryList));
00045 
00046   sprintf(tmpDir->dirName,"%s",data);
00047 
00048   if (0x0 == dirList) {
00049     dirList = tmpDir;
00050     }
00051   else {
00052     tmpDir->next = dirList;
00053     tmpDir->prev = 0x0;
00054     dirList->prev = tmpDir;
00055     dirList       = tmpDir;
00056     }
00057 
00058   if (!strcmp(":",data)) {
00059     tmpDir->dirCache = (char *)kmalloc(0x4000);
00060     }
00061 
00062   return(tmpDir);
00063   }
00064 
00065 int 
00066 addDirEntry(struct directoryEntry *dir,fileDescriptor *fd) {
00067   uInt32 i = 0x0;
00068   uInt32 entries = 0x0;
00069   struct directoryEntry *tmp = 0x0;
00070 
00071   tmp = (struct directoryEntry *)kmalloc(fd->size);
00072 
00073   readUbixFS(fd,(char *)tmp,fd->offset,fd->size);
00074   entries = fd->size/sizeof(struct directoryEntry);
00075   for (i=0;(tmp[i].attributes != 0x0) && (i < entries);i++);
00076 
00077   if (i == entries) {
00078     tmp = (struct directoryEntry *)kmalloc(0x1000);
00079     i = 0x0;
00080     }
00081   else {
00082     fd->offset = 0x0;
00083     }
00084   memcpy(&tmp[i],dir,sizeof(struct directoryEntry));
00085   
00086   if (writeUbixFS(fd,(char *)tmp,fd->offset,fd->size) == 0x0) {
00087     kprintf("Error Creating Directory\n");
00088     }
00089   
00090   return(0x0);
00091   }
00092 
00093 int 
00094 ubixFSmkDir(char *directory,fileDescriptor *fd) {
00095   int block = 0x0;
00096 
00097   struct directoryEntry *dir   = 0x0;
00098   struct directoryEntry *entry = 0x0;
00099   struct ubixFSInfo *fsInfo    = fd->mp->fsInfo;
00100 
00101   //kprintf("Creating Directory: %s",directory);
00102   
00103   block = getFreeBlocks(1,fd);
00104   if (block != 0x0) {
00105     dir   = (struct directoryEntry *)kmalloc(UBIXFS_BLOCKSIZE_BYTES);
00106     entry = (struct directoryEntry *)kmalloc(sizeof(struct directoryEntry));
00107 
00108     entry->startCluster = block;
00109     entry->size         = UBIXFS_BLOCKSIZE_BYTES;
00110     entry->attributes   = typeDirectory;
00111     entry->permissions  = 0xEAA;
00112     sprintf(entry->fileName, directory);
00113 
00114     //dir->attributes = typeDirectory;
00115     //sprintf(dir->fileName,"Test Entry");
00116     
00117     fd->mp->device->devInfo->write(fd->mp->device->devInfo->info,
00118                        dir,
00119                        fd->mp->diskLabel->partitions[fd->mp->partition].pOffset+fsInfo->blockAllocationTable[block].realSector,
00120                        blockSize);
00121     addDirEntry(entry,fd);
00122     kfree(dir);
00123     kfree(entry);
00124     }
00125 
00126   return(0x0);
00127   }
00128 
00129 /***
00130  $Log: directory_8c-source.html,v $
00130  Revision 1.7  2006/12/15 17:47:05  reddawg
00130  Updates
00130 
00131  Revision 1.1.1.1  2006/06/01 12:46:17  reddawg
00132  ubix2
00133 
00134  Revision 1.2  2005/10/12 00:13:37  reddawg
00135  Removed
00136 
00137  Revision 1.1.1.1  2005/09/26 17:24:41  reddawg
00138  no message
00139 
00140  Revision 1.12  2004/08/14 11:23:02  reddawg
00141  Changes
00142 
00143  Revision 1.11  2004/08/01 17:58:39  flameshadow
00144  chg: fixed string allocation bug in ubixfs_cacheNew()
00145 
00146  Revision 1.10  2004/07/23 09:10:06  reddawg
00147  ubixfs: cleaned up some functions played with the caching a bit
00148  vfs:    renamed a bunch of functions
00149  cleaned up a few misc bugs
00150 
00151  Revision 1.9  2004/07/16 20:17:29  flameshadow
00152  chg: broke the ufs stuff
00153  chg: changed vfsRegisterFS() to accept a fileSystem struct
00154  chg: modified calls to vfsRegisterFS() to pass fileSystem struct
00155 
00156  Revision 1.8  2004/06/29 03:59:47  reddawg
00157  Fixed a few issues with subdirectories they are working much better now
00158 
00159  Revision 1.7  2004/06/28 23:12:58  reddawg
00160  file format now container:/path/to/file
00161 
00162  Revision 1.6  2004/06/04 13:20:22  reddawg
00163  ubixFSmkDir(): played with it a bit to see if it still worked
00164 
00165  Revision 1.5  2004/06/04 10:19:42  reddawg
00166  notes: we compile again, thank g-d anyways i was about to cry
00167 
00168  Revision 1.4  2004/05/19 15:20:06  reddawg
00169  Fixed reference problems due to changes in drive subsystem
00170 
00171  Revision 1.3  2004/05/19 04:07:43  reddawg
00172  kmalloc(size,pid) no more it is no kmalloc(size); the way it should of been
00173 
00174  Revision 1.2  2004/04/28 02:22:55  reddawg
00175  This is a fiarly large commit but we are starting to use new driver model
00176  all around
00177 
00178  Revision 1.1.1.1  2004/04/15 12:07:07  reddawg
00179  UbixOS v1.0
00180 
00181  Revision 1.6  2004/04/13 16:36:34  reddawg
00182  Changed our copyright, it is all now under a BSD-Style license
00183 
00184  END
00185  ***/

Generated on Fri Dec 15 11:18:55 2006 for UbixOS V2 by  doxygen 1.4.7