Commit fc4ab83b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1264e9fa
......@@ -19,16 +19,18 @@
#include "wcfs_misc.h"
error osfile::close() {
osfile *f = this;
namespace os {
error File::close() {
File *f = this;
int err = close(f->fd);
if (err != 0)
return f->_errno("close");
}
error osfile::stat(struct stat *st) {
osfile *f = this;
error File::stat(struct stat *st) {
File *f = this;
int err = fstat(f->fd, st);
if (err != 0)
......@@ -38,7 +40,8 @@ error osfile::stat(struct stat *st) {
// _errno returns error corresponding to op and errno.
error osfile::_err(const char *op) {
error File::_err(const char *op) {
return errorf("%s %s: %s", op, f->path, strerror_r(errno));
}
} // os::
......@@ -39,9 +39,11 @@ struct error {
}
};
// osfile mimics os.File from Go.
namespace os {
// os::File mimics os.File from Go.
// its operations return error with full file context.
struct osfile {
struct File {
int fd;
string path;
......@@ -49,4 +51,8 @@ struct osfile {
error stat(struct stat *st);
};
// XXX tuple<File, error> open(const string &path)
} // os::
#endif
......@@ -36,6 +36,10 @@ using namespace golang;
#include <unordered_map>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdint.h>
......@@ -93,10 +97,10 @@ private:
//
// XXX doc
struct _File {
Conn *wconn;
Oid foid; // hex of ZBigFile root object ID
size_t blksize; // block size of this file
// .headf file object of head/file
Conn *wconn;
Oid foid; // hex of ZBigFile root object ID
size_t blksize; // block size of this file
os::File headf; // file object of head/file
// .headfsize head/file size is known to be at least headfsize (size ↑=)
dict<int64_t, Tid> pinned; // {} blk -> rev that wcfs already sent us for this file
vector<_Mapping*> mmaps; // []_Mapping ↑blk_start mappings of this file
......@@ -235,18 +239,18 @@ void _Mapping::_remmapblk(int64_t blk, Tid at) {
_File *f = mmap->file;
uint8_t *blkmem = mmap->mem_start + (blk - mmap->blk_start)*f->blksize;
osfile fsfile;
os::File fsfile;
if (at == TidHead) {
fsfile = f->headf;
}
else {
// TODO share @rev fd until wconn is resynced?
fsfile = f->wconn->_wc._open("@%s/bigfile/%s" % (h(at), h(f->foid)), "rb")
fsfile = f->wconn->_wc->_open("@%s/bigfile/%s" % (h(at), h(f->foid)), "rb")
defer(fsfile.close)
}
struct stat st;
err = fsfile.stat(&st);
auto err = fsfile.stat(&st);
if (err != nil)
return err;
ASSERT(st.st_blksize == f->blksize); // FIXME assert
......@@ -257,6 +261,6 @@ void _Mapping::_remmapblk(int64_t blk, Tid at) {
}
// block is inside file - mmap file data
else {
mm.map_into_ro(blkmem, fsfile.fileno(), blk*f->blksize);
mm.map_into_ro(blkmem, fsfile.fd, blk*f->blksize);
}
}
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