-
Notifications
You must be signed in to change notification settings - Fork 1
/
yaffs_endian.c
105 lines (84 loc) · 2.61 KB
/
yaffs_endian.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
*
* Copyright (C) 2002-2018 Aleph One Ltd.
*
* Created by Charles Manning <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Endian processing functions.
*/
#include "yaffs_endian.h"
#include "yaffs_guts.h"
void yaffs_do_endian_u32(struct yaffs_dev *dev, u32 *val)
{
if (!dev->swap_endian)
return;
*val = swap_u32(*val);
}
void yaffs_do_endian_s32(struct yaffs_dev *dev, s32 *val)
{
if (!dev->swap_endian)
return;
*val = swap_s32(*val);
}
void yaffs_do_endian_oh(struct yaffs_dev *dev, struct yaffs_obj_hdr *oh)
{
if (!dev->swap_endian)
return;
/* Change every field */
oh->type = swap_u32(oh->type);
oh->parent_obj_id = swap_u32(oh->parent_obj_id);
oh->yst_mode = swap_u32(oh->yst_mode);
oh->yst_uid = swap_u32(oh->yst_uid);
oh->yst_gid = swap_u32(oh->yst_gid);
oh->yst_atime = swap_u32(oh->yst_atime);
oh->yst_mtime = swap_u32(oh->yst_mtime);
oh->yst_ctime = swap_u32(oh->yst_ctime);
oh->file_size_low = swap_u32(oh->file_size_low);
oh->equiv_id = swap_u32(oh->equiv_id);
oh->yst_rdev = swap_u32(oh->yst_rdev);
oh->win_ctime[0] = swap_u32(oh->win_ctime[0]);
oh->win_ctime[1] = swap_u32(oh->win_ctime[1]);
oh->win_atime[0] = swap_u32(oh->win_atime[0]);
oh->win_atime[1] = swap_u32(oh->win_atime[1]);
oh->win_mtime[0] = swap_u32(oh->win_mtime[0]);
oh->win_mtime[1] = swap_u32(oh->win_mtime[1]);
oh->inband_shadowed_obj_id = swap_u32(oh->inband_shadowed_obj_id);
oh->inband_is_shrink = swap_u32(oh->inband_is_shrink);
oh->file_size_high = swap_u32(oh->file_size_high);
oh->reserved[0] = swap_u32(oh->reserved[0]);
oh->shadows_obj = swap_s32(oh->shadows_obj);
oh->is_shrink = swap_u32(oh->is_shrink);
}
void yaffs_do_endian_packed_tags2(struct yaffs_dev *dev,
struct yaffs_packed_tags2_tags_only *ptt)
{
if (!dev->swap_endian)
return;
ptt->seq_number = swap_u32(ptt->seq_number);
ptt->obj_id = swap_u32(ptt->obj_id);
ptt->chunk_id = swap_u32(ptt->chunk_id);
ptt->n_bytes = swap_u32(ptt->n_bytes);
}
void yaffs_endian_config(struct yaffs_dev *dev)
{
u32 x = 1;
if (dev->tnode_size < 1)
BUG();
dev->swap_endian = 0;
if (((char *)&x)[0] == 1) {
/* Little Endian. */
if (dev->param.stored_endian == 2 /* big endian */)
dev->swap_endian = 1;
} else {
/* Big Endian. */
if (dev->param.stored_endian == 1 /* little endian */)
dev->swap_endian = 1;
}
if (dev->swap_endian)
dev->tn_swap_buffer = kmalloc(dev->tnode_size, GFP_NOFS);
}