// Open the first three in order to get STDIN, STDOUT, STDERR
int fd;
- fd = open("/dev/stdin", O_RDONLY);
+ fd = open("/dev/stdin", O_RDONLY, 0);
assert(fd == 0);
if (fd < 0)
rtn = errno;
- fd = open("/dev/stdout", O_WRONLY);
+ fd = open("/dev/stdout", O_WRONLY, 0);
assert(fd == 1);
if (fd < 0)
rtn = errno;
- fd = open("/dev/stderr", O_WRONLY);
+ fd = open("/dev/stderr", O_WRONLY, 0);
assert(fd == 2);
if (fd < 0)
rtn = errno;
return AllocateFD(handle, path);
}
-int KernelProxy::open(const char* path, int open_flags) {
+int KernelProxy::open(const char* path, int open_flags, mode_t mode) {
ScopedFilesystem fs;
ScopedNode node;
- Error error = AcquireFsAndNode(path, open_flags, &fs, &node);
+ Error error = AcquireFsAndNode(path, open_flags, mode, &fs, &node);
if (error) {
errno = error;
return -1;
}
int KernelProxy::chmod(const char* path, mode_t mode) {
- int fd = KernelProxy::open(path, O_RDONLY);
+ int fd = open(path, O_RDONLY, mode);
if (-1 == fd)
return -1;
return 0;
}
-int KernelProxy::utime(const char* filename, const struct utimbuf* times) {
- return 0;
-}
-
int KernelProxy::mkdir(const char* path, mode_t mode) {
ScopedFilesystem fs;
Path rel;
}
int KernelProxy::stat(const char* path, struct stat* buf) {
- int fd = open(path, O_RDONLY);
+ int fd = open(path, O_RDONLY, 0);
if (-1 == fd)
return -1;
return 0;
}
+int KernelProxy::futimens(int fd, const struct timespec times[2]) {
+ ScopedKernelHandle handle;
+ Error error = AcquireHandle(fd, &handle);
+ if (error) {
+ errno = error;
+ return -1;
+ }
+
+ error = handle->node()->Futimens(times);
+ if (error) {
+ errno = error;
+ return -1;
+ }
+
+ return 0;
+}
+
off_t KernelProxy::lseek(int fd, off_t offset, int whence) {
ScopedKernelHandle handle;
Error error = AcquireHandle(fd, &handle);
}
int KernelProxy::truncate(const char* path, off_t len) {
- int fd = KernelProxy::open(path, O_WRONLY);
+ int fd = open(path, O_WRONLY, 0);
if (-1 == fd)
return -1;
return 0;
}
-// TODO(noelallen): Needs implementation.
-int KernelProxy::fchmod(int fd, int mode) {
+int KernelProxy::fchmod(int fd, mode_t mode) {
ScopedKernelHandle handle;
Error error = AcquireHandle(fd, &handle);
if (error) {
return -1;
}
+ error = handle->node()->Fchmod(mode);
+ if (error) {
+ errno = error;
+ return -1;
+ }
+
return 0;
}
}
int KernelProxy::access(const char* path, int amode) {
- ScopedFilesystem fs;
- Path rel;
+ struct stat buf;
+ int rtn = stat(path, &buf);
+ if (rtn != 0)
+ return rtn;
- Error error = AcquireFsAndRelPath(path, &fs, &rel);
- if (error) {
- errno = error;
+ if (((amode & R_OK) && !(buf.st_mode & S_IREAD)) ||
+ ((amode & W_OK) && !(buf.st_mode & S_IWRITE)) ||
+ ((amode & X_OK) && !(buf.st_mode & S_IEXEC))) {
+ errno = EACCES;
return -1;
}
- error = fs->Access(rel, amode);
- if (error) {
- errno = error;
- return -1;
- }
return 0;
}
return -1;
}
-int KernelProxy::utimes(const char* filename, const struct timeval times[2]) {
- LOG_TRACE("utimes is not implemented.");
- errno = EINVAL;
- return -1;
+int KernelProxy::utimens(const char* path, const struct timespec times[2]) {
+ int fd = open(path, O_RDONLY, 0);
+ if (-1 == fd)
+ return -1;
+
+ int result = futimens(fd, times);
+ close(fd);
+ return result;
}
// TODO(noelallen): Needs implementation.
return host_resolver_.getaddrinfo(node, service, hints, res);
}
+int KernelProxy::getnameinfo(const struct sockaddr *sa,
+ socklen_t salen,
+ char *host,
+ size_t hostlen,
+ char *serv,
+ size_t servlen,
+ int flags) {
+ return host_resolver_.getnameinfo(sa, salen, host, hostlen, serv, servlen,
+ flags);
+}
+
struct hostent* KernelProxy::gethostbyname(const char* name) {
return host_resolver_.gethostbyname(name);
}