Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=4fc17a61607... Commit: 4fc17a616077cb60180cb1831c461c3d4a8164a0 Parent: fc8f16fe894145c36425f4c16bd2f022bf094810 Author: Andrew Price anprice@redhat.com AuthorDate: Thu Feb 20 16:54:48 2014 +0000 Committer: Andrew Price anprice@redhat.com CommitterDate: Sat Mar 29 23:20:29 2014 +0000
libgfs2: Add lgfs2_space_for_data()
Add a function which calculates the total number of blocks required for a file given the size of its contents.
Signed-off-by: Andrew Price anprice@redhat.com --- gfs2/libgfs2/fs_ops.c | 18 ++++++++++++++++++ gfs2/libgfs2/libgfs2.h | 2 ++ 2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/fs_ops.c b/gfs2/libgfs2/fs_ops.c index 198f6eb..b95f2ed 100644 --- a/gfs2/libgfs2/fs_ops.c +++ b/gfs2/libgfs2/fs_ops.c @@ -273,6 +273,24 @@ void unstuff_dinode(struct gfs2_inode *ip) ip->i_di.di_height = 1; }
+/** + * Calculate the total number of blocks required by a file containing 'bytes' bytes of data. + */ +uint64_t lgfs2_space_for_data(const struct gfs2_sbd *sdp, const unsigned bsize, const uint64_t bytes) +{ + uint64_t blks = (bytes + bsize - 1) / bsize; + uint64_t ptrs = blks; + + if (bytes <= bsize - sizeof(struct gfs2_dinode)) + return 1; + + while (ptrs > sdp->sd_diptrs) { + ptrs = (ptrs + sdp->sd_inptrs - 1) / sdp->sd_inptrs; + blks += ptrs; + } + return blks + 1; +} + unsigned int calc_tree_height(struct gfs2_inode *ip, uint64_t size) { struct gfs2_sbd *sdp = ip->i_sbd; diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h index 6248e4b..ce51e8c 100644 --- a/gfs2/libgfs2/libgfs2.h +++ b/gfs2/libgfs2/libgfs2.h @@ -450,6 +450,8 @@ extern void inode_put(struct gfs2_inode **ip); extern uint64_t data_alloc(struct gfs2_inode *ip); extern int lgfs2_meta_alloc(struct gfs2_inode *ip, uint64_t *blkno); extern int lgfs2_dinode_alloc(struct gfs2_sbd *sdp, const uint64_t blksreq, uint64_t *blkno); +extern uint64_t lgfs2_space_for_data(const struct gfs2_sbd *sdp, unsigned bsize, uint64_t bytes); + extern int gfs2_readi(struct gfs2_inode *ip, void *buf, uint64_t offset, unsigned int size); #define gfs2_writei(ip, buf, offset, size) \
cluster-commits@lists.fedorahosted.org