2012-10-30 07:12:24 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2013-03-19 06:43:20 +04:00
|
|
|
* Copyright (C) Laxmikant Rashinkar 2013 LK.Rashinkar@gmail.com
|
2012-10-30 07:12:24 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/* FUSE mount point */
|
|
|
|
char g_fuse_root_path[256] = "";
|
2013-04-27 05:55:28 +04:00
|
|
|
char g_fuse_clipboard_path[256] = ""; /* for clipboard use */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
#ifndef XRDP_FUSE
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** **
|
|
|
|
** when FUSE is NOT enabled in xrdp **
|
|
|
|
** **
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-03-11 23:43:57 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
#include "arch.h"
|
2013-03-11 23:43:57 +04:00
|
|
|
#include "chansrv_fuse.h"
|
2019-11-14 17:43:57 +03:00
|
|
|
#include "chansrv_xfs.h"
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* dummy calls when XRDP_FUSE is not defined */
|
2020-11-30 03:36:20 +03:00
|
|
|
int xfuse_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int xfuse_deinit(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int xfuse_check_wait_objs(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int xfuse_get_wait_objs(tbus *objs, int *count, int *timeout)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int xfuse_create_share(tui32 device_id, const char *dirname)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_delete_share(tui32 share_id) {}
|
2020-11-30 03:36:20 +03:00
|
|
|
int xfuse_clear_clip_dir(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int xfuse_file_contents_range(int stream_id, const char *data, int data_bytes)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
int xfuse_file_contents_size(int stream_id, int file_size)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
int xfuse_add_clip_dir_item(const char *filename,
|
2020-11-30 03:36:20 +03:00
|
|
|
int flags, int size, int lindex)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
void xfuse_devredir_cb_enum_dir_add_entry(
|
2020-11-30 03:36:20 +03:00
|
|
|
struct state_dirscan *fip,
|
|
|
|
const char *name,
|
|
|
|
const struct file_attr *fattr)
|
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_enum_dir_done(struct state_dirscan *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_lookup_entry(struct state_lookup *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
const struct file_attr *file_info)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_setattr(struct state_setattr *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_create_file(struct state_create *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
tui32 DeviceId, tui32 FileId)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_open_file(struct state_open *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
tui32 DeviceId, tui32 FileId)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_read_file(struct state_read *fip,
|
2020-03-03 13:02:32 +03:00
|
|
|
enum NTSTATUS IoStatus,
|
2019-11-14 17:43:57 +03:00
|
|
|
const char *buf, size_t length)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_write_file(
|
2020-11-30 03:36:20 +03:00
|
|
|
struct state_write *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
off_t offset,
|
|
|
|
size_t length)
|
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_rmdir_or_file(struct state_remove *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_rename_file(struct state_rename *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_file_close(struct state_close *fip)
|
2020-11-30 03:36:20 +03:00
|
|
|
{}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
** **
|
|
|
|
** when FUSE is enabled in xrdp **
|
|
|
|
** **
|
|
|
|
******************************************************************************/
|
2012-10-30 09:12:44 +04:00
|
|
|
|
2021-03-24 14:32:28 +03:00
|
|
|
/* FUSE_USE_VERSION must be defined globally for other parts of
|
|
|
|
* xrdp-chansrv which include <fuse_lowlevel.h> for definitions. Check
|
|
|
|
* it's actually defined here */
|
|
|
|
#ifndef FUSE_USE_VERSION
|
|
|
|
#error Define FUSE_USE_VERSION in the make system and recompile
|
|
|
|
#endif
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2016-11-16 08:21:36 +03:00
|
|
|
#include <fuse_lowlevel.h>
|
2012-10-30 07:12:24 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2013-03-09 03:37:30 +04:00
|
|
|
#include <time.h>
|
2012-10-30 07:12:24 +04:00
|
|
|
#include <unistd.h>
|
2013-03-09 03:37:30 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
2012-10-30 07:12:24 +04:00
|
|
|
#include "arch.h"
|
|
|
|
#include "os_calls.h"
|
2020-08-22 20:05:24 +03:00
|
|
|
#include "string_calls.h"
|
2016-11-16 05:33:36 +03:00
|
|
|
#include "clipboard_file.h"
|
2012-10-30 07:12:24 +04:00
|
|
|
#include "chansrv_fuse.h"
|
2019-11-14 17:43:57 +03:00
|
|
|
#include "chansrv_xfs.h"
|
2020-10-08 04:55:08 +03:00
|
|
|
#include "chansrv.h"
|
2020-07-06 13:53:56 +03:00
|
|
|
#include "chansrv_config.h"
|
2016-11-16 05:33:36 +03:00
|
|
|
#include "devredir.h"
|
2013-04-27 05:55:28 +04:00
|
|
|
#include "list.h"
|
2016-11-16 05:33:36 +03:00
|
|
|
#include "file.h"
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2015-03-18 06:18:39 +03:00
|
|
|
#ifndef EREMOTEIO
|
|
|
|
#define EREMOTEIO EIO
|
|
|
|
#endif
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
#define XFUSE_ATTR_TIMEOUT 5.0
|
|
|
|
#define XFUSE_ENTRY_TIMEOUT 5.0
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Type of buffer used for fuse_add_direntry() calls */
|
|
|
|
struct dirbuf1
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
char buf[4096];
|
|
|
|
size_t len;
|
2019-03-21 19:48:01 +03:00
|
|
|
};
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a directory scan
|
|
|
|
*/
|
|
|
|
struct state_dirscan
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_req_t req; /* Original FUSE request from opendir */
|
|
|
|
struct fuse_file_info fi; /* File info struct passed to opendir */
|
|
|
|
fuse_ino_t pinum; /* inum of parent directory */
|
2012-11-05 13:04:04 +04:00
|
|
|
};
|
2012-11-05 01:52:33 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running an entry lookup
|
|
|
|
*/
|
|
|
|
struct state_lookup
|
|
|
|
{
|
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
fuse_ino_t pinum; /* inum of parent directory */
|
|
|
|
char name[XFS_MAXFILENAMELEN];
|
2020-11-30 03:36:20 +03:00
|
|
|
/* Name to look up */
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_ino_t existing_inum;
|
2020-11-30 03:36:20 +03:00
|
|
|
/* inum of an existing entry */
|
2019-11-14 17:43:57 +03:00
|
|
|
tui32 existing_generation;
|
2020-11-30 03:36:20 +03:00
|
|
|
/* generation of the above */
|
2019-11-14 17:43:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running an entry setattr
|
|
|
|
*/
|
|
|
|
struct state_setattr
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
fuse_ino_t inum; /* inum of entry */
|
|
|
|
struct file_attr fattr; /* File attributes to set */
|
|
|
|
tui32 change_mask; /* Attributes to set in fattr */
|
2013-03-09 03:37:30 +04:00
|
|
|
};
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running an open
|
|
|
|
*/
|
|
|
|
struct state_open
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
struct fuse_file_info fi; /* File info struct passed to open */
|
|
|
|
fuse_ino_t inum; /* inum of file to open */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a create
|
|
|
|
*/
|
|
|
|
struct state_create
|
|
|
|
{
|
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
struct fuse_file_info fi; /* File info struct passed to open */
|
|
|
|
fuse_ino_t pinum; /* inum of parent directory */
|
|
|
|
char name[XFS_MAXFILENAMELEN];
|
2020-11-30 03:36:20 +03:00
|
|
|
/* Name of file in parent directory */
|
2019-11-14 17:43:57 +03:00
|
|
|
mode_t mode; /* Mode of file to create */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a read
|
|
|
|
*/
|
|
|
|
struct state_read
|
|
|
|
{
|
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a write
|
|
|
|
*/
|
|
|
|
struct state_write
|
|
|
|
{
|
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
fuse_ino_t inum; /* inum of file we're writing */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a remove
|
|
|
|
*/
|
|
|
|
struct state_remove
|
|
|
|
{
|
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
fuse_ino_t inum; /* inum of file we're removing */
|
2013-04-21 03:42:49 +04:00
|
|
|
};
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a rename
|
|
|
|
*/
|
|
|
|
struct state_rename
|
|
|
|
{
|
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
fuse_ino_t pinum; /* inum of parent of file */
|
|
|
|
fuse_ino_t new_pinum; /* inum of new parent of file */
|
|
|
|
char name[XFS_MAXFILENAMELEN];
|
2020-11-30 03:36:20 +03:00
|
|
|
/* New name of file in new parent dir */
|
2019-11-14 17:43:57 +03:00
|
|
|
};
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Record type used to maintain state when running a close
|
|
|
|
*/
|
|
|
|
struct state_close
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_req_t req; /* Original FUSE request from lookup */
|
|
|
|
struct fuse_file_info fi; /* File info struct passed to open */
|
|
|
|
fuse_ino_t inum; /* inum of file to open */
|
2012-10-30 07:12:24 +04:00
|
|
|
};
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
struct xfuse_handle
|
|
|
|
{
|
|
|
|
tui32 DeviceId;
|
|
|
|
tui32 FileId;
|
2013-05-06 05:42:17 +04:00
|
|
|
int is_loc_resource; /* this is not a redirected resource */
|
2020-11-30 03:36:20 +03:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
/* a directory handle, if this xfuse_handle represents a directory.
|
|
|
|
* NULL, if this xfuse_handle represents a file.
|
|
|
|
*
|
2020-11-30 03:36:20 +03:00
|
|
|
* Note: when this xfuse_handle represents a directory, then the other
|
2020-09-15 18:37:56 +03:00
|
|
|
* fields of this structure contain invalid values.
|
|
|
|
*/
|
|
|
|
struct xfs_dir_handle *dir_handle;
|
2012-11-04 05:47:04 +04:00
|
|
|
};
|
2013-03-09 03:37:30 +04:00
|
|
|
typedef struct xfuse_handle XFUSE_HANDLE;
|
|
|
|
|
2013-04-27 05:55:28 +04:00
|
|
|
/* used for file data request sent to client */
|
|
|
|
struct req_list_item
|
|
|
|
{
|
|
|
|
fuse_req_t req;
|
|
|
|
int stream_id;
|
|
|
|
int lindex;
|
|
|
|
int off;
|
|
|
|
int size;
|
|
|
|
};
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-07-06 13:53:56 +03:00
|
|
|
extern struct config_chansrv *g_cfg; /* in chansrv.c */
|
2013-09-25 04:19:10 +04:00
|
|
|
|
2013-04-27 05:55:28 +04:00
|
|
|
static struct list *g_req_list = 0;
|
2019-11-14 17:43:57 +03:00
|
|
|
static struct xfs_fs *g_xfs; /* an inst of xrdp file system */
|
|
|
|
static ino_t g_clipboard_inum; /* inode of clipboard dir */
|
2013-03-09 03:37:30 +04:00
|
|
|
static char *g_mount_point = 0; /* our FUSE mount point */
|
|
|
|
static struct fuse_lowlevel_ops g_xfuse_ops; /* setup FUSE callbacks */
|
|
|
|
static int g_xfuse_inited = 0; /* true when FUSE is inited */
|
|
|
|
static struct fuse_chan *g_ch = 0;
|
|
|
|
static struct fuse_session *g_se = 0;
|
|
|
|
static char *g_buffer = 0;
|
|
|
|
static int g_fd = 0;
|
|
|
|
static tintptr g_bufsize = 0;
|
|
|
|
|
|
|
|
/* forward declarations for internal access */
|
2015-12-30 00:28:15 +03:00
|
|
|
static int xfuse_init_xrdp_fs(void);
|
|
|
|
static int xfuse_deinit_xrdp_fs(void);
|
2013-03-19 06:43:20 +04:00
|
|
|
static int xfuse_init_lib(struct fuse_args *args);
|
2016-11-14 08:37:41 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/* forward declarations for FUSE callbacks */
|
|
|
|
static void xfuse_cb_lookup(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name);
|
|
|
|
|
|
|
|
static void xfuse_cb_getattr(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi);
|
|
|
|
|
2016-02-14 07:41:07 +03:00
|
|
|
/* this is not a callback, but it's used by xfuse_cb_readdir() */
|
2013-04-21 03:42:49 +04:00
|
|
|
static int xfuse_dirbuf_add1(fuse_req_t req, struct dirbuf1 *b,
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode, off_t offset);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
|
|
|
|
off_t off, struct fuse_file_info *fi);
|
|
|
|
|
|
|
|
static void xfuse_cb_mkdir(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name, mode_t mode);
|
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
static void xfuse_cb_unlink(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name);
|
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
static void xfuse_cb_rename(fuse_req_t req,
|
|
|
|
fuse_ino_t old_parent, const char *old_name,
|
|
|
|
fuse_ino_t new_parent, const char *new_name);
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Whether to create a dir of file depends on whether S_IFDIR is set in the
|
|
|
|
mode field */
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_create_dir_or_file(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name, mode_t mode,
|
2019-11-14 17:43:57 +03:00
|
|
|
struct fuse_file_info *fi);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
static void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi);
|
|
|
|
|
2013-05-19 06:44:16 +04:00
|
|
|
static void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct
|
|
|
|
fuse_file_info *fi);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size,
|
|
|
|
off_t off, struct fuse_file_info *fi);
|
|
|
|
|
|
|
|
static void xfuse_cb_write(fuse_req_t req, fuse_ino_t ino, const char *buf,
|
|
|
|
size_t size, off_t off, struct fuse_file_info *fi);
|
2012-11-04 05:47:04 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_create(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name, mode_t mode,
|
|
|
|
struct fuse_file_info *fi);
|
2012-11-04 05:47:04 +04:00
|
|
|
|
2016-11-14 08:37:41 +03:00
|
|
|
#if 0
|
2013-05-21 23:57:06 +04:00
|
|
|
static void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
|
|
|
|
struct fuse_file_info *fi);
|
2016-11-14 08:37:41 +03:00
|
|
|
#endif
|
2013-05-21 23:57:06 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
|
|
|
|
int to_set, struct fuse_file_info *fi);
|
|
|
|
|
2013-08-12 05:06:39 +04:00
|
|
|
static void xfuse_cb_opendir(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi);
|
|
|
|
|
|
|
|
static void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi);
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* miscellaneous functions */
|
|
|
|
static void xfs_inode_to_fuse_entry_param(const XFS_INODE *xinode,
|
2020-11-30 03:36:20 +03:00
|
|
|
struct fuse_entry_param *e);
|
2019-11-14 17:43:57 +03:00
|
|
|
static void make_fuse_entry_reply(fuse_req_t req, const XFS_INODE *xinode);
|
|
|
|
static void make_fuse_attr_reply(fuse_req_t req, const XFS_INODE *xinode);
|
|
|
|
static const char *filename_on_device(const char *full_path);
|
|
|
|
static void update_inode_file_attributes(const struct file_attr *fattr,
|
2020-11-30 03:36:20 +03:00
|
|
|
tui32 change_mask, XFS_INODE *xinode);
|
2019-11-14 17:43:57 +03:00
|
|
|
static char *get_name_for_entry_in_parent(fuse_ino_t parent, const char *name);
|
2020-08-22 20:05:24 +03:00
|
|
|
static unsigned int format_user_info(char *dest, unsigned int len,
|
|
|
|
const char *format);
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2014-04-20 04:08:55 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-04-20 04:08:55 +04:00
|
|
|
load_fuse_config(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
/*****************************************************************************/
|
2020-11-30 03:36:20 +03:00
|
|
|
XFUSE_HANDLE *
|
2020-09-15 18:37:56 +03:00
|
|
|
xfuse_handle_create()
|
|
|
|
{
|
|
|
|
return g_new0(XFUSE_HANDLE, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void
|
|
|
|
xfuse_handle_delete(XFUSE_HANDLE *self)
|
|
|
|
{
|
|
|
|
if (self == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
if (self->dir_handle != NULL)
|
|
|
|
{
|
|
|
|
free(self->dir_handle);
|
|
|
|
}
|
|
|
|
free(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
uint64_t
|
|
|
|
xfuse_handle_to_fuse_handle(XFUSE_HANDLE *self)
|
|
|
|
{
|
|
|
|
return (uint64_t) (tintptr) self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2020-11-30 03:36:20 +03:00
|
|
|
XFUSE_HANDLE *
|
2020-09-15 18:37:56 +03:00
|
|
|
xfuse_handle_from_fuse_handle(uint64_t handle)
|
|
|
|
{
|
|
|
|
return (XFUSE_HANDLE *) (tintptr) handle;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/*****************************************************************************
|
|
|
|
** **
|
|
|
|
** public functions - can be called from any code path **
|
|
|
|
** **
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize FUSE subsystem
|
|
|
|
*
|
2020-08-22 20:05:24 +03:00
|
|
|
* @return 0 on success, -1 on failure, 1 for feature disabled
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-04-20 04:08:55 +04:00
|
|
|
xfuse_init(void)
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2013-03-19 06:43:20 +04:00
|
|
|
struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
|
2012-11-04 05:47:04 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/* if already inited, just return */
|
|
|
|
if (g_xfuse_inited)
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "already inited");
|
2020-08-22 20:05:24 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This feature may be disabled */
|
|
|
|
if (!g_cfg->enable_fuse_mount)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Only log the 'disabled mounts' message one time
|
|
|
|
*/
|
|
|
|
static int disabled_mounts_msg_shown = 0;
|
|
|
|
if (!disabled_mounts_msg_shown)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_INFO, "FUSE mounts are disabled by config");
|
|
|
|
disabled_mounts_msg_shown = 1;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_ch != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "g_ch is not zero");
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-04-20 04:08:55 +04:00
|
|
|
load_fuse_config();
|
|
|
|
|
2020-08-22 20:05:24 +03:00
|
|
|
/* define FUSE mount point */
|
|
|
|
if (g_cfg->fuse_mount_name[0] == '/')
|
|
|
|
{
|
|
|
|
/* String is an absolute path to the mount point containing
|
|
|
|
* %u or %U characters */
|
|
|
|
format_user_info(g_fuse_root_path, sizeof(g_fuse_root_path),
|
|
|
|
g_cfg->fuse_mount_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* mount_name is relative to $HOME, e.g. ~/xrdp_client,
|
|
|
|
* or ~/thinclient_drives */
|
|
|
|
g_snprintf(g_fuse_root_path, sizeof(g_fuse_root_path), "%s/%s",
|
|
|
|
g_getenv("HOME"), g_cfg->fuse_mount_name);
|
|
|
|
}
|
2013-04-27 05:55:28 +04:00
|
|
|
g_snprintf(g_fuse_clipboard_path, 255, "%s/.clipboard", g_fuse_root_path);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* if FUSE mount point does not exist, create it */
|
|
|
|
if (!g_directory_exist(g_fuse_root_path))
|
|
|
|
{
|
2020-08-22 20:05:24 +03:00
|
|
|
(void)g_create_path(g_fuse_root_path);
|
2013-03-09 03:37:30 +04:00
|
|
|
if (!g_create_dir(g_fuse_root_path))
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "mkdir %s failed. If %s is already mounted, you must "
|
2013-03-09 03:37:30 +04:00
|
|
|
"first unmount it", g_fuse_root_path, g_fuse_root_path);
|
|
|
|
return -1;
|
2012-11-04 05:47:04 +04:00
|
|
|
}
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup xrdp file system */
|
|
|
|
if (xfuse_init_xrdp_fs())
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* setup FUSE callbacks */
|
|
|
|
g_memset(&g_xfuse_ops, 0, sizeof(g_xfuse_ops));
|
2013-08-12 05:06:39 +04:00
|
|
|
g_xfuse_ops.lookup = xfuse_cb_lookup;
|
|
|
|
g_xfuse_ops.readdir = xfuse_cb_readdir;
|
|
|
|
g_xfuse_ops.mkdir = xfuse_cb_mkdir;
|
2019-11-14 17:43:57 +03:00
|
|
|
g_xfuse_ops.rmdir = xfuse_cb_unlink;
|
2013-08-12 05:06:39 +04:00
|
|
|
g_xfuse_ops.unlink = xfuse_cb_unlink;
|
|
|
|
g_xfuse_ops.rename = xfuse_cb_rename;
|
|
|
|
g_xfuse_ops.open = xfuse_cb_open;
|
|
|
|
g_xfuse_ops.release = xfuse_cb_release;
|
|
|
|
g_xfuse_ops.read = xfuse_cb_read;
|
|
|
|
g_xfuse_ops.write = xfuse_cb_write;
|
|
|
|
g_xfuse_ops.create = xfuse_cb_create;
|
2013-05-21 23:57:06 +04:00
|
|
|
//g_xfuse_ops.fsync = xfuse_cb_fsync; /* LK_TODO delete this */
|
2013-08-12 05:06:39 +04:00
|
|
|
g_xfuse_ops.getattr = xfuse_cb_getattr;
|
|
|
|
g_xfuse_ops.setattr = xfuse_cb_setattr;
|
|
|
|
g_xfuse_ops.opendir = xfuse_cb_opendir;
|
|
|
|
g_xfuse_ops.releasedir = xfuse_cb_releasedir;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
fuse_opt_add_arg(&args, "xrdp-chansrv");
|
|
|
|
fuse_opt_add_arg(&args, g_fuse_root_path);
|
2013-09-25 04:19:10 +04:00
|
|
|
//fuse_opt_add_arg(&args, "-s"); /* single threaded mode */
|
|
|
|
//fuse_opt_add_arg(&args, "-d"); /* debug mode */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
if (xfuse_init_lib(&args))
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
|
|
|
xfuse_deinit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_xfuse_inited = 1;
|
2012-11-04 05:47:04 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* De-initialize FUSE subsystem
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2014-04-20 04:08:55 +04:00
|
|
|
xfuse_deinit(void)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
if (g_ch != 0)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_session_remove_chan(g_ch);
|
|
|
|
fuse_unmount(g_mount_point, g_ch);
|
|
|
|
g_ch = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_se != 0)
|
|
|
|
{
|
|
|
|
fuse_session_destroy(g_se);
|
|
|
|
g_se = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_buffer != 0)
|
|
|
|
{
|
|
|
|
g_free(g_buffer);
|
|
|
|
g_buffer = 0;
|
2012-11-04 05:47:04 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-04-27 05:55:28 +04:00
|
|
|
if (g_req_list != 0)
|
|
|
|
{
|
|
|
|
list_delete(g_req_list);
|
|
|
|
g_req_list = 0;
|
|
|
|
}
|
|
|
|
|
2019-02-26 16:22:30 +03:00
|
|
|
xfuse_deinit_xrdp_fs();
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
g_xfuse_inited = 0;
|
2012-11-04 05:47:04 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
int xfuse_check_wait_objs(void)
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
struct fuse_chan *tmpch;
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
if (g_ch == 0)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (g_tcp_select(g_fd, 0) & 1)
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
tmpch = g_ch;
|
|
|
|
|
|
|
|
rval = fuse_chan_recv(&tmpch, g_buffer, g_bufsize);
|
|
|
|
if (rval == -EINTR)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (rval == -ENODEV)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
if (rval <= 0)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
fuse_session_process(g_se, g_buffer, rval, tmpch);
|
2012-11-04 05:47:04 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
int xfuse_get_wait_objs(tbus *objs, int *count, int *timeout)
|
|
|
|
{
|
|
|
|
int lcount;
|
|
|
|
|
|
|
|
if (g_ch == 0)
|
2020-11-30 03:36:20 +03:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
lcount = *count;
|
|
|
|
objs[lcount] = g_fd;
|
|
|
|
lcount++;
|
|
|
|
*count = lcount;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create specified share directory.
|
|
|
|
*
|
|
|
|
* This code gets called from devredir
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-01-22 21:27:50 +03:00
|
|
|
int xfuse_create_share(tui32 device_id, const char *dirname)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
int result = -1;
|
|
|
|
XFS_INODE *xinode;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (dirname != NULL && strlen(dirname) > 0 &&
|
2020-11-30 03:36:20 +03:00
|
|
|
xfuse_init_xrdp_fs() == 0)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
xinode = xfs_add_entry(g_xfs, FUSE_ROOT_ID, dirname, (0777 | S_IFDIR));
|
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xfs_add_entry() failed");
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-03 19:16:09 +03:00
|
|
|
xinode->is_redirected = 1;
|
2019-11-14 17:43:57 +03:00
|
|
|
xinode->device_id = device_id;
|
|
|
|
result = 0;
|
|
|
|
}
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
return result;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/**
|
|
|
|
* @brief Remove specified share directory.
|
|
|
|
*
|
|
|
|
* This code gets called from devredir
|
|
|
|
*****************************************************************************/
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_delete_share(tui32 device_id)
|
|
|
|
{
|
2020-03-03 19:16:09 +03:00
|
|
|
xfs_delete_redirected_entries_with_device_id(g_xfs, device_id);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
2013-04-27 05:55:28 +04:00
|
|
|
* Clear all clipboard entries in xrdp_fs
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
2013-04-27 05:55:28 +04:00
|
|
|
* This function is called by clipboard code
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
int xfuse_clear_clip_dir(void)
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
int result = 0;
|
2013-04-27 05:55:28 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (g_xfs != NULL && g_clipboard_inum > 0)
|
2015-12-27 04:22:27 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
xfs_remove_directory_contents(g_xfs, g_clipboard_inum);
|
2013-04-27 05:55:28 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
return result;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-27 05:55:28 +04:00
|
|
|
* Return clipboard data to fuse
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-01-22 21:27:50 +03:00
|
|
|
int
|
|
|
|
xfuse_file_contents_range(int stream_id, const char *data, int data_bytes)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: stream_id=%d data_bytes=%d", stream_id, data_bytes);
|
2013-04-27 05:55:28 +04:00
|
|
|
|
|
|
|
struct req_list_item *rli;
|
|
|
|
|
|
|
|
if ((rli = (struct req_list_item *) list_get_item(g_req_list, 0)) == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "range error!");
|
2013-04-27 05:55:28 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "lindex=%d off=%d size=%d", rli->lindex, rli->off, rli->size);
|
2013-04-27 05:55:28 +04:00
|
|
|
|
|
|
|
fuse_reply_buf(rli->req, data, data_bytes);
|
|
|
|
|
|
|
|
list_remove_item(g_req_list, 0);
|
|
|
|
if (g_req_list->count <= 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "completed all requests");
|
2013-04-27 05:55:28 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send next request */
|
|
|
|
rli = (struct req_list_item *) list_get_item(g_req_list, 0);
|
|
|
|
if (rli == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "range error!");
|
2013-04-27 05:55:28 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "requesting clipboard file data");
|
2013-04-27 05:55:28 +04:00
|
|
|
|
|
|
|
clipboard_request_file_data(rli->stream_id, rli->lindex,
|
2020-11-30 03:36:20 +03:00
|
|
|
rli->off, rli->size);
|
2013-04-27 05:55:28 +04:00
|
|
|
|
|
|
|
return 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-27 05:55:28 +04:00
|
|
|
* Create a file in .clipboard dir
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
2013-04-27 05:55:28 +04:00
|
|
|
* This function is called by clipboard code
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-01-22 21:27:50 +03:00
|
|
|
int
|
|
|
|
xfuse_add_clip_dir_item(const char *filename, int flags, int size, int lindex)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-08-22 20:05:24 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG,
|
|
|
|
"entered: filename=%s flags=%d size=%d lindex=%d",
|
2013-04-27 05:55:28 +04:00
|
|
|
filename, flags, size, lindex);
|
|
|
|
|
2020-08-22 20:05:24 +03:00
|
|
|
int result = -1;
|
|
|
|
|
|
|
|
if (g_xfs == NULL)
|
2016-07-21 10:02:21 +03:00
|
|
|
{
|
2020-08-22 20:05:24 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR,
|
2021-02-04 13:11:54 +03:00
|
|
|
"xfuse_add_clip_dir_item() called with no filesystem");
|
2020-08-22 20:05:24 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* add entry to xrdp_fs */
|
|
|
|
XFS_INODE *xinode = xfs_add_entry( g_xfs,
|
|
|
|
g_clipboard_inum, /* parent inode */
|
|
|
|
filename,
|
|
|
|
(0666 | S_IFREG));
|
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_INFO,
|
|
|
|
"failed to create file %s in xrdp filesystem", filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xinode->size = size;
|
|
|
|
xinode->lindex = lindex;
|
|
|
|
result = 0;
|
|
|
|
}
|
2016-07-21 10:02:21 +03:00
|
|
|
}
|
2013-04-27 05:55:28 +04:00
|
|
|
|
2020-08-22 20:05:24 +03:00
|
|
|
return result;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
int xfuse_file_contents_size(int stream_id, int file_size)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: stream_id=%d file_size=%d", stream_id, file_size);
|
2013-04-27 05:55:28 +04:00
|
|
|
return 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** **
|
|
|
|
** private functions - can only be called from within this file **
|
|
|
|
** **
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize FUSE library
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
static int xfuse_init_lib(struct fuse_args *args)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-19 06:43:20 +04:00
|
|
|
if (fuse_parse_cmdline(args, &g_mount_point, 0, 0) < 0)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "fuse_parse_cmdline() failed");
|
2013-03-19 06:43:20 +04:00
|
|
|
fuse_opt_free_args(args);
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
if ((g_ch = fuse_mount(g_mount_point, args)) == 0)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "fuse_mount() failed");
|
2013-03-19 06:43:20 +04:00
|
|
|
fuse_opt_free_args(args);
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
g_se = fuse_lowlevel_new(args, &g_xfuse_ops, sizeof(g_xfuse_ops), 0);
|
2013-03-09 03:37:30 +04:00
|
|
|
if (g_se == 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "fuse_lowlevel_new() failed");
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_unmount(g_mount_point, g_ch);
|
|
|
|
g_ch = 0;
|
2013-03-19 06:43:20 +04:00
|
|
|
fuse_opt_free_args(args);
|
2013-03-09 03:37:30 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-03-19 06:43:20 +04:00
|
|
|
fuse_opt_free_args(args);
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_session_add_chan(g_se, g_ch);
|
|
|
|
g_bufsize = fuse_chan_bufsize(g_ch);
|
|
|
|
|
2016-11-16 06:44:24 +03:00
|
|
|
g_buffer = g_new0(char, g_bufsize);
|
2013-03-09 03:37:30 +04:00
|
|
|
g_fd = fuse_chan_fd(g_ch);
|
|
|
|
|
2013-04-27 05:55:28 +04:00
|
|
|
g_req_list = list_create();
|
|
|
|
g_req_list->auto_free = 1;
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Initialize xrdp file system
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-12-23 20:52:22 +03:00
|
|
|
static int xfuse_init_xrdp_fs(void)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xino;
|
|
|
|
int result = -1;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2017-07-31 13:06:49 +03:00
|
|
|
/* Already called? */
|
2019-11-14 17:43:57 +03:00
|
|
|
if (g_xfs != NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
result = 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((g_xfs = xfs_create_xfs_fs(0, g_getuid(), g_getgid())) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Need a top-level .clipboard directory */
|
|
|
|
xino = xfs_add_entry(g_xfs, FUSE_ROOT_ID, ".clipboard",
|
|
|
|
(0777 | S_IFDIR));
|
|
|
|
if (xino == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
xfs_delete_xfs_fs(g_xfs);
|
|
|
|
g_xfs = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clipboard_inum = xino->inum;
|
|
|
|
result = 0;
|
2020-11-30 03:36:20 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
return result;
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* zap the xrdp file system
|
|
|
|
*
|
|
|
|
* @return 0 on success, -1 on failure
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-12-23 20:52:22 +03:00
|
|
|
static int xfuse_deinit_xrdp_fs(void)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
xfs_delete_xfs_fs(g_xfs);
|
|
|
|
g_xfs = NULL;
|
|
|
|
g_clipboard_inum = 0;
|
2019-02-26 16:22:30 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/******************************************************************************
|
|
|
|
** **
|
|
|
|
** callbacks for devredir **
|
|
|
|
** **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* Add a file or directory to xrdp file system as part of a
|
|
|
|
* directory request
|
2013-03-09 03:37:30 +04:00
|
|
|
*
|
2019-11-14 17:43:57 +03:00
|
|
|
* If the file or directory already exists, no changes are made to it.
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_enum_dir_add_entry(
|
2020-11-30 03:36:20 +03:00
|
|
|
struct state_dirscan *fip,
|
|
|
|
const char *name,
|
|
|
|
const struct file_attr *fattr)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode = NULL;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (!xfs_get(g_xfs, fip->pinum))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", fip->pinum);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else if ((strcmp(name, ".") == 0) ||
|
|
|
|
(strcmp(name, "..") == 0))
|
|
|
|
{
|
|
|
|
; /* filename is . or .. - don't add it */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "parent_inode=%ld name=%s", fip->pinum, name);
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/* Does the file already exist ? If it does it's important we
|
|
|
|
* don't mess with it, as we're only enumerating the directory, and
|
|
|
|
* we don't want to disrupt any existing operations on the file
|
|
|
|
*/
|
|
|
|
xinode = xfs_lookup_in_dir(g_xfs, fip->pinum, name);
|
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
|
|
|
/* Add a new node to the file system */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Creating name=%s in parent=%ld in xrdp_fs",
|
2019-11-14 17:43:57 +03:00
|
|
|
name, fip->pinum);
|
|
|
|
xinode = xfs_add_entry(g_xfs, fip->pinum, name, fattr->mode);
|
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "xfs_add_entry() failed");
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xinode->size = fattr->size;
|
|
|
|
xinode->atime = fattr->atime;
|
|
|
|
xinode->mtime = fattr->mtime;
|
|
|
|
/* Initially, set the attribute change time to the file data
|
|
|
|
change time */
|
|
|
|
xinode->ctime = fattr->mtime;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* device_id is inherited from parent */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* This routine is called by devredir when the opendir request has
|
|
|
|
* completed
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_enum_dir_done(struct state_dirscan *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "fip=%p IoStatus=0x%x", fip, IoStatus);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
2019-12-19 12:55:38 +03:00
|
|
|
* STATUS_NO_SUCH_FILE is returned for empty directories
|
2019-11-14 17:43:57 +03:00
|
|
|
*/
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS && IoStatus != STATUS_NO_SUCH_FILE)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
int status;
|
|
|
|
switch (IoStatus)
|
|
|
|
{
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_ACCESS_DENIED:
|
2019-11-14 17:43:57 +03:00
|
|
|
status = EACCES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = ENOENT;
|
|
|
|
}
|
|
|
|
fuse_reply_err(fip->req, status);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (!xfs_get(g_xfs, fip->pinum))
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", fip->pinum);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
}
|
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
struct fuse_file_info *fi = &fip->fi;
|
2020-09-15 18:37:56 +03:00
|
|
|
XFUSE_HANDLE *xhandle = xfuse_handle_create();
|
2020-11-30 03:36:20 +03:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
if (xhandle == NULL
|
2020-11-30 03:36:20 +03:00
|
|
|
|| (xhandle->dir_handle = xfs_opendir(g_xfs, fip->pinum)) == NULL)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
2020-09-15 18:37:56 +03:00
|
|
|
xfuse_handle_delete(xhandle);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, ENOMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-15 18:37:56 +03:00
|
|
|
fi->fh = xfuse_handle_to_fuse_handle(xhandle);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_open(fip->req, &fip->fi);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
free(fip);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-11-30 03:36:20 +03:00
|
|
|
* This routine is caused as a result of a devredir remote lookup
|
2019-11-14 17:43:57 +03:00
|
|
|
* instigated by xfuse_cb_lookup()
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_lookup_entry(struct state_lookup *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
const struct file_attr *file_info)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode = NULL;
|
2013-03-31 02:51:50 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
switch (IoStatus)
|
|
|
|
{
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_SHARING_VIOLATION:
|
2020-11-30 03:36:20 +03:00
|
|
|
/* This can happen when trying to read the attributes of
|
|
|
|
* some system files (e.g. pagefile.sys) */
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_ACCESS_DENIED:
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, EACCES);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_UNSUCCESSFUL:
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Happens if we try to lookup an illegal filename (e.g.
|
|
|
|
* one with a '*' in it) */
|
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
break;
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_NO_SUCH_FILE:
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Remove our copy, if any */
|
2020-11-30 03:36:20 +03:00
|
|
|
if (fip->existing_inum &&
|
|
|
|
(xinode = xfs_get(g_xfs, fip->existing_inum)) != NULL &&
|
|
|
|
xinode->generation == fip->existing_generation)
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
xfs_remove_entry(g_xfs, fip->existing_inum);
|
|
|
|
}
|
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
break;
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "Error code %08x - fallthrough", (int) IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, EIO);
|
|
|
|
break;
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (!xfs_get(g_xfs, fip->pinum))
|
2013-08-10 06:43:45 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "parent inode %ld is not valid", fip->pinum);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
else
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "parent_inode=%ld name=%s", fip->pinum, fip->name);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
/* Does the file already exist ? */
|
2019-11-14 17:43:57 +03:00
|
|
|
xinode = xfs_lookup_in_dir(g_xfs, fip->pinum, fip->name);
|
2019-03-21 19:48:01 +03:00
|
|
|
if (xinode != NULL)
|
|
|
|
{
|
|
|
|
/* Is the existing file the same type ? */
|
|
|
|
if ((xinode->mode & (S_IFREG | S_IFDIR)) ==
|
2020-11-30 03:36:20 +03:00
|
|
|
(file_info->mode & (S_IFREG | S_IFDIR)))
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "inode=%ld name=%s already exists in xrdp_fs as %ld",
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->pinum, fip->name, xinode->inum);
|
|
|
|
if (xfs_get_file_open_count(g_xfs, xinode->inum) > 0)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Don't mess with open files. The local attributes are
|
|
|
|
* almost certainly more up-to-date. A worst case scenario
|
|
|
|
* would be truncating a file we're currently writing
|
|
|
|
* to, as the lookup value for the size is stale.
|
|
|
|
*/
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "inode=%ld is open - "
|
2019-11-14 17:43:57 +03:00
|
|
|
"preferring local attributes", xinode->inum);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Updating attributes of inode=%ld", xinode->inum);
|
2019-11-14 17:43:57 +03:00
|
|
|
update_inode_file_attributes(file_info, TO_SET_ALL, xinode);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Type has changed from file to directory, or vice-versa */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "inode=%ld name=%s of different type in xrdp_fs"
|
2019-11-14 17:43:57 +03:00
|
|
|
" - removing",
|
|
|
|
fip->pinum, xinode->name);
|
|
|
|
xfs_remove_entry(g_xfs, xinode->inum);
|
2019-03-21 19:48:01 +03:00
|
|
|
xinode = NULL;
|
|
|
|
}
|
|
|
|
}
|
2013-08-12 05:06:39 +04:00
|
|
|
|
2019-03-21 19:48:01 +03:00
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
|
|
|
/* Add a new node to the file system */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Creating name=%s in parent=%ld in xrdp_fs",
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->name, fip->pinum);
|
|
|
|
xinode = xfs_add_entry(g_xfs, fip->pinum, fip->name,
|
|
|
|
file_info->mode);
|
2019-03-21 19:48:01 +03:00
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "xfs_add_entry() failed");
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
xinode->size = file_info->size;
|
|
|
|
xinode->atime = file_info->atime;
|
|
|
|
xinode->mtime = file_info->mtime;
|
|
|
|
/* Initially, set the attribute change time to the file data
|
|
|
|
change time */
|
|
|
|
xinode->ctime = file_info->mtime;
|
|
|
|
/* device_id is inherited from parent */
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xinode != NULL)
|
|
|
|
{
|
|
|
|
make_fuse_entry_reply(fip->req, xinode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fuse_reply_err(fip->req, EIO);
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine is caused as a result of a devredir remote setattr
|
|
|
|
* instigated by xfuse_cb_setattr()
|
|
|
|
*****************************************************************************/
|
|
|
|
void xfuse_devredir_cb_setattr(struct state_setattr *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
|
|
|
{
|
|
|
|
XFS_INODE *xinode;
|
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
|
|
|
switch (IoStatus)
|
|
|
|
{
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_SHARING_VIOLATION:
|
2020-11-30 03:36:20 +03:00
|
|
|
/* This can happen when trying to read the attributes of
|
|
|
|
* some system files (e.g. pagefile.sys) */
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_ACCESS_DENIED:
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, EACCES);
|
|
|
|
break;
|
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_UNSUCCESSFUL:
|
2020-11-30 03:36:20 +03:00
|
|
|
/* Happens if we try to lookup an illegal filename */
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_NO_SUCH_FILE:
|
2019-03-21 19:48:01 +03:00
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "Error code %08x - fallthrough", (int) IoStatus);
|
2019-03-21 19:48:01 +03:00
|
|
|
fuse_reply_err(fip->req, EIO);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((xinode = xfs_get(g_xfs, fip->inum)) == NULL)
|
|
|
|
{
|
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
}
|
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
update_inode_file_attributes(&fip->fattr, fip->change_mask, xinode);
|
|
|
|
make_fuse_attr_reply(fip->req, xinode);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
free(fip);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/**
|
|
|
|
* This routine is caused as a result of a file or directory
|
|
|
|
* create request */
|
|
|
|
void xfuse_devredir_cb_create_file(struct state_create *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
tui32 DeviceId, tui32 FileId)
|
|
|
|
{
|
|
|
|
XFUSE_HANDLE *fh = NULL;
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2013-06-09 05:44:21 +04:00
|
|
|
if (IoStatus != 0)
|
|
|
|
{
|
|
|
|
switch (IoStatus)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
case STATUS_ACCESS_DENIED:
|
|
|
|
fuse_reply_err(fip->req, EACCES);
|
|
|
|
break;
|
2013-06-09 05:44:21 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case STATUS_OBJECT_NAME_INVALID:
|
|
|
|
case STATUS_OBJECT_NAME_NOT_FOUND:
|
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
break;
|
2013-06-09 05:44:21 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
default:
|
|
|
|
fuse_reply_err(fip->req, EIO);
|
|
|
|
break;
|
2013-06-09 05:44:21 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((fip->mode & S_IFREG) != 0)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* We've created a regular file */
|
|
|
|
/* Allocate an XFUSE_HANDLE for future file operations */
|
2020-09-15 18:37:56 +03:00
|
|
|
if ((fh = xfuse_handle_create()) != NULL)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
/* save file handle for later use */
|
|
|
|
fh->DeviceId = DeviceId;
|
|
|
|
fh->FileId = FileId;
|
2013-06-09 05:44:21 +04:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
fip->fi.fh = xfuse_handle_to_fuse_handle(fh);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((fip->mode & S_IFREG) != 0 && fh == NULL)
|
2019-03-04 18:52:49 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* We failed to allocate a file handle */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-03-04 18:52:49 +03:00
|
|
|
fuse_reply_err(fip->req, ENOMEM);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
|
|
|
/* create entry in xrdp file system */
|
|
|
|
xinode = xfs_add_entry(g_xfs, fip->pinum, fip->name, fip->mode);
|
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
|
|
|
/* It's possible xfs_add_entry() has failed, as the
|
|
|
|
* file has already been added (by a lookup request)
|
|
|
|
* in the time between our request and the response
|
|
|
|
* This can happen if an 'ls' is happening in the same
|
|
|
|
* directory as this file is being created.
|
|
|
|
*
|
|
|
|
* We'll check for this before we fail the create */
|
|
|
|
if ((xinode = xfs_lookup_in_dir(g_xfs,
|
|
|
|
fip->pinum,
|
|
|
|
fip->name)) != NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The mode should be correct anyway, but we'll
|
|
|
|
* set it to the mode requested at creation
|
|
|
|
*/
|
|
|
|
xinode->mode = fip->mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xinode == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Out of memory!");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, ENOMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((fip->mode & S_IFDIR) != 0)
|
|
|
|
{
|
|
|
|
make_fuse_entry_reply(fip->req, xinode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct fuse_entry_param e;
|
|
|
|
xfs_inode_to_fuse_entry_param(xinode, &e);
|
|
|
|
fuse_reply_create(fip->req, &e, &fip->fi);
|
|
|
|
xfs_increment_file_open_count(g_xfs, xinode->inum);
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2020-10-08 04:55:08 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This routine is caused as a result of a file open request */
|
|
|
|
void xfuse_devredir_cb_open_file(struct state_open *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
tui32 DeviceId, tui32 FileId)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFUSE_HANDLE *fh;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (IoStatus != 0)
|
2013-05-21 23:57:06 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
switch (IoStatus)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
case STATUS_ACCESS_DENIED:
|
|
|
|
fuse_reply_err(fip->req, EACCES);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
case STATUS_OBJECT_NAME_INVALID:
|
|
|
|
case STATUS_OBJECT_NAME_NOT_FOUND:
|
|
|
|
fuse_reply_err(fip->req, ENOENT);
|
|
|
|
break;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
default:
|
|
|
|
fuse_reply_err(fip->req, EIO);
|
|
|
|
break;
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-05-21 23:57:06 +04:00
|
|
|
}
|
2019-03-13 13:56:37 +03:00
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Allocate an XFUSE_HANDLE for future file operations */
|
2020-09-15 18:37:56 +03:00
|
|
|
if ((fh = xfuse_handle_create()) == NULL)
|
2019-03-13 13:56:37 +03:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, ENOMEM);
|
2019-03-13 13:56:37 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* save file handle for later use */
|
|
|
|
fh->DeviceId = DeviceId;
|
|
|
|
fh->FileId = FileId;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
fip->fi.fh = xfuse_handle_to_fuse_handle(fh);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "sending fuse_reply_open(); "
|
2019-11-14 17:43:57 +03:00
|
|
|
"DeviceId=%d FileId=%d req=%p",
|
|
|
|
fh->DeviceId, fh->FileId, fip->req);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* update open count */
|
|
|
|
xfs_increment_file_open_count(g_xfs, fip->inum);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_open(fip->req, &fip->fi);
|
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
free(fip);
|
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_read_file(struct state_read *fip,
|
2020-03-03 13:02:32 +03:00
|
|
|
enum NTSTATUS IoStatus,
|
2019-11-14 17:43:57 +03:00
|
|
|
const char *buf, size_t length)
|
|
|
|
{
|
2020-03-03 13:02:32 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Read NTSTATUS is %d", (int) IoStatus);
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(fip->req, EIO);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fuse_reply_buf(fip->req, buf, length);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_write_file(
|
2020-11-30 03:36:20 +03:00
|
|
|
struct state_write *fip,
|
|
|
|
enum NTSTATUS IoStatus,
|
|
|
|
off_t offset,
|
|
|
|
size_t length)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Write NTSTATUS is %d", (int) IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, EIO);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2019-12-05 19:44:52 +03:00
|
|
|
off_t new_size = offset + length;
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_write(fip->req, length);
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* update file size */
|
|
|
|
if ((xinode = xfs_get(g_xfs, fip->inum)) != NULL)
|
2014-07-21 03:36:33 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
if (new_size > xinode->size)
|
|
|
|
{
|
|
|
|
xinode->size = new_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is invalid", fip->inum);
|
2014-07-21 03:36:33 +04:00
|
|
|
}
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_rmdir_or_file(struct state_remove *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode = xfs_get(g_xfs, fip->inum);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
switch (IoStatus)
|
2013-05-21 23:57:06 +04:00
|
|
|
{
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_SUCCESS:
|
|
|
|
case STATUS_NO_SUCH_FILE:
|
2019-11-14 17:43:57 +03:00
|
|
|
xfs_remove_entry(g_xfs, xinode->inum); /* Remove local copy */
|
|
|
|
fuse_reply_err(fip->req, 0);
|
|
|
|
break;
|
2013-05-21 23:57:06 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
case STATUS_SHARING_VIOLATION:
|
|
|
|
case STATUS_ACCESS_DENIED:
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, EACCES);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "Error code %08x - fallthrough", (int) IoStatus);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, EBADF);
|
|
|
|
break;
|
2013-05-21 23:57:06 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
free(fip);
|
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
void xfuse_devredir_cb_rename_file(struct state_rename *fip,
|
|
|
|
enum NTSTATUS IoStatus)
|
|
|
|
{
|
|
|
|
int status;
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2019-12-19 12:55:38 +03:00
|
|
|
if (IoStatus != STATUS_SUCCESS)
|
2013-05-20 04:23:18 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
status =
|
2019-12-19 12:55:38 +03:00
|
|
|
(IoStatus == STATUS_SHARING_VIOLATION) ? EBUSY :
|
|
|
|
(IoStatus == STATUS_ACCESS_DENIED) ? EACCES :
|
2020-11-30 03:36:20 +03:00
|
|
|
/* default */ EEXIST ;
|
2013-05-20 04:23:18 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-05-06 05:42:17 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
status = xfs_move_entry(g_xfs, fip->pinum,
|
|
|
|
fip->new_pinum, fip->name);
|
2013-05-06 05:42:17 +04:00
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(fip->req, status);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void xfuse_devredir_cb_file_close(struct state_close *fip)
|
|
|
|
{
|
2013-03-19 06:43:20 +04:00
|
|
|
fuse_reply_err(fip->req, 0);
|
2019-11-14 17:43:57 +03:00
|
|
|
xfs_decrement_file_open_count(g_xfs, fip->inum);
|
|
|
|
|
|
|
|
free(fip);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/******************************************************************************
|
|
|
|
** **
|
|
|
|
** callbacks for fuse **
|
|
|
|
** **
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up a directory entry by name and get its attributes
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_cb_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *parent_xinode;
|
|
|
|
XFS_INODE *xinode = NULL;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "looking for parent=%ld name=%s", parent, name);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (strlen(name) > XFS_MAXFILENAMELEN)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENAMETOOLONG);
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((parent_xinode = xfs_get(g_xfs, parent)) == NULL)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", parent);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
else
|
|
|
|
{
|
2020-03-03 19:16:09 +03:00
|
|
|
if (!parent_xinode->is_redirected)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* File cannot be remote - we either know about it or we don't */
|
|
|
|
if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) != NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "found entry for parent=%ld name=%s",
|
2019-11-14 17:43:57 +03:00
|
|
|
parent, name);
|
|
|
|
make_fuse_entry_reply(req, xinode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fuse_reply_err(req, ENOENT);
|
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* specified file resides on redirected share
|
|
|
|
*
|
|
|
|
* We always look these up, and relying on libfuse to do sane
|
|
|
|
* caching */
|
|
|
|
struct state_lookup *fip = g_new0(struct state_lookup, 1);
|
|
|
|
char *full_path = get_name_for_entry_in_parent(parent, name);
|
|
|
|
|
|
|
|
if (fip == NULL || full_path == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
free(full_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
fip->pinum = parent;
|
|
|
|
strcpy(fip->name, name);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(full_path);
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* If the file already exists on our side, save the inum
|
|
|
|
* and generation. If it's not remote any more this means we
|
|
|
|
* can remove it when we get the response
|
|
|
|
*/
|
|
|
|
if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) != NULL)
|
|
|
|
{
|
|
|
|
fip->existing_inum = xinode->inum;
|
|
|
|
fip->existing_generation = xinode->generation;
|
|
|
|
}
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Looking up %s in %s on %d", name, cptr,
|
2020-11-30 03:36:20 +03:00
|
|
|
parent_xinode->device_id);
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_lookup_entry()
|
|
|
|
*/
|
|
|
|
if (devredir_lookup_entry(fip, parent_xinode->device_id, cptr))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_lookup_entry() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EREMOTEIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
free(full_path);
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Get file attributes
|
2019-11-14 17:43:57 +03:00
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_cb_getattr(fuse_req_t req, fuse_ino_t ino,
|
2020-11-30 03:36:20 +03:00
|
|
|
struct fuse_file_info *fi)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xino;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "req=%p ino=%ld", req, ino);
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/* if ino is not valid, just return */
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((xino = xfs_get(g_xfs, ino)) == NULL)
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", ino);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2012-11-04 05:47:04 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-09-25 04:19:10 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
make_fuse_attr_reply(req, xino);
|
2013-09-25 04:19:10 +04:00
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Adds an entry to the buffer, using fuse_add_direnty()
|
|
|
|
*
|
|
|
|
* Returns 1 for success, or zero if the entry couldn't be added
|
|
|
|
*/
|
2013-04-21 03:42:49 +04:00
|
|
|
static int xfuse_dirbuf_add1(fuse_req_t req, struct dirbuf1 *b,
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode, off_t offset)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
|
|
|
struct stat stbuf;
|
2019-11-14 17:43:57 +03:00
|
|
|
size_t len;
|
|
|
|
int result = 0;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
|
|
|
memset(&stbuf, 0, sizeof(stbuf));
|
2019-11-14 17:43:57 +03:00
|
|
|
stbuf.st_ino = xinode->inum;
|
2020-07-06 13:53:56 +03:00
|
|
|
stbuf.st_mode = xinode->mode & ~g_cfg->file_umask;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Try to add the entry. From the docs for fuse_add_direntry():-
|
|
|
|
* "Buffer needs to be large enough to hold the entry. If it's not,
|
|
|
|
* then the entry is not filled in but the size of the entry is
|
|
|
|
* still returned."
|
|
|
|
*/
|
|
|
|
len = fuse_add_direntry(req,
|
2020-11-30 03:36:20 +03:00
|
|
|
&b->buf[b->len], /* index where new entry will be added to buf */
|
|
|
|
sizeof(b->buf) - b->len, /* Space left */
|
|
|
|
xinode->name, /* name of entry */
|
|
|
|
&stbuf, /* file attributes */
|
|
|
|
offset /* offset of next entry */
|
|
|
|
);
|
2019-11-14 17:43:57 +03:00
|
|
|
if (len + b->len <= sizeof(b->buf))
|
|
|
|
{
|
|
|
|
/* Entry fitted in OK */
|
|
|
|
b->len += len;
|
|
|
|
result = 1;
|
|
|
|
}
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
return result;
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
|
|
|
|
off_t off, struct fuse_file_info *fi)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2020-09-15 18:37:56 +03:00
|
|
|
XFUSE_HANDLE *xhandle;
|
2019-11-14 17:43:57 +03:00
|
|
|
struct xfs_dir_handle *dh;
|
2013-08-12 05:06:39 +04:00
|
|
|
struct dirbuf1 b;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "req=%p inode=%ld size=%zd offset=%lld", req, ino, size, (long long) off);
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* On the first call, check the inode is valid */
|
|
|
|
if (off == 0 && !xfs_get(g_xfs, ino))
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", ino);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
2020-09-15 18:37:56 +03:00
|
|
|
else if ((xhandle = xfuse_handle_from_fuse_handle(fi->fh)) == NULL
|
2020-11-30 03:36:20 +03:00
|
|
|
|| (dh = xhandle->dir_handle) == NULL)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2013-08-12 05:06:39 +04:00
|
|
|
/* something seriously wrong somewhere! */
|
|
|
|
fuse_reply_buf(req, 0, 0);
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
b.len = 0;
|
2013-04-21 03:42:49 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
off_t new_off = off;
|
|
|
|
while ((xinode = xfs_readdir(g_xfs, dh, &new_off)) != NULL)
|
2013-04-21 03:42:49 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
if (xfuse_dirbuf_add1(req, &b, xinode, new_off) == 0)
|
2013-09-25 04:19:10 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
break; /* buffer is full */
|
2013-09-25 04:19:10 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Make sure we get the next entry next time */
|
|
|
|
off = new_off;
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
2013-08-12 05:06:39 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_buf(req, b.buf, b.len);
|
2013-04-21 03:42:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Create a directory
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_cb_mkdir(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name, mode_t mode)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: parent_inode=%ld name=%s", parent, name);
|
2013-05-20 04:23:18 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) != NULL)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
/* dir already exists, just return it */
|
2019-11-14 17:43:57 +03:00
|
|
|
make_fuse_entry_reply(req, xinode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* dir does not exist, create it */
|
|
|
|
xfuse_create_dir_or_file(req, parent, name, mode | S_IFDIR, NULL);
|
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a dir or file
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void xfuse_cb_unlink(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: parent=%ld name=%s", parent, name);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (strlen(name) > XFS_MAXFILENAMELEN)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENAMETOOLONG);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((xinode = xfs_lookup_in_dir(g_xfs, parent, name)) == NULL)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "did not find file with pinode=%ld name=%s", parent, name);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((xinode->mode & S_IFDIR) != 0 &&
|
|
|
|
!xfs_is_dir_empty(g_xfs, xinode->inum))
|
2012-11-05 01:52:33 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "cannot rmdir; directory is not empty");
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_reply_err(req, ENOTEMPTY);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
2012-11-05 01:52:33 +04:00
|
|
|
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!xinode->is_redirected)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
/* specified file is a local resource */
|
|
|
|
//XFUSE_HANDLE *fh;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "LK_TODO: this is still a TODO");
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(req, EROFS);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* specified file resides on redirected share */
|
|
|
|
struct state_remove *fip = g_new0(struct state_remove, 1);
|
|
|
|
char *full_path = xfs_get_full_path(g_xfs, xinode->inum);
|
|
|
|
if (!full_path || !fip)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
fip->inum = xinode->inum;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(full_path);
|
2019-03-12 15:16:50 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* get devredir to open the remote file
|
|
|
|
*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_rmdir_or_file()
|
|
|
|
*/
|
|
|
|
if (devredir_rmdir_or_file(fip, xinode->device_id, cptr))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_rmdir_or_file() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EREMOTEIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
free(full_path);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2013-03-24 23:08:55 +04:00
|
|
|
static void xfuse_cb_rename(fuse_req_t req,
|
|
|
|
fuse_ino_t old_parent, const char *old_name,
|
|
|
|
fuse_ino_t new_parent, const char *new_name)
|
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *old_xinode;
|
|
|
|
XFS_INODE *new_parent_xinode;
|
2013-03-24 23:08:55 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: old_parent=%ld old_name=%s new_parent=%ld new_name=%s",
|
2013-03-24 23:08:55 +04:00
|
|
|
old_parent, old_name, new_parent, new_name);
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (strlen(old_name) > XFS_MAXFILENAMELEN ||
|
2020-11-30 03:36:20 +03:00
|
|
|
strlen(new_name) > XFS_MAXFILENAMELEN)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENAMETOOLONG);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (!(old_xinode = xfs_lookup_in_dir(g_xfs, old_parent, old_name)))
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "did not find file with pinode=%ld name=%s",
|
2019-11-14 17:43:57 +03:00
|
|
|
old_parent, old_name);
|
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (!(new_parent_xinode = xfs_get(g_xfs, new_parent)))
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", new_parent);
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (!xfs_check_move_entry(g_xfs, old_xinode->inum,
|
|
|
|
new_parent, new_name))
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-03-03 13:02:32 +03:00
|
|
|
/* Catchall -see rename(2). Fix when logging is improved */
|
2013-03-24 23:08:55 +04:00
|
|
|
fuse_reply_err(req, EINVAL);
|
|
|
|
}
|
|
|
|
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (new_parent_xinode->is_redirected != old_xinode->is_redirected ||
|
|
|
|
new_parent_xinode->device_id != old_xinode->device_id)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(req, EXDEV);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!old_xinode->is_redirected)
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
|
|
|
/* specified file is a local resource */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "LK_TODO: this is still a TODO");
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(req, EROFS);
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-03-24 23:08:55 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* resource is on a redirected share */
|
|
|
|
struct state_rename *fip = g_new0(struct state_rename, 1);
|
|
|
|
char *old_full_path = xfs_get_full_path(g_xfs, old_xinode->inum);
|
|
|
|
char *new_full_path = get_name_for_entry_in_parent(new_parent,
|
2020-11-30 03:36:20 +03:00
|
|
|
new_name);
|
2019-03-12 15:16:50 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (!old_full_path || !new_full_path || !fip)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
free(old_full_path);
|
|
|
|
free(new_full_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
|
|
|
const char *cp;
|
2019-03-12 15:16:50 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
fip->pinum = old_xinode->inum;
|
|
|
|
fip->new_pinum = new_parent;
|
|
|
|
strcpy(fip->name, new_name);
|
|
|
|
|
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(old_full_path);
|
|
|
|
cp = filename_on_device(new_full_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_rename_file()
|
|
|
|
*/
|
|
|
|
if (devredir_file_rename(fip, old_xinode->device_id, cptr, cp))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_file_rename() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EREMOTEIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
free(old_full_path);
|
|
|
|
free(new_full_path);
|
|
|
|
}
|
2013-03-24 23:08:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Create a directory or file
|
|
|
|
*
|
|
|
|
* @param req opaque FUSE object
|
|
|
|
* @param parent parent inode
|
|
|
|
* @param name name of dir or file to create
|
|
|
|
* @param mode creation mode
|
2019-11-14 17:43:57 +03:00
|
|
|
* @param fi File info from fuse_lowlevel_ops.create, or NULL.
|
|
|
|
* This may need to be copied if we're not replying immediately
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_create_dir_or_file(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name, mode_t mode,
|
2019-11-14 17:43:57 +03:00
|
|
|
struct fuse_file_info *fi)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: parent_ino=%ld name=%s mode=%o type=%s",
|
2019-11-14 17:43:57 +03:00
|
|
|
parent, name, mode, (mode & S_IFDIR) ? "dir" : "file");
|
2013-03-09 03:37:30 +04:00
|
|
|
|
|
|
|
/* name must be valid */
|
2019-11-14 17:43:57 +03:00
|
|
|
if (strlen(name) > XFS_MAXFILENAMELEN)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENAMETOOLONG);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2012-11-04 05:47:04 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Sanitise the mode
|
|
|
|
*
|
|
|
|
* Currently group/world write is not allowed.
|
|
|
|
*/
|
|
|
|
if (mode & S_IFDIR)
|
|
|
|
{
|
|
|
|
mode = (mode & 0777) | S_IFDIR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mode = (mode & 0777) | S_IFREG;
|
|
|
|
}
|
2012-11-04 05:47:04 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/* is parent inode valid? */
|
2020-03-03 13:02:32 +03:00
|
|
|
if (parent == FUSE_ROOT_ID)
|
|
|
|
{
|
|
|
|
fuse_reply_err(req, EROFS);
|
|
|
|
}
|
|
|
|
else if ((xinode = xfs_get(g_xfs, parent)) == NULL)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
fuse_reply_err(req, ENOENT);
|
|
|
|
}
|
2020-03-03 13:02:32 +03:00
|
|
|
else if ((xinode->mode & S_IFDIR) == 0)
|
|
|
|
{
|
|
|
|
fuse_reply_err(req, ENOTDIR);
|
|
|
|
}
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!xinode->is_redirected)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
/* specified file is a local resource */
|
|
|
|
//XFUSE_HANDLE *fh;
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "LK_TODO: this is still a TODO");
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(req, EROFS);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct state_create *fip = g_new0(struct state_create, 1);
|
|
|
|
char *full_path = get_name_for_entry_in_parent(parent, name);
|
2012-11-04 05:47:04 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (full_path == NULL || fip == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
free(full_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
2019-03-12 15:16:50 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
if (fi != NULL)
|
|
|
|
{
|
|
|
|
fip->fi = *fi;
|
|
|
|
}
|
|
|
|
fip->pinum = parent;
|
|
|
|
strcpy(fip->name, name);
|
|
|
|
fip->mode = mode;
|
|
|
|
|
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(full_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens
|
|
|
|
* in xfuse_devredir_cb_create_file()
|
|
|
|
*/
|
|
|
|
if (devredir_file_create(fip, xinode->device_id, cptr, mode))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_file_create() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EREMOTEIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
free(full_path);
|
|
|
|
}
|
|
|
|
}
|
2012-11-04 05:47:04 +04:00
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
|
|
|
* Open specified file
|
2019-11-14 17:43:57 +03:00
|
|
|
*
|
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_cb_open(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: ino=%ld", ino);
|
2013-05-06 05:42:17 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (!(xinode = xfs_get(g_xfs, ino)))
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", ino);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-09-25 04:19:10 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (xinode->mode & S_IFDIR)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* Can't open directories like this */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "reading/writing a dir not allowed!");
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_reply_err(req, EISDIR);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((fi->flags & O_ACCMODE) != O_RDONLY &&
|
|
|
|
(fi->flags & O_ACCMODE) != O_WRONLY &&
|
|
|
|
(fi->flags & O_ACCMODE) != O_RDWR)
|
2019-03-13 13:56:37 +03:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "Invalid access mode specified");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EINVAL);
|
|
|
|
}
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!xinode->is_redirected)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-04-27 05:55:28 +04:00
|
|
|
/* specified file is a local resource */
|
2020-03-03 13:02:32 +03:00
|
|
|
if ((fi->flags & O_ACCMODE) != O_RDONLY)
|
|
|
|
{
|
|
|
|
fuse_reply_err(req, EROFS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-15 18:37:56 +03:00
|
|
|
XFUSE_HANDLE *fh = xfuse_handle_create();
|
2020-03-03 13:02:32 +03:00
|
|
|
fh->is_loc_resource = 1;
|
2020-09-15 18:37:56 +03:00
|
|
|
fi->fh = xfuse_handle_to_fuse_handle(fh);
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_open(req, fi);
|
|
|
|
}
|
2013-04-27 05:55:28 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-04-27 05:55:28 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* specified file resides on redirected share */
|
|
|
|
struct state_open *fip = g_new0(struct state_open, 1);
|
|
|
|
char *full_path = xfs_get_full_path(g_xfs, ino);
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (!full_path || !fip)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
free(full_path);
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
fip->fi = *fi;
|
|
|
|
fip->inum = ino;
|
|
|
|
|
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(full_path);
|
|
|
|
|
|
|
|
/* get devredir to open the remote file
|
|
|
|
*
|
|
|
|
* If the caller has set O_TRUNC when writing the file,
|
|
|
|
* fuse should call us back via fuse_cb_setattr() to set
|
|
|
|
* the size to zero - we don't need to do this ourselves.
|
|
|
|
*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_open_file()
|
|
|
|
*/
|
|
|
|
if (devredir_file_open(fip, xinode->device_id, cptr, fi->flags))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_file_open() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EREMOTEIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
free(full_path);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
|
|
|
*/
|
2013-05-19 06:44:16 +04:00
|
|
|
static void xfuse_cb_release(fuse_req_t req, fuse_ino_t ino, struct
|
|
|
|
fuse_file_info *fi)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
XFUSE_HANDLE *handle = xfuse_handle_from_fuse_handle(fi->fh);
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: ino=%ld fi=%p fi->fh=0x%llx", ino, fi,
|
2016-11-16 08:59:11 +03:00
|
|
|
(long long) fi->fh);
|
2013-05-06 05:42:17 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((xinode = xfs_get(g_xfs, ino)) == NULL)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", ino);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-09-25 04:19:10 +04:00
|
|
|
}
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!xinode->is_redirected)
|
2013-03-19 06:43:20 +04:00
|
|
|
{
|
|
|
|
/* specified file is a local resource */
|
2013-04-27 05:55:28 +04:00
|
|
|
fuse_reply_err(req, 0);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-05-19 06:44:16 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* specified file resides on redirected share */
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
struct state_close *fip = g_new0(struct state_close, 1);
|
|
|
|
if (fip == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
fip->inum = ino;
|
|
|
|
fip->fi = *fi;
|
2013-03-19 06:43:20 +04:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
fi->fh = xfuse_handle_to_fuse_handle(NULL);
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_file_close()
|
|
|
|
*/
|
|
|
|
if (devredir_file_close(fip, xinode->device_id, handle->FileId))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_close_file() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EREMOTEIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
2013-05-19 06:44:16 +04:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
xfuse_handle_delete(handle);
|
2013-03-19 06:43:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-03-09 03:37:30 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_cb_read(fuse_req_t req, fuse_ino_t ino, size_t size,
|
|
|
|
off_t off, struct fuse_file_info *fi)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-04-27 05:55:28 +04:00
|
|
|
XFUSE_HANDLE *fh;
|
2019-11-14 17:43:57 +03:00
|
|
|
struct state_read *fusep;
|
|
|
|
XFS_INODE *xinode;
|
2013-04-27 05:55:28 +04:00
|
|
|
struct req_list_item *rli;
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "want_bytes %zd bytes at off %lld", size, (long long) off);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
if ((fh = xfuse_handle_from_fuse_handle(fi->fh)) == NULL)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_reply_err(req, EINVAL);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (fh->is_loc_resource)
|
2012-11-08 10:48:18 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
/* target file is in .clipboard dir */
|
2013-04-27 05:55:28 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "target file is in .clipboard dir");
|
2013-04-27 05:55:28 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((xinode = xfs_get(g_xfs, ino)) == NULL)
|
2013-04-27 05:55:28 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "ino does not exist in xrdp_fs");
|
2013-04-27 05:55:28 +04:00
|
|
|
fuse_reply_buf(req, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-16 06:44:24 +03:00
|
|
|
rli = g_new0(struct req_list_item, 1);
|
2013-04-27 05:55:28 +04:00
|
|
|
|
|
|
|
rli->stream_id = 0;
|
|
|
|
rli->req = req;
|
|
|
|
rli->lindex = xinode->lindex;
|
|
|
|
rli->off = off;
|
|
|
|
rli->size = size;
|
|
|
|
list_add_item(g_req_list, (tbus) rli);
|
|
|
|
|
|
|
|
if (g_req_list->count == 1)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "requesting clipboard file data lindex = %d off = %lld size = %zd",
|
2016-11-16 08:59:11 +03:00
|
|
|
rli->lindex, (long long) off, size);
|
2013-04-27 05:55:28 +04:00
|
|
|
|
|
|
|
clipboard_request_file_data(rli->stream_id, rli->lindex,
|
|
|
|
(int) off, (int) size);
|
|
|
|
}
|
2012-11-08 10:48:18 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* target file is on a remote device */
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fusep = g_new0(struct state_read, 1);
|
|
|
|
if (fusep == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fusep->req = req;
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_read_file()
|
|
|
|
*/
|
|
|
|
devredir_file_read(fusep, fh->DeviceId, fh->FileId, size, off);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
|
2013-05-21 23:57:06 +04:00
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-05-21 23:57:06 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_write(fuse_req_t req, fuse_ino_t ino, const char *buf,
|
|
|
|
size_t size, off_t off, struct fuse_file_info *fi)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
XFUSE_HANDLE *fh;
|
2019-11-14 17:43:57 +03:00
|
|
|
struct state_write *fusep;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "write %zd bytes at off %lld to inode=%ld",
|
2016-11-16 08:59:11 +03:00
|
|
|
size, (long long) off, ino);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-09-15 18:37:56 +03:00
|
|
|
if ((fh = xfuse_handle_from_fuse_handle(fi->fh)) == NULL)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "file handle fi->fh is NULL");
|
2013-03-09 03:37:30 +04:00
|
|
|
fuse_reply_err(req, EINVAL);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (fh->is_loc_resource)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2013-03-09 03:37:30 +04:00
|
|
|
/* target file is in .clipboard dir */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "THIS IS STILL A TODO!");
|
2020-03-03 13:02:32 +03:00
|
|
|
fuse_reply_err(req, EROFS);
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2012-11-05 13:04:04 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* target file is on a remote device */
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fusep = g_new0(struct state_write, 1);
|
|
|
|
if (fusep == NULL)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fusep->req = req;
|
|
|
|
fusep->inum = ino;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens in
|
|
|
|
* xfuse_devredir_cb_write_file()
|
|
|
|
*/
|
|
|
|
devredir_file_write(fusep, fh->DeviceId, fh->FileId, buf,
|
|
|
|
size, off);
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
2012-10-30 09:12:44 +04:00
|
|
|
|
2013-05-21 23:57:06 +04:00
|
|
|
/**
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
|
|
|
*/
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_create(fuse_req_t req, fuse_ino_t parent,
|
|
|
|
const char *name, mode_t mode,
|
|
|
|
struct fuse_file_info *fi)
|
2012-11-05 01:52:33 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: parent_inode=%ld, name=%s fi=%p",
|
2016-11-16 08:59:11 +03:00
|
|
|
parent, name, fi);
|
2013-05-20 04:23:18 +04:00
|
|
|
|
2020-11-30 03:36:20 +03:00
|
|
|
xfuse_create_dir_or_file(req, parent, name, mode & ~S_IFDIR, fi);
|
2012-11-05 01:52:33 +04:00
|
|
|
}
|
|
|
|
|
2013-05-21 23:57:06 +04:00
|
|
|
/**
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-11-14 08:37:41 +03:00
|
|
|
#if 0
|
2013-05-21 23:57:06 +04:00
|
|
|
static void xfuse_cb_fsync(fuse_req_t req, fuse_ino_t ino, int datasync,
|
|
|
|
struct fuse_file_info *fi)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "#################### entered: ino=%ld datasync=%d", ino, datasync);
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "function not required");
|
2013-05-21 23:57:06 +04:00
|
|
|
fuse_reply_err(req, EINVAL);
|
|
|
|
}
|
2016-11-14 08:37:41 +03:00
|
|
|
#endif
|
2013-05-21 23:57:06 +04:00
|
|
|
|
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* Sets attributes for a directory entry.
|
|
|
|
*
|
|
|
|
* If the file resides on a remote share, devredir
|
|
|
|
* is asked to update it. This will result in the following
|
|
|
|
* callbacks:-
|
|
|
|
* - xfuse_devredir_cb_setattr() to update our copy and return status
|
|
|
|
*
|
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-05-21 23:57:06 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
static void xfuse_cb_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
|
|
|
|
int to_set, struct fuse_file_info *fi)
|
2012-10-30 09:12:44 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered to_set=0x%x", to_set);
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((xinode = xfs_get(g_xfs, ino)) == NULL)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", ino);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if (((to_set & FUSE_SET_ATTR_UID) && attr->st_uid != xinode->uid) ||
|
|
|
|
((to_set & FUSE_SET_ATTR_GID) && attr->st_gid != xinode->gid))
|
2013-09-25 04:19:10 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* We don't allow any of these */
|
|
|
|
fuse_reply_err(req, EPERM);
|
2013-09-25 04:19:10 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else if ((to_set & FUSE_SET_ATTR_MODE) &&
|
2020-11-30 03:36:20 +03:00
|
|
|
(attr->st_mode & ~(0777 | S_IFDIR | S_IFREG)) != 0)
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
/* We only support standard mode bits and S_IFDIR / S_IFREG */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "Asking for invalid mode bits 0%o to be set", attr->st_mode);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, EINVAL);
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
else
|
2013-03-09 03:37:30 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
struct file_attr attrs = {0};
|
|
|
|
tui32 change_mask = 0;
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((to_set & FUSE_SET_ATTR_MODE) && xinode->mode != attr->st_mode)
|
|
|
|
{
|
|
|
|
attrs.mode = attr->st_mode & (0777 | S_IFDIR | S_IFREG);
|
|
|
|
change_mask |= TO_SET_MODE;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((to_set & FUSE_SET_ATTR_SIZE) && xinode->size != attr->st_size)
|
|
|
|
{
|
|
|
|
attrs.size = attr->st_size;
|
|
|
|
change_mask |= TO_SET_SIZE;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((to_set & FUSE_SET_ATTR_ATIME) && xinode->atime != attr->st_atime)
|
|
|
|
{
|
|
|
|
attrs.atime = attr->st_atime;
|
|
|
|
change_mask |= TO_SET_ATIME;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((to_set & FUSE_SET_ATTR_MTIME) && xinode->mtime != attr->st_mtime)
|
|
|
|
{
|
|
|
|
attrs.mtime = attr->st_mtime;
|
|
|
|
change_mask |= TO_SET_MTIME;
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (change_mask == 0)
|
|
|
|
{
|
|
|
|
/* No changes have been made */
|
|
|
|
make_fuse_attr_reply(req, xinode);
|
|
|
|
}
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!xinode->is_redirected)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
/* Update the local fs */
|
|
|
|
update_inode_file_attributes(&attrs, change_mask, xinode);
|
|
|
|
make_fuse_attr_reply(req, xinode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct state_setattr *fip = g_new0(struct state_setattr, 1);
|
|
|
|
char *full_path = xfs_get_full_path(g_xfs, ino);
|
|
|
|
if (!full_path || !fip)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "system out of memory");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
free(full_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
|
|
|
fip->req = req;
|
|
|
|
fip->inum = ino;
|
|
|
|
/* Save the important stuff so we can update our node if the
|
|
|
|
* remote update is successful */
|
|
|
|
fip->fattr = attrs;
|
|
|
|
fip->change_mask = change_mask;
|
|
|
|
|
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(full_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens
|
|
|
|
* in xfuse_devredir_cb_setattr()
|
|
|
|
*/
|
|
|
|
if (devredir_setattr_for_entry(fip, xinode->device_id,
|
|
|
|
cptr, &attrs, change_mask) < 0)
|
|
|
|
{
|
|
|
|
fuse_reply_err(req, EIO);
|
|
|
|
free(fip);
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
free(full_path);
|
|
|
|
}
|
|
|
|
}
|
2013-03-09 03:37:30 +04:00
|
|
|
}
|
2012-10-30 09:12:44 +04:00
|
|
|
}
|
|
|
|
|
2013-09-25 04:19:10 +04:00
|
|
|
/**
|
|
|
|
* Get dir listing
|
|
|
|
*
|
2019-11-14 17:43:57 +03:00
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-09-25 04:19:10 +04:00
|
|
|
*****************************************************************************/
|
2019-11-14 17:43:57 +03:00
|
|
|
static void xfuse_cb_opendir(fuse_req_t req, fuse_ino_t ino,
|
2020-11-30 03:36:20 +03:00
|
|
|
struct fuse_file_info *fi)
|
2013-08-12 05:06:39 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
XFS_INODE *xinode;
|
2020-09-15 18:37:56 +03:00
|
|
|
XFUSE_HANDLE *xhandle;
|
2013-08-12 05:06:39 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "inode=%ld", ino);
|
2013-08-12 05:06:39 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((xinode = xfs_get(g_xfs, ino)) == NULL)
|
2013-08-12 05:06:39 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "inode %ld is not valid", ino);
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_err(req, ENOENT);
|
2013-08-12 05:06:39 +04:00
|
|
|
}
|
2020-03-03 19:16:09 +03:00
|
|
|
else if (!xinode->is_redirected)
|
2013-09-25 04:19:10 +04:00
|
|
|
{
|
2020-09-15 18:37:56 +03:00
|
|
|
if ((xhandle = xfuse_handle_create()) == NULL)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-09-15 18:37:56 +03:00
|
|
|
if ((xhandle->dir_handle = xfs_opendir(g_xfs, ino)) == NULL)
|
|
|
|
{
|
|
|
|
xfuse_handle_delete(xhandle);
|
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fi->fh = xfuse_handle_to_fuse_handle(xhandle);
|
|
|
|
fuse_reply_open(req, fi);
|
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
}
|
2013-09-25 04:19:10 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
else
|
2013-08-12 05:06:39 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "did not find entry; redirecting call to devredir");
|
2019-11-14 17:43:57 +03:00
|
|
|
struct state_dirscan *fip = g_new0(struct state_dirscan, 1);
|
|
|
|
char *full_path = xfs_get_full_path(g_xfs, ino);
|
2013-08-12 05:06:39 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (full_path == NULL || fip == NULL)
|
|
|
|
{
|
|
|
|
fuse_reply_err(req, ENOMEM);
|
|
|
|
free(fip);
|
|
|
|
free(full_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *cptr;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "dev_id=%d ino=%ld full_path=%s",
|
2019-11-14 17:43:57 +03:00
|
|
|
xinode->device_id, ino, full_path);
|
2019-03-12 15:16:50 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fip->req = req;
|
|
|
|
fip->pinum = ino;
|
|
|
|
fip->fi = *fi;
|
|
|
|
|
|
|
|
/* we want path minus 'root node of the share' */
|
|
|
|
cptr = filename_on_device(full_path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this call succeeds, further request processing happens in:-
|
|
|
|
* - xfuse_devredir_cb_enum_dir_add_entry()
|
|
|
|
* Called for every file in the directory
|
|
|
|
* - xfuse_devredir_cb_enum_dir_done()
|
|
|
|
* Called at the end of the directory scan
|
|
|
|
*/
|
|
|
|
if (devredir_get_dir_listing(fip, xinode->device_id, cptr))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "failed to send devredir_get_dir_listing() cmd");
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_buf(req, NULL, 0);
|
|
|
|
free(fip);
|
|
|
|
}
|
|
|
|
free(full_path);
|
|
|
|
}
|
2013-08-12 05:06:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-14 17:43:57 +03:00
|
|
|
* GOTCHA : For FUSE 2.9 at least, the 'fi' parameter is allocated on the
|
|
|
|
* stack by the caller, so must be copied if we're not using it
|
|
|
|
* to reply to FUSE immediately
|
2013-08-12 05:06:39 +04:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
static void xfuse_cb_releasedir(fuse_req_t req, fuse_ino_t ino,
|
|
|
|
struct fuse_file_info *fi)
|
|
|
|
{
|
2020-09-15 18:37:56 +03:00
|
|
|
XFUSE_HANDLE *xhandle = xfuse_handle_from_fuse_handle(fi->fh);
|
|
|
|
xfs_closedir(g_xfs, xhandle->dir_handle);
|
|
|
|
xhandle->dir_handle = NULL;
|
|
|
|
xfuse_handle_delete(xhandle);
|
2013-08-12 05:06:39 +04:00
|
|
|
fuse_reply_err(req, 0);
|
|
|
|
}
|
|
|
|
|
2013-08-10 06:43:45 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* miscellaneous functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void xfs_inode_to_fuse_entry_param(const XFS_INODE *xinode,
|
2020-11-30 03:36:20 +03:00
|
|
|
struct fuse_entry_param *e)
|
2019-11-14 17:43:57 +03:00
|
|
|
{
|
|
|
|
memset(e, 0, sizeof(*e));
|
|
|
|
e->ino = xinode->inum;
|
|
|
|
e->attr_timeout = XFUSE_ATTR_TIMEOUT;
|
|
|
|
e->entry_timeout = XFUSE_ENTRY_TIMEOUT;
|
|
|
|
e->attr.st_ino = xinode->inum;
|
2020-07-06 13:53:56 +03:00
|
|
|
e->attr.st_mode = xinode->mode & ~g_cfg->file_umask;
|
2019-11-14 17:43:57 +03:00
|
|
|
e->attr.st_nlink = 1;
|
|
|
|
e->attr.st_uid = xinode->uid;
|
|
|
|
e->attr.st_gid = xinode->gid;
|
|
|
|
e->attr.st_size = xinode->size;
|
|
|
|
e->attr.st_atime = xinode->atime;
|
|
|
|
e->attr.st_mtime = xinode->mtime;
|
|
|
|
e->attr.st_ctime = xinode->ctime;
|
|
|
|
e->generation = xinode->generation;
|
|
|
|
}
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void make_fuse_entry_reply(fuse_req_t req, const XFS_INODE *xinode)
|
2013-08-10 06:43:45 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
struct fuse_entry_param e;
|
|
|
|
xfs_inode_to_fuse_entry_param(xinode, &e);
|
|
|
|
fuse_reply_entry(req, &e);
|
|
|
|
}
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
static void make_fuse_attr_reply(fuse_req_t req, const XFS_INODE *xinode)
|
|
|
|
{
|
|
|
|
struct stat st;
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
memset(&st, 0, sizeof(st));
|
|
|
|
st.st_ino = xinode->inum;
|
2020-07-06 13:53:56 +03:00
|
|
|
st.st_mode = xinode->mode & ~g_cfg->file_umask;
|
2019-11-14 17:43:57 +03:00
|
|
|
st.st_nlink = 1;
|
|
|
|
st.st_uid = xinode->uid;
|
|
|
|
st.st_gid = xinode->gid;
|
|
|
|
st.st_size = xinode->size;
|
|
|
|
st.st_atime = xinode->atime;
|
|
|
|
st.st_mtime = xinode->mtime;
|
|
|
|
st.st_ctime = xinode->ctime;
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
fuse_reply_attr(req, &st, XFUSE_ATTR_TIMEOUT);
|
|
|
|
}
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Get the name of a file on the device
|
|
|
|
*
|
|
|
|
* For redirected devices, the routine xfs_get_full_path() returns names
|
|
|
|
* like "/C:/Windows/System32".
|
|
|
|
* This routine simply returns a pointer to the part of the name following
|
|
|
|
* the device specification.
|
|
|
|
*/
|
|
|
|
static const char *filename_on_device(const char *full_path)
|
|
|
|
{
|
|
|
|
const char *result = NULL;
|
|
|
|
if (full_path[0] != '\0')
|
|
|
|
{
|
|
|
|
result = strchr(full_path + 1, '/');
|
2013-08-10 06:43:45 +04:00
|
|
|
}
|
2019-11-14 17:43:57 +03:00
|
|
|
return result ? result : "/";
|
2013-08-10 06:43:45 +04:00
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Updates attributes on the filesystem, and bumps the inode ctime
|
2013-08-10 06:43:45 +04:00
|
|
|
*
|
2019-11-14 17:43:57 +03:00
|
|
|
* This call is used to set attributes, either locally, or following a
|
|
|
|
* setattr devredir call
|
|
|
|
*/
|
|
|
|
static void update_inode_file_attributes(const struct file_attr *fattr,
|
2020-11-30 03:36:20 +03:00
|
|
|
tui32 change_mask, XFS_INODE *xinode)
|
2013-08-10 06:43:45 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
int updated = 0;
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((change_mask & TO_SET_MODE) != 0 && xinode->mode != fattr->mode)
|
2013-08-10 06:43:45 +04:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
xinode->mode = fattr->mode;
|
|
|
|
updated = 1;
|
|
|
|
}
|
|
|
|
if ((change_mask & TO_SET_SIZE) != 0 && xinode->size != fattr->size)
|
|
|
|
{
|
|
|
|
xinode->size = fattr->size;
|
|
|
|
updated = 1;
|
|
|
|
}
|
|
|
|
if ((change_mask & TO_SET_ATIME) != 0 && xinode->atime != fattr->atime)
|
|
|
|
{
|
|
|
|
xinode->atime = fattr->atime;
|
|
|
|
updated = 1;
|
|
|
|
}
|
|
|
|
if ((change_mask & TO_SET_MTIME) != 0 && xinode->mtime != fattr->mtime)
|
|
|
|
{
|
|
|
|
xinode->mtime = fattr->mtime;
|
|
|
|
updated = 1;
|
|
|
|
}
|
2013-08-10 06:43:45 +04:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if (updated)
|
|
|
|
{
|
|
|
|
xinode->ctime = time(0);
|
2013-08-10 06:43:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
/*
|
|
|
|
* Gets the name for a file where we know the parent inode and the
|
|
|
|
* name for the file under that inode
|
|
|
|
*
|
|
|
|
* Result must be freed after use
|
|
|
|
*/
|
|
|
|
static char *get_name_for_entry_in_parent(fuse_ino_t parent, const char *name)
|
2019-03-21 19:48:01 +03:00
|
|
|
{
|
2019-11-14 17:43:57 +03:00
|
|
|
char *result;
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
if ((result = xfs_get_full_path(g_xfs, parent)) != NULL)
|
|
|
|
{
|
2020-11-30 03:36:20 +03:00
|
|
|
char *p = (char *) realloc(result,
|
|
|
|
strlen(result) + 1 + strlen(name) + 1);
|
2019-11-14 17:43:57 +03:00
|
|
|
if (p == NULL)
|
|
|
|
{
|
2020-01-16 14:49:13 +03:00
|
|
|
/* See cppcheck trac #9292 and #9437 */
|
|
|
|
/* cppcheck-suppress doubleFree symbolName=result */
|
2019-11-14 17:43:57 +03:00
|
|
|
free(result);
|
|
|
|
result = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = p;
|
|
|
|
strcat(result, "/");
|
|
|
|
strcat(result, name);
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 19:48:01 +03:00
|
|
|
|
2019-11-14 17:43:57 +03:00
|
|
|
return result;
|
2019-03-21 19:48:01 +03:00
|
|
|
}
|
|
|
|
|
2020-08-22 20:05:24 +03:00
|
|
|
/*
|
|
|
|
* Scans a user-provided string substituting %u/%U for UID/username
|
|
|
|
*/
|
|
|
|
static unsigned int format_user_info(char *dest, unsigned int len,
|
|
|
|
const char *format)
|
|
|
|
{
|
|
|
|
char uidstr[64];
|
|
|
|
char username[64];
|
|
|
|
const struct info_string_tag map[] =
|
|
|
|
{
|
|
|
|
{'u', uidstr},
|
|
|
|
{'U', username},
|
|
|
|
INFO_STRING_END_OF_LIST
|
|
|
|
};
|
|
|
|
|
|
|
|
int uid = g_getuid();
|
|
|
|
g_snprintf(uidstr, sizeof(uidstr), "%d", uid);
|
|
|
|
if (g_getlogin(username, sizeof(username)) != 0)
|
|
|
|
{
|
|
|
|
/* Fall back to UID */
|
|
|
|
g_strncpy(username, uidstr, sizeof(username) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_format_info_string(dest, len, format, map);
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
#endif /* end else #ifndef XRDP_FUSE */
|