DebugServer2
Loading...
Searching...
No Matches
File.h
1//
2// Copyright (c) 2014-present, Facebook, Inc.
3// All rights reserved.
4//
5// This source code is licensed under the University of Illinois/NCSA Open
6// Source License found in the LICENSE file in the root directory of this
7// source tree. An additional grant of patent rights can be found in the
8// PATENTS file in the same directory.
9//
10
11#pragma once
12
13#include "DebugServer2/Base.h"
14#include "DebugServer2/Constants.h"
15#include "DebugServer2/Types.h"
16#include "DebugServer2/Utils/Log.h"
17
18#include <string>
19#include <utility>
20
21namespace ds2 {
22namespace Host {
23
24class File {
25public:
26 File(std::string const &path, OpenFlags flags, uint32_t mode);
27 ~File();
28
29public:
30 File(const File &other) = delete;
31 File &operator=(const File &other) = delete;
32
33public:
34 File(File &&other) : _fd(-1), _lastError(kErrorInvalidHandle) {
35 *this = std::move(other);
36 }
37
38 File &operator=(File &&other) {
39 DS2ASSERT(&other != this);
40
41 std::swap(_fd, other._fd);
42 std::swap(_lastError, other._lastError);
43
44 return *this;
45 }
46
47public:
48 ErrorCode pread(ByteVector &buf, uint64_t &count, uint64_t offset);
49 ErrorCode pwrite(ByteVector const &buf, uint64_t &count, uint64_t offset);
50 ErrorCode fstat(ByteVector &buffer) const;
51
52public:
53 bool valid() const { return (_fd >= 0); }
54 ErrorCode lastError() const { return _lastError; }
55
56public:
57 static ErrorCode chmod(std::string const &path, uint32_t mode);
58
59public:
60 static ErrorCode unlink(std::string const &path);
61
62public:
63 static ErrorCode createDirectory(std::string const &path, uint32_t flags);
64
65public:
66 static ErrorCode fileSize(std::string const &path, uint64_t &size);
67 static ErrorCode fileMode(std::string const &path, uint32_t &mode);
68
69protected:
70 int _fd;
71 ErrorCode _lastError;
72};
73} // namespace Host
74} // namespace ds2
Definition File.h:24