]> Zhao Yanbai Git Server - kernel.git/commitdiff
improve shell
authorAceVest <zhaoyanbai@126.com>
Thu, 31 Jul 2014 17:31:02 +0000 (01:31 +0800)
committerAceVest <zhaoyanbai@126.com>
Thu, 31 Jul 2014 17:31:02 +0000 (01:31 +0800)
bin/shell.c
fs/ext2.c

index 5b62fd5e73c6d041db276bf3bfe13b76f11457a7..295ea12077a8394b0fc8f10ac521bde64e4bcb13 100644 (file)
 #include <types.h>
 #include <string.h>
 
-int systest();
-int sysdebug();
-int pause(unsigned long tick);
 int main()
 {
 
     while(1)
     {
         printf("shell#");
-        char buf[256];
-        read(0, buf, 256);
+        char cmd[256];
+        read(0, cmd, 256);
 
         int pid = fork();
         if(pid > 0)
@@ -32,30 +29,12 @@ int main()
         }
         else
         {
-            execv(buf, 0);
+            execv(cmd, 0);
+            printf("failed to execute cmd: %s\n", cmd);
+            exit(0);
         }
     }
 
 
-
-    int pid = fork();
-    printf("pid %u\n", pid);
-    if(pid > 0)
-    {
-        printf("parent. child pid %u\n", pid);
-        while(1) {
-            systest();
-            sysdebug(0x44444444);
-        }
-    }
-    else
-    {
-        printf("child\n");
-        while(1) {
-            systest();
-            sysdebug(0xAABBCCDD);
-        }
-    }
-
     return 0;
 }
index 06c060e8f527cc9bbc3c7a0b5562c073363fee63..9bff1cff0a42cd0d3f57fc11f1efd5dd65f6060e 100644 (file)
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -125,9 +125,10 @@ void ext2_read_data(const ext2_inode_t *inode, unsigned int offset, size_t size,
 }
 
 
-unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode)
+unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode, unsigned int *file_type)
 {
     unsigned int ino = 0;
+    *file_type = EXT2_FT_UNKNOWN;
 
     void *blk = ext2_alloc_block();
     assert(blk != 0);
@@ -146,10 +147,17 @@ unsigned int ext2_search_indir(const char *name, const ext2_inode_t *inode)
         if(strcmp(name, tmp) == 0)
         {
             ino = dirent->inode;
+            *file_type = dirent->file_type;
             break;
         }
 
         dirent = (ext2_dirent_t *) (((unsigned int)dirent) + dirent->rec_len);
+
+        if(((unsigned long) dirent - (unsigned long)blk) >= EXT2_BLOCK_SIZE)
+        {
+            ino = 0;
+            break;
+        }
     }
     
     ext2_free_block(blk);
@@ -174,6 +182,9 @@ static int get_filename_from_path(const char *path, char *file)
 
 unsigned int ext2_search_inpath(const char *path)
 {
+    if(path == 0 || strlen(path) == 0 || path[0] != '/')
+        return 0;
+
     assert(path != 0);
     assert(strlen(path) > 0);
     assert(path[0] == '/');
@@ -188,9 +199,12 @@ unsigned int ext2_search_inpath(const char *path)
     char file[MAX_FILE_NAME];
     int len;
 
+    unsigned int file_type = EXT2_FT_UNKNOWN;
     while((len=get_filename_from_path(path, file)) != 0)
     {
-        ino = ext2_search_indir(file, inode);
+        ino = ext2_search_indir(file, inode, &file_type);
+        if(ino == 0)
+            return 0;
         //assert(ino != 0);
 
         path += len;
@@ -201,9 +215,15 @@ unsigned int ext2_search_inpath(const char *path)
             ext2_read_inode(ino, inode);
         }
         else
+        {
+            return 0;
             assert(0);
+        }
     }
 
+    if(file_type != EXT2_FT_REG_FILE)
+        return 0;
+
     return ino;
 }
 
@@ -257,21 +277,6 @@ void ext2_setup_fs()
     }
 
     ext2_read_inode(2, &ext2_root_inode);
-#if 0
-    printk("root inode.i_size %u \n", ext2_root_inode.i_size);
-    printk("root blocks %u \n", ext2_root_inode.i_blocks);
-
-    ext2_read_inode(ext2_search_indir("boot", &ext2_root_inode), &boot_inode);
-    ext2_read_inode(ext2_search_indir("Kernel", &boot_inode), &krnl_inode);
-    printk("krnl inode.i_size %u \n", krnl_inode.i_size);
-    printk("krnl blocks %u \n", krnl_inode.i_blocks);
-#endif
-
-
-    //printk("----- ino %u\n", ext2_search_inpath("/bin/test/test.txt"));
-    //printk("----- ino %u\n", ext2_search_inpath("/bin/hello"));
-    //printk("----- ino %u\n", ext2_search_inpath("/boot/Kernel"));
-    //printk("----- ino %u\n", ext2_search_inpath("/boot/grub2/fonts/unicode.pf2"));
 }