This file is indexed.

/usr/include/lvm2app.h is in liblvm2-dev 2.02.111-2.2+deb8u1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
/*
 * Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
 *
 * This file is part of LVM2.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License v.2.1.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#ifndef _LIB_LVM2APP_H
#define _LIB_LVM2APP_H

#include <libdevmapper.h>

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/******************************** WARNING ***********************************
 *
 * NOTE: This API is under development and subject to change at any time.
 *
 * Please send feedback to lvm-devel@redhat.com
 *
 *********************************** WARNING ********************************/

/*************************** Design Overview ********************************/

/**
 * \mainpage LVM library API
 *
 * The API is designed around the following basic LVM objects:
 * 1) Physical Volume (pv_t) 2) Volume Group (vg_t) 3) Logical Volume (lv_t).
 *
 * The library provides functions to list the objects in a system,
 * get and set object properties (such as names, UUIDs, and sizes), as well
 * as create/remove objects and perform more complex operations and
 * transformations. Each object instance is represented by a handle, and
 * handles are passed to and from the functions to perform the operations.
 *
 * A central object in the library is the Volume Group, represented by the
 * VG handle, vg_t. Performing an operation on a PV or LV object first
 * requires obtaining a VG handle. Once the vg_t has been obtained, it can
 * be used to enumerate the pv_t and lv_t objects within that vg_t. Attributes
 * of these objects can then be queried or changed.
 *
 * A volume group handle may be obtained with read or write permission.
 * Any attempt to change a property of a pv_t, vg_t, or lv_t without
 * obtaining write permission on the vg_t will fail with EPERM.
 *
 * An application first opening a VG read-only, then later wanting to change
 * a property of an object must first close the VG and re-open with write
 * permission. Currently liblvm provides no mechanism to determine whether
 * the VG has changed on-disk in between these operations - this is the
 * application's responsiblity. One way the application can ensure the VG
 * has not changed is to save the "vg_seqno" field after opening the VG with
 * READ permission. If the application later needs to modify the VG, it can
 * close the VG and re-open with WRITE permission. It should then check
 * whether the original "vg_seqno" obtained with READ permission matches
 * the new one obtained with WRITE permission.
 */

/**
 * Retrieve the library version.
 *
 * The library version is the same format as the full LVM version.
 * The format is as follows:
 *    LVM_MAJOR.LVM_MINOR.LVM_PATCHLEVEL(LVM_LIBAPI)[-LVM_RELEASE]
 * An application wishing to determine compatibility with a particular version
 * of the library should check at least the LVM_MAJOR, LVM_MINOR, and
 * LVM_LIBAPI numbers.  For example, assume the full LVM version is
 * 2.02.50(1)-1.  The application should verify the "2.02" and the "(1)".
 *
 * \return  A string describing the library version.
 */
const char *lvm_library_get_version(void);

/******************************** structures ********************************/

/**
 * Opaque C pointers - Internal structures may change without notice between
 * releases, whereas this API will be changed much less frequently.  Backwards
 * compatibility will normally be preserved in future releases.  On any occasion
 * when the developers do decide to break backwards compatibility in any
 * significant way, the LVM_LIBAPI number (included in the library's soname)
 * will be incremented.
 */

/**
 * \class lvm_t
 *
 * This is the base handle that is needed to open and create objects such as
 * volume groups and logical volumes.  In addition, this handle provides a
 * context for error handling information, saving any error number (see
 * lvm_errno()) and error message (see lvm_errmsg()) that any function may
 * generate.
 */
typedef struct lvm *lvm_t;

/**
 * \class vg_t
 *
 * The volume group object is a central object in the library, and can be
 * either a read-only object or a read-write object depending on the function
 * used to obtain the object handle. For example, lvm_vg_create() always
 * returns a read/write handle, while lvm_vg_open() has a "mode" argument
 * to define the read/write mode of the handle.
 */
typedef struct volume_group *vg_t;

/**
 * \class lv_t
 *
 * This logical volume object is bound to a vg_t and has the same
 * read/write mode as the vg_t.  Changes will be written to disk
 * when the vg_t gets committed to disk by calling lvm_vg_write().
 */
typedef struct logical_volume *lv_t;

/**
 * \class pv_t
 *
 * This physical volume object is bound to a vg_t and has the same
 * read/write mode as the vg_t.  Changes will be written to disk
 * when the vg_t gets committed to disk by calling lvm_vg_write().
 */
typedef struct physical_volume *pv_t;

/**
 * \class lvseg_t
 *
 * This lv segment object is bound to a lv_t.
 */
typedef struct lv_segment *lvseg_t;

/**
 * \class pvseg_t
 *
 * This pv segment object is bound to a pv_t.
 */
typedef struct pv_segment *pvseg_t;

/**
 * \class lv_create_params
 *
 * This lv_create_params represents the plethora of available options when
 * creating a logical volume
 */
typedef struct lvm_lv_create_params *lv_create_params_t;

/**
 * \class pv_create_params
 *
 * This pv_create_params represents the plethora of available options when
 * creating a physical volume
 */
typedef struct lvm_pv_create_params *pv_create_params_t;

/**
 * Logical Volume object list.
 *
 * Lists of these structures are returned by lvm_vg_list_lvs().
 */
typedef struct lvm_lv_list {
	struct dm_list list;
	lv_t lv;
} lv_list_t;

/**
 * Logical Volume Segment object list.
 *
 * Lists of these structures are returned by lvm_lv_list_lvsegs().
 */
typedef struct lvm_lvseg_list {
	struct dm_list list;
	lvseg_t lvseg;
} lvseg_list_t;

/**
 * Physical volume object list.
 *
 * Lists of these structures are returned by lvm_vg_list_pvs().
 */
typedef struct lvm_pv_list {
	struct dm_list list;
	pv_t pv;
} pv_list_t;

/**
 * Physical Volume Segment object list.
 *
 * Lists of these structures are returned by lvm_pv_list_pvsegs().
 */
typedef struct lvm_pvseg_list {
	struct dm_list list;
	pvseg_t pvseg;
} pvseg_list_t;

/**
 * String list.
 *
 * This string list contains read-only strings.
 * Lists of these structures are returned by functions such as
 * lvm_list_vg_names() and lvm_list_vg_uuids().
 */
typedef struct lvm_str_list {
	struct dm_list list;
	const char *str;
} lvm_str_list_t;

/**
 * Property Value
 *
 * This structure defines a single LVM property value for an LVM object.
 * The structures are returned by functions such as
 * lvm_vg_get_property().
 *
 * is_settable: indicates whether a 'set' function exists for this property
 * is_string: indicates whether this property is a string (1) or not (0)
 * is_integer: indicates whether this property is an integer (1) or not (0)
 * is_valid: indicates whether 'value' is valid (1) or not (0)
 */
typedef struct lvm_property_value {
	uint32_t is_settable:1;
	uint32_t is_string:1;
	uint32_t is_integer:1;
	uint32_t is_valid:1;
	uint32_t padding:28;
	union {
		const char *string;
		uint64_t integer;
	} value;
} lvm_property_value_t;

/*************************** generic lvm handling ***************************/
/**
 * Create a LVM handle.
 *
 * \memberof lvm_t
 *
 * Once all LVM operations have been completed, use lvm_quit() to release
 * the handle and any associated resources.
 *
 * \param system_dir
 * Set an alternative LVM system directory. Use NULL to use the
 * default value. If the environment variable LVM_SYSTEM_DIR is set,
 * it will override any system_dir setting.
 *
 * \return
 * A valid LVM handle is returned or NULL if there has been a
 * memory allocation problem. You have to check if an error occured
 * with the lvm_error() function.
 */
lvm_t lvm_init(const char *system_dir);

/**
 * Destroy a LVM handle allocated with lvm_init().
 *
 * \memberof lvm_t
 *
 * This function should be used after all LVM operations are complete or after
 * an unrecoverable error.  Destroying the LVM handle frees the memory and
 * other resources associated with the handle.  Once destroyed, the handle
 * cannot be used subsequently.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 */
void lvm_quit(lvm_t libh);

/**
 * Reload the original configuration from the system directory.
 *
 * \memberof lvm_t
 *
 * This function should be used when any LVM configuration changes in the LVM
 * system_dir or by another lvm_config* function, and the change is needed by
 * the application.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_config_reload(lvm_t libh);

/**
 * Override the LVM configuration with a configuration string.
 *
 * \memberof lvm_t
 *
 * This function is equivalent to the --config option on lvm commands.
 * Once this API has been used to over-ride the configuration,
 * use lvm_config_reload() to apply the new settings.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \param   config_string
 * LVM configuration string to apply.  See the lvm.conf file man page
 * for the format of the config string.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_config_override(lvm_t libh, const char *config_string);

/**
 * Find a boolean value in the LVM configuration.
 *
 * \memberof lvm_t
 *
 * This function finds a boolean value associated with a path
 * in current LVM configuration.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \param   config_path
 * A path in LVM configuration
 *
 * \param   fail
 * Value to return if the path is not found.
 *
 * \return
 * boolean value for 'config_path' (success) or the value of 'fail' (error)
 */
int lvm_config_find_bool(lvm_t libh, const char *config_path, int fail);

/**
 * Return stored error no describing last LVM API error.
 *
 * \memberof lvm_t
 *
 * Users of liblvm should use lvm_errno to determine the details of a any
 * failure of the last call.  A basic success or fail is always returned by
 * every function, either by returning a 0 or -1, or a non-NULL / NULL.
 * If a function has failed, lvm_errno may be used to get a more specific
 * error code describing the failure.  In this way, lvm_errno may be used
 * after every function call, even after a 'get' function call that simply
 * returns a value.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \return
 * An errno value describing the last LVM error.
 */
int lvm_errno(lvm_t libh);

/**
 * Return stored error message describing last LVM error.
 *
 * \memberof lvm_t
 *
 * This function may be used in conjunction with lvm_errno() to obtain more
 * specific error information for a function that is known to have failed.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \return
 * An error string describing the last LVM error.
 */
const char *lvm_errmsg(lvm_t libh);

/**
 * Scan all devices on the system for VGs and LVM metadata.
 *
 * \memberof lvm_t
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_scan(lvm_t libh);

/**
 * Return the list of volume group names.
 *
 * \memberof lvm_t
 *
 * The memory allocated for the list is tied to the lvm_t handle and will be
 * released when lvm_quit() is called.
 *
 * NOTE: This function normally does not scan devices in the system for LVM
 * metadata.  To scan the system, use lvm_scan().
 *
 * To process the list, use the dm_list iterator functions.  For example:
 *      vg_t vg;
 *      struct dm_list *vgnames;
 *      struct lvm_str_list *strl;
 *
 *      vgnames = lvm_list_vg_names(libh);
 *	dm_list_iterate_items(strl, vgnames) {
 *		vgname = strl->str;
 *              vg = lvm_vg_open(libh, vgname, "r");
 *              // do something with vg
 *              lvm_vg_close(vg);
 *      }
 *
 *
 * \return
 * A list with entries of type struct lvm_str_list, containing the
 * VG name strings of the Volume Groups known to the system.
 * NULL is returned if unable to allocate memory.
 * An empty list (verify with dm_list_empty) is returned if no VGs
 * exist on the system.
 */
struct dm_list *lvm_list_vg_names(lvm_t libh);

/**
 * Return the list of volume group uuids.
 *
 * \memberof lvm_t
 *
 * The memory allocated for the list is tied to the lvm_t handle and will be
 * released when lvm_quit() is called.
 *
 * NOTE: This function normally does not scan devices in the system for LVM
 * metadata.  To scan the system, use lvm_scan().
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \return
 * A list with entries of type struct lvm_str_list, containing the
 * VG UUID strings of the Volume Groups known to the system.
 * NULL is returned if unable to allocate memory.
 * An empty list (verify with dm_list_empty) is returned if no VGs
 * exist on the system.
 */
struct dm_list *lvm_list_vg_uuids(lvm_t libh);

/**
 * Return the volume group name given a PV UUID
 *
 * \memberof lvm_t
 *
 * The memory allocated for the name is tied to the lvm_t handle and will be
 * released when lvm_quit() is called.
 *
 * NOTE: This function may scan devices in the system for LVM metadata.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \return
 * The volume group name for the given PV UUID.
 * NULL is returned if the PV UUID is not associated with a volume group.
 */
const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid);

/**
 * Return the volume group name given a device name
 *
 * \memberof lvm_t
 *
 * The memory allocated for the name is tied to the lvm_t handle and will be
 * released when lvm_quit() is called.
 *
 * NOTE: This function may scan devices in the system for LVM metadata.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \return
 * The volume group name for the given device name.
 * NULL is returned if the device is not an LVM device.
 *
 */
const char *lvm_vgname_from_device(lvm_t libh, const char *device);

/**
 * Open an existing VG.
 *
 * Open a VG for reading or writing.
 *
 * \memberof lvm_t
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \param   vgname
 * Name of the VG to open.
 *
 * \param   mode
 * Open mode - either "r" (read) or "w" (read/write).
 * Any other character results in an error with EINVAL set.
 *
 * \param   flags
 * Open flags - currently ignored.
 *
 * \return  non-NULL VG handle (success) or NULL (failure).
 */
vg_t lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
		  uint32_t flags);

/**
 * Validate a name to be used for new VG construction.
 *
 * This function checks that the name has no invalid characters,
 * the length doesn't exceed maximum and that the VG name isn't already in use
 * and that the name adheres to any other limitations.
 *
 * \param libh
 * Valid library handle
 *
 * \param name
 * Name to validate for new VG create.
 */
int lvm_vg_name_validate(lvm_t libh, const char *vg_name);

/**
 * Create a VG with default parameters.
 *
 * \memberof lvm_t
 *
 * This function creates a Volume Group object in memory.
 * Upon success, other APIs may be used to set non-default parameters.
 * For example, to set a non-default extent size, use lvm_vg_set_extent_size().
 * Next, to add physical storage devices to the volume group, use
 * lvm_vg_extend() for each device.
 * Once all parameters are set appropriately and all devices are added to the
 * VG, use lvm_vg_write() to commit the new VG to disk, and lvm_vg_close() to
 * release the VG handle.
 *
 * \param   libh
 * Handle obtained from lvm_init().
 *
 * \param   vg_name
 * Name of the VG to open.
 *
 * \return
 * non-NULL vg handle (success) or NULL (failure)
 */
vg_t lvm_vg_create(lvm_t libh, const char *vg_name);

/*************************** volume group handling **************************/

/**
 * Return a list of LV handles for a given VG handle.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * A list of lvm_lv_list structures containing lv handles for this vg.
 * If no LVs exist on the given VG, NULL is returned.
 */
struct dm_list *lvm_vg_list_lvs(vg_t vg);

/**
 * Return a list of PV handles for all.
 *
 * \memberof lvm_t
 *
 * \param   libh
 * Library handle retrieved from lvm_init
 *
 * \return
 * A list of lvm_pv_list structures containing pv handles for all physical
 * volumes. If no PVs exist or a global lock was unable to be obtained a
 * NULL is returned.  Do not attempt to remove one of the PVs until after the
 * call to lvm_list_pvs_free has been made.
 */
struct dm_list *lvm_list_pvs(lvm_t libh);

/**
 * Free the resources used by acquiring the pvlist.  This should be called as
 * soon as possible after processing the needed information from the pv list as
 * a global lock is held.
 *
 * \param	pvlist
 * PV list to be freed
 *
 * \return
 * 0 on success, else -1 with library errno and text set.
 */
int lvm_list_pvs_free(struct dm_list *pvlist);

/**
 *  Create a physical volume.
 *  \param	libh	Library handle
 *  \param	pv_name	The physical volume name
 *  \param	size	Size of physical volume, 0 = use all available.
 *  \return
 *  0 on success, else -1 with library errno and text set.
 */
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size);

/**
 * Create a physical volume parameter object for PV creation.
 *
 * \param	libh	Library handle
 * \param	pv_name	Device name
 *
 * \return
 * NULL on error, else valid parameter object to use.
 */
pv_create_params_t lvm_pv_params_create(lvm_t libh, const char *pv_name);

/**
 * Create a parameter object to use in function lvm_pv_create_adv
 *
 * 	\param 	params	The params object to get property value from
 * 	\param	name	The name of the property to retrieve
 *
 * 	Available properties:
 *
 * 	size					zero indicates use detected size of device
 * 							(recommended and default)
 *	pvmetadatacopies		Number of metadata copies (0,1,2)
 *	pvmetadatasize			The approx. size to be to be set aside for metadata
 *	data_alignment			Align the start of the data to a multiple of
 *							this number
 *	data_alignment_offset	Shift the start of the data area by this addl.
 *							offset
 *	zero					Set to 1 to zero out first 2048 bytes of
 *							device, 0 to not (default is 1)
 *
 * 	\return
 * 	lvm_property_value
 */
struct lvm_property_value lvm_pv_params_get_property(
						const pv_create_params_t params,
						const char *name);

/**
 * Sets a property of a PV parameter create object.
 *
 * \param	params		The parameter object
 * \param	name		The name of the property to set (see get prop list)
 * \param	prop		The property to set the value on.
 */
int lvm_pv_params_set_property(pv_create_params_t params, const char *name,
								struct lvm_property_value *prop);
/**
 * Creates a physical volume using the supplied params object.
 *
 * \param	params		The parameters to use for physical volume creation
 *
 * \return
 * -1 on error, 0 on success.
 */
int lvm_pv_create_adv(pv_create_params_t params);

/**
 *  Remove a physical volume.
 *  Note: You cannot remove a PV while iterating through the list of PVs as
 *  locks are held for the PV list.
 *  \param	libh	Library handle
 *  \param	pv_name	The physical volume name
 *  \return
 *  0 on success, else -1 with library errno and text set.
 */
int lvm_pv_remove(lvm_t libh, const char *pv_name);

/**
 * Return a list of PV handles for a given VG handle.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * A list of lvm_pv_list structures containing pv handles for this vg.
 * If no PVs exist on the given VG, NULL is returned.
 */
struct dm_list *lvm_vg_list_pvs(vg_t vg);

/**
 * Write a VG to disk.
 *
 * \memberof vg_t
 *
 * This function commits the Volume Group object referenced by the VG handle
 * to disk. Upon failure, retry the operation and/or release the VG handle
 * with lvm_vg_close().
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_write(vg_t vg);

/**
 * Remove a VG from the system.
 *
 * \memberof vg_t
 *
 * This function removes a Volume Group object in memory, and requires
 * calling lvm_vg_write() to commit the removal to disk.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_remove(vg_t vg);

/**
 * Close a VG opened with lvm_vg_create or lvm_vg_open().
 *
 * \memberof vg_t
 *
 * This function releases a VG handle and any resources associated with the
 * handle.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_close(vg_t vg);

/**
 * Extend a VG by adding a device.
 *
 * \memberof vg_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully adding a device, use lvm_vg_write() to commit the new VG
 * to disk.  Upon failure, retry the operation or release the VG handle with
 * lvm_vg_close().
 * If the device is not initialized for LVM use, it will be initialized
 * before adding to the VG.  Although some internal checks are done,
 * the caller should be sure the device is not in use by other subsystems
 * before calling lvm_vg_extend().
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   device
 * Absolute pathname of device to add to VG.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_extend(vg_t vg, const char *device);

/**
 * Reduce a VG by removing an unused device.
 *
 * \memberof vg_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully removing a device, use lvm_vg_write() to commit the new VG
 * to disk.  Upon failure, retry the operation or release the VG handle with
 * lvm_vg_close().
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   device
 * Name of device to remove from VG.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_reduce(vg_t vg, const char *device);

/**
 * Add a tag to a VG.
 *
 * \memberof vg_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully adding a tag, use lvm_vg_write() to commit the
 * new VG to disk.  Upon failure, retry the operation or release the VG handle
 * with lvm_vg_close().
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   tag
 * Tag to add to the VG.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_add_tag(vg_t vg, const char *tag);

/**
 * Remove a tag from a VG.
 *
 * \memberof vg_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully removing a tag, use lvm_vg_write() to commit the
 * new VG to disk.  Upon failure, retry the operation or release the VG handle
 * with lvm_vg_close().
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   tag
 * Tag to remove from VG.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_remove_tag(vg_t vg, const char *tag);

/**
 * Set the extent size of a VG.
 *
 * \memberof vg_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully setting a new extent size, use lvm_vg_write() to commit
 * the new VG to disk.  Upon failure, retry the operation or release the VG
 * handle with lvm_vg_close().
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   new_size
 * New extent size in bytes.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_set_extent_size(vg_t vg, uint32_t new_size);

/**
 * Get whether or not a volume group is clustered.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * 1 if the VG is clustered, 0 if not
 */
uint64_t lvm_vg_is_clustered(vg_t vg);

/**
 * Get whether or not a volume group is exported.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * 1 if the VG is exported, 0 if not
 */
uint64_t lvm_vg_is_exported(vg_t vg);

/**
 * Get whether or not a volume group is a partial volume group.
 *
 * \memberof vg_t
 *
 * When one or more physical volumes belonging to the volume group
 * are missing from the system the volume group is a partial volume
 * group.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * 1 if the VG is PVs, 0 if not
 */
uint64_t lvm_vg_is_partial(vg_t vg);

/**
 * Get the current metadata sequence number of a volume group.
 *
 * \memberof vg_t
 *
 * The metadata sequence number is incrented for each metadata change.
 * Applications may use the sequence number to determine if any LVM objects
 * have changed from a prior query.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Metadata sequence number.
 */
uint64_t lvm_vg_get_seqno(const vg_t vg);

/**
 * Get the current uuid of a volume group.
 *
 * \memberof vg_t
 *
 * The memory allocated for the uuid is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Copy of the uuid string.
 */
const char *lvm_vg_get_uuid(const vg_t vg);

/**
 * Get the current name of a volume group.
 *
 * \memberof vg_t
 *
 * The memory allocated for the name is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Copy of the name.
 */
const char *lvm_vg_get_name(const vg_t vg);

/**
 * Get the current size in bytes of a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Size in bytes.
 */
uint64_t lvm_vg_get_size(const vg_t vg);

/**
 * Get the current unallocated space in bytes of a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Free size in bytes.
 */
uint64_t lvm_vg_get_free_size(const vg_t vg);

/**
 * Get the current extent size in bytes of a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Extent size in bytes.
 */
uint64_t lvm_vg_get_extent_size(const vg_t vg);

/**
 * Get the current number of total extents of a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Extent count.
 */
uint64_t lvm_vg_get_extent_count(const vg_t vg);

/**
 * Get the current number of free extents of a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Free extent count.
 */
uint64_t lvm_vg_get_free_extent_count(const vg_t vg);

/**
 * Get the current number of physical volumes of a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Physical volume count.
 */
uint64_t lvm_vg_get_pv_count(const vg_t vg);

/**
 * Get the maximum number of physical volumes allowed in a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Maximum number of physical volumes allowed in a volume group.
 */
uint64_t lvm_vg_get_max_pv(const vg_t vg);

/**
 * Get the maximum number of logical volumes allowed in a volume group.
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \return
 * Maximum number of logical volumes allowed in a volume group.
 */
uint64_t lvm_vg_get_max_lv(const vg_t vg);

/**
 * Return the list of volume group tags.
 *
 * \memberof vg_t
 *
 * The memory allocated for the list is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * To process the list, use the dm_list iterator functions.  For example:
 *      vg_t vg;
 *      struct dm_list *tags;
 *      struct lvm_str_list *strl;
 *
 *      tags = lvm_vg_get_tags(vg);
 *	dm_list_iterate_items(strl, tags) {
 *		tag = strl->str;
 *              // do something with tag
 *      }
 *
 *
 * \return
 * A list with entries of type struct lvm_str_list, containing the
 * tag strings attached to volume group.
 * If no tags are attached to the given VG, an empty list is returned
 * (check with dm_list_empty()).
 * If there is a problem obtaining the list of tags, NULL is returned.
 */
struct dm_list *lvm_vg_get_tags(const vg_t vg);

/**
 * Get the value of a VG property
 *
 * \memberof vg_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   name
 * Name of property to query.  See vgs man page for full list of properties
 * that may be queried.
 *
 * The memory allocated for a string property value is tied to the vg_t
 * handle and will be released when lvm_vg_close() is called.
 *
 * Example:
 *      lvm_property_value v;
 *      char *prop_name = "vg_mda_count";
 *
 *      v = lvm_vg_get_property(vg, prop_name);
 *      if (!v.is_valid) {
 *           printf("Invalid property name or unable to query"
 *                  "'%s', errno = %d.\n", prop_name, lvm_errno(libh));
 *           return;
 *      }
 *      if (v.is_string)
 *           printf(", value = %s\n", v.value.string);
 *	if (v.is_integer)
 *           printf(", value = %"PRIu64"\n", v.value.integer);
 *
 *
 * \return
 * lvm_property_value structure that will contain the current
 * value of the property.  Caller should check 'is_valid' flag before using
 * the value.  If 'is_valid' is not set, caller should check lvm_errno()
 * for specific error.
 */
struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name);

/**
 * Set the value of a VG property.  Note that the property must be
 * a 'settable' property, as evidenced by the 'is_settable' flag
 * when querying the property.
 *
 * \memberof vg_t
 *
 * The memory allocated for a string property value is tied to the vg_t
 * handle and will be released when lvm_vg_close() is called.
 *
 * Example (integer):
 *      lvm_property_value copies;
 *
 *      if (lvm_vg_get_property(vg, "vg_mda_copies", &copies) < 0) {
 *              // Error - unable to query property
 *      }
 *      if (!copies.is_settable) {
 *              // Error - property not settable
 *      }
 *      copies.value.integer = 2;
 *      if (lvm_vg_set_property(vg, "vg_mda_copies", &copies) < 0) {
 *              // handle error
 *      }
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_set_property(const vg_t vg, const char *name,
			struct lvm_property_value *value);

/************************** logical volume handling *************************/

/**
 * Create a linear logical volume.
 * This function commits the change to disk and does _not_ require calling
 * lvm_vg_write().
 * NOTE: The commit behavior of this function is subject to change
 * as the API is developed.
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   name
 * Name of logical volume to create.
 *
 * \param   size
 * Size of logical volume in extents.
 *
 * \return
 * non-NULL handle to an LV object created, or NULL if creation fails.
 *
 */
lv_t lvm_vg_create_lv_linear(vg_t vg, const char *name, uint64_t size);

/**
 * Return a list of lvseg handles for a given LV handle.
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * A list of lvm_lvseg_list structures containing lvseg handles for this lv.
 */
struct dm_list *lvm_lv_list_lvsegs(lv_t lv);

/**
 * Lookup an LV handle in a VG by the LV name.
 *
 * \memberof lv_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   name
 * Name of LV to lookup.
 *
 * \return
 * non-NULL handle to the LV 'name' attached to the VG.
 * NULL is returned if the LV name is not associated with the VG handle.
 */
lv_t lvm_lv_from_name(vg_t vg, const char *name);

/**
 * Lookup an LV handle in a VG by the LV uuid.
 * The form of the uuid may be either the formatted, human-readable form,
 * or the non-formatted form.
 *
 * \memberof lv_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   uuid
 * UUID of LV to lookup.
 *
 * \return
 * non-NULL handle to the LV with 'uuid' attached to the VG.
 * NULL is returned if the LV uuid is not associated with the VG handle.
 */
lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid);

/**
 * Activate a logical volume.
 *
 * \memberof lv_t
 *
 * This function is the equivalent of the lvm command "lvchange -ay".
 *
 * NOTE: This function cannot currently handle LVs with an in-progress pvmove or
 * lvconvert.
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_lv_activate(lv_t lv);

/**
 * Deactivate a logical volume.
 *
 * \memberof lv_t
 *
 * This function is the equivalent of the lvm command "lvchange -an".
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_lv_deactivate(lv_t lv);

/**
 * Remove a logical volume from a volume group.
 *
 * \memberof lv_t
 *
 * This function commits the change to disk and does _not_ require calling
 * lvm_vg_write().
 * NOTE: The commit behavior of this function is subject to change
 * as the API is developed.
 * Currently only removing linear LVs are possible.
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_vg_remove_lv(lv_t lv);

/**
 * Get the current name of a logical volume.
 *
 * \memberof lv_t
 *
 * The memory allocated for the uuid is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * Copy of the uuid string.
 */
const char *lvm_lv_get_uuid(const lv_t lv);

/**
 * Get the current uuid of a logical volume.
 *
 * \memberof lv_t
 *
 * The memory allocated for the name is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * Copy of the name.
 */
const char *lvm_lv_get_name(const lv_t lv);

/**
 * Get the attributes of a logical volume.
 *
 * \memberof lv_t
 *
 * The memory allocated for the name is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * Copy of the attributes for the logical volume
 */
const char *lvm_lv_get_attr(const lv_t lv);

/**
 * Get the origin of a snapshot.
 *
 * \memberof lv_t
 *
 * The memory allocated for the name is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * Null if the logical volume is not a snapshot, else origin name.
 */
const char *lvm_lv_get_origin(const lv_t lv);

/**
 * Get the current size in bytes of a logical volume.
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * Size in bytes.
 */
uint64_t lvm_lv_get_size(const lv_t lv);

/**
 * Get the value of a LV property
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \param   name
 * Name of property to query.  See lvs man page for full list of properties
 * that may be queried.
 *
 * The memory allocated for a string property value is tied to the vg_t
 * handle and will be released when lvm_vg_close() is called.
 *
 * Example:
 *      lvm_property_value v;
 *      char *prop_name = "seg_count";
 *
 *      v = lvm_lv_get_property(lv, prop_name);
 *      if (!v.is_valid) {
 *           printf("Invalid property name or unable to query"
 *                  "'%s', errno = %d.\n", prop_name, lvm_errno(libh));
 *           return;
 *      }
 *      if (v.is_string)
 *           printf(", value = %s\n", v.value.string);
 *	if (v.is_integer)
 *           printf(", value = %"PRIu64"\n", v.value.integer);
 *
 * \return
 * lvm_property_value structure that will contain the current
 * value of the property.  Caller should check 'is_valid' flag before using
 * the value.  If 'is_valid' is not set, caller should check lvm_errno()
 * for specific error.
 */
struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name);

/**
 * Get the value of a LV segment property
 *
 * \memberof lv_t
 *
 * \param   lvseg
 * Logical volume segment handle.
 *
 * \param   name
 * Name of property to query.  See lvs man page for full list of properties
 * that may be queried.
 *
 * The memory allocated for a string property value is tied to the vg_t
 * handle and will be released when lvm_vg_close() is called.
 *
 * Example:
 *      lvm_property_value v;
 *      char *prop_name = "seg_start_pe";
 *
 *      v = lvm_lvseg_get_property(lvseg, prop_name);
 *      if (lvm_errno(libh) || !v.is_valid) {
 *           // handle error
 *           printf("Invalid property name or unable to query"
 *                  "'%s'.\n", prop_name);
 *           return;
 *      }
 *      if (v.is_string)
 *           printf(", value = %s\n", v.value.string);
 *	else
 *           printf(", value = %"PRIu64"\n", v.value.integer);
 *
 * \return
 * lvm_property_value structure that will contain the current
 * value of the property.  Caller should check lvm_errno() as well
 * as 'is_valid' flag before using the value.
 */
struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
						 const char *name);

/**
 * Get the current activation state of a logical volume.
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * 1 if the LV is active in the kernel, 0 if not
 */
uint64_t lvm_lv_is_active(const lv_t lv);

/**
 * Get the current suspended state of a logical volume.
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \return
 * 1 if the LV is suspended in the kernel, 0 if not
 */
uint64_t lvm_lv_is_suspended(const lv_t lv);

/**
 * Add a tag to an LV.
 *
 * \memberof lv_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully adding a tag, use lvm_vg_write() to commit the
 * new VG to disk.  Upon failure, retry the operation or release the VG handle
 * with lvm_vg_close().
 *
 * \param   lv
 * Logical volume handle.
 *
 * \param   tag
 * Tag to add to an LV.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_lv_add_tag(lv_t lv, const char *tag);

/**
 * Remove a tag from an LV.
 *
 * \memberof lv_t
 *
 * This function requires calling lvm_vg_write() to commit the change to disk.
 * After successfully removing a tag, use lvm_vg_write() to commit the
 * new VG to disk.  Upon failure, retry the operation or release the VG handle
 * with lvm_vg_close().
 *
 * \param   lv
 * Logical volume handle.
 *
 * \param   tag
 * Tag to remove from LV.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_lv_remove_tag(lv_t lv, const char *tag);

/**
 * Return the list of logical volume tags.
 *
 * \memberof lv_t
 *
 * The memory allocated for the list is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * To process the list, use the dm_list iterator functions.  For example:
 *      lv_t lv;
 *      struct dm_list *tags;
 *      struct lvm_str_list *strl;
 *
 *      tags = lvm_lv_get_tags(lv);
 *	dm_list_iterate_items(strl, tags) {
 *		tag = strl->str;
 *              // do something with tag
 *      }
 *
 *
 * \return
 * A list with entries of type struct lvm_str_list, containing the
 * tag strings attached to volume group.
 * If no tags are attached to the LV, an empty list is returned
 * (check with dm_list_empty()).
 * If there is a problem obtaining the list of tags, NULL is returned.
 */
struct dm_list *lvm_lv_get_tags(const lv_t lv);

/**
 * Rename logical volume to new_name.
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \param   new_name
 * New name of logical volume.
 *
 * \return
 * 0 (success) or -1 (failure).
 *
 */
int lvm_lv_rename(lv_t lv, const char *new_name);

/**
 * Resize logical volume to new_size bytes.
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \param   new_size
 * New size in bytes.
 *
 * \return
 * 0 (success) or -1 (failure).
 *
 */
int lvm_lv_resize(const lv_t lv, uint64_t new_size);

/**
 * Create a snapshot of a logical volume
 *
 * \memberof lv_t
 *
 * \param   lv
 * Logical volume handle.
 *
 * \param   snap_name
 * Name of the snapshot.
 *
 * \param   max_snap_size
 * Max snapshot space to use. If you pass zero the same amount of space as
 * the origin will be used.
 *
 * \return
 * Valid lv pointer on success, else NULL on error.
 *
 */
lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name, uint64_t max_snap_size);

/**
 * Validate a name to be used for LV creation.
 *
 * Validates that the name does not contain any invalid characters, max length
 * and that the LV name doesn't already exist for this VG.
 *
 * Note: You can have the same LV name in different VGs, thus the reason this
 * function requires that you specify a VG to check against.
 *
 * \param lv
 * Volume group handle.
 *
 * \param name
 * Name to validate
 */
int lvm_lv_name_validate(const vg_t vg, const char *lv_name);

/**
 * Thin provisioning discard policies
 */
typedef enum {
	LVM_THIN_DISCARDS_IGNORE,
	LVM_THIN_DISCARDS_NO_PASSDOWN,
	LVM_THIN_DISCARDS_PASSDOWN,
} lvm_thin_discards_t;

/**
 * Create a thinpool parameter passing object for the specified VG
 *
 * \param   vg
 * Volume Group handle.
 *
 * \param   pool_name
 * Name of the pool.
 *
 * \param   size
 * size of the pool
 *
 * \param   chunk_size
 * data block size of the pool
 * Default value is DEFAULT_THIN_POOL_CHUNK_SIZE * 2 when 0 passed as chunk_size
 * DM_THIN_MIN_DATA_BLOCK_SIZE < chunk_size < DM_THIN_MAX_DATA_BLOCK_SIZE
 *
 * \param meta_size
 * Size of thin pool's metadata logical volume. Allowed range is 2MB-16GB.
 * Default value (ie if 0) pool size / pool chunk size * 64
 *
 * \param discard
 * Thin discard policy
 * Note: THIN_DISCARDS_PASSDOWN is the default.
 *
 * \return
 * Valid lv_create_params pointer on success, else NULL on error.
 * Note: Memory is associated with the vg, it will get reclaimed when vg is
 * closed.
 *
 */
lv_create_params_t lvm_lv_params_create_thin_pool(vg_t vg,
		const char *pool_name, uint64_t size, uint32_t chunk_size,
		uint64_t meta_size, lvm_thin_discards_t discard);

#define lvm_lv_params_create_thin_pool_default(vg, pool_name, size) \
			lvm_lv_params_create_thin_pool((vg), (pool_name), (size), 0, 0, \
			LVM_THIN_DISCARDS_PASSDOWN)

/**
 * Creates the snapshot parameter passing object for the specified lv.
 *
 * \param	lv
 * The logical volume to snapshot
 *
 * \param	snap_name
 * Name of snapshot
 *
 * \param	max_snap_size
 * Used for old snap shots max size, set to zero for thinp
 *
 * \return
 * Valid lv_create_params pointer on success, else NULL on error.
 * Note: Memory is associated with the vg, it will get reclaimed when vg is
 * closed.
 */
lv_create_params_t lvm_lv_params_create_snapshot(const lv_t lv,
													const char *snap_name,
													uint64_t max_snap_size);
/**
 * Get the specific value of a lv create parameter by name
 *
 * \param	params		lv create parameters
 *
 * \param	name		name of parameter
 *
 * \return
 * lvm_property_value structure that will contain the current
 * value of the property.  Caller should check 'is_valid' flag before using
 * the value.  If 'is_valid' is not set, caller should check lvm_errno()
 * for specific error.
 */
struct lvm_property_value lvm_lv_params_get_property(
											const lv_create_params_t params,
											const char *name);


/**
 * Set the specific value of a lv create parameter by name
 *
 * Note that the property must be a 'settable' property, as evidenced '
 * by the 'is_settable' flag when querying the property.
 *
 * The memory allocated for a string property value is tied to the vg_t
 * handle associated with the lv_create_params_t and will be released when
 * lvm_vg_close() is called.
 *
 * \param	params		lv create parameters
 *
 * \param	name		name of parameter
 *
 * \param	prop		Property value to use for setting
 *
 * \return
 * 0 on success, -1 on error.
 */
int lvm_lv_params_set_property(lv_create_params_t params,
								const char *name,
								struct lvm_property_value *prop);

/**
 * Create a thin LV creation parameters in a given VG & thin pool
 *
 * \param   vg
 * Volume Group handle.
 *
 * \param   pool_name
 * Name of the pool.
 *
 * \param lvname
 * Name of the LV to create
 *
 * \param   size
 * Size of logical volume
 *
 * \return
 * Valid lv_create_params pointer on success, else NULL on error.
 * Note: Memory is associated with the vg, it will get reclaimed when vg is
 * closed.
 *
 */
lv_create_params_t lvm_lv_params_create_thin(const vg_t vg, const char *pool_name,
									const char *lvname, uint64_t size);
/**
 * Create the actual logical volume.
 *
 * \param	params		The parameters object for lv creation
 *
 * \return
 * Valid lv pointer on success, else NULL on error.
 */
lv_t lvm_lv_create(lv_create_params_t params);

/************************** physical volume handling ************************/

/**
 * Physical volume handling should not be needed anymore. Only physical volumes
 * bound to a vg contain useful information. Therefore the creation,
 * modification and the removal of orphan physical volumes is not suported.
 */

/**
 * Get the current uuid of a physical volume.
 *
 * \memberof pv_t
 *
 * The memory allocated for the uuid is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * Copy of the uuid string.
 */
const char *lvm_pv_get_uuid(const pv_t pv);

/**
 * Get the current name of a physical volume.
 *
 * \memberof pv_t
 *
 * The memory allocated for the name is tied to the vg_t handle and will be
 * released when lvm_vg_close() is called.
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * Copy of the name.
 */
const char *lvm_pv_get_name(const pv_t pv);

/**
 * Get the current number of metadata areas in the physical volume.
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * Number of metadata areas in the PV.
 */
uint64_t lvm_pv_get_mda_count(const pv_t pv);

/**
 * Get the current size in bytes of a device underlying a
 * physical volume.
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * Size in bytes.
 */
uint64_t lvm_pv_get_dev_size(const pv_t pv);

/**
 * Get the current size in bytes of a physical volume.
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * Size in bytes.
 */
uint64_t lvm_pv_get_size(const pv_t pv);

/**
 * Get the current unallocated space in bytes of a physical volume.
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * Free size in bytes.
 */
uint64_t lvm_pv_get_free(const pv_t pv);

/**
 * Get the value of a PV property
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \param   name
 * Name of property to query.  See pvs man page for full list of properties
 * that may be queried.
 *
 * The memory allocated for a string property value is tied to the vg_t handle
 * and will be released when lvm_vg_close() is called. For "percent" values
 * (those obtained for copy_percent and snap_percent properties), please see
 * dm_percent_range_t and lvm_percent_to_float().
 *
 * Example:
 *      lvm_property_value value;
 *      char *prop_name = "pv_mda_count";
 *
 *      v = lvm_pv_get_property(pv, prop_name);
 *      if (!v.is_valid) {
 *           printf("Invalid property name or unable to query"
 *                  "'%s', errno = %d.\n", prop_name, lvm_errno(libh));
 *           return;
 *      }
 *      if (v.is_string)
 *           printf(", value = %s\n", v.value.string);
 *	if (v.is_integer)
 *           printf(", value = %"PRIu64"\n", v.value.integer);
 *
 * \return
 * lvm_property_value structure that will contain the current
 * value of the property.  Caller should check 'is_valid' flag before using
 * the value.  If 'is_valid' is not set, caller should check lvm_errno()
 * for specific error.
 */
struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name);

/**
 * Get the value of a PV segment property
 *
 * \memberof pv_t
 *
 * \param   pvseg
 * Physical volume segment handle.
 *
 * \param   name
 * Name of property to query.  See pvs man page for full list of properties
 * that may be queried.
 *
 * The memory allocated for a string property value is tied to the vg_t
 * handle and will be released when lvm_vg_close() is called.
 *
 * Example:
 *      lvm_property_value v;
 *      char *prop_name = "pvseg_start";
 *
 *      v = lvm_pvseg_get_property(pvseg, prop_name);
 *      if (lvm_errno(libh) || !v.is_valid) {
 *           // handle error
 *           printf("Invalid property name or unable to query"
 *                  "'%s'.\n", prop_name);
 *           return;
 *      }
 *      if (v.is_string)
 *           printf(", value = %s\n", v.value.string);
 *	else
 *           printf(", value = %"PRIu64"\n", v.value.integer);
 *
 * \return
 * lvm_property_value structure that will contain the current
 * value of the property.  Caller should check lvm_errno() as well
 * as 'is_valid' flag before using the value.
 */
struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
						 const char *name);

/**
 * Return a list of pvseg handles for a given PV handle.
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \return
 * A list of lvm_pvseg_list structures containing pvseg handles for this pv.
 */
struct dm_list *lvm_pv_list_pvsegs(pv_t pv);

/**
 * Lookup an PV handle in a VG by the PV name.
 *
 * \memberof pv_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   name
 * Name of PV to lookup.
 *
 * \return
 * non-NULL handle to the PV 'name' attached to the VG.
 * NULL is returned if the PV name is not associated with the VG handle.
 */
pv_t lvm_pv_from_name(vg_t vg, const char *name);

/**
 * Lookup an PV handle in a VG by the PV uuid.
 * The form of the uuid may be either the formatted, human-readable form,
 * or the non-formatted form.
 *
 * \memberof pv_t
 *
 * \param   vg
 * VG handle obtained from lvm_vg_create() or lvm_vg_open().
 *
 * \param   uuid
 * UUID of PV to lookup.
 *
 * \return
 * non-NULL handle to the PV with 'uuid' attached to the VG.
 * NULL is returned if the PV uuid is not associated with the VG handle.
 */
pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid);

/**
 * Resize physical volume to new_size bytes.
 *
 * \memberof pv_t
 *
 * \param   pv
 * Physical volume handle.
 *
 * \param   new_size
 * New size in bytes.
 *
 * \return
 * 0 (success) or -1 (failure).
 */
int lvm_pv_resize(const pv_t pv, uint64_t new_size);

#define PERCENT_0 DM_PERCENT_0
#define PERCENT_1 DM_PERCENT_1
#define PERCENT_100 DM_PERCENT_100
#define PERCENT_INVALID DM_PERCENT_INVALID
#define PERCENT_MERGE_FAILED DM_PERCENT_FAILED

typedef dm_percent_t percent_t;

/**
 * Convert a (fixed-point) value obtained from the percent-denominated
 * *_get_property functions into a floating-point value.
 */
float lvm_percent_to_float(percent_t v);

#ifdef __cplusplus
}
#endif
#endif /* _LIB_LVM2APP_H */