-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#ifndef _ALLOC_H_ | ||
#define _ALLOC_H_ | ||
|
||
|
||
#include <stdlib.h> | ||
#include <inttypes.h> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <stdio.h> | ||
#include "commands.h" | ||
|
||
|
||
static void _tree_rec(fs_file *file, uint8_t deep) | ||
{ | ||
for(uint8_t i = 0; i < deep ; ++i) | ||
for(uint8_t j = 0; j < 4; j++) | ||
putchar(' '); | ||
puts(fs_get_name(file)); | ||
|
||
if (fs_is_directory(file)) { | ||
fs_iterator iterator = fs_get_first_child(file); | ||
while (iterator != NULL) { | ||
_tree_rec(fs_get_file_by_iter(iterator), deep+1); | ||
iterator = fs_get_next_child(iterator); | ||
} | ||
} | ||
} | ||
|
||
uint8_t tree(fs_file *file) | ||
{ | ||
if (file == NULL) | ||
return CMD_ERROR; | ||
|
||
_tree_rec(file, 0); | ||
return CMD_SUCCESS; | ||
} | ||
|
||
|
||
uint8_t ls(fs_file *file) | ||
{ | ||
if (file == NULL) | ||
return CMD_ERROR; | ||
|
||
if (fs_is_directory(file)) { | ||
fs_iterator iterator = fs_get_first_child(file); | ||
while (iterator != NULL) { | ||
puts(fs_get_name(fs_get_file_by_iter(iterator))); | ||
iterator = fs_get_next_child(iterator); | ||
} | ||
} else { | ||
puts(fs_get_name(file)); | ||
} | ||
|
||
return CMD_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef _COMMANDS_H_ | ||
#define _COMMANDS_H_ | ||
|
||
|
||
#include "filesystem.h" | ||
|
||
#define CMD_SUCCESS 1 | ||
#define CMD_ERROR 0 | ||
|
||
uint8_t tree(fs_file *file); | ||
|
||
uint8_t ls(fs_file *file); | ||
|
||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifdef TEST_COMMANDS | ||
|
||
#include "tests.h" | ||
|
||
#include "commands.h" | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
mem_allocator allocator; | ||
uint8_t *memory = malloc(MEM_SIZE); | ||
mem_init(&allocator, memory, MEM_SIZE); | ||
|
||
fs_file root; | ||
if(fs_new_root(&allocator, &root) == FS_ERROR) | ||
puts("Error pour fs_init_directory"); | ||
if (fs_add_regular(&allocator, &root, "monFichierapappapapapapapapapapapapaas", NULL) == FS_ERROR) | ||
puts("Error pour fs_add_file"); | ||
fs_file *home, *user; | ||
fs_add_dir(&allocator, &root, "home", &home); | ||
fs_add_dir(&allocator, home, "user", &user); | ||
fs_add_regular(&allocator, user, "file1", NULL); | ||
fs_add_regular(&allocator, user, "file2", NULL); | ||
|
||
puts("* Test LS"); | ||
ls(&root); | ||
puts("* End"); | ||
|
||
puts("* Test TREE"); | ||
tree(&root); | ||
puts("* End"); | ||
|
||
|
||
if (fs_delete_root(&allocator, &root) == FS_ERROR) | ||
puts("Error pour fs_delete_root"); | ||
|
||
// clean test | ||
free(memory); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ int main(int argc, char const *argv[]) | |
|
||
mem_debug(&allocator); | ||
|
||
// clean test | ||
free(memory); | ||
|
||
return 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef TESTS_H | ||
#define TESTS_H | ||
|
||
|
||
#define MEM_SIZE 1024 | ||
|
||
#endif |