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, 2026 Free Software Foundation,
5 Inc.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (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, see <http://www.gnu.org/licenses/>. */
19
20#include <inttypes.h>
21#include <uuid/uuid.h>
22
23/* hack: use the ext2 uuid library to generate a reasonably random (hopefully
24 * with /dev/random) number. Unfortunately, we can only use 4 bytes of it.
25 * We make sure to avoid returning zero which may be interpreted as no FAT
26 * serial number or no MBR signature.
27 */
28static inline uint32_t
29generate_random_uint32 (void)
30{
31 union {
32 uuid_t uuid;
33 uint32_t i;
34 } uu32;
35
36 uuid_generate (uu32.uuid);
37
38 return uu32.i > 0 ? uu32.i : 0xffffffff;
39}
40
41/* Return nonzero if FS_TYPE_NAME starts with "linux-swap".
42 This must match the NUL-terminated "linux-swap" as well
43 as "linux-swap(v0)" and "linux-swap(v1)". */
44static inline int
45is_linux_swap (char const *fs_type_name)
46{
47 char const *prefix = "linux-swap";
48 return strncmp (fs_type_name, prefix, strlen (prefix)) == 0;
49}
uint8_t uuid[16]
Definition f2fs.h:27