summaryrefslogblamecommitdiffstats
path: root/libblkid/blkid.h
blob: b283009f6e925790156415d21ef8769af8675253 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458









































































































































































































































































































































































































































































                                                                                               
/*
 * blkid.h - Interface for libblkid, a library to identify block devices
 *
 * Copyright (C) 2001 Andreas Dilger
 * Copyright (C) 2003 Theodore Ts'o
 * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef _BLKID_BLKID_H
#define _BLKID_BLKID_H

#include <stdint.h>
#include <sys/types.h>

#define _SC_HOST_NAME_MAX 255
#ifdef __cplusplus
extern "C" {
#endif

#define BLKID_VERSION   "2.22.0"
#define BLKID_DATE      "04-Sep-2012"

/**
 * blkid_dev:
 *
 * The device object keeps information about one device
 */
typedef struct blkid_struct_dev *blkid_dev;

/**
 * blkid_cache:
 *
 * information about all system devices
 */
typedef struct blkid_struct_cache *blkid_cache;

/**
 * blkid_probe:
 *
 * low-level probing setting
 */
typedef struct blkid_struct_probe *blkid_probe;

/**
 * blkid_topology:
 *
 * device topology information
 */
typedef struct blkid_struct_topology *blkid_topology;

/**
 * blkid_partlist
 *
 * list of all detected partitions and partitions tables
 */
typedef struct blkid_struct_partlist *blkid_partlist;

/**
 * blkid_partition:
 *
 * information about a partition
 */
typedef struct blkid_struct_partition *blkid_partition;

/**
 * blkid_parttable:
 *
 * information about a partition table
 */
typedef struct blkid_struct_parttable *blkid_parttable;

/**
 * blkid_loff_t:
 *
 * 64-bit signed number for offsets and sizes
 */
typedef int64_t blkid_loff_t;

/**
 * blkid_tag_iterate:
 *
 * tags iterator for high-level (blkid_cache) API
 */
typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;

/**
 * blkid_dev_iterate:
 *
 * devices iterator for high-level (blkid_cache) API
 */
typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;

/*
 * Flags for blkid_get_dev
 *
 * BLKID_DEV_CREATE	Create an empty device structure if not found
 *			in the cache.
 * BLKID_DEV_VERIFY	Make sure the device structure corresponds
 *			with reality.
 * BLKID_DEV_FIND	Just look up a device entry, and return NULL
 *			if it is not found.
 * BLKID_DEV_NORMAL	Get a valid device structure, either from the
 *			cache or by probing the device.
 */
#define BLKID_DEV_FIND		0x0000
#define BLKID_DEV_CREATE	0x0001
#define BLKID_DEV_VERIFY	0x0002
#define BLKID_DEV_NORMAL	(BLKID_DEV_CREATE | BLKID_DEV_VERIFY)


#ifndef __GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__
#  define __GNUC_PREREQ(maj, min)  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
# else
#  define __GNUC_PREREQ(maj, min) 0
# endif
#endif

#ifndef __ul_attribute__
# if __GNUC_PREREQ (3, 4)
#  define __ul_attribute__(_a_) __attribute__(_a_)
# else
#  define __ul_attribute__(_a_)
# endif
#endif

/* cache.c */
extern void blkid_put_cache(blkid_cache cache);
extern int blkid_get_cache(blkid_cache *cache, const char *filename);
extern void blkid_gc_cache(blkid_cache cache);

/* dev.c */
extern const char *blkid_dev_devname(blkid_dev dev)
			__ul_attribute__((warn_unused_result));

extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache)
			__ul_attribute__((nonnull));
extern int blkid_dev_set_search(blkid_dev_iterate iter,
				char *search_type, char *search_value);
extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);

/* devno.c */
extern char *blkid_devno_to_devname(dev_t devno)
			__ul_attribute__((warn_unused_result));
extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
                        size_t len, dev_t *diskdevno)
			__ul_attribute__((warn_unused_result));

/* devname.c */
extern int blkid_probe_all(blkid_cache cache);
extern int blkid_probe_all_new(blkid_cache cache);
extern int blkid_probe_all_removable(blkid_cache cache);

extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);

/* getsize.c */
extern blkid_loff_t blkid_get_dev_size(int fd)
			__ul_attribute__((warn_unused_result));

/* verify.c */
extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);

/* read.c */

/* resolve.c */
extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
				       const char *devname)
			__ul_attribute__((warn_unused_result));
extern char *blkid_get_devname(blkid_cache cache, const char *token,
			       const char *value)
			__ul_attribute__((warn_unused_result));

/* tag.c */
extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev)
			__ul_attribute__((warn_unused_result));
extern int blkid_tag_next(blkid_tag_iterate iterate,
			      const char **type, const char **value);
extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value)
			__ul_attribute__((nonnull(1,2)));

extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
					 const char *type,
					 const char *value)
			__ul_attribute__((warn_unused_result));

extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);

/* version.c */
extern int blkid_parse_version_string(const char *ver_string)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern int blkid_get_library_version(const char **ver_string,
				     const char **date_string);

/* encode.c */
extern int blkid_encode_string(const char *str, char *str_enc, size_t len);
extern int blkid_safe_string(const char *str, char *str_safe, size_t len);

/* evaluate.c */
extern int blkid_send_uevent(const char *devname, const char *action);
extern char *blkid_evaluate_tag(const char *token, const char *value,
				blkid_cache *cache)
			__ul_attribute__((warn_unused_result));
extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
			__ul_attribute__((warn_unused_result));

/* probe.c */
extern blkid_probe blkid_new_probe(void)
			__ul_attribute__((warn_unused_result));
extern blkid_probe blkid_new_probe_from_filename(const char *filename)
			__ul_attribute__((warn_unused_result));
extern void blkid_free_probe(blkid_probe pr);

extern void blkid_reset_probe(blkid_probe pr);

extern int blkid_probe_set_device(blkid_probe pr, int fd,
	                blkid_loff_t off, blkid_loff_t size);

extern dev_t blkid_probe_get_devno(blkid_probe pr)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern int blkid_probe_is_wholedisk(blkid_probe pr)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern blkid_loff_t blkid_probe_get_size(blkid_probe pr)
			__ul_attribute__((warn_unused_result));
extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr)
			__ul_attribute__((warn_unused_result));
extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr)
			__ul_attribute__((warn_unused_result));
extern blkid_loff_t blkid_probe_get_sectors(blkid_probe pr)
			__ul_attribute__((warn_unused_result));

extern int blkid_probe_get_fd(blkid_probe pr)
			__ul_attribute__((warn_unused_result));

/*
 * superblocks probing
 */
extern int blkid_known_fstype(const char *fstype)
			__ul_attribute__((warn_unused_result));

extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);

extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);

#define BLKID_SUBLKS_LABEL	(1 << 1) /* read LABEL from superblock */
#define BLKID_SUBLKS_LABELRAW	(1 << 2) /* read and define LABEL_RAW result value*/
#define BLKID_SUBLKS_UUID	(1 << 3) /* read UUID from superblock */
#define BLKID_SUBLKS_UUIDRAW	(1 << 4) /* read and define UUID_RAW result value */
#define BLKID_SUBLKS_TYPE	(1 << 5) /* define TYPE result value */
#define BLKID_SUBLKS_SECTYPE	(1 << 6) /* define compatible fs type (second type) */
#define BLKID_SUBLKS_USAGE	(1 << 7) /* define USAGE result value */
#define BLKID_SUBLKS_VERSION	(1 << 8) /* read FS type from superblock */
#define BLKID_SUBLKS_MAGIC	(1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */

#define BLKID_SUBLKS_DEFAULT	(BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
				 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)

extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags);
extern int blkid_probe_reset_superblocks_filter(blkid_probe pr);
extern int blkid_probe_invert_superblocks_filter(blkid_probe pr);

/**
 * BLKID_FLTR_NOTIN
 */
#define BLKID_FLTR_NOTIN		1
/**
 * BLKID_FLTR_ONLYIN
 */
#define BLKID_FLTR_ONLYIN		2
extern int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[]);

#define BLKID_USAGE_FILESYSTEM		(1 << 1)
#define BLKID_USAGE_RAID		(1 << 2)
#define BLKID_USAGE_CRYPTO		(1 << 3)
#define BLKID_USAGE_OTHER		(1 << 4)
extern int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage);

/*
 * topology probing
 */
extern int blkid_probe_enable_topology(blkid_probe pr, int enable);

/* binary interface */
extern blkid_topology blkid_probe_get_topology(blkid_probe pr)
			__ul_attribute__((warn_unused_result));

extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

/*
 * partitions probing
 */
extern int blkid_known_pttype(const char *pttype)
			__ul_attribute__((warn_unused_result));

extern int blkid_probe_enable_partitions(blkid_probe pr, int enable);

extern int blkid_probe_reset_partitions_filter(blkid_probe pr);
extern int blkid_probe_invert_partitions_filter(blkid_probe pr);
extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[]);

/* partitions probing flags */
#define BLKID_PARTS_FORCE_GPT		(1 << 1)
#define BLKID_PARTS_ENTRY_DETAILS	(1 << 2)
#define BLKID_PARTS_MAGIC		(1 << 3)
extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags);

/* binary interface */
extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr)
			__ul_attribute__((warn_unused_result));

extern int blkid_partlist_numof_partitions(blkid_partlist ls)
			__ul_attribute__((warn_unused_result));
extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls)
			__ul_attribute__((warn_unused_result));
extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n)
			__ul_attribute__((warn_unused_result));
extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno)
			__ul_attribute__((warn_unused_result));
extern blkid_parttable blkid_partition_get_table(blkid_partition par)
			__ul_attribute__((warn_unused_result));

extern const char *blkid_partition_get_name(blkid_partition par)
			__ul_attribute__((warn_unused_result));
extern const char *blkid_partition_get_uuid(blkid_partition par)
			__ul_attribute__((warn_unused_result));
extern int blkid_partition_get_partno(blkid_partition par)
			__ul_attribute__((warn_unused_result));
extern blkid_loff_t blkid_partition_get_start(blkid_partition par)
			__ul_attribute__((warn_unused_result));
extern blkid_loff_t blkid_partition_get_size(blkid_partition par)
			__ul_attribute__((warn_unused_result));

extern int blkid_partition_get_type(blkid_partition par)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern const char *blkid_partition_get_type_string(blkid_partition par)
			__ul_attribute__((warn_unused_result));

extern unsigned long long blkid_partition_get_flags(blkid_partition par)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern int blkid_partition_is_logical(blkid_partition par)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern int blkid_partition_is_extended(blkid_partition par)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));
extern int blkid_partition_is_primary(blkid_partition par)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern const char *blkid_parttable_get_type(blkid_parttable tab)
			__ul_attribute__((warn_unused_result));

extern const char *blkid_parttable_get_id(blkid_parttable tab)
			__ul_attribute__((warn_unused_result));

extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab)
			__ul_attribute__((warn_unused_result));
extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab)
			__ul_attribute__((warn_unused_result));

/*
 * NAME=value low-level interface
 */
extern int blkid_do_probe(blkid_probe pr);
extern int blkid_do_safeprobe(blkid_probe pr);
extern int blkid_do_fullprobe(blkid_probe pr);

extern int blkid_probe_numof_values(blkid_probe pr)
			__ul_attribute__((warn_unused_result));
extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
                        const char **data, size_t *len);
extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
                        const char **data, size_t *len);
extern int blkid_probe_has_value(blkid_probe pr, const char *name)
			__ul_attribute__((nonnull))
			__ul_attribute__((warn_unused_result));

extern int blkid_do_wipe(blkid_probe pr, int dryrun);
extern int blkid_probe_step_back(blkid_probe pr);

/*
 * Deprecated functions/macros
 */
#ifndef BLKID_DISABLE_DEPRECATED

#define BLKID_PROBREQ_LABEL     BLKID_SUBLKS_LABEL
#define BLKID_PROBREQ_LABELRAW  BLKID_SUBLKS_LABELRAW
#define BLKID_PROBREQ_UUID      BLKID_SUBLKS_UUID
#define BLKID_PROBREQ_UUIDRAW   BLKID_SUBLKS_UUIDRAW
#define BLKID_PROBREQ_TYPE      BLKID_SUBLKS_TYPE
#define BLKID_PROBREQ_SECTYPE   BLKID_SUBLKS_SECTYPE
#define BLKID_PROBREQ_USAGE     BLKID_SUBLKS_USAGE
#define BLKID_PROBREQ_VERSION   BLKID_SUBLKS_VERSION

extern int blkid_probe_set_request(blkid_probe pr, int flags)
			__ul_attribute__((deprecated));

extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
			__ul_attribute__((deprecated));

extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
			__ul_attribute__((deprecated));

extern int blkid_probe_invert_filter(blkid_probe pr)
			__ul_attribute__((deprecated));

extern int blkid_probe_reset_filter(blkid_probe pr)
			__ul_attribute__((deprecated));

#endif /* BLKID_DISABLE_DEPRECATED */

#ifdef __cplusplus
}
#endif

#endif /* _BLKID_BLKID_H */