VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/swab.h@ 16146

Last change on this file since 16146 was 15776, checked in by vboxsync, 16 years ago

Linux 2.6.28 hack

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
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 Sun Microsystems, Inc.
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 (GPL) as published by the Free Software
23 * Foundation, in version 2 as it comes in the "COPYING" file of the
24 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
25 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
26 *
27 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
28 * Clara, CA 95054 USA or visit http://www.sun.com if you need
29 * additional information or have any questions.
30 */
31
32#ifndef _VBOX_LINUX_SWAB_H
33#define _VBOX_LINUX_SWAB_H
34
35# define _LINUX_BYTEORDER_SWAB_H
36# define _LINUX_BYTEORDER_SWABB_H
37
38#include <asm/types.h>
39
40/* Sorry for the unnecessary brackets here, but I really think
41 readability requires them */
42static __inline__ __u16 __swab16p(const __u16 *px)
43{
44 __u16 x = *px;
45 return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
46}
47
48static __inline__ __u32 __swab32p(const __u32 *px)
49{
50 __u32 x = *px;
51 return ((x & 0xff) << 24) | ((x & 0xff00) << 8)
52 | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff);
53}
54
55static __inline__ __u64 __swab64p(const __u64 *px)
56{
57 __u64 x = *px;
58 return ((x & 0xff) << 56) | ((x & 0xff00) << 40)
59 | ((x & 0xff0000) << 24) | ((x & 0xff000000) << 8)
60 | ((x >> 8) & 0xff000000) | ((x >> 24) & 0xff0000)
61 | ((x >> 40) & 0xff00) | ((x >> 56) & 0xff);
62}
63
64#endif /* _VBOX_LINUX_SWAB_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette