2021-03-18 20:06:28 +03:00
|
|
|
/*
|
2022-01-05 01:58:22 +03:00
|
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
2021-03-18 20:06:28 +03:00
|
|
|
*
|
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
#include "eden/fs/inodes/InodeNumber.h"
|
|
|
|
#include "eden/fs/nfs/NfsdRpc.h"
|
|
|
|
|
|
|
|
namespace facebook::eden {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstraction to only add as many directory entries that can fit into a given
|
|
|
|
* amount of memory.
|
|
|
|
*/
|
|
|
|
class NfsDirList {
|
|
|
|
public:
|
2021-12-16 03:07:24 +03:00
|
|
|
explicit NfsDirList(uint32_t count, nfsv3Procs listType);
|
2021-03-18 20:06:28 +03:00
|
|
|
|
|
|
|
NfsDirList(NfsDirList&&) = default;
|
|
|
|
NfsDirList& operator=(NfsDirList&&) = default;
|
|
|
|
|
|
|
|
NfsDirList() = delete;
|
|
|
|
NfsDirList(const NfsDirList&) = delete;
|
|
|
|
NfsDirList& operator=(const NfsDirList&) = delete;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an entry. Return true if the entry was successfully added, false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
bool add(folly::StringPiece name, InodeNumber ino, uint64_t offset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move the built list out of the NfsDirList.
|
|
|
|
*/
|
2021-12-16 03:07:24 +03:00
|
|
|
template <typename T>
|
|
|
|
XdrList<T> extractList() {
|
|
|
|
return std::get<XdrList<T>>(std::move(list_));
|
2021-03-18 20:06:28 +03:00
|
|
|
}
|
|
|
|
|
2021-12-16 03:07:24 +03:00
|
|
|
/**
|
|
|
|
* Access the built list via reference. Only implemented for entryplus3
|
|
|
|
* since only the entryplus3 implementation will need to fill in stat data.
|
|
|
|
*
|
|
|
|
* Use this method when you need to modify the NfsDirList's vector of entries.
|
|
|
|
*/
|
|
|
|
std::vector<entryplus3>& getListRef() {
|
|
|
|
return std::get<XdrList<entryplus3>>(list_).list;
|
|
|
|
}
|
|
|
|
|
2021-03-18 20:06:28 +03:00
|
|
|
private:
|
|
|
|
uint32_t remaining_;
|
2021-12-16 03:07:24 +03:00
|
|
|
std::variant<XdrList<entry3>, XdrList<entryplus3>> list_{};
|
2021-03-18 20:06:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace facebook::eden
|
|
|
|
|
|
|
|
#endif
|