libparted 3.6
Loading...
Searching...
No Matches
misc.h
Go to the documentation of this file.
1/* -*- Mode: c; indent-tabs-mode: nil -*-
2
3 libparted - a library for manipulating disk partitions
4 Copyright (C) 2007, 2009-2014, 2019-2023 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#include <inttypes.h>
20#include <uuid/uuid.h>
21
22/* hack: use the ext2 uuid library to generate a reasonably random (hopefully
23 * with /dev/random) number. Unfortunately, we can only use 4 bytes of it.
24 * We make sure to avoid returning zero which may be interpreted as no FAT
25 * serial number or no MBR signature.
26 */
27static inline uint32_t
28generate_random_uint32 (void)
29{
30 union {
31 uuid_t uuid;
32 uint32_t i;
33 } uu32;
34
35 uuid_generate (uu32.uuid);
36
37 return uu32.i > 0 ? uu32.i : 0xffffffff;
38}
39
40/* Return nonzero if FS_TYPE_NAME starts with "linux-swap".
41 This must match the NUL-terminated "linux-swap" as well
42 as "linux-swap(v0)" and "linux-swap(v1)". */
43static inline int
44is_linux_swap (char const *fs_type_name)
45{
46 char const *prefix = "linux-swap";
47 return strncmp (fs_type_name, prefix, strlen (prefix)) == 0;
48}
uint8_t uuid[16]
Definition: f2fs.h:27