add all warnings + pedantic
This commit is contained in:
parent
d68b874b24
commit
4e37240971
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
CFLAGS = -g3 -O0 -I. -Iinc
|
||||
CFLAGS = -g3 -O0 -Wall -Wpedantic -I. -Iinc
|
||||
|
||||
build: main
|
||||
|
||||
|
|
10
inc/color.h
10
inc/color.h
|
@ -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 ""
|
||||
|
|
2
inc/fs.h
2
inc/fs.h
|
@ -39,7 +39,7 @@ struct fs_inode_extension {
|
|||
|
||||
__attribute__((packed))
|
||||
struct fs_directory_record {
|
||||
unsigned char fname[FS_MAX_FNAME_LEN+1];
|
||||
char fname[FS_MAX_FNAME_LEN+1];
|
||||
unsigned int inode_no;
|
||||
};
|
||||
|
||||
|
|
|
@ -62,7 +62,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;
|
||||
}
|
||||
|
||||
|
@ -156,6 +156,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);
|
||||
|
|
67
src/fs.c
67
src/fs.c
|
@ -36,7 +36,7 @@ static int read_block(unsigned int block_no, void *data)
|
|||
}
|
||||
|
||||
if (block_no * FS_BLOCK_SIZE >= st.st_size) {
|
||||
pr_err("read beyond device address space denied (%d >= %d)\n",
|
||||
pr_err("read beyond device address space denied (%d >= %ld)\n",
|
||||
block_no * FS_BLOCK_SIZE, st.st_size);
|
||||
return -1;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ static int write_block(unsigned int block_no, void *data)
|
|||
}
|
||||
|
||||
if (block_no * FS_BLOCK_SIZE >= st.st_size) {
|
||||
pr_err("write beyond device address space denied (%d >= %d)\n",
|
||||
pr_err("write beyond device address space denied (%d >= %ld)\n",
|
||||
block_no * FS_BLOCK_SIZE, st.st_size);
|
||||
return -1;
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ static int fs_find_free_directory_record(unsigned int dir_inode_ptr)
|
|||
read_block(dir.blocks[i], (void *) &r);
|
||||
|
||||
for (int j = 0; j < DIRECTORY_RECORDS_PER_BLOCK; j++, found_block_no++) {
|
||||
if (r[j].fname)
|
||||
if (r[j].fname[0])
|
||||
continue;
|
||||
|
||||
if (found_block_no >= fsh.max_inode_count)
|
||||
|
@ -467,7 +467,6 @@ static int fs_find_free_directory_record(unsigned int dir_inode_ptr)
|
|||
struct fs_inode_extension ext;
|
||||
|
||||
unsigned int next_ext = dir.next_extension;
|
||||
unsigned int curr_ext = 0;
|
||||
|
||||
while (next_ext) {
|
||||
read_block(next_ext, (void *) &ext);
|
||||
|
@ -486,7 +485,7 @@ static int fs_find_free_directory_record(unsigned int dir_inode_ptr)
|
|||
read_block(ext.blocks[i], (void *) &r);
|
||||
|
||||
for (int j = 0; j < DIRECTORY_RECORDS_PER_BLOCK; j++, found_block_no++) {
|
||||
if (r[j].fname)
|
||||
if (r[j].fname[0])
|
||||
continue;
|
||||
|
||||
if (found_block_no >= fsh.max_inode_count)
|
||||
|
@ -518,7 +517,7 @@ static int *find_filename_in_directory(unsigned int dir_inode_ptr, char *fname)
|
|||
read_block(dir.blocks[i], (void *) &recs);
|
||||
|
||||
for (int k = 0; k < DIRECTORY_RECORDS_PER_BLOCK; k++) {
|
||||
if (!recs[k].fname)
|
||||
if (!recs[k].fname[0])
|
||||
continue;
|
||||
|
||||
if (strcmp(fname, recs[k].fname))
|
||||
|
@ -549,7 +548,7 @@ static int *find_filename_in_directory(unsigned int dir_inode_ptr, char *fname)
|
|||
read_block(ext.blocks[i], (void *) &recs);
|
||||
|
||||
for (int k = 0; k < DIRECTORY_RECORDS_PER_BLOCK; k++) {
|
||||
if (!recs[k].fname)
|
||||
if (!recs[k].fname[0])
|
||||
continue;
|
||||
|
||||
if (strcmp(fname, recs[k].fname))
|
||||
|
@ -666,7 +665,7 @@ static int fs_add_fname_to_directory(unsigned int dir_inode_ptr, unsigned int ta
|
|||
new_block, dir_inode_ptr, read_inode_ptr(dir_inode_ptr), block_no);
|
||||
}
|
||||
|
||||
char zero_data[FS_BLOCK_SIZE] = {};
|
||||
char zero_data[FS_BLOCK_SIZE] = {0};
|
||||
memset(zero_data, 0, FS_BLOCK_SIZE);
|
||||
write_block(new_block, &zero_data);
|
||||
|
||||
|
@ -837,7 +836,7 @@ static int fs_remove_fname_from_directory(unsigned int dir_inode_ptr, char *fnam
|
|||
read_block(dir.blocks[i], &recs);
|
||||
|
||||
for (int k = 0; k < DIRECTORY_RECORDS_PER_BLOCK; k++) {
|
||||
if (!recs[k].fname)
|
||||
if (!recs[k].fname[0])
|
||||
continue;
|
||||
|
||||
if (strcmp(fname, recs[k].fname))
|
||||
|
@ -874,7 +873,7 @@ static int fs_remove_fname_from_directory(unsigned int dir_inode_ptr, char *fnam
|
|||
read_block(ext.blocks[i], (void *) &recs);
|
||||
|
||||
for (int k = 0; k < DIRECTORY_RECORDS_PER_BLOCK; k++) {
|
||||
if (!recs[k].fname)
|
||||
if (!recs[k].fname[0])
|
||||
continue;
|
||||
|
||||
if (strcmp(fname, recs[k].fname))
|
||||
|
@ -918,7 +917,7 @@ static void resolve_path(struct resolved_path *rp, char *path, unsigned int para
|
|||
return;
|
||||
}
|
||||
|
||||
char current_fname[FS_MAX_FNAME_LEN+1] = {};
|
||||
char current_fname[FS_MAX_FNAME_LEN+1] = {0};
|
||||
int current_inode_ptr;
|
||||
int i;
|
||||
|
||||
|
@ -934,7 +933,7 @@ static void resolve_path(struct resolved_path *rp, char *path, unsigned int para
|
|||
i = 0;
|
||||
}
|
||||
|
||||
char next_fname[FS_MAX_FNAME_LEN+1] = {};
|
||||
char next_fname[FS_MAX_FNAME_LEN+1] = {0};
|
||||
int next_fname_ptr = 0;
|
||||
|
||||
for ( ; i < path_len; i++) {
|
||||
|
@ -1127,7 +1126,7 @@ static int write_fd_block(unsigned int fd, unsigned int block_index, unsigned ch
|
|||
write_block(fs_file_descriptions[fd].inode, (void *) &f);
|
||||
}
|
||||
|
||||
write_block(f.blocks[block_index], (void *) buf);
|
||||
return write_block(f.blocks[block_index], (void *) buf);
|
||||
} else {
|
||||
int ext_no = (block_index - BLOCK_ADDRESSES_PER_INODE) / BLOCK_ADDRESSES_PER_INODE_EXTENSION;
|
||||
int ext_offset = (block_index - BLOCK_ADDRESSES_PER_INODE) % BLOCK_ADDRESSES_PER_INODE_EXTENSION;
|
||||
|
@ -1194,7 +1193,7 @@ static int write_fd_block(unsigned int fd, unsigned int block_index, unsigned ch
|
|||
write_block(curr_ext, (void *) &ext);
|
||||
}
|
||||
|
||||
write_block(ext.blocks[ext_offset], (void *) buf);
|
||||
return write_block(ext.blocks[ext_offset], (void *) buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1462,6 +1461,8 @@ int fs_close(void *d)
|
|||
pr("No open fd reference inode %d, cleaning up\n", inode_location_cache);
|
||||
|
||||
clean_inode(inode_location_cache);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1507,7 +1508,7 @@ int fs_create(void *d)
|
|||
}
|
||||
|
||||
// write new file inode
|
||||
struct fs_inode newf = {};
|
||||
struct fs_inode newf = {0};
|
||||
newf.ftype = REGULAR;
|
||||
newf.ref_count = 1;
|
||||
newf.size = 0;
|
||||
|
@ -1647,6 +1648,8 @@ original_inode_ptr_found:
|
|||
write_block(read_inode_ptr(original_inode_ptr), (void *) &f);
|
||||
|
||||
pr("Updated inode ref_count (%d -> %d)\n", f.ref_count-1, f.ref_count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1679,22 +1682,6 @@ static int extract_basename(char *path, char *name)
|
|||
return fname_len;
|
||||
}
|
||||
|
||||
static void extract_parent_directory_path(char *path, char *parent_path)
|
||||
{
|
||||
int path_len = strlen(path);
|
||||
int lsp = last_significant_slash_position(path, path_len);
|
||||
int parent_len = last_significant_slash_position(path, lsp-1);
|
||||
|
||||
if (parent_len > 1) {
|
||||
memcpy(parent_path, path, parent_len-1);
|
||||
parent_path[parent_len] = '\0';
|
||||
} else {
|
||||
strcpy(parent_path, "/");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
int fs_mkdir(void *d)
|
||||
{
|
||||
char *dirpath = *((char **)d);
|
||||
|
@ -1766,6 +1753,8 @@ int fs_mkdir(void *d)
|
|||
// add . and ..
|
||||
fs_add_fname_to_directory(target_inode_ptr, target_inode_ptr, ".");
|
||||
fs_add_fname_to_directory(target_inode_ptr, rp.parent_inode_ptr, "..");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1797,13 +1786,11 @@ static int count_active_directory_records(struct fs_inode *inode)
|
|||
|
||||
// inode extensions
|
||||
unsigned int next_ext = inode->next_extension;
|
||||
unsigned int curr_ext = 0;
|
||||
|
||||
struct fs_inode_extension ext;
|
||||
|
||||
while (next_ext) {
|
||||
read_block(next_ext, &ext);
|
||||
curr_ext = next_ext;
|
||||
next_ext = ext.next_extension;
|
||||
|
||||
for (int i = 0; i < BLOCK_ADDRESSES_PER_INODE_EXTENSION; i++) {
|
||||
|
@ -1892,7 +1879,7 @@ static int get_fname_by_inode_ptr(int dir_inode_ptr, int file_inode_ptr, char *n
|
|||
read_block(dir.blocks[i], &recs);
|
||||
|
||||
for (int j = 0; j < DIRECTORY_RECORDS_PER_BLOCK; j++) {
|
||||
if (!recs[j].fname)
|
||||
if (!recs[j].fname[0])
|
||||
continue;
|
||||
|
||||
if (recs[j].inode_no != file_inode_ptr)
|
||||
|
@ -1905,13 +1892,11 @@ static int get_fname_by_inode_ptr(int dir_inode_ptr, int file_inode_ptr, char *n
|
|||
|
||||
// search inode extensions
|
||||
unsigned int next_ext = dir.next_extension;
|
||||
unsigned int curr_ext = 0;
|
||||
|
||||
struct fs_inode_extension ext;
|
||||
|
||||
while (next_ext) {
|
||||
read_block(next_ext, &ext);
|
||||
curr_ext = next_ext;
|
||||
next_ext = ext.next_extension;
|
||||
|
||||
for (int i = 0; i < BLOCK_ADDRESSES_PER_INODE_EXTENSION; i++) {
|
||||
|
@ -1923,7 +1908,7 @@ static int get_fname_by_inode_ptr(int dir_inode_ptr, int file_inode_ptr, char *n
|
|||
read_block(ext.blocks[i], &recs);
|
||||
|
||||
for (int j = 0; j < DIRECTORY_RECORDS_PER_BLOCK; j++) {
|
||||
if (!recs[j].fname)
|
||||
if (!recs[j].fname[0])
|
||||
continue;
|
||||
|
||||
if (recs[j].inode_no != file_inode_ptr)
|
||||
|
@ -2307,14 +2292,14 @@ int fs_mkfs(void *d)
|
|||
return 0;
|
||||
}
|
||||
|
||||
pr("Formatting storage device '%s' of size %d (total_block_count = %d, bitmap_blocks = %d) with %d allowed inode pointers\n", used_file_path, st.st_size, block_count, blocks_used_for_bitmap, max_inode_count);
|
||||
pr("Formatting storage device '%s' of size %ld (total_block_count = %d, bitmap_blocks = %d) with %d allowed inode pointers\n", used_file_path, st.st_size, block_count, blocks_used_for_bitmap, max_inode_count);
|
||||
|
||||
struct fs_header fsh = {};
|
||||
struct fs_header fsh = {0};
|
||||
fsh.version = 0x1;
|
||||
fsh.max_inode_count = max_inode_count;
|
||||
fsh.block_count = block_count;
|
||||
|
||||
pr("header size is %d bytes, writing it to the first block\n", sizeof(fsh));
|
||||
pr("header size is %ld bytes, writing it to the first block\n", sizeof(fsh));
|
||||
|
||||
int result = write_block(0, (void *) &fsh);
|
||||
if (FS_BLOCK_SIZE != result) {
|
||||
|
@ -2364,7 +2349,7 @@ finish_current_block:
|
|||
|
||||
// create root directory automatically
|
||||
|
||||
struct fs_inode root_dir = {};
|
||||
struct fs_inode root_dir = {0};
|
||||
root_dir.ftype = DIRECTORY;
|
||||
root_dir.ref_count = 1;
|
||||
|
||||
|
|
Loading…
Reference in New Issue