[Ocfs2-tools-devel] [PATCH 4/6] Fix filesize in create_file
Sunil Mushran
sunil.mushran at oracle.com
Tue Oct 25 13:51:17 PDT 2011
I am confused. create_file() merely creates a file and adds it
to a directory. It dies not allocate any space to it. The file size
should be zero.
On 08/22/2011 03:36 PM, Goldwyn Rodrigues wrote:
> While creating a new file, the filesize is left at zero, even though
> there is an extent in the file.
> This fix is required because further extents added using
> ocfs2_extend_allocation compute the offset based on current filesize.
>
> Signed-off-by: Goldwyn Rodrigues<rgoldwyn at suse.de>
> ---
> fswreck/extent.c | 18 ++++++++++++++++++
> 1 files changed, 18 insertions(+), 0 deletions(-)
>
> diff --git a/fswreck/extent.c b/fswreck/extent.c
> index e36deb9..f6fade0 100644
> --- a/fswreck/extent.c
> +++ b/fswreck/extent.c
> @@ -44,6 +44,12 @@ void create_file(ocfs2_filesys *fs, uint64_t blkno,
> uint64_t *retblkno)
> errcode_t ret;
> uint64_t tmp_blkno = 0;
> char random_name[OCFS2_MAX_FILENAME_LEN];
> + char *buf;
> + struct ocfs2_dinode *di;
> +
> + ret = ocfs2_malloc_block(fs->fs_io,&buf);
> + if (ret)
> + FSWRK_COM_FATAL(progname, errno);
>
> memset(random_name, 0, sizeof(random_name));
> sprintf(random_name, "testXXXXXX");
> @@ -70,8 +76,20 @@ void create_file(ocfs2_filesys *fs, uint64_t blkno,
> uint64_t *retblkno)
> if (ret)
> FSWRK_COM_FATAL(progname, ret);
>
> + /* Fix the i_size of the new file to greater than zero */
> + ret = ocfs2_read_inode(fs, tmp_blkno, buf);
> + if (ret)
> + FSWRK_COM_FATAL(progname, ret);
> + di = (struct ocfs2_dinode *)buf;
> +
> + di->i_size = ocfs2_clusters_to_bytes(fs, 1) - 25;
> + ret = ocfs2_write_inode(fs, tmp_blkno, buf);
> + if (ret)
> + FSWRK_COM_FATAL(progname, ret);
> +
> *retblkno = tmp_blkno;
>
> + ocfs2_free(&buf);
> return;
> }
>
More information about the Ocfs2-tools-devel
mailing list