littlekernel / lk

LK embedded kernel
MIT License
3.11k stars 611 forks source link

Integrate the virtual 9P driver with the fs library to make it support fs operations #402

Closed mob5566 closed 2 months ago

mob5566 commented 2 months ago

With the following changes, the VirtIO 9p device can be exported as a LK filesystem and use the file APIs, e.g. fs_open_file, fs_read_file, fs_write_file, etc.

An example of using LK command ls to examine the shared filesystem is provided.

# 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
...

On the other hand, I add an example test v9fs_tests to validate the basic functions of the VirtIO 9p filesystem. The test does a similar check as app/tests/v9p_tests.c. It mount the littlekernel codebase onto /v9p and dump the first 1024 bytes of the LICENSE file.

starting internet servers
starting app shell
entering main console loop
] v9fs_tests
0x802d5060: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 |/*. * Copyright
0x802d5070: 28 63 29 20 32 30 30 38 2d 32 30 31 35 20 54 72 |(c) 2008-2015 Tr
0x802d5080: 61 76 69 73 20 47 65 69 73 65 6c 62 72 65 63 68 |avis Geiselbrech
0x802d5090: 74 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 73 69 |t. *. * Permissi
0x802d50a0: 6f 6e 20 69 73 20 68 65 72 65 62 79 20 67 72 61 |on is hereby gra
travisg commented 2 months ago

Very cool! Taking as is. Looks great!

travisg commented 2 months ago

Suggestion: move the test stuff into lib/fs/v9p to go along with it. I'm starting to move things out of that app into sub modules for various things and trying to generally switch standalone things to the unittest framework. I think FS tests are probably not usable as a unittest per se, since they require the system be set up a particular way, but as an example lib/fs/fat has a test sub module with all the stuff there.

travisg commented 2 months ago

Oh there's a WITH_TESTS build variable and #define that you can switch including the submodule on.

mob5566 commented 2 months ago

Hi @travisg,

That sounds great! I should have moved the testing code along with the modules, right? The folder app/tests will contain unittests only. Do I understand correctly?