Compare commits
4 Commits
049405989b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e0c37abee | |||
| d5c8b24c64 | |||
| ae0a2c0430 | |||
| b6bc6da235 |
4
config.h
4
config.h
@@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
|
|
||||||
/* CLI config section */
|
/* CLI config section */
|
||||||
#define CLI_MAX_LINE_LENGTH 256
|
#define CLI_MAX_LINE_LENGTH 1024
|
||||||
#define CLI_MAX_ACCEPTED_ARGS 4
|
#define CLI_MAX_ACCEPTED_ARGS 4
|
||||||
#define CLI_MAX_TOKEN_LENGTH 64
|
#define CLI_MAX_TOKEN_LENGTH 256
|
||||||
|
|
||||||
|
|
||||||
/* FS config section */
|
/* FS config section */
|
||||||
|
|||||||
14
src/cli.c
14
src/cli.c
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
static const struct CliCommandEntry cmd[] = {
|
static const struct CliCommandEntry cmd[] = {
|
||||||
@@ -208,11 +209,11 @@ abandon_struct:
|
|||||||
|
|
||||||
unsigned int cli_poll_process_next(void)
|
unsigned int cli_poll_process_next(void)
|
||||||
{
|
{
|
||||||
for ( ;; ) {
|
int echo_commands = !isatty(STDIN_FILENO);
|
||||||
fputs(fs_get_cwd(), stdout);
|
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
if (fs_get_cwd()[0]) {
|
if (fs_get_cwd()[0]) {
|
||||||
printf(" $ ");
|
printf("%s $ ", fs_get_cwd());
|
||||||
} else {
|
} else {
|
||||||
printf("$ ");
|
printf("$ ");
|
||||||
}
|
}
|
||||||
@@ -221,8 +222,13 @@ unsigned int cli_poll_process_next(void)
|
|||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
|
|
||||||
ssize_t result = getline(&line, &buf_size, stdin);
|
ssize_t result = getline(&line, &buf_size, stdin);
|
||||||
if (result == -1)
|
if (result == -1) {
|
||||||
|
printf("\n");
|
||||||
return 0x1;
|
return 0x1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (echo_commands)
|
||||||
|
printf(line);
|
||||||
|
|
||||||
char **tokenized_line = tokenize_line(line, result);
|
char **tokenized_line = tokenize_line(line, result);
|
||||||
free(line);
|
free(line);
|
||||||
|
|||||||
73
src/fs.c
73
src/fs.c
@@ -998,6 +998,8 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pr("Found symlink '%s', following (-> '%s')\n", next_fname, symlink_path);
|
||||||
|
|
||||||
if (symlink_path[0] == '/') {
|
if (symlink_path[0] == '/') {
|
||||||
memmove(&(path[symlink_path_len]), &(path[i+1]), path_len-i-1);
|
memmove(&(path[symlink_path_len]), &(path[i+1]), path_len-i-1);
|
||||||
strcpy(path, &(symlink_path[1]));
|
strcpy(path, &(symlink_path[1]));
|
||||||
@@ -1021,6 +1023,7 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!(params & FOLLOW_LAST_SYMLINK)) {
|
if (!(params & FOLLOW_LAST_SYMLINK)) {
|
||||||
|
pr("Stopping at symlink '%s', not following\n", next_fname);
|
||||||
rp->target_inode_ptr = res;
|
rp->target_inode_ptr = res;
|
||||||
strcpy(rp->parent_fname, current_fname);
|
strcpy(rp->parent_fname, current_fname);
|
||||||
strcpy(rp->target_fname, next_fname);
|
strcpy(rp->target_fname, next_fname);
|
||||||
@@ -1045,6 +1048,8 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pr("Found symlink '%s' at last position, following (-> '%s')\n", next_fname, symlink_path);
|
||||||
|
|
||||||
if (!strcmp(symlink_path, "/")) {
|
if (!strcmp(symlink_path, "/")) {
|
||||||
rp->parent_inode_ptr = 0;
|
rp->parent_inode_ptr = 0;
|
||||||
rp->target_inode_ptr = 0;
|
rp->target_inode_ptr = 0;
|
||||||
@@ -1078,6 +1083,7 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori
|
|||||||
rp->target_inode_ptr = -1;
|
rp->target_inode_ptr = -1;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
pr("Stopping at regular file '%s'\n", next_fname);
|
||||||
rp->target_inode_ptr = res;
|
rp->target_inode_ptr = res;
|
||||||
strcpy(rp->parent_fname, current_fname);
|
strcpy(rp->parent_fname, current_fname);
|
||||||
strcpy(rp->target_fname, next_fname);
|
strcpy(rp->target_fname, next_fname);
|
||||||
@@ -1092,6 +1098,7 @@ static void resolve_path(struct resolved_path * const rp, const char * const ori
|
|||||||
strcpy(current_fname, next_fname);
|
strcpy(current_fname, next_fname);
|
||||||
memset(next_fname, 0, FS_MAX_FNAME_LEN);
|
memset(next_fname, 0, FS_MAX_FNAME_LEN);
|
||||||
} else {
|
} else {
|
||||||
|
pr("Stopping at directory '%s'\n", next_fname);
|
||||||
rp->target_inode_ptr = res;
|
rp->target_inode_ptr = res;
|
||||||
strcpy(rp->parent_fname, current_fname);
|
strcpy(rp->parent_fname, current_fname);
|
||||||
strcpy(rp->target_fname, next_fname);
|
strcpy(rp->target_fname, next_fname);
|
||||||
@@ -2419,15 +2426,29 @@ int fs_la(void *d)
|
|||||||
struct fs_inode f_inode;
|
struct fs_inode f_inode;
|
||||||
read_block(read_inode_ptr(recs[k].inode_no), (void *) &f_inode);
|
read_block(read_inode_ptr(recs[k].inode_no), (void *) &f_inode);
|
||||||
|
|
||||||
if (f_inode.ftype == DIRECTORY) {
|
if (f_inode.ftype == REGULAR) {
|
||||||
|
pr_stdout("%s (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=reg)\n",
|
||||||
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
|
f_inode.ref_count, f_inode.size);
|
||||||
|
} else if (f_inode.ftype == DIRECTORY) {
|
||||||
pr_stdout(COLOR_BLUE "%s" COLOR_RESET
|
pr_stdout(COLOR_BLUE "%s" COLOR_RESET
|
||||||
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=dir)\n",
|
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=dir)\n",
|
||||||
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
f_inode.ref_count, f_inode.size);
|
f_inode.ref_count, f_inode.size);
|
||||||
} else {
|
} else if (f_inode.ftype == SYMLINK) {
|
||||||
pr_stdout("%s (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=reg)\n",
|
char l_path[FS_MAX_PATH_LEN+1];
|
||||||
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
int l_path_len = read_symlink(recs[k].inode_no, l_path);
|
||||||
f_inode.ref_count, f_inode.size);
|
|
||||||
|
if (l_path_len > 0)
|
||||||
|
pr_stdout(COLOR_CYAN "%s" COLOR_RESET
|
||||||
|
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=lnk, -> '%s')\n",
|
||||||
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
|
f_inode.ref_count, f_inode.size, l_path);
|
||||||
|
else
|
||||||
|
pr_stdout(COLOR_RED "%s" COLOR_RESET
|
||||||
|
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=lnk)\n",
|
||||||
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
|
f_inode.ref_count, f_inode.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2454,15 +2475,29 @@ int fs_la(void *d)
|
|||||||
struct fs_inode f_inode;
|
struct fs_inode f_inode;
|
||||||
read_block(read_inode_ptr(recs[k].inode_no), (void *) &f_inode);
|
read_block(read_inode_ptr(recs[k].inode_no), (void *) &f_inode);
|
||||||
|
|
||||||
if (f_inode.ftype == DIRECTORY) {
|
if (f_inode.ftype == REGULAR) {
|
||||||
|
pr_stdout("%s (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=reg)\n",
|
||||||
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
|
f_inode.ref_count, f_inode.size);
|
||||||
|
} else if (f_inode.ftype == DIRECTORY) {
|
||||||
pr_stdout(COLOR_BLUE "%s" COLOR_RESET
|
pr_stdout(COLOR_BLUE "%s" COLOR_RESET
|
||||||
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=dir)\n",
|
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=dir)\n",
|
||||||
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
f_inode.ref_count, f_inode.size);
|
f_inode.ref_count, f_inode.size);
|
||||||
} else {
|
} else if (f_inode.ftype == SYMLINK) {
|
||||||
pr_stdout("%s (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=reg)\n",
|
char l_path[FS_MAX_PATH_LEN+1];
|
||||||
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
int l_path_len = read_symlink(recs[k].inode_no, l_path);
|
||||||
f_inode.ref_count, f_inode.size);
|
|
||||||
|
if (l_path_len > 0)
|
||||||
|
pr_stdout(COLOR_CYAN "%s" COLOR_RESET
|
||||||
|
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=lnk, -> '%s')\n",
|
||||||
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
|
f_inode.ref_count, f_inode.size, l_path);
|
||||||
|
else
|
||||||
|
pr_stdout(COLOR_RED "%s" COLOR_RESET
|
||||||
|
" (inode_ptr=%d -> inode=%d, ref_count=%d, size=%d, type=lnk)\n",
|
||||||
|
recs[k].fname, recs[k].inode_no, read_inode_ptr(recs[k].inode_no),
|
||||||
|
f_inode.ref_count, f_inode.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2486,12 +2521,22 @@ int fs_stat(void *d)
|
|||||||
struct fs_inode i;
|
struct fs_inode i;
|
||||||
read_block(read_inode_ptr(rp.target_inode_ptr), &i);
|
read_block(read_inode_ptr(rp.target_inode_ptr), &i);
|
||||||
|
|
||||||
if (i.ftype == DIRECTORY) {
|
if (i.ftype == REGULAR) {
|
||||||
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=dir\n",
|
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=regular\n",
|
||||||
rp.target_inode_ptr, read_inode_ptr(rp.target_inode_ptr), i.ref_count, i.size);
|
rp.target_inode_ptr, read_inode_ptr(rp.target_inode_ptr), i.ref_count, i.size);
|
||||||
} else {
|
} else if (i.ftype == DIRECTORY) {
|
||||||
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=reg\n",
|
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=directory\n",
|
||||||
rp.target_inode_ptr, read_inode_ptr(rp.target_inode_ptr), i.ref_count, i.size);
|
rp.target_inode_ptr, read_inode_ptr(rp.target_inode_ptr), i.ref_count, i.size);
|
||||||
|
} else if (i.ftype == SYMLINK) {
|
||||||
|
char l_path[FS_MAX_PATH_LEN+1];
|
||||||
|
int l_path_len = read_symlink(rp.target_inode_ptr, l_path);
|
||||||
|
if (l_path_len > 0) {
|
||||||
|
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=symlink\npoints to: %s\n",
|
||||||
|
rp.target_inode_ptr, read_inode_ptr(rp.target_inode_ptr), i.ref_count, i.size, l_path);
|
||||||
|
} else {
|
||||||
|
pr_stdout("inode_ptr=%d -> inode=%d\nref_count=%d\nsize=%d\ntype=symlink\n<broken>\n",
|
||||||
|
rp.target_inode_ptr, read_inode_ptr(rp.target_inode_ptr), i.ref_count, i.size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
55
testing_script.t
Normal file
55
testing_script.t
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
use disk1
|
||||||
|
mkfs 32
|
||||||
|
|
||||||
|
mkdir test1
|
||||||
|
mkdir test2
|
||||||
|
la
|
||||||
|
|
||||||
|
cd test1
|
||||||
|
la
|
||||||
|
|
||||||
|
create hello1
|
||||||
|
mkdir inside
|
||||||
|
symlink ../../test2/ inside/hello3
|
||||||
|
stat inside/hello3
|
||||||
|
|
||||||
|
cd ../test2
|
||||||
|
la
|
||||||
|
|
||||||
|
symlink ../test1/inside hello2
|
||||||
|
stat hello2
|
||||||
|
|
||||||
|
cd /
|
||||||
|
cd test1/../test2/hello2/../../test2/.././././test1/inside/hello3/./hello2/.
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
create inside/././hello3/.././test1/f7
|
||||||
|
symlink /test1/f7 ../f1
|
||||||
|
la
|
||||||
|
cd ..
|
||||||
|
la
|
||||||
|
cd test1
|
||||||
|
open ../test2/hello2/../../f1
|
||||||
|
write 0 data
|
||||||
|
la
|
||||||
|
close 0
|
||||||
|
|
||||||
|
cd /
|
||||||
|
rm test1
|
||||||
|
rmdir test1
|
||||||
|
rm test1/inside/hello3
|
||||||
|
rmdir test1/inside
|
||||||
|
rm test1/hello1
|
||||||
|
rm test1/f7
|
||||||
|
rmdir test1
|
||||||
|
|
||||||
|
cd test2
|
||||||
|
la
|
||||||
|
cd hello2
|
||||||
|
|
||||||
|
symlink garbage/ttttt ..
|
||||||
|
cd ..
|
||||||
|
la
|
||||||
|
|
||||||
|
cd ttttt
|
||||||
|
rm ttttt
|
||||||
Reference in New Issue
Block a user