# ubixfs.h

    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 permitted provided that the following conditions are met:
    00006
    00007 Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
    00008 Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
    00009 in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
    00010 contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    00011
    00012 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
    00013 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    00014 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    00015 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
    00016 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    00017 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    00018 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00019
    00020  $Id$
    00021
    00022 **************************************************************************************/
    00023
    00024 #ifndef _UBIXFS_H
    00025 #define _UBIXFS_H
    00026
    00027 #include <ubixos/types.h>
    00028 #include <sys/device.h>
    00029 #include <vfs/file.h>
    00030
    00031 #define UBIXDISKMAGIC     ((uInt32)0x45) /* The disk magic number */
    00032 #define MAXPARTITIONS     4
    00033 #define blockSize         8
    00034 #define blockByteSize     blockSize*512
    00035
    00036 #define EOBC              -1
    00037
    00038
    00039 #define typeFile      1
    00040 #define typeContainer 2
    00041 #define typeDirectory 4
    00042 #define typeDeleted   8
    00043
    00044 //Partition Information
    00045 struct ubixDiskLabel {
    00046   uInt32 magicNum;
    00047   uInt32 magicNum2;
    00048   uInt16 driveType;
    00049   uInt16 numPartitions;
    00050   struct  drivePartitions {  //the partition table
    00051     uInt32 pSize;            //number of sectors in partition
    00052     uInt32 pOffset;          //starting sector
    00053     uInt32 pFsSize;          //filesystem basic fragment size
    00054     uInt32 pBatSize;         //BAT size
    00055     uInt8  pFsType;          //filesystem type, see below
    00056     uInt8 pFrag;            //filesystem fragments per block
    00057     } partitions[MAXPARTITIONS];
    00058   };
    00059
    00060 struct partitionInformation {
    00061   uInt32 size;                 //Size In Sectors
    00062   uInt32 startSector;          //Base Sector Of Partition
    00063   uInt32 blockAllocationTable; //Base Sector Of BAT
    00064   uInt32 rootDirectory;        //Base Sector Of Root Directory
    00065   };
    00066
    00067 //Block Allocation Table Entry
    00068 struct blockAllocationTableEntry {
    00069   long attributes; //Block Attributes
    00070   long realSector; //Real Sector
    00071   long nextBlock;  //Sector Of Next Block
    00072   long reserved;   //Reserved
    00073   };
    00074
    00075 //UbixFS Directory Entry
    00076 struct directoryEntry {
    00077   uInt32  startCluster;   //Starting Cluster Of File
    00078   uInt32  size;           //Size Of File
    00079   uInt32  creationDate;  //Date Created
    00080   uInt32  lastModified;  //Date Last Modified
    00081   uInt32  uid;           //UID Of Owner
    00082   uInt32  gid;           //GID Of Owner
    00083   uShort attributes;    //Files Attributes
    00084   uShort permissions;   //Files Permissions
    00085   char   fileName[256]; //File Name
    00086   };
    00087
    00088 struct bootSect {
    00089   uChar jmp[4];
    00090   uChar id[6];
    00091   uShort version;
    00092   uShort tmp;
    00093   uShort fsStart;
    00094   uShort tmp2;
    00095   uInt32 krnl_start;
    00096   uInt BytesPerSector;
    00097   uInt SectersPerTrack;
    00098   uInt TotalHeads;
    00099   uInt32 TotalSectors;
    00100   uChar code[479];
    00101   };
    00102
    00103 struct ubixFsInfo {
    00104   struct blockAllocationTableEntry *blockAllocationTable;
    00105   uInt32 batEntries;
    00106   };
    00107
    00108 int readFile(char *file);
    00109 int writeFileByte(int ch,fileDescriptor *fd,long offset);
    00110 int openFileUbixFS(char *file,fileDescriptor *fd);
    00111 int mkDirUbixFS(char *dir,fileDescriptor *fd);
    00112 int getFreeBlocks(int count,fileDescriptor *fd);
    00113 //extern struct ubixDiskLabel *diskLabel;
    00114
    00115 //Good Functions
    00116 void initUbixFS(struct mountPoints *mp);
    00117 int enableUbixFS();
    00118 int readUbixFS(fileDescriptor *fd,char *data,long offset,long size);
    00119 int writeUbixFS(fileDescriptor *fd,char *data,long offset,long size);
    00120 void syncBat(struct mountPoints *mp);
    00121 int freeBlocks(int block,fileDescriptor *fd);
    00122 int addDirEntry(struct directoryEntry *dir,fileDescriptor *fd);
    00123 void ubixFSUnlink(char *path,struct mountPoints *mp);
    00124
    00125 #endif