return 0;
}
-struct erofs_buffer_head *erofs_buffer_init(void);
+void erofs_buffer_init(erofs_blk_t startblk);
int erofs_bh_balloon(struct erofs_buffer_head *bh, erofs_off_t incr);
struct erofs_buffer_head *erofs_balloc(int type, erofs_off_t size,
void erofs_put_super(struct erofs_sb_info *sbi);
int erofs_writesb(struct erofs_sb_info *sbi, struct erofs_buffer_head *sb_bh,
erofs_blk_t *blocks);
+struct erofs_buffer_head *erofs_reserve_sb(void);
/* namei.c */
int erofs_read_inode_from_disk(struct erofs_inode *vi);
.flush = erofs_bh_flush_skip_write,
};
-/* return buffer_head of erofs super block (with size 0) */
-struct erofs_buffer_head *erofs_buffer_init(void)
+void erofs_buffer_init(erofs_blk_t startblk)
{
int i, j;
- struct erofs_buffer_head *bh = erofs_balloc(META, 0, 0, 0);
-
- if (IS_ERR(bh))
- return bh;
-
- bh->op = &erofs_skip_write_bhops;
for (i = 0; i < ARRAY_SIZE(mapped_buckets); i++)
for (j = 0; j < ARRAY_SIZE(mapped_buckets[0]); j++)
init_list_head(&mapped_buckets[i][j]);
- return bh;
+ tail_blkaddr = startblk;
}
static void erofs_bupdate_mapped(struct erofs_buffer_block *bb)
erofs_bdrop(sb_bh, false);
return ret;
}
+
+struct erofs_buffer_head *erofs_reserve_sb(void)
+{
+ struct erofs_buffer_head *bh;
+ int err;
+
+ erofs_buffer_init(0);
+ bh = erofs_balloc(META, 0, 0, 0);
+ if (IS_ERR(bh)) {
+ erofs_err("failed to allocate super: %s", PTR_ERR(bh));
+ return bh;
+ }
+ bh->op = &erofs_skip_write_bhops;
+ err = erofs_bh_balloon(bh, EROFS_SUPER_END);
+ if (err < 0) {
+ erofs_err("failed to balloon super: %s", erofs_strerror(err));
+ goto err_bdrop;
+ }
+
+ /* make sure that the super block should be the very first blocks */
+ (void)erofs_mapbh(bh->block);
+ if (erofs_btell(bh, false) != 0) {
+ erofs_err("failed to pin super block @ 0");
+ err = -EFAULT;
+ goto err_bdrop;
+ }
+ return bh;
+err_bdrop:
+ erofs_bdrop(bh, true);
+ return ERR_PTR(err);
+}
sbi.blkszbits = src->blkszbits;
}
- sb_bh = erofs_buffer_init();
+ sb_bh = erofs_reserve_sb();
if (IS_ERR(sb_bh)) {
err = PTR_ERR(sb_bh);
- erofs_err("failed to initialize buffers: %s",
- erofs_strerror(err));
- goto exit;
- }
- err = erofs_bh_balloon(sb_bh, EROFS_SUPER_END);
- if (err < 0) {
- erofs_err("failed to balloon erofs_super_block: %s",
- erofs_strerror(err));
- goto exit;
- }
-
- /* make sure that the super block should be the very first blocks */
- (void)erofs_mapbh(sb_bh->block);
- if (erofs_btell(sb_bh, false) != 0) {
- erofs_err("failed to reserve erofs_super_block");
goto exit;
}