Commit 49b78e74 authored by binji's avatar binji Committed by Commit bot

[NaCl SDK] nacl_io: Fix FuseFs.{read,write}

I misinterpreted the docs as meaning that read() and write() should
always return the number of bytes requested.

What it actually says is that the functions should always return the
number of bytes requested _unless_ the EOF is reached or there is an
error.

BUG=411557
R=sbc@chromium.org

Review URL: https://codereview.chromium.org/549353003

Cr-Commit-Position: refs/heads/master@{#294018}
parent 8266ca7b
......@@ -341,13 +341,11 @@ Error FileFuseFsNode::Read(const HandleAttr& attr,
if (result < 0)
return -result;
// Fuse docs say that a read() call will always completely fill the buffer
// (padding with zeroes) unless the direct_io filesystem flag is set.
// TODO(binji): support the direct_io flag
if (static_cast<size_t>(result) < count)
memset(&cbuf[result], 0, count - result);
*out_bytes = count;
*out_bytes = result;
return 0;
}
......@@ -365,9 +363,6 @@ Error FileFuseFsNode::Write(const HandleAttr& attr,
if (result < 0)
return -result;
// Fuse docs say that a write() call will always write the entire buffer
// unless the direct_io filesystem flag is set.
// TODO(binji): What should we do if the user breaks this contract? Warn?
// TODO(binji): support the direct_io flag
*out_bytes = result;
return 0;
......
......@@ -222,9 +222,14 @@ TEST_F(FuseFsTest, OpenAndRead) {
int bytes_read = 0;
HandleAttr attr;
ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
// FUSE always fills the buffer (padding with \0) unless in direct_io mode.
ASSERT_EQ(sizeof(buffer), bytes_read);
ASSERT_EQ(strlen(hello_world), bytes_read);
ASSERT_STREQ(hello_world, buffer);
// Try to read past the end of the file.
attr.offs = strlen(hello_world) - 7;
ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
ASSERT_EQ(7, bytes_read);
ASSERT_STREQ("World!\n", buffer);
}
TEST_F(FuseFsTest, CreateAndWrite) {
......@@ -241,8 +246,7 @@ TEST_F(FuseFsTest, CreateAndWrite) {
char buffer[40] = {0};
int bytes_read = 0;
ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
// FUSE always fills the buffer (padding with \0) unless in direct_io mode.
ASSERT_EQ(sizeof(buffer), bytes_read);
ASSERT_EQ(strlen(message), bytes_read);
ASSERT_STREQ(message, buffer);
}
......@@ -349,7 +353,7 @@ TEST_F(KernelProxyFuseTest, Basic) {
char buffer[30];
memset(buffer, 0, sizeof(buffer));
ASSERT_EQ(sizeof(buffer), ki_read(fd, buffer, sizeof(buffer)));
ASSERT_EQ(sizeof(hello_world), ki_read(fd, buffer, sizeof(buffer)));
EXPECT_STREQ(hello_world, buffer);
EXPECT_EQ(0, ki_close(fd));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment