VirtualBox

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

Last change on this file since 98110 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/* $Id: swab.h 98103 2023-01-17 14:15:46Z 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-2023 Oracle and/or its affiliates.
19 *
20 * This file is part of VirtualBox base platform packages, as
21 * available from https://www.virtualbox.org.
22 *
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation, in version 3 of the
26 * License.
27 *
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, see <https://www.gnu.org/licenses>.
35 *
36 * SPDX-License-Identifier: GPL-3.0-only
37 */
38
39#ifndef VBOX_INCLUDED_SRC_Storage_swab_h
40#define VBOX_INCLUDED_SRC_Storage_swab_h
41#ifndef RT_WITHOUT_PRAGMA_ONCE
42# pragma once
43#endif
44
45#define _LINUX_BYTEORDER_SWAB_H
46#define _LINUX_BYTEORDER_SWABB_H
47
48#include <asm/types.h>
49
50/* Sorry for the unnecessary brackets here, but I really think
51 readability requires them */
52static __inline__ __u16 __swab16p(const __u16 *px)
53{
54 __u16 x = *px;
55 return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
56}
57
58static __inline__ __u32 __swab32p(const __u32 *px)
59{
60 __u32 x = *px;
61 return ((x & 0xff) << 24) | ((x & 0xff00) << 8)
62 | ((x >> 8) & 0xff00) | ((x >> 24) & 0xff);
63}
64
65static __inline__ __u64 __swab64p(const __u64 *px)
66{
67 __u64 x = *px;
68 return ((x & 0xff) << 56) | ((x & 0xff00) << 40)
69 | ((x & 0xff0000) << 24) | ((x & 0xff000000) << 8)
70 | ((x >> 8) & 0xff000000) | ((x >> 24) & 0xff0000)
71 | ((x >> 40) & 0xff00) | ((x >> 56) & 0xff);
72}
73
74#endif /* !VBOX_INCLUDED_SRC_Storage_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