From a73501f2159875aef082ab0a61731a8b7673d477 Mon Sep 17 00:00:00 2001 From: Rozhuk Ivan Date: Sat, 9 May 2020 13:29:00 +0300 Subject: [PATCH] Improve FreeBSD support: - include posix_openpt() usage patch - add workaround for readdir() issue: #211, #278 - fix few warnings --- sshfs.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/sshfs.c b/sshfs.c index 5513266..d373819 100644 --- a/sshfs.c +++ b/sshfs.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -602,6 +603,9 @@ static const char *type_name(uint8_t type) #define list_entry(ptr, type, member) \ container_of(ptr, type, member) +static int sshfs_releasedir(const char *path, struct fuse_file_info *fi); + + static void list_init(struct list_head *head) { head->next = head; @@ -1108,7 +1112,11 @@ static int pty_master(char **name) { int mfd; +#ifdef __FreeBSD__ + mfd = posix_openpt(O_RDWR | O_NOCTTY); +#else mfd = open("/dev/ptmx", O_RDWR | O_NOCTTY); +#endif if (mfd == -1) { perror("failed to open pty"); return -1; @@ -1891,12 +1899,8 @@ static void *sshfs_init(struct fuse_conn_info *conn, if (conn->capable & FUSE_CAP_ASYNC_READ) sshfs.sync_read = 1; - // These workarounds require the "path" argument. - cfg->nullpath_ok = !(sshfs.truncate_workaround || sshfs.fstat_workaround); - - // When using multiple connections, release() needs to know the path - if (sshfs.max_conns > 1) - cfg->nullpath_ok = 0; + /* Allways require the "path" argument. */ + cfg->nullpath_ok = 0; // Lookup of . and .. is supported conn->capable |= FUSE_CAP_EXPORT_SUPPORT; @@ -2200,6 +2204,7 @@ static int sshfs_req_pending(struct request *req) static int sftp_readdir_async(struct conn *conn, struct buffer *handle, void *buf, off_t offset, fuse_fill_dir_t filler) { + (void) offset; int err = 0; int outstanding = 0; int max = READDIR_START; @@ -2278,6 +2283,7 @@ static int sftp_readdir_async(struct conn *conn, struct buffer *handle, static int sftp_readdir_sync(struct conn *conn, struct buffer *handle, void *buf, off_t offset, fuse_fill_dir_t filler) { + (void) offset; int err; assert(offset == 0); do { @@ -2327,10 +2333,17 @@ static int sshfs_readdir(const char *path, void *dbuf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags) { - (void) path; (void) flags; + (void) flags; int err; struct dir_handle *handle; + if (path == NULL) + return -EIO; + err = sshfs_opendir(path, fi); + if (err) + return err; + offset = 0; + handle = (struct dir_handle*) fi->fh; if (sshfs.sync_readdir) @@ -2340,6 +2353,8 @@ static int sshfs_readdir(const char *path, void *dbuf, fuse_fill_dir_t filler, err = sftp_readdir_async(handle->conn, &handle->buf, dbuf, offset, filler); + sshfs_releasedir(path, fi); + return err; }