Get timothy quick tests building cleanly.
[yaffs2.git] / yaffs_endian.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
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.
12  *
13  * Endian processing functions.
14  */
15
16 #include "yaffs_endian.h"
17 #include "yaffs_guts.h"
18
19
20 void yaffs_do_endian_u32(struct yaffs_dev *dev, u32 *val)
21 {
22         if (!dev->swap_endian)
23                 return;
24         *val = swap_u32(*val);
25 }
26
27 void yaffs_do_endian_s32(struct yaffs_dev *dev, s32 *val)
28 {
29         if (!dev->swap_endian)
30                 return;
31         *val = swap_s32(*val);
32 }
33
34 void yaffs_do_endian_oh(struct yaffs_dev *dev, struct yaffs_obj_hdr *oh)
35 {
36         if (!dev->swap_endian)
37                 return;
38         /* Change every field */
39         oh->type = swap_u32(oh->type);
40         oh->parent_obj_id = swap_u32(oh->parent_obj_id);
41
42         oh->yst_mode = swap_u32(oh->yst_mode);
43
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);
49
50         oh->file_size_low = swap_u32(oh->file_size_low);
51
52         oh->equiv_id = swap_u32(oh->equiv_id);
53
54         oh->yst_rdev = swap_u32(oh->yst_rdev);
55
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]);
62
63         oh->inband_shadowed_obj_id = swap_u32(oh->inband_shadowed_obj_id);
64         oh->inband_is_shrink = swap_u32(oh->inband_is_shrink);
65
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);
69
70         oh->is_shrink = swap_u32(oh->is_shrink);
71 }
72
73
74 void yaffs_do_endian_packed_tags2(struct yaffs_dev *dev,
75                                 struct yaffs_packed_tags2_tags_only *ptt)
76 {
77         if (!dev->swap_endian)
78                 return;
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);
83 }
84
85 void yaffs_endian_config(struct yaffs_dev *dev)
86 {
87         u32 x = 1;
88
89         if (dev->tnode_size < 1)
90                 BUG();
91
92         dev->swap_endian = 0;
93
94         if (((char *)&x)[0] == 1) {
95                 /* Little Endian. */
96                 if (dev->param.stored_endian == 2 /* big endian */)
97                         dev->swap_endian = 1;
98         } else  {
99                 /* Big Endian. */
100                 if (dev->param.stored_endian == 1 /* little endian */)
101                         dev->swap_endian = 1;
102         }
103
104         if (dev->swap_endian)
105                 dev->tn_swap_buffer = kmalloc(dev->tnode_size, GFP_NOFS);
106 }