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 struct reiserfs_convert_info {
49 struct reiserfs_key privroot_key;
50 struct reiserfs_key xattr_key;
52 /* only set during copy_inodes */
53 struct task_ctx *progress;
55 /* used to track hardlinks */
57 unsigned alloced_slots;
61 static u32 reiserfs_count_objectids(reiserfs_filsys_t fs)
63 struct reiserfs_super_block *sb = fs->fs_ondisk_sb;
68 if (fs->fs_format == REISERFS_FORMAT_3_6)
69 map = (u32 *) (sb + 1);
71 map = (u32 *)((struct reiserfs_super_block_v1 *)sb + 1);
73 for (i = 0; i < get_sb_oid_cursize(sb); i += 2)
74 count += le32_to_cpu(map[i + 1]) - (le32_to_cpu(map[i]) + 1);
80 static int reiserfs_open_fs(struct btrfs_convert_context *cxt, const char *name)
82 struct reiserfs_convert_info *info;
86 fs = reiserfs_open(name, O_RDONLY, &error, NULL, 0);
90 error = reiserfs_open_ondisk_bitmap(fs);
97 cxt->blocksize = fs->fs_blocksize;
98 cxt->block_count = get_sb_block_count(fs->fs_ondisk_sb);
99 cxt->total_bytes = cxt->blocksize * cxt->block_count;
100 cxt->volume_name = strndup(fs->fs_ondisk_sb->s_label, 16);
101 cxt->first_data_block = 0;
102 cxt->inodes_count = reiserfs_count_objectids(fs);
103 cxt->free_inodes_count = 0;
104 info = calloc(1, sizeof(*info));
111 * Inode attributes are somewhat of a hack on reiserfs and it was
112 * once possible to have garbage in the flags field. A superblock
113 * field now indicates that the field has been cleared and can
114 * be considered valid, but only on v3.6 format file systems.
116 if (fs->fs_format == REISERFS_FORMAT_3_6 &&
117 get_sb_v2_flag(fs->fs_ondisk_sb, reiserfs_attrs_cleared))
118 info->copy_attrs = true;
124 static void reiserfs_close_fs(struct btrfs_convert_context *cxt)
126 reiserfs_filsys_t fs = cxt->fs_data;
127 struct reiserfs_convert_info *info = fs->fs_vp;
131 free(info->objectids);
136 /* We don't want changes to be persistent */
137 fs->fs_bitmap2->bm_dirty = 0;
142 static int compare_objectids(const void *p1, const void *p2)
154 static int lookup_cached_objectid(reiserfs_filsys_t fs, u64 objectid)
156 struct reiserfs_convert_info *info = fs->fs_vp;
159 if (!info->objectids)
161 result = bsearch(&objectid, info->objectids, info->used_slots,
162 sizeof(u64), compare_objectids);
163 return result != NULL;
166 static int insert_cached_objectid(reiserfs_filsys_t fs, u64 objectid)
168 struct reiserfs_convert_info *info = fs->fs_vp;
170 if (info->used_slots + 1 >= info->alloced_slots) {
171 u64 *objectids = realloc(info->objectids,
172 (info->alloced_slots + 1000) * sizeof(u64));
176 info->objectids = objectids;
177 info->alloced_slots += 1000;
179 info->objectids[info->used_slots++] = objectid;
181 qsort(info->objectids, info->used_slots, sizeof(u64), compare_objectids);
185 static int reiserfs_locate_privroot(reiserfs_filsys_t fs)
189 struct reiserfs_convert_info *info = fs->fs_vp;
190 struct reiserfs_key key = root_dir_key;
192 err = reiserfs_find_entry(fs, &key, ".reiserfs_priv",
193 &generation, &info->privroot_key);
195 err = reiserfs_find_entry(fs, &info->privroot_key, "xattrs",
196 &generation, &info->xattr_key);
198 memset(&info->xattr_key, 0, sizeof(info->xattr_key));
204 static void reiserfs_convert_inode_flags(struct btrfs_inode_item *inode,
205 const struct stat_data *sd)
207 u16 attrs = sd_v2_sd_attrs(sd);
210 if (attrs & FS_IMMUTABLE_FL)
211 new_flags |= BTRFS_INODE_IMMUTABLE;
213 if (attrs & FS_APPEND_FL)
214 new_flags |= BTRFS_INODE_APPEND;
216 if (attrs & FS_SYNC_FL)
217 new_flags |= BTRFS_INODE_SYNC;
219 if (attrs & FS_NOATIME_FL)
220 new_flags |= BTRFS_INODE_NOATIME;
222 if (attrs & FS_NODUMP_FL)
223 new_flags |= BTRFS_INODE_NODUMP;
225 if (attrs & FS_NODUMP_FL)
226 new_flags |= BTRFS_INODE_NODUMP;
228 btrfs_set_stack_inode_flags(inode, new_flags);
232 static void reiserfs_copy_inode_item(struct btrfs_inode_item *inode,
233 struct item_head *ih, void *stat_data,
234 bool copy_inode_flags)
239 memset(inode, 0, sizeof(*inode));
240 btrfs_set_stack_inode_generation(inode, 1);
241 if (get_ih_key_format(ih) == KEY_FORMAT_1) {
242 struct stat_data_v1 *sd = stat_data;
244 mode = sd_v1_mode(sd);
245 btrfs_set_stack_inode_size(inode, sd_v1_size(sd));
246 btrfs_set_stack_inode_nlink(inode, sd_v1_nlink(sd));
247 btrfs_set_stack_inode_uid(inode, sd_v1_uid(sd));
248 btrfs_set_stack_inode_gid(inode, sd_v1_gid(sd));
249 btrfs_set_stack_timespec_sec(&inode->atime, sd_v1_atime(sd));
250 btrfs_set_stack_timespec_sec(&inode->ctime, sd_v1_ctime(sd));
251 btrfs_set_stack_timespec_sec(&inode->mtime, sd_v1_mtime(sd));
253 if (!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
254 rdev = new_decode_dev(sd_v1_rdev(sd));
256 struct stat_data *sd = stat_data;
258 mode = sd_v2_mode(sd);
259 btrfs_set_stack_inode_size(inode, sd_v2_size(sd));
260 btrfs_set_stack_inode_nlink(inode, sd_v2_nlink(sd));
261 btrfs_set_stack_inode_uid(inode, sd_v2_uid(sd));
262 btrfs_set_stack_inode_gid(inode, sd_v2_gid(sd));
263 btrfs_set_stack_timespec_sec(&inode->atime, sd_v2_atime(sd));
264 btrfs_set_stack_timespec_sec(&inode->ctime, sd_v2_ctime(sd));
265 btrfs_set_stack_timespec_sec(&inode->mtime, sd_v2_mtime(sd));
267 if (!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
268 rdev = new_decode_dev(sd_v2_rdev(sd));
270 if (copy_inode_flags)
271 reiserfs_convert_inode_flags(inode, sd);
275 btrfs_set_stack_inode_size(inode, 0);
276 btrfs_set_stack_inode_nlink(inode, 1);
278 btrfs_set_stack_inode_mode(inode, mode);
279 btrfs_set_stack_inode_rdev(inode, rdev);
282 struct reiserfs_blk_iterate_data {
283 struct blk_iterate_data blk_data;
289 static void init_reiserfs_blk_iterate_data(
290 struct reiserfs_blk_iterate_data *data,
291 struct btrfs_trans_handle *trans,
292 struct btrfs_root *root,
293 struct btrfs_inode_item *inode,
294 u64 objectid, u32 convert_flags)
296 init_blk_iterate_data(&data->blk_data, trans, root, inode, objectid,
297 convert_flags & CONVERT_FLAG_DATACSUM);
298 data->inline_data = NULL;
299 data->inline_offset = (u64)-1;
300 data->inline_length = 0;
303 static int reiserfs_record_indirect_extent(reiserfs_filsys_t fs, u64 position,
304 u64 size, int num_ptrs,
305 u32 *ptrs, void *data)
307 struct reiserfs_blk_iterate_data *bdata = data;
308 u32 file_block = position / fs->fs_blocksize;
312 for (i = 0; i < num_ptrs; i++, file_block++) {
313 u32 block = d32_get(ptrs, i);
315 ret = block_iterate_proc(block, file_block, &bdata->blk_data);
324 * Unlike btrfs inline extents, reiserfs can have multiple inline extents.
325 * This handles concatanating multiple tails into one inline extent
328 static int reiserfs_record_direct_extent(reiserfs_filsys_t fs, __u64 position,
329 __u64 size, const char *body,
330 size_t len, void *data)
332 struct reiserfs_blk_iterate_data *bdata = data;
335 if (bdata->inline_offset == (u64)-1)
336 bdata->inline_offset = position;
337 else if (bdata->inline_offset + bdata->inline_length != position) {
339 * This condition shouldn't actually happen, but better to
340 * catch it than break silently.
343 "source fs contains file with multiple tails but they are not contiguous");
347 inline_data = realloc(bdata->inline_data, bdata->inline_length + len);
351 bdata->inline_data = inline_data;
352 memcpy(bdata->inline_data + bdata->inline_length, body, len);
353 bdata->inline_length += len;
358 static int convert_direct(struct btrfs_trans_handle *trans,
359 struct btrfs_root *root, u64 objectid,
360 struct btrfs_inode_item *inode, const char *body,
361 u32 length, u64 offset, u32 convert_flags)
363 struct btrfs_key key;
364 u32 sectorsize = root->fs_info->sectorsize;
366 struct extent_buffer *eb;
368 BUG_ON(length > sectorsize);
369 ret = btrfs_reserve_extent(trans, root, sectorsize,
370 0, 0, -1ULL, &key, 1);
374 eb = alloc_extent_buffer(&root->fs_info->extent_cache, key.objectid,
380 write_extent_buffer(eb, body, 0, length);
381 ret = write_and_map_eb(root->fs_info, eb);
382 free_extent_buffer(eb);
386 return btrfs_record_file_extent(trans, root, objectid, inode, offset,
387 key.objectid, sectorsize);
390 static int reiserfs_convert_tail(struct btrfs_trans_handle *trans,
391 struct btrfs_root *root,
392 struct btrfs_inode_item *inode,
393 u64 objectid, u64 offset,
394 const void *body, unsigned length,
400 if (length >= BTRFS_MAX_INLINE_DATA_SIZE(root))
401 return convert_direct(trans, root, objectid, inode, body,
402 length, offset, convert_flags);
404 ret = btrfs_insert_inline_extent(trans, root, objectid,
405 offset, body, length);
409 isize = btrfs_stack_inode_nbytes(inode);
410 btrfs_set_stack_inode_nbytes(inode, isize + length);
415 static inline u32 block_count(u64 size, u32 blocksize)
417 return round_up(size, blocksize) / blocksize;
420 static int reiserfs_record_file_extents(reiserfs_filsys_t fs,
421 struct btrfs_trans_handle *trans,
422 struct btrfs_root *root,
424 struct btrfs_inode_item *inode,
425 struct reiserfs_key *sd_key,
430 u32 blocksize = fs->fs_blocksize;
431 u64 inode_size = btrfs_stack_inode_size(inode);
433 struct reiserfs_blk_iterate_data data;
435 init_reiserfs_blk_iterate_data(&data, trans, root, inode,
436 objectid, convert_flags);
438 ret = reiserfs_iterate_file_data(fs, sd_key,
439 reiserfs_record_indirect_extent,
440 reiserfs_record_direct_extent, &data);
445 * blk_iterate_block has no idea that we're done iterating, so record
446 * the final range if any. This range can end and still have a tail
449 if (data.blk_data.num_blocks) {
450 ret = record_file_blocks(&data.blk_data,
451 data.blk_data.first_block,
452 data.blk_data.disk_block,
453 data.blk_data.num_blocks);
456 data.blk_data.first_block += data.blk_data.num_blocks;
457 data.blk_data.num_blocks = 0;
461 * Handle a hole at the end of the file. ReiserFS will
462 * not write a tail followed by a hole but it will write a hole
463 * followed by a tail.
465 last_block = block_count(inode_size - data.inline_length, blocksize);
466 if (last_block > data.blk_data.first_block) {
467 ret = record_file_blocks(&data.blk_data,
468 data.blk_data.first_block, 0,
469 last_block - data.blk_data.first_block);
474 if (data.inline_length) {
475 ret = reiserfs_convert_tail(trans, root, inode, objectid,
478 data.inline_length, convert_flags);
488 #define OID_OFFSET (BTRFS_FIRST_FREE_OBJECTID - REISERFS_ROOT_OBJECTID)
489 static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
490 u32 convert_flags, u32 deh_dirid,
491 u32 deh_objectid, u8 *type);
493 struct reiserfs_dirent_data {
496 struct btrfs_inode_item *inode;
497 struct btrfs_root *root;
500 static int reiserfs_copy_dirent(reiserfs_filsys_t fs,
501 const struct reiserfs_key *dir_short_key,
502 const char *name, size_t len,
503 __u32 deh_dirid, __u32 deh_objectid,
508 struct btrfs_trans_handle *trans;
509 u64 objectid = deh_objectid + OID_OFFSET;
510 struct reiserfs_convert_info *info = fs->fs_vp;
511 struct reiserfs_dirent_data *dirent_data = cb_data;
512 struct btrfs_root *root = dirent_data->root;
513 __u32 dir_objectid = get_key_objectid(dir_short_key) + OID_OFFSET;
516 * These are the extended attributes and shouldn't appear as files
517 * in the converted file systems.
519 if (deh_objectid == get_key_objectid(&info->privroot_key))
522 ret = reiserfs_copy_meta(fs, root, dirent_data->convert_flags,
523 deh_dirid, deh_objectid, &type);
526 "an error occured while converting \"%.*s\", reiserfs key [%u %u]: %s",
527 (int)len, name, deh_dirid, deh_objectid,
531 trans = btrfs_start_transaction(root, 1);
535 ret = convert_insert_dirent(trans, root, name, len, dir_objectid,
536 objectid, type, dirent_data->index++,
538 return btrfs_commit_transaction(trans, root);
541 static int reiserfs_copy_symlink(struct btrfs_trans_handle *trans,
542 struct btrfs_root *root, u64 objectid,
543 struct btrfs_inode_item *btrfs_inode,
544 reiserfs_filsys_t fs,
545 struct reiserfs_path *sd_path)
547 INITIALIZE_REISERFS_PATH(path);
548 struct item_head *ih = tp_item_head(sd_path);
549 struct reiserfs_key key = ih->ih_key;
554 set_key_uniqueness(&key, type2uniqueness(TYPE_DIRECT));
555 set_key_offset_v1(&key, 1);
557 ret = reiserfs_search_by_key_3(fs, &key, &path);
558 if (ret != ITEM_FOUND) {
563 symlink = tp_item_body(&path);
564 len = get_ih_item_len(tp_item_head(&path));
566 ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
568 btrfs_set_stack_inode_nbytes(btrfs_inode, len + 1);
574 static int reiserfs_copy_meta(reiserfs_filsys_t fs, struct btrfs_root *root,
575 u32 convert_flags, u32 deh_dirid,
576 u32 deh_objectid, u8 *type)
578 INITIALIZE_REISERFS_PATH(path);
580 struct item_head *ih;
581 struct reiserfs_key key;
582 struct btrfs_inode_item btrfs_inode;
583 struct btrfs_trans_handle *trans = NULL;
584 struct reiserfs_convert_info *info = fs->fs_vp;
586 u64 objectid = deh_objectid + OID_OFFSET;
587 u64 parent = deh_dirid + OID_OFFSET;
588 struct reiserfs_dirent_data dirent_data = {
590 .convert_flags = convert_flags,
591 .inode = &btrfs_inode,
595 /* The root directory's dirid in reiserfs points to an object
596 * that does't exist. In btrfs it's self-referential.
598 if (deh_dirid == REISERFS_ROOT_PARENT_OBJECTID)
601 set_key_dirid(&key, deh_dirid);
602 set_key_objectid(&key, deh_objectid);
603 set_key_offset_v2(&key, 0);
604 set_key_type_v2(&key, TYPE_STAT_DATA);
606 ret = reiserfs_search_by_key_3(fs, &key, &path);
607 if (ret != ITEM_FOUND) {
612 ih = tp_item_head(&path);
613 if (!is_stat_data_ih(ih)) {
618 reiserfs_copy_inode_item(&btrfs_inode, ih, tp_item_body(&path),
620 mode = btrfs_stack_inode_mode(&btrfs_inode);
621 *type = mode_to_file_type(mode);
624 /* Inodes with hardlinks should only be inserted once */
625 if (btrfs_stack_inode_nlink(&btrfs_inode) > 1) {
626 if (lookup_cached_objectid(fs, deh_objectid)) {
628 goto fail; /* Not a failure */
630 ret = insert_cached_objectid(fs, deh_objectid);
636 if (!(convert_flags & CONVERT_FLAG_DATACSUM)) {
637 u32 flags = btrfs_stack_inode_flags(&btrfs_inode) |
638 BTRFS_INODE_NODATASUM;
639 btrfs_set_stack_inode_flags(&btrfs_inode, flags);
642 switch (mode & S_IFMT) {
644 trans = btrfs_start_transaction(root, 1);
649 ret = reiserfs_record_file_extents(fs, trans, root, objectid,
650 &btrfs_inode, &ih->ih_key,
656 ret = reiserfs_iterate_dir(fs, &ih->ih_key,
657 reiserfs_copy_dirent, &dirent_data);
660 trans = btrfs_start_transaction(root, 1);
666 ret = btrfs_insert_inode_ref(trans, root, "..", 2, parent,
670 trans = btrfs_start_transaction(root, 1);
675 ret = reiserfs_copy_symlink(trans, root, objectid,
676 &btrfs_inode, fs, &path);
681 trans = btrfs_start_transaction(root, 1);
688 ret = btrfs_insert_inode(trans, root, objectid, &btrfs_inode);
691 ret = btrfs_commit_transaction(trans, root);
692 info->progress->cur_copy_inodes++;
699 struct reiserfs_xattr_data {
700 struct btrfs_root *root;
701 struct btrfs_trans_handle *trans;
709 static int reiserfs_xattr_indirect_fn(reiserfs_filsys_t fs, u64 position,
710 u64 size, int num_blocks,
711 u32 *blocks, void *data)
714 struct reiserfs_xattr_data *xa_data = data;
715 size_t alloc = min(position + num_blocks * fs->fs_blocksize, size);
718 if (size > BTRFS_LEAF_DATA_SIZE(xa_data->root) -
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 body = realloc(xa_data->body, alloc);
730 xa_data->body = body;
731 xa_data->len = alloc;
733 for (i = 0; i < num_blocks; i++) {
735 u32 block = d32_get(blocks, i);
736 u64 offset = (u64)block * fs->fs_blocksize;
737 size_t chunk = min_t(u64, size - position, fs->fs_blocksize);
738 char *buffer = xa_data->body + position;
740 ret = read_disk_extent(xa_data->root, offset, chunk, buffer);
749 static int reiserfs_xattr_direct_fn(reiserfs_filsys_t fs, __u64 position,
750 __u64 size, const char *body, size_t len,
753 struct reiserfs_xattr_data *xa_data = data;
756 if (size > BTRFS_LEAF_DATA_SIZE(xa_data->root) -
757 sizeof(struct btrfs_item) - sizeof(struct btrfs_dir_item)) {
758 fprintf(stderr, "skip large xattr on objectid %llu name %.*s\n",
759 xa_data->target_oid, (int)xa_data->namelen,
764 newbody = realloc(xa_data->body, position + len);
767 xa_data->body = newbody;
768 xa_data->len = position + len;
769 memcpy(xa_data->body + position, body, len);
773 static int reiserfs_acl_to_xattr(void *dst, const void *src,
774 size_t dst_size, size_t src_size)
777 const void *end = src + src_size;
778 acl_ea_header *ext_acl = (acl_ea_header *)dst;
779 acl_ea_entry *dst_entry = ext_acl->a_entries;
780 struct reiserfs_acl_entry *src_entry;
782 if (src_size < sizeof(struct reiserfs_acl_header))
784 if (((struct reiserfs_acl_header *)src)->a_version !=
785 cpu_to_le32(REISERFS_ACL_VERSION))
787 src += sizeof(struct reiserfs_acl_header);
788 count = reiserfs_acl_count(src_size);
792 BUG_ON(dst_size < acl_ea_size(count));
793 ext_acl->a_version = cpu_to_le32(ACL_EA_VERSION);
794 for (i = 0; i < count; i++, dst_entry++) {
795 src_entry = (struct reiserfs_acl_entry *)src;
796 if (src + sizeof(struct reiserfs_acl_entry_short) > end)
798 dst_entry->e_tag = src_entry->e_tag;
799 dst_entry->e_perm = src_entry->e_perm;
800 switch (le16_to_cpu(src_entry->e_tag)) {
805 src += sizeof(struct reiserfs_acl_entry_short);
806 dst_entry->e_id = cpu_to_le32(ACL_UNDEFINED_ID);
810 src += sizeof(struct reiserfs_acl_entry);
813 dst_entry->e_id = src_entry->e_id;
826 static int reiserfs_copy_one_xattr(reiserfs_filsys_t fs,
827 const struct reiserfs_key *dir_short_key,
828 const char *name, size_t namelen,
830 __u32 deh_objectid, void *cb_data)
832 struct reiserfs_convert_info *info = fs->fs_vp;
833 struct reiserfs_xattr_data *xa_data = cb_data;
834 struct reiserfs_key key = {
835 .k2_dir_id = deh_dirid,
836 .k2_objectid = deh_objectid,
842 xa_data->name = name;
843 xa_data->namelen = namelen;
845 ret = reiserfs_iterate_file_data(fs, &key, reiserfs_xattr_indirect_fn,
846 reiserfs_xattr_direct_fn, cb_data);
850 if (!reiserfs_check_xattr(xa_data->body, xa_data->len)) {
852 "skip corrupted xattr on objectid %u name %.*s\n",
853 deh_objectid, (int)xa_data->namelen,
858 body = xa_data->body + sizeof(struct reiserfs_xattr_header);
859 len = xa_data->len - sizeof(struct reiserfs_xattr_header);
861 if (!strncmp("system.posix_acl_default", name, namelen) ||
862 !strncmp("system.posix_acl_access", name, namelen)) {
863 size_t bufsize = acl_ea_size(ext2_acl_count(len));
864 char *databuf = malloc(bufsize);
868 ret = reiserfs_acl_to_xattr(databuf, body, bufsize, len);
875 ret = btrfs_insert_xattr_item(xa_data->trans, xa_data->root,
876 name, namelen, body, len,
877 xa_data->target_oid);
879 info->progress->cur_copy_inodes++;
882 body != xa_data->body + sizeof(struct reiserfs_xattr_header))
886 xa_data->body = NULL;
892 static int reiserfs_copy_xattr_dir(reiserfs_filsys_t fs,
893 const struct reiserfs_key *dir_short_key,
894 const char *name, size_t len,
895 __u32 deh_dirid, __u32 deh_objectid,
898 struct reiserfs_convert_info *info = fs->fs_vp;
899 struct reiserfs_xattr_data *xa_data = cb_data;
900 struct reiserfs_key dir_key = {
901 .k2_dir_id = deh_dirid,
902 .k2_objectid = deh_objectid,
907 xa_data->target_oid = strtoull(name, NULL, 16);
908 if (xa_data->target_oid == ULLONG_MAX && errno)
911 xa_data->target_oid += OID_OFFSET;
913 xa_data->trans = btrfs_start_transaction(xa_data->root, 1);
917 ret = reiserfs_iterate_dir(fs, &dir_key,
918 reiserfs_copy_one_xattr, xa_data);
920 err = btrfs_commit_transaction(xa_data->trans, xa_data->root);
921 info->progress->cur_copy_inodes++;
922 xa_data->trans = NULL;
926 static int reiserfs_copy_xattrs(reiserfs_filsys_t fs, struct btrfs_root *root)
928 struct reiserfs_convert_info *info = fs->fs_vp;
929 struct reiserfs_xattr_data data = {
933 if (get_key_objectid(&info->xattr_key) == 0)
936 return reiserfs_iterate_dir(fs, &info->xattr_key,
937 reiserfs_copy_xattr_dir, &data);
940 static int reiserfs_copy_inodes(struct btrfs_convert_context *cxt,
941 struct btrfs_root *root,
945 reiserfs_filsys_t fs = cxt->fs_data;
946 struct reiserfs_convert_info *info = fs->fs_vp;
952 ret = reiserfs_locate_privroot(fs);
956 ret = reiserfs_copy_meta(fs, root, convert_flags,
957 REISERFS_ROOT_PARENT_OBJECTID,
958 REISERFS_ROOT_OBJECTID, &type);
962 if (convert_flags & CONVERT_FLAG_XATTR)
963 ret = reiserfs_copy_xattrs(fs, root);
966 info->progress = NULL;
970 static int reiserfs_read_used_space(struct btrfs_convert_context *cxt)
972 reiserfs_filsys_t fs = cxt->fs_data;
974 unsigned int size = get_sb_block_count(fs->fs_ondisk_sb);
975 unsigned long *bitmap = (unsigned long *)fs->fs_bitmap2->bm_map;
979 * We have the entire bitmap loaded so we can just ping pong with
985 start = find_next_bit(bitmap, size, end);
988 end = find_next_zero_bit(bitmap, size, start);
991 offset = start * fs->fs_blocksize;
992 length = (end - start) * fs->fs_blocksize;
993 ret = add_merge_cache_extent(&cxt->used_space, offset, length);
1001 static int reiserfs_check_state(struct btrfs_convert_context *cxt)
1006 const struct btrfs_convert_operations reiserfs_convert_ops = {
1008 .open_fs = reiserfs_open_fs,
1009 .read_used_space = reiserfs_read_used_space,
1010 .copy_inodes = reiserfs_copy_inodes,
1011 .close_fs = reiserfs_close_fs,
1012 .check_state = reiserfs_check_state,
1015 #endif /* BTRFSCONVERT_REISERFS */