diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 35 |
1 files changed, 19 insertions, 16 deletions
@@ -17,12 +17,24 @@ bool mog_open_expire_retry(struct mog_svc *svc) return false; } +static struct mog_fd *mog_file_init_common(int fd, struct mog_svc *svc) +{ + struct mog_fd *mfd = mog_fd_init(fd, MOG_FD_TYPE_FILE); + struct mog_file *file; + + file = &mfd->as.file; + memset(file, 0, sizeof(struct mog_file)); + file->svc = svc; + file->ioq = mog_ioq_current; + + return mfd; +} + /* path must be a free()-able pointer */ struct mog_fd * mog_file_open_read(struct mog_svc *svc, char *path) { struct mog_fd *mfd; - struct mog_file *mfile; int fd = mog_open_read(svc, path); if (fd < 0 && mog_open_expire_retry(svc)) @@ -30,12 +42,8 @@ mog_file_open_read(struct mog_svc *svc, char *path) if (fd < 0) return NULL; - mfd = mog_fd_init(fd, MOG_FD_TYPE_FILE); - - mfile = &mfd->as.file; - memset(mfile, 0, sizeof(struct mog_file)); - mfile->fsize = -1; - mfile->svc = svc; + mfd = mog_file_init_common(fd, svc); + mfd->as.file.fsize = -1; return mfd; } @@ -61,8 +69,6 @@ static int mkpath_open_put(struct mog_svc *svc, char *path, int flags) struct mog_fd * mog_file_open_put(struct mog_svc *svc, char *path, int flags) { - struct mog_fd *mfd; - struct mog_file *mfile; int fd = mkpath_open_put(svc, path, flags); if (fd < 0 && mog_open_expire_retry(svc)) @@ -70,18 +76,13 @@ mog_file_open_put(struct mog_svc *svc, char *path, int flags) if (fd < 0) return NULL; - mfd = mog_fd_init(fd, MOG_FD_TYPE_FILE); - - mfile = &mfd->as.file; - memset(mfile, 0, sizeof(struct mog_file)); - mfile->svc = svc; - - return mfd; + return mog_file_init_common(fd, svc); } void mog_file_close(struct mog_fd *mfd) { struct mog_file *mfile = &mfd->as.file; + struct mog_ioq *ioq; assert(mfd->fd_type == MOG_FD_TYPE_FILE && "mog_fd is not a file"); @@ -90,5 +91,7 @@ void mog_file_close(struct mog_fd *mfd) free(mfile->tmppath); mog_digest_destroy(&mfile->digest); + ioq = mfile->ioq; mog_fd_put(mfd); + mog_ioq_next(ioq); } |