-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.rs
More file actions
150 lines (127 loc) · 4.32 KB
/
file.rs
File metadata and controls
150 lines (127 loc) · 4.32 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
//! File related types
// ============================================================================
// Imports
// ============================================================================
use bitflags::bitflags;
// ============================================================================
// Constants
// ============================================================================
// None
// ============================================================================
// Types
// ============================================================================
/// Represents an open file
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Handle(u8);
impl Handle {
/// The magic file ID for Standard Input
const STDIN: u8 = 0;
/// The magic file ID for Standard Output
const STDOUT: u8 = 1;
/// The magic file ID for Standard Error
const STDERR: u8 = 2;
/// Construct a new `Handle` from an integer.
///
/// Only the OS should call this - applications should not be constructing
/// their own file handles! But if you do, you probably can't harm anything
/// and it's no worse that C just using `int`.
pub const fn new(value: u8) -> Handle {
Handle(value)
}
/// Create a file handle for Standard Input
pub const fn new_stdin() -> Handle {
Handle(Self::STDIN)
}
/// Create a file handle for Standard Output
pub const fn new_stdout() -> Handle {
Handle(Self::STDOUT)
}
/// Create a file handle for Standard Error
pub const fn new_stderr() -> Handle {
Handle(Self::STDERR)
}
/// Get the numeric value of this File Handle
pub const fn value(&self) -> u8 {
self.0
}
}
/// Describes a file on disk.
///
/// This is set up for 8.3 filenames on MS-DOS FAT32 partitions currently.
#[repr(C)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Stat {
/// How big is this file
pub file_size: u64,
/// When was the file created
pub ctime: Time,
/// When was the last modified
pub mtime: Time,
/// File attributes (Directory, Volume, etc)
pub attr: Attributes,
}
bitflags! {
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
/// Describes the attributes of a file.
pub struct Flags: u8 {
/// Enable write support for this file.
const WRITE = 0x01;
/// Create the file if it doesn't exist.
const CREATE = 0x02;
/// Truncate the file to zero length upon opening.
const TRUNCATE = 0x04;
}
}
bitflags! {
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
/// The attributes a file on disk can have.alloc
///
/// Based on that supported by the FAT32 file system.
pub struct Attributes: u8 {
/// File is read-only
const READ_ONLY = 0x01;
/// File should not appear in directory listing
const HIDDEN = 0x02;
/// File should not be moved on disk
const SYSTEM = 0x04;
/// File is a volume label
const VOLUME = 0x08;
/// File is a directory
const DIRECTORY = 0x10;
/// File has not been backed up
const ARCHIVE = 0x20;
/// File is actually a device
const DEVICE = 0x40;
}
}
/// Represents an instant in time, in the local time zone.
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
pub struct Time {
/// Add 1970 to this file to get the calendar year
pub year_since_1970: u8,
/// Add one to this value to get the calendar month
pub zero_indexed_month: u8,
/// Add one to this value to get the calendar day
pub zero_indexed_day: u8,
/// The number of hours past midnight
pub hours: u8,
/// The number of minutes past the hour
pub minutes: u8,
/// The number of seconds past the minute
pub seconds: u8,
}
// ============================================================================
// Functions
// ============================================================================
// None
// ============================================================================
// Tests
// ============================================================================
// None
// ============================================================================
// End of File
// ============================================================================