2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2018 Aleph One Ltd.
6 * Created by Charles Manning <charles@aleph1.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * Endian processing functions.
15 #include "yaffs_endian.h"
16 #include "yaffs_guts.h"
19 void yaffs_do_endian_u32(struct yaffs_dev *dev, u32 *val)
21 if (!dev->swap_endian)
23 *val = swap_u32(*val);
26 void yaffs_do_endian_s32(struct yaffs_dev *dev, s32 *val)
28 if (!dev->swap_endian)
30 *val = swap_s32(*val);
33 void yaffs_do_endian_oh(struct yaffs_dev *dev, struct yaffs_obj_hdr *oh)
35 if (!dev->swap_endian)
37 /* Change every field */
38 oh->type = swap_u32(oh->type);
39 oh->parent_obj_id = swap_u32(oh->parent_obj_id);
41 oh->yst_mode = swap_u32(oh->yst_mode);
43 oh->yst_uid = swap_u32(oh->yst_uid);
44 oh->yst_gid = swap_u32(oh->yst_gid);
45 oh->yst_atime = swap_u32(oh->yst_atime);
46 oh->yst_mtime = swap_u32(oh->yst_mtime);
47 oh->yst_ctime = swap_u32(oh->yst_ctime);
49 oh->file_size_low = swap_u32(oh->file_size_low);
51 oh->equiv_id = swap_u32(oh->equiv_id);
53 oh->yst_rdev = swap_u32(oh->yst_rdev);
55 oh->win_ctime[0] = swap_u32(oh->win_ctime[0]);
56 oh->win_ctime[1] = swap_u32(oh->win_ctime[1]);
57 oh->win_atime[0] = swap_u32(oh->win_atime[0]);
58 oh->win_atime[1] = swap_u32(oh->win_atime[1]);
59 oh->win_mtime[0] = swap_u32(oh->win_mtime[0]);
60 oh->win_mtime[1] = swap_u32(oh->win_mtime[1]);
62 oh->inband_shadowed_obj_id = swap_u32(oh->inband_shadowed_obj_id);
63 oh->inband_is_shrink = swap_u32(oh->inband_is_shrink);
65 oh->file_size_high = swap_u32(oh->file_size_high);
66 oh->reserved[0] = swap_u32(oh->reserved[0]);
67 oh->shadows_obj = swap_s32(oh->shadows_obj);
69 oh->is_shrink = swap_u32(oh->is_shrink);
73 void yaffs_do_endian_packed_tags2(struct yaffs_dev *dev,
74 struct yaffs_packed_tags2_tags_only *ptt)
76 if (!dev->swap_endian)
78 ptt->seq_number = swap_u32(ptt->seq_number);
79 ptt->obj_id = swap_u32(ptt->obj_id);
80 ptt->chunk_id = swap_u32(ptt->chunk_id);
81 ptt->n_bytes = swap_u32(ptt->n_bytes);
84 void yaffs_endian_config(struct yaffs_dev *dev)
88 if (dev->tnode_size < 1)
93 if (((char *)&x)[0] == 1) {
95 if (dev->param.stored_endian == 2 /* big endian */)
99 if (dev->param.stored_endian == 1 /* little endian */)
100 dev->swap_endian = 1;
103 if (dev->swap_endian)
104 dev->tn_swap_buffer = kmalloc(dev->tnode_size, GFP_NOFS);