1 | // SPDX-License-Identifier: GPL-3.0-or-later |
---|---|
2 | |
3 | #include "blockdev.h" |
4 | #include "ext4fs.hpp" |
5 | #include "proto/blockdev.services.h" |
6 | #include "proto/userfs-manager.services.h" |
7 | |
8 | #include <iostream> |
9 | |
10 | #define DEBUG 1 |
11 | |
12 | std::unique_ptr<UserFSManagerStub> userfs_manager; |
13 | std::unique_ptr<BlockdevManagerStub> blockdev_manager; |
14 | |
15 | int main(int argc, char **) |
16 | { |
17 | std::cout << "EXT2/3/4 File System Driver for MOS"<< std::endl; |
18 | |
19 | if (argc > 1) |
20 | std::cerr << "Too many arguments"<< std::endl, exit(status: 1); |
21 | |
22 | blockdev_manager = std::make_unique<BlockdevManagerStub>(BLOCKDEV_MANAGER_RPC_SERVER_NAME); |
23 | userfs_manager = std::make_unique<UserFSManagerStub>(USERFS_SERVER_RPC_NAME); |
24 | |
25 | const auto server_name = "fs.ext4"s; |
26 | |
27 | #if DEBUG |
28 | ext4_dmask_set(DEBUG_ALL); |
29 | #endif |
30 | |
31 | mosrpc_userfs_register_request req{ |
32 | .fs = { .name = strdup(string: "ext4") }, |
33 | .rpc_server_name = strdup(string: server_name.c_str()), |
34 | }; |
35 | mosrpc_userfs_register_response resp; |
36 | const auto reg_result = userfs_manager->register_filesystem(request: &req, response: &resp); |
37 | if (reg_result != RPC_RESULT_OK || !resp.result.success) |
38 | { |
39 | std::cerr << "Failed to register filesystem"<< std::endl; |
40 | if (resp.result.error) |
41 | std::cerr << "Error: "<< resp.result.error << std::endl; |
42 | return 1; |
43 | } |
44 | |
45 | pb_release(fields: &mosrpc_userfs_register_request_msg, dest_struct: &req); |
46 | pb_release(fields: &mosrpc_userfs_register_response_msg, dest_struct: &resp); |
47 | |
48 | Ext4UserFS ext4_userfs(server_name); |
49 | ext4_userfs.run(); |
50 | return 0; |
51 | } |
52 |