]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/safe_io.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
18 #include "common/compiler_extensions.h"
19 #include <sys/types.h>
26 * Safe functions wrapping the raw read() and write() libc functions.
27 * These retry on EINTR, and on error return -errno instead of returning
28 * -1 and setting errno).
30 ssize_t
safe_read(int fd
, void *buf
, size_t count
)
32 ssize_t
safe_write(int fd
, const void *buf
, size_t count
)
34 ssize_t
safe_pread(int fd
, void *buf
, size_t count
, off_t offset
)
36 ssize_t
safe_pwrite(int fd
, const void *buf
, size_t count
, off_t offset
)
38 #ifdef CEPH_HAVE_SPLICE
40 * Similar to the above (non-exact version) and below (exact version).
41 * See splice(2) for parameter descriptions.
43 ssize_t
safe_splice(int fd_in
, off_t
*off_in
, int fd_out
, off_t
*off_out
,
44 size_t len
, unsigned int flags
)
46 ssize_t
safe_splice_exact(int fd_in
, off_t
*off_in
, int fd_out
,
47 off_t
*off_out
, size_t len
, unsigned int flags
)
52 * Same as the above functions, but return -EDOM unless exactly the requested
53 * number of bytes can be read.
55 ssize_t
safe_read_exact(int fd
, void *buf
, size_t count
)
57 ssize_t
safe_pread_exact(int fd
, void *buf
, size_t count
, off_t offset
)
62 * Safe functions to read and write an entire file.
64 int safe_write_file(const char *base
, const char *file
,
65 const char *val
, size_t vallen
);
66 int safe_read_file(const char *base
, const char *file
,
67 char *val
, size_t vallen
);