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
|
/* $NetBSD: fs.c,v 1.1 2022/01/22 08:09:40 pho Exp $ */
/*
* Copyright (c) 2021 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: fs.c,v 1.1 2022/01/22 08:09:40 pho Exp $");
#endif /* !lint */
/*
* Filesystem Stacking API, appeared on FUSE 2.7.
*
* So many callback functions in struct fuse_operations have different
* prototypes between versions. We use the stacking API to abstract
* that away to implement puffs operations in a manageable way.
*/
#include <err.h>
#include <fuse_internal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dirent.h>
#include <sys/errno.h>
struct fuse_fs {
void* op;
int op_version;
void* user_data;
};
#define UNKNOWN_VERSION(op_version) \
errc(EXIT_FAILURE, ENOSYS, "%s: unknown fuse_operations version: %d", \
__func__, op_version)
static void*
clone_op(const void* op, int op_version) {
void* cloned;
switch (op_version) {
#define CLONE_OP(VER) \
case VER: \
cloned = malloc(sizeof(struct __CONCAT(fuse_operations_v,VER))); \
if (!cloned) \
return NULL; \
memcpy(cloned, op, sizeof(struct __CONCAT(fuse_operations_v,VER))); \
return cloned
CLONE_OP(11);
CLONE_OP(21);
CLONE_OP(22);
CLONE_OP(23);
CLONE_OP(25);
CLONE_OP(26);
CLONE_OP(28);
CLONE_OP(29);
CLONE_OP(30);
CLONE_OP(34);
CLONE_OP(35);
CLONE_OP(38);
#undef CLONE_OP
default:
UNKNOWN_VERSION(op_version);
}
}
struct fuse_fs*
__fuse_fs_new(const void* op, int op_version, void* user_data) {
struct fuse_fs* fs;
fs = malloc(sizeof(struct fuse_fs));
if (!fs)
err(EXIT_FAILURE, __func__);
/* Callers aren't obliged to keep "op" valid during the lifetime
* of struct fuse_fs*. We must clone it now, even though it's
* non-trivial. */
fs->op = clone_op(op, op_version);
if (!fs->op)
err(EXIT_FAILURE, __func__);
fs->op_version = op_version;
fs->user_data = user_data;
return fs;
}
/* Clobber the context private_data with that of this filesystem
* layer. This function needs to be called before invoking any of
* operation callbacks. */
static void
clobber_context_user_data(struct fuse_fs* fs) {
fuse_get_context()->private_data = fs->user_data;
}
/* Ugly... These are like hand-written vtables... */
int
fuse_fs_getattr_v27(struct fuse_fs *fs, const char *path, struct stat *buf) {
return fuse_fs_getattr_v30(fs, path, buf, NULL);
}
int
fuse_fs_getattr_v30(struct fuse_fs* fs, const char* path,
struct stat* buf, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_GETATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr(path, buf); \
else \
return -ENOSYS
CALL_OLD_GETATTR(11);
CALL_OLD_GETATTR(21);
CALL_OLD_GETATTR(22);
CALL_OLD_GETATTR(23);
CALL_OLD_GETATTR(25);
CALL_OLD_GETATTR(26);
CALL_OLD_GETATTR(28);
CALL_OLD_GETATTR(29);
#undef CALL_OLD_GETATTR
#define CALL_GETATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr(path, buf, fi); \
else \
return -ENOSYS
CALL_GETATTR(30);
CALL_GETATTR(34);
CALL_GETATTR(38);
#undef CALL_GETATTR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_fgetattr(struct fuse_fs* fs, const char* path, struct stat* buf,
struct fuse_file_info* fi) {
clobber_context_user_data(fs);
/* fgetattr() was introduced on FUSE 2.5 then disappeared on FUSE
* 3.0. Fall back to getattr() if it's missing. */
switch (fs->op_version) {
case 11:
case 21:
case 22:
case 23:
return fuse_fs_getattr_v30(fs, path, buf, fi);
#define CALL_FGETATTR_OR_OLD_GETATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fgetattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fgetattr(path, buf, fi); \
else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr(path, buf); \
else \
return -ENOSYS
CALL_FGETATTR_OR_OLD_GETATTR(25);
CALL_FGETATTR_OR_OLD_GETATTR(26);
CALL_FGETATTR_OR_OLD_GETATTR(28);
CALL_FGETATTR_OR_OLD_GETATTR(29);
#undef CALL_FGETATTR_OR_OLD_GETATTR
case 30:
case 34:
case 38:
return fuse_fs_getattr_v30(fs, path, buf, fi);
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_rename_v27(struct fuse_fs* fs, const char* oldpath, const char* newpath) {
return fuse_fs_rename_v30(fs, oldpath, newpath, 0);
}
int
fuse_fs_rename_v30(struct fuse_fs* fs, const char* oldpath,
const char* newpath, unsigned int flags) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_RENAME(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename(oldpath, newpath); \
else \
return -ENOSYS
CALL_OLD_RENAME(11);
CALL_OLD_RENAME(21);
CALL_OLD_RENAME(22);
CALL_OLD_RENAME(23);
CALL_OLD_RENAME(25);
CALL_OLD_RENAME(26);
CALL_OLD_RENAME(28);
CALL_OLD_RENAME(29);
#undef CALL_OLD_RENAME
#define CALL_RENAME(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename(oldpath, newpath, flags); \
else \
return -ENOSYS
CALL_RENAME(30);
CALL_RENAME(34);
CALL_RENAME(38);
#undef CALL_RENAME
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_unlink(struct fuse_fs* fs, const char* path) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_UNLINK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->unlink) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->unlink(path); \
else \
return -ENOSYS
CALL_UNLINK(11);
CALL_UNLINK(21);
CALL_UNLINK(22);
CALL_UNLINK(23);
CALL_UNLINK(25);
CALL_UNLINK(26);
CALL_UNLINK(28);
CALL_UNLINK(29);
CALL_UNLINK(30);
CALL_UNLINK(34);
CALL_UNLINK(38);
#undef CALL_UNLINK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_rmdir(struct fuse_fs* fs, const char* path) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_RMDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rmdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rmdir(path); \
else \
return -ENOSYS
CALL_RMDIR(11);
CALL_RMDIR(21);
CALL_RMDIR(22);
CALL_RMDIR(23);
CALL_RMDIR(25);
CALL_RMDIR(26);
CALL_RMDIR(28);
CALL_RMDIR(29);
CALL_RMDIR(30);
CALL_RMDIR(34);
CALL_RMDIR(38);
#undef CALL_RMDIR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_symlink(struct fuse_fs* fs, const char* linkname, const char* path) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_SYMLINK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->symlink) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->symlink(linkname, path); \
else \
return -ENOSYS
CALL_SYMLINK(11);
CALL_SYMLINK(21);
CALL_SYMLINK(22);
CALL_SYMLINK(23);
CALL_SYMLINK(25);
CALL_SYMLINK(26);
CALL_SYMLINK(28);
CALL_SYMLINK(29);
CALL_SYMLINK(30);
CALL_SYMLINK(34);
CALL_SYMLINK(38);
#undef CALL_SYMLINK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_link(struct fuse_fs* fs, const char* oldpath, const char* newpath) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_LINK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->link) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->link(oldpath, newpath); \
else \
return -ENOSYS
CALL_LINK(11);
CALL_LINK(21);
CALL_LINK(22);
CALL_LINK(23);
CALL_LINK(25);
CALL_LINK(26);
CALL_LINK(28);
CALL_LINK(29);
CALL_LINK(30);
CALL_LINK(34);
CALL_LINK(38);
#undef CALL_LINK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_release(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_RELEASE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release(path, fi->flags); \
else \
return 0 /* Special case */
CALL_OLD_RELEASE(11);
CALL_OLD_RELEASE(21);
#undef CALL_OLD_RELEASE
#define CALL_RELEASE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release(path, fi); \
else \
return 0 /* Special case */
CALL_RELEASE(22);
CALL_RELEASE(23);
CALL_RELEASE(25);
CALL_RELEASE(26);
CALL_RELEASE(28);
CALL_RELEASE(29);
CALL_RELEASE(30);
CALL_RELEASE(34);
CALL_RELEASE(38);
#undef CALL_RELEASE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_open(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_OPEN(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open(path, fi->flags); \
else \
return 0 /* Special case */
CALL_OLD_OPEN(11);
CALL_OLD_OPEN(21);
#undef CALL_OLD_OPEN
#define CALL_OPEN(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open(path, fi); \
else \
return 0 /* Special case */
CALL_OPEN(22);
CALL_OPEN(23);
CALL_OPEN(25);
CALL_OPEN(26);
CALL_OPEN(28);
CALL_OPEN(29);
CALL_OPEN(30);
CALL_OPEN(34);
CALL_OPEN(38);
#undef CALL_OPEN
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_read(struct fuse_fs* fs, const char* path, char* buf,
size_t size, off_t off, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_READ(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read(path, buf, size, off); \
else \
return -ENOSYS
CALL_OLD_READ(11);
CALL_OLD_READ(21);
#undef CALL_OLD_READ
#define CALL_READ(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read(path, buf, size, off, fi); \
else \
return -ENOSYS
CALL_READ(22);
CALL_READ(23);
CALL_READ(25);
CALL_READ(26);
CALL_READ(28);
CALL_READ(29);
CALL_READ(30);
CALL_READ(34);
CALL_READ(38);
#undef CALL_READ
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_read_buf(struct fuse_fs* fs, const char* path,
struct fuse_bufvec** bufp, size_t size, off_t off,
struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.9 didn't have read_buf(). */
case 11:
case 21:
case 22:
case 23:
case 25:
case 26:
case 28:
return -ENOSYS;
#define CALL_READ_BUF(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read_buf) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read_buf(path, bufp, size, off, fi); \
else \
return -ENOSYS
CALL_READ_BUF(29);
CALL_READ_BUF(30);
CALL_READ_BUF(34);
CALL_READ_BUF(38);
#undef CALL_READ_BUF
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_write(struct fuse_fs* fs, const char* path, const char* buf,
size_t size, off_t off, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_WRITE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write(path, buf, size, off); \
else \
return -ENOSYS
CALL_OLD_WRITE(11);
CALL_OLD_WRITE(21);
#undef CALL_OLD_WRITE
#define CALL_WRITE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write(path, buf, size, off, fi); \
else \
return -ENOSYS
CALL_WRITE(22);
CALL_WRITE(23);
CALL_WRITE(25);
CALL_WRITE(26);
CALL_WRITE(28);
CALL_WRITE(29);
CALL_WRITE(30);
CALL_WRITE(34);
CALL_WRITE(38);
#undef CALL_WRITE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_write_buf(struct fuse_fs* fs, const char* path,
struct fuse_bufvec* bufp, off_t off,
struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.9 didn't have write_buf(). */
case 11:
case 21:
case 22:
case 23:
case 25:
case 26:
case 28:
return -ENOSYS;
#define CALL_WRITE_BUF(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write_buf) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write_buf(path, bufp, off, fi); \
else \
return -ENOSYS
CALL_WRITE_BUF(29);
CALL_WRITE_BUF(30);
CALL_WRITE_BUF(34);
CALL_WRITE_BUF(38);
#undef CALL_WRITE_BUF
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_fsync(struct fuse_fs* fs, const char* path, int datasync, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_FSYNC(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync(path, datasync); \
else \
return -ENOSYS
CALL_OLD_FSYNC(11);
CALL_OLD_FSYNC(21);
#undef CALL_OLD_FSYNC
#define CALL_FSYNC(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync(path, datasync, fi); \
else \
return -ENOSYS
CALL_FSYNC(22);
CALL_FSYNC(23);
CALL_FSYNC(25);
CALL_FSYNC(26);
CALL_FSYNC(28);
CALL_FSYNC(29);
CALL_FSYNC(30);
CALL_FSYNC(34);
CALL_FSYNC(38);
#undef CALL_FSYNC
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_flush(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
/* flush() appeared on FUSE 2.1 and its prototype was changed on
* 2.2. */
switch (fs->op_version) {
case 11:
return -ENOSYS;
case 21:
if (((const struct fuse_operations_v21 *)fs->op)->flush)
return ((const struct fuse_operations_v21 *)fs->op)->flush(path);
else
return -ENOSYS;
#define CALL_FLUSH(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flush) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flush(path, fi); \
else \
return -ENOSYS
CALL_FLUSH(22);
CALL_FLUSH(23);
CALL_FLUSH(25);
CALL_FLUSH(26);
CALL_FLUSH(28);
CALL_FLUSH(29);
CALL_FLUSH(30);
CALL_FLUSH(34);
CALL_FLUSH(38);
#undef CALL_FLUSH
default:
UNKNOWN_VERSION(fs->op_version);
}
}
static void
zero_statvfs(struct statvfs* dst) {
dst->f_bsize = 0;
dst->f_frsize = 0;
dst->f_blocks = 0;
dst->f_bfree = 0;
dst->f_bavail = 0;
dst->f_files = 0;
dst->f_ffree = 0;
dst->f_fresvd = 0;
}
static void
fuse_statfs_to_statvfs(struct statvfs* dst, const struct fuse_statfs* src) {
dst->f_bsize = (unsigned long)src->block_size;
dst->f_frsize = (unsigned long)src->block_size; /* Dunno if this is correct. */
dst->f_blocks = (fsblkcnt_t)src->blocks;
dst->f_bfree = (fsblkcnt_t)src->blocks_free;
dst->f_bavail = (fsblkcnt_t)src->blocks_free;
dst->f_files = (fsfilcnt_t)src->files;
dst->f_ffree = (fsfilcnt_t)src->files_free;
}
static void
linux_statfs_to_statvfs(struct statvfs* dst, const struct statfs* src) {
dst->f_bsize = (unsigned long)src->f_bsize;
dst->f_frsize = (unsigned long)src->f_bsize; /* Dunno if this is correct. */
dst->f_blocks = src->f_blocks;
dst->f_bfree = src->f_bfree;
dst->f_bavail = src->f_bavail;
dst->f_files = src->f_files;
dst->f_ffree = src->f_ffree;
}
int
fuse_fs_statfs(struct fuse_fs* fs, const char* path, struct statvfs* buf) {
clobber_context_user_data(fs);
zero_statvfs(buf);
switch (fs->op_version) {
/* FUSE < 2.1 used "struct fuse_statfs". */
case 11:
if (((const struct fuse_operations_v11*)fs->op)->statfs) {
struct fuse_statfs statfs_v11;
int ret;
ret = ((const struct fuse_operations_v11*)fs->op)->statfs(path, &statfs_v11);
if (ret == 0)
fuse_statfs_to_statvfs(buf, &statfs_v11);
return ret;
}
else
return 0; /* Special case */
/* FUSE >= 2.2 && < 2.5 used Linux-specific "struct
* statfs". */
#define CALL_LINUX_STATFS(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs) { \
struct statfs statfs_v22; \
int ret; \
\
ret = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs(path, &statfs_v22); \
if (ret == 0) \
linux_statfs_to_statvfs(buf, &statfs_v22); \
\
return ret; \
} \
else \
return 0; /* Special case */
CALL_LINUX_STATFS(22);
CALL_LINUX_STATFS(23);
#undef CALL_STATFS
/* FUSE >= 2.5 use struct statvfs. */
#define CALL_STATFS(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs(path, buf); \
else \
return 0; /* Special case */
CALL_STATFS(25);
CALL_STATFS(26);
CALL_STATFS(28);
CALL_STATFS(29);
CALL_STATFS(30);
CALL_STATFS(34);
CALL_STATFS(38);
#undef CALL_STATFS
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_opendir(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.3 didn't have opendir() and used to read
* directories without opening them. */
case 11:
case 21:
case 22:
return 0; /* Special case */
#define CALL_OPENDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->opendir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->opendir(path, fi); \
else \
return 0 /* Special case */
CALL_OPENDIR(23);
CALL_OPENDIR(25);
CALL_OPENDIR(26);
CALL_OPENDIR(28);
CALL_OPENDIR(29);
CALL_OPENDIR(30);
CALL_OPENDIR(34);
CALL_OPENDIR(38);
#undef CALL_OPENDIR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
/* ===================================
* -=- The readdir Madness -=-
* Juggling with Nested Shims
* =================================== */
struct fuse_fill_dir_v23_shim {
void* dirh;
fuse_fill_dir_t_v23 fill_dir_v23;
};
/* Translate dirent DT_* to mode_t. Needed by shim functions. */
static mode_t
dt_to_mode(int dt) {
switch (dt) {
case DT_UNKNOWN: return 0;
case DT_FIFO: return S_IFIFO;
case DT_CHR: return S_IFCHR;
case DT_DIR: return S_IFCHR;
case DT_BLK: return S_IFBLK;
case DT_REG: return S_IFREG;
case DT_LNK: return S_IFLNK;
case DT_SOCK: return S_IFSOCK;
case DT_WHT: return S_IFWHT;
default:
errx(EXIT_FAILURE, "%s: unknown dirent type: %d",
__func__, dt);
}
}
/* This is a shim function that satisfies the type of
* fuse_dirfil_t_v11 but calls fuse_fill_dir_v23. */
static int
fuse_dirfil_v11_to_fill_dir_v23(fuse_dirh_t handle, const char* name, int type) {
struct fuse_fill_dir_v23_shim* shim = handle;
struct stat stbuf;
int res; /* 1 or 0 */
memset(&stbuf, 0, sizeof(stbuf));
stbuf.st_mode = dt_to_mode(type);
res = shim->fill_dir_v23(shim->dirh, name, &stbuf, 0);
return res ? -ENOMEM : 0;
}
/* This is a shim function that satisfies the type of
* fuse_dirfil_t_v22 but calls fuse_fill_dir_v23. */
static int
fuse_dirfil_v22_to_fill_dir_v23(fuse_dirh_t handle, const char* name, int type, ino_t ino) {
struct fuse_fill_dir_v23_shim* shim = handle;
struct stat stbuf;
int res; /* 1 or 0 */
memset(&stbuf, 0, sizeof(stbuf));
stbuf.st_mode = dt_to_mode(type);
stbuf.st_ino = ino;
res = shim->fill_dir_v23(shim->dirh, name, &stbuf, 0);
return res ? -ENOMEM : 0;
}
struct fuse_fill_dir_v30_shim {
void* dirh;
fuse_fill_dir_t_v30 fill_dir_v30;
};
/* This is a shim function that satisfies the type of
* fuse_fill_dir_v23 but calls fuse_fill_dir_v30. */
static int
fuse_fill_dir_v23_to_v30(void* buf, const char* name,
const struct stat* stat, off_t off) {
struct fuse_fill_dir_v30_shim* shim = buf;
return shim->fill_dir_v30(shim->dirh, name, stat, off, (enum fuse_fill_dir_flags)0);
}
int
fuse_fs_readdir_v27(struct fuse_fs* fs, const char* path, void* buf,
fuse_fill_dir_t_v23 filler, off_t off,
struct fuse_file_info* fi) {
struct fuse_fill_dir_v23_shim v23_shim;
v23_shim.dirh = buf;
v23_shim.fill_dir_v23 = filler;
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.2 had getdir() that used fuse_dirfil_t_v11. */
#define CALL_GETDIR_V11(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir(path, &v23_shim, fuse_dirfil_v11_to_fill_dir_v23); \
else \
return -ENOSYS
CALL_GETDIR_V11(11);
CALL_GETDIR_V11(21);
#undef CALL_GETDIR_V11
/* FUSE 2.2 had getdir() that used fuse_dirfil_t_v22 but
* didn't have readdir(). */
case 22:
if (((const struct fuse_operations_v22*)fs->op)->getdir)
return ((const struct fuse_operations_v22*)fs->op)->getdir(path, &v23_shim, fuse_dirfil_v22_to_fill_dir_v23);
else
return -ENOSYS;
/* FUSE 2.3 introduced readdir() but still had getdir() as
* a deprecated operation. It had been this way until FUSE 3.0
* finally removed getdir() and also changed the prototype of
* readdir(). */
#define CALL_READDIR_OR_GETDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir(path, buf, filler, off, fi); \
else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir(path, &v23_shim, fuse_dirfil_v22_to_fill_dir_v23); \
else \
return -ENOSYS
CALL_READDIR_OR_GETDIR(23);
CALL_READDIR_OR_GETDIR(25);
CALL_READDIR_OR_GETDIR(26);
CALL_READDIR_OR_GETDIR(28);
CALL_READDIR_OR_GETDIR(29);
#undef CALL_READDIR_OR_GETDIR
default:
/* FUSE >= 3.0 filesystems will never call this function. We
* can safely ignore them here. */
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_readdir_v30(struct fuse_fs* fs, const char* path, void* buf,
fuse_fill_dir_t_v30 filler, off_t off,
struct fuse_file_info* fi, enum fuse_readdir_flags flags) {
clobber_context_user_data(fs);
if (fs->op_version < 30) {
struct fuse_fill_dir_v30_shim v30_shim;
v30_shim.dirh = buf;
v30_shim.fill_dir_v30 = filler;
return fuse_fs_readdir_v27(fs, path, &v30_shim, fuse_fill_dir_v23_to_v30, off, fi);
}
else {
switch (fs->op_version) {
#define CALL_READDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir(path, buf, filler, off, fi, flags); \
else \
return -ENOSYS
CALL_READDIR(30);
CALL_READDIR(34);
CALL_READDIR(38);
#undef CALL_READDIR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
}
/* ==============================
* The End of readdir Madness
* ============================== */
int
fuse_fs_fsyncdir(struct fuse_fs* fs, const char* path, int datasync, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
/* fsyncdir() appeared on FUSE 2.3. */
switch (fs->op_version) {
case 11:
case 21:
case 22:
return -ENOSYS;
#define CALL_FSYNCDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsyncdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsyncdir(path, datasync, fi); \
else \
return -ENOSYS
CALL_FSYNCDIR(23);
CALL_FSYNCDIR(25);
CALL_FSYNCDIR(26);
CALL_FSYNCDIR(28);
CALL_FSYNCDIR(29);
CALL_FSYNCDIR(30);
CALL_FSYNCDIR(34);
CALL_FSYNCDIR(38);
#undef CALL_FSYNCDIR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_releasedir(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.3 didn't have releasedir() and was reading
* directories without opening them. */
case 11:
case 21:
case 22:
return 0; /* Special case */
#define CALL_RELEASEDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->releasedir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->releasedir(path, fi); \
else \
return 0 /* Special case */
CALL_RELEASEDIR(23);
CALL_RELEASEDIR(25);
CALL_RELEASEDIR(26);
CALL_RELEASEDIR(28);
CALL_RELEASEDIR(29);
CALL_RELEASEDIR(30);
CALL_RELEASEDIR(34);
CALL_RELEASEDIR(38);
#undef CALL_RELEASEDIR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_create(struct fuse_fs* fs, const char* path, mode_t mode, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.5 didn't have create(). */
case 11:
case 21:
case 22:
case 23:
return -ENOSYS;
#define CALL_CREATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->create) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->create(path, mode, fi); \
else \
return -ENOSYS
CALL_CREATE(25);
CALL_CREATE(26);
CALL_CREATE(28);
CALL_CREATE(29);
CALL_CREATE(30);
CALL_CREATE(34);
CALL_CREATE(38);
#undef CALL_CREATE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_lock(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi,
int cmd, struct flock* lock) {
clobber_context_user_data(fs);
/* locK() appeared on FUSE 2.6. */
switch (fs->op_version) {
case 11:
case 21:
case 22:
case 23:
case 25:
return -ENOSYS;
#define CALL_LOCK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lock) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lock(path, fi, cmd, lock); \
else \
return -ENOSYS
CALL_LOCK(26);
CALL_LOCK(28);
CALL_LOCK(29);
CALL_LOCK(30);
CALL_LOCK(34);
CALL_LOCK(38);
#undef CALL_LOCK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_flock(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi, int op) {
clobber_context_user_data(fs);
/* flocK() appeared on FUSE 2.9. */
switch (fs->op_version) {
case 11:
case 21:
case 22:
case 23:
case 25:
case 26:
case 28:
return -ENOSYS;
#define CALL_FLOCK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flock) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flock(path, fi, op); \
else \
return -ENOSYS
CALL_FLOCK(29);
CALL_FLOCK(30);
CALL_FLOCK(34);
CALL_FLOCK(38);
#undef CALL_FLOCK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_chmod_v27(struct fuse_fs *fs, const char *path, mode_t mode) {
return fuse_fs_chmod_v30(fs, path, mode, NULL);
}
int
fuse_fs_chmod_v30(struct fuse_fs* fs, const char* path,
mode_t mode, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_CHMOD(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod(path, mode); \
else \
return -ENOSYS
CALL_OLD_CHMOD(11);
CALL_OLD_CHMOD(21);
CALL_OLD_CHMOD(22);
CALL_OLD_CHMOD(23);
CALL_OLD_CHMOD(25);
CALL_OLD_CHMOD(26);
CALL_OLD_CHMOD(28);
CALL_OLD_CHMOD(29);
#undef CALL_OLD_CHMOD
#define CALL_CHMOD(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod(path, mode, fi); \
else \
return -ENOSYS
CALL_CHMOD(30);
CALL_CHMOD(34);
CALL_CHMOD(38);
#undef CALL_CHMOD
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int fuse_fs_chown_v27(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid) {
return fuse_fs_chown_v30(fs, path, uid, gid, NULL);
}
int
fuse_fs_chown_v30(struct fuse_fs* fs, const char* path,
uid_t uid, gid_t gid, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_CHOWN(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown(path, uid, gid); \
else \
return -ENOSYS
CALL_OLD_CHOWN(11);
CALL_OLD_CHOWN(21);
CALL_OLD_CHOWN(22);
CALL_OLD_CHOWN(23);
CALL_OLD_CHOWN(25);
CALL_OLD_CHOWN(26);
CALL_OLD_CHOWN(28);
CALL_OLD_CHOWN(29);
#undef CALL_OLD_CHOWN
#define CALL_CHOWN(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown(path, uid, gid, fi); \
else \
return -ENOSYS
CALL_CHOWN(30);
CALL_CHOWN(34);
CALL_CHOWN(38);
#undef CALL_CHOWN
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int fuse_fs_truncate_v27(struct fuse_fs *fs, const char *path, off_t size) {
return fuse_fs_truncate_v30(fs, path, size, NULL);
}
int
fuse_fs_truncate_v30(struct fuse_fs* fs, const char* path, off_t size, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_OLD_TRUNCATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size); \
else \
return -ENOSYS
CALL_OLD_TRUNCATE(11);
CALL_OLD_TRUNCATE(21);
CALL_OLD_TRUNCATE(22);
CALL_OLD_TRUNCATE(23);
CALL_OLD_TRUNCATE(25);
CALL_OLD_TRUNCATE(26);
CALL_OLD_TRUNCATE(28);
CALL_OLD_TRUNCATE(29);
#undef CALL_OLD_TRUNCATE
#define CALL_TRUNCATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size, fi); \
else \
return -ENOSYS
CALL_TRUNCATE(30);
CALL_TRUNCATE(34);
CALL_TRUNCATE(38);
#undef CALL_TRUNCATE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_ftruncate(struct fuse_fs* fs, const char* path, off_t size, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.5 didn't have ftruncate(). Always fall back to
* truncate(). */
#define CALL_OLD_TRUNCATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size); \
else \
return -ENOSYS
CALL_OLD_TRUNCATE(11);
CALL_OLD_TRUNCATE(21);
CALL_OLD_TRUNCATE(22);
CALL_OLD_TRUNCATE(23);
#undef CALL_OLD_TRUNCATE
/* ftruncate() appeared on FUSE 2.5 and then disappeared on
* FUSE 3.0. Call it if it exists, or fall back to truncate()
* otherwise. */
#define CALL_FTRUNCATE_OR_TRUNCATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ftruncate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ftruncate(path, size, fi); \
else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size); \
else \
return -ENOSYS
CALL_FTRUNCATE_OR_TRUNCATE(25);
CALL_FTRUNCATE_OR_TRUNCATE(26);
CALL_FTRUNCATE_OR_TRUNCATE(28);
CALL_FTRUNCATE_OR_TRUNCATE(29);
#undef CALL_FTRUNCATE_OR_TRUNCATE
/* FUSE >= 3.0 have truncate() but with a different function
* type. */
#define CALL_TRUNCATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size, fi); \
else \
return -ENOSYS
CALL_TRUNCATE(30);
CALL_TRUNCATE(34);
CALL_TRUNCATE(38);
#undef CALL_TRUNCATE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_utimens_v27(struct fuse_fs *fs, const char *path, const struct timespec tv[2]) {
return fuse_fs_utimens_v30(fs, path, tv, NULL);
}
int
fuse_fs_utimens_v30(struct fuse_fs* fs, const char* path,
const struct timespec tv[2], struct fuse_file_info* fi) {
struct utimbuf timbuf;
timbuf.actime = tv[0].tv_sec;
timbuf.modtime = tv[1].tv_sec;
clobber_context_user_data(fs);
switch (fs->op_version) {
/* FUSE < 2.6 didn't have utimens() but had utime()
* instead. */
#define CALL_UTIME(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime(path, &timbuf); \
else \
return -ENOSYS
CALL_UTIME(11);
CALL_UTIME(21);
CALL_UTIME(22);
CALL_UTIME(23);
CALL_UTIME(25);
#undef CALL_UTIME
/* utimens() appeared on FUSE 2.6. Call it if it exists, or fall back to
* utime() otherwise. */
#define CALL_UTIMENS_OR_UTIME(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens(path, tv); \
else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime(path, &timbuf); \
else \
return -ENOSYS
CALL_UTIMENS_OR_UTIME(26);
CALL_UTIMENS_OR_UTIME(28);
CALL_UTIMENS_OR_UTIME(29);
#undef CALL_UTIMENS_OR_UTIME
/* utime() disappeared on FUSE 3.0. */
#define CALL_UTIMENS(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens(path, tv, fi); \
else \
return -ENOSYS
CALL_UTIMENS(30);
CALL_UTIMENS(34);
CALL_UTIMENS(38);
#undef CALL_UTIMENS
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_access(struct fuse_fs* fs, const char* path, int mask) {
clobber_context_user_data(fs);
/* access() appeared on FUSE 2.5. */
switch (fs->op_version) {
case 11:
case 21:
case 22:
case 23:
return -ENOSYS;
#define CALL_ACCESS(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->access) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->access(path, mask); \
else \
return -ENOSYS
CALL_ACCESS(25);
CALL_ACCESS(26);
CALL_ACCESS(28);
CALL_ACCESS(29);
CALL_ACCESS(30);
CALL_ACCESS(34);
CALL_ACCESS(38);
#undef CALL_ACCESS
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_readlink(struct fuse_fs* fs, const char* path, char* buf, size_t len) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_READLINK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readlink) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readlink(path, buf, len); \
else \
return -ENOSYS
CALL_READLINK(11);
CALL_READLINK(21);
CALL_READLINK(22);
CALL_READLINK(23);
CALL_READLINK(25);
CALL_READLINK(26);
CALL_READLINK(28);
CALL_READLINK(29);
CALL_READLINK(30);
CALL_READLINK(34);
CALL_READLINK(38);
#undef CALL_READLINK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_mknod(struct fuse_fs* fs, const char* path, mode_t mode, dev_t rdev) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_MKNOD(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mknod) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mknod(path, mode, rdev); \
else \
return -ENOSYS
CALL_MKNOD(11);
CALL_MKNOD(21);
CALL_MKNOD(22);
CALL_MKNOD(23);
CALL_MKNOD(25);
CALL_MKNOD(26);
CALL_MKNOD(28);
CALL_MKNOD(29);
CALL_MKNOD(30);
CALL_MKNOD(34);
CALL_MKNOD(38);
#undef CALL_MKNOD
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_mkdir(struct fuse_fs* fs, const char* path, mode_t mode) {
clobber_context_user_data(fs);
switch (fs->op_version) {
#define CALL_MKDIR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mkdir) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mkdir(path, mode); \
else \
return -ENOSYS
CALL_MKDIR(11);
CALL_MKDIR(21);
CALL_MKDIR(22);
CALL_MKDIR(23);
CALL_MKDIR(25);
CALL_MKDIR(26);
CALL_MKDIR(28);
CALL_MKDIR(29);
CALL_MKDIR(30);
CALL_MKDIR(34);
CALL_MKDIR(38);
#undef CALL_MKDIR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int fuse_fs_setxattr(struct fuse_fs* fs, const char* path, const char* name,
const char* value, size_t size, int flags) {
clobber_context_user_data(fs);
/* setxattr() appeared on FUSE 2.1. */
switch (fs->op_version) {
case 11:
return -ENOSYS;
#define CALL_SETXATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->setxattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->setxattr(path, name, value, size, flags); \
else \
return -ENOSYS
CALL_SETXATTR(21);
CALL_SETXATTR(22);
CALL_SETXATTR(23);
CALL_SETXATTR(25);
CALL_SETXATTR(26);
CALL_SETXATTR(28);
CALL_SETXATTR(29);
CALL_SETXATTR(30);
CALL_SETXATTR(34);
CALL_SETXATTR(38);
#undef CALL_SETXATTR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_getxattr(struct fuse_fs* fs, const char* path, const char* name,
char* value, size_t size) {
clobber_context_user_data(fs);
/* getxattr() appeared on FUSE 2.1. */
switch (fs->op_version) {
case 11:
return -ENOSYS;
#define CALL_GETXATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getxattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getxattr(path, name, value, size); \
else \
return -ENOSYS
CALL_GETXATTR(21);
CALL_GETXATTR(22);
CALL_GETXATTR(23);
CALL_GETXATTR(25);
CALL_GETXATTR(26);
CALL_GETXATTR(28);
CALL_GETXATTR(29);
CALL_GETXATTR(30);
CALL_GETXATTR(34);
CALL_GETXATTR(38);
#undef CALL_GETXATTR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int fuse_fs_listxattr(struct fuse_fs* fs, const char* path, char* list, size_t size) {
clobber_context_user_data(fs);
/* listxattr() appeared on FUSE 2.1. */
switch (fs->op_version) {
case 11:
return -ENOSYS;
#define CALL_LISTXATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->listxattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->listxattr(path, list, size); \
else \
return -ENOSYS
CALL_LISTXATTR(21);
CALL_LISTXATTR(22);
CALL_LISTXATTR(23);
CALL_LISTXATTR(25);
CALL_LISTXATTR(26);
CALL_LISTXATTR(28);
CALL_LISTXATTR(29);
CALL_LISTXATTR(30);
CALL_LISTXATTR(34);
CALL_LISTXATTR(38);
#undef CALL_LISTXATTR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_removexattr(struct fuse_fs* fs, const char* path, const char* name) {
clobber_context_user_data(fs);
/* removexattr() appeared on FUSE 2.1. */
switch (fs->op_version) {
case 11:
return -ENOSYS;
#define CALL_REMOVEXATTR(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->removexattr) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->removexattr(path, name); \
else \
return -ENOSYS
CALL_REMOVEXATTR(21);
CALL_REMOVEXATTR(22);
CALL_REMOVEXATTR(23);
CALL_REMOVEXATTR(25);
CALL_REMOVEXATTR(26);
CALL_REMOVEXATTR(28);
CALL_REMOVEXATTR(29);
CALL_REMOVEXATTR(30);
CALL_REMOVEXATTR(34);
CALL_REMOVEXATTR(38);
#undef CALL_REMOVEXATTR
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_bmap(struct fuse_fs* fs, const char* path, size_t blocksize, uint64_t *idx) {
clobber_context_user_data(fs);
/* bmap() appeared on FUSE 2.6. */
switch (fs->op_version) {
case 11:
case 22:
case 23:
case 25:
return -ENOSYS;
#define CALL_BMAP(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->bmap) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->bmap(path, blocksize, idx); \
else \
return -ENOSYS
CALL_BMAP(26);
CALL_BMAP(28);
CALL_BMAP(29);
CALL_BMAP(30);
CALL_BMAP(34);
CALL_BMAP(38);
#undef CALL_BMAP
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int fuse_fs_ioctl_v28(struct fuse_fs* fs, const char* path, int cmd, void* arg,
struct fuse_file_info* fi, unsigned int flags, void* data) {
return fuse_fs_ioctl_v35(fs, path, (unsigned int)cmd, arg, fi, flags, data);
}
int fuse_fs_ioctl_v35(struct fuse_fs* fs, const char* path, unsigned int cmd, void* arg,
struct fuse_file_info* fi, unsigned int flags, void* data) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* ioctl() appeared on FUSE 2.8 but with (int)cmd. */
case 11:
case 22:
case 23:
case 25:
case 26:
return -ENOSYS;
#define CALL_OLD_IOCTL(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl(path, (int)cmd, arg, fi, flags, data); \
else \
return -ENOSYS
CALL_OLD_IOCTL(28);
CALL_OLD_IOCTL(29);
CALL_OLD_IOCTL(30);
CALL_OLD_IOCTL(34);
#undef CALL_OLD_IOCTL
/* It was then changed to (unsigned int)cmd on FUSE 3.5. */
#define CALL_IOCTL(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl(path, cmd, arg, fi, flags, data); \
else \
return -ENOSYS
CALL_IOCTL(35);
CALL_IOCTL(38);
#undef CALL_IOCTL
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_poll(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi,
struct fuse_pollhandle* ph, unsigned* reventsp) {
clobber_context_user_data(fs);
/* poll() appeared on FUSE 2.8. */
switch (fs->op_version) {
case 11:
case 22:
case 23:
case 25:
case 26:
return -ENOSYS;
#define CALL_POLL(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->poll) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->poll(path, fi, ph, reventsp); \
else \
return -ENOSYS
CALL_POLL(28);
CALL_POLL(29);
CALL_POLL(30);
CALL_POLL(34);
CALL_POLL(38);
#undef CALL_POLL
default:
UNKNOWN_VERSION(fs->op_version);
}
}
int
fuse_fs_fallocate(struct fuse_fs* fs, const char* path, int mode, off_t offset,
off_t length, struct fuse_file_info* fi) {
clobber_context_user_data(fs);
/* fallocate() appeared on FUSE 2.9. */
switch (fs->op_version) {
case 11:
case 22:
case 23:
case 25:
case 26:
case 28:
return -ENOSYS;
#define CALL_FALLOCATE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fallocate) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fallocate(path, mode, offset, length, fi); \
else \
return -ENOSYS
CALL_FALLOCATE(29);
CALL_FALLOCATE(30);
CALL_FALLOCATE(34);
CALL_FALLOCATE(38);
#undef CALL_FALLOCATE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
ssize_t
fuse_fs_copy_file_range(struct fuse_fs *fs,
const char *path_in, struct fuse_file_info *fi_in, off_t off_in,
const char *path_out, struct fuse_file_info *fi_out, off_t off_out,
size_t len, int flags) {
clobber_context_user_data(fs);
/* copy_file_range() appeared on FUSE 3.4. */
switch (fs->op_version) {
case 11:
case 22:
case 23:
case 25:
case 26:
case 28:
case 29:
case 30:
return -ENOSYS;
#define CALL_COPY_FILE_RANGE(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->copy_file_range) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->copy_file_range(path_in, fi_in, off_in, path_out, fi_out, off_out, len, flags); \
else \
return -ENOSYS
CALL_COPY_FILE_RANGE(34);
CALL_COPY_FILE_RANGE(38);
#undef CALL_COPY_FILE_RANGE
default:
UNKNOWN_VERSION(fs->op_version);
}
}
off_t
fuse_fs_lseek(struct fuse_fs* fs, const char* path, off_t off, int whence,
struct fuse_file_info* fi) {
clobber_context_user_data(fs);
/* lseek() appeared on FUSE 3.8. */
switch (fs->op_version) {
case 11:
case 22:
case 23:
case 25:
case 26:
case 28:
case 29:
case 30:
case 34:
return -ENOSYS;
#define CALL_LSEEK(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lseek) \
return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lseek(path, off, whence, fi); \
else \
return -ENOSYS
CALL_LSEEK(38);
#undef CALL_LSEEK
default:
UNKNOWN_VERSION(fs->op_version);
}
}
void
fuse_fs_init_v27(struct fuse_fs *fs, struct fuse_conn_info *conn) {
fuse_fs_init_v30(fs, conn, NULL);
}
void
fuse_fs_init_v30(struct fuse_fs* fs, struct fuse_conn_info* conn,
struct fuse_config* cfg) {
clobber_context_user_data(fs);
switch (fs->op_version) {
case 11:
case 21:
case 22:
break;
/* init() appeared on FUSE 2.3 as init(void). */
#define CALL_NULLARY_INIT(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init) \
fs->user_data = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init(); \
break
CALL_NULLARY_INIT(23);
CALL_NULLARY_INIT(25);
#undef CALL_NULLARY_INIT
/* It was changed to init(struct fuse_conn_info*) on FUSE
* 2.6. */
#define CALL_UNARY_INIT(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init) \
fs->user_data = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init(conn); \
break
CALL_UNARY_INIT(26);
CALL_UNARY_INIT(28);
CALL_UNARY_INIT(29);
#undef CALL_INIT
/* It was again changed to init(struct fuse_conn_info*, struct
* fuse_config*) on FUSE 3.0. */
#define CALL_BINARY_INIT(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init) \
fs->user_data = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init(conn, cfg); \
break
CALL_BINARY_INIT(30);
CALL_BINARY_INIT(34);
CALL_BINARY_INIT(38);
#undef CALL_BINARY_INIT
default:
UNKNOWN_VERSION(fs->op_version);
}
}
void
fuse_fs_destroy(struct fuse_fs *fs) {
clobber_context_user_data(fs);
switch (fs->op_version) {
/* destroy() appeared on FUSE 2.3. */
case 11:
case 21:
case 22:
break;
#define CALL_DESTROY(VER) \
case VER: \
if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->destroy) \
((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->destroy(fs->user_data); \
break
CALL_DESTROY(23);
CALL_DESTROY(25);
CALL_DESTROY(26);
CALL_DESTROY(28);
CALL_DESTROY(29);
CALL_DESTROY(30);
CALL_DESTROY(34);
CALL_DESTROY(38);
#undef CALL_DESTROY
default:
UNKNOWN_VERSION(fs->op_version);
}
/* fuse_fs_destroy(3) also deallocates struct fuse_fs itself. */
free(fs->op);
free(fs);
}
|