MCPcopy Create free account
hub / github.com/ceph/ceph / read_file

Method read_file

src/common/buffer.cc:1786–1829  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1784}
1785
1786int buffer::list::read_file(const char *fn, std::string *error)
1787{
1788 int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
1789 if (fd < 0) {
1790 int err = errno;
1791 std::ostringstream oss;
1792 oss << "can't open " << fn << ": " << cpp_strerror(err);
1793 *error = oss.str();
1794 return -err;
1795 }
1796
1797 struct stat st;
1798 // FIPS zeroization audit 20191115: this memset is not security related.
1799 memset(&st, 0, sizeof(st));
1800 if (::fstat(fd, &st) < 0) {
1801 int err = errno;
1802 std::ostringstream oss;
1803 oss << "bufferlist::read_file(" << fn << "): stat error: "
1804 << cpp_strerror(err);
1805 *error = oss.str();
1806 VOID_TEMP_FAILURE_RETRY(::close(fd));
1807 return -err;
1808 }
1809
1810 ssize_t ret = read_fd(fd, st.st_size);
1811 if (ret < 0) {
1812 std::ostringstream oss;
1813 oss << "bufferlist::read_file(" << fn << "): read error:"
1814 << cpp_strerror(ret);
1815 *error = oss.str();
1816 VOID_TEMP_FAILURE_RETRY(::close(fd));
1817 return ret;
1818 }
1819 else if (ret != st.st_size) {
1820 // Premature EOF.
1821 // Perhaps the file changed between stat() and read()?
1822 std::ostringstream oss;
1823 oss << "bufferlist::read_file(" << fn << "): warning: got premature EOF.";
1824 *error = oss.str();
1825 // not actually an error, but weird
1826 }
1827 VOID_TEMP_FAILURE_RETRY(::close(fd));
1828 return 0;
1829}
1830
1831ssize_t buffer::list::read_fd(int fd, size_t len)
1832{

Callers 15

mainFunction · 0.45
mainFunction · 0.45
get_auth_incFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
rewrite_transactionFunction · 0.45
update_mkfsFunction · 0.45
dupFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
do_encodeFunction · 0.45

Calls 2

cpp_strerrorFunction · 0.85
strMethod · 0.45

Tested by 2

TESTFunction · 0.36
run_checkMethod · 0.36