Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1/*
  2 * linux/fs/befs/endian.h
  3 *
  4 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
  5 *
  6 * Partially based on similar funtions in the sysv driver.
  7 */
  8
  9#ifndef LINUX_BEFS_ENDIAN
 10#define LINUX_BEFS_ENDIAN
 11
 12#include <asm/byteorder.h>
 13
 14static inline u64
 15fs64_to_cpu(const struct super_block *sb, fs64 n)
 16{
 17	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 18		return le64_to_cpu((__force __le64)n);
 19	else
 20		return be64_to_cpu((__force __be64)n);
 21}
 22
 23static inline fs64
 24cpu_to_fs64(const struct super_block *sb, u64 n)
 25{
 26	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 27		return (__force fs64)cpu_to_le64(n);
 28	else
 29		return (__force fs64)cpu_to_be64(n);
 30}
 31
 32static inline u32
 33fs32_to_cpu(const struct super_block *sb, fs32 n)
 34{
 35	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 36		return le32_to_cpu((__force __le32)n);
 37	else
 38		return be32_to_cpu((__force __be32)n);
 39}
 40
 41static inline fs32
 42cpu_to_fs32(const struct super_block *sb, u32 n)
 43{
 44	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 45		return (__force fs32)cpu_to_le32(n);
 46	else
 47		return (__force fs32)cpu_to_be32(n);
 48}
 49
 50static inline u16
 51fs16_to_cpu(const struct super_block *sb, fs16 n)
 52{
 53	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 54		return le16_to_cpu((__force __le16)n);
 55	else
 56		return be16_to_cpu((__force __be16)n);
 57}
 58
 59static inline fs16
 60cpu_to_fs16(const struct super_block *sb, u16 n)
 61{
 62	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 63		return (__force fs16)cpu_to_le16(n);
 64	else
 65		return (__force fs16)cpu_to_be16(n);
 66}
 67
 68/* Composite types below here */
 69
 70static inline befs_block_run
 71fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
 72{
 73	befs_block_run run;
 74
 75	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
 76		run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group);
 77		run.start = le16_to_cpu((__force __le16)n.start);
 78		run.len = le16_to_cpu((__force __le16)n.len);
 79	} else {
 80		run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group);
 81		run.start = be16_to_cpu((__force __be16)n.start);
 82		run.len = be16_to_cpu((__force __be16)n.len);
 83	}
 84	return run;
 85}
 86
 87static inline befs_disk_block_run
 88cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
 89{
 90	befs_disk_block_run run;
 91
 92	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
 93		run.allocation_group = cpu_to_le32(n.allocation_group);
 94		run.start = cpu_to_le16(n.start);
 95		run.len = cpu_to_le16(n.len);
 96	} else {
 97		run.allocation_group = cpu_to_be32(n.allocation_group);
 98		run.start = cpu_to_be16(n.start);
 99		run.len = cpu_to_be16(n.len);
100	}
101	return run;
102}
103
104static inline befs_data_stream
105fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
106{
107	befs_data_stream data;
108	int i;
109
110	for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
111		data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);
112
113	data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
114	data.indirect = fsrun_to_cpu(sb, n->indirect);
115	data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
116	data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
117	data.max_double_indirect_range = fs64_to_cpu(sb,
118						     n->
119						     max_double_indirect_range);
120	data.size = fs64_to_cpu(sb, n->size);
121
122	return data;
123}
124
125#endif				//LINUX_BEFS_ENDIAN
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * linux/fs/befs/endian.h
  4 *
  5 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
  6 *
  7 * Partially based on similar funtions in the sysv driver.
  8 */
  9
 10#ifndef LINUX_BEFS_ENDIAN
 11#define LINUX_BEFS_ENDIAN
 12
 13#include <asm/byteorder.h>
 14
 15static inline u64
 16fs64_to_cpu(const struct super_block *sb, fs64 n)
 17{
 18	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 19		return le64_to_cpu((__force __le64)n);
 20	else
 21		return be64_to_cpu((__force __be64)n);
 22}
 23
 24static inline fs64
 25cpu_to_fs64(const struct super_block *sb, u64 n)
 26{
 27	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 28		return (__force fs64)cpu_to_le64(n);
 29	else
 30		return (__force fs64)cpu_to_be64(n);
 31}
 32
 33static inline u32
 34fs32_to_cpu(const struct super_block *sb, fs32 n)
 35{
 36	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 37		return le32_to_cpu((__force __le32)n);
 38	else
 39		return be32_to_cpu((__force __be32)n);
 40}
 41
 42static inline fs32
 43cpu_to_fs32(const struct super_block *sb, u32 n)
 44{
 45	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 46		return (__force fs32)cpu_to_le32(n);
 47	else
 48		return (__force fs32)cpu_to_be32(n);
 49}
 50
 51static inline u16
 52fs16_to_cpu(const struct super_block *sb, fs16 n)
 53{
 54	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 55		return le16_to_cpu((__force __le16)n);
 56	else
 57		return be16_to_cpu((__force __be16)n);
 58}
 59
 60static inline fs16
 61cpu_to_fs16(const struct super_block *sb, u16 n)
 62{
 63	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
 64		return (__force fs16)cpu_to_le16(n);
 65	else
 66		return (__force fs16)cpu_to_be16(n);
 67}
 68
 69/* Composite types below here */
 70
 71static inline befs_block_run
 72fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
 73{
 74	befs_block_run run;
 75
 76	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
 77		run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group);
 78		run.start = le16_to_cpu((__force __le16)n.start);
 79		run.len = le16_to_cpu((__force __le16)n.len);
 80	} else {
 81		run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group);
 82		run.start = be16_to_cpu((__force __be16)n.start);
 83		run.len = be16_to_cpu((__force __be16)n.len);
 84	}
 85	return run;
 86}
 87
 88static inline befs_disk_block_run
 89cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
 90{
 91	befs_disk_block_run run;
 92
 93	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
 94		run.allocation_group = cpu_to_le32(n.allocation_group);
 95		run.start = cpu_to_le16(n.start);
 96		run.len = cpu_to_le16(n.len);
 97	} else {
 98		run.allocation_group = cpu_to_be32(n.allocation_group);
 99		run.start = cpu_to_be16(n.start);
100		run.len = cpu_to_be16(n.len);
101	}
102	return run;
103}
104
105static inline befs_data_stream
106fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
107{
108	befs_data_stream data;
109	int i;
110
111	for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
112		data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);
113
114	data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
115	data.indirect = fsrun_to_cpu(sb, n->indirect);
116	data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
117	data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
118	data.max_double_indirect_range = fs64_to_cpu(sb,
119						     n->
120						     max_double_indirect_range);
121	data.size = fs64_to_cpu(sb, n->size);
122
123	return data;
124}
125
126#endif				//LINUX_BEFS_ENDIAN