starnix_uapi/
file_lease.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::errors::Errno;
6use crate::{error, uapi};
7
8/// See fcntl F_SETLEASE and F_GETLEASE.
9#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
10pub enum FileLeaseType {
11    /// Corresponds to F_UNLCK.
12    #[default]
13    Unlocked,
14
15    /// Corresponds to F_RDLCK.
16    Read,
17
18    /// Corresponds to F_WRLCK.
19    Write,
20}
21
22impl FileLeaseType {
23    pub fn from_bits(value: u32) -> Result<Self, Errno> {
24        match value {
25            uapi::F_UNLCK => Ok(Self::Unlocked),
26            uapi::F_RDLCK => Ok(Self::Read),
27            uapi::F_WRLCK => Ok(Self::Write),
28            _ => error!(EINVAL),
29        }
30    }
31
32    pub fn bits(&self) -> u32 {
33        match self {
34            Self::Unlocked => uapi::F_UNLCK,
35            Self::Read => uapi::F_RDLCK,
36            Self::Write => uapi::F_WRLCK,
37        }
38    }
39}