Пример #1
0
	virtual status_t IO(off_t offset, void* buffer, size_t* length)
	{
		iovec vec;
		vec.iov_base = buffer;
		vec.iov_len = *length;

		if (fWrite) {
			return FS_CALL(fVnode, write_pages, fCookie, offset, &vec, 1,
				length);
		}

		return FS_CALL(fVnode, read_pages, fCookie, offset, &vec, 1, length);
	}
Пример #2
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_write(lua_State* L) {
  uv_file file = luaL_checkinteger(L, 1);
  uv_buf_t buf;
  int64_t offset;
  int ref;
  uv_fs_t* req;
  size_t count;
  uv_buf_t *bufs = NULL;

  if (lua_istable(L, 2)) {
    bufs = luv_prep_bufs(L, 2, &count);
  }
  else if (lua_isstring(L, 2)) {
    luv_check_buf(L, 2, &buf);
    count = 1;
  }
  else {
    return luaL_argerror(L, 2, "data must be string or table of strings");
  }

  offset = luaL_checkinteger(L, 3);
  ref = luv_check_continuation(L, 4);
  req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  req->ptr = buf.base;
  ((luv_req_t*)req->data)->data = bufs;
  FS_CALL(write, req, file, bufs ? bufs : &buf, count, offset);
}
Пример #3
0
int luv_fs_symlink(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  const char* new_path = luaL_checkstring(L, 2);
  int flags = luv_string_to_flags(L, luaL_checkstring(L, 3));
  uv_fs_t* req = luv_fs_store_callback(L, 4);
  FS_CALL(symlink, 4, new_path, path, new_path, flags);
}
Пример #4
0
int luv_fs_chown(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  int uid = luaL_checkint(L, 2);
  int gid = luaL_checkint(L, 3);
  uv_fs_t* req = luv_fs_store_callback(L, 4);
  FS_CALL(chown, 4, path, path, uid, gid);
}
Пример #5
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_mkdtemp(lua_State* L) {
  const char* tpl = luaL_checkstring(L, 1);
  int ref = luv_check_continuation(L, 2);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(mkdtemp, req, tpl);
}
Пример #6
0
int luv_fs_futime(lua_State* L) {
  uv_file file = luaL_checkint(L, 1);
  double atime = luaL_checknumber(L, 2);
  double mtime = luaL_checknumber(L, 3);
  uv_fs_t* req = luv_fs_store_callback(L, 4);
  FS_CALL(futime, 4, NULL, file, atime, mtime);
}
Пример #7
0
int luv_fs_open(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  int flags = luv_string_to_flags(L, luaL_checkstring(L, 2));
  int mode = luaL_checkint(L, 3);
  uv_fs_t* req = luv_fs_store_callback(L, 4);
  FS_CALL(open, 4, path, path, flags, mode);
}
Пример #8
0
int luv_fs_fchown(lua_State* L) {
  uv_file file = luaL_checkint(L, 1);
  int uid = luaL_checkint(L, 2);
  int gid = luaL_checkint(L, 3);
  uv_fs_t* req = luv_fs_store_callback(L, 4);
  FS_CALL(fchown, 4, NULL, file, uid, gid);
}
Пример #9
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_readlink(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  int ref = luv_check_continuation(L, 2);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(readlink, req, path);
}
Пример #10
0
int luv_fs_utime(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  double atime = luaL_checknumber(L, 2);
  double mtime = luaL_checknumber(L, 3);
  uv_fs_t* req = luv_fs_store_callback(L, 4);
  FS_CALL(utime, 4, path, path, atime, mtime);
}
Пример #11
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_fdatasync(lua_State* L) {
  uv_file file = luaL_checkinteger(L, 1);
  int ref = luv_check_continuation(L, 2);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(fdatasync, req, file);
}
Пример #12
0
Файл: luv_fs.c Проект: nko/luvit
int luv_fs_write(lua_State* L) {
    uv_file file = luaL_checkint(L, 1);
    off_t offset = luaL_checkint(L, 2);
    size_t length;
    void* chunk = (void*)luaL_checklstring(L, 3, &length);
    uv_fs_t* req = luv_fs_store_callback(L, 4);
    FS_CALL(write, 4, NULL, file, chunk, length, offset);
}
Пример #13
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_chmod(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  int mode = luaL_checkinteger(L, 2);
  int ref = luv_check_continuation(L, 3);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(chmod, req, path, mode);
}
Пример #14
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_access(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  int amode = luv_check_amode(L, 2);
  int ref = luv_check_continuation(L, 3);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(access, req, path, amode);
}
Пример #15
0
int luv_fs_sendfile(lua_State* L) {
  uv_file out_fd = luaL_checkint(L, 1);
  uv_file in_fd = luaL_checkint(L, 2);
  off_t in_offset = luaL_checkint(L, 3);
  size_t length = luaL_checkint(L, 4);
  uv_fs_t* req = luv_fs_store_callback(L, 5);
  FS_CALL(sendfile, 5, NULL, out_fd, in_fd, in_offset, length);
}
Пример #16
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_ftruncate(lua_State* L) {
  uv_file file = luaL_checkinteger(L, 1);
  int64_t offset = luaL_checkinteger(L, 2);
  int ref = luv_check_continuation(L, 3);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(ftruncate, req, file, offset);
}
Пример #17
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_scandir(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  int flags = 0; // TODO: find out what these flags are.
  int ref = luv_check_continuation(L, 2);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(scandir, req, path, flags);
}
Пример #18
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_fchown(lua_State* L) {
  uv_file file = luaL_checkinteger(L, 1);
  uv_uid_t uid = luaL_checkinteger(L, 2);
  uv_uid_t gid = luaL_checkinteger(L, 3);
  int ref = luv_check_continuation(L, 4);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(fchown, req, file, uid, gid);
}
Пример #19
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_chown(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  uv_uid_t uid = luaL_checkinteger(L, 2);
  uv_uid_t gid = luaL_checkinteger(L, 3);
  int ref = luv_check_continuation(L, 4);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(chown, req, path, uid, gid);
}
Пример #20
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_futime(lua_State* L) {
  uv_file file = luaL_checkinteger(L, 1);
  double atime = luaL_checknumber(L, 2);
  double mtime = luaL_checknumber(L, 3);
  int ref = luv_check_continuation(L, 4);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(futime, req, file, atime, mtime);
}
Пример #21
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_utime(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  double atime = luaL_checknumber(L, 2);
  double mtime = luaL_checknumber(L, 3);
  int ref = luv_check_continuation(L, 4);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(utime, req, path, atime, mtime);
}
Пример #22
0
Файл: luv_fs.c Проект: nko/luvit
int luv_fs_read(lua_State* L) {
    uv_file file = luaL_checkint(L, 1);
    int offset = luaL_checkint(L, 2);
    int length = luaL_checkint(L, 3);
    uv_fs_t* req = luv_fs_store_callback(L, 4);
    void* buf = malloc(length);
    ((luv_fs_ref_t*)req->data)->buf = buf;
    FS_CALL(read, 4, NULL, file, buf, length, offset);
}
Пример #23
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_sendfile(lua_State* L) {
  uv_file out_fd = luaL_checkinteger(L, 1);
  uv_file in_fd = luaL_checkinteger(L, 2);
  int64_t in_offset = luaL_checkinteger(L, 3);
  size_t length = luaL_checkinteger(L, 4);
  int ref = luv_check_continuation(L, 5);
  uv_fs_t* req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  FS_CALL(sendfile, req, out_fd, in_fd, in_offset, length);
}
Пример #24
0
status_t
vfs_vnode_io(struct vnode* vnode, void* cookie, io_request* request)
{
	status_t result = B_ERROR;
	if (!HAS_FS_CALL(vnode, io)
		|| (result = FS_CALL(vnode, io, cookie, request)) == B_UNSUPPORTED) {
		// no io() call -- fall back to synchronous I/O
		VnodeIO io(request->IsWrite(), vnode, cookie);
		return synchronous_io(request, io);
	}

	return result;
}
Пример #25
0
int luv_fs_write(lua_State* L) {
  uv_file file = luaL_checkint(L, 1);
  off_t offset = luaL_checkint(L, 2);
  size_t length;
  uv_fs_t* req;
  void* chunk = (void*)luaL_checklstring(L, 3, &length);
  luv_fs_ref_t* ref = luv_fs_ref_alloc(L);
  luv_io_ctx_init(&ref->cbs);
  luv_io_ctx_add(L, &ref->cbs, 3);
  luv_io_ctx_callback_add(L, &ref->cbs, 4);
  req = &ref->fs_req;
  FS_CALL(write, 4, NULL, file, chunk, length, offset);
}
Пример #26
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_read(lua_State* L) {
  uv_file file = luaL_checkinteger(L, 1);
  int64_t len = luaL_checkinteger(L, 2);
  int64_t offset = luaL_checkinteger(L, 3);
  uv_buf_t buf;
  int ref;
  uv_fs_t* req;
  char* data = malloc(len);
  if (!data) return luaL_error(L, "Failure to allocate buffer");
  buf = uv_buf_init(data, len);
  ref = luv_check_continuation(L, 4);
  req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);
  // TODO: find out why we can't just use req->ptr for the base
  ((luv_req_t*)req->data)->data = buf.base;
  FS_CALL(read, req, file, &buf, 1, offset);
}
Пример #27
0
Файл: fs.c Проект: kidaa/luv
static int luv_fs_symlink(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  const char* new_path = luaL_checkstring(L, 2);
  int flags = 0, ref;
  uv_fs_t* req;
  if (lua_type(L, 3) == LUA_TTABLE) {
    lua_getfield(L, 3, "dir");
    if (lua_toboolean(L, -1)) flags |= UV_FS_SYMLINK_DIR;
    lua_pop(L, 1);
    lua_getfield(L, 3, "junction");
    if (lua_toboolean(L, -1)) flags |= UV_FS_SYMLINK_JUNCTION;
    lua_pop(L, 1);
  }
  ref = luv_check_continuation(L, 4);
  req = lua_newuserdata(L, sizeof(*req));
  req->data = luv_setup_req(L, ref);

  FS_CALL(symlink, req, path, new_path, flags);
}
Пример #28
0
int luv_fs_read(lua_State* L) {
  uv_file file = luaL_checkint(L, 1);
  int offset = -1;
  int length;
  uv_fs_t* req;
  void* buf;
  if (!lua_isnil(L, 2)) {
    offset = luaL_checkint(L, 2);
  }
  length = luaL_checkint(L, 3);
  req = luv_fs_store_callback(L, 4);
  buf = malloc(length);
  ((luv_fs_ref_t*)req->data)->buf = buf;
  
  uv_buf_t bufs[1];
  bufs[0].base = buf;
  bufs[0].len = length;
  
  FS_CALL(read, 4, NULL, file, bufs, 1, offset);
}
Пример #29
0
int luv_fs_fchmod(lua_State* L) {
  uv_file file = luaL_checkint(L, 1);
  int mode = strtoul(luaL_checkstring(L, 2), NULL, 8);
  uv_fs_t* req = luv_fs_store_callback(L, 3);
  FS_CALL(fchmod, 3, NULL, file, mode);
}
Пример #30
0
int luv_fs_readlink(lua_State* L) {
  const char* path = luaL_checkstring(L, 1);
  uv_fs_t* req = luv_fs_store_callback(L, 2);
  FS_CALL(readlink, 2, path, path);
}