util-linux (2.39)

(root)/
include/
blkid/
blkid.h
       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  
      23  #ifndef _BLKID_BLKID_H
      24  #define _BLKID_BLKID_H
      25  
      26  #include <stdint.h>
      27  #include <sys/types.h>
      28  
      29  #ifdef __cplusplus
      30  extern "C" {
      31  #endif
      32  
      33  #define BLKID_VERSION   "2.39.0"
      34  #define BLKID_DATE      "17-May-2023"
      35  
      36  /**
      37   * blkid_dev:
      38   *
      39   * The device object keeps information about one device
      40   */
      41  typedef struct blkid_struct_dev *blkid_dev;
      42  
      43  /**
      44   * blkid_cache:
      45   *
      46   * information about all system devices
      47   */
      48  typedef struct blkid_struct_cache *blkid_cache;
      49  
      50  /**
      51   * blkid_probe:
      52   *
      53   * low-level probing setting
      54   */
      55  typedef struct blkid_struct_probe *blkid_probe;
      56  
      57  /**
      58   * blkid_topology:
      59   *
      60   * device topology information
      61   */
      62  typedef struct blkid_struct_topology *blkid_topology;
      63  
      64  /**
      65   * blkid_partlist
      66   *
      67   * list of all detected partitions and partitions tables
      68   */
      69  typedef struct blkid_struct_partlist *blkid_partlist;
      70  
      71  /**
      72   * blkid_partition:
      73   *
      74   * information about a partition
      75   */
      76  typedef struct blkid_struct_partition *blkid_partition;
      77  
      78  /**
      79   * blkid_parttable:
      80   *
      81   * information about a partition table
      82   */
      83  typedef struct blkid_struct_parttable *blkid_parttable;
      84  
      85  /**
      86   * blkid_loff_t:
      87   *
      88   * 64-bit signed number for offsets and sizes
      89   */
      90  typedef int64_t blkid_loff_t;
      91  
      92  /**
      93   * blkid_tag_iterate:
      94   *
      95   * tags iterator for high-level (blkid_cache) API
      96   */
      97  typedef struct blkid_struct_tag_iterate *blkid_tag_iterate;
      98  
      99  /**
     100   * blkid_dev_iterate:
     101   *
     102   * devices iterator for high-level (blkid_cache) API
     103   */
     104  typedef struct blkid_struct_dev_iterate *blkid_dev_iterate;
     105  
     106  /*
     107   * Flags for blkid_get_dev
     108   *
     109   * BLKID_DEV_CREATE	Create an empty device structure if not found
     110   *			in the cache.
     111   * BLKID_DEV_VERIFY	Make sure the device structure corresponds
     112   *			with reality.
     113   * BLKID_DEV_FIND	Just look up a device entry, and return NULL
     114   *			if it is not found.
     115   * BLKID_DEV_NORMAL	Get a valid device structure, either from the
     116   *			cache or by probing the device.
     117   */
     118  #define BLKID_DEV_FIND		0x0000
     119  #define BLKID_DEV_CREATE	0x0001
     120  #define BLKID_DEV_VERIFY	0x0002
     121  #define BLKID_DEV_NORMAL	(BLKID_DEV_CREATE | BLKID_DEV_VERIFY)
     122  
     123  
     124  #ifndef __GNUC_PREREQ
     125  # if defined __GNUC__ && defined __GNUC_MINOR__
     126  #  define __GNUC_PREREQ(maj, min)  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
     127  # else
     128  #  define __GNUC_PREREQ(maj, min) 0
     129  # endif
     130  #endif
     131  
     132  #ifndef __ul_attribute__
     133  # if __GNUC_PREREQ (3, 4)
     134  #  define __ul_attribute__(_a_) __attribute__(_a_)
     135  # else
     136  #  define __ul_attribute__(_a_)
     137  # endif
     138  #endif
     139  
     140  /* init.c */
     141  extern void blkid_init_debug(int mask);
     142  
     143  /* cache.c */
     144  extern void blkid_put_cache(blkid_cache cache);
     145  extern int blkid_get_cache(blkid_cache *cache, const char *filename);
     146  extern void blkid_gc_cache(blkid_cache cache);
     147  
     148  /* dev.c */
     149  extern const char *blkid_dev_devname(blkid_dev dev)
     150  			__ul_attribute__((warn_unused_result));
     151  
     152  extern blkid_dev_iterate blkid_dev_iterate_begin(blkid_cache cache);
     153  extern int blkid_dev_set_search(blkid_dev_iterate iter,
     154  				const char *search_type, const char *search_value);
     155  extern int blkid_dev_next(blkid_dev_iterate iterate, blkid_dev *dev);
     156  extern void blkid_dev_iterate_end(blkid_dev_iterate iterate);
     157  
     158  /* devno.c */
     159  extern char *blkid_devno_to_devname(dev_t devno)
     160  			__ul_attribute__((warn_unused_result));
     161  extern int blkid_devno_to_wholedisk(dev_t dev, char *diskname,
     162                          size_t len, dev_t *diskdevno)
     163  			__ul_attribute__((warn_unused_result));
     164  
     165  /* devname.c */
     166  extern int blkid_probe_all(blkid_cache cache);
     167  extern int blkid_probe_all_new(blkid_cache cache);
     168  extern int blkid_probe_all_removable(blkid_cache cache);
     169  
     170  extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags);
     171  
     172  /* getsize.c */
     173  extern blkid_loff_t blkid_get_dev_size(int fd);
     174  
     175  /* verify.c */
     176  extern blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev);
     177  
     178  /* read.c */
     179  
     180  /* resolve.c */
     181  extern char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
     182  				       const char *devname)
     183  			__ul_attribute__((warn_unused_result));
     184  extern char *blkid_get_devname(blkid_cache cache, const char *token,
     185  			       const char *value)
     186  			__ul_attribute__((warn_unused_result));
     187  
     188  /* tag.c */
     189  extern blkid_tag_iterate blkid_tag_iterate_begin(blkid_dev dev);
     190  extern int blkid_tag_next(blkid_tag_iterate iterate,
     191  			      const char **type, const char **value);
     192  extern void blkid_tag_iterate_end(blkid_tag_iterate iterate);
     193  extern int blkid_dev_has_tag(blkid_dev dev, const char *type, const char *value);
     194  
     195  extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
     196  					 const char *type,
     197  					 const char *value);
     198  
     199  extern int blkid_parse_tag_string(const char *token, char **ret_type, char **ret_val);
     200  
     201  /* version.c */
     202  extern int blkid_parse_version_string(const char *ver_string)
     203  			__ul_attribute__((nonnull));
     204  extern int blkid_get_library_version(const char **ver_string,
     205  				     const char **date_string);
     206  
     207  /* encode.c */
     208  extern int blkid_encode_string(const char *str, char *str_enc, size_t len);
     209  extern int blkid_safe_string(const char *str, char *str_safe, size_t len);
     210  
     211  /* evaluate.c */
     212  extern int blkid_send_uevent(const char *devname, const char *action);
     213  extern char *blkid_evaluate_tag(const char *token, const char *value,
     214  				blkid_cache *cache)
     215  			__ul_attribute__((warn_unused_result));
     216  extern char *blkid_evaluate_spec(const char *spec, blkid_cache *cache)
     217  			__ul_attribute__((warn_unused_result));
     218  
     219  /* probe.c */
     220  extern blkid_probe blkid_new_probe(void)
     221  			__ul_attribute__((warn_unused_result));
     222  extern blkid_probe blkid_new_probe_from_filename(const char *filename)
     223  			__ul_attribute__((warn_unused_result))
     224  			__ul_attribute__((nonnull));
     225  extern void blkid_free_probe(blkid_probe pr);
     226  
     227  extern void blkid_reset_probe(blkid_probe pr);
     228  extern int blkid_probe_reset_buffers(blkid_probe pr);
     229  extern int blkid_probe_hide_range(blkid_probe pr, uint64_t off, uint64_t len);
     230  
     231  extern int blkid_probe_set_device(blkid_probe pr, int fd,
     232  	                blkid_loff_t off, blkid_loff_t size)
     233  			__ul_attribute__((nonnull));
     234  
     235  extern dev_t blkid_probe_get_devno(blkid_probe pr)
     236  			__ul_attribute__((nonnull));
     237  
     238  extern dev_t blkid_probe_get_wholedisk_devno(blkid_probe pr)
     239  			__ul_attribute__((nonnull));
     240  
     241  extern int blkid_probe_is_wholedisk(blkid_probe pr)
     242  			__ul_attribute__((nonnull));
     243  
     244  extern blkid_loff_t blkid_probe_get_size(blkid_probe pr)
     245  			__ul_attribute__((nonnull));
     246  extern blkid_loff_t blkid_probe_get_offset(blkid_probe pr)
     247  			__ul_attribute__((nonnull));
     248  extern unsigned int blkid_probe_get_sectorsize(blkid_probe pr)
     249  			__ul_attribute__((nonnull));
     250  extern int blkid_probe_set_sectorsize(blkid_probe pr, unsigned int sz)
     251  			__ul_attribute__((nonnull));
     252  extern blkid_loff_t blkid_probe_get_sectors(blkid_probe pr)
     253  			__ul_attribute__((nonnull));
     254  
     255  extern int blkid_probe_get_fd(blkid_probe pr)
     256  			__ul_attribute__((nonnull));
     257  
     258  extern int blkid_probe_set_hint(blkid_probe pr, const char *name, uint64_t value)
     259  			__ul_attribute__((nonnull));
     260  extern void blkid_probe_reset_hints(blkid_probe pr)
     261  			__ul_attribute__((nonnull));
     262  
     263  /*
     264   * superblocks probing
     265   */
     266  extern int blkid_known_fstype(const char *fstype)
     267  			__ul_attribute__((nonnull));
     268  
     269  extern int blkid_superblocks_get_name(size_t idx, const char **name, int *usage);
     270  
     271  extern int blkid_probe_enable_superblocks(blkid_probe pr, int enable)
     272  			__ul_attribute__((nonnull));
     273  
     274  #define BLKID_SUBLKS_LABEL	(1 << 1) /* read LABEL from superblock */
     275  #define BLKID_SUBLKS_LABELRAW	(1 << 2) /* read and define LABEL_RAW result value*/
     276  #define BLKID_SUBLKS_UUID	(1 << 3) /* read UUID from superblock */
     277  #define BLKID_SUBLKS_UUIDRAW	(1 << 4) /* read and define UUID_RAW result value */
     278  #define BLKID_SUBLKS_TYPE	(1 << 5) /* define TYPE result value */
     279  #define BLKID_SUBLKS_SECTYPE	(1 << 6) /* define compatible fs type (second type) */
     280  #define BLKID_SUBLKS_USAGE	(1 << 7) /* define USAGE result value */
     281  #define BLKID_SUBLKS_VERSION	(1 << 8) /* read FS type from superblock */
     282  #define BLKID_SUBLKS_MAGIC	(1 << 9) /* define SBMAGIC and SBMAGIC_OFFSET */
     283  #define BLKID_SUBLKS_BADCSUM	(1 << 10) /* allow a bad checksum */
     284  #define BLKID_SUBLKS_FSINFO	(1 << 11) /* read and define fs properties from superblock */
     285  
     286  #define BLKID_SUBLKS_DEFAULT	(BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID | \
     287  				 BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE)
     288  
     289  extern int blkid_probe_set_superblocks_flags(blkid_probe pr, int flags)
     290  			__ul_attribute__((nonnull));
     291  extern int blkid_probe_reset_superblocks_filter(blkid_probe pr)
     292  			__ul_attribute__((nonnull));
     293  extern int blkid_probe_invert_superblocks_filter(blkid_probe pr)
     294  			__ul_attribute__((nonnull));
     295  
     296  /**
     297   * BLKID_FLTR_NOTIN
     298   */
     299  #define BLKID_FLTR_NOTIN		1
     300  /**
     301   * BLKID_FLTR_ONLYIN
     302   */
     303  #define BLKID_FLTR_ONLYIN		2
     304  extern int blkid_probe_filter_superblocks_type(blkid_probe pr, int flag, char *names[])
     305  			__ul_attribute__((nonnull));
     306  
     307  #define BLKID_USAGE_FILESYSTEM		(1 << 1)
     308  #define BLKID_USAGE_RAID		(1 << 2)
     309  #define BLKID_USAGE_CRYPTO		(1 << 3)
     310  #define BLKID_USAGE_OTHER		(1 << 4)
     311  extern int blkid_probe_filter_superblocks_usage(blkid_probe pr, int flag, int usage)
     312  			__ul_attribute__((nonnull));
     313  
     314  /*
     315   * topology probing
     316   */
     317  extern int blkid_probe_enable_topology(blkid_probe pr, int enable)
     318  			__ul_attribute__((nonnull));
     319  
     320  /* binary interface */
     321  extern blkid_topology blkid_probe_get_topology(blkid_probe pr)
     322  			__ul_attribute__((nonnull));
     323  
     324  extern unsigned long blkid_topology_get_alignment_offset(blkid_topology tp)
     325  			__ul_attribute__((nonnull));
     326  extern unsigned long blkid_topology_get_minimum_io_size(blkid_topology tp)
     327  			__ul_attribute__((nonnull));
     328  extern unsigned long blkid_topology_get_optimal_io_size(blkid_topology tp)
     329  			__ul_attribute__((nonnull));
     330  extern unsigned long blkid_topology_get_logical_sector_size(blkid_topology tp)
     331  			__ul_attribute__((nonnull));
     332  extern unsigned long blkid_topology_get_physical_sector_size(blkid_topology tp)
     333  			__ul_attribute__((nonnull));
     334  extern unsigned long blkid_topology_get_dax(blkid_topology tp)
     335  			__ul_attribute__((nonnull));
     336  extern uint64_t blkid_topology_get_diskseq(blkid_topology tp)
     337  			__ul_attribute__((nonnull));
     338  
     339  /*
     340   * partitions probing
     341   */
     342  extern int blkid_known_pttype(const char *pttype);
     343  extern int blkid_partitions_get_name(const size_t idx, const char **name);
     344  
     345  extern int blkid_probe_enable_partitions(blkid_probe pr, int enable)
     346  			__ul_attribute__((nonnull));
     347  
     348  extern int blkid_probe_reset_partitions_filter(blkid_probe pr)
     349  			__ul_attribute__((nonnull));
     350  extern int blkid_probe_invert_partitions_filter(blkid_probe pr)
     351  			__ul_attribute__((nonnull));
     352  extern int blkid_probe_filter_partitions_type(blkid_probe pr, int flag, char *names[])
     353  			__ul_attribute__((nonnull));
     354  
     355  /* partitions probing flags */
     356  #define BLKID_PARTS_FORCE_GPT		(1 << 1)
     357  #define BLKID_PARTS_ENTRY_DETAILS	(1 << 2)
     358  #define BLKID_PARTS_MAGIC		(1 << 3)
     359  extern int blkid_probe_set_partitions_flags(blkid_probe pr, int flags)
     360  			__ul_attribute__((nonnull));
     361  
     362  /* binary interface */
     363  extern blkid_partlist blkid_probe_get_partitions(blkid_probe pr)
     364  			__ul_attribute__((nonnull));
     365  
     366  extern int blkid_partlist_numof_partitions(blkid_partlist ls)
     367  			__ul_attribute__((nonnull));
     368  extern blkid_parttable blkid_partlist_get_table(blkid_partlist ls)
     369  			__ul_attribute__((nonnull));
     370  extern blkid_partition blkid_partlist_get_partition(blkid_partlist ls, int n)
     371  			__ul_attribute__((nonnull));
     372  extern blkid_partition blkid_partlist_get_partition_by_partno(blkid_partlist ls, int n)
     373  			__ul_attribute__((nonnull));
     374  extern blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno)
     375  			__ul_attribute__((nonnull));
     376  extern blkid_parttable blkid_partition_get_table(blkid_partition par)
     377  			__ul_attribute__((nonnull));
     378  
     379  extern const char *blkid_partition_get_name(blkid_partition par)
     380  			__ul_attribute__((nonnull));
     381  extern const char *blkid_partition_get_uuid(blkid_partition par)
     382  			__ul_attribute__((nonnull));
     383  extern int blkid_partition_get_partno(blkid_partition par)
     384  			__ul_attribute__((nonnull));
     385  extern blkid_loff_t blkid_partition_get_start(blkid_partition par)
     386  			__ul_attribute__((nonnull));
     387  extern blkid_loff_t blkid_partition_get_size(blkid_partition par)
     388  			__ul_attribute__((nonnull));
     389  
     390  extern int blkid_partition_get_type(blkid_partition par)
     391  			__ul_attribute__((nonnull));
     392  extern const char *blkid_partition_get_type_string(blkid_partition par)
     393  			__ul_attribute__((nonnull));
     394  extern unsigned long long blkid_partition_get_flags(blkid_partition par)
     395  			__ul_attribute__((nonnull));
     396  
     397  extern int blkid_partition_is_logical(blkid_partition par)
     398  			__ul_attribute__((nonnull));
     399  extern int blkid_partition_is_extended(blkid_partition par)
     400  			__ul_attribute__((nonnull));
     401  extern int blkid_partition_is_primary(blkid_partition par)
     402  			__ul_attribute__((nonnull));
     403  
     404  extern const char *blkid_parttable_get_type(blkid_parttable tab)
     405  			__ul_attribute__((nonnull));
     406  extern const char *blkid_parttable_get_id(blkid_parttable tab)
     407  			__ul_attribute__((nonnull));
     408  extern blkid_loff_t blkid_parttable_get_offset(blkid_parttable tab)
     409  			__ul_attribute__((nonnull));
     410  extern blkid_partition blkid_parttable_get_parent(blkid_parttable tab)
     411  			__ul_attribute__((nonnull));
     412  
     413  /*
     414   * NAME=value low-level interface
     415   */
     416  extern int blkid_do_probe(blkid_probe pr)
     417  			__ul_attribute__((nonnull));
     418  extern int blkid_do_safeprobe(blkid_probe pr)
     419  			__ul_attribute__((nonnull));
     420  extern int blkid_do_fullprobe(blkid_probe pr)
     421  			__ul_attribute__((nonnull));
     422  
     423  /**
     424   * BLKID_PROBE_OK:
     425   *
     426   * probing return value; superblock (RAID, partiton table, ...) succesfully detected
     427   */
     428  #define BLKID_PROBE_OK	0
     429  /**
     430   * BLKID_PROBE_NONE:
     431   *
     432   * probing return value; found nothing
     433   */
     434  #define BLKID_PROBE_NONE	1
     435  /**
     436   * BLKID_PROBE_ERROR:
     437   *
     438   * probing return value; probing ends with en error (see errno for more details)
     439   */
     440  #define BLKID_PROBE_ERROR	-1
     441  /**
     442   * BLKID_PROBE_AMBIGUOUS:
     443   *
     444   * probing return value; more than one probing result, in this case, it's not
     445   * safe to use the device automaticaly and user intervention is recommended
     446   */
     447  #define BLKID_PROBE_AMBIGUOUS	-2
     448  
     449  extern int blkid_probe_numof_values(blkid_probe pr)
     450  			__ul_attribute__((nonnull));
     451  extern int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
     452                          const char **data, size_t *len)
     453  			__ul_attribute__((nonnull(1)));
     454  extern int blkid_probe_lookup_value(blkid_probe pr, const char *name,
     455                          const char **data, size_t *len)
     456  			__ul_attribute__((nonnull(1, 2)));
     457  extern int blkid_probe_has_value(blkid_probe pr, const char *name)
     458  			__ul_attribute__((nonnull));
     459  extern int blkid_do_wipe(blkid_probe pr, int dryrun)
     460  			__ul_attribute__((nonnull));
     461  extern int blkid_probe_step_back(blkid_probe pr)
     462  			__ul_attribute__((nonnull));
     463  
     464  /*
     465   * Deprecated functions/macros
     466   */
     467  #ifndef BLKID_DISABLE_DEPRECATED
     468  
     469  #define BLKID_PROBREQ_LABEL     BLKID_SUBLKS_LABEL
     470  #define BLKID_PROBREQ_LABELRAW  BLKID_SUBLKS_LABELRAW
     471  #define BLKID_PROBREQ_UUID      BLKID_SUBLKS_UUID
     472  #define BLKID_PROBREQ_UUIDRAW   BLKID_SUBLKS_UUIDRAW
     473  #define BLKID_PROBREQ_TYPE      BLKID_SUBLKS_TYPE
     474  #define BLKID_PROBREQ_SECTYPE   BLKID_SUBLKS_SECTYPE
     475  #define BLKID_PROBREQ_USAGE     BLKID_SUBLKS_USAGE
     476  #define BLKID_PROBREQ_VERSION   BLKID_SUBLKS_VERSION
     477  
     478  extern int blkid_probe_set_request(blkid_probe pr, int flags)
     479  			__ul_attribute__((deprecated));
     480  
     481  extern int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage)
     482  			__ul_attribute__((deprecated));
     483  
     484  extern int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[])
     485  			__ul_attribute__((deprecated));
     486  
     487  extern int blkid_probe_invert_filter(blkid_probe pr)
     488  			__ul_attribute__((deprecated));
     489  
     490  extern int blkid_probe_reset_filter(blkid_probe pr)
     491  			__ul_attribute__((deprecated));
     492  
     493  #endif /* BLKID_DISABLE_DEPRECATED */
     494  
     495  #ifdef __cplusplus
     496  }
     497  #endif
     498  
     499  #endif /* _BLKID_BLKID_H */