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