#define Z_EROFS_COMPR_QUEUE_SZ (EROFS_CONFIG_COMPR_MAX_SZ * 2)
void z_erofs_drop_inline_pcluster(struct erofs_inode *inode);
-int erofs_write_compressed_file(struct erofs_inode *inode, int fd);
+int erofs_write_compressed_file(struct erofs_inode *inode, int fd, u64 fpos);
int z_erofs_compress_init(struct erofs_sb_info *sbi,
struct erofs_buffer_head *bh);
struct z_erofs_compress_ictx { /* inode context */
struct erofs_inode *inode;
- int fd;
unsigned int pclustersize;
+ int fd;
+ u64 fpos;
u32 tof_chksum;
bool fix_dedupedfrag;
int z_erofs_compress_segment(struct z_erofs_compress_sctx *ctx,
u64 offset, erofs_blk_t blkaddr)
{
- int fd = ctx->ictx->fd;
+ struct z_erofs_compress_ictx *ictx = ctx->ictx;
+ int fd = ictx->fd;
ctx->blkaddr = blkaddr;
while (ctx->remaining) {
ret = (offset == -1 ?
read(fd, ctx->queue + ctx->tail, rx) :
- pread(fd, ctx->queue + ctx->tail, rx, offset));
+ pread(fd, ctx->queue + ctx->tail, rx,
+ ictx->fpos + offset));
if (ret != rx)
return -errno;
}
#endif
-int erofs_write_compressed_file(struct erofs_inode *inode, int fd)
+int erofs_write_compressed_file(struct erofs_inode *inode, int fd, u64 fpos)
{
static u8 g_queue[Z_EROFS_COMPR_QUEUE_SZ];
struct erofs_buffer_head *bh;
blkaddr = erofs_mapbh(bh->block); /* start_blkaddr */
ctx.inode = inode;
ctx.pclustersize = z_erofs_get_max_pclustersize(inode);
+ ctx.fd = fd;
+ ctx.fpos = fpos;
ctx.metacur = compressmeta + Z_EROFS_LEGACY_MAP_HEADER_SIZE;
init_list_head(&ctx.extents);
- ctx.fd = fd;
ctx.fix_dedupedfrag = false;
ctx.fragemitted = false;
sctx = (struct z_erofs_compress_sctx) { .ictx = &ctx, };
}
if (cfg.c_compr_opts[0].alg && erofs_file_is_compressible(inode)) {
- ret = erofs_write_compressed_file(inode, fd);
+ ret = erofs_write_compressed_file(inode, fd, fpos);
if (!ret || ret != -ENOSPC)
return ret;
inode->nid = inode->sbi->packed_nid;
}
- ret = erofs_write_compressed_file(inode, fd);
+ ret = erofs_write_compressed_file(inode, fd, 0);
if (ret == -ENOSPC) {
ret = lseek(fd, 0, SEEK_SET);
if (ret < 0)