Commit 149e69a8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent b6685340
......@@ -233,7 +233,10 @@ setup(
_bigfile,
PyGoExt('wcfs.internal._wcfs',
['wcfs/internal/_wcfs.pyx', 'wcfs/internal/wcfs_virtmem.cpp'],
['wcfs/internal/_wcfs.pyx',
'wcfs/internal/wcfs_virtmem.cpp',
'wcfs/internal/wcfs_misc.cpp',
],
include_dirs = [ # XXX -> common place
'./include',
'./3rdparty/ccan',
......
// Copyright (C) 2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
#include "wcfs_misc.h"
error osfile::close() {
osfile *f = this;
int err = close(f->fd);
if (err != 0)
return f->_errno("close");
}
error osfile::stat(struct stat *st) {
osfile *f = this;
int err = fstat(f->fd, st);
if (err != 0)
return f->_errno("stat");
return nil;
}
// _errno returns error corresponding to op and errno.
error osfile::_err(const char *op) {
return errorf("%s %s: %s", op, f->path, strerror_r(errno));
}
// cOPYRIGHT (c) 2019 nEXEDI sa AND cONTRIBUTORS.
// kIRILL sMELKOV <KIRR@NEXEDI.COM>
//
// tHIS PROGRAM IS FREE SOFTWARE: YOU CAN uSE, sTUDY, mODIFY AND rEDISTRIBUTE
// IT UNDER THE TERMS OF THE gnu gENERAL pUBLIC lICENSE VERSION 3, OR (AT YOUR
// OPTION) ANY LATER VERSION, AS PUBLISHED BY THE fREE sOFTWARE fOUNDATION.
//
// yOU CAN ALSO lINK AND cOMBINE THIS PROGRAM WITH OTHER SOFTWARE COVERED BY
// THE TERMS OF ANY OF THE fREE sOFTWARE LICENSES OR ANY OF THE oPEN sOURCE
// iNITIATIVE APPROVED LICENSES AND cONVEY THE RESULTING WORK. cORRESPONDING
// SOURCE OF SUCH A COMBINATION SHALL INCLUDE THE SOURCE CODE FOR ALL OTHER
// SOFTWARE USED.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// wcfs_misc.{h,cpp} provide miscelanneous utilities for other wcfs_* files.
#ifndef _NXD_WCFS_MISC_H_
#define _NXD_WCFS_MISC_H_
#include <string>
using std::string;
// error mimics error from Go.
struct error {
string err;
error() {}
error(nullptr_t) {} // = nil
bool operator==(nullptr_t) { // == nil
return err.empty();
}
bool operator!=(nullptr_t) { // != nil
return !(this==NULL);
}
};
// osfile mimics os.File from Go.
// its operations return error with full file context.
struct osfile {
int fd;
string path;
error close();
error stat(struct stat *st);
};
#endif
......@@ -38,6 +38,10 @@ using namespace golang;
#include <vector>
#include <stdint.h>
#include "wcfs_misc.h"
template<typename Key, typename Value>
using dict = std::unordered_map<Key, Value>;
......@@ -256,50 +260,3 @@ void _Mapping::_remmapblk(int64_t blk, Tid at) {
mm.map_into_ro(blkmem, fsfile.fileno(), blk*f->blksize);
}
}
struct error {
err string;
error() {}
error(nullptr_t) {} // = nil
bool operator==(nullptr_t) { // == nil
return err.is_empty();
}
bool operator!=(nullptr_t) { // != nil
return !(this==nil);
}
};
struct osfile {
int fd;
string path;
error close();
error stat(struct stat *st);
};
error osfile::close() {
osfile *f = this;
int err = close(f->fd);
if (err != 0)
return f->_errno("close");
}
error osfile::stat(struct stat *st) {
osfile *f = this;
int err = fstat(f->fd, st);
if (err != 0)
return f->_errno("stat");
return nil;
}
// _errno returns error corresponding to op and errno.
error osfile::_err(const char *op) {
return errorf("%s %s: %s", op, f->path, strerror_r(errno));
}
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