Use FUSE_COMPAT_22_INIT_OUT_SIZE always if available.
We return the minor version number 15 to FUSE_INIT since we don't handle
BATCH_FORGET. Thus the kernel does not accept the latest size of
fuse_init_out. Instead we need to use FUSE_COMPAT_22_INIT_OUT_SIZE.
Bug: 32779923
Test: libappfuse_test
Change-Id: I5c979d0e45344ca8adfe3ad3f4a9561442abcb3a
diff --git a/libappfuse/FuseBuffer.cc b/libappfuse/FuseBuffer.cc
index 45280a5..5f4c1f8 100644
--- a/libappfuse/FuseBuffer.cc
+++ b/libappfuse/FuseBuffer.cc
@@ -101,23 +101,18 @@
return;
}
- // We limit ourselves to 15 because we don't handle BATCH_FORGET yet
- size_t response_size = sizeof(fuse_init_out);
+ // We limit ourselves to minor=15 because we don't handle BATCH_FORGET yet.
+ // Thus we need to use FUSE_COMPAT_22_INIT_OUT_SIZE.
#if defined(FUSE_COMPAT_22_INIT_OUT_SIZE)
// FUSE_KERNEL_VERSION >= 23.
-
- // If the kernel only works on minor revs older than or equal to 22,
- // then use the older structure size since this code only uses the 7.22
- // version of the structure.
- if (minor <= 22) {
- response_size = FUSE_COMPAT_22_INIT_OUT_SIZE;
- }
+ const size_t response_size = FUSE_COMPAT_22_INIT_OUT_SIZE;
+#else
+ const size_t response_size = sizeof(fuse_init_out);
#endif
response.Reset(response_size, kFuseSuccess, unique);
fuse_init_out* const out = &response.init_out;
out->major = FUSE_KERNEL_VERSION;
- // We limit ourselves to 15 because we don't handle BATCH_FORGET yet.
out->minor = std::min(minor, 15u);
out->max_readahead = max_readahead;
out->flags = FUSE_ATOMIC_O_TRUNC | FUSE_BIG_WRITES;
diff --git a/libappfuse/tests/FuseBufferTest.cc b/libappfuse/tests/FuseBufferTest.cc
index 1aacfe3..7f42845 100644
--- a/libappfuse/tests/FuseBufferTest.cc
+++ b/libappfuse/tests/FuseBufferTest.cc
@@ -163,7 +163,7 @@
buffer.HandleInit();
- ASSERT_EQ(sizeof(fuse_out_header) + sizeof(fuse_init_out),
+ ASSERT_EQ(sizeof(fuse_out_header) + FUSE_COMPAT_22_INIT_OUT_SIZE,
buffer.response.header.len);
EXPECT_EQ(kFuseSuccess, buffer.response.header.error);
EXPECT_EQ(static_cast<unsigned int>(FUSE_KERNEL_VERSION),