0

[NaCl SDK] nacl_io: Make the default directory size returned by stat to be 4096

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

Cr-Commit-Position: refs/heads/master@{#343298}
This commit is contained in:
zhitingzhu
2015-08-13 16:17:26 -07:00
committed by Commit bot
parent 9924b74c85
commit 4b30ffe83c
2 changed files with 9 additions and 2 deletions
native_client_sdk/src
libraries
nacl_io
tests
nacl_io_test

@ -26,6 +26,8 @@ namespace nacl_io {
namespace {
const int kEmptyDirSize = 4096;
struct OutputBuffer {
void* data;
int element_count;
@ -156,6 +158,8 @@ Error Html5FsNode::GetStat(struct stat* stat) {
// Fill in known info here.
memcpy(stat, &stat_, sizeof(stat_));
stat->st_size = static_cast<off_t>(info.size);
// Fill in the additional info from ppapi.
switch (info.type) {
case PP_FILETYPE_REGULAR:
@ -163,12 +167,15 @@ Error Html5FsNode::GetStat(struct stat* stat) {
break;
case PP_FILETYPE_DIRECTORY:
stat->st_mode |= S_IFDIR;
// Hack the directory size
// In Linux, even a empty directory has size 4096
// info.size is always zero for directories
stat->st_size = kEmptyDirSize;
break;
case PP_FILETYPE_OTHER:
default:
break;
}
stat->st_size = static_cast<off_t>(info.size);
stat->st_atime = info.last_access_time;
stat->st_mtime = info.last_modified_time;
stat->st_ctime = info.creation_time;

@ -411,7 +411,7 @@ TEST_F(Html5FsTest, GetStat) {
EXPECT_EQ(0, node->GetStat(&statbuf));
EXPECT_TRUE(S_ISDIR(statbuf.st_mode));
EXPECT_EQ(S_IRALL | S_IWALL | S_IXALL, statbuf.st_mode & S_MODEBITS);
EXPECT_EQ(0, statbuf.st_size);
EXPECT_EQ(4096, statbuf.st_size);
EXPECT_EQ(access_time, statbuf.st_atime);
EXPECT_EQ(creation_time, statbuf.st_ctime);
EXPECT_EQ(modified_time, statbuf.st_mtime);