Index: native_client_sdk/src/libraries/nacl_io/passthroughfs/real_node.cc |
diff --git a/native_client_sdk/src/libraries/nacl_io/passthroughfs/real_node.cc b/native_client_sdk/src/libraries/nacl_io/passthroughfs/real_node.cc |
index 7f585f640c54b35c633801da9cbd46b08b436721..39f7a9105723f605a1923eb50a347159904a8edc 100644 |
--- a/native_client_sdk/src/libraries/nacl_io/passthroughfs/real_node.cc |
+++ b/native_client_sdk/src/libraries/nacl_io/passthroughfs/real_node.cc |
@@ -12,11 +12,13 @@ |
#include "nacl_io/log.h" |
namespace nacl_io { |
+ |
RealNode::RealNode(Filesystem* filesystem, int real_fd, bool close_on_destroy) |
: Node(filesystem), |
real_fd_(real_fd), |
close_on_destroy_(close_on_destroy) |
{ |
+ GetStat(&stat_); |
} |
void RealNode::Destroy() { |
@@ -89,22 +91,34 @@ Error RealNode::GetDents(size_t offs, |
struct dirent* pdir, |
size_t count, |
int* out_bytes) { |
- size_t nread; |
- int err = _real_getdents(real_fd_, pdir, count, &nread); |
- if (err) |
- return err; |
- return nread; |
+ size_t out_bytes_as_size_t; |
+ Error rtn = _real_getdents(real_fd_, pdir, count, &out_bytes_as_size_t); |
+ if (rtn == 0) |
+ *out_bytes = out_bytes_as_size_t; |
+ return rtn; |
} |
+#ifndef S_UNSUP |
+#define S_UNSUP S_IFMT |
+#endif |
+ |
Error RealNode::GetStat(struct stat* stat) { |
int err = _real_fstat(real_fd_, stat); |
if (err) |
return err; |
- // On windows, fstat() of stdin/stdout/stderr returns all zeros |
- // for the permission bits. This can cause problems down the |
- // line. For example, CanOpen() will fail. |
+ // On windows, fstat() of stdin/stdout/stderr (when they are represented |
+ // as char device or FIFO) returns all zeros for the mode bits. This can |
+ // cause problems down the line. For example, CanOpen() will fail. |
+ // We also have to check for S_UNSUP because S_IFIFO is currently not |
+ // reported by the windows sel_ldr. |
// TODO(sbc): Fix this within sel_ldr instead. |
- if (S_ISCHR(stat->st_mode) && (stat->st_mode & S_IRWXU) == 0) |
+ if ((stat->st_mode & S_IRWXU) == 0) { |
+ LOG_WARN("_real_fstat(%d) reported not access permissions: st_mode=O%o\n", |
+ real_fd_, stat->st_mode); |
+ } |
+ if ((S_ISCHR(stat->st_mode) |
+ || S_ISFIFO(stat->st_mode) |
+ || (stat->st_mode & S_IFMT) == S_UNSUP) && (stat->st_mode & S_IRWXU) == 0) |
stat->st_mode |= S_IRWXU; |
return 0; |
} |