Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 46a22bf)
raw | patch | inline | side by side (parent: 46a22bf)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Thu, 31 Jul 2014 17:31:02 +0000 (01:31 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 02:45:41 +0000 (10:45 +0800) |
| bin/shell.c | patch | blob | history | |
| fs/ext2.c | patch | blob | history |
diff --git a/bin/shell.c b/bin/shell.c
--- a/bin/shell.c
+++ b/bin/shell.c
#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)
}
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;
}
diff --git a/fs/ext2.c b/fs/ext2.c
--- 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);
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);
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] == '/');
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;
ext2_read_inode(ino, inode);
}
else
+ {
+ return 0;
assert(0);
+ }
}
+ if(file_type != EXT2_FT_REG_FILE)
+ return 0;
+
return ino;
}
}
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"));
}