Commit Graph

103 Commits

Author SHA1 Message Date
Travis Geiselbrecht
2377c3d440 [make] fix three misuses of TOBOOL
Forgot to expand the variable in the call to the TOBOOL function which
would cause the result to always be true. In this case always resulted
in the test code for these three modules to be included.
2025-09-03 15:14:18 -07:00
Travis Geiselbrecht
ac5cd774a6 [lib][fs][9p] fail mount gracefully if bdev isn't passed 2024-04-25 00:25:30 -07:00
Cody Wong
7ed757b144 [fs][v9fs] Add file operations for v9fs
- Add the file operations APIs for VirtIO 9p devices, such as file
   create/open/close/read/write/stat.
 - After this commit, almost complete file operations for v9p file
   sharing are supported. An intuitive example is that users can use
   filesystem commands, such as `ls`, to examine the shared folder.

   Example:

   ```
   # Build the littlekernel with the current directory (the codebase) as
   the shared v9p folder
   $ scripts/do-qemuarm -f .
   ...
   welcome to lk/MP

   boot args 0x0 0x0 0x0 0x0
   INIT: cpu 0, calling hook 0x8011fa81 (version) at level 0x3ffff,
   flags 0x1
   ...
   # Mount the default VirtIO 9p device `v9p0` as the 9p filesystem onto
   # `/v9p` path
   ] fs mount /v9p 9p v9p0
   # List the `/v9p` folder, and we can see the littlekernel codebase
   ] ls /v9p
   D 4096             arch
   F 590              lk_inc.mk.example
   D 4096             .cache
   D 4096             project
   D 4096             .github
   D 4096             platform
   D 4096             kernel
   D 4096             external
   F 1132             LICENSE
   D 4096             target
   D 4096             dev
   D 4096             .git
   F 120              .gitignore
   F 12579            engine.mk
   F 1388             README.md
   D 4096             make
   D 4096             top
   error -2 opening file '/v9p/..'
   D 4096             build-qemu-virt-arm32-test
   F 763965           compile_commands.json
   D 4096             scripts
   D 4096             lib
   D 4096             app
   D 4096             docs
   D 4096             .
   D 4096             tools
   F 1113             makefile
   ```

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Cody Wong
05b39a87cf [fs][v9fs] Add directory operations for v9fs
- Add the directory operations, e.g., open directory, make directory,
   read directory, and close directory.

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Cody Wong
b29df9194b [fs][v9fs] Add VirtIO 9p filesystem structure
Add the fundamental filesystem structure to attach a VirtualIO 9p
device. With the implementation of VirtIO 9p devices (lk/dev/virtio/9p),
we can use those APIs to connect to a shared folder as a LK filesystem.

Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Cody Wong
947cf27830 [fs][shell] Correct the path name for better understanding
Signed-off-by: Cody Wong <codycswong@google.com>
2024-04-25 00:17:02 -07:00
Travis Geiselbrecht
9e9e7d3fe4 [lib][fs] move the existing test code into its own sub module lib/fs/test
No real functional change, just following the pattern of moving unittest
code into a sub module that is picked up by the build system when
WITH_TESTS is set.
2024-04-23 23:49:19 -07:00
Chieh-Min Wang
b651168fa1 [lib][stdio] wrap file io APIs with stdio APIs
Implement stdio file io APIs with LK lib/fs APIs

Signed-off-by: Chieh-Min Wang <cmwang@google.com>
2024-04-17 23:59:49 -07:00
Travis Geiselbrecht
4a7c0ae925 [fs][fat] fix an incorrect assert 2022-05-13 01:03:15 -07:00
Travis Geiselbrecht
d525a5f7b5 [fs][fat][test] pass in the path to the test dir so files can be included correctly
Due to the way INCBIN works, the full path relative to the root of the
assembler instance must be used, so pass in the full path as a define.
2022-05-12 22:26:22 -07:00
Travis Geiselbrecht
def9bea065 [fs][fat] general fs structural improvements
Move more of the driver into a proper object oriented model.
Start to build the structure to track open file/dirs so as to
allow multiple open instances share the same underlying object.
2022-05-12 20:26:52 -07:00
Travis Geiselbrecht
89f8e62587 [fs][fat][test] add some more test code
Also create a large zero filled file and add it to the test fs, to try
to make sure there's at least one file that crosses a FAT sector.
2022-04-29 22:12:30 -07:00
Travis Geiselbrecht
144f608bce [fs][fat] add support for FAT12
The 12 bit fat parsing code is a little tricky.
2022-04-29 22:10:11 -07:00
Travis Geiselbrecht
1c9caf9f64 [fs][fat][test] start of unittests for fat file system
Requires a block device be present with a pre-formatted fs, but
should fail gracefully if its not present.
2022-04-25 23:17:55 -07:00
Travis Geiselbrecht
f6f43edc3c [fs][tests] break some fs tests into their own module
Include the test modules if the overal virtual/test module is included.
Also set a new global build system var along with a configuration
variable.
2022-04-25 23:17:55 -07:00
Travis Geiselbrecht
cb5ccee400 [fs][fat] fix a bug in close_dir that forgot to delete dir nodes 2022-04-25 23:17:55 -07:00
Travis Geiselbrecht
c08d540fd6 [lib][fs] add a trace printf when unmounting 2022-04-25 23:17:45 -07:00
Travis Geiselbrecht
5cbe21919b [fs][fat] add header guard to new iterator code header 2022-04-25 00:38:29 -07:00
Travis Geiselbrecht
e615a80993 [fs][fat] reuse directory iterator logic for files
Use the new helper class to also help reading from files efficiently.
2022-04-25 00:28:09 -07:00
Travis Geiselbrecht
b6b82852a2 [fs][fat][test] add a script to create some test block devices
Create a few file systems for fat 12, 16, and 32.
2022-04-23 00:39:33 -07:00
Travis Geiselbrecht
cad9af3420 [fs][fat] add readdir support 2022-04-23 00:27:31 -07:00
Travis Geiselbrecht
011cc61478 [fs][fat] break the dir entry code into a helper routine
Now extract the code to step one entry into a directory into a separate
routine so it can be reused for search and readdir code.
2022-04-22 23:43:30 -07:00
Travis Geiselbrecht
375f5fbfe3 [fs][fat] revamp the directory walk code
Use a new directory iterator routine that tracks the offset within the
directory and handles transitions between sectors and clusters.
Redo the entry parsing code to make a single pass across the long file
names to handle crossing sector boundaries.
2022-04-22 23:03:14 -07:00
Travis Geiselbrecht
9c1c0c6e3f [fs][fat] add a single mutex around the whole FS 2022-04-22 20:27:23 -07:00
Travis Geiselbrecht
ada94e94c7 [fs][fat] get the scaffolding in place for opendir/readdir/closedir
Currently returns a dir handle that reads nothing.
2022-04-22 20:27:23 -07:00
Travis Geiselbrecht
1191f3a601 [lib][fat] restructure directory code
Move the directory handling code to dir.cpp
Handle walking the entire directory structure
Make file open be a much simpler function that just calls dir routines

TODO:
properly deal with FAT16 and FAT12 root directories
remove runtime mallocs in dir routines
2022-04-22 00:46:44 -07:00
Travis Geiselbrecht
b300a95ab4 [fs][fat] split the logic into more files, change fat detection logic
Generally split the driver into more files for future expansion.
Follow the FAT spec more closely to determine FAT type.
2022-04-21 23:06:18 -07:00
Travis Geiselbrecht
3229494b3b [fs][fat] rename from fat32 to simply fat
It also handles fat16 and (soon) fat12.
2022-04-21 21:37:34 -07:00
Travis Geiselbrecht
fe2a370171 [fs][fat] general C++ificatition of the code and a bit of cleanup 2022-04-21 21:31:01 -07:00
Travis Geiselbrecht
d829ad24ef [fs][fat] fix up the mount and read logic in fat32
Now seems to be capable of mounting a simple fat32 volume and
successfully reading a single file in the root directory that spans a
few 512 byte clusters.
2022-04-19 00:02:23 -07:00
Travis Geiselbrecht
d4969ccb3c [fs][fat32] trivially convert to C++ 2022-04-18 22:24:27 -07:00
Travis Geiselbrecht
fdb027fe7b [lib][bcache] add C++ header guards 2022-04-18 22:24:02 -07:00
Travis Geiselbrecht
c7bef34590 [lib][fs] fix path parsing bug
If two mount points had similar names but one was longer, the path
matching logic would be triggered on the shorter name.

ie, /foo and /foo2 were illegal, since /foo2 path matching would match
against /foo. Tighten the logic a bit to match against the matching
element of the passed in path.

Note: heirarchial path matching still works, so /foo/bar/baz will match
against a mount point at /foo/bar. Debatable if heirarchial mount points
should work at the moment with this simple logic, but it's there for
now.
2022-04-18 21:32:57 -07:00
Travis Geiselbrecht
b88d9e5df5 [lib][fs] add path normalization tests, add few shell commands
Move the test normalization routine into a separate test file.
Add shell commands to list registered file systems and mount points.
2022-04-18 21:04:51 -07:00
Travis Geiselbrecht
fcb65c9a88 [dev/lib][warnings] fix -Wmissing-declarations warnings in dev/ and lib/ 2021-10-21 23:16:20 -07:00
Travis Geiselbrecht
20af129a81 [lib][fs] error code for null from malloc 2021-09-18 14:39:59 -07:00
Travis Geiselbrecht
4edb93adde [lib][console] rename some console command types to be prefixed with console_
Some of the structures, notably 'cmd', in the lib console stuff are a
little too generically named and have collided with some other code
so prefix the names a bit more cleanly with console_

The change is largely mechanical, and folks with out of tree code can
easily switch by renaming:
cmd -> console_cmd
cmd_args -> console_cmd_args
cmd_block -> console_cmd_block
console_cmd -> console_cmd_func

Apologies if this breaks you but it should be pretty easy to fix.
2020-07-25 15:59:58 -07:00
Travis Geiselbrecht
f10d9baadb [lib][fs] switch the fs registration to __start __stop style registration
Use the linker's auto generation of a __start_* and __stop_* symbol to
define a run of global structures.
2020-05-14 23:53:46 -07:00
Travis Geiselbrecht
6cb02526b7 [include][console] split lib/console.h into two
TL;DR most uses of lib/console.h -> lk/console_cmd.h

Move the part that lets a piece of code somewhere in the system to
define a console command from the actual lib/console api to start an
instance of the console. Move in almost every place the user of the
console command definition to the new header, lk/console_cmd.h which is
always in the include path.

Also remove most uses of testing for WITH_LIB_CONSOLE since you can
almost always just safely define it and then let the linker remove it.
2019-07-13 16:56:33 -07:00
Travis Geiselbrecht
3aecdda231 [includes] replace header guards with #pragma once 2019-07-13 15:46:16 -07:00
Travis Geiselbrecht
cba9e47987 [license] replace the longer full MIT license with a shorter one
Used scripts/replacelic. Everything seems to build fine.
2019-07-05 17:22:23 -07:00
Travis Geiselbrecht
d8fa82cb91 [formatting] run everything through codestyle
Almost nothing changes here except moving braces to the same line as the
function declaration. Everything else is largely whitespace changes and
a few dangling files with tab indents.

See scripts/codestyle
2019-06-19 21:02:24 -07:00
Travis Geiselbrecht
1b7a28efb8 [include][lk] fixup lk/ include path move 2019-06-19 19:46:11 -07:00
Travis Geiselbrecht
75b312b30b [lib][fs][spifs] abort cleanly on mount if device is null 2019-06-10 17:10:42 -07:00
Travis Geiselbrecht
f98cef7992 [warnings] fix warnings across the entire code base
Fix or squelch all warnings in all code covered by buildall.
2018-12-16 17:33:22 -08:00
Travis Geiselbrecht
7bbf6d5831 [nit] fix extraneous trailing ; in CDECLS lines 2018-12-16 16:49:40 -08:00
Travis Geiselbrecht
5dea3e1933 [warnings] fix a few warnings introduced with newer version of gcc
Most of the warnings are new, such as needing to mark fallthroughs on
cases explicitly. A few are based on signed vs unsigned comparisons.

Disable one warning that was annoying about comparing null to arguments
marked nonnull.
2018-03-15 14:10:12 -07:00
klemens
d0b90c2d68 [spelling] spelling-fixes. (not external/) 2016-08-25 17:30:34 -07:00
Søren Gjesse
6faa2957e1 [spifs] Fix warning with GCC 5.3.1
With GCC 5.3.1 (5-2016-q2-update from https://launchpad.net/gcc-arm-embedded)
additional warnings about unused variables cause compilation to fail.
2016-05-31 12:19:57 -07:00
Gurjant Kalsi
c19fcc5bb3 [spifs] Implement the ioctl to test whether or not the device is memory mapped. 2016-05-10 18:23:11 -07:00