diff --git a/fs/mqueue/mq_open.c b/fs/mqueue/mq_open.c index 18ab420ecd..627e57f4dd 100644 --- a/fs/mqueue/mq_open.c +++ b/fs/mqueue/mq_open.c @@ -253,10 +253,9 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name, /* Associate the inode with a file structure */ - mq->f_oflags = oflags; - mq->f_pos = 0; - mq->f_inode = inode; - mq->f_priv = NULL; + memset(mq, 0, sizeof(*mq)); + mq->f_oflags = oflags; + mq->f_inode = inode; if (created) { @@ -303,10 +302,9 @@ static int file_mq_vopen(FAR struct file *mq, FAR const char *mq_name, /* Associate the inode with a file structure */ - mq->f_oflags = oflags; - mq->f_pos = 0; - mq->f_inode = inode; - mq->f_priv = NULL; + memset(mq, 0, sizeof(*mq)); + mq->f_oflags = oflags; + mq->f_inode = inode; INODE_SET_MQUEUE(inode); inode->u.i_ops = &g_nxmq_fileops; diff --git a/fs/nxffs/nxffs_write.c b/fs/nxffs/nxffs_write.c index 35d2c42d80..a586635665 100644 --- a/fs/nxffs/nxffs_write.c +++ b/fs/nxffs/nxffs_write.c @@ -607,8 +607,8 @@ ssize_t nxffs_write(FAR struct file *filep, FAR const char *buffer, /* Success.. return the number of bytes written */ - ret = total; - filep->f_pos = wrfile->datlen; + ret = total; + filep->f_pos = wrfile->datlen; errout_with_lock: nxmutex_unlock(&volume->lock); diff --git a/fs/shm/shm_open.c b/fs/shm/shm_open.c index d10f8366d6..6274e460ed 100644 --- a/fs/shm/shm_open.c +++ b/fs/shm/shm_open.c @@ -141,10 +141,9 @@ static int file_shm_open(FAR struct file *shm, FAR const char *name, /* Associate the inode with a file structure */ + memset(shm, 0, sizeof(*shm)); shm->f_oflags = oflags; - shm->f_pos = 0; shm->f_inode = inode; - shm->f_priv = NULL; errout_with_sem: inode_unlock(); diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c index 523270329f..a7ab19002e 100644 --- a/fs/unionfs/fs_unionfs.c +++ b/fs/unionfs/fs_unionfs.c @@ -869,7 +869,7 @@ static int unionfs_open(FAR struct file *filep, FAR const char *relpath, /* Allocate a container to hold the open file system information */ uf = (FAR struct unionfs_file_s *) - kmm_malloc(sizeof(struct unionfs_file_s)); + kmm_zalloc(sizeof(struct unionfs_file_s)); if (uf == NULL) { ret = -ENOMEM; @@ -883,9 +883,7 @@ static int unionfs_open(FAR struct file *filep, FAR const char *relpath, um->um_node->u.i_mops != NULL); uf->uf_file.f_oflags = filep->f_oflags; - uf->uf_file.f_pos = 0; uf->uf_file.f_inode = um->um_node; - uf->uf_file.f_priv = NULL; ret = unionfs_tryopen(&uf->uf_file, relpath, um->um_prefix, oflags, mode); if (ret >= 0) @@ -901,9 +899,7 @@ static int unionfs_open(FAR struct file *filep, FAR const char *relpath, um = &ui->ui_fs[1]; uf->uf_file.f_oflags = filep->f_oflags; - uf->uf_file.f_pos = 0; uf->uf_file.f_inode = um->um_node; - uf->uf_file.f_priv = NULL; ret = unionfs_tryopen(&uf->uf_file, relpath, um->um_prefix, oflags, mode); diff --git a/fs/vfs/fs_close.c b/fs/vfs/fs_close.c index 139ea2592e..926f48f480 100644 --- a/fs/vfs/fs_close.c +++ b/fs/vfs/fs_close.c @@ -80,10 +80,7 @@ int file_close(FAR struct file *filep) /* Reset the user file struct instance so that it cannot be reused. */ - filep->f_oflags = 0; - filep->f_pos = 0; - filep->f_inode = NULL; - filep->f_priv = NULL; + memset(filep, 0, sizeof(*filep)); } return ret; diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c index eeb8415114..8568628457 100644 --- a/fs/vfs/fs_dir.c +++ b/fs/vfs/fs_dir.c @@ -607,8 +607,8 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) return ret; } - filep->f_inode = &g_dir_inode; - filep->f_priv = dir; + filep->f_inode = &g_dir_inode; + filep->f_priv = dir; inode_addref(&g_dir_inode); return ret; } diff --git a/fs/vfs/fs_dup2.c b/fs/vfs/fs_dup2.c index cb07556524..dfe91eada3 100644 --- a/fs/vfs/fs_dup2.c +++ b/fs/vfs/fs_dup2.c @@ -79,10 +79,10 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2) /* Then clone the file structure */ + memset(&temp, 0, sizeof(temp)); temp.f_oflags = filep1->f_oflags; temp.f_pos = filep1->f_pos; temp.f_inode = inode; - temp.f_priv = NULL; /* Call the open method on the file, driver, mountpoint so that it * can maintain the correct open counts. diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 44e344adf4..b0ca901666 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -156,10 +156,9 @@ static int file_vopen(FAR struct file *filep, FAR const char *path, /* Associate the inode with a file structure */ + memset(filep, 0, sizeof(*filep)); filep->f_oflags = oflags; - filep->f_pos = 0; filep->f_inode = inode; - filep->f_priv = NULL; /* Perform the driver open operation. NOTE that the open method may be * called many times. The driver/mountpoint logic should handle this