sapling/eden/fs/nfs/NfsUtils.cpp
Katie Mancini d15b6ccd81 get nfs_utils building on Windows
Summary:
I'm getting nfs to build on windows to prototype it and see how feasible it
might be as an option on Windows. PrjFS has a very different model than EdenFS,
and that has made EdenFS correctness on Windows very difficult. NFS may be
easier to get correct, though the performance is suspect. Just exploring
options here.

NOTE: this one is more than removing ifdefs, please review carefully

Reviewed By: xavierd

Differential Revision: D44152041

fbshipit-source-id: 21affcc417dce492c2846902225686334eb2dc30
2023-03-29 12:52:44 -07:00

52 lines
1.5 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "eden/fs/nfs/NfsUtils.h"
#include <utility>
namespace facebook::eden {
uint32_t getEffectiveAccessRights(
const struct stat& stat,
uint32_t desiredAccess) {
bool accessRead = (stat.st_mode & S_IRUSR) | (stat.st_mode & S_IRGRP) |
(stat.st_mode & S_IROTH);
bool accessWrite = (stat.st_mode & S_IWUSR) | (stat.st_mode & S_IWGRP) |
(stat.st_mode & S_IWOTH);
bool accessExecute = (stat.st_mode & S_IXUSR) | (stat.st_mode & S_IXGRP) |
(stat.st_mode & S_IXOTH);
// The delete bit indicates whether entries can be deleted from a directory
// or not. NOT whether this file can be deleted. So this bit is kinda useless
// for files. The NFS spec suggests that NFS servers should return 0 for
// files, so we only set this bit for directories.
bool accessDelete = (stat.st_mode & S_IFDIR) && accessWrite;
uint32_t expandedAccessBits = 0;
if (accessRead) {
expandedAccessBits |= ACCESS3_READ;
expandedAccessBits |= ACCESS3_LOOKUP;
}
if (accessWrite) {
expandedAccessBits |= ACCESS3_MODIFY;
expandedAccessBits |= ACCESS3_EXTEND;
}
if (accessDelete) {
expandedAccessBits |= ACCESS3_DELETE;
}
if (accessExecute) {
expandedAccessBits |= ACCESS3_EXECUTE;
}
return desiredAccess & expandedAccessBits;
}
} // namespace facebook::eden