static errcode_t write_directory(e2fsck_t ctx, ext2_filsys fs, struct out_dir *outdir, ext2_ino_t ino, struct ext2_inode *inode, int compress) { struct write_dir_struct wd; errcode_t retval; retval = e2fsck_expand_directory(ctx, ino, -1, outdir->num); if (retval) return retval; wd.outdir = outdir; wd.err = 0; wd.ino = ino; wd.ctx = ctx; wd.dir = ino; retval = ext2fs_block_iterate3(fs, ino, 0, NULL, write_dir_block, &wd); if (retval) return retval; if (wd.err) return wd.err; e2fsck_read_inode(ctx, ino, inode, "rehash_dir"); if (compress) inode->i_flags &= ~EXT2_INDEX_FL; else inode->i_flags |= EXT2_INDEX_FL; #ifdef REHASH_DEBUG printf("%u: set inode size to %u blocks = %u bytes\n", ino, outdir->num, outdir->num * fs->blocksize); #endif retval = ext2fs_inode_size_set(fs, inode, (ext2_off64_t)outdir->num * fs->blocksize); if (retval) return retval; /* ext2fs_punch() calls ext2fs_write_inode() which writes the size */ return ext2fs_punch(fs, ino, inode, NULL, outdir->num, ~0ULL); }
static errcode_t file_test(ext2_filsys fs) { struct ext2_inode inode; ext2_ino_t newfile; errcode_t retval; size_t size; char *buf = 0, *cmpbuf = 0; int i; /* create a new file */ retval = ext2fs_new_inode(fs, 2, 010755, 0, &newfile); if (retval) { com_err("file_test", retval, "while allocaing a new inode"); return 1; } memset(&inode, 0, sizeof(inode)); inode.i_flags |= EXT4_INLINE_DATA_FL; inode.i_size = EXT4_MIN_INLINE_DATA_SIZE; inode.i_mode = LINUX_S_IFREG; retval = ext2fs_write_new_inode(fs, newfile, &inode); if (retval) { com_err("file_test", retval, "while writting a new inode"); return 1; } retval = ext2fs_inline_data_init(fs, newfile); if (retval) { com_err("file_test", retval, "while init 'system.data'"); return 1; } retval = ext2fs_inline_data_size(fs, newfile, &size); if (retval) { com_err("file_test", retval, "while getting size"); return 1; } if (size != EXT4_MIN_INLINE_DATA_SIZE) { fprintf(stderr, "tst_inline_data: size of inline data is wrong\n"); return 1; } ext2fs_get_mem(BUFF_SIZE, &buf); memset(buf, 'a', BUFF_SIZE); retval = ext2fs_inline_data_set(fs, newfile, 0, buf, BUFF_SIZE); if (retval) { com_err("file_test", retval, "while setting inline data %s", buf); goto err; } ext2fs_get_mem(BUFF_SIZE, &cmpbuf); retval = ext2fs_inline_data_get(fs, newfile, 0, cmpbuf, &size); if (retval) { com_err("file_test", retval, "while getting inline data"); goto err; } if (size != BUFF_SIZE) { fprintf(stderr, "tst_inline_data: size %lu != buflen %u\n", size, BUFF_SIZE); retval = 1; goto err; } if (memcmp(buf, cmpbuf, BUFF_SIZE)) { fprintf(stderr, "tst_inline_data: buf != cmpbuf\n"); retval = 1; goto err; } retval = ext2fs_punch(fs, newfile, 0, 0, 0, ~0ULL); if (retval) { com_err("file_test", retval, "while truncating inode"); goto err; } /* reload inode and check isize */ ext2fs_read_inode(fs, newfile, &inode); if (inode.i_size != 0) { fprintf(stderr, "tst_inline_data: i_size should be 0\n"); retval = 1; } err: if (cmpbuf) ext2fs_free_mem(&cmpbuf); if (buf) ext2fs_free_mem(&buf); return retval; }