26 Commits

Author SHA1 Message Date
hasslesstech 6e0c37abee improve testing script 2025-05-18 15:00:45 +03:00
hasslesstech d5c8b24c64 add testing script 2025-05-18 13:39:32 +03:00
hasslesstech ae0a2c0430 improve CLI handling of non-tty sources 2025-05-18 13:22:34 +03:00
hasslesstech b6bc6da235 handle symlinks in ls, la and stat, improve resolve_path logging 2025-05-18 13:21:19 +03:00
hasslesstech 049405989b add symlink follow counter 2025-05-17 22:40:02 +03:00
hasslesstech 1dbdbd20d3 fix symlink handling in resolve_path 2025-05-17 22:27:11 +03:00
hasslesstech db6187be39 wip: add support or reading symlinks in resolve_path 2025-05-17 20:51:09 +03:00
hasslesstech 552e574cde add symlink command 2025-05-17 18:52:52 +03:00
hasslesstech 72a02047d5 fix opening directories and saving inode_ptr instead of inode in fd 2025-05-17 17:14:06 +03:00
hasslesstech 585492b6d7 update fs_stat, fs_open, fs_ln and fs_truncate to operate on paths 2025-05-17 16:49:39 +03:00
hasslesstech 4e37240971 add all warnings + pedantic 2025-05-17 13:53:32 +03:00
hasslesstech d68b874b24 generalize resolve_directory into resolve_path, fix mkdir, cd, update rm, create, add rmdir 2025-05-17 12:59:07 +03:00
hasslesstech 117e8706a8 fix deleted directory record listing 2025-05-16 15:57:09 +03:00
hasslesstech 941c51200c fix fs_mkdir and fs_cd 2025-05-16 14:32:44 +03:00
hasslesstech ff684fad45 wip: add mkdir, cd, simplify find_filename_in_directory usage, fix old issues 2025-05-16 12:22:31 +03:00
hasslesstech a90f09ff6e fix fs_truncate bugs 2025-05-01 22:40:24 +03:00
hasslesstech 0a14404160 update config.h to simplify testing and comply with previous changes 2025-05-01 22:05:32 +03:00
hasslesstech c296e6e93d add full extension support, fix bugs 2025-05-01 22:03:32 +03:00
hasslesstech 0315963125 fix mark_free logging 2025-05-01 00:29:11 +03:00
hasslesstech e39815a2e7 fix write_fd_block 2025-04-30 22:46:35 +03:00
hasslesstech ba8f8031f0 [wip] fixing fs_write 2025-04-30 22:33:23 +03:00
hasslesstech 60a2815f3a [wip] fix bugs, add more extension support, allow file name length to be configured 2025-04-30 21:39:27 +03:00
hasslesstech dc611bb787 add stat 2025-04-26 22:33:28 +03:00
hasslesstech 3ee64e5b5d add truncate 2025-04-26 22:12:26 +03:00
hasslesstech 3b3ce23df0 add seek, read, write 2025-04-26 19:46:34 +03:00
hasslesstech 87f3239c52 [wip] add read and write 2025-04-26 19:03:39 +03:00
8 changed files with 2046 additions and 306 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
CFLAGS = -g3 -O0 -I. -Iinc
CFLAGS = -g3 -O0 -Wall -Wpedantic -I. -Iinc
build: main
+6 -3
View File
@@ -14,17 +14,20 @@
/* CLI config section */
#define CLI_MAX_LINE_LENGTH 256
#define CLI_MAX_LINE_LENGTH 1024
#define CLI_MAX_ACCEPTED_ARGS 4
#define CLI_MAX_TOKEN_LENGTH 64
#define CLI_MAX_TOKEN_LENGTH 256
/* FS config section */
#define FS_MAX_DEVICE_FILE_NAME_LEN 512
#define FS_BLOCK_SIZE 4096
#define FS_BLOCK_SIZE 16
#define FS_MAX_BITMAP_SIZE 64
#define FS_MAX_PATH_LEN 512
#define FS_MAX_OPEN_FD 32
#define FS_MAX_FNAME_LEN 11
#define FS_MAX_DIRECTORY_DEPTH 2048
#define FS_MAX_SYMLINK_FOLLOWS 1024
#endif
+5 -5
View File
@@ -5,11 +5,11 @@
#include "config.h"
#if COLOR_ENABLE == 1
#define COLOR_RESET "\e[0m"
#define COLOR_RED "\e[0;31m"
#define COLOR_YELLOW "\e[0;33m"
#define COLOR_BLUE "\e[0;34m"
#define COLOR_CYAN "\e[0;36m"
#define COLOR_RESET "\x1b[0m"
#define COLOR_RED "\x1b[0;31m"
#define COLOR_YELLOW "\x1b[0;33m"
#define COLOR_BLUE "\x1b[0;34m"
#define COLOR_CYAN "\x1b[0;36m"
#else
#define COLOR_RESET ""
#define COLOR_RED ""
+21 -2
View File
@@ -1,8 +1,11 @@
#include "config.h"
#define FOLLOW_LAST_SYMLINK 0x1
enum fs_filetype {
REGULAR,
DIRECTORY
DIRECTORY,
SYMLINK
};
__attribute__((packed))
@@ -37,7 +40,7 @@ struct fs_inode_extension {
__attribute__((packed))
struct fs_directory_record {
unsigned char fname[60];
char fname[FS_MAX_FNAME_LEN+1];
unsigned int inode_no;
};
@@ -46,6 +49,13 @@ struct fs_file_description {
unsigned int rw_offset;
};
struct resolved_path {
int target_inode_ptr;
int parent_inode_ptr;
char target_fname[FS_MAX_FNAME_LEN+1];
char parent_fname[FS_MAX_FNAME_LEN+1];
};
char *fs_get_cwd(void);
int fs_create(void *d);
@@ -54,8 +64,17 @@ 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);
int fs_read(void *d);
int fs_write(void *d);
int fs_close(void *d);
int fs_mkdir(void *d);
int fs_rmdir(void *d);
int fs_cd(void *d);
int fs_symlink(void *d);
int fs_truncate(void *d);
int fs_allow_write(void *d);
int fs_prohibit_write(void *d);
+35 -41
View File
@@ -3,70 +3,64 @@
#include <stdio.h>
#include <unistd.h>
#include "config.h"
#include "color.h"
#if DEBUG == 1
#define pr(...) { printf("[%s:%d] ", __FILE__, __LINE__); printf(__VA_ARGS__); }
#define pr(...) do { printf("[%s:%d] ", __FILE__, __LINE__); printf(__VA_ARGS__); } while (0)
#else
#define pr(...) {}
#define pr(...)
#endif
#if ENABLE_STDOUT == 1
#define pr_stdout(...) { printf(__VA_ARGS__); }
#define pr_stdout(...) do { printf(__VA_ARGS__); } while (0)
#define write_stdout(data, size) do { write(1, (data), (size)); } while (0)
#else
#define pr_stdout(...) {}
#define pr_stdout(...)
#define write_stdout(data, size)
#endif
#if LOG_LEVEL >= 0
#if ENABLE_FILE_LINE_IN_OTHER_PR == 1
#define pr_generic(color, prefix, ...) do { \
printf(color "[%s:%d] " prefix, __FILE__, __LINE__); \
printf(__VA_ARGS__); \
printf(COLOR_RESET); \
} while (0)
#else
#define pr_generic(color, prefix, ...) do { \
printf(color prefix); \
printf(__VA_ARGS__); \
printf(COLOR_RESET); \
} while (0)
#endif
#else
#define pr_generic(color, prefix, ...)
#endif
#if LOG_LEVEL >= 2
#if ENABLE_FILE_LINE_IN_OTHER_PR == 1
#define pr_err(...) { \
printf(COLOR_RED "[%s:%d] Error: ", __FILE__, __LINE__); \
printf(__VA_ARGS__); \
printf(COLOR_RESET); \
}
#else
#define pr_err(...) { \
printf(COLOR_RED "Error: "); \
printf(__VA_ARGS__); \
printf(COLOR_RESET);\
}
#endif
#define pr_err(...) pr_generic(COLOR_RED, "Error: ", __VA_ARGS__)
#else
#define pr_err(...) {}
#define pr_err(...)
#endif
#if LOG_LEVEL >= 3
#if ENABLE_FILE_LINE_IN_OTHER_PR == 1
#define pr_warn(...) { \
printf(COLOR_YELLOW "[%s:%d] Warning: ", __FILE__, __LINE__); \
printf(__VA_ARGS__); \
printf(COLOR_RESET); \
}
#else
#define pr_warn(...) { \
printf(COLOR_YELLOW "Warning: "); \
printf(__VA_ARGS__); \
printf(COLOR_RESET); \
}
#endif
#define pr_warn(...) pr_generic(COLOR_YELLOW, "Warning: ", __VA_ARGS__)
#else
#define pr_warn(...) {}
#define pr_warn(...)
#endif
#if LOG_LEVEL >= 4
#if ENABLE_FILE_LINE_IN_OTHER_PR == 1
#define pr_info(...) { \
printf("[%s:%d] Info: ", __FILE__, __LINE__); \
printf(__VA_ARGS__); \
}
#else
#define pr_info(...) { printf("Info: "); printf(__VA_ARGS__); }
#endif
#define pr_info(...) pr_generic(COLOR_RESET, "Info: ", __VA_ARGS__)
#else
#define pr_info(...) {}
#define pr_info(...)
#endif
+27 -13
View File
@@ -9,23 +9,29 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
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},
//{"truncate", 2, (enum CliArgType[]) {STR, INT}, fs_truncate},
{"truncate", 2, (enum CliArgType[]) {STR, INT}, fs_truncate},
{"open", 1, (enum CliArgType[]) {STR}, fs_open},
//{"seek", 2, (enum CliArgType[]) {INT, INT}, fs_seek},
//{"read", 2, (enum CliArgType[]) {INT, INT}, fs_read},
//{"write", 2, (enum CliArgType[]) {INT, STR}, fs_write},
{"seek", 2, (enum CliArgType[]) {INT, INT}, fs_seek},
{"read", 2, (enum CliArgType[]) {INT, INT}, fs_read},
{"write", 2, (enum CliArgType[]) {INT, STR}, fs_write},
{"close", 1, (enum CliArgType[]) {INT}, fs_close},
{"mkdir", 1, (enum CliArgType[]) {STR}, fs_mkdir},
{"rmdir", 1, (enum CliArgType[]) {STR}, fs_rmdir},
{"cd", 1, (enum CliArgType[]) {STR}, fs_cd},
{"symlink", 2, (enum CliArgType[]) {STR, STR}, fs_symlink},
// custom commands
{"use", 1, (enum CliArgType[]) {STR}, fs_use},
{"la", 0, NULL, fs_la},
@@ -58,7 +64,7 @@ static int tokenized_line_len(char **t)
static char **tokenize_line(char *line, ssize_t result)
{
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;
}
@@ -68,8 +74,8 @@ static char **tokenize_line(char *line, ssize_t result)
unsigned int i, t, l;
for (
i = 0, t = 0, l = 0;
i < CLI_MAX_LINE_LENGTH,
t <= CLI_MAX_ACCEPTED_ARGS,
i < CLI_MAX_LINE_LENGTH &&
t <= CLI_MAX_ACCEPTED_ARGS &&
l < CLI_MAX_TOKEN_LENGTH;
i++
) {
@@ -152,6 +158,9 @@ void *format_args(char **tokenized_line, unsigned int arg_count, enum CliArgType
case STR:
struct_size += sizeof(char *);
break;
case WRONG_TYPE:
pr_err("Wrong type occured in i=%d\n", i);
break;
}
new_struct = malloc(struct_size);
@@ -200,21 +209,26 @@ abandon_struct:
unsigned int cli_poll_process_next(void)
{
for ( ;; ) {
fputs(fs_get_cwd(), stdout);
int echo_commands = !isatty(STDIN_FILENO);
for ( ;; ) {
if (fs_get_cwd()[0]) {
fputs(" $ ", stdout);
printf("%s $ ", fs_get_cwd());
} else {
fputs("$ ", stdout);
printf("$ ");
}
size_t buf_size = 0;
char *line = NULL;
ssize_t result = getline(&line, &buf_size, stdin);
if (result == -1)
if (result == -1) {
printf("\n");
return 0x1;
}
if (echo_commands)
printf(line);
char **tokenized_line = tokenize_line(line, result);
free(line);
+1896 -241
View File
File diff suppressed because it is too large Load Diff
+55
View 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