blob: 46d60ef435dee277799a0878227904314a53d548 [file] [log] [blame]
Theodore Ts'o50e1e101997-04-26 13:58:21 +00001/*
2 * swapfs.c --- swap ext2 filesystem data structures
Theodore Ts'oefc6f622008-08-27 23:07:54 -04003 *
Theodore Ts'o8132d842002-10-02 22:07:17 -04004 * Copyright (C) 1995, 1996, 2002 Theodore Ts'o.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00005 *
6 * %Begin-Header%
Theodore Ts'o543547a2010-05-17 21:31:56 -04007 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
Theodore Ts'o19c78dc1997-04-29 16:17:09 +00009 * %End-Header%
Theodore Ts'o50e1e101997-04-26 13:58:21 +000010 */
11
12#include <stdio.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000013#if HAVE_UNISTD_H
Theodore Ts'o50e1e101997-04-26 13:58:21 +000014#include <unistd.h>
Theodore Ts'o4cbe8af1997-08-10 23:07:40 +000015#endif
Theodore Ts'o73311962005-01-25 23:42:56 -050016#include <string.h>
Theodore Ts'o50e1e101997-04-26 13:58:21 +000017#include <time.h>
18
Theodore Ts'ob5abe6f1998-01-19 14:47:53 +000019#include "ext2_fs.h"
Theodore Ts'o50e1e101997-04-26 13:58:21 +000020#include "ext2fs.h"
Theodore Ts'o73311962005-01-25 23:42:56 -050021#include <ext2fs/ext2_ext_attr.h>
Theodore Ts'o50e1e101997-04-26 13:58:21 +000022
Theodore Ts'oa5dda052007-08-11 03:11:12 -040023#ifdef WORDS_BIGENDIAN
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000024void ext2fs_swap_super(struct ext2_super_block * sb)
Theodore Ts'o50e1e101997-04-26 13:58:21 +000025{
Theodore Ts'o8132d842002-10-02 22:07:17 -040026 int i;
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000027 sb->s_inodes_count = ext2fs_swab32(sb->s_inodes_count);
28 sb->s_blocks_count = ext2fs_swab32(sb->s_blocks_count);
29 sb->s_r_blocks_count = ext2fs_swab32(sb->s_r_blocks_count);
30 sb->s_free_blocks_count = ext2fs_swab32(sb->s_free_blocks_count);
31 sb->s_free_inodes_count = ext2fs_swab32(sb->s_free_inodes_count);
32 sb->s_first_data_block = ext2fs_swab32(sb->s_first_data_block);
33 sb->s_log_block_size = ext2fs_swab32(sb->s_log_block_size);
JP Abgralle0ed7402014-03-19 19:08:39 -070034 sb->s_log_cluster_size = ext2fs_swab32(sb->s_log_cluster_size);
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000035 sb->s_blocks_per_group = ext2fs_swab32(sb->s_blocks_per_group);
JP Abgralle0ed7402014-03-19 19:08:39 -070036 sb->s_clusters_per_group = ext2fs_swab32(sb->s_clusters_per_group);
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000037 sb->s_inodes_per_group = ext2fs_swab32(sb->s_inodes_per_group);
38 sb->s_mtime = ext2fs_swab32(sb->s_mtime);
39 sb->s_wtime = ext2fs_swab32(sb->s_wtime);
40 sb->s_mnt_count = ext2fs_swab16(sb->s_mnt_count);
41 sb->s_max_mnt_count = ext2fs_swab16(sb->s_max_mnt_count);
42 sb->s_magic = ext2fs_swab16(sb->s_magic);
43 sb->s_state = ext2fs_swab16(sb->s_state);
44 sb->s_errors = ext2fs_swab16(sb->s_errors);
45 sb->s_minor_rev_level = ext2fs_swab16(sb->s_minor_rev_level);
46 sb->s_lastcheck = ext2fs_swab32(sb->s_lastcheck);
47 sb->s_checkinterval = ext2fs_swab32(sb->s_checkinterval);
48 sb->s_creator_os = ext2fs_swab32(sb->s_creator_os);
49 sb->s_rev_level = ext2fs_swab32(sb->s_rev_level);
50 sb->s_def_resuid = ext2fs_swab16(sb->s_def_resuid);
51 sb->s_def_resgid = ext2fs_swab16(sb->s_def_resgid);
52 sb->s_first_ino = ext2fs_swab32(sb->s_first_ino);
53 sb->s_inode_size = ext2fs_swab16(sb->s_inode_size);
54 sb->s_block_group_nr = ext2fs_swab16(sb->s_block_group_nr);
55 sb->s_feature_compat = ext2fs_swab32(sb->s_feature_compat);
56 sb->s_feature_incompat = ext2fs_swab32(sb->s_feature_incompat);
57 sb->s_feature_ro_compat = ext2fs_swab32(sb->s_feature_ro_compat);
58 sb->s_algorithm_usage_bitmap = ext2fs_swab32(sb->s_algorithm_usage_bitmap);
Theodore Ts'o5d28e3b2004-12-22 20:55:48 -050059 sb->s_reserved_gdt_blocks = ext2fs_swab16(sb->s_reserved_gdt_blocks);
Theodore Ts'oe5b38a52001-01-01 16:17:12 +000060 sb->s_journal_inum = ext2fs_swab32(sb->s_journal_inum);
61 sb->s_journal_dev = ext2fs_swab32(sb->s_journal_dev);
62 sb->s_last_orphan = ext2fs_swab32(sb->s_last_orphan);
Theodore Ts'o8061d2c2006-11-11 09:44:47 -050063 sb->s_desc_size = ext2fs_swab16(sb->s_desc_size);
Theodore Ts'o1ba7a2f2004-01-30 01:48:06 -050064 sb->s_default_mount_opts = ext2fs_swab32(sb->s_default_mount_opts);
Theodore Ts'oc046ac72002-10-20 00:38:57 -040065 sb->s_first_meta_bg = ext2fs_swab32(sb->s_first_meta_bg);
Theodore Ts'o1ba7a2f2004-01-30 01:48:06 -050066 sb->s_mkfs_time = ext2fs_swab32(sb->s_mkfs_time);
Theodore Ts'o6b3ce982006-11-11 09:45:22 -050067 sb->s_blocks_count_hi = ext2fs_swab32(sb->s_blocks_count_hi);
68 sb->s_r_blocks_count_hi = ext2fs_swab32(sb->s_r_blocks_count_hi);
69 sb->s_free_blocks_hi = ext2fs_swab32(sb->s_free_blocks_hi);
70 sb->s_min_extra_isize = ext2fs_swab16(sb->s_min_extra_isize);
71 sb->s_want_extra_isize = ext2fs_swab16(sb->s_want_extra_isize);
Theodore Ts'of77704e2006-11-11 22:32:35 -050072 sb->s_flags = ext2fs_swab32(sb->s_flags);
JP Abgralle0ed7402014-03-19 19:08:39 -070073 sb->s_mmp_update_interval = ext2fs_swab16(sb->s_mmp_update_interval);
74 sb->s_mmp_block = ext2fs_swab64(sb->s_mmp_block);
Theodore Ts'ob7c5b402009-03-05 19:40:20 -050075 sb->s_kbytes_written = ext2fs_swab64(sb->s_kbytes_written);
Theodore Ts'of5448c12010-06-24 21:08:37 -040076 sb->s_snapshot_inum = ext2fs_swab32(sb->s_snapshot_inum);
Theodore Ts'occc7cf02010-07-30 18:41:47 -040077 sb->s_snapshot_id = ext2fs_swab32(sb->s_snapshot_id);
Theodore Ts'of5448c12010-06-24 21:08:37 -040078 sb->s_snapshot_r_blocks_count =
79 ext2fs_swab64(sb->s_snapshot_r_blocks_count);
80 sb->s_snapshot_list = ext2fs_swab32(sb->s_snapshot_list);
JP Abgralle0ed7402014-03-19 19:08:39 -070081 sb->s_usr_quota_inum = ext2fs_swab32(sb->s_usr_quota_inum);
82 sb->s_grp_quota_inum = ext2fs_swab32(sb->s_grp_quota_inum);
83 sb->s_overhead_blocks = ext2fs_swab32(sb->s_overhead_blocks);
84 sb->s_checksum = ext2fs_swab32(sb->s_checksum);
Theodore Ts'of5448c12010-06-24 21:08:37 -040085
Theodore Ts'o8132d842002-10-02 22:07:17 -040086 for (i=0; i < 4; i++)
87 sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]);
Eric Sandeen6eb229d2009-11-10 14:45:44 -060088
89 /* if journal backup is for a valid extent-based journal... */
JP Abgralle0ed7402014-03-19 19:08:39 -070090 if (ext2fs_extent_header_verify(sb->s_jnl_blocks,
91 sizeof(sb->s_jnl_blocks)) == 0) {
92 /* ... swap only the journal i_size and i_size_high,
93 * and the extent data is not swapped on read */
94 i = 15;
95 } else {
96 /* direct/indirect journal: swap it all */
97 i = 0;
Eric Sandeen6eb229d2009-11-10 14:45:44 -060098 }
JP Abgralle0ed7402014-03-19 19:08:39 -070099 for (; i < 17; i++)
Theodore Ts'o1ba7a2f2004-01-30 01:48:06 -0500100 sb->s_jnl_blocks[i] = ext2fs_swab32(sb->s_jnl_blocks[i]);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000101}
102
JP Abgralle0ed7402014-03-19 19:08:39 -0700103void ext2fs_swap_group_desc2(ext2_filsys fs, struct ext2_group_desc *gdp)
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000104{
JP Abgralle0ed7402014-03-19 19:08:39 -0700105 struct ext4_group_desc *gdp4 = (struct ext4_group_desc *)gdp;
106
107 /* Do the 32-bit parts first */
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000108 gdp->bg_block_bitmap = ext2fs_swab32(gdp->bg_block_bitmap);
109 gdp->bg_inode_bitmap = ext2fs_swab32(gdp->bg_inode_bitmap);
110 gdp->bg_inode_table = ext2fs_swab32(gdp->bg_inode_table);
111 gdp->bg_free_blocks_count = ext2fs_swab16(gdp->bg_free_blocks_count);
112 gdp->bg_free_inodes_count = ext2fs_swab16(gdp->bg_free_inodes_count);
113 gdp->bg_used_dirs_count = ext2fs_swab16(gdp->bg_used_dirs_count);
Theodore Ts'of5fa2002006-05-08 20:17:26 -0400114 gdp->bg_flags = ext2fs_swab16(gdp->bg_flags);
JP Abgralle0ed7402014-03-19 19:08:39 -0700115 gdp->bg_exclude_bitmap_lo = ext2fs_swab32(gdp->bg_exclude_bitmap_lo);
116 gdp->bg_block_bitmap_csum_lo =
117 ext2fs_swab16(gdp->bg_block_bitmap_csum_lo);
118 gdp->bg_inode_bitmap_csum_lo =
119 ext2fs_swab16(gdp->bg_inode_bitmap_csum_lo);
Theodore Ts'o8815fb82006-11-11 09:41:52 -0500120 gdp->bg_itable_unused = ext2fs_swab16(gdp->bg_itable_unused);
121 gdp->bg_checksum = ext2fs_swab16(gdp->bg_checksum);
JP Abgralle0ed7402014-03-19 19:08:39 -0700122 /* If we're 32-bit, we're done */
123 if (fs == NULL || EXT2_DESC_SIZE(fs->super) < EXT2_MIN_DESC_SIZE_64BIT)
124 return;
125
126 /* Swap the 64-bit parts */
127 gdp4->bg_block_bitmap_hi = ext2fs_swab32(gdp4->bg_block_bitmap_hi);
128 gdp4->bg_inode_bitmap_hi = ext2fs_swab32(gdp4->bg_inode_bitmap_hi);
129 gdp4->bg_inode_table_hi = ext2fs_swab32(gdp4->bg_inode_table_hi);
130 gdp4->bg_free_blocks_count_hi =
131 ext2fs_swab16(gdp4->bg_free_blocks_count_hi);
132 gdp4->bg_free_inodes_count_hi =
133 ext2fs_swab16(gdp4->bg_free_inodes_count_hi);
134 gdp4->bg_used_dirs_count_hi =
135 ext2fs_swab16(gdp4->bg_used_dirs_count_hi);
136 gdp4->bg_itable_unused_hi = ext2fs_swab16(gdp4->bg_itable_unused_hi);
137 gdp4->bg_exclude_bitmap_hi = ext2fs_swab16(gdp4->bg_exclude_bitmap_hi);
138 gdp4->bg_block_bitmap_csum_hi =
139 ext2fs_swab16(gdp4->bg_block_bitmap_csum_hi);
140 gdp4->bg_inode_bitmap_csum_hi =
141 ext2fs_swab16(gdp4->bg_inode_bitmap_csum_hi);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000142}
143
JP Abgralle0ed7402014-03-19 19:08:39 -0700144void ext2fs_swap_group_desc(struct ext2_group_desc *gdp)
145{
146 ext2fs_swap_group_desc2(0, gdp);
147}
148
149
Andreas Dilgerfefaef32008-02-02 01:16:32 -0700150void ext2fs_swap_ext_attr_header(struct ext2_ext_attr_header *to_header,
151 struct ext2_ext_attr_header *from_header)
152{
153 int n;
154
155 to_header->h_magic = ext2fs_swab32(from_header->h_magic);
156 to_header->h_blocks = ext2fs_swab32(from_header->h_blocks);
157 to_header->h_refcount = ext2fs_swab32(from_header->h_refcount);
158 to_header->h_hash = ext2fs_swab32(from_header->h_hash);
159 for (n = 0; n < 4; n++)
160 to_header->h_reserved[n] =
161 ext2fs_swab32(from_header->h_reserved[n]);
162}
163
164void ext2fs_swap_ext_attr_entry(struct ext2_ext_attr_entry *to_entry,
165 struct ext2_ext_attr_entry *from_entry)
166{
167 to_entry->e_value_offs = ext2fs_swab16(from_entry->e_value_offs);
168 to_entry->e_value_block = ext2fs_swab32(from_entry->e_value_block);
169 to_entry->e_value_size = ext2fs_swab32(from_entry->e_value_size);
170 to_entry->e_hash = ext2fs_swab32(from_entry->e_hash);
171}
172
Theodore Ts'o73311962005-01-25 23:42:56 -0500173void ext2fs_swap_ext_attr(char *to, char *from, int bufsize, int has_header)
174{
175 struct ext2_ext_attr_header *from_header =
176 (struct ext2_ext_attr_header *)from;
177 struct ext2_ext_attr_header *to_header =
178 (struct ext2_ext_attr_header *)to;
179 struct ext2_ext_attr_entry *from_entry, *to_entry;
180 char *from_end = (char *)from_header + bufsize;
Theodore Ts'o73311962005-01-25 23:42:56 -0500181
182 if (to_header != from_header)
183 memcpy(to_header, from_header, bufsize);
184
Theodore Ts'o73311962005-01-25 23:42:56 -0500185 if (has_header) {
Andreas Dilgerfefaef32008-02-02 01:16:32 -0700186 ext2fs_swap_ext_attr_header(to_header, from_header);
187
Theodore Ts'o73311962005-01-25 23:42:56 -0500188 from_entry = (struct ext2_ext_attr_entry *)(from_header+1);
189 to_entry = (struct ext2_ext_attr_entry *)(to_header+1);
Andreas Dilgerfefaef32008-02-02 01:16:32 -0700190 } else {
191 from_entry = (struct ext2_ext_attr_entry *)from_header;
192 to_entry = (struct ext2_ext_attr_entry *)to_header;
Theodore Ts'o73311962005-01-25 23:42:56 -0500193 }
194
195 while ((char *)from_entry < from_end && *(__u32 *)from_entry) {
Andreas Dilgerfefaef32008-02-02 01:16:32 -0700196 ext2fs_swap_ext_attr_entry(to_entry, from_entry);
Theodore Ts'o73311962005-01-25 23:42:56 -0500197 from_entry = EXT2_EXT_ATTR_NEXT(from_entry);
198 to_entry = EXT2_EXT_ATTR_NEXT(to_entry);
199 }
200}
201
202void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
203 struct ext2_inode_large *f, int hostorder,
204 int bufsize)
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000205{
Eric Sandeen82e54182008-02-29 16:10:21 -0600206 unsigned i, has_data_blocks, extra_isize, attr_magic;
Eric Sandeenfb6627a2008-03-24 08:25:40 -0400207 int has_extents = 0;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000208 int islnk = 0;
Theodore Ts'o73311962005-01-25 23:42:56 -0500209 __u32 *eaf, *eat;
210
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000211 if (hostorder && LINUX_S_ISLNK(f->i_mode))
212 islnk = 1;
213 t->i_mode = ext2fs_swab16(f->i_mode);
214 if (!hostorder && LINUX_S_ISLNK(t->i_mode))
215 islnk = 1;
216 t->i_uid = ext2fs_swab16(f->i_uid);
217 t->i_size = ext2fs_swab32(f->i_size);
218 t->i_atime = ext2fs_swab32(f->i_atime);
219 t->i_ctime = ext2fs_swab32(f->i_ctime);
220 t->i_mtime = ext2fs_swab32(f->i_mtime);
221 t->i_dtime = ext2fs_swab32(f->i_dtime);
222 t->i_gid = ext2fs_swab16(f->i_gid);
223 t->i_links_count = ext2fs_swab16(f->i_links_count);
Eric Sandeendb9097c2007-07-17 20:40:25 -0500224 t->i_file_acl = ext2fs_swab32(f->i_file_acl);
Bryn M. Reeves3f4c46e2007-04-14 14:00:31 -0400225 if (hostorder)
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400226 has_data_blocks = ext2fs_inode_data_blocks(fs,
Bryn M. Reeves3f4c46e2007-04-14 14:00:31 -0400227 (struct ext2_inode *) f);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000228 t->i_blocks = ext2fs_swab32(f->i_blocks);
Bryn M. Reeves3f4c46e2007-04-14 14:00:31 -0400229 if (!hostorder)
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400230 has_data_blocks = ext2fs_inode_data_blocks(fs,
Bryn M. Reeves3f4c46e2007-04-14 14:00:31 -0400231 (struct ext2_inode *) t);
Theodore Ts'o4ce3b772007-09-01 09:10:43 -0400232 if (hostorder && (f->i_flags & EXT4_EXTENTS_FL))
Eric Sandeenfb6627a2008-03-24 08:25:40 -0400233 has_extents = 1;
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000234 t->i_flags = ext2fs_swab32(f->i_flags);
Eric Sandeenfb6627a2008-03-24 08:25:40 -0400235 if (!hostorder && (t->i_flags & EXT4_EXTENTS_FL))
236 has_extents = 1;
Theodore Ts'o1ba7a2f2004-01-30 01:48:06 -0500237 t->i_dir_acl = ext2fs_swab32(f->i_dir_acl);
Eric Sandeenfb6627a2008-03-24 08:25:40 -0400238 /* extent data are swapped on access, not here */
239 if (!has_extents && (!islnk || has_data_blocks)) {
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000240 for (i = 0; i < EXT2_N_BLOCKS; i++)
241 t->i_block[i] = ext2fs_swab32(f->i_block[i]);
242 } else if (t != f) {
243 for (i = 0; i < EXT2_N_BLOCKS; i++)
244 t->i_block[i] = f->i_block[i];
245 }
Theodore Ts'oe72a9ba1999-06-25 15:40:18 +0000246 t->i_generation = ext2fs_swab32(f->i_generation);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000247 t->i_faddr = ext2fs_swab32(f->i_faddr);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000248
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000249 switch (fs->super->s_creator_os) {
250 case EXT2_OS_LINUX:
Theodore Ts'od362a3f2007-04-19 01:53:53 -0400251 t->osd1.linux1.l_i_version =
252 ext2fs_swab32(f->osd1.linux1.l_i_version);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400253 t->osd2.linux2.l_i_blocks_hi =
Theodore Ts'o5d171192006-11-11 06:32:03 -0500254 ext2fs_swab16(f->osd2.linux2.l_i_blocks_hi);
Aneesh Kumar K.V2ea504b2008-06-04 14:31:23 +0530255 t->osd2.linux2.l_i_file_acl_high =
256 ext2fs_swab16(f->osd2.linux2.l_i_file_acl_high);
Theodore Ts'o80e808f2000-02-02 16:19:59 +0000257 t->osd2.linux2.l_i_uid_high =
258 ext2fs_swab16 (f->osd2.linux2.l_i_uid_high);
259 t->osd2.linux2.l_i_gid_high =
260 ext2fs_swab16 (f->osd2.linux2.l_i_gid_high);
JP Abgralle0ed7402014-03-19 19:08:39 -0700261 t->osd2.linux2.l_i_checksum_lo =
262 ext2fs_swab16(f->osd2.linux2.l_i_checksum_lo);
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000263 break;
264 case EXT2_OS_HURD:
265 t->osd1.hurd1.h_i_translator =
266 ext2fs_swab32 (f->osd1.hurd1.h_i_translator);
267 t->osd2.hurd2.h_i_frag = f->osd2.hurd2.h_i_frag;
268 t->osd2.hurd2.h_i_fsize = f->osd2.hurd2.h_i_fsize;
269 t->osd2.hurd2.h_i_mode_high =
270 ext2fs_swab16 (f->osd2.hurd2.h_i_mode_high);
271 t->osd2.hurd2.h_i_uid_high =
272 ext2fs_swab16 (f->osd2.hurd2.h_i_uid_high);
273 t->osd2.hurd2.h_i_gid_high =
274 ext2fs_swab16 (f->osd2.hurd2.h_i_gid_high);
275 t->osd2.hurd2.h_i_author =
276 ext2fs_swab32 (f->osd2.hurd2.h_i_author);
277 break;
Coly Lic9548bc2007-08-23 15:08:30 +0800278 default:
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000279 break;
280 }
Theodore Ts'o73311962005-01-25 23:42:56 -0500281
282 if (bufsize < (int) (sizeof(struct ext2_inode) + sizeof(__u16)))
283 return; /* no i_extra_isize field */
284
Theodore Ts'oc8440102007-06-22 19:53:21 -0400285 if (hostorder)
286 extra_isize = f->i_extra_isize;
Theodore Ts'o73311962005-01-25 23:42:56 -0500287 t->i_extra_isize = ext2fs_swab16(f->i_extra_isize);
Theodore Ts'oc8440102007-06-22 19:53:21 -0400288 if (!hostorder)
289 extra_isize = t->i_extra_isize;
290 if (extra_isize > EXT2_INODE_SIZE(fs->super) -
Theodore Ts'o73311962005-01-25 23:42:56 -0500291 sizeof(struct ext2_inode)) {
292 /* this is error case: i_extra_size is too large */
293 return;
294 }
295
JP Abgralle0ed7402014-03-19 19:08:39 -0700296 if (extra_isize >= 4)
297 t->i_checksum_hi = ext2fs_swab16(f->i_checksum_hi);
298 if (extra_isize >= 8)
299 t->i_ctime_extra = ext2fs_swab32(f->i_ctime_extra);
300 if (extra_isize >= 12)
301 t->i_mtime_extra = ext2fs_swab32(f->i_mtime_extra);
302 if (extra_isize >= 16)
303 t->i_atime_extra = ext2fs_swab32(f->i_atime_extra);
304 if (extra_isize >= 20)
305 t->i_crtime = ext2fs_swab32(f->i_crtime);
306 if (extra_isize >= 24)
307 t->i_crtime_extra = ext2fs_swab32(f->i_crtime_extra);
308 if (extra_isize >= 28)
309 t->i_version_hi = ext2fs_swab32(f->i_version_hi);
310
Theodore Ts'oc8440102007-06-22 19:53:21 -0400311 i = sizeof(struct ext2_inode) + extra_isize + sizeof(__u32);
Theodore Ts'o73311962005-01-25 23:42:56 -0500312 if (bufsize < (int) i)
313 return; /* no space for EA magic */
314
315 eaf = (__u32 *) (((char *) f) + sizeof(struct ext2_inode) +
Theodore Ts'oc8440102007-06-22 19:53:21 -0400316 extra_isize);
Theodore Ts'o73311962005-01-25 23:42:56 -0500317
Eric Sandeen82e54182008-02-29 16:10:21 -0600318 attr_magic = *eaf;
319 if (!hostorder)
320 attr_magic = ext2fs_swab32(attr_magic);
321
322 if (attr_magic != EXT2_EXT_ATTR_MAGIC)
Theodore Ts'o73311962005-01-25 23:42:56 -0500323 return; /* it seems no magic here */
324
325 eat = (__u32 *) (((char *) t) + sizeof(struct ext2_inode) +
Theodore Ts'oc8440102007-06-22 19:53:21 -0400326 extra_isize);
Theodore Ts'o73311962005-01-25 23:42:56 -0500327 *eat = ext2fs_swab32(*eaf);
328
329 /* convert EA(s) */
330 ext2fs_swap_ext_attr((char *) (eat + 1), (char *) (eaf + 1),
331 bufsize - sizeof(struct ext2_inode) -
Theodore Ts'oc8440102007-06-22 19:53:21 -0400332 extra_isize - sizeof(__u32), 0);
Theodore Ts'o73311962005-01-25 23:42:56 -0500333
Theodore Ts'o1e3472c1997-04-29 14:53:37 +0000334}
Theodore Ts'o73311962005-01-25 23:42:56 -0500335
336void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t,
337 struct ext2_inode *f, int hostorder)
338{
339 ext2fs_swap_inode_full(fs, (struct ext2_inode_large *) t,
340 (struct ext2_inode_large *) f, hostorder,
341 sizeof(struct ext2_inode));
342}
343
JP Abgralle0ed7402014-03-19 19:08:39 -0700344void ext2fs_swap_mmp(struct mmp_struct *mmp)
345{
346 mmp->mmp_magic = ext2fs_swab32(mmp->mmp_magic);
347 mmp->mmp_seq = ext2fs_swab32(mmp->mmp_seq);
348 mmp->mmp_time = ext2fs_swab64(mmp->mmp_time);
349 mmp->mmp_check_interval = ext2fs_swab16(mmp->mmp_check_interval);
350}
351
Theodore Ts'o5df55d72001-06-11 07:00:04 +0000352#endif