diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel index a78af623eea..8af4fc8e0c6 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel @@ -148,7 +148,6 @@ cf_cc_library( "//cuttlefish/io:lz4_legacy", "//cuttlefish/io:native_filesystem", "//cuttlefish/io:reader", - "//cuttlefish/io:shared_fd", "//cuttlefish/io:string", "//cuttlefish/io:write_exact", "//cuttlefish/posix:remove", @@ -633,6 +632,7 @@ cf_cc_library( hdrs = ["vendor_dlkm_utils.h"], deps = [ "//cuttlefish/common/libs/fs", + "//cuttlefish/common/libs/fs:fd", "//cuttlefish/common/libs/utils:contains", "//cuttlefish/common/libs/utils:disk_usage", "//cuttlefish/common/libs/utils:environment", @@ -644,7 +644,6 @@ cf_cc_library( "//cuttlefish/host/libs/avb", "//cuttlefish/host/libs/config:config_utils", "//cuttlefish/host/libs/config:known_paths", - "//cuttlefish/io:shared_fd", "//cuttlefish/process:command", "//cuttlefish/process:execute", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc index 9d3d8ddd135..ebba077baf3 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/boot_image_utils.cc @@ -56,7 +56,6 @@ #include "cuttlefish/io/lz4_legacy.h" #include "cuttlefish/io/native_filesystem.h" #include "cuttlefish/io/reader.h" -#include "cuttlefish/io/shared_fd.h" #include "cuttlefish/io/string.h" #include "cuttlefish/io/write_exact.h" #include "cuttlefish/posix/remove.h" @@ -220,12 +219,10 @@ Result UnpackBootImage(const std::string& boot_image_path, Result UnpackVendorBootImageIfNotUnpacked( const std::string& vendor_boot_image_path, const std::string& unpack_dir) { - SharedFD vendor_boot_fd = SharedFD::Open(vendor_boot_image_path, O_RDONLY); - CF_EXPECTF(vendor_boot_fd->IsOpen(), "Failed to open '{}': '{}'", - vendor_boot_image_path, vendor_boot_fd->StrError()); + Fd vendor_boot_fd = CF_EXPECT(Fd::Open(vendor_boot_image_path, O_RDONLY)); VendorBootImage vendor_boot = CF_EXPECT( - VendorBootImage::Read(std::make_unique(vendor_boot_fd))); + VendorBootImage::Read(std::make_unique(std::move(vendor_boot_fd)))); // The ramdisk file is created during the first unpack. If it's already there, // a unpack has occurred and there's no need to repeat the process. std::string concat_file_path = unpack_dir + "/" + kConcatenatedVendorRamdisk; diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel index e910c068b31..c2867040e8c 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel @@ -152,6 +152,7 @@ cf_cc_library( hdrs = ["generate_persistent_bootconfig.h"], deps = [ "//cuttlefish/common/libs/fs", + "//cuttlefish/common/libs/fs:fd", "//cuttlefish/common/libs/key_equals_value", "//cuttlefish/common/libs/utils:files", "//cuttlefish/common/libs/utils:size_utils", @@ -162,7 +163,6 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:data_image", "//cuttlefish/host/libs/image_aggregator", - "//cuttlefish/io:shared_fd", "//cuttlefish/io:string", "//cuttlefish/result", "@abseil-cpp//absl/log", diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp index 69430432fe5..2a1f2998d8e 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp @@ -28,6 +28,7 @@ #include "absl/log/log.h" +#include "cuttlefish/common/libs/fs/fd.h" #include "cuttlefish/common/libs/fs/shared_buf.h" #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/key_equals_value/key_equals_value.h" @@ -41,7 +42,6 @@ #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/data_image.h" #include "cuttlefish/host/libs/image_aggregator/image_aggregator.h" -#include "cuttlefish/io/shared_fd.h" #include "cuttlefish/io/string.h" #include "cuttlefish/result/result.h" @@ -51,11 +51,9 @@ namespace { Result>> ReadBuiltInBootconfigArgs(const CuttlefishConfig::InstanceSpecific& instance) { std::string image_path = instance.vendor_boot_image(); - SharedFD fd = SharedFD::Open(image_path, O_RDONLY); - CF_EXPECTF(fd->IsOpen(), "Failed to open '{}': '{}'", image_path, - fd->StrError()); + Fd fd = CF_EXPECT(Fd::Open(image_path, O_RDONLY)); VendorBootImage vendor_boot = - CF_EXPECT(VendorBootImage::Read(std::make_unique(fd))); + CF_EXPECT(VendorBootImage::Read(std::make_unique(std::move(fd)))); auto bootconfig_opt = vendor_boot.Bootconfig(); if (!bootconfig_opt) { return {}; diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.cc index ade4b248f19..66bce8758b4 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/vendor_dlkm_utils.cc @@ -38,6 +38,7 @@ #include "android-base/file.h" #include "fmt/format.h" +#include "cuttlefish/common/libs/fs/fd.h" #include "cuttlefish/common/libs/fs/shared_buf.h" #include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/utils/contains.h" @@ -51,7 +52,6 @@ #include "cuttlefish/host/libs/avb/avb.h" #include "cuttlefish/host/libs/config/config_utils.h" #include "cuttlefish/host/libs/config/known_paths.h" -#include "cuttlefish/io/shared_fd.h" #include "cuttlefish/process/command.h" #include "cuttlefish/process/execute.h" #include "cuttlefish/result/result.h" @@ -473,11 +473,9 @@ Result SplitRamdiskModules(const std::string& ramdisk_path, if (!FileExists(module_location)) { continue; } - SharedFD module_fd = SharedFD::Open(module_location, O_RDONLY); - CF_EXPECT(module_fd->IsOpen(), module_fd->StrError()); - SharedFdIo module_io(module_fd); + Fd module_fd = CF_EXPECT(Fd::Open(module_location, O_RDONLY)); - if (IsKernelModuleSigned(module_io).value_or(false)) { + if (IsKernelModuleSigned(module_fd).value_or(false)) { const auto system_dlkm_module_location = fmt::format("{}/{}", system_modules_dir, module_path); diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/BUILD.bazel index 035e2a14a07..d057a357052 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/BUILD.bazel @@ -132,7 +132,6 @@ cf_cc_library( srcs = ["log_sources.cc"], hdrs = ["log_sources.h"], deps = [ - "//cuttlefish/common/libs/fs", "//cuttlefish/common/libs/fs:fd", "//cuttlefish/common/libs/utils:tee_logging", "//cuttlefish/files:file_exists", @@ -145,7 +144,6 @@ cf_cc_library( "//cuttlefish/host/commands/cvd/instances", "//cuttlefish/host/libs/log_names", "//cuttlefish/io", - "//cuttlefish/io:shared_fd", "//cuttlefish/result", "@abseil-cpp//absl/strings", ], diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/log_sources.cc b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/log_sources.cc index 756455787f8..72fcd6f0d2f 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/log_sources.cc +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/monitor/log_sources.cc @@ -28,7 +28,6 @@ #include "absl/strings/str_cat.h" #include "cuttlefish/common/libs/fs/fd.h" -#include "cuttlefish/common/libs/fs/shared_fd.h" #include "cuttlefish/common/libs/utils/tee_logging.h" #include "cuttlefish/files/file_exists.h" #include "cuttlefish/host/commands/cvd/cli/commands/monitor/file_monitor_source.h" @@ -40,7 +39,6 @@ #include "cuttlefish/host/commands/cvd/instances/local_instance.h" #include "cuttlefish/host/libs/log_names/log_names.h" #include "cuttlefish/io/io.h" -#include "cuttlefish/io/shared_fd.h" #include "cuttlefish/result/result.h" namespace cuttlefish { @@ -92,11 +90,11 @@ std::unique_ptr LauncherLogMonitorSource( if (!FileExists(path)) { return {}; } - SharedFD fd = Fd::Open(path, O_RDONLY).value_or(Fd()); - if (!fd->IsOpen() || fd->LSeek(0, SEEK_END) <= 0) { + Result fd = Fd::Open(path, O_RDONLY); + if (!fd.has_value() || !fd->SeekEnd(0).has_value()) { return {}; } - std::unique_ptr io = std::make_unique(fd); + std::unique_ptr io = std::make_unique(std::move(*fd)); return std::make_unique( path, std::move(io), ColorLauncherOrLogTee, std::bind_front(FilterLauncherOrLogTee, severity)); @@ -109,11 +107,11 @@ std::unique_ptr KernelLogMonitorSource( if (!FileExists(path)) { return {}; } - SharedFD fd = Fd::Open(path, O_RDONLY).value_or(Fd()); - if (!fd->IsOpen() || fd->LSeek(0, SEEK_END) <= 0) { + Result fd = Fd::Open(path, O_RDONLY); + if (!fd.has_value() || !fd->SeekEnd(0).has_value()) { return {}; } - std::unique_ptr io = std::make_unique(fd); + std::unique_ptr io = std::make_unique(std::move(*fd)); return std::make_unique( path, std::move(io), ColorKernelLine, [](std::string_view) { return true; }); @@ -126,11 +124,11 @@ std::unique_ptr LogcatMonitorSource( if (!FileExists(path)) { return {}; } - SharedFD fd = Fd::Open(path, O_RDONLY).value_or(Fd()); - if (!fd->IsOpen() || fd->LSeek(0, SEEK_END) <= 0) { + Result fd = Fd::Open(path, O_RDONLY); + if (!fd.has_value() || !fd->SeekEnd(0).has_value()) { return {}; } - std::unique_ptr io = std::make_unique(fd); + std::unique_ptr io = std::make_unique(std::move(*fd)); return std::make_unique( path, std::move(io), ColorLogcatLine, std::bind_front(FilterLogcatLine, severity)); diff --git a/base/cvd/cuttlefish/io/BUILD.bazel b/base/cvd/cuttlefish/io/BUILD.bazel index aef21a993ed..6120dae4d60 100644 --- a/base/cvd/cuttlefish/io/BUILD.bazel +++ b/base/cvd/cuttlefish/io/BUILD.bazel @@ -121,7 +121,6 @@ cf_cc_library( "//cuttlefish/io:concat", "//cuttlefish/io:read_window_view", "//cuttlefish/io:reader", - "//cuttlefish/io:shared_fd", "//cuttlefish/result:expect", "//cuttlefish/result:result_type", ], @@ -379,18 +378,6 @@ cf_cc_test( ], ) -cf_cc_library( - name = "shared_fd", - srcs = ["shared_fd.cc"], - hdrs = ["shared_fd.h"], - deps = [ - "//cuttlefish/common/libs/fs", - "//cuttlefish/io", - "//cuttlefish/result:expect", - "//cuttlefish/result:result_type", - ], -) - cf_cc_library( name = "string", srcs = ["string.cc"], diff --git a/base/cvd/cuttlefish/io/default_visitor.cc b/base/cvd/cuttlefish/io/default_visitor.cc index 41fdc2461ab..7f5e70ce30b 100644 --- a/base/cvd/cuttlefish/io/default_visitor.cc +++ b/base/cvd/cuttlefish/io/default_visitor.cc @@ -19,7 +19,6 @@ #include "cuttlefish/io/io.h" #include "cuttlefish/io/read_window_view.h" #include "cuttlefish/io/reader.h" -#include "cuttlefish/io/shared_fd.h" #include "cuttlefish/result/expect.h" #include "cuttlefish/result/result_type.h" @@ -53,11 +52,6 @@ Result DefaultIoVisitor::Accept(Seeker&) { return CF_ERR("Unimplemented"); } -Result DefaultIoVisitor::Accept(SharedFdIo& io) { - CF_EXPECT(Accept(static_cast(io))); - return {}; -} - Result DefaultIoVisitor::Accept(Writer&) { return CF_ERR("Unimplemented"); } diff --git a/base/cvd/cuttlefish/io/default_visitor.h b/base/cvd/cuttlefish/io/default_visitor.h index 41e6e36b46c..f2057fc0dae 100644 --- a/base/cvd/cuttlefish/io/default_visitor.h +++ b/base/cvd/cuttlefish/io/default_visitor.h @@ -31,7 +31,6 @@ class DefaultIoVisitor : public IoVisitor { Result Accept(ReaderSeeker&); Result Accept(ReaderWriterSeeker&); Result Accept(Seeker&); - Result Accept(SharedFdIo&); Result Accept(Writer&); Result Accept(WriterSeeker&); }; diff --git a/base/cvd/cuttlefish/io/io.h b/base/cvd/cuttlefish/io/io.h index 1e4a2535c41..e953512f247 100644 --- a/base/cvd/cuttlefish/io/io.h +++ b/base/cvd/cuttlefish/io/io.h @@ -25,7 +25,6 @@ namespace cuttlefish { class ConcatReaderSeeker; class ReadWindowView; -class SharedFdIo; class Writer : public virtual IoVisitable { public: @@ -105,7 +104,6 @@ class IoVisitor { virtual Result Accept(ReaderSeeker&) = 0; virtual Result Accept(ReaderWriterSeeker&) = 0; virtual Result Accept(Seeker&) = 0; - virtual Result Accept(SharedFdIo&) = 0; virtual Result Accept(Writer&) = 0; virtual Result Accept(WriterSeeker&) = 0; }; diff --git a/base/cvd/cuttlefish/io/shared_fd.cc b/base/cvd/cuttlefish/io/shared_fd.cc deleted file mode 100644 index 661b6378b7f..00000000000 --- a/base/cvd/cuttlefish/io/shared_fd.cc +++ /dev/null @@ -1,77 +0,0 @@ -// -// Copyright (C) 2026 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/io/shared_fd.h" - -#include -#include - -#include - -#include "cuttlefish/common/libs/fs/shared_fd.h" -#include "cuttlefish/io/io.h" -#include "cuttlefish/result/expect.h" -#include "cuttlefish/result/result_type.h" - -namespace cuttlefish { - -SharedFdIo::SharedFdIo(SharedFD fd) : fd_(std::move(fd)) {} - -Result SharedFdIo::Visit(IoVisitor& visitor) { - CF_EXPECT(visitor.Accept(*this)); - return {}; -} - -Result SharedFdIo::Read(void* buf, uint64_t count) { - return CF_EXPECT(fd_->Read(buf, count)); -} - -Result SharedFdIo::Write(const void* buf, uint64_t count) { - return CF_EXPECT(fd_->Write(buf, count)); -} - -Result SharedFdIo::SeekSet(uint64_t offset) { - CF_EXPECT_EQ(fd_->LSeek(offset, SEEK_SET), offset, fd_->StrError()); - return offset; -} - -Result SharedFdIo::SeekCur(int64_t offset) { - int64_t new_offset = fd_->LSeek(offset, SEEK_CUR); - CF_EXPECT_GE(new_offset, 0, fd_->StrError()); - return new_offset; -} - -Result SharedFdIo::SeekEnd(int64_t offset) { - int64_t new_offset = fd_->LSeek(offset, SEEK_END); - CF_EXPECT_GE(new_offset, 0, fd_->StrError()); - return new_offset; -} - -Result SharedFdIo::PRead(void* buf, uint64_t count, - uint64_t offset) const { - return CF_EXPECT(fd_->PRead(buf, count, offset)); -} - -Result SharedFdIo::PWrite(const void* buf, uint64_t count, - uint64_t offset) { - return CF_EXPECT(fd_->PWrite(buf, count, offset)); -} - -Result SharedFdIo::Truncate(uint64_t size) { - CF_EXPECT(fd_->Truncate(size)); - return {}; -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/io/shared_fd.h b/base/cvd/cuttlefish/io/shared_fd.h deleted file mode 100644 index a9cf48bf224..00000000000 --- a/base/cvd/cuttlefish/io/shared_fd.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright (C) 2026 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - -#include "cuttlefish/common/libs/fs/shared_fd.h" -#include "cuttlefish/io/io.h" -#include "cuttlefish/result/result_type.h" - -namespace cuttlefish { - -class SharedFdIo : public ReaderWriterSeeker { - public: - explicit SharedFdIo(SharedFD); - - Result Visit(IoVisitor&) override; - Result Read(void* buf, uint64_t count) override; - Result Write(const void* buf, uint64_t count) override; - Result SeekSet(uint64_t offset) override; - Result SeekCur(int64_t offset) override; - Result SeekEnd(int64_t offset) override; - Result PRead(void* buf, uint64_t count, - uint64_t offset) const override; - Result PWrite(const void* buf, uint64_t count, - uint64_t offset) override; - Result Truncate(uint64_t size) override; - - private: - SharedFD fd_; -}; - -} // namespace cuttlefish