2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 #ifndef __BLOCK_DEVICE_H__
18 #define __BLOCK_DEVICE_H__
20 #include <unordered_map>
23 #include <sys/ioctl.h>
24 #include <sys/types.h>
31 #include <klay/filesystem.h>
37 template <typename OffsetType, typename LengthType>
38 Block(OffsetType offset, LengthType len) : physicalOffset(offset), length(len) {}
41 unsigned long long physicalOffset;
42 unsigned long long length;
45 class BlockDevice final {
47 typedef std::unordered_map<std::string, std::string> DeviceList;
48 typedef DeviceList::const_iterator DeviceListIterator;
50 BlockDevice(const std::string &path);
51 BlockDevice(const BlockDevice &) = delete;
52 BlockDevice(BlockDevice &&) = delete;
55 BlockDevice &operator=(const BlockDevice &) = delete;
56 BlockDevice &operator=(BlockDevice &&) = delete;
59 void close(int descriptor);
61 int discard(const Block &block);
62 int secDiscard(const Block &block);
64 const std::string &getName() const;
68 void createDeviceList();
69 void evaluateDevice(const std::string &path);
75 DeviceList deviceList;
80 #endif /* __BLOCK_DEVICE_H__ */