0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Filesystem.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
32 #ifndef Common_Filesystem_h
33 #define Common_Filesystem_h
34 
36 
37 #include <Common/Serializable.h>
38 #include <Common/String.h>
39 #include <Common/StaticBuffer.h>
40 #include <Common/Status.h>
41 #include <Common/Timer.h>
42 
43 #include <memory>
44 #include <string>
45 #include <vector>
46 
47 using namespace std;
48 
49 #define HT_DIRECT_IO_ALIGNMENT 512
50 
51 #define HT_IO_ALIGNED(size) \
52  (((size) % HT_DIRECT_IO_ALIGNMENT) == 0)
53 
54 #define HT_IO_ALIGNMENT_PADDING(size) \
55  (HT_DIRECT_IO_ALIGNMENT - ((size) % HT_DIRECT_IO_ALIGNMENT))
56 
57 namespace Hypertable {
58 
61 
72  class Filesystem {
73  public:
74 
76  enum class Flags : uint8_t {
78  NONE=0,
80  FLUSH=1,
82  SYNC=2
83  };
84 
85  enum OpenFlags {
86  OPEN_FLAG_DIRECTIO = 0x00000001,
87  OPEN_FLAG_OVERWRITE = 0x00000002,
88  OPEN_FLAG_VERIFY_CHECKSUM = 0x00000004
89  };
90 
92  class Dirent : public Serializable {
93 
94  public:
98  uint64_t length {};
100  time_t last_modification_time {};
102  bool is_dir {};
103 
104  private:
105 
106  uint8_t encoding_version() const override;
107 
108  size_t encoded_length_internal() const override;
109 
110  void encode_internal(uint8_t **bufp) const override;
111 
112  void decode_internal(uint8_t version, const uint8_t **bufp,
113  size_t *remainp) override;
114 
115  };
116 
117  virtual ~Filesystem() { }
118 
128  virtual void open(const String &name, uint32_t flags,
129  DispatchHandler *handler) = 0;
130 
137  virtual int open(const String &name, uint32_t flags) = 0;
138 
151  virtual int open_buffered(const String &name, uint32_t flags,
152  uint32_t buf_size, uint32_t outstanding, uint64_t start_offset = 0,
153  uint64_t end_offset = 0) = 0;
154 
158  virtual void decode_response_open(EventPtr &event, int32_t *fd) = 0;
159 
173  virtual void create(const String &name, uint32_t flags, int32_t bufsz,
174  int32_t replication, int64_t blksz, DispatchHandler *handler) = 0;
175 
185  virtual int create(const String &name, uint32_t flags, int32_t bufsz,
186  int32_t replication, int64_t blksz) = 0;
187 
191  virtual void decode_response_create(EventPtr &event, int32_t *fd) = 0;
192 
201  virtual void close(int fd, DispatchHandler *handler) = 0;
202 
210  virtual void close(int fd) = 0;
211 
223  virtual void read(int fd, size_t len, DispatchHandler *handler) = 0;
224 
236  virtual size_t read(int fd, void *dst, size_t len) = 0;
237 
243  virtual void decode_response_read(EventPtr &event, const void **buffer,
244  uint64_t *offset, uint32_t *length) = 0;
245 
256  virtual void append(int fd, StaticBuffer &buffer, Flags flags,
257  DispatchHandler *handler) = 0;
258 
269  virtual size_t append(int fd, StaticBuffer &buffer, Flags flags = Flags::NONE) = 0;
270 
277  virtual void decode_response_append(EventPtr &event, uint64_t *offset,
278  uint32_t *length) = 0;
279 
289  virtual void seek(int fd, uint64_t offset, DispatchHandler *handler) = 0;
290 
299  virtual void seek(int fd, uint64_t offset) = 0;
300 
308  virtual void remove(const String &name, DispatchHandler *handler) = 0;
309 
316  virtual void remove(const String &name, bool force = true) = 0;
317 
327  virtual void length(const String &name, bool accurate,
328  DispatchHandler *handler) = 0;
329 
337  virtual int64_t length(const String &name, bool accurate = true) = 0;
338 
342  virtual int64_t decode_response_length(EventPtr &event) = 0;
343 
356  virtual void pread(int fd, size_t amount, uint64_t offset,
357  bool verify_checksum, DispatchHandler *handler) = 0;
358 
372  virtual size_t pread(int fd, void *dst, size_t len, uint64_t offset,
373  bool verify_checksum = true) = 0;
374 
380  virtual void decode_response_pread(EventPtr &event, const void **buffer,
381  uint64_t *offset, uint32_t *length) = 0;
382 
391  virtual void mkdirs(const String &name, DispatchHandler *handler) = 0;
392 
398  virtual void mkdirs(const String &name) = 0;
399 
407  virtual void rmdir(const String &name, DispatchHandler *handler) = 0;
408 
415  virtual void rmdir(const String &name, bool force = true) = 0;
416 
424  virtual void readdir(const String &name, DispatchHandler *handler) = 0;
425 
432  virtual void readdir(const String &name, std::vector<Dirent> &listing) = 0;
433 
437  virtual void decode_response_readdir(EventPtr &event,
438  std::vector<Dirent> &listing) = 0;
439 
449  virtual void flush(int fd, DispatchHandler *handler) = 0;
450 
463  virtual void flush(int fd) = 0;
464 
472  virtual void sync(int fd) = 0;
473 
481  virtual void exists(const String &name, DispatchHandler *handler) = 0;
482 
488  virtual bool exists(const String &name) = 0;
489 
493  virtual bool decode_response_exists(EventPtr &event) = 0;
494 
500  virtual void rename(const String &src, const String &dst,
501  DispatchHandler *handler) = 0;
502 
508  virtual void rename(const String &src, const String &dst) = 0;
509 
514  virtual void status(Status &status, Timer *timer=0) = 0;
515 
519  virtual void decode_response_status(EventPtr &event, Status &status) = 0;
520 
526  static int decode_response(EventPtr &event);
527 
533  virtual void debug(int32_t command,
534  StaticBuffer &serialized_parameters) = 0;
535 
542  virtual void debug(int32_t command, StaticBuffer &serialized_parameters,
543  DispatchHandler *handler) = 0;
544 
556  static String dirname(String name, char separator = '/');
557 
568  static String basename(String name, char separator = '/');
569  };
570 
572  typedef std::shared_ptr<Filesystem> FilesystemPtr;
573 
574  inline bool operator< (const Filesystem::Dirent& lhs,
575  const Filesystem::Dirent& rhs) {
576  return lhs.name.compare(rhs.name) < 0;
577  }
578 
584  extern Filesystem::Flags convert(std::string str);
585 
587 
588 } // namespace Hypertable
589 
590 #endif // Common_Filesystem_h
591 
A memory buffer of static size.
Definition: StaticBuffer.h:45
static PyObject * convert(const SerializedCellsWriter &scw)
Holds Nagios-style program status information.
Definition: Status.h:42
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Declarations for Status.
Abstract base class for application dispatch handlers registered with AsyncComm.
Flags
Enumeration type for append flags.
Definition: Filesystem.h:76
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
STL namespace.
bool operator<(const Filesystem::Dirent &lhs, const Filesystem::Dirent &rhs)
Definition: Filesystem.h:574
Declarations for DispatchHandler.
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
Definition: Utility.cc:408
A timer class to keep timeout states across AsyncComm related calls.
A memory buffer of static size.
Declarations for Serializable.
Hypertable definitions
Flags
Enumeration for poll interest constants.
Definition: PollEvent.h:40
Mixin class that provides a standard serialization interface.
Definition: Serializable.h:65
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
Definition: Filesystem.h:572
String name
File or directory name.
Definition: Filesystem.h:96
A timer class to keep timeout states across AsyncComm related calls.
Definition: Timer.h:44
A String class based on std::string.
Abstract base class for a filesystem.
Definition: Filesystem.h:72