mirror of
https://github.com/libfuse/libfuse.git
synced 2024-11-23 12:14:15 +08:00
Fix returning d_ino and d_type by readdir(3) in non-plus mode
When not using the readdir_plus mode, the d_type was not returned, and the use_ino flag was not used for returning d_ino. This patch fixes the returned values for d_ino and d_type by readdir(3) The test for the returned value of d_ino has been adjusted to also take the d_type into consideration and to check the returned values in both basic readdir and readdir_plus modes. This is done by executing the passthrough test twice. Co-authored-by: Jean-Pierre André <jpandre@users.sourceforge.net>
This commit is contained in:
parent
77d662459a
commit
bdd2d4110f
@ -1,3 +1,5 @@
|
|||||||
|
* Fix returning d_ino and d_type from readdir(3) in non-plus mode
|
||||||
|
|
||||||
libfuse 3.10.2 (2021-02-05)
|
libfuse 3.10.2 (2021-02-05)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
|
|
||||||
#include "passthrough_helpers.h"
|
#include "passthrough_helpers.h"
|
||||||
|
|
||||||
|
static int fill_dir_plus = 0;
|
||||||
|
|
||||||
static void *xmp_init(struct fuse_conn_info *conn,
|
static void *xmp_init(struct fuse_conn_info *conn,
|
||||||
struct fuse_config *cfg)
|
struct fuse_config *cfg)
|
||||||
{
|
{
|
||||||
@ -132,7 +134,7 @@ static int xmp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
|
|||||||
memset(&st, 0, sizeof(st));
|
memset(&st, 0, sizeof(st));
|
||||||
st.st_ino = de->d_ino;
|
st.st_ino = de->d_ino;
|
||||||
st.st_mode = de->d_type << 12;
|
st.st_mode = de->d_type << 12;
|
||||||
if (filler(buf, de->d_name, &st, 0, FUSE_FILL_DIR_PLUS))
|
if (filler(buf, de->d_name, &st, 0, fill_dir_plus))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -551,6 +553,18 @@ static const struct fuse_operations xmp_oper = {
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
enum { MAX_ARGS = 10 };
|
||||||
|
int i,new_argc;
|
||||||
|
char *new_argv[MAX_ARGS];
|
||||||
|
|
||||||
umask(0);
|
umask(0);
|
||||||
return fuse_main(argc, argv, &xmp_oper, NULL);
|
/* Process the "--plus" option apart */
|
||||||
|
for (i=0, new_argc=0; (i<argc) && (new_argc<MAX_ARGS); i++) {
|
||||||
|
if (!strcmp(argv[i], "--plus")) {
|
||||||
|
fill_dir_plus = FUSE_FILL_DIR_PLUS;
|
||||||
|
} else {
|
||||||
|
new_argv[new_argc++] = argv[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fuse_main(new_argc, new_argv, &xmp_oper, NULL);
|
||||||
}
|
}
|
||||||
|
@ -3578,6 +3578,11 @@ static int fill_dir_plus(void *dh_, const char *name, const struct stat *statp,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
e.attr.st_ino = FUSE_UNKNOWN_INO;
|
e.attr.st_ino = FUSE_UNKNOWN_INO;
|
||||||
|
if (statp) {
|
||||||
|
e.attr.st_mode = statp->st_mode;
|
||||||
|
if (f->conf.use_ino)
|
||||||
|
e.attr.st_ino = statp->st_ino;
|
||||||
|
}
|
||||||
if (!f->conf.use_ino && f->conf.readdir_ino) {
|
if (!f->conf.use_ino && f->conf.readdir_ino) {
|
||||||
e.attr.st_ino = (ino_t)
|
e.attr.st_ino = (ino_t)
|
||||||
lookup_nodeid(f, dh->nodeid, name);
|
lookup_nodeid(f, dh->nodeid, name);
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Prints each directory entry and its inode as returned by 'readdir'.
|
* Prints each directory entry, its inode and d_type as returned by 'readdir'.
|
||||||
* Skips '.' and '..' because readdir is not required to return them and
|
* Skips '.' and '..' because readdir is not required to return them and
|
||||||
* some of our examples don't.
|
* some of our examples don't. However if they are returned, their d_type
|
||||||
|
* should be valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -30,7 +31,18 @@ int main(int argc, char* argv[])
|
|||||||
dent = readdir(dirp);
|
dent = readdir(dirp);
|
||||||
while (dent != NULL) {
|
while (dent != NULL) {
|
||||||
if (strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0) {
|
if (strcmp(dent->d_name, ".") != 0 && strcmp(dent->d_name, "..") != 0) {
|
||||||
printf("%llu %s\n", (unsigned long long)dent->d_ino, dent->d_name);
|
printf("%llu %d %s\n", (unsigned long long)dent->d_ino,
|
||||||
|
(int)dent->d_type, dent->d_name);
|
||||||
|
if ((long long)dent->d_ino < 0)
|
||||||
|
fprintf(stderr,"%s : bad d_ino %llu\n",
|
||||||
|
dent->d_name, (unsigned long long)dent->d_ino);
|
||||||
|
if ((dent->d_type < 1) || (dent->d_type > 15))
|
||||||
|
fprintf(stderr,"%s : bad d_type %d\n",
|
||||||
|
dent->d_name, (int)dent->d_type);
|
||||||
|
} else {
|
||||||
|
if (dent->d_type != DT_DIR)
|
||||||
|
fprintf(stderr,"%s : bad d_type %d\n",
|
||||||
|
dent->d_name, (int)dent->d_type);
|
||||||
}
|
}
|
||||||
dent = readdir(dirp);
|
dent = readdir(dirp);
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,8 @@ def test_hello(tmpdir, name, options, cmdline_builder, output_checker):
|
|||||||
umount(mount_process, mnt_dir)
|
umount(mount_process, mnt_dir)
|
||||||
|
|
||||||
@pytest.mark.parametrize("writeback", (False, True))
|
@pytest.mark.parametrize("writeback", (False, True))
|
||||||
@pytest.mark.parametrize("name", ('passthrough', 'passthrough_fh', 'passthrough_ll'))
|
@pytest.mark.parametrize("name", ('passthrough', 'passthrough_plus',
|
||||||
|
'passthrough_fh', 'passthrough_ll'))
|
||||||
@pytest.mark.parametrize("debug", (False, True))
|
@pytest.mark.parametrize("debug", (False, True))
|
||||||
def test_passthrough(short_tmpdir, name, debug, output_checker, writeback):
|
def test_passthrough(short_tmpdir, name, debug, output_checker, writeback):
|
||||||
# Avoid false positives from libfuse debug messages
|
# Avoid false positives from libfuse debug messages
|
||||||
@ -124,9 +125,14 @@ def test_passthrough(short_tmpdir, name, debug, output_checker, writeback):
|
|||||||
mnt_dir = str(short_tmpdir.mkdir('mnt'))
|
mnt_dir = str(short_tmpdir.mkdir('mnt'))
|
||||||
src_dir = str(short_tmpdir.mkdir('src'))
|
src_dir = str(short_tmpdir.mkdir('src'))
|
||||||
|
|
||||||
cmdline = base_cmdline + \
|
if name == 'passthrough_plus':
|
||||||
[ pjoin(basename, 'example', name),
|
cmdline = base_cmdline + \
|
||||||
'-f', mnt_dir ]
|
[ pjoin(basename, 'example', 'passthrough'),
|
||||||
|
'--plus', '-f', mnt_dir ]
|
||||||
|
else:
|
||||||
|
cmdline = base_cmdline + \
|
||||||
|
[ pjoin(basename, 'example', name),
|
||||||
|
'-f', mnt_dir ]
|
||||||
if debug:
|
if debug:
|
||||||
cmdline.append('-d')
|
cmdline.append('-d')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user