"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/lib/libcryptsetup_macros.h" (13 Jan 2022, 2220 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "libcryptsetup_macros.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Definitions of common constant and generic macros fo libcryptsetup
    3  *
    4  * Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
    5  * Copyright (C) 2009-2021 Milan Broz
    6  *
    7  * This program is free software; you can redistribute it and/or
    8  * modify it under the terms of the GNU General Public License
    9  * as published by the Free Software Foundation; either version 2
   10  * of the License, or (at your option) any later version.
   11  *
   12  * This program is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  * GNU General Public License for more details.
   16  *
   17  * You should have received a copy of the GNU General Public License
   18  * along with this program; if not, write to the Free Software
   19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   20  */
   21 
   22 #ifndef _LIBCRYPTSETUP_MACROS_H
   23 #define _LIBCRYPTSETUP_MACROS_H
   24 
   25 /* to silent gcc -Wcast-qual for const cast */
   26 #define CONST_CAST(x) (x)(uintptr_t)
   27 
   28 #define UNUSED(x) (void)(x)
   29 
   30 #ifndef ARRAY_SIZE
   31 # define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
   32 #endif
   33 
   34 #define BITFIELD_SIZE(BF_PTR) (sizeof(*(BF_PTR)) * 8)
   35 
   36 #define MOVE_REF(x, y) \
   37     do { \
   38         __typeof__(x) *_px = &(x), *_py = &(y); \
   39         *_px = *_py; \
   40         *_py = NULL; \
   41     } while (0)
   42 
   43 #define FREE_AND_NULL(x) do { free(x); x = NULL; } while (0)
   44 
   45 #define AT_LEAST(a, b) ({ __typeof__(a) __at_least = (a); (__at_least >= (b))?__at_least:(b); })
   46 
   47 #define SHIFT_4K          12
   48 #define SECTOR_SHIFT       9
   49 #define SECTOR_SIZE     (1 << SECTOR_SHIFT)
   50 #define MAX_SECTOR_SIZE 4096 /* min page size among all platforms */
   51 #define ROUND_SECTOR(x) (((x) + SECTOR_SIZE - 1) / SECTOR_SIZE)
   52 
   53 #define MISALIGNED(a, b)    ((a) & ((b) - 1))
   54 #define MISALIGNED_4K(a)    MISALIGNED((a), 1 << SHIFT_4K)
   55 #define MISALIGNED_512(a)   MISALIGNED((a), 1 << SECTOR_SHIFT)
   56 #define NOTPOW2(a)      MISALIGNED((a), (a))
   57 
   58 #define DEFAULT_DISK_ALIGNMENT  1048576 /* 1MiB */
   59 #define DEFAULT_MEM_ALIGNMENT   4096
   60 
   61 #define DM_UUID_LEN     129
   62 #define DM_BY_ID_PREFIX     "dm-uuid-"
   63 #define DM_BY_ID_PREFIX_LEN 8
   64 #define DM_UUID_PREFIX      "CRYPT-"
   65 #define DM_UUID_PREFIX_LEN  6
   66 
   67 #endif /* _LIBCRYPTSETUP_MACROS_H */