Fixed bug with handling of . and .. that was trashing the heap. Fixed soname of libgc...
authorJohn Hodge <[email protected]>
Fri, 2 Oct 2009 15:22:01 +0000 (23:22 +0800)
committerJohn Hodge <[email protected]>
Fri, 2 Oct 2009 15:22:01 +0000 (23:22 +0800)
Kernel/heap.c
Kernel/threads.c
Kernel/vfs/open.c
Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/ls_src/main.c
Usermode/Libraries/ld-acess.so_src/main.c
Usermode/Libraries/libgcc.so_src/Makefile

index 79f5f40..0bffaec 100644 (file)
@@ -280,7 +280,7 @@ void free(void *Ptr)
                return;
        }
        if(foot->Magic != MAGIC_FOOT) {
-               Warning("free - Footer magic is invalid (%p, 0x%x)\n", head, foot->Magic);
+               Warning("free - Footer magic is invalid (%p, %p = 0x%x)\n", head, &foot->Magic, foot->Magic);
                return;
        }
        
index 5f2e3d7..e244139 100644 (file)
@@ -455,7 +455,7 @@ void Threads_Sleep()
        tThread *cur = Proc_GetCurThread();
        tThread *thread;
        
-       Log("Proc_Sleep: %i going to sleep", cur->TID);
+       //Log("Proc_Sleep: %i going to sleep", cur->TID);
        
        // Acquire Spinlock
        LOCK( &giThreadListLock );
index 6f03417..2fc27d6 100644 (file)
@@ -89,17 +89,22 @@ char *VFS_GetAbsPath(char *Path)
                if(pos - read <= 2)
                {
                        // Current Dir "."
-                       if(strncmp(&ret[read], ".", pos-read) == 0)     continue;
+                       if(strncmp(&ret[read], ".", pos-read) == 0) {
+                               ret[write] = '\0';
+                               continue;
+                       }
                        // Parent ".."
                        if(strncmp(&ret[read], "..", pos-read) == 0)
                        {
                                // If there is no higher, silently ignore
                                if(slashNum < 1) {
                                        write = 1;
+                                       ret[1] = '\0';
                                        continue;
                                }
                                // Reverse write pointer
                                write = slashOffsets[ --slashNum ];
+                               ret[write] = '\0';
                                continue;
                        }
                }
@@ -125,7 +130,6 @@ char *VFS_GetAbsPath(char *Path)
                write += (pos-read)+1;
        }
        
-       ret[write] = '\0';      // Cap string (to deal with . or .. being the last terms)
        // `ret` should now be the absolute path
        LEAVE('s', ret);
        //Log("VFS_GetAbsPath: RETURN '%s'", ret);
index ec83ac9..a8db5ad 100644 (file)
@@ -48,7 +48,7 @@ char  **gasCommandHistory;
 int main(int argc, char *argv[], char *envp[])\r
 {\r
        char    *sCommandStr;\r
-       char    *saArgs[32];\r
+       char    *saArgs[32] = {0};\r
         int    length = 0;\r
         int    i;\r
         int    iArgCount = 0;\r
index 82f9c2a..fc99a40 100644 (file)
@@ -8,11 +8,20 @@
 
 #define        BUF_SIZE        1024
 
+// === CONSTANTS ===
+enum eFileTypes {
+       FTYPE_NORMAL,
+       FTYPE_EXEC,
+       FTYPE_DIR,
+       FTYPE_SYMLINK
+};
+
 // === PROTOTYPES ===
  int   main(int argc, char *argv[]);
 void   ShowUsage(char *ProgName);
 void   ParseArguments(int argc, char *argv[]);
 void   SortFileList();
+void   DisplayFile(char *Filename);
 
 // === GLOBALS ===
 // --- Flags ---
@@ -33,6 +42,7 @@ char  **gFileList;
 int main(int argc, char *argv[])
 {
         int    fd, tmp;
+        int    i;
        char    buf[BUF_SIZE+1];
        t_sysFInfo      info;
         int    space = 0;
@@ -55,6 +65,15 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
        }
 
+       // Check if we should include the implicit . and ..
+       if(gbShowImplicit)
+       {
+               space = 16;
+               gFileList = malloc(space*sizeof(char*));
+               gFileList[giNumFiles++] = ".";
+               gFileList[giNumFiles++] = "..";
+       }
+
        // Traverse Directory
        while( (tmp = readdir(fd, buf)) )
        {
@@ -80,6 +99,12 @@ int main(int argc, char *argv[])
        // Sort File List according to rules passed
        SortFileList();
 
+       // Show the file list
+       for( i = 0; i < giNumFiles; i ++ )
+       {
+               DisplayFile( gFileList[i] );
+       }
+
        close(fd);
        printf("\n");
 
@@ -163,3 +188,118 @@ void SortFileList()
 {
        qsort(gFileList, giNumFiles, sizeof(char*), strcmpp);
 }
+
+/**
+ * \fn void DisplayFile(char *Filename)
+ * \brief Prints out the information for a file
+ */
+void DisplayFile(char *Filename)
+{
+       t_sysFInfo      info;
+       t_sysACL        acl;
+       char    *path;
+        int    fd;
+        int    dirLen = strlen(gsDirectory);
+        int    type = FTYPE_NORMAL, perms = 0;
+       uint64_t        size = 0;
+        int    owner = 0, group = 0;
+       
+       // Check if we should skip this file
+       if(!gbShowAll && Filename[0] == '.')    return;
+       
+       // Allocate path
+       path = malloc(dirLen+1+strlen(Filename)+1);
+       if(!path) {
+               fprintf(stderr, "heap exhausted\n");
+               exit(EXIT_FAILURE);
+       }
+       
+       // Create path
+       strcpy(path, gsDirectory);
+       path[dirLen] = '/';
+       strcpy(&path[dirLen+1], Filename);
+       
+       // Get file type
+       fd = open(path, 0);
+       if(fd == -1) {
+               fprintf(stderr, "Unable to open '%s'\n", path);
+       }
+       else {
+               // Get Info
+               finfo(fd, &info, 0);
+               // Get Type
+               if(info.flags & FILEFLAG_DIRECTORY) {
+                       type = FTYPE_DIR;
+               }
+               else if(info.flags & FILEFLAG_SYMLINK) {
+                       type = FTYPE_SYMLINK;
+               }
+               else {
+                       type = FTYPE_NORMAL;
+               }
+               // Get Size
+               size = info.size;
+               // Get Owner and Group
+               owner = info.uid;
+               group = info.gid;
+               
+               // Get Permissions
+               // - Owner
+               acl.group = 0;  acl.id = info.uid;
+               _SysGetACL(fd, &acl);
+               if(acl.perms & 1)       perms |= 0400;  // R
+               if(acl.perms & 2)       perms |= 0200;  // W
+               if(acl.perms & 8)       perms |= 0100;  // X
+               // - Group
+               acl.group = 1;  acl.id = info.gid;
+               _SysGetACL(fd, &acl);
+               if(acl.perms & 1)       perms |= 0040;  // R
+               if(acl.perms & 2)       perms |= 0020;  // W
+               if(acl.perms & 8)       perms |= 0010;  // X
+               // - World
+               acl.group = 1;  acl.id = -1;
+               _SysGetACL(fd, &acl);
+               if(acl.perms & 1)       perms |= 0004;  // R
+               if(acl.perms & 2)       perms |= 0002;  // W
+               if(acl.perms & 8)       perms |= 0001;  // X
+       }
+       free(path);     // We're finished with it
+       
+       // Extended view?
+       if(gbViewExtended)
+       {
+               char    permStr[11] = " ---------";
+               if(type == FTYPE_DIR)   permStr[0] = 'd';
+               if(perms & 0400)        permStr[1] = 'r';
+               if(perms & 0200)        permStr[2] = 'w';
+               if(perms & 0100)        permStr[3] = 'x';
+               if(perms & 0040)        permStr[4] = 'r';
+               if(perms & 0020)        permStr[5] = 'w';
+               if(perms & 0010)        permStr[6] = 'x';
+               if(perms & 0004)        permStr[7] = 'r';
+               if(perms & 0002)        permStr[8] = 'w';
+               if(perms & 0001)        permStr[9] = 'x';
+               printf("%s %4i %4i ", permStr, owner, group);
+               if(gbViewHumanReadable) {
+                       if(size < 2048) {       // < 2 KiB
+                               printf("%8lli B   ", size);
+                       }
+                       else if(size < 2048*1024) {     // < 2 MiB
+                               printf("%8lli KiB ", size>>10);
+                       }
+                       else if(size < (uint64_t)2048*1024*1024) {      // < 2 GiB
+                               printf("%8lli MiB ", size>>20);
+                       }
+                       else if(size < (uint64_t)2048*1024*1024*1024) { // < 2 TiB
+                               printf("%8lli GiB ", size>>30);
+                       }
+                       else {  // Greater than 2 TiB
+                               printf("%8i TiB ", size>>40);
+                       }
+               } else {
+                       printf("%8i ", size);
+               }
+       }
+       
+       printf("%s\n", Filename);
+}
index a250afa..dc5d4d3 100644 (file)
@@ -23,8 +23,8 @@ int SoMain(Uint base, int arg1)
 {\r
         int    ret;\r
        \r
-       SysDebug("SoMain: base = 0x%x", base);\r
-       SysDebug("SoMain: arg1 = 0x%x", arg1);\r
+       //SysDebug("SoMain: base = 0x%x", base);\r
+       //SysDebug("SoMain: arg1 = 0x%x", arg1);\r
         \r
        // - Assume that the file pointer will be less than 4096\r
        if(base < 0x1000) {\r
@@ -79,7 +79,7 @@ int DoRelocate( Uint base, char **envp, char *Filename )
 */\r
 int CallUser(Uint entry, Uint sp)\r
 {\r
-       SysDebug("CallUser: (entry=0x%x, sp=0x%x)", entry, sp);\r
+       //SysDebug("CallUser: (entry=0x%x, sp=0x%x)", entry, sp);\r
        *(Uint*)(sp-4) = 0;     // Clear return address\r
        __asm__ __volatile__ (\r
        "mov %%eax, %%esp;\n\t"\r
index ada47db..e57f3a2 100644 (file)
@@ -8,7 +8,7 @@ OBJS = libgcc.o
 BIN = ../libgcc.so
 
 CFLAGS  += -Wall -Werror
-LDFLAGS += -soname libgcc.acess.so
+LDFLAGS += -soname libgcc.so
 
 .PHONY: all clean
 

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