2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public
4 * License v2 as published by the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * General Public License for more details.
11 * You should have received a copy of the GNU General Public
12 * License along with this program; if not, write to the
13 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
14 * Boston, MA 021110-1307, USA.
17 #if BTRFSCONVERT_REISERFS
19 #include "kerncompat.h"
20 #include <linux/limits.h>
26 #include "transaction.h"
29 #include "convert/common.h"
30 #include "convert/source-reiserfs.h"
32 static inline u8 mode_to_file_type(u32 mode)
34 switch (mode & S_IFMT) {
35 case S_IFREG: return BTRFS_FT_REG_FILE;
36 case S_IFDIR: return BTRFS_FT_DIR;
37 case S_IFCHR: return BTRFS_FT_CHRDEV;
38 case S_IFBLK: return BTRFS_FT_BLKDEV;
39 case S_IFIFO: return BTRFS_FT_FIFO;
40 case S_IFSOCK: return BTRFS_FT_SOCK;
41 case S_IFLNK: return BTRFS_FT_SYMLINK;
44 return BTRFS_FT_UNKNOWN;
47 static u32 reiserfs_count_objectids(reiserfs_filsys_t fs)
49 struct reiserfs_super_block *sb = fs->fs_ondisk_sb;
54 if (fs->fs_format == REISERFS_FORMAT_3_6)
55 map = (u32 *) (sb + 1);
57 map = (u32 *)((struct reiserfs_super_block_v1 *)sb + 1);
59 for (i = 0; i < get_sb_oid_cursize(sb); i += 2)
60 count += le32_to_cpu(map[i + 1]) - (le32_to_cpu(map[i]) + 1);
66 static int reiserfs_open_fs(struct btrfs_convert_context *cxt, const char *name)
68 struct reiserfs_convert_info *info;
72 fs = reiserfs_open(name, O_RDONLY, &error, NULL, 0);
76 error = reiserfs_open_ondisk_bitmap(fs);
83 cxt->blocksize = fs->fs_blocksize;
84 cxt->block_count = get_sb_block_count(fs->fs_ondisk_sb);
85 cxt->total_bytes = cxt->blocksize * cxt->block_count;
86 cxt->volume_name = strndup(fs->fs_ondisk_sb->s_label, 16);
87 cxt->first_data_block = 0;
88 cxt->inodes_count = reiserfs_count_objectids(fs);
89 cxt->free_inodes_count = 0;
90 info = calloc(1, sizeof(*info));
97 * Inode attributes are somewhat of a hack on reiserfs and it was
98 * once possible to have garbage in the flags field. A superblock
99 * field now indicates that the field has been cleared and can
100 * be considered valid, but only on v3.6 format file systems.
102 if (fs->fs_format == REISERFS_FORMAT_3_6 &&
103 get_sb_v2_flag(fs->fs_ondisk_sb, reiserfs_attrs_cleared))
104 info->copy_attrs = true;
110 static void reiserfs_close_fs(struct btrfs_convert_context *cxt)
112 reiserfs_filsys_t fs = cxt->fs_data;
113 struct reiserfs_convert_info *info = fs->fs_vp;
117 free(info->objectids);
122 /* We don't want changes to be persistent */
123 fs->fs_bitmap2->bm_dirty = 0;
128 static int compare_objectids(const void *p1, const void *p2)
140 static int lookup_cached_objectid(reiserfs_filsys_t fs, u64 objectid)
142 struct reiserfs_convert_info *info = fs->fs_vp;
145 if (!info->objectids)
147 result = bsearch(&objectid, info->objectids, info->used_slots,
148 sizeof(u64), compare_objectids);
149 return result != NULL;
152 static int insert_cached_objectid(reiserfs_filsys_t fs, u64 objectid)
154 struct reiserfs_convert_info *info = fs->fs_vp;
156 if (info->used_slots + 1 >= info->alloced_slots) {
157 u64 *objectids = realloc(info->objectids,
158 (info->alloced_slots + 1000) * sizeof(u64));
162 info->objectids = objectids;
163 info->alloced_slots += 1000;
165 info->objectids[info->used_slots++] = objectid;
167 qsort(info->objectids, info->used_slots, sizeof(u64), compare_objectids);
171 static int reiserfs_locate_privroot(reiserfs_filsys_t fs)
175 struct reiserfs_convert_info *info = fs->fs_vp;
176 struct reiserfs_key key = root_dir_key;
178 err = reiserfs_find_entry(fs, &key, ".reiserfs_priv",
179 &generation, &info->privroot_key);
181 err = reiserfs_find_entry(fs, &info->privroot_key, "xattrs",
182 &generation, &info->xattr_key);
184 memset(&info->xattr_key, 0, sizeof(info->xattr_key));
190 static void reiserfs_convert_inode_flags(struct btrfs_inode_item *inode,
191 const struct stat_data *sd)
193 u16 attrs = sd_v2_sd_attrs(sd);
196 if (attrs & FS_IMMUTABLE_FL)
197 new_flags |= BTRFS_INODE_IMMUTABLE;
199 if (attrs & FS_APPEND_FL)
200 new_flags |= BTRFS_INODE_APPEND;
202 if (attrs & FS_SYNC_FL)
203 new_flags |= BTRFS_INODE_SYNC;
205 if (attrs & FS_NOATIME_FL)
206 new_flags |= BTRFS_INODE_NOATIME;
208 if (attrs & FS_NODUMP_FL)
209 new_flags |= BTRFS_INODE_NODUMP;
211 if (attrs & FS_NODUMP_FL)
212 new_flags |= BTRFS_INODE_NODUMP;
214 btrfs_set_stack_inode_flags(inode, new_flags);
218 static void reiserfs_copy_inode_item(struct btrfs_inode_item *inode,
219 struct item_head *ih, void *stat_data,
220 bool copy_inode_flags)
225 memset(inode, 0, sizeof(*inode));
226 btrfs_set_stack_inode_generation(inode, 1);
227 if (get_ih_key_format(ih) == KEY_FORMAT_1) {
228 struct stat_data_v1 *sd = stat_data;
230 mode = sd_v1_mode(sd);
231 btrfs_set_stack_inode_size(inode, sd_v1_size(sd));
232 btrfs_set_stack_inode_nlink(inode, sd_v1_nlink(sd));
233 btrfs_set_stack_inode_uid(inode, sd_v1_uid(sd));
234 btrfs_set_stack_inode_gid(inode, sd_v1_gid(sd));
235 btrfs_set_stack_timespec_sec(&inode->atime, sd_v1_atime(sd));
236 btrfs_set_stack_timespec_sec(&inode->ctime, sd_v1_ctime(sd));
237 btrfs_set_stack_timespec_sec(&inode->mtime, sd_v1_mtime(sd));
239 if (!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
240 rdev = decode_dev(sd_v1_rdev(sd));
242 struct stat_data *sd = stat_data;
244 mode = sd_v2_mode(sd);
245 btrfs_set_stack_inode_size(inode, sd_v2_size(sd));
246 btrfs_set_stack_inode_nlink(inode, sd_v2_nlink(sd));
247 btrfs_set_stack_inode_uid(inode, sd_v2_uid(sd));
248 btrfs_set_stack_inode_gid(inode, sd_v2_gid(sd));
249 btrfs_set_stack_timespec_sec(&inode->atime, sd_v2_atime(sd));
250 btrfs_set_stack_timespec_sec(&inode->ctime, sd_v2_ctime(sd));
251 btrfs_set_stack_timespec_sec(&inode->mtime, sd_v2_mtime(sd));
253 if (!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
254 rdev = decode_dev(sd_v2_rdev(sd));
256 if (copy_inode_flags)
257 reiserfs_convert_inode_flags(inode, sd);
261 btrfs_set_stack_inode_size(inode, 0);
262 btrfs_set_stack_inode_nlink(inode, 1);
264 btrfs_set_stack_inode_mode(inode, mode);
265 btrfs_set_stack_inode_rdev(inode, rdev);
268 static void init_reiserfs_blk_iterate_data(
269 struct reiserfs_blk_iterate_data *data,
270 struct btrfs_trans_handle *trans,
271 struct btrfs_root *root,
272 struct btrfs_inode_item *inode,
273 u64 objectid, u32 convert_flags)
275 init_blk_iterate_data(&data->blk_data, trans, root, inode, objectid,
276 convert_flags & CONVERT_FLAG_DATACSUM);
277 data->inline_data = NULL;
278 data->inline_offset = (u64)-1;
279 data->inline_length = 0;
282 static int reiserfs_record_indirect_extent(reiserfs_filsys_t fs, u64 position,
283 u64 size, int num_ptrs,
284 u32 *ptrs, void *data)
286 struct reiserfs_blk_iterate_data *bdata = data;
287 u32 file_block = position / fs->fs_blocksize;
291 for (i = 0; i < num_ptrs; i++, file_block++) {
292 u32 block = d32_get(ptrs, i);
294 ret = block_iterate_proc(block, file_block, &bdata->blk_data);
303 * Unlike btrfs inline extents, reiserfs can have multiple inline extents.
304 * This handles concatanating multiple tails into one inline extent
307 static int reiserfs_record_direct_extent(reiserfs_filsys_t fs, __u64 position,
308 __u64 size, const char *body,
309 size_t len, void *data)
311 struct reiserfs_blk_iterate_data *bdata = data;
314 if (bdata->inline_offset == (u64)-1)
315 bdata->inline_offset = position;
316 else if (bdata->inline_offset + bdata->inline_length != position) {
318 * This condition shouldn't actually happen, but better to
319 * catch it than break silently.
322 "source fs contains file with multiple tails but they are not contiguous");
326 inline_data = realloc(bdata->inline_data, bdata->inline_length + len);
330 bdata->inline_data = inline_data;
331 memcpy(bdata->inline_data + bdata->inline_length, body, len);
332 bdata->inline_length += len;
337 static int convert_direct(struct btrfs_trans_handle *trans,
338 struct btrfs_root *root, u64 objectid,
339 struct btrfs_inode_item *inode, const char *body,
340 u32 length, u64 offset, u32 convert_flags)
342 struct btrfs_key key;
343 u32 sectorsize = root->fs_info->sectorsize;
345 struct extent_buffer *eb;
347 BUG_ON(length > sectorsize);
348 ret = btrfs_reserve_extent(trans, root, sectorsize,
349 0, 0, -1ULL, &key, 1);
353 eb = alloc_extent_buffer(&root->fs_info->extent_cache, key.objectid,
359 write_extent_buffer(eb, body, 0, length);
360 ret = write_and_map_eb(root->fs_info, eb);
361 free_extent_buffer(eb);
365 return btrfs_record_file_extent(trans, root, objectid, inode, offset,
366 key.objectid, sectorsize);
369 static int reiserfs_convert_tail(struct btrfs_trans_handle *trans,
370 struct btrfs_root *root,
371 struct btrfs_inode_item *inode,
372 u64 objectid, u64 offset,
373 const void *body, unsigned length,
379 if (length >= BTRFS_MAX_INLINE_DATA_SIZE(root->fs_info) ||
380 length >= root->fs_info->sectorsize)
381 return convert_direct(trans, root, objectid, inode, body,
382 length, offset, convert_flags);
384 ret = btrfs_insert_inline_extent(trans, root, objectid,
385 offset, body, length);
389 isize = btrfs_stack_inode_nbytes(inode);
390 btrfs_set_stack_inode_nbytes(inode, isize + length);
395 static inline u32 block_count(u64 size, u32 blocksize)
397 return round_up(size, blocksize) / blocksize;
400 static int reiserfs_record_file_extents(reiserfs_filsys_t fs,
401 struct btrfs_trans_handle *trans,
402 struct btrfs_root *root,
404 struct btrfs_inode_item *inode,
405 struct reiserfs_key *sd_key,
410 u32 blocksize = fs->fs_blocksize;
411 u64 inode_size = btrfs_stack_inode_size(inode);
413 struct reiserfs_blk_iterate_data data;
415 init_reiserfs_blk_iterate_data(&data, trans, root, inode,
416 objectid, convert_flags);
418 ret = reiserfs_iterate_file_data(fs, sd_key,
419 reiserfs_record_indirect_extent,
420 reiserfs_record_direct_extent, &data);
425 * blk_iterate_block has no idea that we're done iterating, so record
426 * the final range if any. This range can end and still have a tail
429 if (data.blk_data.num_blocks) {
430 ret = record_file_blocks(&data.blk_data,
431 data.blk_data.first_block,
432 data.blk_data.disk_block,
433 data.blk_data.num_blocks);
436 data.blk_data.first_block += data.blk_data.num_blocks;
437 data.blk_data.num_blocks = 0;
441 * Handle a hole at the end of the file. ReiserFS will
442 * not write a tail followed by a hole but it will write a hole
443 * followed by a tail.
445 last_block = block_count(inode_size - data.inline_length, blocksize);
446 if (last_block > data.blk_data.first_block) {
447 ret = record_file_blocks(&data.blk_data,
448 data.blk_data.first_block, 0,
449 last_block - data.blk_data.first_block);
454 if (data.inline_length) {
455 ret = reiserfs_convert_tail(trans, root, inode, objectid,
458 data.inline_length, convert_flags);
468 static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
469 u32 convert_flags, u32 deh_dirid,
470 u32 deh_objectid, u8 *type);
472 static int reiserfs_copy_dirent(reiserfs_filsys_t fs,
473 const struct reiserfs_key *dir_short_key,
474 const char *name, size_t len,
475 __u32 deh_dirid, __u32 deh_objectid,
480 struct btrfs_trans_handle *trans;
481 u64 objectid = deh_objectid + OID_OFFSET;
482 struct reiserfs_convert_info *info = fs->fs_vp;
483 struct reiserfs_dirent_data *dirent_data = cb_data;
484 struct btrfs_root *root = dirent_data->root;
485 __u32 dir_objectid = get_key_objectid(dir_short_key) + OID_OFFSET;
488 * These are the extended attributes and shouldn't appear as files
489 * in the converted file systems.
491 if (deh_objectid == get_key_objectid(&info->privroot_key))
494 ret = reiserfs_copy_meta(fs, root, dirent_data->convert_flags,
495 deh_dirid, deh_objectid, &type);
498 "an error occured while converting \"%.*s\", reiserfs key [%u %u]: %s",
499 (int)len, name, deh_dirid, deh_objectid,
503 trans = btrfs_start_transaction(root, 1);
505 return PTR_ERR(trans);
507 ret = convert_insert_dirent(trans, root, name, len, dir_objectid,
508 objectid, type, dirent_data->index++,
510 return btrfs_commit_transaction(trans, root);
513 static int reiserfs_copy_symlink(struct btrfs_trans_handle *trans,
514 struct btrfs_root *root, u64 objectid,
515 struct btrfs_inode_item *btrfs_inode,
516 reiserfs_filsys_t fs,
517 struct reiserfs_path *sd_path)
519 INITIALIZE_REISERFS_PATH(path);
520 struct item_head *ih = tp_item_head(sd_path);
521 struct reiserfs_key key = ih->ih_key;
526 set_key_uniqueness(&key, type2uniqueness(TYPE_DIRECT));
527 set_key_offset_v1(&key, 1);
529 ret = reiserfs_search_by_key_3(fs, &key, &path);
530 if (ret != ITEM_FOUND) {
535 symlink = tp_item_body(&path);
536 len = get_ih_item_len(tp_item_head(&path));
538 ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
540 btrfs_set_stack_inode_nbytes(btrfs_inode, len + 1);
546 static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
547 u32 convert_flags, u32 deh_dirid,
548 u32 deh_objectid, u8 *type)
550 INITIALIZE_REISERFS_PATH(path);
552 struct item_head *ih;
553 struct reiserfs_key key;
554 struct btrfs_inode_item btrfs_inode;
555 struct btrfs_trans_handle *trans = NULL;
556 struct reiserfs_convert_info *info = fs->fs_vp;
558 u64 objectid = deh_objectid + OID_OFFSET;
559 u64 parent = deh_dirid + OID_OFFSET;
560 struct reiserfs_dirent_data dirent_data = {
562 .convert_flags = convert_flags,
563 .inode = &btrfs_inode,
567 /* The root directory's dirid in reiserfs points to an object
568 * that does't exist. In btrfs it's self-referential.
570 if (deh_dirid == REISERFS_ROOT_PARENT_OBJECTID)
573 set_key_dirid(&key, deh_dirid);
574 set_key_objectid(&key, deh_objectid);
575 set_key_offset_v2(&key, 0);
576 set_key_type_v2(&key, TYPE_STAT_DATA);
578 ret = reiserfs_search_by_key_3(fs, &key, &path);
579 if (ret != ITEM_FOUND) {
584 ih = tp_item_head(&path);
585 if (!is_stat_data_ih(ih)) {
590 reiserfs_copy_inode_item(&btrfs_inode, ih, tp_item_body(&path),
592 mode = btrfs_stack_inode_mode(&btrfs_inode);
593 *type = mode_to_file_type(mode);
596 /* Inodes with hardlinks should only be inserted once */
597 if (btrfs_stack_inode_nlink(&btrfs_inode) > 1) {
598 if (lookup_cached_objectid(fs, deh_objectid)) {
600 goto fail; /* Not a failure */
602 ret = insert_cached_objectid(fs, deh_objectid);
608 if (!(convert_flags & CONVERT_FLAG_DATACSUM)) {
609 u32 flags = btrfs_stack_inode_flags(&btrfs_inode) |
610 BTRFS_INODE_NODATASUM;
611 btrfs_set_stack_inode_flags(&btrfs_inode, flags);
614 switch (mode & S_IFMT) {
616 trans = btrfs_start_transaction(root, 1);
618 ret = PTR_ERR(trans);
621 ret = reiserfs_record_file_extents(fs, trans, root, objectid,
622 &btrfs_inode, &ih->ih_key,
628 ret = reiserfs_iterate_dir(fs, &ih->ih_key,
629 reiserfs_copy_dirent, &dirent_data);
632 trans = btrfs_start_transaction(root, 1);
634 ret = PTR_ERR(trans);
638 ret = btrfs_insert_inode_ref(trans, root, "..", 2, parent,
642 trans = btrfs_start_transaction(root, 1);
644 ret = PTR_ERR(trans);
647 ret = reiserfs_copy_symlink(trans, root, objectid,
648 &btrfs_inode, fs, &path);
653 trans = btrfs_start_transaction(root, 1);
655 ret = PTR_ERR(trans);
660 ret = btrfs_insert_inode(trans, root, objectid, &btrfs_inode);
663 ret = btrfs_commit_transaction(trans, root);
664 info->progress->cur_copy_inodes++;
671 static int reiserfs_xattr_indirect_fn(reiserfs_filsys_t fs, u64 position,
672 u64 size, int num_blocks,
673 u32 *blocks, void *data)
676 struct reiserfs_xattr_data *xa_data = data;
677 size_t alloc = min(position + num_blocks * fs->fs_blocksize, size);
680 if (size > BTRFS_LEAF_DATA_SIZE(xa_data->root->fs_info) -
681 sizeof(struct btrfs_item) - sizeof(struct btrfs_dir_item)) {
682 fprintf(stderr, "skip large xattr on objectid %llu name %.*s\n",
683 xa_data->target_oid, (int)xa_data->namelen,
688 body = realloc(xa_data->body, alloc);
692 xa_data->body = body;
693 xa_data->len = alloc;
695 for (i = 0; i < num_blocks; i++) {
697 u32 block = d32_get(blocks, i);
698 u64 offset = (u64)block * fs->fs_blocksize;
699 size_t chunk = min_t(u64, size - position, fs->fs_blocksize);
700 char *buffer = xa_data->body + position;
702 ret = read_disk_extent(xa_data->root, offset, chunk, buffer);
711 static int reiserfs_xattr_direct_fn(reiserfs_filsys_t fs, __u64 position,
712 __u64 size, const char *body, size_t len,
715 struct reiserfs_xattr_data *xa_data = data;
718 if (size > BTRFS_LEAF_DATA_SIZE(xa_data->root->fs_info) -
719 sizeof(struct btrfs_item) - sizeof(struct btrfs_dir_item)) {
720 fprintf(stderr, "skip large xattr on objectid %llu name %.*s\n",
721 xa_data->target_oid, (int)xa_data->namelen,
726 newbody = realloc(xa_data->body, position + len);
729 xa_data->body = newbody;
730 xa_data->len = position + len;
731 memcpy(xa_data->body + position, body, len);
735 static int reiserfs_acl_to_xattr(void *dst, const void *src,
736 size_t dst_size, size_t src_size)
739 const void *end = src + src_size;
740 acl_ea_header *ext_acl = (acl_ea_header *)dst;
741 acl_ea_entry *dst_entry = ext_acl->a_entries;
742 struct reiserfs_acl_entry *src_entry;
744 if (src_size < sizeof(struct reiserfs_acl_header))
746 if (((struct reiserfs_acl_header *)src)->a_version !=
747 cpu_to_le32(REISERFS_ACL_VERSION))
749 src += sizeof(struct reiserfs_acl_header);
750 count = reiserfs_acl_count(src_size);
754 BUG_ON(dst_size < acl_ea_size(count));
755 ext_acl->a_version = cpu_to_le32(ACL_EA_VERSION);
756 for (i = 0; i < count; i++, dst_entry++) {
757 src_entry = (struct reiserfs_acl_entry *)src;
758 if (src + sizeof(struct reiserfs_acl_entry_short) > end)
760 dst_entry->e_tag = src_entry->e_tag;
761 dst_entry->e_perm = src_entry->e_perm;
762 switch (le16_to_cpu(src_entry->e_tag)) {
767 src += sizeof(struct reiserfs_acl_entry_short);
768 dst_entry->e_id = cpu_to_le32(ACL_UNDEFINED_ID);
772 src += sizeof(struct reiserfs_acl_entry);
775 dst_entry->e_id = src_entry->e_id;
788 static int reiserfs_copy_one_xattr(reiserfs_filsys_t fs,
789 const struct reiserfs_key *dir_short_key,
790 const char *name, size_t namelen,
792 __u32 deh_objectid, void *cb_data)
794 struct reiserfs_convert_info *info = fs->fs_vp;
795 struct reiserfs_xattr_data *xa_data = cb_data;
796 struct reiserfs_key key = {
797 .k2_dir_id = deh_dirid,
798 .k2_objectid = deh_objectid,
804 xa_data->name = name;
805 xa_data->namelen = namelen;
807 ret = reiserfs_iterate_file_data(fs, &key, reiserfs_xattr_indirect_fn,
808 reiserfs_xattr_direct_fn, cb_data);
812 if (!reiserfs_check_xattr(xa_data->body, xa_data->len)) {
814 "skip corrupted xattr on objectid %u name %.*s\n",
815 deh_objectid, (int)xa_data->namelen,
820 body = xa_data->body + sizeof(struct reiserfs_xattr_header);
821 len = xa_data->len - sizeof(struct reiserfs_xattr_header);
823 if (!strncmp("system.posix_acl_default", name, namelen) ||
824 !strncmp("system.posix_acl_access", name, namelen)) {
825 size_t bufsize = acl_ea_size(ext2_acl_count(len));
826 char *databuf = malloc(bufsize);
830 ret = reiserfs_acl_to_xattr(databuf, body, bufsize, len);
837 ret = btrfs_insert_xattr_item(xa_data->trans, xa_data->root,
838 name, namelen, body, len,
839 xa_data->target_oid);
841 info->progress->cur_copy_inodes++;
844 body != xa_data->body + sizeof(struct reiserfs_xattr_header))
848 xa_data->body = NULL;
854 static int reiserfs_copy_xattr_dir(reiserfs_filsys_t fs,
855 const struct reiserfs_key *dir_short_key,
856 const char *name, size_t len,
857 __u32 deh_dirid, __u32 deh_objectid,
860 struct reiserfs_convert_info *info = fs->fs_vp;
861 struct reiserfs_xattr_data *xa_data = cb_data;
862 struct reiserfs_key dir_key = {
863 .k2_dir_id = deh_dirid,
864 .k2_objectid = deh_objectid,
869 xa_data->target_oid = strtoull(name, NULL, 16);
870 if (xa_data->target_oid == ULLONG_MAX && errno)
873 xa_data->target_oid += OID_OFFSET;
875 xa_data->trans = btrfs_start_transaction(xa_data->root, 1);
876 if (IS_ERR(xa_data->trans))
877 return PTR_ERR(xa_data->trans);
879 ret = reiserfs_iterate_dir(fs, &dir_key,
880 reiserfs_copy_one_xattr, xa_data);
882 err = btrfs_commit_transaction(xa_data->trans, xa_data->root);
883 info->progress->cur_copy_inodes++;
884 xa_data->trans = NULL;
888 static int reiserfs_copy_xattrs(reiserfs_filsys_t fs, struct btrfs_root *root)
890 struct reiserfs_convert_info *info = fs->fs_vp;
891 struct reiserfs_xattr_data data = {
895 if (get_key_objectid(&info->xattr_key) == 0)
898 return reiserfs_iterate_dir(fs, &info->xattr_key,
899 reiserfs_copy_xattr_dir, &data);
902 static int reiserfs_copy_inodes(struct btrfs_convert_context *cxt,
903 struct btrfs_root *root,
907 reiserfs_filsys_t fs = cxt->fs_data;
908 struct reiserfs_convert_info *info = fs->fs_vp;
914 ret = reiserfs_locate_privroot(fs);
918 ret = reiserfs_copy_meta(fs, root, convert_flags,
919 REISERFS_ROOT_PARENT_OBJECTID,
920 REISERFS_ROOT_OBJECTID, &type);
924 if (convert_flags & CONVERT_FLAG_XATTR)
925 ret = reiserfs_copy_xattrs(fs, root);
928 info->progress = NULL;
932 static int reiserfs_read_used_space(struct btrfs_convert_context *cxt)
934 reiserfs_filsys_t fs = cxt->fs_data;
936 unsigned int size = get_sb_block_count(fs->fs_ondisk_sb);
937 unsigned long *bitmap = (unsigned long *)fs->fs_bitmap2->bm_map;
941 * We have the entire bitmap loaded so we can just ping pong with
947 start = find_next_bit(bitmap, size, end);
950 end = find_next_zero_bit(bitmap, size, start);
953 offset = start * fs->fs_blocksize;
954 length = (end - start) * fs->fs_blocksize;
955 ret = add_merge_cache_extent(&cxt->used_space, offset, length);
963 static int reiserfs_check_state(struct btrfs_convert_context *cxt)
968 const struct btrfs_convert_operations reiserfs_convert_ops = {
970 .open_fs = reiserfs_open_fs,
971 .read_used_space = reiserfs_read_used_space,
972 .copy_inodes = reiserfs_copy_inodes,
973 .close_fs = reiserfs_close_fs,
974 .check_state = reiserfs_check_state,
977 #endif /* BTRFSCONVERT_REISERFS */