- 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>
- Add the directory operations, e.g., open directory, make directory,
read directory, and close directory.
Signed-off-by: Cody Wong <codycswong@google.com>
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>
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.
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.
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.
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
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.
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.
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.
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.
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
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.