Skip to content

Commit bef1051

Browse files
sutes-workCQ Bot
authored andcommitted
[storage] Change GetDevicePath to return std::string
Avoid NUL terminator confusion by switching all GetDevicePath methods to std::string. Fixed: 63405 Change-Id: I3e58857d0bbe48f0ea2294968732a4bcc3ec2f81 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/580602 Reviewed-by: Brandon Castellano <bcastell@google.com> Commit-Queue: Chris Suter <csuter@google.com>
1 parent aea9fda commit bef1051

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/lib/storage/vfs/cpp/BUILD.gn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ static_library("cpp") {
113113
"//zircon/public/lib/zx",
114114

115115
# <fs/trace.h> has #include <lib/trace/event.h>.
116-
"//zircon/public/lib/zxc",
117116
"//zircon/system/ulib/trace",
117+
118+
# <fs/vnode.h> has #include <lib/zx/status.h>
119+
"//zircon/public/lib/zxc",
118120
]
119121
deps += [
120122
"//sdk/fidl/fuchsia.cobalt:fuchsia.cobalt_c",

src/lib/storage/vfs/cpp/directory_connection.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,11 @@ void DirectoryConnection::GetDevicePath(GetDevicePathRequestView request,
487487
return;
488488
}
489489

490-
char name[fio::wire::kMaxPath];
491-
size_t actual = 0;
492-
zx_status_t status = vnode()->GetDevicePath(sizeof(name), name, &actual);
493-
completer.Reply(status, fidl::StringView(name, actual));
490+
if (auto device_path_or = vnode()->GetDevicePath(); device_path_or.is_error()) {
491+
completer.Reply(device_path_or.error_value(), {});
492+
} else {
493+
completer.Reply(ZX_OK, fidl::StringView::FromExternal(device_path_or.value()));
494+
}
494495
}
495496

496497
void DirectoryConnection::AdvisoryLock(AdvisoryLockRequestView request,

src/lib/storage/vfs/cpp/vnode.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ zx_status_t Vnode::GetVmo(int flags, zx::vmo* out_vmo, size_t* out_size) {
299299

300300
zx_status_t Vnode::QueryFilesystem(fio::wire::FilesystemInfo* out) { return ZX_ERR_NOT_SUPPORTED; }
301301

302-
zx_status_t Vnode::GetDevicePath(size_t buffer_len, char* out_name, size_t* out_len) {
303-
return ZX_ERR_NOT_SUPPORTED;
304-
}
302+
zx::status<std::string> Vnode::GetDevicePath() const { return zx::error(ZX_ERR_NOT_SUPPORTED); }
305303

306304
zx_status_t Vnode::AttachRemote(MountChannel h) { return ZX_ERR_NOT_SUPPORTED; }
307305

src/lib/storage/vfs/cpp/vnode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <fidl/fuchsia.io2/cpp/wire.h>
3838
#include <lib/file-lock/file-lock.h>
3939
#include <lib/zx/channel.h>
40+
#include <lib/zx/status.h>
4041
#include <lib/zx/stream.h>
4142
#include <zircon/device/vfs.h>
4243

@@ -364,7 +365,7 @@ class Vnode : public VnodeRefCounted<Vnode>, public fbl::Recyclable<Vnode> {
364365
virtual zx_status_t QueryFilesystem(fuchsia_io::wire::FilesystemInfo* out);
365366

366367
// Returns the name of the device backing the filesystem, if one exists.
367-
virtual zx_status_t GetDevicePath(size_t buffer_len, char* out_name, size_t* out_len);
368+
virtual zx::status<std::string> GetDevicePath() const;
368369

369370
// Attaches a handle to the vnode, if possible. Otherwise, returns an error.
370371
virtual zx_status_t AttachRemote(MountChannel h);

0 commit comments

Comments
 (0)