chiark / gitweb /
Make run_directory.c stat the place it is going to try to run.
[elogind.git] / extras / volume_id / libvolume_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 program is free software; you can redistribute it and/or modify it
7  *      under the terms of the GNU General Public License as published by the
8  *      Free Software Foundation version 2 of the License.
9  */
10
11 #ifndef _VOLUME_ID_UTIL_
12 #define _VOLUME_ID_UTIL_
13
14 #ifndef _GNU_SOURCE
15 #define _GNU_SOURCE 1
16 #endif
17
18 #ifdef HAVE_CONFIG_H
19 #  include <config.h>
20 #endif
21
22 #include <endian.h>
23
24 /* size of superblock buffer, reiserfs block is at 64k */
25 #define SB_BUFFER_SIZE                          0x11000
26 /* size of seek buffer, FAT cluster is 32k max */
27 #define SEEK_BUFFER_SIZE                        0x10000
28
29 /* probe volume for all known filesystems in specific order */
30 #define bswap16(x) (uint16_t)   ((((uint16_t)(x) & 0x00ffu) << 8) | \
31                                 (((uint16_t)(x) & 0xff00u) >> 8))
32
33 #define bswap32(x) (uint32_t)   ((((uint32_t)(x) & 0xff000000u) >> 24) | \
34                                 (((uint32_t)(x) & 0x00ff0000u) >>  8) | \
35                                 (((uint32_t)(x) & 0x0000ff00u) <<  8) | \
36                                 (((uint32_t)(x) & 0x000000ffu) << 24))
37
38 #define bswap64(x) (uint64_t)   ((((uint64_t)(x) & 0xff00000000000000ull) >> 56) | \
39                                 (((uint64_t)(x) & 0x00ff000000000000ull) >> 40) | \
40                                 (((uint64_t)(x) & 0x0000ff0000000000ull) >> 24) | \
41                                 (((uint64_t)(x) & 0x000000ff00000000ull) >>  8) | \
42                                 (((uint64_t)(x) & 0x00000000ff000000ull) <<  8) | \
43                                 (((uint64_t)(x) & 0x0000000000ff0000ull) << 24) | \
44                                 (((uint64_t)(x) & 0x000000000000ff00ull) << 40) | \
45                                 (((uint64_t)(x) & 0x00000000000000ffull) << 56))
46
47 #ifdef __BYTE_ORDER
48 #if (__BYTE_ORDER == __LITTLE_ENDIAN)
49 #define le16_to_cpu(x) (x)
50 #define le32_to_cpu(x) (x)
51 #define le64_to_cpu(x) (x)
52 #define be16_to_cpu(x) bswap16(x)
53 #define be32_to_cpu(x) bswap32(x)
54 #define cpu_to_le16(x) (x)
55 #define cpu_to_le32(x) (x)
56 #define cpu_to_be32(x) bswap32(x)
57 #elif (__BYTE_ORDER == __BIG_ENDIAN)
58 #define le16_to_cpu(x) bswap16(x)
59 #define le32_to_cpu(x) bswap32(x)
60 #define le64_to_cpu(x) bswap64(x)
61 #define be16_to_cpu(x) (x)
62 #define be32_to_cpu(x) (x)
63 #define cpu_to_le16(x) bswap16(x)
64 #define cpu_to_le32(x) bswap32(x)
65 #define cpu_to_be32(x) (x)
66 #endif
67 #endif /* __BYTE_ORDER */
68
69 enum uuid_format {
70         UUID_DCE_STRING,
71         UUID_DCE,
72         UUID_DOS,
73         UUID_NTFS,
74         UUID_HFS,
75 };
76
77 enum endian {
78         LE = 0,
79         BE = 1
80 };
81
82 extern void volume_id_set_unicode16(char *str, size_t len, const uint8_t *buf, enum endian endianess, size_t count);
83 extern void volume_id_set_usage(struct volume_id *id, enum volume_id_usage usage_id);
84 extern void volume_id_set_usage_part(struct volume_id_partition *part, enum volume_id_usage usage_id);
85 extern void volume_id_set_label_raw(struct volume_id *id, const uint8_t *buf, size_t count);
86 extern void volume_id_set_label_string(struct volume_id *id, const uint8_t *buf, size_t count);
87 extern void volume_id_set_label_unicode16(struct volume_id *id, const uint8_t *buf, enum endian endianess, size_t count);
88 extern void volume_id_set_uuid(struct volume_id *id, const uint8_t *buf, enum uuid_format format);
89 extern uint8_t *volume_id_get_buffer(struct volume_id *id, uint64_t off, size_t len);
90 extern void volume_id_free_buffer(struct volume_id *id);
91
92 #endif /* _VOLUME_ID_UTIL_ */
93