forked from mxmlnkn/mfusepy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmfusepy.py
More file actions
2338 lines (2022 loc) · 95.9 KB
/
mfusepy.py
File metadata and controls
2338 lines (2022 loc) · 95.9 KB
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
# Copyright (c) 2012 Terence Honles <terence@honles.com> (maintainer)
# Copyright (c) 2008 Giorgos Verigakis <verigak@gmail.com> (author)
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# Note that for ABI forward compatibility and other issues, most C-types should be initialized
# to 0 and the ctypes module does that for us out of the box!
# https://github.com/python/cpython/blob/f8a736b8e14ab839e1193cb1d3955b61c316d048/Lib/test/test_ctypes/test_numbers.py#L95
import contextlib
import ctypes
import errno
import functools
import inspect
import logging
import os
import platform
import warnings
from collections.abc import Iterable, Sequence
from ctypes import CFUNCTYPE, POINTER, c_char_p, c_int, c_size_t, c_ssize_t, c_uint, c_void_p
from ctypes.util import find_library
from signal import SIG_DFL, SIGINT, SIGTERM, signal
from stat import S_IFDIR
from typing import TYPE_CHECKING, Any, Optional, Union, get_type_hints
FieldsEntry = Union[tuple[str, type], tuple[str, type, int]]
BitFieldsEntry = tuple[str, type, int]
ReadDirResult = Iterable[Union[str, tuple[str, dict[str, int], int], tuple[str, int, int]]]
if TYPE_CHECKING:
c_byte_p = ctypes._Pointer[ctypes.c_byte] # noqa: W212
c_uint64_p = ctypes._Pointer[ctypes.c_uint64] # noqa: W212
else:
c_byte_p = ctypes.POINTER(ctypes.c_byte)
c_uint64_p = ctypes.POINTER(ctypes.c_uint64)
log = logging.getLogger("fuse")
_system = platform.system()
_machine = platform.machine()
if _system == 'Windows' or _system.startswith('CYGWIN'):
# NOTE:
#
# sizeof(long)==4 on Windows 32-bit and 64-bit
# sizeof(long)==4 on Cygwin 32-bit and ==8 on Cygwin 64-bit
#
# We have to fix up c_long and c_ulong so that it matches the
# Cygwin (and UNIX) sizes when run on Windows.
import sys
c_win_long = ctypes.c_int64 if sys.maxsize > 0xFFFFFFFF else ctypes.c_int32
c_win_ulong = ctypes.c_uint64 if sys.maxsize > 0xFFFFFFFF else ctypes.c_uint32
class c_timespec(ctypes.Structure):
if _system == 'Windows' or _system.startswith('CYGWIN'):
_fields_ = [('tv_sec', c_win_long), ('tv_nsec', c_win_long)]
elif _system in ('OpenBSD', 'FreeBSD', 'NetBSD'):
# https://github.com/NetBSD/src/blob/netbsd-10/sys/sys/timespec.h#L47
# https://github.com/NetBSD/src/blob/netbsd-10/sys/arch/hpc/stand/include/machine/types.h#L40
_fields_ = [('tv_sec', ctypes.c_int64), ('tv_nsec', ctypes.c_long)]
else:
_fields_ = [('tv_sec', ctypes.c_long), ('tv_nsec', ctypes.c_long)]
class c_utimbuf(ctypes.Structure):
_fields_ = [('actime', c_timespec), ('modtime', c_timespec)]
# Beware that FUSE_LIBRARY_PATH path was unchecked! If it is set to libfuse3.so.3.14.0,
# then it will mount without error, but when trying to access the mount point, will give:
# Uncaught exception from FUSE operation setxattr, returning errno.EINVAL:
# 'utf-8' codec can't decode byte 0xe8 in position 1: invalid continuation byte
# Traceback (most recent call last):
# File "fuse.py", line 820, in _wrapper
# return func(*args, **kwargs) or 0
# ^^^^^^^^^^^^^^^^^^^^^
# File "fuse.py", line 991, in setxattr
# name.decode(self.encoding),
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
# UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 1:
# invalid continuation byte
_libfuse_path = os.environ.get('FUSE_LIBRARY_PATH')
if not _libfuse_path:
if _system == 'Darwin':
# libfuse dependency
_libiconv = ctypes.CDLL(find_library('iconv'), ctypes.RTLD_GLOBAL)
_libfuse_path = (
find_library('fuse4x') or find_library('osxfuse') or find_library('fuse') or find_library('fuse-t')
)
elif _system == 'Windows':
# pytype: disable=module-attr
try:
import _winreg as reg # pytype: disable=import-error
except ImportError:
import winreg as reg # pytype: disable=import-error
def reg32_get_value(rootkey, keyname, valname):
key, val = None, None
try:
key = reg.OpenKey(
rootkey, keyname, 0, reg.KEY_READ | reg.KEY_WOW64_32KEY
) # pytype: disable=import-error
val = str(reg.QueryValueEx(key, valname)[0])
except OSError: # pylint: disable=undefined-variable # pytype: disable=name-error
pass
finally:
if key is not None:
reg.CloseKey(key)
return val
_libfuse_path = reg32_get_value(reg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WinFsp", r"InstallDir")
if _libfuse_path:
arch = "x64" if sys.maxsize > 0xFFFFFFFF else "x86"
_libfuse_path += f"bin\\winfsp-{arch}.dll"
# pytype: enable=module-attr
elif _libfuse_name := os.environ.get('FUSE_LIBRARY_NAME'):
_libfuse_path = find_library(_libfuse_name)
else:
_libfuse_path = find_library('fuse')
if not _libfuse_path:
_libfuse_path = find_library('fuse3')
if not _libfuse_path:
raise OSError('Unable to find libfuse')
_libfuse = ctypes.CDLL(_libfuse_path)
if _system == 'Darwin' and hasattr(_libfuse, 'macfuse_version'):
_system = 'Darwin-MacFuse'
def get_fuse_version(libfuse):
version = libfuse.fuse_version()
if version < 100:
return version // 10, version % 10
if version < 1000:
return version // 100, version % 100
raise AttributeError(f"Version {version} of found library {_libfuse._name} cannot be parsed!")
fuse_version_major, fuse_version_minor = get_fuse_version(_libfuse)
if fuse_version_major == 2 and fuse_version_minor < 6:
raise AttributeError(
f"Found library {_libfuse_path} is too old: {fuse_version_major}.{fuse_version_minor}. "
"There have been several ABI breaks in each version. Libfuse < 2.6 is not supported!"
)
if fuse_version_major != 2 and not (fuse_version_major == 3 and _system == 'Linux'):
raise AttributeError(
f"Found library {_libfuse_path} has wrong major version: {fuse_version_major}. Expected FUSE 2!"
)
# Some platforms, like macOS 15, define ENOATTR and ENODATA with different values.
# For missing xattrs, errno is set to the ENOATTR value (e.g. in getxattr and removexattr).
# But, on some other platforms, ENOATTR is missing; use the same value as ENODATA there.
# We have a test that makes sure this is not None for all platforms we test on.
ENOATTR = getattr(errno, 'ENOATTR', getattr(errno, 'ENODATA', None))
# Check FUSE major version changes by cloning https://github.com/libfuse/libfuse.git
# and check the diff with:
# git diff -w fuse-2.9.9 fuse-3.0.0 include/fuse.h
# or with comments stripped and diffed:
# colordiff <( gcc -fpreprocessed -dD -E -P -Wno-all -x c \
# <( git show fuse-2.9.9:include/fuse.h ) ) \
# <( gcc -fpreprocessed -dD -E -P -Wno-all -x c \
# <( git show fuse-3.0.2:include/fuse.h ) )
# and repeat for fuse_common.h and possibly over included headers, or check
# the official changelog:
# https://github.com/libfuse/libfuse/blob/master/ChangeLog.rst#libfuse-300-2016-12-08
#
# Header changes summarized:
# - Added enum fuse_readdir_flags, which is added as last argument to readdir.
# - Added enum fuse_fill_dir_flags, which is added to the fuse_fill_dir_t
# function callback argument to readdir.
# - Removed fuse_operations.getdir and related types fuse_dirh_t.
# Was already deprecated in favor of readdir.
# - Added fuse_fill_dir_flags to fuse_dirfil_t callback function pointer that
# is used for readdir.
# - Added fuse_config struct, which is the new second parameter of
# fuse_operations.init.
# - Added new fuse_file_info struct (fuse_common.h), which is added as
# additional arguments to:
# - Added as last argument to: getattr, chmod, chown, truncate, utimens.
# - This argument already existed for: open, read, write, flush, release, fsync,
# opendir, readdir, releasedir, fsyncdir, create, ftruncate, fgetattr, lock,
# ioctl, read_buf, fallocate, poll, write_buf, flock.
# - Added unsigned int flags to rename.
# - Removed utime in favor of utimens, which has been added in libFUSE 2.6.
# - Removed deprecated functions: fuse_fs_fgetattr, fuse_fs_ftruncate,
# fuse_invalidate, and fuse_is_lib_option.
# - Removed flags from fuse_operations: flag_nullpath_ok, flag_nopath,
# flag_utime_omit_ok, flag_reserved. These are now in the new fuse_config struct.
# - Added version argument to fuse_main_real, but this should not be called directly
# anyway and instead the fuse_main wrapper, which is unchanged should be called.
# - Removed first argument struct fuse_chan* from fuse_new.
# - Removed fuse_chan* return value from fuse_mount and fuse_chan* argument from
# fuse_unmount (and moved both methods from fuse_common.h into fuse.h).
# - Added int clone_fd argument to fuse_loop_mt.
# - Added macro definitions for constants FUSE_CAP_* to fuse_common.h.
# - Added fuse_apply_conn_info_opts to fuse_common.h, see the official changelog
# for reasoning.
# Set non-FUSE-specific kernel type definitions.
if _system in ('Darwin', 'Darwin-MacFuse', 'FreeBSD'):
ENOTSUP = 45
c_dev_t: type = ctypes.c_int32
c_fsblkcnt_t: type = ctypes.c_ulong
c_fsfilcnt_t: type = ctypes.c_ulong
c_gid_t: type = ctypes.c_uint32
c_mode_t: type = ctypes.c_uint16
c_off_t: type = ctypes.c_int64
c_pid_t: type = ctypes.c_int32
c_uid_t: type = ctypes.c_uint32
setxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
ctypes.c_int,
ctypes.c_uint32,
)
getxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
ctypes.c_uint32,
)
if _system == 'Darwin':
c_fsblkcnt_t: type = ctypes.c_uint # type: ignore[no-redef]
c_fsfilcnt_t: type = ctypes.c_uint # type: ignore[no-redef]
# https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/bsd/sys/stat.h
_c_stat__fields_: Sequence[FieldsEntry] = [
('st_dev', c_dev_t),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_uint16),
('st_ino', ctypes.c_uint64),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_birthtimespec', c_timespec),
('st_size', c_off_t),
('st_blocks', ctypes.c_int64),
('st_blksize', ctypes.c_int32),
('st_flags', ctypes.c_int32),
('st_gen', ctypes.c_int32),
('st_lspare', ctypes.c_int32),
('st_qspare', ctypes.c_int64 * 2),
]
elif _system == 'FreeBSD':
# FreeBSD amd64 struct stat layout
# https://github.com/freebsd/freebsd-src/blob/releng/14.3/sys/sys/stat.h#L159
# Use explicit 64-bit integers for dev and ino to avoid changing global typedefs.
_c_stat__fields_ = [
('st_dev', ctypes.c_uint64),
('st_ino', ctypes.c_uint64),
('st_nlink', ctypes.c_uint64),
('st_mode', c_mode_t),
('st_bsdflags', ctypes.c_int16),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_padding1', ctypes.c_uint32),
('st_rdev', ctypes.c_uint64),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_birthtimespec', c_timespec),
('st_size', c_off_t),
('st_blocks', ctypes.c_int64),
('st_blksize', ctypes.c_uint32),
('st_flags', ctypes.c_uint32),
('st_gen', ctypes.c_uint32),
('st_filerev', ctypes.c_uint64),
('st_spare', ctypes.c_int64 * 9),
]
else:
# Darwin-MacFuse fallback (legacy)
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_ino', ctypes.c_uint32),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_uint16),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_size', c_off_t),
('st_blocks', ctypes.c_int64),
('st_blksize', ctypes.c_int32),
]
elif _system == 'Linux':
ENOTSUP = 95
# sys/statvfs.h
c_fsblkcnt_t = ctypes.c_ulonglong
c_fsfilcnt_t = ctypes.c_ulonglong
# https://man7.org/linux/man-pages/man0/sys_types.h.0p.html
c_dev_t = ctypes.c_ulonglong
c_gid_t = ctypes.c_uint
c_mode_t = ctypes.c_uint
c_off_t = ctypes.c_longlong
c_pid_t = ctypes.c_int
c_uid_t = ctypes.c_uint
# sys/xattr.h
setxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, c_byte_p, ctypes.c_size_t, ctypes.c_int
)
getxattr_t = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, c_byte_p, ctypes.c_size_t)
# https://github.com/torvalds/linux/blob/v6.18/arch/x86/include/uapi/asm/stat.h#L83-L104
# -> See /arch/<arch> subfolders. Unfortunately, arch=arm64 does not have stat.h for some reason.
if _machine == 'x86_64':
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_ino', ctypes.c_ulong),
('st_nlink', ctypes.c_ulong),
('st_mode', c_mode_t),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('__pad0', ctypes.c_int),
('st_rdev', c_dev_t),
('st_size', c_off_t),
('st_blksize', ctypes.c_long),
('st_blocks', ctypes.c_long),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('reserved', ctypes.c_long * 3),
]
elif _machine == 'mips':
_c_stat__fields_ = [
('st_dev', c_dev_t),
('__pad1_1', ctypes.c_ulong),
('__pad1_2', ctypes.c_ulong),
('__pad1_3', ctypes.c_ulong),
('st_ino', ctypes.c_ulong),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_ulong),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('__pad2_1', ctypes.c_ulong),
('__pad2_2', ctypes.c_ulong),
('st_size', c_off_t),
('__pad3', ctypes.c_ulong),
('st_atimespec', c_timespec),
('__pad4', ctypes.c_ulong),
('st_mtimespec', c_timespec),
('__pad5', ctypes.c_ulong),
('st_ctimespec', c_timespec),
('__pad6', ctypes.c_ulong),
('st_blksize', ctypes.c_long),
('st_blocks', ctypes.c_long),
('__pad7_1', ctypes.c_ulong),
('__pad7_2', ctypes.c_ulong),
('__pad7_3', ctypes.c_ulong),
('__pad7_4', ctypes.c_ulong),
('__pad7_5', ctypes.c_ulong),
('__pad7_6', ctypes.c_ulong),
('__pad7_7', ctypes.c_ulong),
('__pad7_8', ctypes.c_ulong),
('__pad7_9', ctypes.c_ulong),
('__pad7_10', ctypes.c_ulong),
('__pad7_11', ctypes.c_ulong),
('__pad7_12', ctypes.c_ulong),
('__pad7_13', ctypes.c_ulong),
('__pad7_14', ctypes.c_ulong),
]
elif _machine == 'ppc':
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_ino', ctypes.c_ulonglong),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_uint),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('__pad2', ctypes.c_ushort),
('st_size', c_off_t),
('st_blksize', ctypes.c_long),
('st_blocks', ctypes.c_longlong),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
]
elif _machine in ('ppc64', 'ppc64le'):
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_ino', ctypes.c_ulong),
('st_nlink', ctypes.c_ulong),
('st_mode', c_mode_t),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('__pad', ctypes.c_uint),
('st_rdev', c_dev_t),
('st_size', c_off_t),
('st_blksize', ctypes.c_long),
('st_blocks', ctypes.c_long),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
]
elif _machine == 'aarch64':
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_ino', ctypes.c_ulong),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_uint),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('__pad1', ctypes.c_ulong),
('st_size', c_off_t),
('st_blksize', ctypes.c_int),
('__pad2', ctypes.c_int),
('st_blocks', ctypes.c_long),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('__reserved', ctypes.c_ulong), # unclear what this is
]
else:
# i686, use as fallback for everything else
_c_stat__fields_ = [
('st_dev', c_dev_t),
('__pad1', ctypes.c_ushort),
('__st_ino', ctypes.c_ulong),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_uint),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('__pad2', ctypes.c_ushort),
('st_size', c_off_t),
('st_blksize', ctypes.c_long),
('st_blocks', ctypes.c_longlong),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_ino', ctypes.c_ulonglong),
]
elif _system == 'Windows' or _system.startswith('CYGWIN'):
ENOTSUP = 129 if _system == 'Windows' else 134
c_dev_t = ctypes.c_uint
c_fsblkcnt_t = c_win_ulong
c_fsfilcnt_t = c_win_ulong
c_gid_t = ctypes.c_uint
c_mode_t = ctypes.c_uint
c_off_t = ctypes.c_longlong
c_pid_t = ctypes.c_int
c_uid_t = ctypes.c_uint
setxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
ctypes.c_int,
)
getxattr_t = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_char_p, ctypes.c_char_p, c_byte_p, ctypes.c_size_t)
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_ino', ctypes.c_ulonglong),
('st_mode', c_mode_t),
('st_nlink', ctypes.c_ushort),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('st_size', c_off_t),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_blksize', ctypes.c_int),
('st_blocks', ctypes.c_longlong),
('st_birthtimespec', c_timespec),
]
elif _system == 'OpenBSD':
ENOTSUP = 91
c_dev_t = ctypes.c_int32
c_uid_t = ctypes.c_uint32
c_gid_t = ctypes.c_uint32
c_mode_t = ctypes.c_uint32
c_off_t = ctypes.c_int64
c_pid_t = ctypes.c_int32
c_ino_t = ctypes.c_uint64
c_nlink_t = ctypes.c_uint32
c_blkcnt_t = ctypes.c_int64
c_blksize_t = ctypes.c_int32
setxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
ctypes.c_int,
)
getxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
)
c_fsblkcnt_t = ctypes.c_uint64
c_fsfilcnt_t = ctypes.c_uint64
_c_stat__fields_ = [
('st_mode', c_mode_t),
('st_dev', c_dev_t),
('st_ino', c_ino_t),
('st_nlink', c_nlink_t),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('st_rdev', c_dev_t),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_size', c_off_t),
('st_blocks', c_blkcnt_t),
('st_blksize', c_blksize_t),
('st_flags', ctypes.c_uint32),
('st_gen', ctypes.c_uint32),
('st_birthtimespec', c_timespec),
]
elif _system == 'NetBSD':
ENOTSUP = 45
c_dev_t = ctypes.c_uint64
c_uid_t = ctypes.c_uint32
c_gid_t = ctypes.c_uint32
c_mode_t = ctypes.c_uint32
c_off_t = ctypes.c_int64
c_pid_t = ctypes.c_int32
setxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.POINTER(ctypes.c_byte),
ctypes.c_size_t,
ctypes.c_int,
)
getxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int64,
ctypes.c_char_p,
ctypes.c_char_p,
ctypes.POINTER(ctypes.c_byte),
ctypes.c_size_t,
)
c_fsblkcnt_t = ctypes.c_uint64
c_fsfilcnt_t = ctypes.c_uint64
# https://github.com/NetBSD/src/blob/2a172fadee81450ba400e49c8ed98857bedec65c/sys/sys/stat.h#L59-L89
_c_stat__fields_ = [
('st_dev', c_dev_t),
('st_mode', c_mode_t),
('_padding0', ctypes.c_uint32), # alignment padding implied by the next member
('st_ino', ctypes.c_uint64),
('st_nlink', ctypes.c_uint32),
('st_uid', c_uid_t),
('st_gid', c_gid_t),
('_padding1', ctypes.c_uint32), # alignment padding implied by the next member
('st_rdev', c_dev_t),
('st_atimespec', c_timespec),
('st_mtimespec', c_timespec),
('st_ctimespec', c_timespec),
('st_birthtimespec', c_timespec),
('st_size', c_off_t),
('st_blocks', ctypes.c_int64),
('st_blksize', ctypes.c_uint32),
('st_flags', ctypes.c_uint32),
('st_gen', ctypes.c_uint32),
('st_spare', ctypes.c_uint32 * 2),
]
else:
raise NotImplementedError(_system + ' is not supported.')
class c_stat(ctypes.Structure):
_fields_ = _c_stat__fields_
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_statvfs.h.html
if _system == 'FreeBSD':
c_fsblkcnt_t = ctypes.c_uint64
c_fsfilcnt_t = ctypes.c_uint64
setxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
ctypes.c_int,
)
getxattr_t = ctypes.CFUNCTYPE(
ctypes.c_int,
ctypes.c_char_p,
ctypes.c_char_p,
c_byte_p,
ctypes.c_size_t,
)
class c_statvfs(ctypes.Structure):
if _system == 'FreeBSD':
# https://github.com/freebsd/freebsd-src/blob/b1c3a4d75f4ff74218434a11cdd4e56632e13711/sys/sys/statvfs.h#L57-L68
_fields_ = [
('f_bavail', c_fsblkcnt_t),
('f_bfree', c_fsblkcnt_t),
('f_blocks', c_fsblkcnt_t),
('f_favail', c_fsfilcnt_t),
('f_ffree', c_fsfilcnt_t),
('f_files', c_fsfilcnt_t),
('f_bsize', ctypes.c_ulong),
('f_flag', ctypes.c_ulong),
('f_frsize', ctypes.c_ulong),
('f_fsid', ctypes.c_ulong),
('f_namemax', ctypes.c_ulong),
]
elif _system == 'Windows' or _system.startswith('CYGWIN'):
_fields_ = [
('f_bsize', c_win_ulong),
('f_frsize', c_win_ulong),
('f_blocks', c_fsblkcnt_t),
('f_bfree', c_fsblkcnt_t),
('f_bavail', c_fsblkcnt_t),
('f_files', c_fsfilcnt_t),
('f_ffree', c_fsfilcnt_t),
('f_favail', c_fsfilcnt_t),
('f_fsid', c_win_ulong),
('f_flag', c_win_ulong),
('f_namemax', c_win_ulong),
]
elif _system == 'NetBSD':
# https://github.com/NetBSD/src/blob/2a172fadee81450ba400e49c8ed98857bedec65c/sys/sys/statvfs.h#L66-L100
_fields_ = [
('f_flag', ctypes.c_ulong),
('f_bsize', ctypes.c_ulong),
('f_frsize', ctypes.c_ulong),
('f_iosize', ctypes.c_ulong),
('f_blocks', c_fsblkcnt_t),
('f_bfree', c_fsblkcnt_t),
('f_bavail', c_fsblkcnt_t),
('f_bresvd', c_fsblkcnt_t),
('f_files', c_fsfilcnt_t),
('f_ffree', c_fsfilcnt_t),
('f_favail', c_fsfilcnt_t),
('f_fresvd', c_fsfilcnt_t),
('f_syncreads', ctypes.c_uint64),
('f_syncwrites', ctypes.c_uint64),
('f_asyncreads', ctypes.c_uint64),
('f_asyncwrites', ctypes.c_uint64),
('f_fsidx', ctypes.c_int32 * 2), # NetBSD compatible fsid
('f_fsid', ctypes.c_ulong), # POSIX compatible fsid
('f_namemax', ctypes.c_ulong),
('f_owner', c_uid_t),
('f_spare', ctypes.c_uint64 * 4),
('f_fstypename', ctypes.c_char * 32),
('f_mntonname', ctypes.c_char * 1024),
('f_mntfromname', ctypes.c_char * 1024),
('f_mntfromlabel', ctypes.c_char * 1024),
]
else:
# https://sourceware.org/git?p=glibc.git;a=blob;f=bits/statvfs.h;h=ea89d9004d834c81874de00b5e3f5617d3096ccc;hb=HEAD#l33
_fields_ = [
('f_bsize', ctypes.c_ulong),
('f_frsize', ctypes.c_ulong),
('f_blocks', c_fsblkcnt_t),
('f_bfree', c_fsblkcnt_t),
('f_bavail', c_fsblkcnt_t),
('f_files', c_fsfilcnt_t),
('f_ffree', c_fsfilcnt_t),
('f_favail', c_fsfilcnt_t),
('f_fsid', ctypes.c_ulong),
('f_flag', ctypes.c_ulong),
('f_namemax', ctypes.c_ulong),
]
if _system == 'Linux': # Linux x86_64 and aarch64
_fields_ += [
('f_type', ctypes.c_uint),
('__f_spare', ctypes.c_uint * 5),
]
if _system == 'Linux':
# https://github.com/torvalds/linux/blob/20371ba120635d9ab7fc7670497105af8f33eb08/include/uapi/asm-generic/fcntl.h#L195
class c_flock_t(ctypes.Structure): # type: ignore
_fields_ = [
('l_type', ctypes.c_short),
('l_whence', ctypes.c_short),
('l_start', c_off_t),
('l_len', c_off_t),
('l_pid', c_pid_t),
('l_sysid', ctypes.c_long), # not always present
]
elif _system == 'OpenBSD':
# https://github.com/openbsd/src/blob/a465f6177bcfdb2ffa9f98c7ca0780392688fc0d/sys/sys/fcntl.h#L180
class c_flock_t(ctypes.Structure): # type: ignore
_fields_ = [
('l_start', c_off_t), # starting offset
('l_len', c_off_t), # len = 0 means until end of file
('l_pid', c_pid_t), # lock owner
('l_type', ctypes.c_short), # lock type: read/write, etc.
('l_whence', ctypes.c_short), # type of l_start
]
else:
c_flock_t = ctypes.c_void_p # type: ignore
# fuse_file_info as defined in fuse_common.h. Changes in FUSE 3:
# - fh_old was removed
# - poll_events was added
# - writepage was added to the bitfield, but the padding was not decreased,
# so now there are 33 bits in total, which probably lead to some unwanted
# padding in libfuse 3.0.2. This has been made explicit since libfuse 3.7.0:
# https://github.com/libfuse/libfuse/commit/1d8e8ca94a3faa635afd1a3bd8d7d26472063a3f
# - 3.0.0 -> 3.4.2: no change (flags and padding did add up to 33 bits from the beginning)
# - 3.4.2 -> 3.5.0: cache_readdir added correctly
# - 3.5.0 -> 3.6.2: no change
# - 3.6.2 -> 3.7.0: padding 2 was explicitly added but did exist because of alignment
# - 3.7.0 -> 3.10.5: no change
# - 3.10.5 -> 3.11.0: noflush added correctly
# - 3.11.0 -> 3.13.1: no change
# - 3.13.1 -> 3.14.1: parallel_direct_writes was added in the middle.
# Padding was correctly decreased by 1.
# - 3.14.1 -> 3.16.2: no change
_fuse_int32 = ctypes.c_int32 if (fuse_version_major, fuse_version_minor) >= (3, 17) else ctypes.c_int
_fuse_uint32 = ctypes.c_uint32 if (fuse_version_major, fuse_version_minor) >= (3, 17) else ctypes.c_uint
_fuse_file_info_fields_: list[FieldsEntry] = []
_fuse_file_info_fields_bitfield: list[BitFieldsEntry] = []
# Bogus check. It fixes the struct for NetBSD, but it makes the examples not run anymore!
if _system == 'NetBSD_False':
# NetBSD has its own FUSE library reimplementation with mismatching struct layouts!
# writepage is a bitfield (as in libFUSE 3.x), but the fh_old member still exists and the reported version is 2.9!
# https://www.netbsd.org/docs/puffs/
# https://github.com/NetBSD/src/blob/netbsd-11/lib/librefuse/fuse.h#L100-L129
# https://github.com/NetBSD/src/blob/netbsd-10/lib/librefuse/fuse.h#L100-L129
# - fuse_file_info is unchanged between 10 and 11
# - FUSE_USE_VERSION is not set, but is set to _REFUSE_VERSION_ (3.10) with a warning if not set!
# - However, the CI prints FUSE version 2.9?!
# - Seems there is no sane way to get the correct compiled version! This is again an absolute shit show!
# https://github.com/NetBSD/src/blob/netbsd-9/lib/librefuse/fuse.h#L51-L61
# - fuse_file_info looks quite different and version is specified as 2.6!
# - #define FUSE_USE_VERSION 26
fuse_version = (fuse_version_major, fuse_version_minor)
_fuse_file_info_fields_ = [
('flags', ctypes.c_int32),
('fh_old', ctypes.c_uint32),
]
if fuse_version >= (2, 9):
_fuse_file_info_fields_bitfield += [('writepage', ctypes.c_int32, 1)]
else:
_fuse_file_info_fields_ += [('writepage', ctypes.c_int32)]
_fuse_file_info_fields_bitfield += [
('direct_io', ctypes.c_uint32, 1), # Introduced in FUSE 2.4
('keep_cache', ctypes.c_uint32, 1), # Introduced in FUSE 2.4
('flush', ctypes.c_uint32, 1), # Introduced in FUSE 2.6
]
if fuse_version >= (2, 9):
_fuse_file_info_fields_bitfield += [
('nonseekable', ctypes.c_uint, 1), # Introduced in FUSE 2.8
('flock_release', ctypes.c_uint, 1), # Introduced in FUSE 2.9
('cache_readdir', ctypes.c_uint, 1), # Introduced in FUSE 3.5
]
_fuse_file_info_flag_count = sum(x[2] for x in _fuse_file_info_fields_bitfield)
assert _fuse_file_info_flag_count < ctypes.sizeof(_fuse_uint32) * 8
_fuse_file_info_fields_ += _fuse_file_info_fields_bitfield
_fuse_file_info_fields_ += [
('padding', _fuse_uint32, ctypes.sizeof(_fuse_uint32) * 8 - _fuse_file_info_flag_count),
('fh', ctypes.c_uint64),
('lock_owner', ctypes.c_uint64),
]
if fuse_version >= (2, 9):
_fuse_file_info_fields_ += [('poll_events', ctypes.c_uint32)]
elif fuse_version_major == 2:
_fh_old_type = ctypes.c_uint if _system == 'OpenBSD' else ctypes.c_ulong
_fuse_file_info_fields_ = [
('flags', ctypes.c_int),
('fh_old', _fh_old_type),
('writepage', ctypes.c_int),
('direct_io', ctypes.c_uint, 1), # Introduced in libfuse 2.4
('keep_cache', ctypes.c_uint, 1), # Introduced in libfuse 2.4
('flush', ctypes.c_uint, 1), # Introduced in libfuse 2.6
('nonseekable', ctypes.c_uint, 1), # Introduced in libfuse 2.8
('flock_release', ctypes.c_uint, 1), # Introduced in libfuse 2.9
('padding', ctypes.c_uint, 27),
('fh', ctypes.c_uint64),
('lock_owner', ctypes.c_uint64),
]
elif fuse_version_major == 3:
_fuse_file_info_fields_ = [('flags', _fuse_int32)]
# Bit flag types were changed from unsigned int to uint32_t in libfuse 3.17,
# but as far as I understand this change does not matter because it is only 1 bit.
_fuse_file_info_fields_bitfield = [
('writepage', _fuse_uint32, 1),
('direct_io', _fuse_uint32, 1),
('keep_cache', _fuse_uint32, 1),
]
# Introduced in 3.15.0 and its placement is an API-incompatible change / bug!
# https://github.com/libfuse/libfuse/issues/1029
if fuse_version_minor >= 15 and fuse_version_minor < 17:
_fuse_file_info_fields_bitfield += [
('parallel_direct_writes', _fuse_uint32, 1),
]
_fuse_file_info_fields_bitfield += [
('flush', _fuse_uint32, 1),
('nonseekable', _fuse_uint32, 1),
('flock_release', _fuse_uint32, 1),
]
if fuse_version_minor >= 5:
_fuse_file_info_fields_bitfield += [('cache_readdir', ctypes.c_uint, 1)]
if fuse_version_minor >= 11:
_fuse_file_info_fields_bitfield += [('noflush', ctypes.c_uint, 1)]
if fuse_version_minor >= 17:
_fuse_file_info_fields_bitfield += [
('parallel_direct_writes', _fuse_uint32, 1),
]
_fuse_file_info_flag_count = sum(x[2] for x in _fuse_file_info_fields_bitfield)
assert _fuse_file_info_flag_count < ctypes.sizeof(_fuse_uint32) * 8
_fuse_file_info_fields_ += _fuse_file_info_fields_bitfield
_fuse_file_info_fields_ += [
('padding', _fuse_uint32, ctypes.sizeof(_fuse_uint32) * 8 - _fuse_file_info_flag_count),
('padding2', _fuse_uint32),
]
# https://github.com/libfuse/libfuse/pull/1038#discussion_r1775112524
# https://github.com/libfuse/libfuse/pull/1081
# This padding did always exist because fh was aligned to an offset modulo 8 B,
# but libfuse 3.17 made this explicit and I'm not fully sure how ctypes behaves.
if fuse_version_minor >= 17:
_fuse_file_info_fields_ += [('padding3', _fuse_uint32)]
_fuse_file_info_fields_ += [
('fh', ctypes.c_uint64),
('lock_owner', ctypes.c_uint64),
('poll_events', ctypes.c_uint64),
]
class fuse_file_info(ctypes.Structure):
_fields_ = _fuse_file_info_fields_
if ctypes.sizeof(ctypes.c_int) == 4 and (fuse_version_major, fuse_version_minor) >= (3, 17):
assert ctypes.sizeof(fuse_file_info) == 40
class fuse_context(ctypes.Structure):
_fields_ = [
('fuse', ctypes.c_void_p),
('uid', c_uid_t),
('gid', c_gid_t),
('pid', c_pid_t),
('private_data', ctypes.c_void_p),
# Added in 2.8. Note that this is an ABI break because programs compiled against 2.7
# will allocate a smaller struct leading to out-of-bound accesses when used for a 2.8
# shared library! It shouldn't hurt the other way around to have a larger struct than
# the shared library expects. The newer members will simply be ignored.
('umask', c_mode_t),
]
_libfuse.fuse_get_context.restype = ctypes.POINTER(fuse_context)
# FUSE_BUF_IS_FD = (1 << 1),
# FUSE_BUF_FD_SEEK = (1 << 2),
# FUSE_BUF_FD_RETRY = (1 << 3),
fuse_buf_flags = ctypes.c_int
class fuse_buf(ctypes.Structure):
_fields_ = [
('size', ctypes.c_size_t),
('flags', fuse_buf_flags),
('mem', ctypes.c_void_p),
('fd', ctypes.c_int),
('pos', c_off_t),
]
class fuse_bufvec(ctypes.Structure):
_fields_ = [
('count', ctypes.c_size_t),
('idx', ctypes.c_size_t),
('off', ctypes.c_size_t),
('buf', ctypes.POINTER(fuse_buf)),
]
if TYPE_CHECKING:
fuse_fi_p = ctypes._Pointer[fuse_file_info] # noqa: W212
c_stat_p = ctypes._Pointer[c_stat] # noqa: W212
c_statvfs_p = ctypes._Pointer[c_statvfs] # noqa: W212
c_utimbuf_p = ctypes._Pointer[c_utimbuf] # noqa: W212
fuse_bufvec_p = ctypes._Pointer[fuse_bufvec] # noqa: W212
fuse_bufvec_pp = ctypes._Pointer[fuse_bufvec_p] # noqa: W212
else:
fuse_fi_p = ctypes.POINTER(fuse_file_info)
c_stat_p = ctypes.POINTER(c_stat)
c_statvfs_p = ctypes.POINTER(c_statvfs)
c_utimbuf_p = ctypes.POINTER(c_utimbuf)
fuse_bufvec_p = ctypes.POINTER(fuse_bufvec)
fuse_bufvec_pp = ctypes.POINTER(fuse_bufvec_p)
# fuse_conn_info struct as defined and documented in fuse_common.h
_fuse_conn_info_fields: list[FieldsEntry] = [
('proto_major', ctypes.c_uint),
('proto_minor', ctypes.c_uint),
]
# For some reason, NetBSD return 2.9 even though the API is 3.10!
# The correct version is important for the struct layout!
# https://github.com/NetBSD/src/blob/netbsd-10/lib/librefuse/fuse.h#L58-L59
# However, the fuse_operations layout probably fits the advertised version because I had segfaults from utimens!
if fuse_version_major == 2 or _system == 'NetBSD': # No idea why NetBSD did not remove it -.-
_fuse_conn_info_fields += [('async_read', _fuse_uint32)]
_fuse_conn_info_fields += [('max_write', _fuse_uint32)]
if fuse_version_major == 3 or _system == 'NetBSD':
_fuse_conn_info_fields += [('max_read', _fuse_uint32)]
_fuse_conn_info_fields += [('max_readahead', _fuse_uint32)]
if _system == 'Darwin':
_fuse_conn_info_fields += [('enable', _fuse_uint32)] # TODO: is a bitfield
_fuse_conn_info_fields += [
('capable', _fuse_uint32), # Added in 2.8
('want', _fuse_uint32), # Added in 2.8
('max_background', _fuse_uint32), # Added in 2.9
('congestion_threshold', _fuse_uint32), # Added in 2.9
]
if fuse_version_major == 2 and _system != 'NetBSD':
_fuse_conn_info_fields += [('reserved', _fuse_uint32 * (22 if _system == 'Darwin' else 23))]
elif fuse_version_major == 3 or _system == 'NetBSD':
_fuse_conn_info_fields += [('time_gran', _fuse_uint32)]
if fuse_version_minor < 17 or _system == 'NetBSD':
_fuse_conn_info_fields += [('reserved', _fuse_uint32 * 22)]
else:
_fuse_conn_info_fields += [
('max_backing_stack_depth', ctypes.c_uint32),
('no_interrupt', ctypes.c_uint32, 1),
('padding', ctypes.c_uint32, 31),
('capable_ext', ctypes.c_uint64),
('want_ext', ctypes.c_uint64),
('request_timeout', ctypes.c_uint16),
('reserved', ctypes.c_uint16 * 31),
]
# https://github.com/libfuse/libfuse/pull/1081/commits/24f5b129c4e1b03ebbd05ac0c7673f306facea1ak
class fuse_conn_info(ctypes.Structure): # Added in 2.6 (ABI break of "init" from 2.5->2.6)
_fields_ = _fuse_conn_info_fields
if (fuse_version_major, fuse_version_minor) >= (3, 17):
assert ctypes.sizeof(fuse_conn_info) == 128
# FUSE 3-only struct for second init argument defined in fuse.h.
# If a FUSE 2 method is loaded but 'init_with_config' overridden,
# then this argument will only be zero-initialized and should be ignored.
# 3.0.0 -> 3.10.5: no change
# 3.10.5 -> 3.11.0: no_rofd_flush was added in the middle causing an ABI break
# 3.11.0 -> 3.13.1: no change
# 3.13.1 -> 3.14.1: parallel_direct_writes was added in the middle causing an ABI break
# 3.14.1 -> 3.16.2: no change
# 3.16.2 -> 3.17.0: Changed all types to uint32_t, added reserved bytes, reverted order to 3.10.
# https://github.com/libfuse/libfuse/pull/1081
_fuse_config_fields_: list[FieldsEntry] = [
('set_gid', _fuse_int32),
('gid', _fuse_uint32),
('set_uid', _fuse_int32),
('uid', _fuse_uint32),
('set_mode', _fuse_int32),
('umask', _fuse_uint32),