blob: a4363ac2cfeb89ee118f3425bd27501919f5434c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __UDF_ENDIAN_H
3#define __UDF_ENDIAN_H
4
5#include <asm/byteorder.h>
6#include <linux/string.h>
7
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +02008static inline struct kernel_lb_addr lelb_to_cpu(struct lb_addr in)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020010 struct kernel_lb_addr out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 out.logicalBlockNum = le32_to_cpu(in.logicalBlockNum);
13 out.partitionReferenceNum = le16_to_cpu(in.partitionReferenceNum);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 return out;
16}
17
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020018static inline struct lb_addr cpu_to_lelb(struct kernel_lb_addr in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020020 struct lb_addr out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 out.logicalBlockNum = cpu_to_le32(in.logicalBlockNum);
23 out.partitionReferenceNum = cpu_to_le16(in.partitionReferenceNum);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 return out;
26}
27
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020028static inline struct short_ad lesa_to_cpu(struct short_ad in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020030 struct short_ad out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 out.extLength = le32_to_cpu(in.extLength);
33 out.extPosition = le32_to_cpu(in.extPosition);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 return out;
36}
37
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020038static inline struct short_ad cpu_to_lesa(struct short_ad in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020040 struct short_ad out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 out.extLength = cpu_to_le32(in.extLength);
43 out.extPosition = cpu_to_le32(in.extPosition);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 return out;
46}
47
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020048static inline struct kernel_long_ad lela_to_cpu(struct long_ad in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020050 struct kernel_long_ad out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070051
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 out.extLength = le32_to_cpu(in.extLength);
53 out.extLocation = lelb_to_cpu(in.extLocation);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 return out;
56}
57
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020058static inline struct long_ad cpu_to_lela(struct kernel_long_ad in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020060 struct long_ad out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 out.extLength = cpu_to_le32(in.extLength);
63 out.extLocation = cpu_to_lelb(in.extLocation);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070064
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 return out;
66}
67
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020068static inline struct kernel_extent_ad leea_to_cpu(struct extent_ad in)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Pekka Enberg5ca4e4b2008-10-15 12:28:03 +020070 struct kernel_extent_ad out;
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 out.extLength = le32_to_cpu(in.extLength);
73 out.extLocation = le32_to_cpu(in.extLocation);
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 return out;
76}
77
Cyrill Gorcunov28de7942007-07-21 04:37:18 -070078#endif /* __UDF_ENDIAN_H */