2 * dupfs.c --- duplicate a ext2 filesystem handle
4 * Copyright (C) 1997, 1998, 2001, 2003, 2005 by Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
23 errcode_t
ext2fs_dup_handle(ext2_filsys src
, ext2_filsys
*dest
)
28 EXT2_CHECK_MAGIC(src
, EXT2_ET_MAGIC_EXT2FS_FILSYS
);
30 retval
= ext2fs_get_mem(sizeof(struct struct_ext2_filsys
), &fs
);
47 io_channel_bumpcount(fs
->io
);
49 fs
->icache
->refcount
++;
51 retval
= ext2fs_get_mem(strlen(src
->device_name
)+1, &fs
->device_name
);
54 strcpy(fs
->device_name
, src
->device_name
);
56 retval
= ext2fs_get_mem(SUPERBLOCK_SIZE
, &fs
->super
);
59 memcpy(fs
->super
, src
->super
, SUPERBLOCK_SIZE
);
61 retval
= ext2fs_get_mem(SUPERBLOCK_SIZE
, &fs
->orig_super
);
64 memcpy(fs
->orig_super
, src
->orig_super
, SUPERBLOCK_SIZE
);
66 retval
= ext2fs_get_array(fs
->desc_blocks
, fs
->blocksize
,
70 memcpy(fs
->group_desc
, src
->group_desc
,
71 (size_t) fs
->desc_blocks
* fs
->blocksize
);
74 retval
= ext2fs_copy_bitmap(src
->inode_map
, &fs
->inode_map
);
79 retval
= ext2fs_copy_bitmap(src
->block_map
, &fs
->block_map
);
84 retval
= ext2fs_badblocks_copy(src
->badblocks
, &fs
->badblocks
);
89 retval
= ext2fs_copy_dblist(src
->dblist
, &fs
->dblist
);
94 retval
= ext2fs_get_mem(src
->blocksize
, &fs
->mmp_buf
);
97 memcpy(fs
->mmp_buf
, src
->mmp_buf
, src
->blocksize
);
99 if (src
->mmp_fd
>= 0) {
100 fs
->mmp_fd
= dup(src
->mmp_fd
);
101 if (fs
->mmp_fd
< 0) {
102 retval
= EXT2_ET_MMP_OPEN_DIRECT
;
107 int align
= ext2fs_get_dio_alignment(src
->mmp_fd
);
109 retval
= ext2fs_get_memalign(src
->blocksize
, align
,
113 memcpy(fs
->mmp_cmp
, src
->mmp_cmp
, src
->blocksize
);