Compare commits
13 Commits
941c51200c
...
lab5
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e0c37abee | |||
| d5c8b24c64 | |||
| ae0a2c0430 | |||
| b6bc6da235 | |||
| 049405989b | |||
| 1dbdbd20d3 | |||
| db6187be39 | |||
| 552e574cde | |||
| 72a02047d5 | |||
| 585492b6d7 | |||
| 4e37240971 | |||
| d68b874b24 | |||
| 117e8706a8 |
@@ -1,4 +1,4 @@
|
|||||||
CFLAGS = -g3 -O0 -I. -Iinc
|
CFLAGS = -g3 -O0 -Wall -Wpedantic -I. -Iinc
|
||||||
|
|
||||||
build: main
|
build: main
|
||||||
|
|
||||||
|
|||||||
@@ -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 */
|
||||||
@@ -26,7 +26,8 @@
|
|||||||
#define FS_MAX_PATH_LEN 512
|
#define FS_MAX_PATH_LEN 512
|
||||||
#define FS_MAX_OPEN_FD 32
|
#define FS_MAX_OPEN_FD 32
|
||||||
#define FS_MAX_FNAME_LEN 11
|
#define FS_MAX_FNAME_LEN 11
|
||||||
#define FS_MAX_DIRECTORY_DEPTH 512
|
#define FS_MAX_DIRECTORY_DEPTH 2048
|
||||||
|
#define FS_MAX_SYMLINK_FOLLOWS 1024
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+5
-5
@@ -5,11 +5,11 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if COLOR_ENABLE == 1
|
#if COLOR_ENABLE == 1
|
||||||
#define COLOR_RESET "\e[0m"
|
#define COLOR_RESET "\x1b[0m"
|
||||||
#define COLOR_RED "\e[0;31m"
|
#define COLOR_RED "\x1b[0;31m"
|
||||||
#define COLOR_YELLOW "\e[0;33m"
|
#define COLOR_YELLOW "\x1b[0;33m"
|
||||||
#define COLOR_BLUE "\e[0;34m"
|
#define COLOR_BLUE "\x1b[0;34m"
|
||||||
#define COLOR_CYAN "\e[0;36m"
|
#define COLOR_CYAN "\x1b[0;36m"
|
||||||
#else
|
#else
|
||||||
#define COLOR_RESET ""
|
#define COLOR_RESET ""
|
||||||
#define COLOR_RED ""
|
#define COLOR_RED ""
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#define FOLLOW_LAST_SYMLINK 0x1
|
||||||
|
|
||||||
enum fs_filetype {
|
enum fs_filetype {
|
||||||
REGULAR,
|
REGULAR,
|
||||||
DIRECTORY
|
DIRECTORY,
|
||||||
|
SYMLINK
|
||||||
};
|
};
|
||||||
|
|
||||||
__attribute__((packed))
|
__attribute__((packed))
|
||||||
@@ -37,7 +40,7 @@ struct fs_inode_extension {
|
|||||||
|
|
||||||
__attribute__((packed))
|
__attribute__((packed))
|
||||||
struct fs_directory_record {
|
struct fs_directory_record {
|
||||||
unsigned char fname[FS_MAX_FNAME_LEN+1];
|
char fname[FS_MAX_FNAME_LEN+1];
|
||||||
unsigned int inode_no;
|
unsigned int inode_no;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -69,7 +72,9 @@ int fs_read(void *d);
|
|||||||
int fs_write(void *d);
|
int fs_write(void *d);
|
||||||
int fs_close(void *d);
|
int fs_close(void *d);
|
||||||
int fs_mkdir(void *d);
|
int fs_mkdir(void *d);
|
||||||
|
int fs_rmdir(void *d);
|
||||||
int fs_cd(void *d);
|
int fs_cd(void *d);
|
||||||
|
int fs_symlink(void *d);
|
||||||
int fs_truncate(void *d);
|
int fs_truncate(void *d);
|
||||||
int fs_allow_write(void *d);
|
int fs_allow_write(void *d);
|
||||||
int fs_prohibit_write(void *d);
|
int fs_prohibit_write(void *d);
|
||||||
|
|||||||
@@ -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[] = {
|
||||||
@@ -27,7 +28,9 @@ static const struct CliCommandEntry cmd[] = {
|
|||||||
{"close", 1, (enum CliArgType[]) {INT}, fs_close},
|
{"close", 1, (enum CliArgType[]) {INT}, fs_close},
|
||||||
|
|
||||||
{"mkdir", 1, (enum CliArgType[]) {STR}, fs_mkdir},
|
{"mkdir", 1, (enum CliArgType[]) {STR}, fs_mkdir},
|
||||||
|
{"rmdir", 1, (enum CliArgType[]) {STR}, fs_rmdir},
|
||||||
{"cd", 1, (enum CliArgType[]) {STR}, fs_cd},
|
{"cd", 1, (enum CliArgType[]) {STR}, fs_cd},
|
||||||
|
{"symlink", 2, (enum CliArgType[]) {STR, STR}, fs_symlink},
|
||||||
|
|
||||||
// custom commands
|
// custom commands
|
||||||
{"use", 1, (enum CliArgType[]) {STR}, fs_use},
|
{"use", 1, (enum CliArgType[]) {STR}, fs_use},
|
||||||
@@ -61,7 +64,7 @@ static int tokenized_line_len(char **t)
|
|||||||
static char **tokenize_line(char *line, ssize_t result)
|
static char **tokenize_line(char *line, ssize_t result)
|
||||||
{
|
{
|
||||||
if (result > CLI_MAX_LINE_LENGTH) {
|
if (result > CLI_MAX_LINE_LENGTH) {
|
||||||
pr_err("command too long (%d > %d)\n", result+1, CLI_MAX_LINE_LENGTH);
|
pr_err("command too long (%ld > %d)\n", result+1, CLI_MAX_LINE_LENGTH);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,6 +158,9 @@ void *format_args(char **tokenized_line, unsigned int arg_count, enum CliArgType
|
|||||||
case STR:
|
case STR:
|
||||||
struct_size += sizeof(char *);
|
struct_size += sizeof(char *);
|
||||||
break;
|
break;
|
||||||
|
case WRONG_TYPE:
|
||||||
|
pr_err("Wrong type occured in i=%d\n", i);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_struct = malloc(struct_size);
|
new_struct = malloc(struct_size);
|
||||||
@@ -203,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("$ ");
|
||||||
}
|
}
|
||||||
@@ -216,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);
|
||||||
|
|||||||
@@ -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