1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox storage devices:
|
---|
4 | * C++-safe replacements for some Linux byte order macros
|
---|
5 | *
|
---|
6 | * On Linux, DrvHostDVD.cpp includes <linux/cdrom.h>, which in turn
|
---|
7 | * includes <linux/byteorder/swab.h>. Unfortunately, that file is not very
|
---|
8 | * C++ friendly, and our C++ compiler refuses to look at it. The solution
|
---|
9 | * is to define _LINUX_BYTEORDER_SWAB_H, which prevents that file's contents
|
---|
10 | * from getting included at all, and to provide, in this file, our own
|
---|
11 | * C++-proof versions of the macros which are needed by <linux/cdrom.h>
|
---|
12 | * before we include that file. We actually provide them as inline
|
---|
13 | * functions, due to the way they get resolved in the original.
|
---|
14 | */
|
---|
15 |
|
---|
16 | /*
|
---|
17 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
18 | *
|
---|
19 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
20 | * available from http://www.virtualbox.org. This file is free software;
|
---|
21 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
22 | * General Public License as published by the Free Software Foundation,
|
---|
23 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
24 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
25 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef _VBOX_LINUX_SWAB_H
|
---|
29 | #define _VBOX_LINUX_SWAB_H
|
---|
30 |
|
---|
31 | # define _LINUX_BYTEORDER_SWAB_H
|
---|
32 |
|
---|
33 | #include <asm/types.h>
|
---|
34 |
|
---|
35 | /* Sorry for the unnecessary brackets here, but I really think
|
---|
36 | readability requires them */
|
---|
37 | static __inline__ __u16 __swab16p(const __u16 *px)
|
---|
38 | {
|
---|
39 | __u16 x = *px;
|
---|
40 | return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
|
---|
41 | }
|
---|
42 |
|
---|
43 | static __inline__ __u32 __swab32p(const __u32 *px)
|
---|
44 | {
|
---|
45 | __u32 x = *px;
|
---|
46 | return ((x & 0xff) << 24) | ((x & 0xff00) << 8)
|
---|
47 | | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff);
|
---|
48 | }
|
---|
49 |
|
---|
50 | static __inline__ __u64 __swab64p(const __u64 *px)
|
---|
51 | {
|
---|
52 | __u64 x = *px;
|
---|
53 | return ((x & 0xff) << 56) | ((x & 0xff00) << 40)
|
---|
54 | | ((x & 0xff0000) << 24) | ((x & 0xff000000) << 8)
|
---|
55 | | ((x >> 8) & 0xff000000) | ((x >> 24) & 0xff0000)
|
---|
56 | | ((x >> 40) & 0xff00) | ((x >> 56) & 0xff);
|
---|
57 | }
|
---|
58 |
|
---|
59 | #endif /* _VBOX_LINUX_SWAB_H */
|
---|