Skip to content

Commit 5e48989

Browse files
committed
Make file-related structures and enums public
1 parent f701155 commit 5e48989

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

src/proto/media/file.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
//! This module provides the `File` structure, representing an opaque handle to a
2+
//! directory / file, as well as providing functions for opening new files.
3+
//!
4+
//! Usually a file system implementation will return a "root" file, representing
5+
//! `/` on that volume, and with that file it is possible to enumerate and open
6+
//! all the other files on that volume.
7+
18
use bitflags::bitflags;
9+
use core::mem;
210
use crate::{Result, Status};
311
use ucs2;
412

5-
/// A file represents an abstraction of some contiguous block of data residing on a volume.
13+
/// A file represents an abstraction of some contiguous block of data residing
14+
/// on a volume.
15+
///
16+
/// Dropping this structure will result in the file handle being closed.
617
///
718
/// Files have names, and a fixed size.
819
pub struct File<'a> {
@@ -59,19 +70,19 @@ impl<'a> File<'a> {
5970
}
6071
}
6172

62-
/// Close this file handle
63-
///
64-
/// This MUST be called when you are done with the file
65-
pub fn close(self) -> Result<()> {
66-
(self.inner.close)(self.inner).into()
67-
}
73+
/// Close this file handle. Same as dropping this structure.
74+
pub fn close(self) {}
6875

6976
/// Closes and deletes this file
7077
///
7178
/// # Errors
7279
/// * `uefi::Status::WARN_DELETE_FAILURE` The file was closed, but deletion failed
7380
pub fn delete(self) -> Result<()> {
74-
(self.inner.delete)(self.inner).into()
81+
let result = (self.inner.delete)(self.inner).into();
82+
83+
mem::forget(self);
84+
85+
result
7586
}
7687

7788
/// Read data from file
@@ -148,6 +159,14 @@ impl<'a> File<'a> {
148159
}
149160
}
150161

162+
impl<'a> Drop for File<'a> {
163+
fn drop(&mut self) {
164+
let result: Result<()> = (self.inner.close)(self.inner).into();
165+
// The spec says this always succeeds.
166+
result.expect("Failed to close file");
167+
}
168+
}
169+
151170
/// The function pointer table for the File protocol.
152171
#[repr(C)]
153172
struct FileImpl {
@@ -173,20 +192,31 @@ struct FileImpl {
173192
}
174193

175194
bitflags! {
195+
/// Usage flags describing what is possible to do with the file.
176196
pub struct FileMode: u64 {
197+
/// The file can be read from.
177198
const READ = 1;
199+
/// The file can be written to.
178200
const WRITE = 1 << 1;
201+
/// The file will be created if not found.
179202
const CREATE = 1 << 63;
180203
}
181204
}
182205

183206
bitflags! {
207+
/// Attributes describing the properties of a file on the file system.
184208
pub struct FileAttribute: u64 {
209+
/// File can only be opened in [`FileMode::READ`] mode.
185210
const READ_ONLY = 1;
211+
/// Hidden file, not normally visible to the user.
186212
const HIDDEN = 1 << 1;
213+
/// System file, indicates this file is an internal operating system file.
187214
const SYSTEM = 1 << 2;
215+
/// This file is a directory.
188216
const DIRECTORY = 1 << 4;
217+
/// This file is compressed.
189218
const ARCHIVE = 1 << 5;
219+
/// Mask combining all the valid attributes.
190220
const VALID_ATTR = 0x37;
191221
}
192222
}

src/proto/media/file_system.rs renamed to src/proto/media/fs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! File system support protocols.
2+
13
use crate::{Result, Status};
24

35
use super::file::File;
@@ -31,6 +33,6 @@ impl SimpleFileSystem {
3133

3234
impl_proto! {
3335
protocol SimpleFileSystem {
34-
GUID = 0x0964e5b22,0x6459,0x11d2,[0x8e,0x39,0x00,0xa0,0xc9,0x69,0x72,0x3b];
36+
GUID = 0x0964E5B22, 0x6459, 0x11D2, [0x8E, 0x39, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B];
3537
}
3638
}

src/proto/media/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//! They provide both **high-level abstractions** such as **files and partitions**,
55
//! and **low-level access** such as an **block I/O** or **raw ATA** access protocol.
66
7-
mod file;
8-
pub use self::file::File;
7+
pub mod file;
98

10-
mod file_system;
11-
pub use self::file_system::SimpleFileSystem;
9+
pub mod fs;

0 commit comments

Comments
 (0)