chiark / gitweb /
[PATCH] udev_volume_id: volume_id v38
[elogind.git] / extras / volume_id / volume_id / util.h
1 /*
2  * volume_id - reads filesystem label and uuid
3  *
4  * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
5  *
6  *      This library is free software; you can redistribute it and/or
7  *      modify it under the terms of the GNU Lesser General Public
8  *      License as published by the Free Software Foundation; either
9  *      version 2.1 of the License, or (at your option) any later version.
10  *
11  *      This library 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 GNU
14  *      Lesser General Public License for more details.
15  *
16  *      You should have received a copy of the GNU Lesser General Public
17  *      License along with this library; if not, write to the Free Software
18  *      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20
21 #ifndef _VOLUME_ID_UTIL_
22 #define _VOLUME_ID_UTIL_
23
24 #ifndef _GNU_SOURCE
25 #define _GNU_SOURCE 1
26 #endif
27
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif
31
32 /* size of superblock buffer, reiserfs block is at 64k */
33 #define SB_BUFFER_SIZE                          0x11000
34 /* size of seek buffer, FAT cluster is 32k max */
35 #define SEEK_BUFFER_SIZE                        0x10000
36
37 /* probe volume for all known filesystems in specific order */
38 #define bswap16(x) (__u16)((((__u16)(x) & 0x00ffu) << 8) | \
39                            (((__u16)(x) & 0xff00u) >> 8))
40
41 #define bswap32(x) (__u32)((((__u32)(x) & 0xff000000u) >> 24) | \
42                            (((__u32)(x) & 0x00ff0000u) >>  8) | \
43                            (((__u32)(x) & 0x0000ff00u) <<  8) | \
44                            (((__u32)(x) & 0x000000ffu) << 24))
45
46 #define bswap64(x) (__u64)((((__u64)(x) & 0xff00000000000000ull) >> 56) | \
47                            (((__u64)(x) & 0x00ff000000000000ull) >> 40) | \
48                            (((__u64)(x) & 0x0000ff0000000000ull) >> 24) | \
49                            (((__u64)(x) & 0x000000ff00000000ull) >>  8) | \
50                            (((__u64)(x) & 0x00000000ff000000ull) <<  8) | \
51                            (((__u64)(x) & 0x0000000000ff0000ull) << 24) | \
52                            (((__u64)(x) & 0x000000000000ff00ull) << 40) | \
53                            (((__u64)(x) & 0x00000000000000ffull) << 56))
54
55 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
56 #define le16_to_cpu(x) (x)
57 #define le32_to_cpu(x) (x)
58 #define le64_to_cpu(x) (x)
59 #define be16_to_cpu(x) bswap16(x)
60 #define be32_to_cpu(x) bswap32(x)
61 #define cpu_to_le32(x) (x)
62 #define cpu_to_be32(x) bswap32(x)
63 #elif (__BYTE_ORDER == __BIG_ENDIAN)
64 #define le16_to_cpu(x) bswap16(x)
65 #define le32_to_cpu(x) bswap32(x)
66 #define le64_to_cpu(x) bswap64(x)
67 #define be16_to_cpu(x) (x)
68 #define be32_to_cpu(x) (x)
69 #define cpu_to_le32(x) bswap32(x)
70 #define cpu_to_be32(x) (x)
71 #endif
72
73 enum uuid_format {
74         UUID_DCE_STRING,
75         UUID_DCE,
76         UUID_DOS,
77         UUID_NTFS,
78         UUID_HFS,
79 };
80
81 enum endian {
82         LE = 0,
83         BE = 1
84 };
85
86 extern void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage_id);
87 extern void volume_id_set_usage_part(struct volume_id_partition *part, enum volume_id_usage usage_id);
88 extern void volume_id_set_label_raw(struct volume_id *id, const __u8 *buf, unsigned int count);
89 extern void volume_id_set_label_string(struct volume_id *id, const __u8 *buf, unsigned int count);
90 extern void volume_id_set_label_unicode16(struct volume_id *id, const __u8 *buf, enum endian endianess, unsigned int count);
91 extern void volume_id_set_uuid(struct volume_id *id, const __u8 *buf, enum uuid_format format);
92 extern __u8 *volume_id_get_buffer(struct volume_id *id, __u64 off, unsigned int len);
93 extern void volume_id_free_buffer(struct volume_id *id);
94
95 #endif /* _VOLUME_ID_UTIL_ */
96