[GOOD] BUILD 0.1.0.470 DATE 8/30/2011 AT 6:40 PM
==================================================== Mainly changed: HAL.VFS + Designed virtual file system + Completed the VFS + Added verbose mode for VFS + Updated shell script, now shows build number when building ? TODO: Implement one file system (most likely FAT12) ? TODO: Mount floppy device
This commit is contained in:
@ -9,62 +9,114 @@
|
||||
#define FILEIO_H_
|
||||
|
||||
#include <types.h>
|
||||
#include <time.h>
|
||||
|
||||
enum FsFlags
|
||||
// Device routines, will read/write 'BlockSize' bytes per call
|
||||
typedef uint32 (*DevReadRoutine)(uint32 offset, void* buffer);
|
||||
typedef uint32 (*DevWriteRoutine)(uint32 offset, void* buffer);
|
||||
|
||||
enum FileFlags
|
||||
{
|
||||
FsFile = 0x1,
|
||||
FsDirectory = 0x2,
|
||||
FsCharDevice = 0x3,
|
||||
FsBlockDevice = 0x4,
|
||||
FsPipe = 0x5,
|
||||
FsSymbolLink = 0x6,
|
||||
FsMountPoint = 0x8
|
||||
FileFile = 0x1,
|
||||
FileDirectory = 0x2,
|
||||
FileCharDevice = 0x3,
|
||||
FileBlockDevice = 0x4,
|
||||
FilePipe = 0x5,
|
||||
FileSymbolLink = 0x6,
|
||||
FileMountPoint = 0x7,
|
||||
FileOwnerRead = 0x8,
|
||||
FileOwnerWrite = 0x10,
|
||||
FileOwnerExecute = 0x20,
|
||||
FileGroupRead = 0x40,
|
||||
FileGroupWrite = 0x80,
|
||||
FileGroupExecute = 0x100,
|
||||
FileOtherRead = 0x200,
|
||||
FileOtherWrite = 0x400,
|
||||
FileOtherExecute = 0x800,
|
||||
FileHidden = 0x1000,
|
||||
};
|
||||
|
||||
typedef uint32 (*ReadRoutine)(struct _FsNode*, uint32, uint32, uint8*);
|
||||
typedef uint32 (*WriteRoutine)(struct _FsNode*, uint32, uint32, uint8*);
|
||||
typedef void (*OpenRoutine)(struct _FsNode*);
|
||||
typedef void (*CloseRoutine)(struct _FsNode*);
|
||||
typedef struct _DirectoryEntry (*ReadDirRoutine)(struct _FsNode*,uint32);
|
||||
typedef struct _FsNode* (*FindDirRoutine)(struct _FsNode*,char *name);
|
||||
|
||||
typedef struct _FsNode
|
||||
typedef struct _FILE
|
||||
{
|
||||
char Name[128]; // The filename.
|
||||
uint32 Permissions; // The permissions mask.
|
||||
uint32 UserId; // The owning user.
|
||||
uint32 GroupId; // The owning group.
|
||||
uint32 Flags; // Includes the node type. See enum above.
|
||||
uint32 INode; // This is device-specific - provides a way for a filesystem to identify files.
|
||||
uint32 Length; // Size of the file, in bytes.
|
||||
uint32 Implementation; // An implementation-defined number.
|
||||
ReadRoutine Read;
|
||||
WriteRoutine Write;
|
||||
OpenRoutine Open;
|
||||
CloseRoutine Close;
|
||||
ReadDirRoutine ReadDir;
|
||||
FindDirRoutine FindDir;
|
||||
struct _FsNode *Ptr; // Used by mountpoints and symlinks.
|
||||
} FsNode;
|
||||
uint32 DeviceId; // The VFS identifies the mounted device that uses this
|
||||
uint32 Id; // The FS idenitifies files using this field
|
||||
char Name[128];
|
||||
|
||||
/*** Looks like this:
|
||||
* bits description
|
||||
* 0-2 file type
|
||||
* 3-5 owner permissions (rwx)
|
||||
* 6-8 group permissions (rwx)
|
||||
* 9-11 other permissions (rwx)
|
||||
* 12 hidden
|
||||
* 13-31 (unassigned yet)
|
||||
*
|
||||
* Note: In windows FS, the readonly and system attributes are set using permissions and userid */
|
||||
uint32 Flags;
|
||||
uint32 OwnerId, GroupId;
|
||||
uint32 Size;
|
||||
} FILE;
|
||||
|
||||
|
||||
typedef struct _DirectoryEntry
|
||||
{
|
||||
char Name[128];
|
||||
uint32 INode;
|
||||
uint32 Flags, OwnerId, GroupId, Size;
|
||||
TimeSystem TimeCreated, TimeModified, TimeAccessed;
|
||||
|
||||
} DirectoryEntry;
|
||||
|
||||
|
||||
extern uint32 FsRead(FsNode *node, uint32 offset, uint32 size, uint8 *buffer);
|
||||
extern uint32 FsWrite(FsNode *node, uint32 offset, uint32 size, uint8 *buffer);
|
||||
extern void FsOpen(FsNode *node, uint8 read, uint8 write);
|
||||
extern void FsClose(FsNode *node);
|
||||
extern DirectoryEntry *FsReadDir(FsNode *node, uint32 index);
|
||||
extern FsNode *FsFindDir(FsNode *node, char *name);
|
||||
typedef struct {
|
||||
uint32 Id;
|
||||
uint32 FsId;
|
||||
char Name[128];
|
||||
|
||||
uint32 BlockSize;
|
||||
DevReadRoutine Read;
|
||||
DevWriteRoutine Write;
|
||||
} MountPoint;
|
||||
|
||||
|
||||
// File system routines
|
||||
typedef uint32 (*FsReadRoutine)(const MountPoint*, FILE*, uint32, uint32, uint8*);
|
||||
typedef uint32 (*FsWriteRoutine)(const MountPoint*, FILE*, uint32, uint32, uint8*);
|
||||
typedef FILE* (*FsOpenRoutine)(const MountPoint*, FILE*,string);
|
||||
typedef DirectoryEntry* (*FsTestRoutine)(const MountPoint*, string); // Test if a file exists, and returns info
|
||||
typedef FILE* (*FsCloseRoutine)(const MountPoint*, FILE*);
|
||||
typedef DirectoryEntry* (*FsReadDirRoutine)(const MountPoint*,FILE*,uint32);
|
||||
|
||||
typedef uint32 (*FsDetectRoutine) (DevReadRoutine, uint32 blocksz);
|
||||
|
||||
// File system structure
|
||||
typedef struct {
|
||||
uint32 Id;
|
||||
char Name[16];
|
||||
|
||||
FsDetectRoutine Detect;
|
||||
FsOpenRoutine Open;
|
||||
FsCloseRoutine Close;
|
||||
FsReadRoutine Read;
|
||||
FsWriteRoutine Write;
|
||||
FsTestRoutine Test; // See if file exists without having to open it
|
||||
FsReadDirRoutine ReadDirectory;
|
||||
} FileSystem;
|
||||
|
||||
|
||||
// Vfs routines
|
||||
extern void VfsInstall ();
|
||||
extern uint8 VfsInstallFs (FileSystem* fs);
|
||||
extern uint32 VfsFindDevice (string dev);
|
||||
extern uint32 VfsParsePath (string* path);
|
||||
extern uint8 VfsMount (string Name, DevReadRoutine R, DevWriteRoutine W, uint32 BlockSize);
|
||||
extern void VfsUnmount (uint32 dev_id);
|
||||
extern FILE* VfsOpen (FILE* file, string path);
|
||||
extern DirectoryEntry* VfsTest (string path);
|
||||
extern FILE* VfsClose (FILE* file);
|
||||
extern uint32 VfsRead (FILE* file, uint32 bsz, uint32 n, uint8* buffer);
|
||||
extern uint32 VfsWrite (FILE* file, uint32 bsz, uint32 n, uint8* buffer);
|
||||
extern DirectoryEntry* VfsReadDirectory (FILE* handle, uint32 index);
|
||||
|
||||
#ifdef NEVER
|
||||
void VfsRegisterFilesys();
|
||||
void VfsMount();
|
||||
#endif
|
||||
|
||||
#endif /* FILEIO_H_ */
|
||||
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* memory-add.h
|
||||
*
|
||||
* Created on: Aug 27, 2011
|
||||
* Author: Tiberiu
|
||||
*/
|
||||
|
||||
#ifndef MEMORY_ADD_H_
|
||||
#define MEMORY_ADD_H_
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <debugio.h>
|
||||
|
||||
/***************************************************
|
||||
* Paging *
|
||||
***************************************************/
|
||||
typedef uint32 Page;
|
||||
|
||||
enum PageFlags
|
||||
{
|
||||
PagePresent = 0x1,
|
||||
PageWriteable = 0x2,
|
||||
PageUser = 0x4,
|
||||
PageWriteThough = 0x8,
|
||||
PageNotCacheable = 0x10,
|
||||
PageAccessed = 0x20,
|
||||
PageDirty = 0x40,
|
||||
PagePAT = 0x80,
|
||||
PageCpuGlobal = 0x100,
|
||||
PageLvl4Global = 0x200,
|
||||
PageFrame = 0xFFFFF000
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
Page Pages[1024];
|
||||
} PageTable;
|
||||
|
||||
typedef struct {
|
||||
PageTable* Tables[1024];
|
||||
uint32 TablesPhysical[1024];
|
||||
uint32 PhysicalAddr;
|
||||
} PageDirectory;
|
||||
|
||||
extern PageDirectory* CurrentDirectory;
|
||||
extern PageDirectory* KernelDirectory;
|
||||
|
||||
extern void PagingInitialize(uint32 SystemMemory);
|
||||
extern void PagingSwitchPageDirectory (PageDirectory* dir);
|
||||
extern Page* PagingGetPage(uint32 addr, uint8 make, PageDirectory* dir);
|
||||
|
||||
|
||||
/***************************************************
|
||||
* Physical memory manager *
|
||||
***************************************************/
|
||||
extern uint32 TotalFrames;
|
||||
extern uint32 TotalMemory;
|
||||
|
||||
void MemPhInitialize(uint32 SystemMemoryKb);
|
||||
extern void MemPhSetFrame (uint32 frame, uint8 value);
|
||||
uint32 MemPhGetFrame (uint32 frame);
|
||||
uint32 MemPhFindFreeFrame();
|
||||
void MemPhAllocFrame(Page* page, uint8 isKernel, uint8 isWriteable);
|
||||
void MemPhFreeFrame(Page* page);
|
||||
void MemPhReserveFrames (uint32 address, uint32 length);
|
||||
|
||||
|
||||
/***************************************************
|
||||
* Memory heap *
|
||||
***************************************************/
|
||||
typedef struct
|
||||
{
|
||||
OrderedArray Index;
|
||||
uint32 StartAddress, EndAddress, MaxAddress;
|
||||
// bit 0: supervisor-only bit 1: read-only
|
||||
uint8 Flags;
|
||||
} MemHeap;
|
||||
|
||||
extern MemHeap* KernelHeap;
|
||||
|
||||
extern uint32 MemHeapFindSmallestHole (uint32 size, uint8 page_align, MemHeap* heap);
|
||||
extern int32 MemHeapCompare (uint32 a, uint32 b);
|
||||
extern MemHeap* MemHeapCreate(uint32 start, uint32 end, uint32 max, uint8 flags);
|
||||
extern void MemHeapExpand(uint32 newsz, MemHeap* heap, PageDirectory* pd);
|
||||
extern uint32 MemHeapContract(uint32 newsz, MemHeap* heap, PageDirectory* pd);
|
||||
extern uint32 MemHeapAlloc (uint32 size, uint8 isPageAligned, MemHeap* heap, PageDirectory* pd);
|
||||
extern void MemHeapFree (uint32 address, MemHeap* heap, PageDirectory* pd);
|
||||
|
||||
|
||||
#define LogMem(...) { Log("%#[Mem] ", ColorLightCyan); Log(__VA_ARGS__); }
|
||||
#define ErrorMem(...) { Error("%#[Mem] ", ColorLightCyan); Error(__VA_ARGS__); }
|
||||
|
||||
|
||||
#endif /* MEMORY_ADD_H_ */
|
@ -12,6 +12,7 @@ extern void* kmalloc (uint32 size);
|
||||
extern void* kmalloc_a (uint32 size);
|
||||
extern void* kmalloc_p (uint32 size, uint32* phys);
|
||||
extern void* kmalloc_ap (uint32 size, uint32* phys);
|
||||
extern void* kmrealloc (void* original, uint32 newsz);
|
||||
extern void kfree (void* addr);
|
||||
|
||||
extern void MemoryTempInitialize (uint32 kernel_end);
|
||||
|
@ -1,29 +0,0 @@
|
||||
#ifndef __MEMORY__H
|
||||
#define __MEMORY__H
|
||||
|
||||
#include <types.h>
|
||||
#include <settings.h>
|
||||
#include <multiboot.h>
|
||||
|
||||
/***************************************************
|
||||
* Basic memory operations: alloc, free *
|
||||
***************************************************/
|
||||
extern void* kmalloc (uint32 size);
|
||||
extern void* kmalloc_a (uint32 size);
|
||||
extern void* kmalloc_p (uint32 size, uint32* phys);
|
||||
extern void* kmalloc_ap (uint32 size, uint32* phys);
|
||||
extern void kfree (void* addr);
|
||||
|
||||
extern void MemoryTempInitialize (uint32 kernel_end);
|
||||
extern void MemoryInitialize (MultibootInfo* info);
|
||||
|
||||
extern uint32 MemoryGetTotal();
|
||||
extern uint32 MemoryGetFree(); // Returns total free physical memory in bytes
|
||||
extern uint32 MemoryGetUsed(); // Total used physical memory in bytes
|
||||
extern uint32 MemoryGetFrameSize(); // Same as above functions, but in frames
|
||||
extern uint32 MemoryGetFramesTotal();
|
||||
extern uint32 MemoryGetFramesUsed();
|
||||
extern uint32 MemoryGetFramesFree();
|
||||
|
||||
|
||||
#endif
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* settings.h
|
||||
*
|
||||
* Created on: Aug 16, 2011
|
||||
* Author: Tiberiu
|
||||
*/
|
||||
|
||||
#ifndef SETTINGS_H_
|
||||
#define SETTINGS_H_
|
||||
|
||||
// OS info
|
||||
#define OS_STRING "lux"
|
||||
#define OS_VERSION "0.1 [pre-Alpha]"
|
||||
#define OS_BUILD_DATE __DATE__
|
||||
#define OS_BUILD_TIME __TIME__
|
||||
|
||||
#include <version.h>
|
||||
|
||||
// Logger
|
||||
#define VERBOSE_MODE 1
|
||||
#define VERBOSE_ERROR 1
|
||||
#define VERBOSE_PANIC 1
|
||||
|
||||
|
||||
// Clock
|
||||
#define PIT_FREQUENCY 100
|
||||
|
||||
// Console
|
||||
#define CONSOLE_MAX_PARAMS 32
|
||||
#define CONSOLE_DEFAULT_COLOR 0x7
|
||||
|
||||
// Memory manager
|
||||
#define KERNEL_HEAP_START 0xC0000000
|
||||
#define KERNEL_HEAP_END 0xCFFFF000
|
||||
#define KERNEL_HEAP_INITIAL_SIZE 0x100000
|
||||
|
||||
#endif /* SETTINGS_H_ */
|
@ -24,6 +24,8 @@
|
||||
extern uint32 strlen (string s);
|
||||
extern int32 strcmp (string a, string b);
|
||||
extern string strcpy (string s1, const string s2);
|
||||
extern char* strchr (string s, int c);
|
||||
extern char* strrchr (string s, int c);
|
||||
|
||||
/***************************************************
|
||||
* Number operations: len *
|
||||
|
@ -1,69 +0,0 @@
|
||||
#ifndef __STDLIB__H
|
||||
#define __STDLIB__H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
#define IsDigit(c) (c >= '0' && c <= '9')
|
||||
#define IsHexDigit(c) ( (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') )
|
||||
#define IsUpper(c) (c >= 'A' && c <= 'Z')
|
||||
#define IsLower(c) (c >= 'a' && c <= 'z')
|
||||
|
||||
#define IsAlpha(c) (IsLower(c) || IsUpper(c))
|
||||
#define IsAlphaNum(c) (IsAlpha(c) || IsDigit(c))
|
||||
|
||||
#define ToLower(c) ((IsUpper(c)) ? (c - 'A' + 'a') : c)
|
||||
#define ToUpper(c) ((IsLower(c)) ? (c - 'a' + 'A') : c)
|
||||
|
||||
#define Max(a,b) ((a > b) ? (a) : (b))
|
||||
#define Min(a,b) ((a < b) ? (a) : (b))
|
||||
#define Abs(a) ((a < 0) ? (a * -1) : (a))
|
||||
|
||||
/***************************************************
|
||||
* String operations: len, cmp, cpy *
|
||||
***************************************************/
|
||||
extern uint32 strlen (string s);
|
||||
extern int32 strcmp (string a, string b);
|
||||
extern string strcpy (string s1, const string s2);
|
||||
|
||||
/***************************************************
|
||||
* Number operations: len *
|
||||
***************************************************/
|
||||
extern uint32 numlen (int32 number, int32 base);
|
||||
extern uint32 unumlen (uint32 number, int32 base);
|
||||
|
||||
/***************************************************
|
||||
* Memory operations: cpy, cmp, set *
|
||||
***************************************************/
|
||||
void* memcpy (void *dest, const void *src, uint32 count);
|
||||
int32 memcmp (const void *s1, const void *s2, uint32 count);
|
||||
void* memset (void *dest, uint8 val, uint32 count);
|
||||
|
||||
/***************************************************
|
||||
* Conversion operations: num-str/str-num *
|
||||
***************************************************/
|
||||
extern int32 ConvertIntToString (string buffer, int32 number, int32 base);
|
||||
extern uint32 ConvertUIntToString (string buffer, uint32 number, int32 base);
|
||||
extern int32 ConvertStringToInt (string buffer);
|
||||
extern uint32 ConvertStringToUInt (string buffer);
|
||||
extern uint32 ConvertStringToIntHex (string buffer);
|
||||
|
||||
/***************************************************
|
||||
* Ordered array implementation *
|
||||
***************************************************/
|
||||
typedef int (*ComparePredicate) (uint32, uint32);
|
||||
typedef struct {
|
||||
uint32* Data;
|
||||
uint32 Size;
|
||||
uint32 SizeLimit;
|
||||
ComparePredicate Compare;
|
||||
} OrderedArray;
|
||||
|
||||
extern OrderedArray OrderedArrayCreate (uint32 maxSize, ComparePredicate p);
|
||||
extern OrderedArray OrderedArrayPlace (uint32 addr, uint32 maxSize, ComparePredicate p);
|
||||
extern void OrderedArrayDispose (OrderedArray* arr);
|
||||
extern uint32 OrderedArraySearch (uint32 key, OrderedArray* arr, ComparePredicate predicate);
|
||||
extern void OrderedArrayInsert (uint32 item, OrderedArray* arr);
|
||||
extern uint32 OrderedArrayLookup (uint32 index, OrderedArray* arr);
|
||||
extern void OrderedArrayDeleteIndex (uint32 index, OrderedArray* arr);
|
||||
|
||||
#endif
|
@ -10,56 +10,6 @@
|
||||
|
||||
#include <types.h>
|
||||
|
||||
// Storage device
|
||||
typedef struct {
|
||||
|
||||
char MountPointName[32];// E.g. "fd0"; you should avoid spaces, or special chars, or otherwise get weird paths like "Mom's floppy\virus.exe"
|
||||
uint32 DeviceID; // Autocompleted by VFS
|
||||
|
||||
uint32 BlockSize; // E.g. sector size
|
||||
uint32 BlockCount; // How many blocks are loaded in memory per read
|
||||
|
||||
/********************************************************
|
||||
* READ DATA *
|
||||
* Params: *
|
||||
* > offset: read starting from block ~ *
|
||||
* Returns: address to data, NULL for error *
|
||||
********************************************************/
|
||||
uint32 (*ReadData) (uint32 offset);
|
||||
|
||||
/********************************************************
|
||||
* WRITE DATA *
|
||||
* Params: *
|
||||
* > offset: write starting from block ~ *
|
||||
* > address: where to write from *
|
||||
* Returns: NULL for error *
|
||||
********************************************************/
|
||||
uint32 (*WriteData) (uint32 offset, uint32 address);
|
||||
|
||||
uint32 FileSystemID; // Autocompleted by 'mount'... at least should be
|
||||
|
||||
} StorageDevice;
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32 FileSystemID; // Autocompleted by VFS
|
||||
|
||||
/********************************************************
|
||||
* DETECT IF THIS IS THE FS ON STORAGE DEVICE *
|
||||
* Params: *
|
||||
* > *s: Pointer to device info & routines *
|
||||
* Returns: positive if match, NULL otherwise *
|
||||
********************************************************/
|
||||
uint32 (*Detect) (StorageDevice *s);
|
||||
|
||||
uint32 (*Open) (StorageDevice *s, string path);
|
||||
uint32 (*CreateNode) (StorageDevice *s, string path);
|
||||
uint32 (*DeleteNode) (StorageDevice *s, string path);
|
||||
|
||||
} FileSystem;
|
||||
|
||||
|
||||
|
||||
extern void ConvertLbaToChs(uint32 SectorsPerTrack, uint32 lba, uint32 *cyl, uint32 *head, uint32 *sector);
|
||||
|
||||
#endif /* STORAGE_H_ */
|
||||
|
@ -21,8 +21,8 @@ typedef struct _Time Time;
|
||||
typedef struct _TimeSystem TimeSystem;
|
||||
|
||||
|
||||
extern TimeSystem TimeConvertToTimeSystem (Time t);
|
||||
extern Time TimeConvertToTime (TimeSystem InternalTime);
|
||||
extern TimeSystem ConvertTimeToTimeSystem (Time t);
|
||||
extern Time ConvertTimeSystemToTime (TimeSystem InternalTime);
|
||||
extern uint16 TimeCalculateWeekday (Time t);
|
||||
|
||||
extern TimeSystem TimeGetInternalTime();
|
||||
|
@ -1 +1 @@
|
||||
#define OS_BUILD "0.1.0.450"
|
||||
#define OS_BUILD "0.1.0.470"
|
||||
|
@ -1 +0,0 @@
|
||||
-e #define OS_BUILD "0.1.0.418"
|
Reference in New Issue
Block a user