add stat
This commit is contained in:
parent
3ee64e5b5d
commit
dc611bb787
1
inc/fs.h
1
inc/fs.h
|
@ -54,6 +54,7 @@ int fs_use(void *d);
|
|||
int fs_mkfs(void *d);
|
||||
int fs_ls(void *d);
|
||||
int fs_la(void *d);
|
||||
int fs_stat(void *d);
|
||||
int fs_rm(void *d);
|
||||
int fs_open(void *d);
|
||||
int fs_seek(void *d);
|
||||
|
|
|
@ -15,7 +15,7 @@ static const struct CliCommandEntry cmd[] = {
|
|||
// mandatory commands
|
||||
{"mkfs", 1, (enum CliArgType[]) {INT}, fs_mkfs},
|
||||
{"create", 1, (enum CliArgType[]) {STR}, fs_create},
|
||||
//{"stat", 1, (enum CliArgType[]) {STR}, fs_stat},
|
||||
{"stat", 1, (enum CliArgType[]) {STR}, fs_stat},
|
||||
{"ls", 0, NULL, fs_ls},
|
||||
{"ln", 2, (enum CliArgType[]) {STR, STR}, fs_ln},
|
||||
{"rm", 1, (enum CliArgType[]) {STR}, fs_rm},
|
||||
|
|
30
src/fs.c
30
src/fs.c
|
@ -1314,6 +1314,36 @@ int fs_la(void *d)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int fs_stat(void *d)
|
||||
{
|
||||
char *fname = *((char **) d);
|
||||
|
||||
int file_inode_ptr;
|
||||
{
|
||||
int *r = find_filename_in_directory(fs_cwd_inode_ptr, fname);
|
||||
if (r == NULL) {
|
||||
pr_err("no such file: '%s'\n", fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
file_inode_ptr = r[2];
|
||||
free(r);
|
||||
}
|
||||
|
||||
struct fs_inode f;
|
||||
read_block(read_inode_ptr(file_inode_ptr), (void *) &f);
|
||||
|
||||
if (f.ftype == DIRECTORY) {
|
||||
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=dir\n",
|
||||
file_inode_ptr, read_inode_ptr(file_inode_ptr), f.ref_count, f.size);
|
||||
} else {
|
||||
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=reg\n",
|
||||
file_inode_ptr, read_inode_ptr(file_inode_ptr), f.ref_count, f.size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fs_use(void *d)
|
||||
{
|
||||
char *fname = *((char **) d);
|
||||
|
|
Loading…
Reference in New Issue