blob: 8c271891a0197cb2d8e1d039c289e27208cd09b8 [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 Lesser General Public License version 2.1 as
10 * published by the Free Software Foundation.
11 *
12 * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
13 */
14
15#ifndef __YAFFS_ENDIAN_H__
16#define __YAFFS_ENDIAN_H__
17#include "yaffs_guts.h"
18#include "yaffs_packedtags2.h"
19
20static inline u32 swap_u32(u32 val)
21{
22 return ((val >>24) & 0x000000ff) |
23 ((val >> 8) & 0x0000ff00) |
24 ((val << 8) & 0x00ff0000) |
25 ((val <<24) & 0xff000000);
26}
27
28#define swap_s32(val) \
29 (s32)(swap_u32((u32)(val)))
30
31static inline loff_t swap_loff_t(loff_t lval)
32{
33 u32 vall = swap_u32(FSIZE_LOW(lval));
34 u32 valh;
35
36 if (sizeof(loff_t) == sizeof(u32))
37 return (loff_t) vall;
38
39 valh = swap_u32(FSIZE_HIGH(lval));
40
41 return FSIZE_COMBINE(vall, valh); /*NB: h and l are swapped. */
42}
43
44
45
46struct yaffs_dev;
47void yaffs_do_endian_s32(struct yaffs_dev *dev, s32 *val);
48void yaffs_do_endian_u32(struct yaffs_dev *dev, u32 *val);
49void yaffs_do_endian_oh(struct yaffs_dev *dev, struct yaffs_obj_hdr *oh);
50void yaffs_do_endian_packed_tags2(struct yaffs_dev *dev,
51 struct yaffs_packed_tags2_tags_only *ptt);
52void yaffs_endian_config(struct yaffs_dev *dev);
53
54#endif