From: AceVest Date: Sun, 12 Oct 2014 01:01:27 +0000 (+0800) Subject: delete old code X-Git-Url: http://zhaoyanbai.com/repos/?a=commitdiff_plain;h=270e1e3aad85b255e8507f9c204083ddd1366d21;p=kernel.git delete old code --- diff --git a/bin/shell.c b/bin/shell.c index cd4d509..0f2a410 100644 --- a/bin/shell.c +++ b/bin/shell.c @@ -27,6 +27,10 @@ int main() char cmd[256]; read(0, cmd, 256); + int len = strlen(cmd); + if(len > 0) + cmd[len-1] = 0; + int pid = fork(); if(pid > 0) { diff --git a/drivers/console.c b/drivers/console.c index f2f7ea3..2d78b20 100644 --- a/drivers/console.c +++ b/drivers/console.c @@ -132,8 +132,7 @@ int cnsl_read(char *buf, size_t count) if(r) { - if(ch != '\n') - buf[cnt++] = ch; + buf[cnt++] = ch; task->state = TASK_RUNNING; del_wait_queue(&rdwq, &wait); diff --git a/fs/bak.ext2.c b/fs/bak.ext2.c deleted file mode 100644 index 11f7641..0000000 --- a/fs/bak.ext2.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - *-------------------------------------------------------------------------- - * File Name: ext2.c - * - * Author: Zhao Yanbai [zhaoyanbai@126.com] - * Sun Feb 14 15:52:01 2010 - * - * Description: none - * - *-------------------------------------------------------------------------- - */ - -#if 0 -#include -#include -#include -#include - -unsigned int ext2_start_sect; -Inode ext2_root_inode; - -void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count) { /*TODO*/ } -void ext2_read_block(int block_id, char *buf); -static void ext2_print_group_descriptor(pGroupDesc p); -static void ext2_print_inode(pInode p); -int ext2_search_file(const char *file, const pInode in, pInode out); -//char *ext2_loadfile(const char *path, size_t *file_size); - -/* ext2 super block */ -SuperBlock ext2_sb - __attribute__((__aligned__(PAGE_SIZE))); -Inode inode_table[NR_INODES] - __attribute__((__aligned__(PAGE_SIZE))) = {{0,},}; -/* - * ext2 group descriptor table - * 其大小为一个EXT2_BLOCK_SIZE - */ -static pGroupDesc gdesc; - -void setup_ext2() -{ - int i; - - hd_read(ROOT_DEV, ext2_start_sect+2, EXT2_SB, sizeof(SuperBlock)); - printk("EXT2 SB:%x\n", sizeof(SuperBlock)); - printk("inodes count: %d\n", EXT2_SB->s_inodes_count); - printk("blocks count: %d\n", EXT2_SB->s_blocks_count); - printk("s_magic: %x\n", EXT2_SB->s_magic); - printk("LOG BLOCK SIZE:%x\n", EXT2_SB->s_log_block_size); - printk("Block Size:%d %x\n", EXT2_BLOCK_SIZE, EXT2_BLOCK_SIZE); - - - if(EXT2_SB->s_magic != 0xEF53) - panic("Only Support Ext2 File System..."); - - /* 分配group descriptor table 的内存 */ - gdesc = (pGroupDesc) kmalloc_old(EXT2_BLOCK_SIZE); - if(gdesc == NULL) - panic("out of memory for ext2 group descritpor table"); - /* 初始化ext2 group descriptor table */ - ext2_read_block(EXT2_FIRST_BLOCK_ID+1, (char *)gdesc); -#if 0 - printk("-------%d %d %d", - EXT2_BLOCK_SIZE, EXT2_INODE_SIZE, EXT2_INODES_PER_BLOCK); - for(i=0; i<12; i++) - ext2_print_group_descriptor(gdesc+i); -#endif - - ext2_read_inode(2, &ext2_root_inode); -#if 1 - ext2_print_inode(&ext2_root_inode); -#endif - -#if 0 - Inode boot_ino, grub_ino, grubconf_ino; - int boot_n, grub_n, grubconf_n; - boot_n = ext2_search_file("boot", &ext2_root_inode, &boot_ino); - printk("boot_n:%d size:%d\n", boot_n, boot_ino.i_size); - grub_n = ext2_search_file("grub", &boot_ino, &grub_ino); - printk("grub_n:%d size:%d\n", grub_n, grub_ino.i_size); - grubconf_n = ext2_search_file("grub.conf", - &grub_ino, &grubconf_ino); - printk("grubconf_n:%d size:%d\n", grubconf_n, grubconf_ino.i_size); -#endif -#if 0 - size_t filesz; - char *buf=ext2_loadfile("/boot/grub/grub.conf", &filesz); - - for(i=0; ibg_inode_table; - - // 跳过完整的BLOCK - inotbl += (gidx/EXT2_INODES_PER_BLOCK); - gidx %= EXT2_INODES_PER_BLOCK; - - - char *buf = kmalloc_old(EXT2_BLOCK_SIZE); - if(buf == NULL) - panic("faild read inode. out of memory"); - ext2_read_block(inotbl, buf); - - memcpy((void *)ino,(void*)(((pInode)buf)+gidx), EXT2_INODE_SIZE); - - kfree_old(buf); - - return n; -} -int ext2_read_file(const pInode ino, void *buf, size_t count) -{ - int i, blks; - void *p; - - blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE; - assert(blks>0); - - if(blks > EXT2_NDIR_BLOCKS) - panic("file too large to read"); - - p = kmalloc_old(blks*EXT2_BLOCK_SIZE); - - if(p == NULL) - panic("out of memory when search inode in directory"); - - for(i=0; ii_block[i], - (char *)(i*EXT2_BLOCK_SIZE + (unsigned long)p)); - } - - memcpy(buf, p, count); - - kfree_old(p); - - return count; -} -#if 0 -char *load_inode_content(const pInode ino) -{ - int i, blks; - char *buf; - - blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE; - assert(blks>0); - if(blks > EXT2_NDIR_BLOCKS) - panic("unsupport file large than 12KB"); - - - buf = kmalloc_old(blks*EXT2_BLOCK_SIZE); - if(buf == NULL) - panic("out of memory when search inode in directory"); - for(i=0; ii_block[i], buf + i*EXT2_BLOCK_SIZE); - } - - return buf; -} -#endif - -/* - * 从in中查找file从out返回 - * int 型的函数返回值的意思是inode号 - * 失败则返回的是EXT2_BAD_INO - */ -int ext2_search_file(const char *file, const pInode in, pInode out) -{ - assert(file != NULL); - assert(in != NULL); - assert(S_ISDIR(in->i_mode)); - - char *buf; -#if 0 - buf = load_inode_content(in); -#else - buf = kmalloc_old(in->i_size); - ext2_read_file(in, buf, in->i_size); -#endif - - pDirEnt ent = (pDirEnt)buf; - int len = strlen(file); - int inode_n = EXT2_BAD_INO; - while(ent < (pDirEnt)(buf + in->i_size)) - { - if(ent->name_len == len) - { - if(strncmp(file, ent->name, ent->name_len) == 0) - { - inode_n = ent->inode; -#if 0 - printk("file: %s\n", ent->name); -#endif - break; - } - } - - - ent = (pDirEnt)(ent->rec_len + (unsigned long)ent); - } - kfree_old(buf); - - ext2_read_inode(inode_n, out); - - return inode_n; -} - - -static int get_filename_from_path(const char *path, char *filename) -{ - int i = 0; - - while(*path != '/' && *path != '\0') - { - filename[i++] = *path++; - } - filename[i] = 0; - - - return i; // file name len -} - - -int ext2_get_file_inode_nr(const char *path) -{ - assert(*path++ == '/'); /* 目前只支持从根目录开始的路径 */ - Inode ino = ext2_root_inode; - int ino_nr, len; - char file[EXT2_NAME_LEN]; - - while((len=get_filename_from_path(path, file)) != 0) - { -#if 0 - printk("file: %s ", file); -#endif - ino_nr = ext2_search_file(file, &ino, &ino); - - path += len; - - if(*path != 0) - path++; - } -#if 0 - printk("ino_nr:%d\n", ino_nr); -#endif - return ino_nr; -} - -#if 0 -/* - * 需要自己释放内存 - */ -char *ext2_loadfile(const char *path, size_t *file_size) -{ - char *buf; - buf = load_inode_content(&inode); - *file_size = inode.i_size; - - return buf; -} -#endif - -static void ext2_print_group_descriptor(pGroupDesc p) -{ - printk("block bitmap:%d inode bitmap:%d inode table:%d\n", - p->bg_block_bitmap, - p->bg_inode_bitmap, - p->bg_inode_table); -} - -static void ext2_print_inode(pInode p) -{ - printk("i_mode:%04x i_size:%d i_blocks:%d\n", - p->i_mode, p->i_size, p->i_blocks); -} -#endif diff --git a/include/system.h b/include/system.h index adb24f6..c72fb0f 100644 --- a/include/system.h +++ b/include/system.h @@ -56,33 +56,6 @@ void *kmalloc(size_t size, gfp_t gfpflags); void kfree(void *addr); -void *kmalloc_old(size_t size); -void kfree_old(void *p); - -static inline void *get_virt_pages(unsigned int n) -{ - assert(n>0); - size_t size = n << PAGE_SHIFT; - return (void*) kmalloc_old(size); -} -static inline void free_virt_pages(void *p) -{ - kfree_old((void *)p); -} -static inline void *get_phys_pages(unsigned int n) -{ -/* - assert(n>0); - size_t size = n << PAGE_SHIFT; - return (void*) va2pa(kmalloc_old(size)); -*/ - return (void *)va2pa(get_virt_pages(n)); -} -static inline void free_phys_pages(void *p) -{ - free_virt_pages((void*)va2pa(p)); -} - #define panic(msg, ...) do { \ asm("cli;"); \ printk("PANIC:" \ @@ -107,7 +80,6 @@ char gdtr[6],idtr[6]; #define ALIGN(x, a) (((x)+(a)-1) & ~((a)-1)) - // 1 GB #define MAX_SUPT_PHYMM_SIZE (1UL<<30) @@ -131,33 +103,7 @@ enum GDTSelectorIndex INDEX_EMP8, INDEX_TSS, }; -#if 0 -// pushal push eax, ecx, edx, ebx, esp, ebp, esi, edi -typedef struct pt_regs -{ - u32 edi; - u32 esi; - u32 ebp; - u32 ebx; - u32 edx; - u32 ecx; - u32 eax; - u16 ds, _ds; - u16 es, _es; - u16 fs, _fs; - u16 gs, _gs; - union - { - u32 irq; - u32 errcode; - }; - u32 eip; - u16 cs, _cs; - u32 eflags; - u32 esp; - u16 ss, _ss; -} __attribute__((packed)) pt_regs_t; -#else + typedef struct pt_regs { u32 ebx; @@ -182,7 +128,6 @@ typedef struct pt_regs u32 esp; u16 ss, _ss; } __attribute__((packed)) pt_regs_t; -#endif typedef unsigned long dev_t; @@ -298,9 +243,6 @@ void system_delay(); #define REBOOT_RESTART 0x00 #define REBOOT_POWEROFF 0x01 - -#define ROOT_DEV system.root_dev - #define KRNL_INIT_STACK_SIZE 4096 #endif //_SYSTEM_H diff --git a/mm/kmalloc.c b/mm/kmalloc.c deleted file mode 100644 index b22ab1f..0000000 --- a/mm/kmalloc.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - *-------------------------------------------------------------------------- - * File Name: kmalloc_old.c - * - * Author: Zhao Yanbai [zhaoyanbai@126.com] - * Sat Jan 30 12:15:51 2010 - * - * Description: 现在的版本实现得非常简单,简陋。不能分配大于32*4K的内存 - * 另外小于32*4K的都按32*4K分配 - * 以后再来重写这里吧 - *-------------------------------------------------------------------------- - */ -#include -#include -#include -#include - -static int get_order(size_t size) -{ - int i; - return i; -} -void *kmalloc_old(size_t size) -{ - void *p; - return p; -} - - -void kfree_old(void *p) -{ - -} diff --git a/scripts/grub.cfg b/scripts/grub.cfg index 26f771f..08efd8b 100644 --- a/scripts/grub.cfg +++ b/scripts/grub.cfg @@ -8,5 +8,5 @@ insmod ext2 root=(hd0,msdos1) menuentry 'Kernel' --class os { - multiboot /boot/Kernel root=hda0 delay=20000000 + multiboot /boot/Kernel root=hda0 delay=2 }