Commit fc4ab83b authored by Kirill Smelkov's avatar Kirill Smelkov

.

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