BMFS: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
BMFS |
Added link to documentation and how to open a directory. |
||
Line 44: | Line 44: | ||
You can also install it to /usr/local, to avoid having to do that. |
You can also install it to /usr/local, to avoid having to do that. |
||
=== |
=== Initializing the File System === |
||
Once the project is built, and your build system has the information to use the library, you can start writing code. |
Once the project is built, and your build system has the information to use the library, you can start writing code. |
||
Line 95: | Line 95: | ||
} |
} |
||
} |
} |
||
=== Opening a File === |
|||
With the disk and the file system initialized, you can open the file. |
With the disk and the file system initialized, you can open the file. |
||
int |
int show_file(const char *path) { |
||
/* Initialize disk here. */ |
/* Initialize disk here. */ |
||
Line 118: | Line 120: | ||
} |
} |
||
bmfs_file_set_mode(&file, |
bmfs_file_set_mode(&file, BMFS_MODE_READ); |
||
char buf[512]; |
|||
⚫ | |||
while (bmfs_file_eof(&file)) { |
|||
bmfs_uint64 read_count = 0; |
|||
err = bmfs_file_read(&file, buf, 512, &read_count); |
|||
if (err != 0) |
|||
break; |
|||
my_print_function(buf, read_count); |
|||
} |
|||
} |
} |
||
=== Opening a Directory === |
|||
Opening a directory is similar to opening a file. |
|||
You'll have to initialize the file system the same as you did for the file. |
|||
int list_dir(const char *path) { |
|||
⚫ | |||
struct BMFSDir dir; |
|||
bmfs_dir_init(&dir); |
|||
int err = bmfs_open_dir(&bmfs, &dir, path); |
|||
if (err == ENOTDIR) { |
|||
kprintf("Entry '%s' is not a directory.\n", path); |
|||
return -1; |
|||
} else if (err == ENOENT) { |
|||
kprintf("Directory '%s' does not exist.\n", path); |
|||
return -1; |
|||
} else if (err != 0) { |
|||
kprintf("Failed to open directory '%s'.\n", path); |
|||
return -1; |
|||
} |
|||
for (;;) { |
|||
const struct BMFSEntry *entry = bmfs_dir_next(&dir); |
|||
if (entry == BMFS_NULL) |
|||
break; |
|||
kprintf("Entry: %s\n", entry->Name); |
|||
} |
|||
} |
|||
=== Going Further === |
|||
The library can do even more than that and new features are added continuously. |
|||
Visit the Doxygen generated documentation [https://returninfinity.github.io/bmfs-doc/modules.html] for more information. |