VirtualBox

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

Last change on this file since 62506 was 62506, checked in by vboxsync, 8 years ago

(C) 2016

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