Commit cdbb8ac5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e25dd198
......@@ -23,16 +23,16 @@
namespace os {
tuple<File, error> open(const string &path, int flags, mode_t mode) {
File f = {.fd = -1, path = path};
File f = {._fd = -1, .path = path};
int err = std::open(path.c_str(), flags, mode);
if (err != 0)
return f, f._errno("open");
return make_tuple(f, f._errno("open"));
}
error File::close() {
File *f = this;
int err = close(f->fd);
int err = close(f->_fd);
if (err != 0)
return f->_errno("close");
}
......@@ -40,7 +40,7 @@ error File::close() {
error File::stat(struct stat *st) {
File *f = this;
int err = fstat(f->fd, st);
int err = fstat(f->_fd, st);
if (err != 0)
return f->_errno("stat");
return nil;
......@@ -48,7 +48,8 @@ error File::stat(struct stat *st) {
// _errno returns error corresponding to op and errno.
error File::_err(const char *op) {
error File::_errno(const char *op) {
File *f = this;
return errorf("%s %s: %s", op, f->path, strerror_r(errno));
}
......
......@@ -27,6 +27,7 @@ using std::string;
#include <tuple>
using std::tuple;
using std::make_tuple;
using std::tie;
// nil is synonim for nullptr and NULL.
......@@ -60,11 +61,15 @@ class File {
string _path;
public:
friend open...
// XXX empty ctor -> fd=-1, path=?
int fd();
string name();
error close();
error stat(struct stat *st);
private:
error _errno(const char *op);
};
// open opens file @path.
......
......@@ -271,6 +271,7 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
return err;
ASSERT(st.st_blksize == f->blksize); // FIXME assert
#if 0
// block is beyond file size - mmap with zeros (assumes head/f size ↑=)
if ((blk+1)*f->blksize > st.st_size) {
mm.map_zero_into_ro(blkmem); // XXX err
......@@ -279,6 +280,7 @@ error _Mapping::_remmapblk(int64_t blk, Tid at) {
else {
mm.map_into_ro(blkmem, fsfile.fd, blk*f->blksize); // XXX err
}
#endif
return nil;
}
......
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