diff --git a/libappfuse/FuseBuffer.cc b/libappfuse/FuseBuffer.cc index 74fe756a9..3ade31c54 100644 --- a/libappfuse/FuseBuffer.cc +++ b/libappfuse/FuseBuffer.cc @@ -118,23 +118,18 @@ void FuseBuffer::HandleInit() { 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 17f1306fe..c82213513 100644 --- a/libappfuse/tests/FuseBufferTest.cc +++ b/libappfuse/tests/FuseBufferTest.cc @@ -164,7 +164,7 @@ TEST(FuseBufferTest, HandleInit) { 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(FUSE_KERNEL_VERSION),