2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * Endian processing functions.
16 #include "yaffs_endian.h"
17 #include "yaffs_guts.h"
20 void yaffs_do_endian_u32(struct yaffs_dev *dev, u32 *val)
22 if (!dev->swap_endian)
24 *val = swap_u32(*val);
27 void yaffs_do_endian_s32(struct yaffs_dev *dev, s32 *val)
29 if (!dev->swap_endian)
31 *val = swap_s32(*val);
34 void yaffs_do_endian_oh(struct yaffs_dev *dev, struct yaffs_obj_hdr *oh)
36 if (!dev->swap_endian)
38 /* Change every field */
39 oh->type = swap_u32(oh->type);
40 oh->parent_obj_id = swap_u32(oh->parent_obj_id);
42 oh->yst_mode = swap_u32(oh->yst_mode);
44 oh->yst_uid = swap_u32(oh->yst_uid);
45 oh->yst_gid = swap_u32(oh->yst_gid);
46 oh->yst_atime = swap_u32(oh->yst_atime);
47 oh->yst_mtime = swap_u32(oh->yst_mtime);
48 oh->yst_ctime = swap_u32(oh->yst_ctime);
50 oh->file_size_low = swap_u32(oh->file_size_low);
52 oh->equiv_id = swap_u32(oh->equiv_id);
54 oh->yst_rdev = swap_u32(oh->yst_rdev);
56 oh->win_ctime[0] = swap_u32(oh->win_ctime[0]);
57 oh->win_ctime[1] = swap_u32(oh->win_ctime[1]);
58 oh->win_atime[0] = swap_u32(oh->win_atime[0]);
59 oh->win_atime[1] = swap_u32(oh->win_atime[1]);
60 oh->win_mtime[0] = swap_u32(oh->win_mtime[0]);
61 oh->win_mtime[1] = swap_u32(oh->win_mtime[1]);
63 oh->inband_shadowed_obj_id = swap_u32(oh->inband_shadowed_obj_id);
64 oh->inband_is_shrink = swap_u32(oh->inband_is_shrink);
66 oh->file_size_high = swap_u32(oh->file_size_high);
67 oh->reserved[0] = swap_u32(oh->reserved[0]);
68 oh->shadows_obj = swap_s32(oh->shadows_obj);
70 oh->is_shrink = swap_u32(oh->is_shrink);
74 void yaffs_do_endian_packed_tags2(struct yaffs_dev *dev,
75 struct yaffs_packed_tags2_tags_only *ptt)
77 if (!dev->swap_endian)
79 ptt->seq_number = swap_u32(ptt->seq_number);
80 ptt->obj_id = swap_u32(ptt->obj_id);
81 ptt->chunk_id = swap_u32(ptt->chunk_id);
82 ptt->n_bytes = swap_u32(ptt->n_bytes);
85 void yaffs_endian_config(struct yaffs_dev *dev)
89 if (dev->tnode_size < 1)
94 if (((char *)&x)[0] == 1) {
96 if (dev->param.stored_endian == 2 /* big endian */)
100 if (dev->param.stored_endian == 1 /* little endian */)
101 dev->swap_endian = 1;
104 if (dev->swap_endian)
105 dev->tn_swap_buffer = kmalloc(dev->tnode_size, GFP_NOFS);