Commit cdbb8ac5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

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