From 9947d3e67fb4f7ab388c4ae1593dad8bce0f3153 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 7 May 2024 20:48:00 +0200 Subject: [PATCH] lib/nfs/Connection: use nfs_fstat64_async() This is 64-bit-safe and anyway, nfs_fstat_async() doesn't work with NFSv4. --- src/lib/nfs/Connection.cxx | 2 +- src/lib/nfs/FileReader.cxx | 11 +++++++---- src/lib/nfs/FileReader.hxx | 5 ++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx index 6648d6fab..cccf175dd 100644 --- a/src/lib/nfs/Connection.cxx +++ b/src/lib/nfs/Connection.cxx @@ -74,7 +74,7 @@ NfsConnection::CancellableCallback::Stat(nfs_context *ctx, { assert(connection.GetEventLoop().IsInside()); - int result = nfs_fstat_async(ctx, fh, Callback, this); + int result = nfs_fstat64_async(ctx, fh, Callback, this); if (result < 0) throw NfsClientError(ctx, "nfs_fstat_async() failed"); } diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx index 00cd1fc7b..0538f7f73 100644 --- a/src/lib/nfs/FileReader.cxx +++ b/src/lib/nfs/FileReader.cxx @@ -8,12 +8,15 @@ #include "event/Call.hxx" #include "util/ASCII.hxx" +#include // for struct nfs_stat_64 + #include #include #include #include #include +#include // for S_ISREG() NfsFileReader::NfsFileReader() noexcept :defer_open(nfs_get_event_loop(), BIND_THIS_METHOD(OnDeferredOpen)) @@ -180,7 +183,7 @@ NfsFileReader::OpenCallback(nfsfh *_fh) noexcept } inline void -NfsFileReader::StatCallback(const struct stat *_st) noexcept +NfsFileReader::StatCallback(const struct nfs_stat_64 *_st) noexcept { assert(connection != nullptr); assert(fh != nullptr); @@ -195,12 +198,12 @@ NfsFileReader::StatCallback(const struct stat *_st) noexcept const auto *st = _st; #endif - if (!S_ISREG(st->st_mode)) { + if (!S_ISREG(st->nfs_mode)) { OnNfsFileError(std::make_exception_ptr(std::runtime_error("Not a regular file"))); return; } - OnNfsFileOpen(st->st_size); + OnNfsFileOpen(st->nfs_size); } void @@ -219,7 +222,7 @@ NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept break; case State::STAT: - StatCallback((const struct stat *)data); + StatCallback((const struct nfs_stat_64 *)data); break; case State::READ: diff --git a/src/lib/nfs/FileReader.hxx b/src/lib/nfs/FileReader.hxx index 786e87e67..4c05e5184 100644 --- a/src/lib/nfs/FileReader.hxx +++ b/src/lib/nfs/FileReader.hxx @@ -14,9 +14,8 @@ #include #include -#include - struct nfsfh; +struct nfs_stat_64; class NfsConnection; /** @@ -126,7 +125,7 @@ private: void CancelOrClose() noexcept; void OpenCallback(nfsfh *_fh) noexcept; - void StatCallback(const struct stat *st) noexcept; + void StatCallback(const struct nfs_stat_64 *st) noexcept; /* virtual methods from NfsLease */ void OnNfsConnectionReady() noexcept final;