smb_msg/
lock.rs

1use super::FileId;
2use binrw::prelude::*;
3use modular_bitfield::prelude::*;
4
5#[binrw::binrw]
6#[derive(Debug)]
7pub struct LockRequest {
8    #[bw(calc = 48)]
9    #[br(assert(_structure_size == 48))]
10    _structure_size: u16,
11    #[bw(try_calc = locks.len().try_into())]
12    lock_count: u16,
13    pub lock_sequence: LockSequence,
14    pub file_id: FileId,
15    #[br(count = lock_count)]
16    pub locks: Vec<LockElement>,
17}
18
19#[bitfield]
20#[derive(BinWrite, BinRead, Debug, Default, Clone, Copy, PartialEq, Eq)]
21#[bw(map = |&x| Self::into_bytes(x))]
22#[br(map = Self::from_bytes)]
23pub struct LockSequence {
24    pub number: B4,
25    pub index: B28,
26}
27
28#[binrw::binrw]
29#[derive(Debug)]
30pub struct LockElement {
31    pub offset: u64,
32    pub length: u64,
33    pub flags: LockFlag,
34    #[bw(calc = 0)]
35    _reserved: u32,
36}
37
38#[bitfield]
39#[derive(BinWrite, BinRead, Debug, Default, Clone, Copy, PartialEq, Eq)]
40#[bw(map = |&x| Self::into_bytes(x))]
41#[br(map = Self::from_bytes)]
42pub struct LockFlag {
43    pub shared: bool,
44    pub exclusive: bool,
45    pub unlock: bool,
46    pub fail_immediately: bool,
47    #[skip]
48    __: B28,
49}
50
51#[binrw::binrw]
52#[derive(Debug)]
53pub struct LockResponse {
54    #[bw(calc = 4)]
55    #[br(assert(_structure_size == 4))]
56    pub _structure_size: u16,
57    #[bw(calc = 0)]
58    pub _reserved: u16,
59}
60
61#[cfg(test)]
62mod tests {
63
64    // TODO: tests
65}