-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2020-present Daniel Trugman | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef PFS_BLOCK_QUEUE_HPP | ||
#define PFS_BLOCK_QUEUE_HPP | ||
|
||
#include "types.hpp" | ||
|
||
namespace pfs { | ||
|
||
// Hint: See 'https://www.kernel.org/doc/Documentation/block/queue-sysfs.txt' | ||
class block_queue final | ||
{ | ||
public: | ||
block_queue(const block_queue&) = default; | ||
block_queue(block_queue&&) = default; | ||
|
||
block_queue& operator=(const block_queue&) = delete; | ||
block_queue& operator=(block_queue&&) = delete; | ||
|
||
public: // Properties | ||
const std::string& dir() const; | ||
|
||
public: // Getters | ||
bool get_rotational() const; | ||
|
||
private: | ||
friend class block; | ||
block_queue(const std::string& block_root); | ||
|
||
private: | ||
static std::string build_block_queue_root(const std::string& block_root); | ||
|
||
private: | ||
static const std::string QUEUE_DIR; | ||
|
||
private: | ||
const std::string _block_queue_root; | ||
}; | ||
|
||
} // namespace pfs | ||
|
||
#endif // PFS_BLOCK_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2020-present Daniel Trugman | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <string> | ||
|
||
#include "pfs/defer.hpp" | ||
#include "pfs/parsers/common.hpp" | ||
#include "pfs/parsers/generic.hpp" | ||
#include "pfs/block_queue.hpp" | ||
|
||
namespace pfs { | ||
|
||
using namespace impl; | ||
|
||
const std::string block_queue::QUEUE_DIR("queue/"); | ||
|
||
block_queue::block_queue(const std::string& block_root) | ||
: _block_queue_root(build_block_queue_root(block_root)) | ||
{} | ||
|
||
std::string block_queue::build_block_queue_root(const std::string& block_root) | ||
{ | ||
return block_root + QUEUE_DIR; | ||
} | ||
|
||
const std::string& block_queue::dir() const | ||
{ | ||
return _block_queue_root; | ||
} | ||
|
||
bool block_queue::get_rotational() const | ||
{ | ||
static const std::string SIZE_FILE("rotational"); | ||
auto path = _block_queue_root + SIZE_FILE; | ||
|
||
auto value = utils::readline(path); | ||
|
||
int number; | ||
parsers::to_number(value, number, utils::base::decimal); | ||
return number != 0; | ||
} | ||
|
||
} // namespace pfs |