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
// Copyright (C) 2021-2022 Alibaba Cloud. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(unused_imports)]

use std::io;
use std::mem::ManuallyDrop;

use async_trait::async_trait;

use super::*;
use crate::abi::fuse_abi::{
    CreateIn, Opcode, OpenOptions, SetattrValid, FOPEN_IN_KILL_SUIDGID, WRITE_KILL_PRIV,
};
use crate::api::filesystem::{
    AsyncFileSystem, AsyncZeroCopyReader, AsyncZeroCopyWriter, Context, FileSystem,
};

impl<S: BitmapSlice + Send + Sync + 'static> BackendFileSystem for PassthroughFs<S> {
    fn mount(&self) -> io::Result<(Entry, u64)> {
        let entry = self.do_lookup(fuse::ROOT_ID, &CString::new(".").unwrap())?;
        Ok((entry, VFS_MAX_INO))
    }

    fn as_any(&self) -> &dyn Any {
        self
    }
}

impl<'a> InodeData {
    async fn async_get_file(&self, mount_fds: &MountFds) -> io::Result<InodeFile<'_>> {
        // The io_uring doesn't support open_by_handle_at yet, so use sync io.
        self.get_file(mount_fds)
    }
}

impl<S: BitmapSlice + Send + Sync> PassthroughFs<S> {
    /*
    async fn async_open_file(
        &self,
        ctx: &Context,
        dir_fd: i32,
        pathname: &'_ CStr,
        flags: i32,
        mode: u32,
    ) -> io::Result<File> {
        AsyncUtil::open_at(drive, dir_fd, pathname, flags, mode)
            .await
            .map(|fd| unsafe { File::from_raw_fd(fd as i32) })
        }

        async fn async_open_proc_file(
            &self,
            ctx: &Context,
            fd: RawFd,
            flags: i32,
            mode: u32,
        ) -> io::Result<File> {
            if !is_safe_inode(mode) {
                return Err(ebadf());
            }

            let pathname = CString::new(format!("{}", fd))
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;

            // We don't really check `flags` because if the kernel can't handle poorly specified flags
            // then we have much bigger problems. Also, clear the `O_NOFOLLOW` flag if it is set since
            // we need to follow the `/proc/self/fd` symlink to get the file.
            self.async_open_file(
                ctx,
                self.proc_self_fd.as_raw_fd(),
                pathname.as_c_str(),
                (flags | libc::O_CLOEXEC) & (!libc::O_NOFOLLOW),
                0,
            )
            .await
        }

        /// Create a File or File Handle for `name` under directory `dir_fd` to support `lookup()`.
        async fn async_open_file_or_handle<F>(
            &self,
            ctx: &Context,
            dir_fd: RawFd,
            name: &CStr,
            reopen_dir: F,
        ) -> io::Result<(FileOrHandle, InodeStat, InodeAltKey, Option<InodeAltKey>)>
        where
            F: FnOnce(RawFd, libc::c_int, u32) -> io::Result<File>,
        {
            let handle = if self.cfg.inode_file_handles {
                FileHandle::from_name_at_with_mount_fds(dir_fd, name, &self.mount_fds, reopen_dir)
            } else {
                Err(io::Error::from_raw_os_error(libc::ENOTSUP))
            };

            // Ignore errors, because having a handle is optional
            let file_or_handle = if let Ok(h) = handle {
                FileOrHandle::Handle(h)
            } else {
                let f = self
                    .async_open_file(
                        ctx,
                        dir_fd,
                        name,
                        libc::O_PATH | libc::O_NOFOLLOW | libc::O_CLOEXEC,
                        0,
                    )
                    .await?;

                FileOrHandle::File(f)
            };

            let st = match &file_or_handle {
                FileOrHandle::File(f) => {
                    // Count mount ID as part of alt key if use_mntid is true. Note that using
                    // name_to_handle_at() to get mntid is kind of expensive in Lookup intensive
                    // workloads, e.g. when cache is none and accessing lots of files.
                    //
                    // Some filesystems don't support file handle, for example overlayfs mounted
                    // without index feature, if so just use mntid 0 in that case.
                    //
                    // TODO: use statx(2) to query mntid when 5.8 kernel or later are widely used.
                    let mnt_id = if self.cfg.enable_mntid {
                        match FileHandle::from_name_at(dir_fd, name) {
                            Ok(h) => h.mnt_id,
                            Err(_) => 0,
                        }
                    } else {
                        0
                    };
                    InodeStat {
                        stat: self.async_stat(ctx, f, None).await?,
                        mnt_id,
                    }
                }
                FileOrHandle::Handle(h) => InodeStat {
                    stat: self.async_stat_fd(ctx, dir_fd, Some(name)).await?,
                    mnt_id: h.mnt_id,
                },
            };
            let ids_altkey = InodeAltKey::ids_from_stat(&st);

            // Note that this will always be `None` if `cfg.inode_file_handles` is false, but we only
            // really need this alt key when we do not have an `O_PATH` fd open for every inode.  So if
            // `cfg.inode_file_handles` is false, we do not need this key anyway.
            let handle_altkey = file_or_handle.handle().map(|h| InodeAltKey::Handle(*h));

            Ok((file_or_handle, st, ids_altkey, handle_altkey))
        }

        async fn async_open_inode(
            &self,
            ctx: &Context,
            inode: Inode,
            mut flags: i32,
        ) -> io::Result<File> {
            let new_flags = self.get_writeback_open_flags(flags);

            let data = self.inode_map.get(inode)?;
            let file = data.async_get_file(&self.mount_fds).await?;

            self.async_open_proc_file(ctx, file.as_raw_fd(), new_flags, data.mode)
                .await
        }

        async fn async_do_open(
            &self,
            ctx: &Context,
            inode: Inode,
            flags: u32,
            fuse_flags: u32,
        ) -> io::Result<(Option<Handle>, OpenOptions)> {
            let killpriv = if self.killpriv_v2.load(Ordering::Relaxed)
                && (fuse_flags & FOPEN_IN_KILL_SUIDGID != 0)
            {
                self::drop_cap_fsetid()?
            } else {
                None
            };
            let file = self.async_open_inode(ctx, inode, flags as i32).await?;
            drop(killpriv);

            let data = HandleData::new(inode, file);
            let handle = self.next_handle.fetch_add(1, Ordering::Relaxed);
            let mut opts = OpenOptions::empty();

            self.handle_map.insert(handle, data);
            match self.cfg.cache_policy {
                // We only set the direct I/O option on files.
                CachePolicy::Never => opts.set(
                    OpenOptions::DIRECT_IO,
                    flags & (libc::O_DIRECTORY as u32) == 0,
                ),
                CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE,
                _ => {}
            };

            Ok((Some(handle), opts))
        }
        */

    async fn async_do_getattr(
        &self,
        ctx: &Context,
        inode: Inode,
        handle: Option<<Self as FileSystem>::Handle>,
    ) -> io::Result<(libc::stat64, Duration)> {
        unimplemented!()
        /*
        let st;
        let fd;
        let data = self.inode_map.get(inode).map_err(|e| {
            error!("fuse: do_getattr ino {} Not find err {:?}", inode, e);
            e
        })?;

        // kernel sends 0 as handle in case of no_open, and it depends on fuse server to handle
        // this case correctly.
        if !self.no_open.load(Ordering::Relaxed) && handle.is_some() {
            // Safe as we just checked handle
            let hd = self.handle_map.get(handle.unwrap(), inode)?;
            fd = hd.get_handle_raw_fd();
            st = self.async_stat_fd(ctx, fd, None).await;
        } else {
            match &data.file_or_handle {
                FileOrHandle::File(f) => {
                    fd = f.as_raw_fd();
                    st = self.async_stat_fd(ctx, fd, None).await;
                }
                FileOrHandle::Handle(_h) => {
                    let file = data.async_get_file(&self.mount_fds).await?;
                    fd = file.as_raw_fd();
                    st = self.async_stat_fd(ctx, fd, None).await;
                }
            }
        }

        let st = st.map_err(|e| {
            error!(
                "fuse: do_getattr stat failed ino {} fd: {:?} err {:?}",
                inode, fd, e
            );
            e
        })?;

        Ok((st, self.cfg.attr_timeout))
        */
    }

    /*
    async fn async_stat(
        &self,
        ctx: &Context,
        dir: &impl AsRawFd,
        path: Option<&CStr>,
    ) -> io::Result<libc::stat64> {
        self.async_stat_fd(ctx, dir.as_raw_fd(), path).await
    }

    async fn async_stat_fd(
        &self,
        _ctx: &Context,
        dir_fd: RawFd,
        path: Option<&CStr>,
    ) -> io::Result<libc::stat64> {
        // Safe because this is a constant value and a valid C string.
        let pathname =
            path.unwrap_or_else(|| unsafe { CStr::from_bytes_with_nul_unchecked(EMPTY_CSTR) });
        let mut st = MaybeUninit::<libc::stat64>::zeroed();

        // Safe because the kernel will only write data in `st` and we check the return value.
        let res = unsafe {
            libc::fstatat64(
                dir_fd,
                pathname.as_ptr(),
                st.as_mut_ptr(),
                libc::AT_EMPTY_PATH | libc::AT_SYMLINK_NOFOLLOW,
            )
        };
        if res >= 0 {
            // Safe because the kernel guarantees that the struct is now fully initialized.
            Ok(unsafe { st.assume_init() })
        } else {
            Err(io::Error::last_os_error())
        }
    }

    async fn async_get_data(
        &self,
        ctx: &Context,
        handle: Handle,
        inode: Inode,
        flags: libc::c_int,
    ) -> io::Result<Arc<HandleData>> {
        let no_open = self.no_open.load(Ordering::Relaxed);
        if !no_open {
            self.handle_map.get(handle, inode)
        } else {
            let file = self.async_open_inode(ctx, inode, flags as i32).await?;
            Ok(Arc::new(HandleData::new(inode, file)))
        }
    }
     */
}

#[async_trait]
impl<S: BitmapSlice + Send + Sync> AsyncFileSystem for PassthroughFs<S> {
    async fn async_lookup(
        &self,
        ctx: &Context,
        parent: <Self as FileSystem>::Inode,
        name: &CStr,
    ) -> io::Result<Entry> {
        unimplemented!()
        /*
        // Don't use is_safe_path_component(), allow "." and ".." for NFS export support
        if name.to_bytes_with_nul().contains(&SLASH_ASCII) {
            return Err(io::Error::from_raw_os_error(libc::EINVAL));
        }

        let dir = self.inode_map.get(parent)?;
        let dir_file = dir.async_get_file(&self.mount_fds).await?;
        let (file_or_handle, st, ids_altkey, handle_altkey) = self
            .async_open_file_or_handle(ctx, dir_file.as_raw_fd(), name, |fd, flags, mode| {
                Self::open_proc_file(&self.proc_self_fd, fd, flags, mode)
            })
            .await?;

        let mut attr_flags: u32 = 0;
        if let Some(dax_file_size) = self.cfg.dax_file_size {
            // st.stat.st_size is i64
            if self.perfile_dax.load(Ordering::Relaxed)
                && st.stat.st_size >= 0x0
                && st.stat.st_size as u64 >= dax_file_size
            {
                attr_flags |= fuse::FUSE_ATTR_DAX;
            }
        }

        let mut found = None;
        'search: loop {
            match self.inode_map.get_alt(&ids_altkey, handle_altkey.as_ref()) {
                // No existing entry found
                None => break 'search,
                Some(data) => {
                    let curr = data.refcount.load(Ordering::Acquire);
                    // forgot_one() has just destroyed the entry, retry...
                    if curr == 0 {
                        continue 'search;
                    }

                    // Saturating add to avoid integer overflow, it's not realistic to saturate u64.
                    let new = curr.saturating_add(1);

                    // Synchronizes with the forgot_one()
                    if data
                        .refcount
                        .compare_exchange(curr, new, Ordering::AcqRel, Ordering::Acquire)
                        .is_ok()
                    {
                        found = Some(data.inode);
                        break;
                    }
                }
            }
        }

        let inode = if let Some(v) = found {
            v
        } else {
            // Write guard get_alt_locked() and insert_lock() to avoid race conditions.
            let mut inodes = self.inode_map.get_map_mut();

            // Lookup inode_map again after acquiring the inode_map lock, as there might be another
            // racing thread already added an inode with the same altkey while we're not holding
            // the lock. If so just use the newly added inode, otherwise the inode will be replaced
            // and results in EBADF.
            match InodeMap::get_alt_locked(inodes.deref(), &ids_altkey, handle_altkey.as_ref()) {
                Some(data) => {
                    data.refcount.fetch_add(1, Ordering::Relaxed);
                    data.inode
                }
                None => {
                    let inode = self.next_inode.fetch_add(1, Ordering::Relaxed);
                    if inode > VFS_MAX_INO {
                        error!("fuse: max inode number reached: {}", VFS_MAX_INO);
                        return Err(io::Error::new(
                            io::ErrorKind::Other,
                            format!("max inode number reached: {}", VFS_MAX_INO),
                        ));
                    }

                    InodeMap::insert_locked(
                        inodes.deref_mut(),
                        inode,
                        InodeData::new(inode, file_or_handle, 1, ids_altkey, st.get_stat().st_mode),
                        ids_altkey,
                        handle_altkey,
                    );
                    inode
                }
            }
        };

        Ok(Entry {
            inode,
            generation: 0,
            attr: st.get_stat(),
            attr_flags,
            attr_timeout: self.cfg.attr_timeout,
            entry_timeout: self.cfg.entry_timeout,
        })
        */
    }

    async fn async_getattr(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        handle: Option<<Self as FileSystem>::Handle>,
    ) -> io::Result<(libc::stat64, Duration)> {
        self.async_do_getattr(ctx, inode, handle).await
    }

    async fn async_setattr(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        attr: libc::stat64,
        handle: Option<<Self as FileSystem>::Handle>,
        valid: SetattrValid,
    ) -> io::Result<(libc::stat64, Duration)> {
        unimplemented!()
        /*
        enum Data {
            Handle(Arc<HandleData>, RawFd),
            ProcPath(CString),
        }

        let inode_data = self.inode_map.get(inode)?;
        let file = inode_data.async_get_file(&self.mount_fds).await?;
        let data = if self.no_open.load(Ordering::Relaxed) {
            let pathname = CString::new(format!("self/fd/{}", file.as_raw_fd()))
                .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
            Data::ProcPath(pathname)
        } else {
            // If we have a handle then use it otherwise get a new fd from the inode.
            if let Some(handle) = handle {
                let hd = self.handle_map.get(handle, inode)?;
                let fd = hd.get_handle_raw_fd();
                Data::Handle(hd, fd)
            } else {
                let pathname = CString::new(format!("self/fd/{}", file.as_raw_fd()))
                    .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
                Data::ProcPath(pathname)
            }
        };

        if valid.contains(SetattrValid::SIZE) && self.seal_size.load(Ordering::Relaxed) {
            return Err(io::Error::from_raw_os_error(libc::EPERM));
        }

        if valid.contains(SetattrValid::MODE) {
            // Safe because this doesn't modify any memory and we check the return value.
            let res = unsafe {
                match data {
                    Data::Handle(_, fd) => libc::fchmod(fd, attr.st_mode),
                    Data::ProcPath(ref p) => {
                        libc::fchmodat(self.proc_self_fd.as_raw_fd(), p.as_ptr(), attr.st_mode, 0)
                    }
                }
            };
            if res < 0 {
                return Err(io::Error::last_os_error());
            }
        }

        if valid.intersects(SetattrValid::UID | SetattrValid::GID) {
            let uid = if valid.contains(SetattrValid::UID) {
                attr.st_uid
            } else {
                // Cannot use -1 here because these are unsigned values.
                ::std::u32::MAX
            };
            let gid = if valid.contains(SetattrValid::GID) {
                attr.st_gid
            } else {
                // Cannot use -1 here because these are unsigned values.
                ::std::u32::MAX
            };

            // Safe because this is a constant value and a valid C string.
            let empty = unsafe { CStr::from_bytes_with_nul_unchecked(EMPTY_CSTR) };

            // Safe because this doesn't modify any memory and we check the return value.
            let res = unsafe {
                libc::fchownat(
                    file.as_raw_fd(),
                    empty.as_ptr(),
                    uid,
                    gid,
                    libc::AT_EMPTY_PATH | libc::AT_SYMLINK_NOFOLLOW,
                )
            };
            if res < 0 {
                return Err(io::Error::last_os_error());
            }
        }

        if valid.contains(SetattrValid::SIZE) {
            // Cap restored when _killpriv is dropped
            let _killpriv = if self.killpriv_v2.load(Ordering::Relaxed)
                && valid.contains(SetattrValid::KILL_SUIDGID)
            {
                self::drop_cap_fsetid()?
            } else {
                None
            };

            // Safe because this doesn't modify any memory and we check the return value.
            let res = match data {
                Data::Handle(_, fd) => unsafe { libc::ftruncate(fd, attr.st_size) },
                Data::ProcPath(_) => {
                    // There is no `ftruncateat` so we need to get a new fd and truncate it.
                    let f = self
                        .async_open_inode(ctx, inode, libc::O_NONBLOCK | libc::O_RDWR)
                        .await?;
                    unsafe { libc::ftruncate(f.as_raw_fd(), attr.st_size) }
                }
            };
            if res < 0 {
                return Err(io::Error::last_os_error());
            }
        }

        if valid.intersects(SetattrValid::ATIME | SetattrValid::MTIME) {
            let mut tvs = [
                libc::timespec {
                    tv_sec: 0,
                    tv_nsec: libc::UTIME_OMIT,
                },
                libc::timespec {
                    tv_sec: 0,
                    tv_nsec: libc::UTIME_OMIT,
                },
            ];

            if valid.contains(SetattrValid::ATIME_NOW) {
                tvs[0].tv_nsec = libc::UTIME_NOW;
            } else if valid.contains(SetattrValid::ATIME) {
                tvs[0].tv_sec = attr.st_atime;
                tvs[0].tv_nsec = attr.st_atime_nsec;
            }

            if valid.contains(SetattrValid::MTIME_NOW) {
                tvs[1].tv_nsec = libc::UTIME_NOW;
            } else if valid.contains(SetattrValid::MTIME) {
                tvs[1].tv_sec = attr.st_mtime;
                tvs[1].tv_nsec = attr.st_mtime_nsec;
            }

            // Safe because this doesn't modify any memory and we check the return value.
            let res = match data {
                Data::Handle(_, fd) => unsafe { libc::futimens(fd, tvs.as_ptr()) },
                Data::ProcPath(ref p) => unsafe {
                    libc::utimensat(self.proc_self_fd.as_raw_fd(), p.as_ptr(), tvs.as_ptr(), 0)
                },
            };
            if res < 0 {
                return Err(io::Error::last_os_error());
            }
        }

        self.async_do_getattr(ctx, inode, handle).await
         */
    }

    async fn async_open(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        flags: u32,
        fuse_flags: u32,
    ) -> io::Result<(Option<<Self as FileSystem>::Handle>, OpenOptions)> {
        unimplemented!()
        /*
        if self.no_open.load(Ordering::Relaxed) {
            info!("fuse: open is not supported.");
            Err(io::Error::from_raw_os_error(libc::ENOSYS))
        } else {
            self.async_do_open(ctx, inode, flags, fuse_flags).await
        }
         */
    }

    async fn async_create(
        &self,
        ctx: &Context,
        parent: <Self as FileSystem>::Inode,
        name: &CStr,
        args: CreateIn,
    ) -> io::Result<(Entry, Option<<Self as FileSystem>::Handle>, OpenOptions)> {
        unimplemented!()
        /*
        self.validate_path_component(name)?;

        let dir = self.inode_map.get(parent)?;
        let dir_file = dir.async_get_file(&self.mount_fds).await?;

        let new_file = {
            let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;

            let flags = self.get_writeback_open_flags(args.flags as i32);
            Self::create_file_excl(
                dir_file.as_raw_fd(),
                name,
                flags,
                args.mode & !(args.umask & 0o777),
            )?
        };

        let entry = self.async_lookup(ctx, parent, name).await?;
        let file = match new_file {
            // File didn't exist, now created by create_file_excl()
            Some(f) => f,
            // File exists, and args.flags doesn't contain O_EXCL. Now let's open it with
            // open_inode().
            None => {
                // Cap restored when _killpriv is dropped
                let _killpriv = if self.killpriv_v2.load(Ordering::Relaxed)
                    && (args.fuse_flags & FOPEN_IN_KILL_SUIDGID != 0)
                {
                    self::drop_cap_fsetid()?
                } else {
                    None
                };

                let (_uid, _gid) = set_creds(ctx.uid, ctx.gid)?;
                self.async_open_inode(ctx, entry.inode, args.flags as i32)
                    .await?
            }
        };

        let ret_handle = if !self.no_open.load(Ordering::Relaxed) {
            let handle = self.next_handle.fetch_add(1, Ordering::Relaxed);
            let data = HandleData::new(entry.inode, file);

            self.handle_map.insert(handle, data);
            Some(handle)
        } else {
            None
        };

        let mut opts = OpenOptions::empty();
        match self.cfg.cache_policy {
            CachePolicy::Never => opts |= OpenOptions::DIRECT_IO,
            CachePolicy::Always => opts |= OpenOptions::KEEP_CACHE,
            _ => {}
        };

        Ok((entry, ret_handle, opts))
         */
    }

    #[allow(clippy::too_many_arguments)]
    async fn async_read(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        handle: <Self as FileSystem>::Handle,
        w: &mut (dyn AsyncZeroCopyWriter + Send),
        size: u32,
        offset: u64,
        _lock_owner: Option<u64>,
        _flags: u32,
    ) -> io::Result<usize> {
        unimplemented!()
        /*
        let data = self
            .async_get_data(ctx, handle, inode, libc::O_RDONLY)
            .await?;
        let drive = ctx
            .get_drive::<D>()
            .ok_or_else(|| io::Error::from_raw_os_error(libc::EINVAL))?;

        w.async_write_from(drive, data.get_handle_raw_fd(), size as usize, offset)
            .await
         */
    }

    #[allow(clippy::too_many_arguments)]
    async fn async_write(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        handle: <Self as FileSystem>::Handle,
        r: &mut (dyn AsyncZeroCopyReader + Send),
        size: u32,
        offset: u64,
        _lock_owner: Option<u64>,
        _delayed_write: bool,
        _flags: u32,
        fuse_flags: u32,
    ) -> io::Result<usize> {
        unimplemented!()
        /*
        let data = self
            .async_get_data(ctx, handle, inode, libc::O_RDWR)
            .await?;

        if self.seal_size.load(Ordering::Relaxed) {
            let st = self
                .async_stat_fd(cxt, data.get_handle_raw_fd(), None)
                .await?;
            self.seal_size_check(Opcode::Write, st.st_size as u64, offset, size as u64, 0)?;
        }

        // Fallback to sync io if KILLPRIV_V2 is enabled to work around a limitation of io_uring.
        if self.killpriv_v2.load(Ordering::Relaxed) && (fuse_flags & WRITE_KILL_PRIV != 0) {
            // Manually implement File::try_clone() by borrowing fd of data.file instead of dup().
            // It's safe because the `data` variable's lifetime spans the whole function,
            // so data.file won't be closed.
            let f = unsafe { File::from_raw_fd(data.get_handle_raw_fd()) };
            let mut f = ManuallyDrop::new(f);
            // Cap restored when _killpriv is dropped
            let _killpriv = self::drop_cap_fsetid()?;

            r.read_to(&mut *f, size as usize, offset)
        } else {
            let drive = ctx
                .get_drive::<D>()
                .ok_or_else(|| io::Error::from_raw_os_error(libc::EINVAL))?;

            r.async_read_to(drive, data.get_handle_raw_fd(), size as usize, offset)
                .await
        }
         */
    }

    async fn async_fsync(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        datasync: bool,
        handle: <Self as FileSystem>::Handle,
    ) -> io::Result<()> {
        unimplemented!()
        /*
        let data = self
            .async_get_data(ctx, handle, inode, libc::O_RDONLY)
            .await?;
        let drive = ctx
            .get_drive::<D>()
            .ok_or_else(|| io::Error::from_raw_os_error(libc::EINVAL))?;

        AsyncUtil::fsync(drive, data.get_handle_raw_fd(), datasync).await
         */
    }

    async fn async_fallocate(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        handle: <Self as FileSystem>::Handle,
        mode: u32,
        offset: u64,
        length: u64,
    ) -> io::Result<()> {
        unimplemented!()
        /*
        // Let the Arc<HandleData> in scope, otherwise fd may get invalid.
        let data = self
            .async_get_data(ctx, handle, inode, libc::O_RDWR)
            .await?;
        let drive = ctx
            .get_drive::<D>()
            .ok_or_else(|| io::Error::from_raw_os_error(libc::EINVAL))?;

        if self.seal_size.load(Ordering::Relaxed) {
            let st = self
                .async_stat_fd(cxt, data.get_handle_raw_fd(), None)
                .await?;
            self.seal_size_check(
                Opcode::Fallocate,
                st.st_size as u64,
                offset,
                length,
                mode as i32,
            )?;
        }

        AsyncUtil::fallocate(drive, data.get_handle_raw_fd(), offset, length, mode).await
         */
    }

    async fn async_fsyncdir(
        &self,
        ctx: &Context,
        inode: <Self as FileSystem>::Inode,
        datasync: bool,
        handle: <Self as FileSystem>::Handle,
    ) -> io::Result<()> {
        self.async_fsync(ctx, inode, datasync, handle).await
    }
}