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
use super::{Kind, Result, Unimplemented};
bitflags! {
/// - append: append mode (makes sense only for output; conv=notrunc
/// suggested)
///
/// - direct: use direct I/O for data
///
/// - directory: fail unless a directory
///
/// - dsync: use synchronized I/O for data
///
/// - sync: use synchronized io for data AND metadata
///
/// - fullblock: accumulate full blocks of input
///
/// - nonblock: use non-blocking I/O
///
/// - noatime: do not update access time
///
/// - nocache: Request to drop cache. See also oflag=sync
///
/// - noctty: do not assign controlling terminal from file
///
/// - nofollow: do not follow symlinks
///
/// - count_bytes: treat 'count=N' as a byte count
///
/// - skip_bytes: treat 'skip=N' as a byte count
pub struct IFlag: u32 {
/// append mode (makes sense only for output; conv=notrunc suggested)
const APPEND = 0x0001;
/// <NOT IMPLEMENTED> use direct I/O for data
const DIRECT = 0x0002;
/// fail unless a directory
const DIRECTORY = 0x0004;
/// <NOT IMPLEMENTED> use synchronized I/O for data
const DSYNC = 0x0008;
/// <UNIMPLMEMENTED> use synchronized I/O for data and metadata
const SYNC =0x0010;
/// accumulate full blocks of input (iflag only)
const FULLBLOCK= 0x0020;
/// <NOT IMPLEMENTED> use non-blocking I/O
const NONBLOCK = 0x0040;
/// <NOT IMPLEMENTED> do not update access time
const NOATIME = 0x0080;
/// <NOT IMPLEMENTED> Request to drop cache. See also oflag=sync
const NOCACHE = 0x0100;
/// <NOT IMPLEMENTED> do not assign controlling terminal from file
const NOCTTY = 0x0200;
/// <NOT IMPLEMENTED> do not follow symlinks
const NOFOLLOW = 0x0400;
/// treat 'count=N' as a byte count (iflag only)
const COUNT_BYTES = 0x0800;
/// treat 'skip=N' as a byte count (iflag only)
const SKIP_BYTES = 0x1000;
}
}
impl IFlag {
// Unimplemented iflags
/// create a new `opts::IFlag` by parsing a comma-and-optional-whitespace
/// separated list of arguments ```
/// #use dd:opts;
/// assert_eq!(opts::In::new("directory, append ").unwrap(),
/// opts::IFlag::DIRECTORY | opts::IFlag::APPEND); ```
pub fn new(s: &str) -> Result<Self> {
let mut flags = Self::default();
for flag in s.split(',').map(str::trim).filter(|s| s.len() > 0) {
Self::check_if_implemented(flag)?;
flags |= { Self::from_str(flag)? };
}
Ok(flags)
}
fn from_str(flag: &str) -> Result<Self> {
Ok(match flag {
"append" => Self::APPEND,
"directory" => Self::DIRECTORY,
"dsync" => Self::DSYNC,
"sync" => Self::SYNC,
"fullblock" => Self::FULLBLOCK,
"nonblock" => Self::NONBLOCK,
"noatime" => Self::NOATIME,
"nocache" => Self::NOCACHE,
"noctty" => Self::NOCTTY,
"nofollow" => Self::NOFOLLOW,
"count_bytes" => Self::COUNT_BYTES,
"skip_bytes" => Self::SKIP_BYTES,
_ => return Self::unknown(flag.to_owned()),
})
}
}
impl Default for IFlag {
fn default() -> IFlag { IFlag::empty() }
}
impl Unimplemented for IFlag {
const KIND: Kind = Kind::IFlag;
const UNIMPLEMENTED: &'static [&'static str] = &[
"direct",
"directory",
"dync",
"noatime",
"nocache",
"nofollow",
"noctty",
"nonblock",
"fullblock",
];
}