2016-05-12 23:43:17 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-05-12 23:43:17 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2016-05-12 23:43:17 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
#pragma once
|
|
|
|
#include <folly/Range.h>
|
|
|
|
#include <sys/stat.h>
|
2018-03-20 03:01:15 +03:00
|
|
|
#include <memory>
|
2017-04-14 21:31:48 +03:00
|
|
|
#include "eden/fs/utils/DirType.h"
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for populating directory listings.
|
|
|
|
*/
|
|
|
|
class DirList {
|
|
|
|
std::unique_ptr<char[]> buf_;
|
|
|
|
char* end_;
|
|
|
|
char* cur_;
|
|
|
|
|
|
|
|
public:
|
2018-12-05 12:32:48 +03:00
|
|
|
struct ExtractedEntry {
|
|
|
|
std::string name;
|
|
|
|
ino_t inode;
|
|
|
|
dtype_t type;
|
|
|
|
off_t offset;
|
|
|
|
};
|
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
explicit DirList(size_t maxSize);
|
|
|
|
|
|
|
|
DirList(const DirList&) = delete;
|
|
|
|
DirList& operator=(const DirList&) = delete;
|
|
|
|
DirList(DirList&&) = default;
|
|
|
|
DirList& operator=(DirList&&) = default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new dirent to the list.
|
|
|
|
* Returns true on success or false if the list is full.
|
2016-08-25 03:01:41 +03:00
|
|
|
*/
|
|
|
|
bool add(folly::StringPiece name, ino_t inode, dtype_t type, off_t off);
|
|
|
|
|
2018-12-05 12:32:48 +03:00
|
|
|
folly::StringPiece getBuf() const;
|
|
|
|
|
2016-08-25 03:01:41 +03:00
|
|
|
/**
|
2018-12-05 12:32:48 +03:00
|
|
|
* Helper function that parses an accumulated buffer back into its constituent
|
|
|
|
* parts.
|
2016-05-12 23:43:17 +03:00
|
|
|
*/
|
2018-12-05 12:32:48 +03:00
|
|
|
std::vector<ExtractedEntry> extract() const;
|
2016-05-12 23:43:17 +03:00
|
|
|
};
|
2018-03-20 03:01:15 +03:00
|
|
|
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|