FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
read_private.h
1 #ifndef __READ_PRIVATE_H__
2 #define __READ_PRIVATE_H__
3 
4 /*
5  * Copyright 2014 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 <sys/time.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 
28 #include "io_interface.h"
29 #include "file_partition.h"
30 #include "parameters.h"
31 
32 namespace safs
33 {
34 
35 class buffered_io: public io_interface
36 {
37  logical_file_partition partition;
38  /* the array of files that it's going to access */
39  std::vector<int> fds;
40 
41  int flags;
42 public:
43  buffered_io(const logical_file_partition &partition_,
44  thread *t, const safs_header &header, int flags = O_RDWR);
45 
46  virtual ~buffered_io() {
47  for (unsigned i = 0; i < fds.size(); i++)
48  BOOST_VERIFY(close(fds[i]) == 0);
49  }
50 
51  /* get the file descriptor corresponding to the offset. */
52  int get_fd(long offset) {
53  if (fds.size() == 1)
54  return fds[0];
55 
56  int idx = partition.map2file(offset / PAGE_SIZE);
57  return fds[idx];
58  }
59 
60  const std::vector<int> &get_fds() const {
61  return fds;
62  }
63 
64  int num_open_files() {
65  return partition.get_num_files();
66  }
67 
68  const logical_file_partition &get_partition() const {
69  return partition;
70  }
71 
72  int get_file_id() const {
73  return partition.get_file_id();
74  }
75 
76  void cleanup() {
77  for (size_t i = 0; i < fds.size(); i++)
78  fsync(fds[i]);
79  }
80 
81  io_status access(char *buf, off_t offset, ssize_t size, int access_method);
82 };
83 
84 }
85 
86 #endif
virtual void access(io_request *requests, int num, io_status *status=NULL)
Definition: io_interface.h:276