Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / 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
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2011 New Dream Network
7  *
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.
12  *
13  */
14
15 #ifndef CEPH_SAFE_IO
16 #define CEPH_SAFE_IO
17
18 #include "common/compiler_extensions.h"
19 #include <sys/types.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25   /*
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).
29    */
30   ssize_t safe_read(int fd, void *buf, size_t count)
31       WARN_UNUSED_RESULT;
32   ssize_t safe_write(int fd, const void *buf, size_t count)
33       WARN_UNUSED_RESULT;
34   ssize_t safe_pread(int fd, void *buf, size_t count, off_t offset)
35       WARN_UNUSED_RESULT;
36   ssize_t safe_pwrite(int fd, const void *buf, size_t count, off_t offset)
37       WARN_UNUSED_RESULT;
38 #ifdef CEPH_HAVE_SPLICE
39   /*
40    * Similar to the above (non-exact version) and below (exact version).
41    * See splice(2) for parameter descriptions.
42    */
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)
45     WARN_UNUSED_RESULT;
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)
48     WARN_UNUSED_RESULT;
49 #endif
50
51   /*
52    * Same as the above functions, but return -EDOM unless exactly the requested
53    * number of bytes can be read.
54    */
55   ssize_t safe_read_exact(int fd, void *buf, size_t count)
56       WARN_UNUSED_RESULT;
57   ssize_t safe_pread_exact(int fd, void *buf, size_t count, off_t offset)
58       WARN_UNUSED_RESULT;
59
60
61   /*
62    * Safe functions to read and write an entire file.
63    */
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);
68
69 #ifdef __cplusplus
70 }
71 #endif
72
73 #endif