blkid.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * blkid.h - Interface for libblkid, a library to identify block devices
  3. *
  4. * Copyright (C) 2001 Andreas Dilger
  5. * Copyright (C) 2003 Theodore Ts'o
  6. * Copyright (C) 2008 Karel Zak <kzak@redhat.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef _BLKID_BLKID_H
  23. #define _BLKID_BLKID_H
  24. #include <stdint.h>
  25. #include <sys/types.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define BLKID_VERSION "2.28.1"
  30. #define BLKID_DATE "11-Aug-2016"
  31. /**
  32. * blkid_dev:
  33. *
  34. * The device object keeps information about one device
  35. */
  36. typedef struct blkid_struct_dev *blkid_dev;
  37. /**
  38. * blkid_cache:
  39. *
  40. * information about all system devices
  41. */
  42. typedef struct blkid_struct_cache *blkid_cache;
  43. /**
  44. * blkid_probe:
  45. *
  46. * low-level probing setting
  47. */
  48. typedef struct blkid_struct_probe *blkid_probe;
  49. /**
  50. * blkid_topology:
  51. *
  52. * device topology information
  53. */
  54. typedef struct blkid_struct_topology *blkid_topology;
  55. /**
  56. * blkid_partlist
  57. *
  58. * list of all detected partitions and partitions tables
  59. */
  60. typedef struct blkid_struct_partlist *blkid_partlist;
  61. /**
  62. * blkid_partition:
  63. *
  64. * information about a partition
  65. */
  66. typedef struct blkid_struct_partition *blkid_partition;
  67. /**
  68. * blkid_parttable:
  69. *
  70. * information about a partition table
  71. */
  72. typedef struct blkid_struct_parttable *blkid_parttable;
  73. /**
  74. * blkid_loff_t:
  75. *
  76. * 64-bit signed number for offsets and sizes
  77. */
  78. typedef int64_t blkid_loff_t;
  79. /**
  80. * blkid_tag_iterate:
  81. *
  82. * tags iterator for high-level (blkid_cache) API
  83. */
  84. typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
  85. /**
  86. * blkid_dev_iterate:
  87. *
  88. * devices iterator for high-level (blkid_cache) API
  89. */
  90. typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
  91. /*
  92. * Flags for blkid_get_dev
  93. *
  94. * BLKID_DEV_CREATE Create an empty device structure if not found
  95. * in the cache.
  96. * BLKID_DEV_VERIFY Make sure the device structure corresponds
  97. * with reality.
  98. * BLKID_DEV_FIND Just look up a device entry, and return NULL
  99. * if it is not found.
  100. * BLKID_DEV_NORMAL Get a valid device structure, either from the
  101. * cache or by probing the device.
  102. */
  103. #define BLKID_DEV_FIND 0x0000
  104. #define BLKID_DEV_CREATE 0x0001
  105. #define BLKID_DEV_VERIFY 0x0002
  106. #define BLKID_DEV_NORMAL (BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
  107. #ifndef __GNUC_PREREQ
  108. # if defined __GNUC__ && defined __GNUC_MINOR__
  109. # define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  110. # else
  111. # define __GNUC_PREREQ(maj, min) 0
  112. # endif
  113. #endif
  114. #ifndef __ul_attribute__
  115. # if __GNUC_PREREQ (3, 4)
  116. # define __ul_attribute__(_a_) __attribute__(_a_)
  117. # else
  118. # define __ul_attribute__(_a_)
  119. # endif
  120. #endif
  121. /* cache.c */
  122. extern void blkid_init_debug(int mask);
  123. extern void blkid_put_cache(blkid_cache cache);
  124. extern int blkid_get_cache(blkid_cache *cache, const char *filename);
  125. extern void blkid_gc_cache(blkid_cache cache);
  126. /* dev.c */
  127. extern const char *blkid_dev_devname(blkid_dev dev)
  128. __ul_attribute__((warn_unused_result));
  129. extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
  130. extern int blkid_dev_set_search(blkid_dev_iterate iter,
  131. char *search_type, char *search_value);
  132. extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
  133. extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
  134. /* devno.c */
  135. extern char *blkid_devno_to_devname(dev_t devno)
  136. __ul_attribute__((warn_unused_result));
  137. extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
  138. size_t len, dev_t *diskdevno)
  139. __ul_attribute__((warn_unused_result));
  140. /* devname.c */
  141. extern int blkid_probe_all(blkid_cache cache);
  142. extern int blkid_probe_all_new(blkid_cache cache);
  143. extern int blkid_probe_all_removable(blkid_cache cache);
  144. extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);
  145. /* getsize.c */
  146. extern blkid_loff_t blkid_get_dev_size(int fd);
  147. /* verify.c */
  148. extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
  149. /* read.c */
  150. /* resolve.c */
  151. extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
  152. const char *devname)
  153. __ul_attribute__((warn_unused_result));
  154. extern char *blkid_get_devname(blkid_cache cache, const char *token,
  155. const char *value)
  156. __ul_attribute__((warn_unused_result));
  157. /* tag.c */
  158. extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
  159. extern int blkid_tag_next(blkid_tag_iterate iterate,
  160. const char **type, const char **value);
  161. extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
  162. extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value);
  163. extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
  164. const char *type,
  165. const char *value);
  166. extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);
  167. /* version.c */
  168. extern int blkid_parse_version_string(const char *ver_string)
  169. __ul_attribute__((nonnull));
  170. extern int blkid_get_library_version(const char **ver_string,
  171. const char **date_string);
  172. /* encode.c */
  173. extern int blkid_encode_string(const char *str, char *str_enc, size_t len);
  174. extern int blkid_safe_string(const char *str, char *str_safe, size_t len);
  175. /* evaluate.c */
  176. extern int blkid_send_uevent(const char *devname, const char *action);
  177. extern char *blkid_evaluate_tag(const char *token, const char *value,
  178. blkid_cache *cache)
  179. __ul_attribute__((warn_unused_result));
  180. extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
  181. __ul_attribute__((warn_unused_result));
  182. /* probe.c */
  183. extern blkid_probe blkid_new_probe(void)
  184. __ul_attribute__((warn_unused_result));
  185. extern blkid_probe blkid_new_probe_from_filename(const char *filename)
  186. __ul_attribute__((warn_unused_result));
  187. extern void blkid_free_probe(blkid_probe pr);
  188. extern void blkid_reset_probe(blkid_probe pr);
  189. extern int blkid_probe_set_device(blkid_probe pr, int fd,
  190. blkid_loff_t off, blkid_loff_t size);
  191. extern dev_t blkid_probe_get_devno(blkid_probe pr)
  192. __ul_attribute__((nonnull));
  193. extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
  194. __ul_attribute__((nonnull));
  195. extern int blkid_probe_is_wholedisk(blkid_probe pr)
  196. __ul_attribute__((nonnull));
  197. extern blkid_loff_t blkid_probe_get_size(blkid_probe pr);
  198. extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr);
  199. extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr);
  200. extern blkid_loff_t blkid_probe_get_sectors(blkid_probe pr);
  201. extern int blkid_probe_get_fd(blkid_probe pr);
  202. /*
  203. * superblocks probing
  204. */
  205. extern int blkid_known_fstype(const char *fstype);
  206. extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
  207. extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable);
  208. #define BLKID_SUBLKS_LABEL (1 << 1) /* read LABEL from superblock */
  209. #define BLKID_SUBLKS_LABELRAW (1 << 2) /* read and define LABEL_RAW result value*/
  210. #define BLKID_SUBLKS_UUID (1 << 3) /* read UUID from superblock */
  211. #define BLKID_SUBLKS_UUIDRAW (1 << 4) /* read and define UUID_RAW result value */
  212. #define BLKID_SUBLKS_TYPE (1 << 5) /* define TYPE result value */
  213. #define BLKID_SUBLKS_SECTYPE (1 << 6) /* define compatible fs type (second type) */
  214. #define BLKID_SUBLKS_USAGE (1 << 7) /* define USAGE result value */
  215. #define BLKID_SUBLKS_VERSION (1 << 8) /* read FS type from superblock */
  216. #define BLKID_SUBLKS_MAGIC (1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
  217. #define BLKID_SUBLKS_BADCSUM (1 << 10) /* allow a bad checksum */
  218. #define BLKID_SUBLKS_DEFAULT (BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
  219. BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
  220. extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags);
  221. extern int blkid_probe_reset_superblocks_filter(blkid_probe pr);
  222. extern int blkid_probe_invert_superblocks_filter(blkid_probe pr);
  223. /**
  224. * BLKID_FLTR_NOTIN
  225. */
  226. #define BLKID_FLTR_NOTIN 1
  227. /**
  228. * BLKID_FLTR_ONLYIN
  229. */
  230. #define BLKID_FLTR_ONLYIN 2
  231. extern int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[]);
  232. #define BLKID_USAGE_FILESYSTEM (1 << 1)
  233. #define BLKID_USAGE_RAID (1 << 2)
  234. #define BLKID_USAGE_CRYPTO (1 << 3)
  235. #define BLKID_USAGE_OTHER (1 << 4)
  236. extern int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage);
  237. /*
  238. * topology probing
  239. */
  240. extern int blkid_probe_enable_topology(blkid_probe pr, int enable);
  241. /* binary interface */
  242. extern blkid_topology blkid_probe_get_topology(blkid_probe pr);
  243. extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
  244. __ul_attribute__((nonnull));
  245. extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
  246. __ul_attribute__((nonnull));
  247. extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
  248. __ul_attribute__((nonnull));
  249. extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
  250. __ul_attribute__((nonnull));
  251. extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
  252. __ul_attribute__((nonnull));
  253. /*
  254. * partitions probing
  255. */
  256. extern int blkid_known_pttype(const char *pttype);
  257. extern int blkid_probe_enable_partitions(blkid_probe pr, int enable);
  258. extern int blkid_probe_reset_partitions_filter(blkid_probe pr);
  259. extern int blkid_probe_invert_partitions_filter(blkid_probe pr);
  260. extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[]);
  261. /* partitions probing flags */
  262. #define BLKID_PARTS_FORCE_GPT (1 << 1)
  263. #define BLKID_PARTS_ENTRY_DETAILS (1 << 2)
  264. #define BLKID_PARTS_MAGIC (1 << 3)
  265. extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags);
  266. /* binary interface */
  267. extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr);
  268. extern int blkid_partlist_numof_partitions(blkid_partlist ls);
  269. extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls);
  270. extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n);
  271. extern blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n);
  272. extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno);
  273. extern blkid_parttable blkid_partition_get_table(blkid_partition par);
  274. extern const char *blkid_partition_get_name(blkid_partition par);
  275. extern const char *blkid_partition_get_uuid(blkid_partition par);
  276. extern int blkid_partition_get_partno(blkid_partition par);
  277. extern blkid_loff_t blkid_partition_get_start(blkid_partition par);
  278. extern blkid_loff_t blkid_partition_get_size(blkid_partition par);
  279. extern int blkid_partition_get_type(blkid_partition par)
  280. __ul_attribute__((nonnull));
  281. extern const char *blkid_partition_get_type_string(blkid_partition par);
  282. extern unsigned long long blkid_partition_get_flags(blkid_partition par)
  283. __ul_attribute__((nonnull));
  284. extern int blkid_partition_is_logical(blkid_partition par)
  285. __ul_attribute__((nonnull));
  286. extern int blkid_partition_is_extended(blkid_partition par)
  287. __ul_attribute__((nonnull));
  288. extern int blkid_partition_is_primary(blkid_partition par)
  289. __ul_attribute__((nonnull));
  290. extern const char *blkid_parttable_get_type(blkid_parttable tab);
  291. extern const char *blkid_parttable_get_id(blkid_parttable tab);
  292. extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab);
  293. extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab);
  294. /*
  295. * NAME=value low-level interface
  296. */
  297. extern int blkid_do_probe(blkid_probe pr);
  298. extern int blkid_do_safeprobe(blkid_probe pr);
  299. extern int blkid_do_fullprobe(blkid_probe pr);
  300. extern int blkid_probe_numof_values(blkid_probe pr);
  301. extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
  302. const char **data, size_t *len);
  303. extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
  304. const char **data, size_t *len);
  305. extern int blkid_probe_has_value(blkid_probe pr, const char *name)
  306. __ul_attribute__((nonnull));
  307. extern int blkid_do_wipe(blkid_probe pr, int dryrun);
  308. extern int blkid_probe_step_back(blkid_probe pr);
  309. /*
  310. * Deprecated functions/macros
  311. */
  312. #ifndef BLKID_DISABLE_DEPRECATED
  313. #define BLKID_PROBREQ_LABEL BLKID_SUBLKS_LABEL
  314. #define BLKID_PROBREQ_LABELRAW BLKID_SUBLKS_LABELRAW
  315. #define BLKID_PROBREQ_UUID BLKID_SUBLKS_UUID
  316. #define BLKID_PROBREQ_UUIDRAW BLKID_SUBLKS_UUIDRAW
  317. #define BLKID_PROBREQ_TYPE BLKID_SUBLKS_TYPE
  318. #define BLKID_PROBREQ_SECTYPE BLKID_SUBLKS_SECTYPE
  319. #define BLKID_PROBREQ_USAGE BLKID_SUBLKS_USAGE
  320. #define BLKID_PROBREQ_VERSION BLKID_SUBLKS_VERSION
  321. extern int blkid_probe_set_request(blkid_probe pr, int flags)
  322. __ul_attribute__((deprecated));
  323. extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
  324. __ul_attribute__((deprecated));
  325. extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
  326. __ul_attribute__((deprecated));
  327. extern int blkid_probe_invert_filter(blkid_probe pr)
  328. __ul_attribute__((deprecated));
  329. extern int blkid_probe_reset_filter(blkid_probe pr)
  330. __ul_attribute__((deprecated));
  331. #endif /* BLKID_DISABLE_DEPRECATED */
  332. #ifdef __cplusplus
  333. }
  334. #endif
  335. #endif /* _BLKID_BLKID_H */