@@ -143,9 +143,10 @@ static int local_open(FsContext *ctx, const char
*path, int
return open(rpath(ctx, path), flags);
}
-static DIR *local_opendir(FsContext *ctx, const char *path)
+static int local_opendir(FsContext *ctx, const char *path, DIR **dir)
{
- return opendir(rpath(ctx, path));
+ *dir = opendir(rpath(ctx, path));
+ return *dir ? 0 : -errno;
}
static void local_rewinddir(FsContext *ctx, DIR *dir)
@@ -110,9 +110,9 @@ static int v9fs_do_open(V9fsState *s, V9fsString
*path, int
return s->ops->open(&s->ctx, path->data, flags);
}
-static DIR *v9fs_do_opendir(V9fsState *s, V9fsString *path)
+static int v9fs_do_opendir(V9fsState *s, V9fsString *path, DIR **dir)
{
- return s->ops->opendir(&s->ctx, path->data);
+ return s->ops->opendir(&s->ctx, path->data, dir);
}
static void v9fs_do_rewinddir(V9fsState *s, DIR *dir)
@@ -1665,8 +1665,7 @@ static int32_t get_iounit(V9fsState *s, V9fsString
*name)
static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs,
int err)
{
- if (vs->fidp->fs.dir == NULL) {
- err = -errno;
+ if (err < 0) {
goto out;
}
vs->fidp->fid_type = P9_FID_DIR;
@@ -1714,7 +1713,7 @@ static void v9fs_open_post_lstat(V9fsState *s,
V9fsOpenSta
stat_to_qid(&vs->stbuf, &vs->qid);
if (S_ISDIR(vs->stbuf.st_mode)) {
- vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fidp->path);
+ err = v9fs_do_opendir(s, &vs->fidp->path, &vs->fidp->fs.dir);
v9fs_open_post_opendir(s, vs, err);
} else {
if (s->proto_version == V9FS_PROTO_2000L) {
@@ -2397,9 +2396,6 @@ static void v9fs_create_post_perms(V9fsState *s,
V9fsCreat
static void v9fs_create_post_opendir(V9fsState *s, V9fsCreateState *vs,
int err)
{
- if (!vs->fidp->fs.dir) {
- err = -errno;
- }
vs->fidp->fid_type = P9_FID_DIR;
v9fs_post_create(s, vs, err);
}
@@ -2412,7 +2408,7 @@ static void v9fs_create_post_dir_lstat(V9fsState
*s, V9fsC
goto out;
}
- vs->fidp->fs.dir = v9fs_do_opendir(s, &vs->fullname);
+ err = v9fs_do_opendir(s, &vs->fullname, &vs->fidp->fs.dir);
v9fs_create_post_opendir(s, vs, err);
return;
@@ -73,7 +73,7 @@ typedef struct FileOperations
int (*setuid)(FsContext *, uid_t);
int (*close)(FsContext *, int);
int (*closedir)(FsContext *, DIR *);
- DIR *(*opendir)(FsContext *, const char *);
+ int (*opendir)(FsContext *, const char *, DIR **);
int (*open)(FsContext *, const char *, int);
int (*open2)(FsContext *, const char *, int, FsCred *);
void (*rewinddir)(FsContext *, DIR *);