FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
safs_header.h
1 #ifndef __SAFS_HEADER_H__
2 #define __SAFS_HEADER_H__
3 
4 /*
5  * Copyright 2015 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of SAFSlib.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "io_request.h"
24 
25 namespace safs
26 {
27 
28 class safs_header
29 {
30  static const int64_t MAGIC_NUMBER = 0x123456789FFFFFEL;
31  static const int CURR_VERSION = 1;
32 
33  int64_t magic_number;
34  int version_number;
35  // In the number of pages.
36  uint32_t block_size;
37  uint32_t mapping_option;
38  uint32_t writable;
39  uint64_t num_bytes;
40 public:
41  static size_t get_header_size() {
42  return PAGE_SIZE;
43  }
44 
45  safs_header() {
46  this->magic_number = MAGIC_NUMBER;
47  this->version_number = CURR_VERSION;
48  this->block_size = 0;
49  this->mapping_option = 0;
50  this->writable = false;
51  this->num_bytes = 0;
52  }
53 
54  safs_header(int block_size, int mapping_option, bool writable,
55  size_t file_size) {
56  this->magic_number = MAGIC_NUMBER;
57  this->version_number = CURR_VERSION;
58  this->block_size = block_size;
59  this->mapping_option = mapping_option;
60  this->writable = writable;
61  this->num_bytes = file_size;
62  }
63 
64  int get_block_size() const {
65  return block_size;
66  }
67 
68  int get_mapping_option() const {
69  return mapping_option;
70  }
71 
72  bool is_writable() const {
73  return writable;
74  }
75 
76  bool is_safs_file() const {
77  return magic_number == MAGIC_NUMBER;
78  }
79 
80  bool is_right_version() const {
81  return version_number == CURR_VERSION;
82  }
83 
84  bool is_valid() const {
85  return block_size != 0;
86  }
87 
88  void resize(size_t new_size) {
89  this->num_bytes = new_size;
90  }
91 
92  size_t get_size() const {
93  return num_bytes;
94  }
95 };
96 
97 }
98 
99 #endif