"No functional changes" ? With a better commit message, Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx> --D On Tue, May 23, 2023 at 02:30:47PM +0530, Chandan Babu R wrote: > Signed-off-by: Chandan Babu R <chandan.babu@xxxxxxxxxx> > --- > mdrestore/xfs_mdrestore.c | 43 +++++++++++++++++++++++---------------- > 1 file changed, 26 insertions(+), 17 deletions(-) > > diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c > index 52081a6ca..615ecdc77 100644 > --- a/mdrestore/xfs_mdrestore.c > +++ b/mdrestore/xfs_mdrestore.c > @@ -86,6 +86,30 @@ open_device( > return fd; > } > > +static void > +verify_device_size( > + int dev_fd, > + bool is_file, > + xfs_rfsblock_t nr_blocks, > + uint32_t blocksize) > +{ > + if (is_file) { > + /* ensure regular files are correctly sized */ > + if (ftruncate(dev_fd, nr_blocks * blocksize)) > + fatal("cannot set filesystem image size: %s\n", > + strerror(errno)); > + } else { > + /* ensure device is sufficiently large enough */ > + char lb[XFS_MAX_SECTORSIZE] = { 0 }; > + off64_t off; > + > + off = nr_blocks * blocksize - sizeof(lb); > + if (pwrite(dev_fd, lb, sizeof(lb), off) < 0) > + fatal("failed to write last block, is target too " > + "small? (error: %s)\n", strerror(errno)); > + } > +} > + > static int > read_header_v1( > void *header, > @@ -179,23 +203,8 @@ restore_v1( > > ((struct xfs_dsb*)block_buffer)->sb_inprogress = 1; > > - if (is_target_file) { > - /* ensure regular files are correctly sized */ > - > - if (ftruncate(data_fd, sb.sb_dblocks * sb.sb_blocksize)) > - fatal("cannot set filesystem image size: %s\n", > - strerror(errno)); > - } else { > - /* ensure device is sufficiently large enough */ > - > - char lb[XFS_MAX_SECTORSIZE] = { 0 }; > - off64_t off; > - > - off = sb.sb_dblocks * sb.sb_blocksize - sizeof(lb); > - if (pwrite(data_fd, lb, sizeof(lb), off) < 0) > - fatal("failed to write last block, is target too " > - "small? (error: %s)\n", strerror(errno)); > - } > + verify_device_size(data_fd, is_target_file, sb.sb_dblocks, > + sb.sb_blocksize); > > bytes_read = 0; > > -- > 2.39.1 >