Added ProcDev/SysFS + Cleanup
authorJohn Hodge <[email protected]>
Sun, 22 Nov 2009 08:03:14 +0000 (16:03 +0800)
committerJohn Hodge <[email protected]>
Sun, 22 Nov 2009 08:03:14 +0000 (16:03 +0800)
- Added /Devices/system (ProcDev or SysFS)
 > Allows exposing of kernel buffers to usermode (readonly)
- Added use of ProcDev to VFS to expose Mounted filesystems and loaded
  filesystems.
- Created tSpinlock type to make sure that spinlocks are volatile

16 files changed:
Kernel/Makefile
Kernel/Makefile.BuildNum [new file with mode: 0644]
Kernel/arch/x86/include/arch.h
Kernel/drv/proc.c [new file with mode: 0644]
Kernel/include/common.h
Kernel/include/fs_sysfs.h [new file with mode: 0644]
Kernel/include/threads.h
Kernel/include/vfs_int.h
Kernel/messages.c
Kernel/vfs/main.c
Kernel/vfs/mount.c
Kernel/vfs/open.c
Makefile
Modules/IPStack/main.c
Modules/USB/usb.h
Usermode/Applications/CLIShell_src/main.c

index ee8c245..778d3d8 100644 (file)
@@ -8,9 +8,14 @@
 
 -include arch/$(ARCHDIR)/Makefile
 
+-include Makefile.BuildNum
+
+KERNEL_VERSION = 0.5
+
 MAKEDEP                = $(CC) -M
 
-CPPFLAGS       += -I./include -I./arch/$(ARCHDIR)/include -DARCH=$(ARCH)
+CPPFLAGS       += -I./include -I./arch/$(ARCHDIR)/include
+CPPFLAGS    += -DARCH=$(ARCH) -DKERNEL_VERSION=$(KERNEL_VERSION) -DBUILD_NUM=$(BUILD_NUM)
 CFLAGS         += -Wall -Werror -O3 -fno-stack-protector -fno-builtin
 ASFLAGS                += -D ARCH=\"$(ARCH)\"
 LDFLAGS                += -T arch/$(ARCHDIR)/link.ld
@@ -21,7 +26,7 @@ OBJ += binary.o bin/elf.o
 OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/dir.o vfs/io.o vfs/mount.o vfs/memfile.o vfs/nodecache.o
 OBJ += vfs/fs/root.o vfs/fs/devfs.o
 OBJ += $(addprefix vfs/fs/, $(addsuffix .o,$(FILESYSTEMS)))
-OBJ += drv/fifo.o drv/dma.o drv/iocache.o drv/pci.o drv/kb.o drv/vga.o drv/vterm.o
+OBJ += drv/proc.o drv/fifo.o drv/dma.o drv/iocache.o drv/pci.o drv/kb.o drv/vga.o drv/vterm.o
 OBJ += $(addprefix drv/, $(addsuffix .o,$(DRIVERS)))
 OBJ := $(addsuffix .$(ARCH), $(OBJ))
 MODS += $(addprefix ../Modules/, $(addsuffix .xo.$(ARCH),$(MODULES)))
@@ -49,7 +54,7 @@ $(BIN): $(OBJ) $(MODS) arch/$(ARCHDIR)/link.ld Makefile
        @objdump $(BIN) -D > $(BIN).dsm
        cp $(BIN) $(DISTROOT)
        @wc -l $(SRCFILES) > LineCounts.$(ARCH).txt
-#      @git commit -a
+       @echo BUILD_NUM = `calc $(BUILD_NUM)+1` > Makefile.BuildNum
 
 %.ao.$(ARCH): %.asm Makefile
        @echo --- NASM -o $@
diff --git a/Kernel/Makefile.BuildNum b/Kernel/Makefile.BuildNum
new file mode 100644 (file)
index 0000000..92b8fa6
--- /dev/null
@@ -0,0 +1 @@
+BUILD_NUM = 1020
index bc4e0af..92ccf05 100644 (file)
@@ -51,6 +51,7 @@
 #endif
 
 // === MACROS ===
+typedef volatile int   tSpinlock;
 #define LOCK(lockptr)  do {int v=1;\
        while(v)__asm__ __volatile__("lock xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(lockptr));}while(0)
 #define        RELEASE(lockptr)        __asm__ __volatile__("lock andl $0, (%%edi)"::"D"(lockptr));
diff --git a/Kernel/drv/proc.c b/Kernel/drv/proc.c
new file mode 100644 (file)
index 0000000..9aa0a34
--- /dev/null
@@ -0,0 +1,381 @@
+/*
+ * Acess2
+ * - Kernel Status Driver
+ */
+#define DEBUG  1
+#include <common.h>
+#include <modules.h>
+#include <fs_devfs.h>
+#include <fs_sysfs.h>
+
+// === CONSTANTS ===
+#define        VERSION ((0 << 8) | (1))        // 0.01
+#define KERNEL_VERSION_STRING  ("Acess2 " EXPAND_STR(KERNEL_VERSION) " build " EXPAND_STR(BUILD_NUM))
+
+// === TYPES ===
+typedef struct sSysFS_Ent
+{
+       struct sSysFS_Ent       *Next;
+       struct sSysFS_Ent       *ListNext;
+       struct sSysFS_Ent       *Parent;
+       char    *Name;
+       tVFS_Node       Node;
+} tSysFS_Ent;
+
+// === PROTOTYPES ===
+ int   SysFS_Install(char **Arguments);
+ int   SysFS_IOCtl(tVFS_Node *Node, int Id, void *Data);
+
+ int   SysFS_RegisterFile(char *Path, char *Data, int Length);
+ int   SysFS_UpdateFile(int ID, char *Data, int Length);
+ int   SysFS_RemoveFile(int ID);
+
+char   *SysFS_Comm_ReadDir(tVFS_Node *Node, int Id);
+tVFS_Node      *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename);
+Uint64 SysFS_Comm_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
+void   SysFS_Comm_CloseFile(tVFS_Node *Node);
+
+// === GLOBALS ===
+extern tSysFS_Ent      gSysFS_Version; // Defined Later
+extern tSysFS_Ent      gSysFS_Root;    // Defined Later
+MODULE_DEFINE(0, VERSION, SysFS, SysFS_Install, NULL, NULL);
+tSysFS_Ent     gSysFS_Version_Kernel = {
+       NULL, NULL,     // Nexts
+       &gSysFS_Version,        // Parent
+       "Kernel",
+       {
+               .Inode = 1,     // File #1
+               .ImplPtr = KERNEL_VERSION_STRING,
+               .ImplInt = (Uint)&gSysFS_Version_Kernel,        // Self-Link
+               .Size = sizeof(KERNEL_VERSION_STRING)-1,
+               .NumACLs = 1,
+               .ACLs = &gVFS_ACL_EveryoneRO,
+               .Read = SysFS_Comm_ReadFile
+       }
+};
+tSysFS_Ent     gSysFS_Version = {
+       NULL, NULL,
+       &gSysFS_Root,
+       "Version",
+       {
+               .Size = 1,
+               .ImplPtr = &gSysFS_Version_Kernel,
+               .ImplInt = (Uint)&gSysFS_Version,       // Self-Link
+               .NumACLs = 1,
+               .ACLs = &gVFS_ACL_EveryoneRX,
+               .Flags = VFS_FFLAG_DIRECTORY,
+               .ReadDir = SysFS_Comm_ReadDir,
+               .FindDir = SysFS_Comm_FindDir
+       }
+};
+// Root of the SysFS tree (just used for clean code)
+tSysFS_Ent     gSysFS_Root = {
+       NULL, NULL,
+       NULL,
+       "/",
+       {
+               .Size = 1,
+               .ImplPtr = &gSysFS_Version,
+               .ImplInt = (Uint)&gSysFS_Root   // Self-Link
+       //      .NumACLs = 1,
+       //      .ACLs = &gVFS_ACL_EveryoneRX,
+       //      .Flags = VFS_FFLAG_DIRECTORY,
+       //      .ReadDir = SysFS_Comm_ReadDir,
+       //      .FindDir = SysFS_Comm_FindDir
+       }
+};
+tDevFS_Driver  gSysFS_DriverInfo = {
+       NULL, "system",
+       {
+       .NumACLs = 1,
+       .ACLs = &gVFS_ACL_EveryoneRX,
+       .Flags = VFS_FFLAG_DIRECTORY,
+       .ImplPtr = &gSysFS_Version,
+       .Size = sizeof(gSysFS_Root)/sizeof(tSysFS_Ent),
+       .ReadDir = SysFS_Comm_ReadDir,
+       .FindDir = SysFS_Comm_FindDir,
+       .IOCtl = NULL
+       }
+};
+ int   giSysFS_NextFileID = 2;
+tSysFS_Ent     *gSysFS_FileList;
+
+// === CODE ===
+/**
+ * \fn int SysFS_Install(char **Options)
+ * \brief Installs the SysFS Driver
+ */
+int SysFS_Install(char **Options)
+{
+       DevFS_AddDevice( &gSysFS_DriverInfo );
+       return 0;
+}
+
+/**
+ * \fn int SysFS_RegisterFile(char *Path, char *Data, int Length)
+ * \brief Registers a file (buffer) for the user to be able to read from
+ * \param Path Path for the file to be accessable from (relative to SysFS root)
+ * \param Data Pointer to the data buffer (must be non-volatile)
+ * \param Length       Length of the data buffer
+ * \return The file's identifier
+ */
+int SysFS_RegisterFile(char *Path, char *Data, int Length)
+{
+        int    start = 0;
+        int    tmp;
+       tSysFS_Ent      *ent = NULL;
+       tSysFS_Ent      *child, *prev;
+       
+       // Find parent directory
+       while( (tmp = strpos(&Path[start], '/')) != -1 )
+       {
+               prev = NULL;
+               
+               if(ent)
+                       child = ent->Node.ImplPtr;
+               else
+                       child = gSysFS_DriverInfo.RootNode.ImplPtr;
+               for( ; child; prev = child, child = child->Next )
+               {
+                       if( strncmp( &Path[start], child->Name, tmp+1 ) == '/' )
+                               break;
+               }
+               
+               // Need a new directory?
+               if( !child )
+               {
+                       child = calloc( 1, sizeof(tSysFS_Ent) );
+                       child->Next = NULL;
+                       child->Name = malloc(tmp+1);
+                       memcpy(child->Name, &Path[start], tmp);
+                       child->Name[tmp] = '\0';
+                       child->Parent = ent;
+                       child->Node.Inode = 0;
+                       child->Node.ImplPtr = NULL;
+                       child->Node.ImplInt = (Uint)child;      // Uplink
+                       child->Node.NumACLs = 1;
+                       child->Node.ACLs = &gVFS_ACL_EveryoneRX;
+                       child->Node.Flags = VFS_FFLAG_DIRECTORY;
+                       child->Node.ReadDir = SysFS_Comm_ReadDir;
+                       child->Node.FindDir = SysFS_Comm_FindDir;
+                       if( !prev ) {
+                               //if(ent)
+                                       ent->Node.ImplPtr = child;
+                               //else
+                               //      gSysFS_DriverInfo.RootNode.ImplPtr = child;
+                               // ^^^ Impossible (There is already /Version
+                       }
+                       else
+                               prev->Next = child;
+                       if(ent)
+                               ent->Node.Size ++;
+                       else
+                               gSysFS_DriverInfo.RootNode.Size ++;
+                       LOG("Added directory '%s'\n", child->Name);
+               }
+               
+               ent = child;
+               
+               start = tmp+1;
+       }
+       
+       // ent: Parent tSysFS_Ent or NULL
+       // start: beginning of last path element
+       
+       // Check if the name is taken
+       prev = NULL;
+       if(ent)
+               child = ent->Node.ImplPtr;
+       else
+               child = gSysFS_DriverInfo.RootNode.ImplPtr;
+       for( child = ent->Node.ImplPtr; child; prev = child, child = child->Next )
+       {
+               if( strcmp( &Path[start], child->Name ) == 0 )
+                       break;
+       }
+       if( child ) {
+               Warning("[SYSFS] '%s' is taken (in '%s')\n", &Path[start], Path);
+               return 0;
+       }
+       
+       // Create new node
+       child = calloc( 1, sizeof(tSysFS_Ent) );
+       child->Next = NULL;
+       child->Name = strdup(&Path[start]);
+       child->Parent = ent;
+       
+       child->Node.Inode = giSysFS_NextFileID++;
+       child->Node.ImplPtr = Data;
+       child->Node.ImplInt = (Uint)child;      // Uplink
+       child->Node.Size = Length;
+       child->Node.NumACLs = 1;
+       child->Node.ACLs = &gVFS_ACL_EveryoneRO;
+       child->Node.Read = SysFS_Comm_ReadFile;
+       child->Node.Close = SysFS_Comm_CloseFile;
+       
+       // Add to parent's child list
+       if(ent) {
+               ent->Node.Size ++;
+               child->Next = ent->Node.ImplPtr;
+               ent->Node.ImplPtr = child;
+       }
+       else {
+               gSysFS_DriverInfo.RootNode.Size ++;
+               child->Next = gSysFS_DriverInfo.RootNode.ImplPtr;
+               gSysFS_DriverInfo.RootNode.ImplPtr = child;
+       }
+       // Add to global file list
+       child->ListNext = gSysFS_FileList;
+       gSysFS_FileList = child;
+       
+       Log("[SYSFS] Added '%s' (%p)", Path, Data);
+       
+       return child->Node.Inode;
+}
+
+/**
+ * \fn int SysFS_UpdateFile(int ID, char *Data, int Length)
+ * \brief Updates a file
+ * \param ID   Identifier returned by ::SysFS_RegisterFile
+ * \param Data Pointer to the data buffer
+ * \param Length       Length of the data buffer
+ * \return Boolean Success
+ */
+int SysFS_UpdateFile(int ID, char *Data, int Length)
+{
+       tSysFS_Ent      *ent;
+       
+       for( ent = gSysFS_FileList; ent; ent = ent->Next )
+       {
+               // It's a reverse sorted list
+               if(ent->Node.Inode < ID)        return 0;
+               if(ent->Node.Inode == ID)
+               {
+                       ent->Node.ImplPtr = Data;
+                       ent->Node.Size = Length;
+                       return 1;
+               }
+       }
+       
+       return 0;
+}
+
+/**
+ * \fn int SysFS_RemoveFile(int ID)
+ * \brief Removes a file from user access
+ * \param ID   Identifier returned by ::SysFS_RegisterFile
+ * \return Boolean Success
+ * \note If a handle is still open to the file, it will be invalidated
+ */
+int SysFS_RemoveFile(int ID)
+{
+       tSysFS_Ent      *file;
+       tSysFS_Ent      *ent, *parent, *prev;
+       
+       prev = NULL;
+       for( ent = gSysFS_FileList; ent; prev = ent, ent = ent->Next )
+       {
+               // It's a reverse sorted list
+               if(ent->Node.Inode < ID)        return 0;
+               if(ent->Node.Inode == ID)       break;
+       }
+       
+       if(!ent)        return 0;
+       
+       // Set up for next part
+       file = ent;
+       parent = file->Parent;
+       
+       // Remove from file list
+       prev->ListNext = file->ListNext;
+       file->Node.Size = 0;
+       file->Node.ImplPtr = NULL;
+       
+       // Search parent directory
+       for( ent = parent->Node.ImplPtr; ent; prev = ent, ent = ent->Next )
+       {
+               if( ent == file )       break;
+       }
+       if(!ent) {
+               Warning("[SYSFS] Bookkeeping Error: File in list, but not in directory");
+               return 0;
+       }
+       
+       // Remove from parent directory
+       prev->Next = ent->Next;
+       
+       // Free if not in use
+       if(file->Node.ReferenceCount == 0)
+               free(file);
+       
+       return 1;
+}
+
+/**
+ * \fn char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos)
+ * \brief Reads from a SysFS directory
+ */
+char *SysFS_Comm_ReadDir(tVFS_Node *Node, int Pos)
+{
+       tSysFS_Ent      *child = (tSysFS_Ent*)Node->ImplPtr;
+       if(Pos < 0 || Pos >= Node->Size)        return NULL;
+       
+       for( ; child; child = child->Next, Pos-- )
+       {
+               if( Pos == 0 )  return strdup(child->Name);
+       }
+       return NULL;
+}
+
+/**
+ * \fn tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename)
+ * \brief Find a file in a SysFS directory
+ */
+tVFS_Node *SysFS_Comm_FindDir(tVFS_Node *Node, char *Filename)
+{
+       tSysFS_Ent      *child = (tSysFS_Ent*)Node->ImplPtr;
+       
+       for( ; child; child = child->Next )
+       {
+               if( strcmp(child->Name, Filename) == 0 )
+                       return &child->Node;
+       }
+       
+       return NULL;
+}
+
+/**
+ * \fn Uint64 SysFS_Comm_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+ * \brief Read from an exposed buffer
+ */
+Uint64 SysFS_Comm_ReadFile(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+{
+       if( Offset > Node->Size )       return -1;
+       if( Length > Node->Size )       Length = Node->Size;
+       if( Offset + Length > Node->Size)       Length = Node->Size - Offset;
+       
+       if( Node->ImplPtr )
+               memcpy(Buffer, (void*)((Uint)Node->ImplPtr+(Uint)Offset), Length);
+       else
+               return -1;
+       
+       return Length;
+}
+
+/**
+ * \fn void SysFS_Comm_CloseFile(tVFS_Node *Node)
+ * \brief Closes an open file
+ * \param Node Node to close
+ */
+void SysFS_Comm_CloseFile(tVFS_Node *Node)
+{
+       // Dereference
+       Node->ReferenceCount --;
+       if( Node->ReferenceCount > 0 )  return;
+       
+       // Check if it is still valid
+       if( Node->ImplPtr )     return;
+       
+       // Delete
+       free( (void*)Node->ImplInt );
+}
index 0ff9c7f..7888a7a 100644 (file)
@@ -103,12 +103,13 @@ extern void       Debug_HexDump(char *Header, void *Data, Uint Length);
 # define LOG(_fmt...)  Debug_Log((char*)__func__, _fmt)
 # define LEAVE(_t...)  Debug_Leave((char*)__func__, _t)
 # define LEAVE_RET(_t,_v...)   do{LEAVE(_t,_v);return _v;}while(0)
-//# define LEAVE_RET(_t)       do{LEAVE(_t);return;}
+# define LEAVE_RET0()  do{LEAVE('-');return;}while(0)
 #else
 # define ENTER(...)
 # define LOG(...)
 # define LEAVE(...)
 # define LEAVE_RET(_t,_v...)   return (_v)
+# define LEAVE_RET0()  return
 #endif
 /**
  * \}
diff --git a/Kernel/include/fs_sysfs.h b/Kernel/include/fs_sysfs.h
new file mode 100644 (file)
index 0000000..61a6d48
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Acess2
+ * - SysFS Export Header
+ */
+#ifndef _FS_SYSFS_H_
+#define _FS_SYSFS_H_
+
+extern int     SysFS_RegisterFile(char *Path, char *Data, int Length);
+extern int     SysFS_UpdateFile(int ID, char *Data, int Length);
+extern int     SysFS_RemoveFile(int ID);
+
+#endif
index 1e15547..9c5ebe7 100644 (file)
@@ -18,7 +18,7 @@ typedef struct sThread
 {
        // --- threads.c's
        struct sThread  *Next;  //!< Next thread in list
-        int    IsLocked;       //!< Thread's spinlock
+       tSpinlock       IsLocked;       //!< Thread's spinlock
         int    Status;         //!< Thread Status
         int    RetStatus;      //!< Return Status
        
@@ -43,7 +43,7 @@ typedef struct sThread
        tVAddr  SignalHandlers[NSIG];   //!< Signal Handler List
        tTaskState      SignalState;    //!< Saved state for signal handler
        
-       tMsg    *Messages;      //!< Message Queue
+       tMsg * volatile Messages;       //!< Message Queue
        tMsg    *LastMessage;   //!< Last Message (speeds up insertion)
        
         int    Quantum, Remaining;     //!< Quantum Size and remaining timesteps
index f227b23..e548062 100644 (file)
@@ -36,7 +36,7 @@ typedef struct sVFS_Proc {
 } tVFS_Proc;
 
 // === GLOBALS ===
-extern tVFS_Mount      *gMounts;
+extern tVFS_Mount      *gVFS_Mounts;
 
 // === PROTOTYPES ===
 // --- OPEN.C ---
index 057f997..6fcd289 100644 (file)
@@ -99,7 +99,7 @@ int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
        
        // Remove from list
        tmp = cur->Messages->Next;
-       free(cur->Messages);
+       free( (void*)cur->Messages );
        cur->Messages = tmp;
        
        RELEASE( &cur->IsLocked );
index 3d1f8e5..795a64f 100644 (file)
@@ -3,6 +3,7 @@
  * Virtual File System
  */
 #include <common.h>
+#include <fs_sysfs.h>
 #include "vfs.h"
 #include "vfs_int.h"
 #include "vfs_ext.h"
 extern tVFS_Driver     gRootFS_Info;
 extern tVFS_Driver     gDevFS_Info;
 
+// === PROTOTYPES ===
+ int   VFS_Init();
+char   *VFS_GetTruePath(char *Path);
+void   VFS_GetMemPath(void *Base, Uint Length, char *Dest);
+tVFS_Driver    *VFS_GetFSByName(char *Name);
+ int   VFS_AddDriver(tVFS_Driver *Info);
+void   VFS_UpdateDriverFile();
+
 // === GLOBALS ===
 tVFS_Node      NULLNode = {0};
-static int     siDriverListLock = 0;
+tSpinlock      siDriverListLock = 0;
 tVFS_Driver    *gVFS_Drivers = NULL;
+char   *gsVFS_DriverFile = NULL;
+ int   giVFS_DriverFileID = 0;
+
+char   *gsVFS_MountFile = NULL;
+ int   giVFS_MountFileID = 0;
 
 // === CODE ===
 /**
@@ -26,6 +40,11 @@ int VFS_Init()
        // Core Drivers
        gVFS_Drivers = &gRootFS_Info;
        gVFS_Drivers->Next = &gDevFS_Info;
+       VFS_UpdateDriverFile();
+       
+       // Register with SysFS
+       giVFS_MountFileID = SysFS_RegisterFile("VFS/Mounts", NULL, 0);
+       giVFS_DriverFileID = SysFS_RegisterFile("VFS/Drivers", NULL, 0);
        
        VFS_Mount("root", "/", "rootfs", "");
        VFS_MkDir("/Devices");
@@ -99,5 +118,38 @@ int VFS_AddDriver(tVFS_Driver *Info)
        gVFS_Drivers = Info;
        RELEASE( &siDriverListLock );
        
+       VFS_UpdateDriverFile();
+       
        return 0;
 }
+
+/**
+ * \fn void VFS_UpdateDriverFile()
+ * \brief Updates the driver list file
+ */
+void VFS_UpdateDriverFile()
+{
+       tVFS_Driver     *drv;
+        int    len = 0;
+       char    *buf;
+       
+       // Format:
+       // <name>\n
+       for( drv = gVFS_Drivers; drv; drv = drv->Next )
+       {
+               len += 1 + strlen(drv->Name);
+       }
+       buf = malloc(len+1);
+       len = 0;
+       for( drv = gVFS_Drivers; drv; drv = drv->Next )
+       {
+               strcpy( &buf[len], drv->Name );
+               len += strlen(drv->Name);
+               buf[len++] = '\n';
+       }
+       buf[len] = '\0';
+       
+       SysFS_UpdateFile( giVFS_DriverFileID, buf, len );
+       if(gsVFS_DriverFile)    free(gsVFS_DriverFile);
+       gsVFS_DriverFile = buf;
+}
index c4ab833..eb6a5b1 100644 (file)
@@ -4,11 +4,20 @@
 #include <common.h>
 #include <vfs.h>
 #include <vfs_int.h>
+#include <fs_sysfs.h>
+
+// === IMPORTS ===
+extern int     giVFS_MountFileID;
+extern char    *gsVFS_MountFile;
+
+// === PROTOTYPES ===
+ int   VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *ArgString);
+void   VFS_UpdateMountFile();
 
 // === GLOBALS ===
  int   glVFS_MountList = 0;
-tVFS_Mount     *gMounts;
-tVFS_Mount     *gRootMount = NULL;
+tVFS_Mount     *gVFS_Mounts;
+tVFS_Mount     *gVFS_RootMount = NULL;
 
 // === CODE ===
 /**
@@ -67,15 +76,72 @@ int VFS_Mount(char *Device, char *MountPoint, char *Filesystem, char *ArgString)
        }
        
        // Set root
-       if(!gRootMount) gRootMount = mnt;
+       if(!gVFS_RootMount)     gVFS_RootMount = mnt;
        
        // Add to mount list
        LOCK( &glVFS_MountList );
-       mnt->Next = gMounts;
-       gMounts = mnt;
+       {
+               tVFS_Mount      *tmp;
+               mnt->Next = NULL;
+               if(gVFS_Mounts) {
+                       for( tmp = gVFS_Mounts; tmp->Next; tmp = tmp->Next );
+                       tmp->Next = mnt;
+               }
+               else {
+                       gVFS_Mounts = mnt;
+               }
+       }
        RELEASE( &glVFS_MountList );
        
        Log("VFS_Mount: Mounted '%s' to '%s' ('%s')", Device, MountPoint, Filesystem);
        
+       VFS_UpdateMountFile();
+       
        return 0;
 }
+
+/**
+ * \fn void VFS_UpdateMountFile()
+ * \brief Updates the mount file buffer
+ */
+void VFS_UpdateMountFile()
+{
+        int    len = 0;
+       char    *buf;
+       tVFS_Mount      *mnt;
+       
+       // Format:
+       // <device>\t<location>\t<type>\t<options>\n
+       
+       for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
+       {
+               len += 4 + strlen(mnt->Device) + strlen(mnt->MountPoint)
+                       + strlen(mnt->Filesystem->Name) + strlen(mnt->Options);
+       }
+       
+       buf = malloc( len + 1 );
+       len = 0;
+       for(mnt = gVFS_Mounts; mnt; mnt = mnt->Next)
+       {
+               strcpy( &buf[len], mnt->Device );
+               len += strlen(mnt->Device);
+               buf[len++] = '\t';
+               
+               strcpy( &buf[len], mnt->MountPoint );
+               len += strlen(mnt->MountPoint);
+               buf[len++] = '\t';
+               
+               strcpy( &buf[len], mnt->Filesystem->Name );
+               len += strlen(mnt->Filesystem->Name);
+               buf[len++] = '\t';
+               
+               strcpy( &buf[len], mnt->Options );
+               len += strlen(mnt->Options);
+               buf[len++] = '\n';
+       }
+       buf[len] = 0;
+       
+       SysFS_UpdateFile( giVFS_MountFileID, buf, len );
+       if( gsVFS_MountFile )   free( gsVFS_MountFile );
+       gsVFS_MountFile = buf;
+}
index 3a68703..05f7d29 100644 (file)
@@ -15,7 +15,7 @@
 
 // === IMPORTS ===
 extern tVFS_Node       gVFS_MemRoot;
-extern tVFS_Mount      *gRootMount;
+extern tVFS_Mount      *gVFS_RootMount;
 
 // === GLOBALS ===
 tVFS_Handle    *gaUserHandles = (void*)MM_PPD_VFS;
@@ -172,7 +172,7 @@ char *VFS_GetAbsPath(char *Path)
 tVFS_Node *VFS_ParsePath(char *Path, char **TruePath)
 {
        tVFS_Mount      *mnt;
-       tVFS_Mount      *longestMount = gRootMount;     // Root is first
+       tVFS_Mount      *longestMount = gVFS_RootMount; // Root is first
         int    cmp, retLength = 0;
         int    ofs, nextSlash;
        tVFS_Node       *curNode, *tmpNode;
@@ -194,21 +194,21 @@ tVFS_Node *VFS_ParsePath(char *Path, char **TruePath)
        
        if(Path[0] == '/' && Path[1] == '\0') {
                if(TruePath) {
-                       *TruePath = malloc( gRootMount->MountPointLen+1 );
-                       strcpy(*TruePath, gRootMount->MountPoint);
+                       *TruePath = malloc( gVFS_RootMount->MountPointLen+1 );
+                       strcpy(*TruePath, gVFS_RootMount->MountPoint);
                }
-               LEAVE('p', gRootMount->RootNode);
-               return gRootMount->RootNode;
+               LEAVE('p', gVFS_RootMount->RootNode);
+               return gVFS_RootMount->RootNode;
        }
        
        // Check if there is anything mounted
-       if(!gMounts) {
+       if(!gVFS_Mounts) {
                Warning("WTF! There's nothing mounted?");
                return NULL;
        }
        
        // Find Mountpoint
-       for(mnt = gMounts;
+       for(mnt = gVFS_Mounts;
                mnt;
                mnt = mnt->Next)
        {
index 90ed23c..0113ad0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@
 
 .PHONY: all clean
 
-MODULES = FS_Ext2 FDD BochsGA IPStack NE2000
+MODULES = FS_Ext2 FDD BochsGA IPStack NE2000 USB
 USRLIBS = ld-acess.so libacess.so libgcc.so libc.so
 USRAPPS = init login CLIShell cat ls mount ifconfig
 
@@ -24,27 +24,6 @@ all:
        (echo === User Application: $$app && $(MAKE) all --no-print-directory -C Usermode/Applications/`echo $$app`_src) \
        done
 
-#      @echo === ld-acess.so
-#      @$(MAKE) all --no-print-directory -C Usermode/Libraries/ld-acess.so_src
-#      @echo === libacess.so
-#      @$(MAKE) all --no-print-directory -C Usermode/Libraries/libacess.so_src
-#      @echo === libgcc.so
-#      @$(MAKE) all --no-print-directory -C Usermode/Libraries/libgcc.so_src
-#      @echo === libc.so
-#      @$(MAKE) all --no-print-directory -C Usermode/Libraries/libc.so_src
-#      @echo === init
-#      @$(MAKE) all --no-print-directory -C Usermode/Applications/init_src
-#      @echo === login
-#      @$(MAKE) all --no-print-directory -C Usermode/Applications/login_src
-#      @echo === CLIShell
-#      @$(MAKE) all --no-print-directory -C Usermode/Applications/CLIShell_src
-#      @echo === cat
-#      @$(MAKE) all --no-print-directory -C Usermode/Applications/cat_src
-#      @echo === ls
-#      @$(MAKE) all --no-print-directory -C Usermode/Applications/ls_src
-#      @echo === mount
-#      @$(MAKE) all --no-print-directory -C Usermode/Applications/mount_src
-
 clean:
        @for mod in $(MODULES); do \
        ($(MAKE) clean --no-print-directory -C Modules/$$mod) \
@@ -59,14 +38,3 @@ clean:
        @for app in $(USRAPPS); do \
        ($(MAKE) clean --no-print-directory -C Usermode/Applications/`echo $$app`_src) \
        done
-
-#      @make clean --no-print-directory -C Usermode/Libraries/ld-acess.so_src
-#      @make clean --no-print-directory -C Usermode/Libraries/libacess.so_src
-#      @make clean --no-print-directory -C Usermode/Libraries/libc.so_src
-#      @make clean --no-print-directory -C Usermode/Libraries/libgcc.so_src
-#      @make clean --no-print-directory -C Usermode/Applications/init_src
-#      @make clean --no-print-directory -C Usermode/Applications/login_src
-#      @make clean --no-print-directory -C Usermode/Applications/CLIShell_src
-#      @make clean --no-print-directory -C Usermode/Applications/cat_src
-#      @make clean --no-print-directory -C Usermode/Applications/ls_src
-#      @make clean --no-print-directory -C Usermode/Applications/mount_src
index 5a250fb..05e2897 100644 (file)
@@ -36,11 +36,11 @@ tDevFS_Driver       gIP_DriverInfo = {
        .IOCtl = IPStack_IOCtl
        }
 };
- int   glIP_Interfaces = 0;
+tSpinlock      glIP_Interfaces = 0;
 tInterface     *gIP_Interfaces = NULL;
 tInterface     *gIP_Interfaces_Last = NULL;
  int   giIP_NextIfaceId = 1;
- int   glIP_Adapters = 0;
+tSpinlock      glIP_Adapters = 0;
 tAdapter       *gIP_Adapters = NULL;
 
 // === CODE ===
index 1ccf98c..a867c11 100644 (file)
@@ -69,7 +69,7 @@ Uint8 USB_TokenCRC(void *Data, int len);
 /**
  * \note X^16 + X15 + X^2 + 1
  */
-Uint16 USB_TokenCRC(void *Data, int len);
+Uint16 USB_DataCRC(void *Data, int len);
 
 // === STRUCTURES ===
 /**
index 836c6f5..1f381e2 100644 (file)
@@ -135,7 +135,7 @@ char *ReadCommandLine(int *Length)
        char    *ret;\r
         int    len, pos, space = 1023;\r
        char    ch;\r
-       #if 1\r
+       #if 0\r
         int    scrollbackPos = giLastCommand;\r
        #endif\r
         \r

UCC git Repository :: git.ucc.asn.au