| // Copyright 2021 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include <lib/async-loop/cpp/loop.h> |
| #include <lib/async-loop/default.h> |
| #include <lib/sys/cpp/component_context.h> |
| #include <lib/sys/inspect/cpp/component.h> |
| #include <lib/syslog/cpp/macros.h> |
| #include <lib/syslog/cpp/log_settings.h> |
| |
| #include <lib/fdio/directory.h> |
| #include <lib/fdio/fd.h> |
| #include <lib/fdio/fdio.h> |
| #include <lib/fdio/limits.h> |
| #include <lib/fdio/vfs.h> |
| #include <lib/zx/channel.h> |
| |
| |
| #include <block-client/cpp/block-device.h> |
| #include <block-client/cpp/remote-block-device.h> |
| |
| //#include "third_party/f2fs-tools/f2fs_tools.h" |
| |
| #include <iostream> |
| #include <string> |
| |
| #include "third_party/f2fs/f2fs.h" |
| |
| int main(int argc, const char** argv) { |
| f2fs::MountOptions options; |
| f2fs::MkfsOptions mkfs_options; |
| |
| std::cout << "f2fs arg= "; |
| |
| for (int i=0; i < argc; i++) { |
| std::cout<< argv[i] << " "; |
| } |
| |
| std::cout << std::endl; |
| |
| if (argc <= 1) { |
| std::cout << "Hello F2FS!!!" << std::endl; |
| fprintf(stderr, "usage: mkfs [ <options>*] devicepath f2fs\n"); |
| fprintf(stderr, "usage: fsck [ <options>*] devicepath f2fs\n"); |
| fprintf(stderr, "usage: mount [ <options>*] devicepath f2fs\n"); |
| return 0; |
| } |
| |
| |
| // Block device passed by handle |
| zx::channel device_channel = zx::channel(zx_take_startup_handle(FS_HANDLE_BLOCK_DEVICE_ID)); |
| |
| std::unique_ptr<block_client::RemoteBlockDevice> device; |
| zx_status_t status = block_client::RemoteBlockDevice::Create(std::move(device_channel), &device); |
| if (status != ZX_OK) { |
| FX_LOGS(ERROR) << "Could not access block device"; |
| return -1; |
| } |
| |
| std::unique_ptr<f2fs::Bcache> bc; |
| bool readonly_device = false; |
| |
| if (f2fs::CreateBcache(std::move(device), &readonly_device, &bc) != ZX_OK) { |
| fprintf(stderr, "f2fs: error: cannot create block cache\n"); |
| return -1; |
| } |
| |
| //TODO: implement the fsck logic |
| if (!strcmp(argv[1], "mkfs")) { |
| f2fs::Mkfs(mkfs_options, std::move(bc)); |
| } else if (!strcmp(argv[1], "fsck")) { |
| f2fs::Fsck(options, std::move(bc)); |
| } else if (!strcmp(argv[1], "mount")) { |
| f2fs::Mount(options, std::move(bc)); |
| } else { |
| std::cout << "F2FS: unknown operation:" << argv[1] << std::endl; |
| } |
| |
| return 0; |
| } |