aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fuse.c
AgeCommit message (Collapse)AuthorLines
2019-08-29Avoid gcc 9.1 strncpy(3) warnings (#447)Stefan Hajnoczi-1/+1
Recent GCC releases have warnings related to common strncpy(3) bugs. These warnings can be avoided by explicitly NUL-terminating the buffer or using memcpy(3) when the intention is to copy just the characters without the NUL terminator. This commit fixes the following warnings: [1/27] Compiling C object 'test/9f86d08@@test_syscalls@exe/test_syscalls.c.o'. In function ‘test_socket’, inlined from ‘main’ at ../test/test_syscalls.c:1899:9: ../test/test_syscalls.c:1760:2: warning: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 1023 [-Wstringop-truncation] 1760 | strncpy(su.sun_path, testsock, sizeof(su.sun_path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [2/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse.c.o'. ../lib/fuse.c: In function ‘add_name’: ../lib/fuse.c:968:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 968 | strncpy(s, name, len); | ^~~~~~~~~~~~~~~~~~~~~ ../lib/fuse.c:944:15: note: length computed here 944 | size_t len = strlen(name); | ^~~~~~~~~~~~ [3/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse_lowlevel.c.o'. ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry’: ../lib/fuse_lowlevel.c:288:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 288 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:276:12: note: length computed here 276 | namelen = strlen(name); | ^~~~~~~~~~~~ ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry_plus’: ../lib/fuse_lowlevel.c:381:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 381 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:366:12: note: length computed here 366 | namelen = strlen(name); | ^~~~~~~~~~~~ Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2019-06-06Don't return expression in function returning voidMichael Forney-1/+1
This is a constraint violation in ISO C[0]. [0] http://port70.net/~nsz/c/c11/n1570.html#6.8.6.4p1
2019-06-06Don't omit second operand to `?` operatorMichael Forney-1/+1
This is a GNU C extension.
2019-03-11Defined the (*ioctl)() commands as unsigned int (#381)Jean-Pierre André-6/+7
Instead of the Posix ioctl(2) command, Linux uses its own variant of ioctl() in which the commands are requested as "unsigned long" and truncated to 32 bits by the fuse kernel module. Transmitting the commands to user space file systems as "unsigned int" is a workaround for processing ioctl() commands which do not fit into a signed int.
2019-02-13fuse_free_buf(): to check flags of each buffer, rather than only 0thAlbert Chen-1/+1
Fixes: #360
2018-12-22fix memory leak in print_module_help methodalex-0/+1
2018-11-19libfuse: add copy_file_range() supportNiels de Vos-0/+63
Add support for the relatively new copy_file_range() syscall. Backend filesystems can now implement an efficient way of cloning/duplicating data ranges within files. See 'man 2 copy_file_range' for more details.
2018-08-26Fix memory leak of FUSE modulesRostislav-3/+23
2018-08-26Fix invalid free of memory pointer in 'struct fuse_buf'Rostislav-1/+2
2018-07-25Remove unused member of 'struct fuse_dh'Rostislav Skudnov-1/+0
2018-07-21Fix readdir() bug when a non-zero offset is specified in filler (#269)Rostislav-11/+15
The bug occurs when a filesystem client reads a directory until the end, seeks using seekdir() to some valid non-zero position and calls readdir(). A valid 'struct dirent *' is expected, but NULL is returned instead. Pseudocode demonstrating the bug: DIR *dp = opendir("some_dir"); struct dirent *de = readdir(dp); /* Get offset of the second entry */ long offset = telldir(dp); /* Read directory until the end */ while (de) de = readdir(de); seekdir(dp, offset); de = readdir(dp); /* de must contain the second entry, but NULL is returned instead */ The reason of the bug is that when the end of directory is reached, the kernel calls FUSE_READDIR op with an offset at the end of directory, so the filesystem's .readdir callback never calls the filler function, and we end up with dh->filled set to 1. After seekdir(), FUSE_READDIR is called again with a new offset, but this time the filesystem's .readdir callback is never called, and an empty reply is returned. Fix by setting dh->filled to 1 only when zero offsets are given to filler function.
2018-05-18rename: perform user mode dir loop check when not done in kernelBill Zissimooulos-10/+12
Fix conditionals as per maintainer's request.
2018-05-18rename: perform user mode dir loop check when not done in kernelBill Zissimooulos-3/+59
Linux performs the dir loop check (rename(a, a/b/c) or rename(a/b/c, a), etc.) in kernel. Unfortunately other systems do not perform this check (e.g. FreeBSD). This results in a deadlock in get_path2, because libfuse did not expect to handle such cases. We add a check_dir_loop function that performs the dir loop check in user mode and enable it on systems that need it.
2018-02-09Fix uninitialised read in fuse_new_30() (#231) (#234)Ashley Pittman-0/+3
Ensure that conf is always zero before it's read from to prevent sporadic failure at startup if higher layers were build against version 3.0 Signed-off-by: Ashley Pittman <ashley.m.pittman@intel.com>
2017-11-03Backed out d92bf83Nikolaus Rath-1/+1
This change is bogus. fuse_module_factory_t is already a pointer type. Additionally, if dlsym returns NULL, then you will be dereferencing it causing a segfault. In my testing, a segfault will happen even if dlsym returns successfully. Thanks to Michael Theall for spotting!
2017-09-27Adding pointer dereferencing after calling dlsym()Sangwoo Moon-1/+1
dlsym() resolves the location of the loaded symbol, therefore dlsym() returns the type (fuse_module_factory_t *), not (fuse_module_factory_t). Added pinter dereferencing to correctly refer the factory function.
2017-09-25fuse_lib_ioctl(): don't call memcpy with NULL argumentNikolaus Rath-1/+1
This was detected by using clang's undefined behavior sanitizer, but didn't seem to cause problems in practice.
2017-09-19Make *_loop_mt() available in version 3.0 againNikolaus Rath-1/+1
The old versions of these symbols were defined with version tag FUSE_3.0, so this is what we have to use in the .symver directive.
2017-09-19Don't use external symbol names in internal filesNikolaus Rath-4/+1
The fuse_session_loop_mt() and fuse_loop_mt() symbols are only visible when linking against the shared object. The code in lib/, however, is compiled *into* the shared object and should thus use the internal names of these functions. Surprisingly enough, the code still worked before - but only when link time optimization was disabled. Unfortunately, we still can't compile with LTO because it seems that enabling LTO somehow makes the tagged symbols vanish. Without lto, we have: $ nm lib/libfuse3.so | grep fuse_new 0000000000011070 T fuse_new_30 0000000000010a00 t fuse_new_31 0000000000011070 T fuse_new@FUSE_3.0 0000000000010a00 T fuse_new@@FUSE_3.1 and with LTO: $ nm lib/libfuse3.so | grep fuse_new 0000000000019a70 T fuse_new_30 0000000000019270 t fuse_new_31 See also issue #198.
2017-08-24Add idle_threads mount option.Joseph Dodge-2/+14
2017-08-24Allow inode cache invalidation in high-level APISławek Rudnicki-0/+40
We re-introduce the functionality of invalidating the caches for an inode specified by path by adding a new routine fuse_invalidate_path. This is useful for network-based file systems which use the high-level API, enabling them to notify the kernel about external changes. This is a revival of Miklos Szeredi's original code for the fuse_invalidate routine.
2017-08-22Allow building without iconv.Nikolaus Rath-0/+6
cfg.has('HAVE_ICONV') was always true.
2017-08-14directly call fuse_new_31() instead of fuse_new() internallyuserwithuid-2/+0
this fixes building with lto, which failed since commit 503e32d01e4db00e90d7acfd81ab05386559069f
2017-08-11fuse_lib_init(): don't set FUSE_CAP_EXPORT_SUPPORT unconditionallyNikolaus Rath-1/+2
FreeBSD kernel does not support this.
2017-07-13Only declare fuse_new_30() when FUSE_USE_VERSION == 30Nikolaus Rath-24/+26
This function shouldn't be called when using a newer fuse version, so we should not define it in that case.
2017-07-13fuse_new_30(): call fuse_new_31(), not fuse_new()Nikolaus Rath-1/+1
I believe this function call is resolved by the compiler, not the linker, so this seems safer. Thanks to Chris Clayton for spotting this.
2017-07-08Fixup symbol versioning for GCC 4.xNikolaus Rath-4/+7
GCC 4.8 doesn't like to rename fuse_new_30 to fuse_new, if we also define an implementation for fuse_new.
2017-07-08Added public fuse_lib_help(), bumped minor versionNikolaus Rath-40/+85
2017-06-05Fix comparison of integers of different signsAngelo G. Del Regno-1/+1
Some variables of different size and sign were getting compared without any safe casting. The build system also throws warnings at this and, being this library used for filesystems, it's really important to ensure stability.
2017-04-14Set default options before parsingTej Chajed-5/+5
2017-03-03Optimize fuse_fs_read. (#145)amosonn-10/+34
Redundant copy when only op.read is available removed.
2016-10-24Added debug logging to chmodNikolaus Rath-1/+8
2016-10-24Fix segfault in debug logging codeNikolaus Rath-17/+32
fi may be NULL, so we need to protect against this.
2016-10-20Turn fuse_operations.nopath_flag into fuse_config.nullpath_okNikolaus Rath-5/+3
Modifying struct fuse_config in the init() handler is the canonical way to adjust file-system implementation specific settings. There is no need to have flags in struct fuse_operations.
2016-10-20fuse_new(): don't accept options that don't make sense for end-usersNikolaus Rath-6/+0
Several options (use_ino, etc) depend on the file system implementation. Allowing them to be set from the command line makes no sense.
2016-10-20Pass struct fuse_config to high-level init() handler.Nikolaus Rath-30/+4
2016-10-15Make --help output more suitable for end-userNikolaus Rath-10/+4
We now only list options that are potentially useful for an end-user (and unlikely to accidentally break a file system). The full list of FUSE options has been moved to the documentation of the fuse_new() and fuse_session_new() functions.
2016-10-15Removed -o nopath - it never did anythingNikolaus Rath-2/+0
We are overriding this setting with the flag in struct fuse_operations: $ example/hello -f -d ~/tmp/mnt FUSE library version: 3.0.0pre0 nopath: 0 unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0 INIT: 7.25 flags=0x0007fffb max_readahead=0x00020000 INIT: 7.23 flags=0x00006031 max_readahead=0x00020000 max_write=0x00020000 max_background=0 congestion_threshold=0 time_gran=0 unique: 1, success, outsize: 80 $ example/hello -f -d ~/tmp/mnt -o nopath FUSE library version: 3.0.0pre0 nopath: 0 unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0 INIT: 7.25 flags=0x0007fffb max_readahead=0x00020000 INIT: 7.23 flags=0x00006031 max_readahead=0x00020000 max_write=0x00020000 max_background=0 congestion_threshold=0 time_gran=0 unique: 1, success, outsize: 80
2016-10-15Pass fuse_file_info to getattr, chown, chmod, truncate, utimens handlersNikolaus Rath-83/+34
This obsoletes the ftruncate & fgetattr handlers. Fixes #58.
2016-10-15Unify handling of fuse_conn_info optionsNikolaus Rath-1/+0
Instead of using command line options to modify struct fuse_conn_info before and after calling the init() handler, we now give the file system explicit control over this.
2016-10-13Make -o clone_fd into a parameter of session_loop_mt().Nikolaus Rath-2/+2
This option really affects the behavior of the session loop, not the low-level interface. Therefore, it does not belong in the fuse_session object.
2016-10-04Clarified purpose of helper.c, moved *version() to fuse.cNikolaus Rath-0/+10
2016-10-03Merge master fuse_chan into fuse_session.Nikolaus Rath-4/+3
This is a code simplification patch. - It confines most of the implementation channel implementation into fuse_loop_mt (which is its only user). - It makes it more obvious in the code that channels are only ever used when using -o clone_fd and multi-threaded main loop. - It simplies the definition of both struct fuse_session and struct fuse_chan. - Theoretically it should result in (minuscule) performance improvements when not using -o clone_fd. - Overall, it removes a lot more lines of source code than it adds :-).
2016-10-02Merged fuse_mt.c into fuse.cNikolaus Rath-0/+14
There is no point in having a separate file for a 10 line function.
2016-10-02Extended per-file comments.Nikolaus Rath-0/+3
This should make more clear what file contains code for what purpose.
2016-10-02Don't handle --help and --version in fuse_session_new().Nikolaus Rath-40/+34
Help and version messages can be generated using the new fuse_lowlevel_help(), fuse_lowlevel_version(), fuse_mount_help(), and fuse_mount_version() functions. The fuse_parse_cmdline() function has been made more powerful to do this automatically, and is now explicitly intended only for low-level API users. This is a code simplication patch. We don't have to parse for --help and --version in quite as many places, and we no longer have a low-level initialization function be responsible for the (super-high level) task of printing a program usage message. In the high-level API, we can now handle the command line parsing earlier and avoid running other initialization code if we're just going to abort later on.
2016-10-02Add section headings for --help outputNikolaus Rath-2/+3
Also, do not include "General options" in usage message.
2016-10-02Turn struct fuse_chan into an implementation detailNikolaus Rath-9/+8
The only struct fuse_chan that's accessible to the user application is the "master" channel that is returned by fuse_mount and stored in struct fuse_session. When using the multi-threaded main loop with the "clone_fd" option, each worker thread gets its own struct fuse_chan. However, none of these are available to the user application, nor do they hold references to struct fuse_session (the pointer is always null). Therefore, any presence of struct fuse_chan can be removed without loss of functionality by relying on struct fuse_session instead. This reduces the number of API functions and removes a potential source of confusion (since the new API no longer looks as if it might be possible to add multiple channels to one session, or to share one channel between multiple sessions). Fixes issue #17.
2016-10-02Renamed fuse_lowlevel_new() to fuse_session_new().Nikolaus Rath-1/+1
2016-10-02Introduce separate mount/umount functions for low-level API.Nikolaus Rath-0/+10