Coverage Report

Created: 2026-07-16 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/estoraged_shims/stdplus_fd_shim.hpp
Line
Count
Source
1
// Copyright 2026 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
17
#ifndef SHIM_STDPLUS_FD_HPP
18
#define SHIM_STDPLUS_FD_HPP
19
20
#include <span>
21
#include <cstddef>
22
#include <string>
23
#include <cstdint>
24
#include <linux/fs.h>
25
#include <stdexcept>
26
27
// Reopen boost::container to add the missing alias if needed
28
namespace boost {
29
namespace container {
30
using out_of_range = std::out_of_range;
31
}
32
}
33
34
namespace stdplus {
35
namespace fd {
36
37
enum class OpenAccess {
38
    ReadOnly,
39
    WriteOnly,
40
    ReadWrite
41
};
42
43
struct OpenFlags {
44
    OpenAccess access;
45
0
    OpenFlags(OpenAccess a) : access(a) {}
46
};
47
48
class Fd {
49
public:
50
0
    virtual ~Fd() = default;
51
    virtual std::span<const std::byte> write(std::span<const std::byte> data) = 0;
52
    virtual std::span<std::byte> read(std::span<std::byte> buf) = 0;
53
    virtual int ioctl(unsigned long request, void* data) = 0;
54
};
55
56
class ManagedFd : public Fd {
57
public:
58
0
    ManagedFd() = default;
59
    ManagedFd(ManagedFd&&) = default;
60
0
    ManagedFd& operator=(ManagedFd&&) = default;
61
62
0
    std::span<const std::byte> write(std::span<const std::byte> data) override { return data; }
63
0
    std::span<std::byte> read(std::span<std::byte> buf) override { 
64
0
        return buf; 
65
0
    }
66
0
    int ioctl(unsigned long request, void* data) override {
67
0
        if (request == BLKGETSIZE64) {
68
0
            *reinterpret_cast<uint64_t*>(data) = 1024 * 1024; // 1MB dummy size
69
0
        }
70
0
        return 0;
71
0
    }
72
0
    int get() const { return 0; }
73
};
74
75
0
inline ManagedFd open(const std::string&, OpenAccess) {
76
0
    return ManagedFd();
77
0
}
78
0
inline ManagedFd open(const std::string&, OpenFlags) {
79
0
    return ManagedFd();
80
0
}
81
0
inline ManagedFd open(const char*, OpenFlags) {
82
0
    return ManagedFd();
83
0
}
84
85
} // namespace fd
86
} // namespace stdplus
87
#endif