From 4234ed278e6fb9ad1658ad0eeda7cd3d87151ab6 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 15 Nov 2016 21:21:36 -0800 Subject: [PATCH 01/10] Use FUSE_CFLAGS and FUSE_LIBS from pkg-config Include , not , the include path should be set up for that. Don't define _FILE_OFFSET_BITS in one file, FUSE_CFLAGS would enable it for the whole xrdp-chansrv build if needed. --- sesman/chansrv/Makefile.am | 4 ++-- sesman/chansrv/chansrv_fuse.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sesman/chansrv/Makefile.am b/sesman/chansrv/Makefile.am index 2ecd67b4..221437e9 100644 --- a/sesman/chansrv/Makefile.am +++ b/sesman/chansrv/Makefile.am @@ -8,8 +8,8 @@ AM_CPPFLAGS = \ CHANSRV_EXTRA_LIBS = if XRDP_FUSE -AM_CPPFLAGS += -DXRDP_FUSE -CHANSRV_EXTRA_LIBS += -lfuse +AM_CPPFLAGS += -DXRDP_FUSE $(FUSE_CFLAGS) +CHANSRV_EXTRA_LIBS += $(FUSE_LIBS) endif if XRDP_OPUS diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 04209fd9..e55a1c89 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -87,9 +87,8 @@ void xfuse_devredir_cb_file_close(void *vp) {} ******************************************************************************/ #define FUSE_USE_VERSION 26 -#define _FILE_OFFSET_BITS 64 -#include +#include #include #include #include From bf39fed6e4a4b34cbe141f0b90ba2a65a52c891c Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 13 Nov 2016 23:27:58 -0800 Subject: [PATCH 02/10] Fix misuse of NULL for arithmetic type --- sesman/chansrv/chansrv_fuse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index e55a1c89..1214a28a 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -1871,7 +1871,7 @@ void xfuse_devredir_cb_file_close(void *vp) fip->fi, (long long) fip->fi->fh); free((char *) (tintptr) (fip->fi->fh)); - fip->fi->fh = NULL; + fip->fi->fh = 0; } #endif From a547cc3784c41ed7a6f2220545158da3401ce3bf Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 16 Nov 2016 02:33:36 +0000 Subject: [PATCH 03/10] Include needed files in chansrv_fuse.c, remove duplicate declarations --- sesman/chansrv/chansrv_fuse.c | 21 +++------------------ sesman/chansrv/devredir.h | 7 +++++++ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 1214a28a..fe653c60 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -100,9 +100,12 @@ void xfuse_devredir_cb_file_close(void *vp) {} #include "arch.h" #include "os_calls.h" +#include "clipboard_file.h" #include "chansrv_fuse.h" +#include "devredir.h" #include "list.h" #include "fifo.h" +#include "file.h" #ifndef EREMOTEIO #define EREMOTEIO EIO @@ -284,20 +287,6 @@ static void xfuse_update_xrdpfs_size(void); static void xfuse_enum_dir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi); -/* forward declarations for calls we make into devredir */ -int dev_redir_get_dir_listing(void *fusep, tui32 device_id, char *path); - -int dev_redir_file_open(void *fusep, tui32 device_id, char *path, - int mode, int type, char *gen_buf); - -int devredir_file_read(void *fusep, tui32 device_id, tui32 FileId, - tui32 Length, tui64 Offset); - -int dev_redir_file_write(void *fusep, tui32 device_id, tui32 FileId, - const char *buf, int Length, tui64 Offset); - -int devredir_file_close(void *fusep, tui32 device_id, tui32 FileId); - /* forward declarations for FUSE callbacks */ static void xfuse_cb_lookup(fuse_req_t req, fuse_ino_t parent, const char *name); @@ -367,10 +356,6 @@ static int xfuse_proc_opendir_req(fuse_req_t req, fuse_ino_t ino, static void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); -/* clipboard calls */ -int clipboard_request_file_data(int stream_id, int lindex, int offset, - int request_bytes); - /* misc calls */ static void xfuse_mark_as_stale(int pinode); static void xfuse_delete_stale_entries(int pinode); diff --git a/sesman/chansrv/devredir.h b/sesman/chansrv/devredir.h index b49eb1dd..70e15400 100644 --- a/sesman/chansrv/devredir.h +++ b/sesman/chansrv/devredir.h @@ -104,6 +104,13 @@ int devredir_file_close(void *fusep, tui32 device_id, tui32 file_id); int devredir_file_read(void *fusep, tui32 device_id, tui32 FileId, tui32 Length, tui64 Offset); +int APP_CC +dev_redir_file_write(void *fusep, tui32 DeviceId, tui32 FileId, + const char *buf, int Length, tui64 Offset); + +int APP_CC +devredir_rmdir_or_file(void *fusep, tui32 device_id, char *path, int mode); + int send_channel_data(int chan_id, char *data, int size); /* From a4e3952d6570a8db7436fbe5bb50a526a858ab09 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 13 Nov 2016 21:37:41 -0800 Subject: [PATCH 04/10] Disable or remove dead code to prevent it from throwing warnings --- sesman/chansrv/chansrv_fuse.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index fe653c60..956b720c 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -267,7 +267,6 @@ static void xfuse_create_file(fuse_req_t req, fuse_ino_t parent, #endif static void xfuse_dump_fs(void); -static void xfuse_dump_xrdp_inode(struct xrdp_inode *xino); static tui32 xfuse_get_device_id_for_inode(tui32 ino, char *full_path); static void fuse_reverse_pathname(char *full_path, char *reverse_path); @@ -279,13 +278,15 @@ static struct xrdp_inode * xfuse_create_file_in_xrdp_fs(tui32 device_id, int type); static int xfuse_does_file_exist(int parent, char *name); -static int xfuse_delete_file(int parent, char *name); static int xfuse_delete_file_with_xinode(XRDP_INODE *xinode); static int xfuse_delete_dir_with_xinode(XRDP_INODE *xinode); static int xfuse_recursive_delete_dir_with_xinode(XRDP_INODE *xinode); static void xfuse_update_xrdpfs_size(void); + +#ifdef USE_SYNC_FLAG static void xfuse_enum_dir(fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi); +#endif /* forward declarations for FUSE callbacks */ static void xfuse_cb_lookup(fuse_req_t req, fuse_ino_t parent, @@ -295,9 +296,6 @@ static void xfuse_cb_getattr(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /* this is not a callback, but it's used by xfuse_cb_readdir() */ -static void xfuse_dirbuf_add(fuse_req_t req, struct dirbuf *b, - const char *name, fuse_ino_t ino); - static int xfuse_dirbuf_add1(fuse_req_t req, struct dirbuf1 *b, const char *name, fuse_ino_t ino); @@ -341,8 +339,10 @@ static void xfuse_cb_create(fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, struct fuse_file_info *fi); +#if 0 static void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi); +#endif static void xfuse_cb_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, struct fuse_file_info *fi); @@ -1068,6 +1068,7 @@ static void xfuse_dump_fs() * @param xino xinode structure to dump *****************************************************************************/ +#if 0 static void xfuse_dump_xrdp_inode(struct xrdp_inode *xino) { log_debug("--- dumping struct xinode ---"); @@ -1082,6 +1083,7 @@ static void xfuse_dump_xrdp_inode(struct xrdp_inode *xino) log_debug("device_id: %d", xino->device_id); log_debug("%s", ""); } +#endif /** * Return the device_id associated with specified inode and copy the @@ -1278,11 +1280,6 @@ static int xfuse_does_file_exist(int parent, char *name) return 0; } -static int xfuse_delete_file(int parent, char *name) -{ - return -1; -} - static int xfuse_delete_file_with_xinode(XRDP_INODE *xinode) { /* make sure it is not a dir */ @@ -1960,6 +1957,7 @@ static void xfuse_cb_getattr(fuse_req_t req, fuse_ino_t ino, * *****************************************************************************/ +#if 0 static void xfuse_dirbuf_add(fuse_req_t req, struct dirbuf *b, const char *name, fuse_ino_t ino) { @@ -1976,6 +1974,7 @@ static void xfuse_dirbuf_add(fuse_req_t req, struct dirbuf *b, fuse_add_direntry(req, b->p + oldsize, b->size - oldsize, name, &stbuf, b->size); } +#endif static int xfuse_dirbuf_add1(fuse_req_t req, struct dirbuf1 *b, const char *name, fuse_ino_t ino) @@ -2781,6 +2780,7 @@ static void xfuse_cb_create(fuse_req_t req, fuse_ino_t parent, /** *****************************************************************************/ +#if 0 static void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi) { @@ -2788,6 +2788,7 @@ static void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync, log_debug("function not required"); fuse_reply_err(req, EINVAL); } +#endif /** *****************************************************************************/ @@ -2955,9 +2956,9 @@ static int xfuse_proc_opendir_req(fuse_req_t req, fuse_ino_t ino, { goto do_remote_lookup; } -#endif do_remote_lookup: +#endif xfuse_mark_as_stale((int) ino); From 662172012b3b1575409052cd6941251e15546b8d Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 15 Nov 2016 21:24:49 -0800 Subject: [PATCH 05/10] Call devredir_cvt_slash() on the path copy, it changes the argument --- sesman/chansrv/devredir.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sesman/chansrv/devredir.c b/sesman/chansrv/devredir.c index 2ce30286..4a41b983 100644 --- a/sesman/chansrv/devredir.c +++ b/sesman/chansrv/devredir.c @@ -1010,26 +1010,27 @@ dev_redir_get_dir_listing(void *fusep, tui32 device_id, char *path) if ((irp = devredir_irp_new()) == NULL) return -1; - /* cvt / to windows compatible \ */ - devredir_cvt_slash(path); + strncpy(irp->pathname, path, 255); + + /* convert / to windows compatible \ */ + devredir_cvt_slash(irp->pathname); irp->CompletionId = g_completion_id++; irp->completion_type = CID_CREATE_DIR_REQ; irp->DeviceId = device_id; - strncpy(irp->pathname, path, 255); devredir_fuse_data_enqueue(irp, fusep); DesiredAccess = DA_FILE_READ_DATA | DA_SYNCHRONIZE; CreateOptions = CO_FILE_DIRECTORY_FILE | CO_FILE_SYNCHRONOUS_IO_NONALERT; CreateDisposition = CD_FILE_OPEN; - rval = dev_redir_send_drive_create_request(device_id, path, + rval = dev_redir_send_drive_create_request(device_id, irp->pathname, DesiredAccess, CreateOptions, CreateDisposition, irp->CompletionId); - log_debug("looking for device_id=%d path=%s", device_id, path); + log_debug("looking for device_id=%d path=%s", device_id, irp->pathname); /* when we get a response to dev_redir_send_drive_create_request(), we */ /* call dev_redir_send_drive_dir_request(), which needs the following */ From e92c4f3b40406e85994653e1f2b97c510d5d9b79 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 16 Nov 2016 04:04:59 +0000 Subject: [PATCH 06/10] Use constant strings to fix warnings --- sesman/chansrv/chansrv_fuse.c | 2 +- sesman/chansrv/devredir.c | 13 +++++++------ sesman/chansrv/devredir.h | 13 +++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 956b720c..4afd6659 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -2246,7 +2246,7 @@ static void xfuse_cb_rename(fuse_req_t req, char *cptr; char old_full_path[1024]; char new_full_path[1024]; - char *cp; + const char *cp; tui32 device_id; diff --git a/sesman/chansrv/devredir.c b/sesman/chansrv/devredir.c index 4a41b983..111ac465 100644 --- a/sesman/chansrv/devredir.c +++ b/sesman/chansrv/devredir.c @@ -430,7 +430,8 @@ void devredir_send_server_device_announce_resp(tui32 device_id) * @return 0 on success, -1 on failure *****************************************************************************/ -int dev_redir_send_drive_create_request(tui32 device_id, char *path, +int dev_redir_send_drive_create_request(tui32 device_id, + const char *path, tui32 DesiredAccess, tui32 CreateOptions, tui32 CreateDisposition, @@ -997,7 +998,7 @@ dev_redir_proc_query_dir_response(IRP *irp, *****************************************************************************/ int APP_CC -dev_redir_get_dir_listing(void *fusep, tui32 device_id, char *path) +dev_redir_get_dir_listing(void *fusep, tui32 device_id, const char *path) { tui32 DesiredAccess; tui32 CreateOptions; @@ -1044,8 +1045,8 @@ dev_redir_get_dir_listing(void *fusep, tui32 device_id, char *path) } int APP_CC -dev_redir_file_open(void *fusep, tui32 device_id, char *path, - int mode, int type, char *gen_buf) +dev_redir_file_open(void *fusep, tui32 device_id, const char *path, + int mode, int type, const char *gen_buf) { tui32 DesiredAccess; tui32 CreateOptions; @@ -1162,7 +1163,7 @@ int devredir_file_close(void *fusep, tui32 device_id, tui32 FileId) *****************************************************************************/ int APP_CC -devredir_rmdir_or_file(void *fusep, tui32 device_id, char *path, int mode) +devredir_rmdir_or_file(void *fusep, tui32 device_id, const char *path, int mode) { tui32 DesiredAccess; tui32 CreateOptions; @@ -1446,7 +1447,7 @@ devredir_cvt_slash(char *path) } void APP_CC -devredir_cvt_to_unicode(char *unicode, char *path) +devredir_cvt_to_unicode(char *unicode, const char *path) { char *dest; char *src; diff --git a/sesman/chansrv/devredir.h b/sesman/chansrv/devredir.h index 70e15400..6479c6f6 100644 --- a/sesman/chansrv/devredir.h +++ b/sesman/chansrv/devredir.h @@ -48,7 +48,8 @@ void devredir_send_server_device_announce_resp(tui32 device_id); void dev_redir_send_drive_dir_request(IRP *irp, tui32 device_id, tui32 InitialQuery, char *Path); -int dev_redir_send_drive_create_request(tui32 device_id, char *path, +int dev_redir_send_drive_create_request(tui32 device_id, + const char *path, tui32 DesiredAccess, tui32 CreateOptions, tui32 CreateDisposition, @@ -81,7 +82,7 @@ void devredir_insert_DeviceIoRequest(struct stream *s, tui32 MinorFunction); void devredir_cvt_slash(char *path); -void devredir_cvt_to_unicode(char *unicode, char *path); +void devredir_cvt_to_unicode(char *unicode, const char *path); void devredir_cvt_from_unicode_len(char *path, char *unicode, int len); int dev_redir_string_ends_with(char *string, char c); @@ -94,10 +95,10 @@ void devredir_proc_cid_rename_file(IRP *irp, tui32 IoStatus); void devredir_proc_cid_rename_file_resp(IRP *irp, tui32 IoStatus); /* called from FUSE module */ -int dev_redir_get_dir_listing(void *fusep, tui32 device_id, char *path); +int dev_redir_get_dir_listing(void *fusep, tui32 device_id, const char *path); -int dev_redir_file_open(void *fusep, tui32 device_id, char *path, - int mode, int type, char *gen_buf); +int dev_redir_file_open(void *fusep, tui32 device_id, const char *path, + int mode, int type, const char *gen_buf); int devredir_file_close(void *fusep, tui32 device_id, tui32 file_id); @@ -109,7 +110,7 @@ dev_redir_file_write(void *fusep, tui32 DeviceId, tui32 FileId, const char *buf, int Length, tui64 Offset); int APP_CC -devredir_rmdir_or_file(void *fusep, tui32 device_id, char *path, int mode); +devredir_rmdir_or_file(void *fusep, tui32 device_id, const char *path, int mode); int send_channel_data(int chan_id, char *data, int size); From 46f402537247420b0b0b873fa8208db04dfcd4d6 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 13 Nov 2016 21:37:41 -0800 Subject: [PATCH 07/10] Cast pointer to uint64_t through tintptr to avoid warnings Cast to long would damage a pointer on Win64. --- sesman/chansrv/chansrv_fuse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 4afd6659..91739604 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -1513,7 +1513,7 @@ void xfuse_devredir_cb_enum_dir_done(void *vp, tui32 IoStatus) /* this will be used by xfuse_cb_readdir() */ di = calloc(1, sizeof(struct dir_info)); di->index = FIRST_INODE; - fip->fi->fh = (long) di; + fip->fi->fh = (tintptr) di; fuse_reply_open(fip->req, fip->fi); @@ -1595,7 +1595,7 @@ void xfuse_devredir_cb_open_file(void *vp, tui32 IoStatus, tui32 DeviceId, fh->DeviceId = DeviceId; fh->FileId = FileId; - fip->fi->fh = (uint64_t) ((long) fh); + fip->fi->fh = (tintptr) fh; log_debug("+++ XFUSE_INFO=%p XFUSE_INFO->fi=%p XFUSE_INFO->fi->fh=0x%llx", fip, fip->fi, (long long) fip->fi->fh); } @@ -2517,7 +2517,7 @@ static void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino, /* specified file is a local resource */ XFUSE_HANDLE *fh = calloc(1, sizeof(XFUSE_HANDLE)); fh->is_loc_resource = 1; - fi->fh = (uint64_t) ((long) fh); + fi->fh = (tintptr) fh; fuse_reply_open(req, fi); return; } @@ -3011,7 +3011,7 @@ done: di = calloc(1, sizeof(struct dir_info)); di->index = FIRST_INODE; - fi->fh = (long) di; + fi->fh = (tintptr) di; fuse_reply_open(req, fi); g_free(fifo_remove(&g_fifo_opendir)); return -1; From f622a17c751b11435304e888454d1b39b12289c7 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 13 Nov 2016 21:37:41 -0800 Subject: [PATCH 08/10] Remove write-only FileId variable --- sesman/chansrv/chansrv_fuse.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 91739604..8eac7c25 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -2570,7 +2570,6 @@ static void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct { XFUSE_INFO *fip = NULL; XFUSE_HANDLE *handle = (XFUSE_HANDLE *) (tintptr) (fi->fh); - tui32 FileId; log_debug("entered: ino=%ld fi=%p fi->fh=0x%llx", ino, fi, (long long) fi->fh); @@ -2624,7 +2623,6 @@ static void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct log_debug(" +++ created XFUSE_INFO=%p XFUSE_INFO->fi=%p XFUSE_INFO->fi->fh=0x%llx", fip, fip->fi, (long long) fip->fi->fh); - FileId = handle->FileId; fip->fi->fh = 0; xinode->close_in_progress = 1; From 2ab321a7c672d9304b40444e07f0c1c30391cf2f Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 15 Nov 2016 22:11:48 -0800 Subject: [PATCH 09/10] Use fuse_ino_t for FUSE inodes, not tui32 or int --- sesman/chansrv/chansrv_fuse.c | 54 +++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 8eac7c25..8634bce6 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -258,7 +258,7 @@ static tintptr g_bufsize = 0; static int xfuse_init_xrdp_fs(void); static int xfuse_deinit_xrdp_fs(void); static int xfuse_init_lib(struct fuse_args *args); -static int xfuse_is_inode_valid(int ino); +static int xfuse_is_inode_valid(fuse_ino_t ino); // LK_TODO #if 0 @@ -267,17 +267,17 @@ static void xfuse_create_file(fuse_req_t req, fuse_ino_t parent, #endif static void xfuse_dump_fs(void); -static tui32 xfuse_get_device_id_for_inode(tui32 ino, char *full_path); +static tui32 xfuse_get_device_id_for_inode(fuse_ino_t ino, char *full_path); static void fuse_reverse_pathname(char *full_path, char *reverse_path); -static struct xrdp_inode * xfuse_get_inode_from_pinode_name(tui32 pinode, +static struct xrdp_inode * xfuse_get_inode_from_pinode_name(fuse_ino_t pinode, const char *name); static struct xrdp_inode * xfuse_create_file_in_xrdp_fs(tui32 device_id, int pinode, char *name, int type); -static int xfuse_does_file_exist(int parent, char *name); +static int xfuse_does_file_exist(fuse_ino_t parent, char *name); static int xfuse_delete_file_with_xinode(XRDP_INODE *xinode); static int xfuse_delete_dir_with_xinode(XRDP_INODE *xinode); static int xfuse_recursive_delete_dir_with_xinode(XRDP_INODE *xinode); @@ -357,8 +357,8 @@ static void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi); /* misc calls */ -static void xfuse_mark_as_stale(int pinode); -static void xfuse_delete_stale_entries(int pinode); +static void xfuse_mark_as_stale(fuse_ino_t pinode); +static void xfuse_delete_stale_entries(fuse_ino_t pinode); /*****************************************************************************/ int APP_CC @@ -671,7 +671,7 @@ int xfuse_create_share(tui32 device_id, char *dirname) int xfuse_clear_clip_dir(void) { - int i; + fuse_ino_t i; XRDP_INODE *xinode; XRDP_INODE *xip; @@ -955,7 +955,7 @@ static int xfuse_deinit_xrdp_fs() * @return 1 if it does, 0 otherwise *****************************************************************************/ -static int xfuse_is_inode_valid(int ino) +static int xfuse_is_inode_valid(fuse_ino_t ino) { /* is ino present in our table? */ if ((ino < FIRST_INODE) || (ino >= g_xrdp_fs.next_node)) @@ -1039,7 +1039,7 @@ static void xfuse_create_file(fuse_req_t req, fuse_ino_t parent, static void xfuse_dump_fs() { - int i; + fuse_ino_t i; struct xrdp_inode *xinode; log_debug("found %d entries", g_xrdp_fs.num_entries - FIRST_INODE); @@ -1095,10 +1095,10 @@ static void xfuse_dump_xrdp_inode(struct xrdp_inode *xino) * @return the device_id of specified inode *****************************************************************************/ -static tui32 xfuse_get_device_id_for_inode(tui32 ino, char *full_path) +static tui32 xfuse_get_device_id_for_inode(fuse_ino_t ino, char *full_path) { - tui32 parent_inode = 0; - tui32 child_inode = ino; + fuse_ino_t parent_inode = 0; + fuse_ino_t child_inode = ino; char reverse_path[4096]; /* ino == 1 is a special case; we already know that it is not */ @@ -1106,7 +1106,7 @@ static tui32 xfuse_get_device_id_for_inode(tui32 ino, char *full_path) if (ino == 1) { /* just return the device_id for the file in full_path */ - log_debug("looking for file with pinode=%d name=%s", ino, full_path); + log_debug("looking for file with pinode=%ld name=%s", ino, full_path); xfuse_dump_fs(); XRDP_INODE *xinode = xfuse_get_inode_from_pinode_name(ino, full_path); @@ -1165,10 +1165,10 @@ static void fuse_reverse_pathname(char *full_path, char *reverse_path) * Return the inode that matches the name and parent inode *****************************************************************************/ -static struct xrdp_inode * xfuse_get_inode_from_pinode_name(tui32 pinode, +static struct xrdp_inode * xfuse_get_inode_from_pinode_name(fuse_ino_t pinode, const char *name) { - int i; + fuse_ino_t i; struct xrdp_inode * xinode; for (i = FIRST_INODE; i < g_xrdp_fs.num_entries; i++) @@ -1260,9 +1260,9 @@ static struct xrdp_inode * xfuse_create_file_in_xrdp_fs(tui32 device_id, * @return 1 if specified file exists, 0 otherwise *****************************************************************************/ -static int xfuse_does_file_exist(int parent, char *name) +static int xfuse_does_file_exist(fuse_ino_t parent, char *name) { - int i; + fuse_ino_t i; XRDP_INODE *xinode; for (i = FIRST_INODE; i < g_xrdp_fs.num_entries; i++) @@ -1299,7 +1299,7 @@ static int xfuse_delete_file_with_xinode(XRDP_INODE *xinode) static int xfuse_delete_dir_with_xinode(XRDP_INODE *xinode) { XRDP_INODE *xip; - int i; + fuse_ino_t i; /* make sure it is not a file */ if ((xinode == NULL) || (xinode->mode & S_IFREG)) @@ -1335,7 +1335,7 @@ static int xfuse_delete_dir_with_xinode(XRDP_INODE *xinode) static int xfuse_recursive_delete_dir_with_xinode(XRDP_INODE *xinode) { XRDP_INODE *xip; - int i; + fuse_ino_t i; /* make sure it is not a file */ if ((xinode == NULL) || (xinode->mode & S_IFREG)) @@ -2015,7 +2015,7 @@ static void xfuse_cb_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, XRDP_INODE *ti; struct dir_info *di; struct dirbuf1 b; - int i; + fuse_ino_t i; int first_time; log_debug("req=%p inode=%ld size=%zd offset=%lld", req, ino, size, (long long) off); @@ -2510,7 +2510,7 @@ static void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino, return; } - device_id = xfuse_get_device_id_for_inode((tui32) ino, full_path); + device_id = xfuse_get_device_id_for_inode(ino, full_path); if (xinode->is_loc_resource) { @@ -2958,10 +2958,10 @@ static int xfuse_proc_opendir_req(fuse_req_t req, fuse_ino_t ino, do_remote_lookup: #endif - xfuse_mark_as_stale((int) ino); + xfuse_mark_as_stale(ino); log_debug("did not find entry; redirecting call to dev_redir"); - device_id = xfuse_get_device_id_for_inode((tui32) ino, full_path); + device_id = xfuse_get_device_id_for_inode(ino, full_path); log_debug("dev_id=%d ino=%ld full_path=%s", device_id, ino, full_path); @@ -3041,9 +3041,9 @@ static void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino, *****************************************************************************/ static void -xfuse_mark_as_stale(int pinode) +xfuse_mark_as_stale(fuse_ino_t pinode) { - int i; + fuse_ino_t i; XRDP_INODE *xinode; if ((pinode < FIRST_INODE) || (pinode >= g_xrdp_fs.num_entries)) @@ -3070,9 +3070,9 @@ xfuse_mark_as_stale(int pinode) *****************************************************************************/ static void -xfuse_delete_stale_entries(int pinode) +xfuse_delete_stale_entries(fuse_ino_t pinode) { - int i; + fuse_ino_t i; XRDP_INODE *xinode; if ((pinode < FIRST_INODE) || (pinode >= g_xrdp_fs.num_entries)) From e46d15ca84e3adcd47560e1f3efe2fdd9df85850 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Wed, 16 Nov 2016 03:44:24 +0000 Subject: [PATCH 10/10] Fix C++ errors and warnings in FUSE code --- sesman/chansrv/chansrv_fuse.c | 73 +++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/sesman/chansrv/chansrv_fuse.c b/sesman/chansrv/chansrv_fuse.c index 8634bce6..16fda322 100644 --- a/sesman/chansrv/chansrv_fuse.c +++ b/sesman/chansrv/chansrv_fuse.c @@ -607,9 +607,10 @@ int xfuse_create_share(tui32 device_id, char *dirname) if (dirname == NULL || strlen(dirname) == 0) return -1; - if ((xinode = calloc(1, sizeof(struct xrdp_inode))) == NULL) + xinode = g_new0(struct xrdp_inode, 1); + if (xinode == NULL) { - log_debug("calloc() failed"); + log_debug("g_new0() failed"); return -1; } @@ -642,7 +643,8 @@ int xfuse_create_share(tui32 device_id, char *dirname) xinode->nentries++; #if 0 - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); return -1; @@ -830,7 +832,7 @@ static int xfuse_init_lib(struct fuse_args *args) fuse_session_add_chan(g_se, g_ch); g_bufsize = fuse_chan_bufsize(g_ch); - g_buffer = calloc(g_bufsize, 1); + g_buffer = g_new0(char, g_bufsize); g_fd = fuse_chan_fd(g_ch); g_req_list = list_create(); @@ -850,7 +852,7 @@ static int xfuse_init_xrdp_fs() { struct xrdp_inode *xino; - g_xrdp_fs.inode_table = calloc(4096, sizeof(struct xrdp_inode *)); + g_xrdp_fs.inode_table = g_new0(struct xrdp_inode *, 4096); if (g_xrdp_fs.inode_table == NULL) { log_error("system out of memory"); @@ -861,7 +863,8 @@ static int xfuse_init_xrdp_fs() * index 0 is our .. dir */ - if ((xino = calloc(1, sizeof(struct xrdp_inode))) == NULL) + xino = g_new0(struct xrdp_inode, 1); + if (xino == NULL) { log_error("system out of memory"); free(g_xrdp_fs.inode_table); @@ -884,7 +887,8 @@ static int xfuse_init_xrdp_fs() * index 1 is our . dir */ - if ((xino = calloc(1, sizeof(struct xrdp_inode))) == NULL) + xino = g_new0(struct xrdp_inode, 1); + if (xino == NULL) { log_error("system out of memory"); free(g_xrdp_fs.inode_table[0]); @@ -908,7 +912,8 @@ static int xfuse_init_xrdp_fs() * index 2 is for clipboard use */ - if ((xino = calloc(1, sizeof(struct xrdp_inode))) == NULL) + xino = g_new0(struct xrdp_inode, 1); + if (xino == NULL) { log_error("system out of memory"); free(g_xrdp_fs.inode_table[0]); @@ -988,9 +993,10 @@ static void xfuse_create_file(fuse_req_t req, fuse_ino_t parent, fuse_reply_err(req, EBADF); } - if ((xinode = calloc(1, sizeof(struct xrdp_inode))) == NULL) + xinode = g_new0(struct xrdp_inode, 1); + if (xinode == NULL) { - log_error("calloc() failed"); + log_error("g_new0() failed"); fuse_reply_err(req, ENOMEM); } @@ -1208,7 +1214,8 @@ static struct xrdp_inode * xfuse_create_file_in_xrdp_fs(tui32 device_id, if ((name == NULL) || (strlen(name) == 0)) return NULL; - if ((xinode = calloc(1, sizeof(XRDP_INODE))) == NULL) + xinode = g_new0(XRDP_INODE, 1); + if (xinode == NULL) { log_error("system out of memory"); return NULL; @@ -1400,12 +1407,12 @@ static void xfuse_update_xrdpfs_size() } /* zero newly added memory */ - memset(vp + g_xrdp_fs.max_entries * sizeof(struct xrdp_inode *), + memset((char *) vp + g_xrdp_fs.max_entries * sizeof(struct xrdp_inode *), 0, 100 * sizeof(struct xrdp_inode *)); g_xrdp_fs.max_entries += 100; - g_xrdp_fs.inode_table = vp; + g_xrdp_fs.inode_table = (struct xrdp_inode **) vp; } /****************************************************************************** @@ -1511,7 +1518,7 @@ void xfuse_devredir_cb_enum_dir_done(void *vp, tui32 IoStatus) xfuse_delete_stale_entries(fip->inode); /* this will be used by xfuse_cb_readdir() */ - di = calloc(1, sizeof(struct dir_info)); + di = g_new0(struct dir_info, 1); di->index = FIRST_INODE; fip->fi->fh = (tintptr) di; @@ -1528,7 +1535,7 @@ done: while (1) { /* process next request */ - odreq = fifo_peek(&g_fifo_opendir); + odreq = (struct opendir_req *) fifo_peek(&g_fifo_opendir); if (!odreq) return; @@ -1581,7 +1588,8 @@ void xfuse_devredir_cb_open_file(void *vp, tui32 IoStatus, tui32 DeviceId, if (fip->fi != NULL) { - if ((fh = calloc(1, sizeof(XFUSE_HANDLE))) == NULL) + fh = g_new0(XFUSE_HANDLE, 1); + if (fh == NULL) { log_error("system out of memory"); if (fip->invoke_fuse) @@ -2197,7 +2205,8 @@ static void xfuse_remove_dir_or_file(fuse_req_t req, fuse_ino_t parent, /* specified file resides on redirected share */ - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2326,7 +2335,8 @@ static void xfuse_cb_rename(fuse_req_t req, strcat(old_full_path, "/"); strcat(old_full_path, old_name); - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2430,7 +2440,8 @@ static void xfuse_create_dir_or_file(fuse_req_t req, fuse_ino_t parent, /* specified file resides on redirected share */ - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2515,7 +2526,7 @@ static void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino, if (xinode->is_loc_resource) { /* specified file is a local resource */ - XFUSE_HANDLE *fh = calloc(1, sizeof(XFUSE_HANDLE)); + XFUSE_HANDLE *fh = g_new0(XFUSE_HANDLE, 1); fh->is_loc_resource = 1; fi->fh = (tintptr) fh; fuse_reply_open(req, fi); @@ -2524,7 +2535,8 @@ static void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino, /* specified file resides on redirected share */ - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2607,7 +2619,8 @@ static void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct return; } - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2671,8 +2684,7 @@ static void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size, return; } - rli = (struct req_list_item *) - g_malloc(sizeof(struct req_list_item), 1); + rli = g_new0(struct req_list_item, 1); rli->stream_id = 0; rli->req = req; @@ -2695,7 +2707,8 @@ static void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size, /* target file is on a remote device */ - if ((fusep = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fusep = g_new0(XFUSE_INFO, 1); + if (fusep == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2742,7 +2755,8 @@ static void xfuse_cb_write(fuse_req_t req, fuse_ino_t ino, const char *buf, /* target file is on a remote device */ - if ((fusep = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fusep = g_new0(XFUSE_INFO, 1); + if (fusep == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -2885,7 +2899,7 @@ static void xfuse_cb_opendir(fuse_req_t req, fuse_ino_t ino, struct opendir_req *odreq; /* save request */ - odreq = malloc(sizeof(struct opendir_req)); + odreq = g_new(struct opendir_req, 1); odreq->req = req; odreq->ino = ino; odreq->fi = fi; @@ -2965,7 +2979,8 @@ do_remote_lookup: log_debug("dev_id=%d ino=%ld full_path=%s", device_id, ino, full_path); - if ((fip = calloc(1, sizeof(XFUSE_INFO))) == NULL) + fip = g_new0(XFUSE_INFO, 1); + if (fip == NULL) { log_error("system out of memory"); fuse_reply_err(req, ENOMEM); @@ -3007,7 +3022,7 @@ do_remote_lookup: done: - di = calloc(1, sizeof(struct dir_info)); + di = g_new0(struct dir_info, 1); di->index = FIRST_INODE; fi->fh = (tintptr) di; fuse_reply_open(req, fi);