From 54f41759095318f5657793167f920d36b83a618d Mon Sep 17 00:00:00 2001 From: Avi Kivity <avi@cloudius-systems.com> Date: Tue, 3 Dec 2013 14:08:11 +0200 Subject: [PATCH] file: convert finit() to file's constructor Signed-off-by: Avi Kivity <avi@cloudius-systems.com> --- fs/vfs/kern_descrip.cc | 18 +++++++++--------- include/osv/file.h | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/vfs/kern_descrip.cc b/fs/vfs/kern_descrip.cc index 28b03aa31..6983bcf6e 100644 --- a/fs/vfs/kern_descrip.cc +++ b/fs/vfs/kern_descrip.cc @@ -152,14 +152,15 @@ int fget(int fd, struct file **out_fp) return 0; } -static void finit(struct file *fp, unsigned flags, filetype_t type, void *opaque, - struct fileops *ops) +file::file(unsigned flags, filetype_t type, void *opaque, + struct fileops *ops) + : f_flags(flags) + , f_count(1) + , f_ops(ops) + , f_data(opaque) + , f_type(type) { - fp->f_flags = flags; - fp->f_type = type; - fp->f_data = opaque; - fp->f_ops = ops; - fp->f_count = 1; + auto fp = this; TAILQ_INIT(&fp->f_poll_list); fo_init(fp); @@ -168,11 +169,10 @@ static void finit(struct file *fp, unsigned flags, filetype_t type, void *opaque fileref make_file(unsigned flags, filetype_t type, void *opaque, struct fileops *ops) { - file* fp = new (std::nothrow) file; + file* fp = new (std::nothrow) file(flags, type, opaque, ops); if (!fp) { throw ENOMEM; } - finit(fp, flags, type, opaque, ops); return fileref(fp, false); } diff --git a/include/osv/file.h b/include/osv/file.h index 38ec0cf97..7e7a9cc62 100755 --- a/include/osv/file.h +++ b/include/osv/file.h @@ -74,6 +74,8 @@ struct file; * File structure */ struct file { + file(unsigned flags, filetype_t type, void *opaque, + struct fileops *ops); ~file(); void operator delete(void *p) { osv::rcu_dispose(p); } int f_flags; /* open flags */ -- GitLab