Add SDcard password confirm popup
[platform/core/security/ode.git] / server / block-device.h
1 /*
2  *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License
15  */
16
17 #ifndef __BLOCK_DEVICE_H__
18 #define __BLOCK_DEVICE_H__
19
20 #include <unordered_map>
21 #include <fstream>
22
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 #include <limits.h>
28 #include <unistd.h>
29 #include <linux/fs.h>
30
31 #include <klay/filesystem.h>
32
33 namespace ode {
34
35 class Block {
36 public:
37         template <typename OffsetType, typename LengthType>
38         Block(OffsetType offset, LengthType len) : physicalOffset(offset), length(len) {}
39         ~Block() {}
40
41         unsigned long long physicalOffset;
42         unsigned long long length;
43 };
44
45 class BlockDevice final {
46 public:
47         typedef std::unordered_map<std::string, std::string> DeviceList;
48         typedef DeviceList::const_iterator DeviceListIterator;
49
50         BlockDevice(const std::string &path);
51         BlockDevice(const BlockDevice &) = delete;
52         BlockDevice(BlockDevice &&) = delete;
53         ~BlockDevice();
54
55         BlockDevice &operator=(const BlockDevice &) = delete;
56         BlockDevice &operator=(BlockDevice &&) = delete;
57
58         int open(int flags);
59         void close(int descriptor);
60
61         int discard(const Block &block);
62         int secDiscard(const Block &block);
63
64         const std::string &getName() const;
65         int getSize();
66
67 private:
68         void createDeviceList();
69         void evaluateDevice(const std::string &path);
70
71 private:
72         std::string name;
73         int blockSize;
74
75         DeviceList deviceList;
76 };
77
78 } // namespace ode
79
80 #endif /* __BLOCK_DEVICE_H__ */