mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-24 14:01:15 -03:00
Remove fd_check_is_remote
This function is no longer used; instead we detect if a given path is remote, once, typically at startup.
This commit is contained in:
41
src/fds.cpp
41
src/fds.cpp
@@ -18,12 +18,6 @@
|
||||
#include <sys/eventfd.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <sys/statfs.h>
|
||||
#endif
|
||||
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
// The first fd in the "high range." fds below this are allowed to be used directly by users in
|
||||
// redirections, e.g. >&3
|
||||
@@ -273,41 +267,6 @@ int wopen_cloexec(const wcstring &pathname, int flags, mode_t mode) {
|
||||
return open_cloexec(wcs2string(pathname), flags, mode);
|
||||
}
|
||||
|
||||
int fd_check_is_remote(int fd) {
|
||||
UNUSED(fd);
|
||||
#if defined(__linux__)
|
||||
struct statfs buf {};
|
||||
if (fstatfs(fd, &buf) < 0) {
|
||||
return -1;
|
||||
}
|
||||
// Linux has constants for these like NFS_SUPER_MAGIC, SMB_SUPER_MAGIC, CIFS_MAGIC_NUMBER but
|
||||
// these are in varying headers. Simply hard code them.
|
||||
// NOTE: The cast is necessary for 32-bit systems because of the 4-byte CIFS_MAGIC_NUMBER
|
||||
switch (static_cast<unsigned int>(buf.f_type)) {
|
||||
case 0x6969: // NFS_SUPER_MAGIC
|
||||
case 0x517B: // SMB_SUPER_MAGIC
|
||||
case 0xFE534D42U: // SMB2_MAGIC_NUMBER - not in the manpage
|
||||
case 0xFF534D42U: // CIFS_MAGIC_NUMBER
|
||||
return 1;
|
||||
default:
|
||||
// Other FSes are assumed local.
|
||||
return 0;
|
||||
}
|
||||
#elif defined(ST_LOCAL)
|
||||
// ST_LOCAL is a flag to statvfs, which is itself standardized.
|
||||
// In practice the only system to use this path is NetBSD.
|
||||
struct statvfs buf {};
|
||||
if (fstatvfs(fd, &buf) < 0) return -1;
|
||||
return (buf.f_flag & ST_LOCAL) ? 0 : 1;
|
||||
#elif defined(MNT_LOCAL)
|
||||
struct statfs buf {};
|
||||
if (fstatfs(fd, &buf) < 0) return -1;
|
||||
return (buf.f_flags & MNT_LOCAL) ? 0 : 1;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void exec_close(int fd) {
|
||||
assert(fd >= 0 && "Invalid fd");
|
||||
while (close(fd) == -1) {
|
||||
|
||||
@@ -180,10 +180,6 @@ int make_fd_nonblocking(int fd);
|
||||
/// Mark an fd as blocking; returns errno or 0 on success.
|
||||
int make_fd_blocking(int fd);
|
||||
|
||||
/// Check if an fd is on a remote filesystem (NFS, SMB, CFS)
|
||||
/// Return 1 if remote, 0 if local, -1 on error or if not implemented on this platform.
|
||||
int fd_check_is_remote(int fd);
|
||||
|
||||
/// Close a file descriptor \p fd, retrying on EINTR.
|
||||
void exec_close(int fd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user