#include "memory_utils.h"
-#if HAVE_FUSE3
-static inline int dir_filler(fuse_fill_dir_t filler, void *buf,
- const char *name, off_t off)
-{
- return filler(buf, name, NULL, off, FUSE_FILL_DIR_PLUS);
-}
-
-static inline int dirent_filler(fuse_fill_dir_t filler, const char *path,
- const char *name, void *buf, off_t off)
-{
- return filler(buf, name, NULL, off, FUSE_FILL_DIR_PLUS);
-}
-
-static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
- struct dirent *dentry, void *buf, off_t off)
-{
- return filler(buf, dentry->d_name, NULL, off, FUSE_FILL_DIR_PLUS);
-}
+#ifdef HAVE_FUSE3
+#define DIR_FILLER(F,B,N,S,O) F(B,N,S,O,FUSE_FILL_DIR_PLUS)
#else
+#define DIR_FILLER(F,B,N,S,O) F(B,N,S,O)
+#endif
+
static inline int dir_filler(fuse_fill_dir_t filler, void *buf,
const char *name, off_t off)
{
- return filler(buf, name, NULL, off);
+ return DIR_FILLER(filler, buf, name, NULL, off);
}
static inline int dirent_filler(fuse_fill_dir_t filler, const char *path,
dirp = opendir(path);
if (dirp && !fstatat(dirfd(dirp), name, &st, AT_SYMLINK_NOFOLLOW))
- return filler(buf, name, &st, off);
+ return DIR_FILLER(filler, buf, name, &st, off);
- return filler(buf, name, NULL, off);
+ return DIR_FILLER(filler, buf, name, NULL, off);
}
static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
};
}
- return filler(buf, dentry->d_name, &st, off);
+ return DIR_FILLER(filler, buf, dentry->d_name, &st, off);
+}
+static inline int dir_fillerat(fuse_fill_dir_t filler, DIR *dp,
+ const char *name, void *buf, off_t off)
+{
+ struct stat st;
+ int ret;
+
+ ret = fstatat(dirfd(dp), name, &st, AT_SYMLINK_NOFOLLOW);
+ if (ret)
+ return DIR_FILLER(filler, buf, name, NULL, off);
+
+ return DIR_FILLER(filler, buf, name, &st, off);
}
-#endif
#endif /* __LXCFS_FUSE_COMPAT_H */
{
__do_free __u32 *bitarr = NULL;
__do_free char *cg = NULL, *cpuset = NULL;
- __do_closedir DIR *dir = NULL;
+ __do_closedir DIR *dirp = NULL;
struct fuse_context *fc = fuse_get_context();
__u32 last_set_bit = 0;
int ret;
if (ret)
return ret;
+ dirp = opendir(path);
+ if (!dirp)
+ return -ENOENT;
+
for (__u32 bit = 0; bit <= last_set_bit; bit++) {
char cpu[100];
if (ret < 0 || (size_t)ret >= sizeof(cpu))
continue;
- if (dir_filler(filler, buf, cpu, 0) != 0)
+ if (dir_fillerat(filler, dirp, cpu, buf, 0) != 0)
return -ENOENT;
}
- dir = opendir(path);
- if (!dir)
- return -ENOENT;
-
- while ((dirent = readdir(dir))) {
+ while ((dirent = readdir(dirp))) {
char *entry = dirent->d_name;
if (strlen(entry) > 3) {
continue;
}
- if (dirent_fillerat(filler, dir, dirent, buf, 0) != 0)
+ if (dirent_fillerat(filler, dirp, dirent, buf, 0) != 0)
return -ENOENT;
}