diff options
author | sbc <sbc@chromium.org> | 2015-08-22 10:52:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-22 17:53:06 +0000 |
commit | 1ee3626cbd39116f57ede2a22d5acea9f0fbfc32 (patch) | |
tree | a1bb282c07038e62e4582c677b17b226827741a9 | |
parent | 461303becab665006c6c26cdd8b6fe7120b00fc5 (diff) | |
download | chromium_src-1ee3626cbd39116f57ede2a22d5acea9f0fbfc32.zip chromium_src-1ee3626cbd39116f57ede2a22d5acea9f0fbfc32.tar.gz chromium_src-1ee3626cbd39116f57ede2a22d5acea9f0fbfc32.tar.bz2 |
[NaCl SDK] Never return st_size == 0 for directory nodes
The scandir code in newlib assumes that st_size of
direcoties is a reflection of the number of entries,
and in particular has a early out when st_size == 0.
Review URL: https://codereview.chromium.org/1304983004
Cr-Commit-Position: refs/heads/master@{#344986}
-rw-r--r-- | native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc | 9 | ||||
-rw-r--r-- | native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc | 16 |
2 files changed, 17 insertions, 8 deletions
diff --git a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc index 76eff01..bb3a8f5 100644 --- a/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc +++ b/native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc @@ -26,8 +26,6 @@ namespace nacl_io { namespace { -const int kEmptyDirSize = 4096; - struct OutputBuffer { void* data; int element_count; @@ -158,8 +156,6 @@ 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: @@ -167,15 +163,12 @@ 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; diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc index de94f27..b554ade 100644 --- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc +++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc @@ -422,6 +422,14 @@ int KernelProxy::stat(const char* path, struct stat* buf) { return -1; } + /* + * newlib's scandir() assumes that directories are empty if st_size == 0. + * This is probably a bad assumption, but until we fix newlib always return + * a non-zero directory size. + */ + if (node->IsaDir() && buf->st_size == 0) + buf->st_size = 4096; + return 0; } @@ -588,6 +596,14 @@ int KernelProxy::fstat(int fd, struct stat* buf) { return -1; } + /* + * newlib's scandir() assumes that directories are empty if st_size == 0. + * This is probably a bad assumption, but until we fix newlib always return + * a non-zero directory size. + */ + if (handle->node()->IsaDir() && buf->st_size == 0) + buf->st_size = 4096; + return 0; } |