Loading...
   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
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
.\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
.\"
.\" The contents of this file constitute Original Code as defined in and
.\" are subject to the Apple Public Source License Version 1.1 (the
.\" "License").  You may not use this file except in compliance with the
.\" License.  Please obtain a copy of the License at
.\" http://www.apple.com/publicsource and read it before using this file.
.\"
.\" This Original Code and all software distributed under the License are
.\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
.\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
.\" License for the specific language governing rights and limitations
.\" under the License.
.\"
.\"     @(#)getattrlist.2
.
.Dd March 7, 2025
.Dt GETATTRLIST 2
.Os Darwin
.Sh NAME
.Nm getattrlist ,
.Nm fgetattrlist ,
.Nm getattrlistat
.Nd get file system attributes
.Sh SYNOPSIS
.Fd #include <sys/attr.h>
.Fd #include <unistd.h>
.Ft int
.Fn getattrlist "const char* path" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
.
.Ft int
.Fn fgetattrlist "int fd" "struct attrlist * attrList" "void * attrBuf" "size_t attrBufSize" "unsigned long options"
.Ft int
.Fo getattrlistat
.Fa "int fd" "const char *path" "struct attrlist * attrList" "void * attrBuf"
.Fa "size_t attrBufSize" "unsigned long options"
.Fc
.Sh DESCRIPTION
The
.Fn getattrlist
function returns attributes (that is, metadata) of file system objects.
.Fn getattrlist
works on the file system object named by
.Fa path ,
while
.Fn fgetattrlist
works on the provided file descriptor
.Fa fd .
.Pp
The
.Fn getattrlistat
system call is equivalent to
.Fn getattrlist
except in the case where
.Fa path
specifies a relative path.
In this case the attributes are returned for the file system object named by
path relative to the directory associated with the file descriptor
.Fa fd
instead of the current working directory.
If
.Fn getattrlistat
is passed the special value
.Dv AT_FDCWD
in the
.Fa fd
parameter, the current working directory is used and the behavior is
identical to a call to
.Fn getattrlist .
.Pp
You can think of
.Fn getattrlist
as a seriously enhanced version of
.Xr stat 2 .
The functions return attributes about the specified file system object
into the buffer specified by
.Fa attrBuf
and
.Fa attrBufSize .
The
.Fa attrList
parameter determines what attributes are returned.
The
.Fa options
parameter lets you control specific aspects of the function's behavior.
.Pp
.
Not all volumes support all attributes.
See the discussion of
.Dv ATTR_VOL_ATTRIBUTES
for a discussion of how to determine whether a particular volume supports a
particular attribute.
.Pp
Furthermore, you should only request the attributes that you need.
Some attributes are expensive to calculate on some volume formats.
For example,
.Dv ATTR_DIR_ENTRYCOUNT
is usually expensive to calculate on non-HFS [Plus] volumes.
If you don't need a particular attribute, you should not ask for it.
.Pp
.
.\" path parameter
.
The
.Fa path
parameter must reference a valid file system object.
Read, write or execute permission of the object itself is not required, but
all directories listed in the path name leading to the object must be
searchable.
.Pp
.
.\" attrList parameter
.
The
.Fa attrList
parameter is a pointer to an
.Vt attrlist
structure, as defined by
.Aq Pa sys/attr.h
(shown below).
It determines what attributes are returned by the function.
You are responsible for filling out all fields of this structure before calling the function.
.Bd -literal
typedef u_int32_t attrgroup_t;
.Pp
struct attrlist {
    u_short     bitmapcount; /* number of attr. bit sets in list */
    u_int16_t   reserved;    /* (to maintain 4-byte alignment) */
    attrgroup_t commonattr;  /* common attribute group */
    attrgroup_t volattr;     /* volume attribute group */
    attrgroup_t dirattr;     /* directory attribute group */
    attrgroup_t fileattr;    /* file attribute group */
    attrgroup_t forkattr;    /* fork attribute group */
};
#define ATTR_BIT_MAP_COUNT 5
.Ed
.Pp
.
.\" attrlist elements
.
The fields of the
.Vt attrlist
structure are defined as follows.
.Bl -tag -width XXXbitmapcount
.
.It bitmapcount
Number of attribute bit sets in the structure.
In current systems you must set this to
.Dv ATTR_BIT_MAP_COUNT .
.
.It reserved
Reserved.
You must set this to 0.
.
.It commonattr
A bit set that specifies the common attributes that you require.
Common attributes relate to all types of file system objects.
See below for a description of these attributes.
.
.It volattr
A bit set that specifies the volume attributes that you require.
Volume attributes relate to volumes (that is, mounted file systems).
See below for a description of these attributes.
You must set ATTR_VOL_INFO in the volattr field if you request any 
other volume attributes.
In addition, you can't request volume attributes if you also request
file, directory, fork or extended common attributes.
In addition, you can't request volume attributes if you also request the common 
attributes ATTR_CMN_EXTENDED_SECURITY, ATTR_CMN_UUID, ATTR_CMN_GRPUUID, 
ATTR_CMN_FILEID, or ATTR_CMN_PARENTID.  
.
.It dirattr
A bit set that specifies the directory attributes that you require.
See below for a description of these attributes.
.
.It fileattr
A bit set that specifies the file attributes that you require.
See below for a description of these attributes.
.
.It forkattr
A bit set that specifies the fork attributes that you require.
Fork attributes relate to the actual data in the file,
which can be held in multiple named contiguous ranges, or forks.
See below for a description of these attributes.
If the FSOPT_ATTR_CMN_EXTENDED option is given, this bit set is reinterpreted
as extended common attributes attributes, also described below.
.
.El
.Pp
.
Unless otherwise noted in the lists below, attributes are read-only.
Attributes labelled as read/write can be set using
.Xr setattrlist 2 .
.Pp
.
.\" attrBuf and attrBufSize parameters
.
The
.Fa attrBuf
and
.Fa attrBufSize
parameters specify a buffer into which the function places attribute values.
The format of this buffer is sufficiently complex that its description
requires a separate section (see below).
The initial contents of this buffer are ignored.
.Pp
.
.\" option parameter
.
The
.Fa options
parameter is a bit set that controls the behaviour of
the functions.
The following option bits are defined.
.
.Bl -tag -width FSOPT_ATTR_CMN_EXTENDED
.
.It FSOPT_NOFOLLOW
If this bit is set,
.Fn getattrlist
will not follow a symlink if it occurs as
the last component of
.Fa path .
.
.It FSOPT_NOFOLLOW_ANY
If this bit is set,
.Fn getattrlist
will not follow a symlink if it occurs as
the last component of
.Fa path .
In addition an error is returned if a symlink
is encountered before the last component of
.Fa path .
.
.It FSOPT_RESOLVE_BENEATH
If this bit is set, path resolution must not escape the directory associated
with the file descriptor.
.
.It FSOPT_UNIQUE
If this bit is set, the path lookup will fail if the target file has multiple
hard links.
.
.It FSOPT_REPORT_FULLSIZE
The size of the attributes reported (in the first
.Vt u_int32_t
field in the attribute buffer) will be the size needed to hold all the
requested attributes; if not set, only the attributes actually returned
will be reported.  This allows the caller to determine if any truncation
occurred.
.
.It FSOPT_PACK_INVAL_ATTRS
If this is bit is set, then all requested attributes, even ones that are
not supported by the object or file system, will be returned.  Default values
will be used for the invalid ones.  Requires that
.Dv ATTR_CMN_RETURNED_ATTRS
be requested.
.
.It FSOPT_ATTR_CMN_EXTENDED
If this is bit is set, then
.Dv ATTR_CMN_GEN_COUNT
and
.Dv ATTR_CMN_DOCUMENT_ID
can be requested. When this option is used, forkattrs are reinterpreted as a
set of extended common attributes.
.
.It FSOPT_RETURN_REALDEV
If this is bit is set, then ATTR_CMN_DEVID and ATTR_CMN_FSID will return
the values corresponding to the physical volume they are on. When a
filesystem supports VOL_CAP_INT_VOLUME_GROUPS, it is possible that the
filesystem may return a common logical value for these attributes otherwise.
.
.El
.
.Sh ATTRIBUTE BUFFER
.
The data returned in the buffer described by
.Fa attrBuf
and
.Fa attrBufSize
is formatted as follows.
.Pp
.
.Bl -enum
.
.It
The first element of the buffer is a
.Vt u_int32_t
that contains the overall length, in bytes, of the attributes returned.
This size includes the length field itself.
.
.It
Following the length field is a list of attributes.
Each attribute is represented by a field of its type,
where the type is given as part of the attribute description (below).
.
.It
The attributes are placed into the attribute buffer in the order
that they are described below.
.
.It
Each attribute is aligned to a 4-byte boundary (including 64-bit data types).
.El
.Pp
.
If the attribute is of variable length, it is represented
in the list by an
.Vt attrreference
structure, as defined by
.Aq Pa sys/attr.h
(shown below).
.
.Bd -literal
typedef struct attrreference {
    int32_t        attr_dataoffset;
    u_int32_t      attr_length;
} attrreference_t;
.Ed
.Pp
.
This structure contains a 'pointer' to the variable length attribute data.
The
.Fa attr_length
field is the length of the attribute data (in bytes).
The
.Fa attr_dataoffset
field is the offset in bytes from the
.Vt attrreference
structure
to the attribute data.
This offset will always be a multiple of sizeof(u_int32_t) bytes,
so you can safely access common data types without fear of alignment
exceptions.
.Pp
.
The
.Fn getattrlist
function will silently truncate attribute data if
.Fa attrBufSize
is too small.
The length field at the front of the attribute list always represents
the length of the data actually copied into the attribute buffer.
If the data is truncated, there is no easy way to determine the
buffer size that's required to get all of the requested attributes.
You should always pass an
.Fa attrBufSize
that is large enough to accommodate the known size of the attributes
in the attribute list (including the leading length field).
.Pp
.
Because the returned attributes are simply truncated if the buffer is
too small, it's possible for a variable length attribute to reference
data beyond the end of the attribute buffer.  That is, it's possible
for the attribute data to start beyond the end of the attribute buffer
(that is, if
.Fa attrRef
is a pointer to the
.Vt attrreference_t ,
( ( (char *)
.Fa attrRef
) +
.Fa attr_dataoffset
) > ( ( (char *)
.Fa attrBuf
) +
.Fa attrSize
) ) or, indeed, for the attribute data to extend beyond the end of the attribute buffer (that is,
( ( (char *)
.Fa attrRef
) +
.Fa attr_dataoffset
+
.Fa attr_length
) > ( ( (char *)
.Fa attrBuf
) +
.Fa attrSize
) ).
If this happens you must increase the size of the buffer and call
.Fn getattrlist
to get an accurate copy of the attribute.
.
.Sh COMMON ATTRIBUTES
.
Common attributes relate to all types of file system objects.
The following common attributes are defined.
.
.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
.
.It ATTR_CMN_RETURNED_ATTRS
An
.Vt attribute_set_t
structure which is used to report which of the requested attributes
were actually returned. This attribute, when requested, will always
be the first attribute returned. By default, unsupported attributes
will be skipped (i.e. not packed into the output buffer). This behavior
can be over-ridden using the FSOPT_PACK_INVAL_ATTRS option flag. Both
.Xr getattrlist 2 and
.Xr getattrlistbulk 2 support this attribute while
.Xr searchfs 2 does not.
.
.It ATTR_CMN_NAME
An
.Vt attrreference
structure containing the name of the file system object as
UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv NAME_MAX
+ 1 characters, which is
.Dv NAME_MAX
* 3 + 1 bytes (as one UTF-8-encoded character may
take up to three bytes).
.Pp
.
.It ATTR_CMN_DEVID
A
.Vt dev_t
containing the device number of the device on which this
file system object's volume is mounted.
Equivalent to the
.Fa st_dev
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_FSID
An
.Vt fsid_t
structure containing the file system identifier for the volume on which
the file system object resides.
Equivalent to the
.Fa f_fsid
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_CMN_OBJTYPE
An
.Vt fsobj_type_t
that identifies the type of file system object.
The values are taken from
.Vt enum vtype
in
.Aq Pa sys/vnode.h .
.
.It ATTR_CMN_OBJTAG
An
.Vt fsobj_tag_t
that identifies the type of file system containing the object.
The values are taken from
.Vt enum vtagtype
in
.Aq Pa sys/vnode.h .
.
.It ATTR_CMN_OBJID
An
.Vt fsobj_id_t
structure that uniquely identifies the file system object within a mounted 
volume for the duration of its mount; this identifier is not guaranteed to be 
persistent for the volume and may change every time the volume is mounted.
.Pp
On HFS+ volumes, the ATTR_CMN_OBJID of a file system object is distinct from 
the ATTR_CMN_OBJID of any hard link to that file system object. Although the 
ATTR_CMN_OBJID of a file system object may appear similar (in whole
or in part) to it's ATTR_CMN_FILEID (see description of ATTR_CMN_FILEID below), 
\fBno relation between the two attributes should ever be implied.\fP
.Pp
ATTR_CMN_OBJID is deprecated starting with macOS 10.13, iOS 11.0, watchOS 4.0 and
tvOS 11.0 and ATTR_CMNEXT_LINKID should be used in its place.
ATTR_CMN_OBJID can only be used on older operating systems only if the file
system doesn't 64 bit IDs. See the
.Fn getLinkIDInfo
function in the EXAMPLES section.
.
.It ATTR_CMN_OBJPERMANENTID
An
.Vt fsobj_id_t
structure that uniquely and persistently identifies the file system object
within its volume; persistence implies that this attribute is unaffected by
mount/unmount operations on the volume.
.Pp
Some file systems can not return this attribute when the volume is mounted
read-only and will fail the request with error
.Dv EROFS.
.br
(e.g. original HFS modifies on disk structures to generate persistent
identifiers, and hence cannot do so if the volume is mounted read only.)
.
.It ATTR_CMN_PAROBJID
An
.Vt fsobj_id_t
structure that uniquely identifies the parent directory of the file system
object within a mounted volume, for the duration of the volume mount; this 
identifier is not guaranteed to be persistent for the volume and may change 
every time the volume is mounted.
.Pp
.
If a file system object is hard linked from multiple directories, the parent
directory returned for this attribute is non deterministic; it can be any one
of the parent directories of this object.
.
For some volume formats the computing cost for this attribute is significant; 
developers are advised to request this attribute sparingly.
.
.It ATTR_CMN_SCRIPT
(read/write) A
.Vt text_encoding_t
containing a text encoding hint for
the file system object's name.
It is included to facilitate the lossless round trip conversion of names between
Unicode and traditional Mac OS script encodings.
File systems that do not have an appropriate text encoding value should return
kTextEncodingMacUnicode.
.
.It ATTR_CMN_CRTIME
(read/write) A
.Vt timespec
structure containing the time that the file system object
was created.
.
.It ATTR_CMN_MODTIME
(read/write) A
.Vt timespec
structure containing the time that the file system object
was last modified.
Equivalent to the
.Fa st_mtimespec
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_CHGTIME
A
.Vt timespec
structure containing the time that the file system object's
attributes were last modified.
Equivalent to the
.Fa st_ctimespec
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_ACCTIME
(read/write) A
.Vt timespec
structure containing the time that the file system object
was last accessed.
Equivalent to the
.Fa st_atimespec
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_BKUPTIME
(read/write) A
.Vt timespec
structure containing the time that the file system object was
last backed up.
This value is for use by backup utilities.
The file system stores but does not interpret the value.
.
.It ATTR_CMN_FNDRINFO
(read/write) 32 bytes of data for use by the Finder.
Equivalent to the concatenation of a
.Vt FileInfo
structure and an
.Vt ExtendedFileInfo
structure
(or, for directories, a
.Vt FolderInfo
structure and an
.Vt ExtendedFolderInfo
structure).
.Pp
This attribute is not byte swapped by the file system.
The value of multibyte fields on disk is always big endian.
When running on a little endian system (such as Darwin on x86),
you must byte swap any multibyte fields.
.
.It ATTR_CMN_OWNERID
(read/write) A
.Vt uid_t
containing the owner of the file system object.
Equivalent to the
.Fa st_uid
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_GRPID
(read/write) A
.Vt gid_t
containing the group of the file system object.
Equivalent to the
.Fa st_gid
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_ACCESSMASK
(read/write) A
.Vt u_int32_t
containing the access permissions of the file system object.
Equivalent to the
.Fa st_mode
field of the
.Vt stat
structure returned by
.Xr stat 2 .
Only the permission bits of
.Fa st_mode
are valid; other bits should be ignored,
e.g., by masking with
.Dv ~S_IFMT .
.
.It ATTR_CMN_FLAGS
(read/write) A
.Vt u_int32_t
containing file flags.
Equivalent to the
.Fa st_flags
field of the
.Vt stat
structure returned by
.Xr stat 2 .
For more information about these flags, see
.Xr chflags 2 .
.
.It ATTR_CMN_GEN_COUNT
A
.Vt u_int32_t
containing a non zero monotonically increasing generation
count for this file system object. The generation count tracks
the number of times the data in a file system object has been 
modified. No meaning can be implied from its value. The
value of the generation count for a file system object can 
be compared against a previous value of the same file system
object for equality; i.e. an unchanged generation 
count indicates identical data. Requesting this attribute requires the
FSOPT_ATTR_CMN_EXTENDED option flag.
.Pp
.
A generation count value of 0 is invalid and cannot be used to 
determine data change.
.Pp
The generation count is invalid while a file is mmap'ed. An invalid 
generation count value of 0 will be returned for mmap'ed files.
.
.It ATTR_CMN_DOCUMENT_ID
A
.Vt u_int32_t
containing the document id. The document id is a value assigned
by the kernel to a document (which can be a file or directory)
and is used to track the data regardless of where it gets moved. 
The document id survives safe saves; i.e it is sticky to the path it 
was assigned to. Requesting this attribute requires the
FSOPT_ATTR_CMN_EXTENDED option flag.
.Pp
A document id of 0 is invalid.
.
.It ATTR_CMN_USERACCESS
A
.Vt u_int32_t
containing the effective permissions of the current user
(the calling process's effective UID) for this file system object.
You can test for read, write, and execute permission using
.Dv R_OK ,
.Dv W_OK ,
and
.Dv X_OK ,
respectively.
See
.Xr access 2
for more details.
.
.It ATTR_CMN_EXTENDED_SECURITY
A variable-length object (thus an
.Vt attrreference
structure) containing a
.Vt kauth_filesec
structure, of which only the ACL entry is used.
.
.It ATTR_CMN_UUID
A
.Vt guid_t
of the owner of the file system object.  Analogous to
.Dv ATTR_CMN_OWNERID .
.
.It ATTR_CMN_GRPUUID
A
.Vt guid_t
of the group to which the file system object belongs.
Analoguous to
.Dv ATTR_CMN_GRPID .
.
.It ATTR_CMN_FILEID
A
.Vt u_int64_t
that uniquely identifies the file system object within its mounted volume.
Equivalent to 
.Fa st_ino
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMN_PARENTID
A
.Vt u_int64_t
that identifies the parent directory of the file system object.
.
.It ATTR_CMN_FULLPATH
An
.Vt attrreference
structure containing the full path (resolving all symlinks) to 
the file system object as
a UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv PATH_MAX. 
Inconsistent behavior may be observed when this attribute is requested on
hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
natively. Callers should be aware of this when requesting the full path of a hard-linked item.
.
.It ATTR_CMN_ADDEDTIME
A
.Vt timespec
that contains the time that the file system object was created or renamed into
its containing directory.  Note that inconsistent behavior may be observed
when this attribute is requested on hard-linked items. 
.
.It ATTR_CMN_DATA_PROTECT_FLAGS
A
.Vt u_int32_t
that contains the file or directory's data protection class.
.Pp
.
.El
.
.Sh VOLUME ATTRIBUTES
.
Volume attributes relate to volumes (that is, mounted file systems).
The following volume attributes are defined.
.
.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
.
.It ATTR_VOL_INFO
For historical reasons you must set
.Dv ATTR_VOL_INFO
in the
.Fa volattr
field if you request any other volume attributes.
.
.It ATTR_VOL_FSTYPE
A
.Vt u_int32_t
containing the file system type.
Equivalent to the
.Fa f_type
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
Generally not a useful value.
.
.It ATTR_VOL_SIGNATURE
A
.Vt u_int32_t
containing the volume signature word.
This value is unique within a given file system type and lets you
distinguish between different volume formats handled by the same file system.
.
.It ATTR_VOL_SIZE
An
.Vt off_t
containing the total size of the volume in bytes.
.
.It ATTR_VOL_SPACEFREE
An
.Vt off_t
containing the free space on the volume in bytes.
.
.It ATTR_VOL_SPACEAVAIL
An
.Vt off_t
containing the space, in bytes, on the volume available to non-privileged processes.
This is the free space minus the amount of space reserved by the system to prevent critical
disk exhaustion errors.
Non-privileged programs, like a disk management tool, should use this value to display the
space available to the user.
.Pp
.Dv ATTR_VOL_SPACEAVAIL
is to
.Dv ATTR_VOL_SPACEFREE
as
.Fa f_bavail
is to
.Fa f_bfree
in
.Xr statfs 2 .
.
.It ATTR_VOL_SPACEUSED
An
.Vt off_t
containing the total space used on the volume in bytes.
On space sharing volumes, this value may not be identical to the difference
between the volume's size and its free space.
.
.It ATTR_VOL_MINALLOCATION
An
.Vt off_t
containing the minimum allocation size on the volume in bytes.
If you create a file containing one byte, it will consume this much space.
.
.It ATTR_VOL_ALLOCATIONCLUMP
An
.Vt off_t
containing the allocation clump size on the volume, in bytes.
As a file is extended, the file system will attempt to allocate
this much space each time in order to reduce fragmentation.
.
.It ATTR_VOL_IOBLOCKSIZE
A
.Vt u_int32_t
containing the optimal block size when reading or writing data.
Equivalent to the
.Fa f_iosize
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_VOL_OBJCOUNT
A
.Vt u_int32_t
containing the number of file system objects on the volume.
.
.It ATTR_VOL_FILECOUNT
A
.Vt u_int32_t
containing the number of files on the volume.
.
.It ATTR_VOL_DIRCOUNT
A
.Vt u_int32_t
containing the number of directories on the volume.
.
.It ATTR_VOL_MAXOBJCOUNT
A
.Vt u_int32_t
containing the maximum number of file system objects that can be stored on the volume.
.
.It ATTR_VOL_MOUNTPOINT
An
.Vt attrreference
structure containing the path to the volume's mount point as a
UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv MAXPATHLEN .
Equivalent to the
.Fa f_mntonname
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_VOL_NAME
(read/write) An
.Vt attrreference
structure containing the name of the volume as a
UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv NAME_MAX +
1.
.Pp
.
This attribute is only read/write if the
.Dv VOL_CAP_INT_VOL_RENAME
bit is set in the volume capabilities (see below).
.Pp
.
.It ATTR_VOL_MOUNTFLAGS
A
.Vt u_int32_t
containing the volume mount flags.
This is a copy of the value passed to the
.Fa flags
parameter of
.Xr mount 2
when the volume was mounted.
Equivalent to the
.Fa f_flags
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_VOL_MOUNTEDDEVICE
An
.Vt attrreference
structure that returns the same value as the
.Fa f_mntfromname
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
For local volumes this is the path to the device on which the volume is mounted as a
UTF-8 encoded, null terminated C string.
For network volumes, this is a unique string that identifies the mount.
The attribute data length will not be greater than
.Dv MAXPATHLEN .
.Pp
.
.It ATTR_VOL_ENCODINGSUSED
An
.Vt unsigned long long
containing a bitmap of the text encodings used on this volume.
For more information about this, see the discussion of
.Fa encodingsBitmap
in DTS Technote 1150 "HFS Plus Volume Format".
.
.It ATTR_VOL_CAPABILITIES
A
.Vt vol_capabilities_attr_t
structure describing the optional features supported by this volume.
See below for a discussion of volume capabilities.
.
.It ATTR_VOL_UUID
A
.Vt uuid_t
containing the file system UUID.  Typically this will be a
version 5 UUID.
.
.It ATTR_VOL_MOUNTEXTFLAGS
A
.Vt u_int32_t
containing the volume extended mount flags.
Equivalent to the
.Fa f_flags_ext
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_VOL_QUOTA_SIZE
An
.Vt off_t
containing the maximum size of the volume in bytes.
.
.It ATTR_VOL_RESERVED_SIZE
An
.Vt off_t
containing the minimum size of the volume in bytes.
.
.It ATTR_VOL_ATTRIBUTES
A
.Vt vol_attributes_attr_t
structure describing the attributes supported by this volume.
This structure is discussed below, along with volume capabilities.
.
.It ATTR_VOL_FSTYPENAME
An
.Vt attrreference
structure containing the file system type name as a
UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv MFSTYPENAMELEN .
.
.It ATTR_VOL_FSSUBTYPE
A
.Vt u_int32_t
containing the file system sub-type.
Equivalent to the
.Fa f_fssubtype
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_VOL_OWNER
A
.Vt uid_t
containing the user that mounted the filesystem.
Equivalent to the
.Fa f_owner
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.El
.
.Sh DIRECTORY ATTRIBUTES
.
The following directory attributes are defined.
.
.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
.
.It ATTR_DIR_LINKCOUNT
A
.Vt u_int32_t
containing the number of hard links to the directory;
this does not include the historical "." and ".." entries.
For file systems that do not support hard links to directories,
this value will be 1.
.
.It ATTR_DIR_ENTRYCOUNT
A
.Vt u_int32_t
containing the number of file system objects in the directory, not including
any synthetic items.  The historical "." and ".." entries are also
excluded from this count.
.
.It ATTR_DIR_MOUNTSTATUS
A
.Vt u_int32_t
containing flags describing what's mounted on the directory.
Currently the only flag defined is
.Dv DIR_MNTSTATUS_MNTPOINT,
which indicates that there is a file system mounted on this directory.
.
.It ATTR_DIR_ALLOCSIZE
An
.Vt off_t
containing the number of bytes on disk used by the directory
(the physical size).
.
.It ATTR_DIR_IOBLOCKSIZE
A
.Vt u_int32_t
containing the optimal block size when reading or writing data.
.
.It ATTR_DIR_DATALENGTH
An
.Vt off_t
containing the length of the directory in bytes (the logical size).
.El
.
.Pp
Requested directory attributes are not returned for file system objects that
are not directories.
.
.Sh FILE ATTRIBUTES
.
The following file attributes are defined.
.
.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
.
.It ATTR_FILE_LINKCOUNT
A
.Vt u_int32_t
containing the number of hard links to this file.
Equivalent to the
.Fa st_nlink
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_FILE_TOTALSIZE
An
.Vt off_t
containing the total number of bytes in all forks of the file (the logical size).
.
.It ATTR_FILE_ALLOCSIZE
An
.Vt off_t
containing a count of the bytes on disk used by all of the file's forks (the physical size).
.
.It ATTR_FILE_IOBLOCKSIZE
A
.Vt u_int32_t
containing the optimal block size when reading or writing this file's data.
.
.It ATTR_FILE_CLUMPSIZE
A
.Vt u_int32_t
containing the allocation clump size for this file, in bytes.
As the file is extended, the file system will attempt to allocate
this much space each time in order to reduce fragmentation.
This value applies to the data fork.
.
.It ATTR_FILE_DEVTYPE
(read/write) A
.Vt u_int32_t
containing the device type for a special device file.
Equivalent to the
.Fa st_rdev
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_FILE_FILETYPE
A
.Vt u_int32_t
that whose value is reserved.
Clients should ignore its value.
New volume format implementations should not support this attribute.
.
.It ATTR_FILE_FORKCOUNT
A
.Vt u_int32_t
containing the number of forks in the file.
No built-in file systems on Mac OS X currently support forks other
than the data and resource fork.
.
.It ATTR_FILE_FORKLIST
An
.Vt attrreference
structure containing a list of named forks of the file.
No built-in file systems on Mac OS X currently support forks
other than the data and resource fork.
Because of this, the structure of this attribute's value is not yet defined.
.
.It ATTR_FILE_DATALENGTH
An
.Vt off_t
containing the length of the data fork in bytes (the logical size).
.
.It ATTR_FILE_DATAALLOCSIZE
An
.Vt off_t
containing a count of the bytes on disk used by the data fork (the physical size).
.
.It ATTR_FILE_DATAEXTENTS
An
.Vt extentrecord
array for the data fork.
The array contains eight
.Vt diskextent
structures which represent the first
eight extents of the fork.
.Pp
This attributes exists for compatibility reasons.
New clients should not use this attribute.
Rather, they should use the
.Dv F_LOG2PHYS
command in
.Xr fcntl 2 .
.Pp
.
In current implementations the value may not be entirely accurate for
a variety of reasons.
.
.It ATTR_FILE_RSRCLENGTH
An
.Vt off_t
containing the length of the resource fork in bytes (the logical size).
.
.It ATTR_FILE_RSRCALLOCSIZE
An
.Vt off_t
containing a count of the bytes on disk used by the resource fork (the physical size).
.
.It ATTR_FILE_RSRCEXTENTS
An
.Vt extentrecord
array for the resource fork.
The array contains eight
.Vt diskextent
structures which represent the first
eight extents of the fork.
.Pp
See also
.Dv ATTR_FILE_DATAEXTENTS .
.
.El
.
.Pp
File attributes are used for any file system object that is not a directory,
not just ordinary files.
Requested file attributes are not returned for file system objects that
are directories.
.
.Sh FORK ATTRIBUTES
.
Fork attributes relate to the actual data in the file,
which can be held in multiple named contiguous ranges, or forks.
These cannot be used if the FSOPT_ATTR_CMN_EXTENDED is given.
The following fork attributes are defined.
.
.Bl -tag -width ATTR_VOL_ALLOCATIONCLUMP
.
.It ATTR_FORK_TOTALSIZE
Deprecated.
An
.Vt off_t
containing the length of the fork in bytes (the logical size).
.
.It ATTR_FORK_ALLOCSIZE
Deprecated.
An
.Vt off_t
containing a count of the bytes on disk used by the fork (the physical size).
.
.It ATTR_FORK_RESERVED
Reserved.
You must set this to 0.
.
.El
.Pp
.
Fork attributes are deprecated and all bits are reserved.
They are not properly implemented by any current Mac OS X
volume format implementation.
We strongly recommend that client programs do not request fork attributes.
If you are implementing a volume format, you should not support these attributes.
.
.Sh COMMON EXTENDED ATTRIBUTES
.
Common extended attributes are like common attributes except that they are set
in the forkattr field and can only be used if the FSOPT_ATTR_CMN_EXTENDED
option is given. Use of these attributes is mutually exclusive with the above
fork attributes.
.
.Bl -tag -width ATTR_CMNEXT_RECURSIVE_GENCOUNT
.
.It ATTR_CMNEXT_RELPATH
An
.Vt attrreference
structure containing the mount-relative path of
the file system object as
a UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv PATH_MAX.
Inconsistent behavior may be observed when this attribute is requested on
hard-linked items, particularly when the file system does not support
ATTR_CMN_PARENTID natively. Callers should be aware of this when requesting the
relative path of a hard-linked item.
.
.It ATTR_CMNEXT_PRIVATESIZE
An
.Vt off_t
containing the number of bytes that are \fBnot\fP trapped inside a clone
or snapshot, and which would be freed immediately if the file were deleted.
.
.It ATTR_CMNEXT_LINKID
A
.Vt u_int64_t
that uniquely identifies the file system object within a mounted volume for the
duration of its mount. This identifier is persistent on volumes that support the
VOL_CAP_FMT_PERSISTENTOBJECTIDS capability, such as HFS+ and APFS.
.Pp
On HFS+ and APFS volumes, the ATTR_CMNEXT_LINKID of a file system
object is distinct from the ATTR_CMNEXT_LINKID of any hard link to that file
system object. Although the ATTR_CMNEXT_LINKID of a file system object may appear
similar (in whole or in part) to its ATTR_CMN_FILEID (see description of
ATTR_CMN_FILEID above), \fBno relation between the two attributes should ever be implied.\fP
.
.It ATTR_CMNEXT_NOFIRMLINKPATH
An
.Vt attrreference
structure containing a path that does not have firmlinks of
the file system object as
a UTF-8 encoded, null terminated C string.
The attribute data length will not be greater than
.Dv PATH_MAX.
Inconsistent behavior may be observed when this attribute is requested on
hard-linked items, particularly when the file system does not support
ATTR_CMN_PARENTID natively. Callers should be aware of this when requesting the
canonical path of a hard-linked item.
.It ATTR_CMNEXT_REALDEVID
A
.Vt dev_t
containing the real device number of the device on which this
file system object's volume is mounted.
Equivalent to the
.Fa st_dev
field of the
.Vt stat
structure returned by
.Xr stat 2 .
.
.It ATTR_CMNEXT_REALFSID
An
.Vt fsid_t
structure containing the real file system identifier for the volume on which
the file system object resides.
Equivalent to the
.Fa f_fsid
field of the
.Vt statfs
structure returned by
.Xr statfs 2 .
.
.It ATTR_CMNEXT_CLONEID
A
.Vt u_int64_t
that uniquely identifies the data stream associated with the file
system object.  Useful for finding which files are pure clones of each
other (as they will have the same clone-id).
.
.It ATTR_CMNEXT_EXT_FLAGS
A
.Vt u_int64_t
that contains additional flags with information about the file.  The
flags are:
.
.Bl -tag -width EF_SHARES_ALL_BLOCKS
.
.It EF_MAY_SHARE_BLOCKS
If this bit is set then the file may share blocks with another file
(i.e. it may be a clone of another file).
.
.It EF_NO_XATTRS
If this bit is set then the file has no extended attributes.  Useful
for avoiding a call to listxattr().
.
.It EF_IS_SYNC_ROOT
If this bit is set the directory is a "sync root".  This bit will
never be set for regular files.
.
.It EF_IS_PURGEABLE
If this bit is set the item is a "purgeable" item that can be deleted
by the file system when asked to free space.
.
.It EF_IS_SPARSE
If this bit is set the item has sparse regions.
.
.It EF_IS_SYNTHETIC
If this bit is set the item is a synthetic directory/symlink.
.
.It EF_SHARES_ALL_BLOCKS
If this bit is set then the file shares all of its blocks with another
file (i.e. it is a full clone of another file). For compatibility reasons,
EF_SHARES_ALL_BLOCKS means EF_MAY_SHARE_BLOCKS as well.
.
.El
.
.It ATTR_CMNEXT_RECURSIVE_GENCOUNT
A
.Vt u_int64_t
that represents the recursive generation count of a directory that has
been marked as maintain-dir-stats in an apfs file system.  This
gencount is updated any time any child is modified (as part of the
contract that a maintain-dir-stats directory manages).  If the
directory is not marked maintain-dir-stats, a zero is returned.
.
.It ATTR_CMNEXT_ATTRIBUTION_TAG
An optional
.Vt u_int64_t
id that represents the bundle id (owner) associated with the file
(zero means the file isn't attributed yet)
.
.It ATTR_CMNEXT_CLONE_REFCNT
A
.Vt u_int32_t
that represents the number of full clones
(each shares all of its blocks with this file).
.
.El
.Pp
.
.Sh VOLUME CAPABILITIES
.
.\" vol_capabilities_attr_t
.
Not all volumes support all features.
The
.Dv ATTR_VOL_CAPABILITIES
attribute returns a
.Vt vol_capabilities_attr_t
structure (shown below) that indicates which features are supported by the volume.
.
.Bd -literal
typedef u_int32_t vol_capabilities_set_t[4];
.Pp
.
#define VOL_CAPABILITIES_FORMAT     0
#define VOL_CAPABILITIES_INTERFACES 1
#define VOL_CAPABILITIES_RESERVED1  2
#define VOL_CAPABILITIES_RESERVED2  3
.Pp
.
typedef struct vol_capabilities_attr {
    vol_capabilities_set_t capabilities;
    vol_capabilities_set_t valid;
} vol_capabilities_attr_t;
.Ed
.Pp
.
The structure contains two fields,
.Fa capabilities
and
.Fa valid .
Each consists of an array of four elements.
The arrays are indexed by the following values.
.
.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
.
.It VOL_CAPABILITIES_FORMAT
This element contains information about the volume format.
See
.Dv VOL_CAP_FMT_PERSISTENTOBJECTIDS
and so on, below.
.
.It VOL_CAPABILITIES_INTERFACES
This element contains information about which optional functions are
supported by the volume format implementation.
See
.Dv VOL_CAP_INT_SEARCHFS
and so on, below.
.
.It VOL_CAPABILITIES_RESERVED1
Reserved.
A file system implementation should set this element to zero.
A client program should ignore this element.
.
.It VOL_CAPABILITIES_RESERVED2
Reserved.
A file system implementation should set this element to zero.
A client program should ignore this element.
.
.El
.Pp
.
The
.Fa valid
field contains bit sets that indicate which flags are known to the volume format
implementation.
Each bit indicates whether the contents of the corresponding bit in the
.Fa capabilities
field is valid.
.Pp
.
The
.Fa capabilities
field contains bit sets that indicate whether a particular feature is implemented
by this volume format.
.Pp
.
The following bits are defined in the first element (indexed by
.Dv VOL_CAPABILITIES_FORMAT )
of the
.Fa capabilities
and
.Fa valid
fields of the
.Vt vol_capabilities_attr_t
structure.
.
.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
.
.It VOL_CAP_FMT_PERSISTENTOBJECTIDS
If this bit is set the volume format supports persistent object identifiers
and can look up file system objects by their IDs.
See
.Dv ATTR_CMN_OBJPERMANENTID
for details about how to obtain these identifiers.
.
.It VOL_CAP_FMT_SYMBOLICLINKS
If this bit is set the volume format supports symbolic links.
.
.It VOL_CAP_FMT_HARDLINKS
If this bit is set the volume format supports hard links.
.
.It VOL_CAP_FMT_JOURNAL
If this bit is set the volume format supports a journal used to
speed recovery in case of unplanned restart (such as a power outage
or crash).
This does not necessarily mean the volume is actively using a journal.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_JOURNAL_ACTIVE
If this bit is set the volume is currently using a journal for
speedy recovery after an unplanned restart.
This bit can be set only if
.Dv VOL_CAP_FMT_JOURNAL
is also set.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_NO_ROOT_TIMES
If this bit is set the volume format does not store reliable times for
the root directory, so you should not depend on them to detect changes,
identify volumes across unmount/mount, and so on.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_SPARSE_FILES
If this bit is set the volume format supports sparse files,
that is, files which can have 'holes' that have never been written
to, and thus do not consume space on disk.
A sparse file may have an allocated size on disk that is less than its logical length (that is,
.Dv ATTR_FILE_ALLOCSIZE
<
.Dv ATTR_FILE_TOTALSIZE ).
.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_ZERO_RUNS
For security reasons, parts of a file (runs) that have never been
written to must appear to contain zeroes.
When this bit is set, the volume keeps track of allocated but unwritten
runs of a file so that it can substitute zeroes without actually
writing zeroes to the media.
This provides performance similar to sparse files, but not the space savings.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_CASE_SENSITIVE
If this bit is set the volume format treats upper and lower case
characters in file and directory names as different.
Otherwise an upper case character is equivalent to a lower case character,
and you can't have two names that differ solely in the case of
the characters.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_CASE_PRESERVING
If this bit is set the volume format preserves the case of
file and directory names.
Otherwise the volume may change the case of some characters
(typically making them all upper or all lower case).
A volume that sets
.Dv VOL_CAP_FMT_CASE_SENSITIVE
must also set
.Dv VOL_CAP_FMT_CASE_PRESERVING .
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_FAST_STATFS
This bit is used as a hint to upper layers to
indicate that
.Xr statfs 2
is fast enough that its results need not be cached by the caller.
A volume format implementation that caches the
.Xr statfs 2
information in memory should set this bit.
An implementation that must always read from disk or always perform a network
transaction to satisfy
.Xr statfs 2
should not set this bit.
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_FMT_2TB_FILESIZE
If this bit is set the volume format supports file sizes larger
than 4GB, and potentially up to 2TB; it does not indicate
whether the file system supports files larger than that.
.Pp
Introduced with Darwin 8.0 (Mac OS X version 10.4).
.
.It VOL_CAP_FMT_OPENDENYMODES
If this bit is set, the volume format supports open deny modes
(e.g., "open for read write, deny write").
.
.It VOL_CAP_FMT_HIDDEN_FILES
If this bit is set, the volume format supports the
.Dv UF_HIDDEN
file flag, and the
.Dv UF_HIDDEN
flag is mapped to that volume's native "hidden" or "invisible"
bit (e.g., the invisible bit from the Finder Info extended attribute).
.
.It VOL_CAP_FMT_PATH_FROM_ID
If this bit is set, the volume format supports the ability to derive a pathname
to the root of the file system given only the ID of an object.  This also
implies that object IDs on this file system are persistent and not recycled.
Most file systems will not support this capability.
.
.It VOL_CAP_FMT_NO_VOLUME_SIZES
If this bit is set the volume format does not support 
determining values for total data blocks, available blocks, or free blocks, as in 
.Fa f_blocks,
.Fa f_bavail,
and 
.Fa f_bfree
in the 
.Fa struct statfs
returned by
.Xr statfs 2 . 
Historically, those values were set to 0xFFFFFFFF for volumes 
that did not support them.
.Pp
Introduced with Darwin 10.0 (Mac OS X version 10.6).
.
.It VOL_CAP_FMT_64BIT_OBJECT_IDS
If this bit is set, the volume format uses object IDs that are 64-bit. 
This means that ATTR_CMN_FILEID and ATTR_CMN_PARENTID are the primary means of
obtaining object IDs from this volume. The values returned by ATTR_CMN_OBJID,
ATTR_CMN_OBJPERMANENTID, and ATTR_CMN_PAROBJID can be interpreted as 64-bit
object IDs instead of fsobj_id_t.
.
.It VOL_CAP_FMT_DOCUMENT_ID
If this bit is set, the volume format supports document IDs
(an ID which persists across object ID changes) for document revisions.
.It VOL_CAP_FMT_NO_IMMUTABLE_FILES
If this bit is set, the volume format does not support setting the UF_IMMUTABLE
flag.
See ATTR_CMN_FLAGS for more details.
.It VOL_CAP_FMT_NO_PERMISSIONS
If this bit is set, the volume format does not support setting file
permissions.
See ATTR_CMN_USERACCESS for more details.
.It VOL_CAP_FMT_SHARED_SPACE
If this bit is set, the volume format supports having multiple logical filesystems
in a single "partition" which share space.
.It VOL_CAP_FMT_VOL_GROUPS
If this bit is set, the volume format supports having multiple logical filesystems
which may be mounted and unmounted together and may present common filesystem
identifier information.
.It VOL_CAP_FMT_SEALED
If this bit is set, the volume is cryptographically sealed and any modifications
may render the volume unusable.
.It VOL_CAP_FMT_CLONE_MAPPING
If this bit is set, the volume format supports full clone tracking.
See ATTR_CMNEXT_CLONE_REFCNT and ATTR_CMNEXT_CLONEID for more details.
Other features like extended directory statistics, for fast directory sizing,
and attribution tags may be supported as well.
See VOL_CAP_INT_ATTRIBUTION_TAG for more details related to tagging.
.
.
.El
.Pp
.
The following bits are defined in the second element (indexed by
.Dv VOL_CAPABILITIES_INTERFACES )
of the
.Fa capabilities
and
.Fa valid
fields of the
.Vt vol_capabilities_attr_t
structure.
.
.Bl -tag -width VOL_CAP_FMT_PERSISTENTOBJECTIDS
.
.It VOL_CAP_INT_SEARCHFS
If this bit is set the volume format implementation supports
.Xr searchfs 2 .
.
.It VOL_CAP_INT_ATTRLIST
If this bit is set the volume format implementation supports
.Fn getattrlist
and
.Xr setattrlist 2 .
.
.It VOL_CAP_INT_NFSEXPORT
If this bit is set the volume format implementation allows this volume to be exported via NFS.
.
.It VOL_CAP_INT_READDIRATTR
If this bit is set the volume format implementation supports
.Xr getdirentriesattr 2 .
.
.It VOL_CAP_INT_EXCHANGEDATA
If this bit is set the volume format implementation supports
.Xr exchangedata 2 .
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_INT_COPYFILE
If this bit is set the volume format implementation supports the (private and undocumented)
copyfile() function.
(This is not the
.Xr copyfile 3
function.)
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_INT_ALLOCATE
If this bit is set the volume format implementation supports the
.Dv F_PREALLOCATE
selector of
.Xr fcntl 2 .
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_INT_VOL_RENAME
If this bit is set the volume format implementation allows you to
modify the volume name using
.Xr setattrlist 2 .
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_INT_ADVLOCK
If this bit is set the volume format implementation supports
advisory locking, that is, the
.Dv F_GETLK ,
.Dv F_SETLK ,
and
.Dv F_SETLKW
selectors to
.Xr fcntl 2 .
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_INT_FLOCK
If this bit is set the volume format implementation supports
whole file locks.
This includes
.Xr flock 2
and the
.Dv O_EXLOCK
and
.Dv O_SHLOCK
flags to
.Xr open 2 .
.Pp
Introduced with Darwin 7.0 (Mac OS X version 10.3).
.
.It VOL_CAP_INT_EXTENDED_SECURITY
If this bit is set the volume format implementation supports
extended security controls (ACLs).
.Pp
Introduced with Darwin 8.0 (Mac OS X version 10.4).
.
.It VOL_CAP_INT_USERACCESS
If this bit is set the volume format implementation supports the
ATTR_CMN_USERACCESS attribute.
.Pp
Introduced with Darwin 8.0 (Mac OS X version 10.4).
.
.It VOL_CAP_INT_MANLOCK
If this bit is set, the volume format implementation supports
AFP-style mandatory byte range locks via
.Xr ioctl 2 .
.
.It VOL_CAP_INT_EXTENDED_ATTR
If this bit is set, the volume format implementation supports
native extended attributes (see
.Xr setxattr 2 Ns ).
.
.It VOL_CAP_INT_CLONE
If this bit is set, the file system supports cloning files and directories.
See 
.Xr clonefileat 2 
for more details.
.
.It VOL_CAP_INT_SNAPSHOT
If this bit is set, the file system supports snapshots.
See
.Xr fs_snapshot_create 2
for more details.
.
.It VOL_CAP_INT_NAMEDSTREAMS
If this bit is set, the volume format implementation supports
native named streams.
.
.It VOL_CAP_INT_RENAME_SWAP
If this bit is set, the file system supports swapping file system
objects.  See
.Xr rename 2
for more details.
.
.It VOL_CAP_INT_RENAME_EXCL
If this bit is set, the file system supports an exclusive rename
operation. See
.Xr rename 2
for more details.
.
.It VOL_CAP_INT_RENAME_OPENFAIL
If this bit is set, the file system may fail a rename operation
of a directory if one of its descendents is open.
See
.Xr rename 2
for more details.
.
.It VOL_CAP_INT_ATTRIBUTION_TAG
If this bit is set, the file system supports establishing an owner relationship between
a file (excluding small files) and a process on the first read/write/truncate/clone operation.
See ATTR_CMNEXT_ATTRIBUTION_TAG for more details.
.
.It VOL_CAP_INT_PUNCHHOLE
If this bit is set, the file system supports the
.Dv F_PUNCHOLE operation.
See
.Xr fcntl 2
for more details.
.
.It VOL_CAP_INT_BARRIERFSYNC
If this bit is set, the file system supports the
.Dv F_BARRIERFSYNC operation.
See
.Xr fcntl 2
for more details.
.
.El
.Pp
.
.\" vol_attributes_attr_t
.
A volume can also report which attributes it supports.
This information is returned by the
.Dv ATTR_VOL_ATTRIBUTES
attribute, which returns a
.Vt vol_attributes_attr_t
structure (shown below).
.
.Bd -literal
typedef struct attribute_set {
    attrgroup_t commonattr; /* common attribute group */
    attrgroup_t volattr;    /* volume attribute group */
    attrgroup_t dirattr;    /* directory attribute group */
    attrgroup_t fileattr;   /* file attribute group */
    attrgroup_t forkattr;   /* fork attribute group */
} attribute_set_t;
.Pp
.
typedef struct vol_attributes_attr {
    attribute_set_t validattr;
    attribute_set_t nativeattr;
} vol_attributes_attr_t;
.Ed
.Pp
.
The
.Fa validattr
field consists of a number of bit sets that indicate whether an attribute is
supported by the volume format implementation.
The
.Fa nativeattr
is similar except that the bit sets indicate whether an attribute is supported
natively by the volume format.
An attribute is supported natively if the volume format implementation does not have to do
any complex conversions to access the attribute.
For example, a volume format might support persistent object identifiers, but
doing so requires a complex table lookup that is not part of the core volume
format.
In that case, the
.Dv ATTR_VOL_ATTRIBUTES
attribute would return
.Dv ATTR_CMN_OBJPERMANENTID
set in the
.Fa validattr
field of the
.Vt vol_attributes_attr_t ,
but not in the
.Fa nativeattr
field.
.
.Sh RETURN VALUES
Upon successful completion a value of 0 is returned.
Otherwise, a value of -1 is returned and
.Va errno
is set to indicate the error.
.
.Sh COMPATIBILITY
Not all volumes support
.Fn getattrlist .
The best way to test whether a volume supports this function is to
simply call it and check the error result.
.Fn getattrlist
will return
.Dv ENOTSUP
if it is not supported on a particular volume.
.Pp
.
The
.Fn getattrlist
function has been undocumented for more than two years.
In that time a number of volume format implementations have been created without
a proper specification for the behaviour of this routine.
You may encounter volume format implementations with slightly different
behaviour than what is described here.
Your program is expected to be tolerant of this variant behaviour.
.Pp
.
If you're implementing a volume format that supports
.Fn getattrlist ,
you should be careful to support the behaviour specified by this document.
.
.Sh ERRORS
.Fn getattrlist
and
.Fn fgetattrlist
will fail if:
.Bl -tag -width Er
.
.It Bq Er ENOTSUP
The volume does not support the query.
.
.It Bq Er ENOTDIR
A component of the path prefix for
.Fn getattrlist
is not a directory.
.
.It Bq Er ENAMETOOLONG
A component of a path name for
.Fn getattrlist
exceeded
.Dv NAME_MAX
characters, or an entire path name exceeded
.Dv PATH_MAX
characters.
.
.It Bq Er ENOENT
The file system object for
.Fn getattrlist
does not exist.
.
.It Bq Er EBADF
The file descriptor argument for
.Fn fgetattrlist
is not a valid file descriptor.
.
.It Bq Er EACCES
Search permission is denied for a component of the path prefix for
.Fn getattrlist .
.
.It Bq Er ELOOP
Too many symbolic links were encountered in translating the pathname
for
.Fn getattrlist .
.
.It Bq Er ELOOP
FSOPT_NOFOLLOW_ANY was passed and a symbolic link was encountered in
translating the pathname for
.Fn getattrlist .
.
.It Bq Er EFAULT
.Fa path ,
.Fa attrList
or
.Em attrBuf
points to an invalid address.
.
.It Bq Er ERANGE
.Fa attrBufSize
is too small to hold a u_int32_t.
.
.It Bq Er EINVAL
The
.Fa bitmapcount
field of
.Fa attrList
is not
.Dv ATTR_BIT_MAP_COUNT .
.
.It Bq Er EINVAL
You requested an invalid attribute.
.
.It Bq Er EINVAL
You requested an attribute that is not supported for this file system object.
.
.It Bq Er EINVAL
You requested volume attributes and directory or file attributes.
.
.It Bq Er EINVAL
You requested volume attributes but
.Fa path
does not reference the root of the volume.
.
.It Bq Er EROFS
The volume is read-only but must be modified in order to return this attribute.
.
.It Bq Er EIO
An I/O error occurred while reading from or writing to the file system.
.El
.Pp
In addition to the errors returned by the
.Fn getattrlist ,
the
.Fn getattrlistat
function may fail if:
.Bl -tag -width Er
.It Bq Er EBADF
The
.Fa path
argument does not specify an absolute path and the
.Fa fd
argument is neither
.Dv AT_FDCWD
nor a valid file descriptor open for searching.
.It Bq Er ENOTDIR
The
.Fa path
argument is not an absolute path and
.Fa fd
is neither
.Dv AT_FDCWD
nor a file descriptor associated with a directory.
.It Bq Er ENOTCAPABLE
if FSOPT_RESOLVE_BENEATH was passed and
.Fa path
does not reside in the directory hierarchy beneath the starting directory.
.It Bq Er ENOTCAPABLE
if FSOPT_UNIQUE was passed and
.Fa path
has multiple hard links.
.El
.Pp
.
.Sh CAVEATS
.
If you request any volume attributes, you must set
.Dv ATTR_VOL_INFO
in the
.Fa volattr
field, even though it generates no result in the attribute buffer.
.Pp
.
The order that attributes are stored in the attribute buffer almost
invariably matches the order of attribute mask bit values.
For example,
.Dv ATTR_CMN_NAME
(0x00000001) comes before
.Dv ATTR_CMN_DEVID
(0x00000002) because its value is smaller.
When ordering attributes, you should always use the order in which they
are described above.
.Pp
.
The
.Vt timespec
structure is 64-bits (two 32-bit elements) in 32-bit code, and
128-bits (two 64-bit elements) in 64-bit code; however, it is aligned
on a 4-byte (32-bit) boundary, even in 64-bit code.
.Pp
If you use a structure
for the attribute data, it must be correctly packed and aligned (see
examples).
.Pp
.
Inconsistent behavior may be observed when the ATTR_CMN_FULLPATH attribute is requested on
hard-linked items, particularly when the file system does not support ATTR_CMN_PARENTID
natively. Callers should be aware of this when requesting the full path of a hard-linked item, especially
if the full path crosses mount points.
.Pp
.
For more caveats, see also the compatibility notes above.
.
.Sh EXAMPLES
.
The following code prints the file type and creator of a file,
assuming that the volume supports the required attributes.
.
.Bd -literal
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/attr.h>
#include <sys/errno.h>
#include <unistd.h>
#include <sys/vnode.h>
.Pp
.
typedef struct attrlist attrlist_t;
.Pp
.
struct FInfoAttrBuf {
    u_int32_t       length;
    fsobj_type_t    objType;
    char            finderInfo[32];
}  __attribute__((aligned(4), packed));
typedef struct FInfoAttrBuf FInfoAttrBuf;
.Pp
.
static int FInfoDemo(const char *path)
{
    int             err;
    attrlist_t      attrList;
    FInfoAttrBuf    attrBuf;
.Pp
.
    memset(&attrList, 0, sizeof(attrList));
    attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
    attrList.commonattr  = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
.Pp

    err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
    if (err != 0) {
        err = errno;
    }
.Pp

    if (err == 0) {
        assert(attrBuf.length == sizeof(attrBuf));
.Pp

        printf("Finder information for %s:\en", path);
        switch (attrBuf.objType) {
            case VREG:
                printf("file type    = '%.4s'\en", &attrBuf.finderInfo[0]);
                printf("file creator = '%.4s'\en", &attrBuf.finderInfo[4]);
                break;
            case VDIR:
                printf("directory\en");
                break;
            default:
                printf("other object type, %d\en", attrBuf.objType);
                break;
        }
    }
.Pp
.
    return err;
}
.Ed
.Pp
.
The following code is an alternative implementation that uses nested structures
to group the related attributes.
.
.Bd -literal
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <sys/attr.h>
#include <sys/errno.h>
#include <unistd.h>
#include <sys/vnode.h>
.Pp
.
typedef struct attrlist attrlist_t;
.Pp
.
struct FInfo2CommonAttrBuf {
    fsobj_type_t    objType;
    char            finderInfo[32];
} __attribute__((aligned(4), packed));
typedef struct FInfo2CommonAttrBuf FInfo2CommonAttrBuf;
.Pp
.
struct FInfo2AttrBuf {
    u_int32_t           length;
    FInfo2CommonAttrBuf common;
} __attribute__((aligned(4), packed));;
typedef struct FInfo2AttrBuf FInfo2AttrBuf;
.Pp
.
static int FInfo2Demo(const char *path)
{
    int             err;
    attrlist_t      attrList;
    FInfo2AttrBuf   attrBuf;
.Pp
.
    memset(&attrList, 0, sizeof(attrList));
    attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
    attrList.commonattr  = ATTR_CMN_OBJTYPE | ATTR_CMN_FNDRINFO;
.Pp
.
    err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
    if (err != 0) {
        err = errno;
    }
.Pp
.
    if (err == 0) {
        assert(attrBuf.length == sizeof(attrBuf));
.Pp
.
        printf("Finder information for %s:\en", path);
        switch (attrBuf.common.objType) {
            case VREG:
                printf(
                    "file type    = '%.4s'\en",
                    &attrBuf.common.finderInfo[0]
                );
                printf(
                    "file creator = '%.4s'\en",
                    &attrBuf.common.finderInfo[4]
                );
                break;
            case VDIR:
                printf("directory\en");
                break;
            default:
                printf(
                    "other object type, %d\en",
                    attrBuf.common.objType
                );
                break;
        }
    }
.Pp
.
    return err;
}
.Ed
.Pp
.
The following example shows how to deal with variable length attributes.
It assumes that the volume specified by
.Fa path
supports the necessary attributes.
.
.Bd -literal
#include <assert.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <sys/attr.h>
#include <sys/errno.h>
#include <unistd.h>
#include <sys/vnode.h>
.Pp
.
typedef struct attrlist attrlist_t;
.Pp
.
struct VolAttrBuf {
    u_int32_t       length;
    u_int32_t       fileCount;
    u_int32_t       dirCount;
    attrreference_t mountPointRef;
    attrreference_t volNameRef;
    char            mountPointSpace[MAXPATHLEN];
    char            volNameSpace[MAXPATHLEN];
} __attribute__((aligned(4), packed));
typedef struct VolAttrBuf VolAttrBuf;
.Pp
.
static int VolDemo(const char *path)
{
    int             err;
    attrlist_t      attrList;
    VolAttrBuf      attrBuf;
.Pp
.
    memset(&attrList, 0, sizeof(attrList));
    attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
    attrList.volattr     =   ATTR_VOL_INFO
                           | ATTR_VOL_FILECOUNT
                           | ATTR_VOL_DIRCOUNT
                           | ATTR_VOL_MOUNTPOINT
                           | ATTR_VOL_NAME;
.Pp

    err = getattrlist(path, &attrList, &attrBuf, sizeof(attrBuf), 0);
    if (err != 0) {
        err = errno;
    }
.Pp

    if (err == 0) {
        assert(attrBuf.length >  offsetof(VolAttrBuf, mountPointSpace));
        assert(attrBuf.length <= sizeof(attrBuf));
.Pp

        printf("Volume information for %s:\en", path);
        printf("ATTR_VOL_FILECOUNT:  %u\en", attrBuf.fileCount);
        printf("ATTR_VOL_DIRCOUNT:   %u\en", attrBuf.dirCount);
        printf(
            "ATTR_VOL_MOUNTPOINT: %.*s\en",
            (int) attrBuf.mountPointRef.attr_length,
            ( ((char *) &attrBuf.mountPointRef)
              + attrBuf.mountPointRef.attr_dataoffset )
        );
        printf(
            "ATTR_VOL_NAME:       %.*s\en",
            (int) attrBuf.volNameRef.attr_length,
            ( ((char *) &attrBuf.volNameRef)
              + attrBuf.volNameRef.attr_dataoffset )
        );
    }
.Pp
.
    return err;
}
.Ed
.Pp
The following sample demonstrates the need to use packing and alignment
controls; without the attribute, in 64-bit code, the fields of the structure are not
placed at the locations that the kernel expects.
.
.Bd -literal
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <err.h>
#include <time.h>
#include <sys/attr.h>
.Pp
/* The alignment and packing attribute is necessary in 64-bit code */
struct AttrListTimes {
	u_int32_t       length;
	struct timespec st_crtime;
	struct timespec st_modtime;
} __attribute__((aligned(4), packed));
.Pp
main(int argc, char **argv)
{
	int             rv;
	int             i;
.Pp
	for (i = 1; i < argc; i++) {
		struct attrlist attrList;
		struct AttrListTimes myStat = {0};
		char           *path = argv[i];
.Pp
		memset(&attrList, 0, sizeof(attrList));
		attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
		attrList.commonattr = ATTR_CMN_CRTIME |
			ATTR_CMN_MODTIME;
.Pp
		rv = getattrlist(path, &attrList, &myStat, sizeof(myStat), 0);
.Pp
		if (rv == -1) {
			warn("getattrlist(%s)", path);
			continue;
		}
		printf("%s:  Modification time = %s", argv[i], ctime(&myStat.st_modtime.tv_sec));
	}
	return 0;
}
.Ed
.Pp
 The getLinkIDInfo() function determines if ATTR_CMNEXT_LINKID and ATTR_CMN_OBJID
 are valid to use on the file system specified by path.
.
.Bd -literal
int getLinkIDInfo(const char *path, bool *cmnExtLinkIDValid, bool *cmnObjIDValid)
{
    int result;
    struct statfs statfsBuf;
    struct attrlist attrList;
    struct volAttrsBuf {
        u_int32_t length;
        vol_capabilities_attr_t capabilities;
        vol_attributes_attr_t attributes;
    } __attribute__((aligned(4), packed));
    struct volAttrsBuf volAttrs;
.Pp
    memset(&attrList, 0, sizeof(attrList));
    attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
    attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES | ATTR_VOL_ATTRIBUTES;
    // get the file system's mount point path for the input path
    result = statfs(path, &statfsBuf);
    if ( result == 0 ) {
        // get the supported capabilities and attributes
        result = getattrlist(statfsBuf.f_mntonname, &attrList, &volAttrs, sizeof(volAttrs), FSOPT_ATTR_CMN_EXTENDED);
        if ( result == 0 ) {
            if ( volAttrs.attributes.validattr.forkattr & ATTR_CMNEXT_LINKID ) {
                // ATTR_CMNEXT_LINKID is available; do not use ATTR_CMN_OBJID
                *cmnExtLinkIDValid = true;
                *cmnObjIDValid = false;
            }
            else {
                // ATTR_CMNEXT_LINKID is not available
                cmnExtLinkIDValid = false;
                // ATTR_CMN_OBJID can only be used if the file system does not use 64-bit object IDs
                if ( (volAttrs.capabilities.capabilities[VOL_CAPABILITIES_FORMAT] & VOL_CAP_FMT_64BIT_OBJECT_IDS) && (volAttrs.capabilities.valid[VOL_CAPABILITIES_FORMAT] & VOL_CAP_FMT_64BIT_OBJECT_IDS) ) {
                    *cmnObjIDValid = false;
                }
                else {
                    *cmnObjIDValid = true;
                }
            }
        }
    }
    if ( result != 0 ) {
        *cmnExtLinkIDValid = *cmnObjIDValid = false;
    }
    return result;
}
.Ed
.Pp
.
.Sh SEE ALSO
.
.Xr access 2 ,
.Xr chflags 2 ,
.Xr exchangedata 2 ,
.Xr fcntl 2 ,
.Xr getattrlistbulk 2 ,
.Xr mount 2 ,
.Xr searchfs 2 ,
.Xr setattrlist 2 ,
.Xr stat 2 ,
.Xr statfs 2
.
.Sh HISTORY
A
.Fn getattrlist
function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
The
.Fn getattrlistat
function call appeared in OS X 10.10 .