@@ -21,31 +21,54 @@ impl RegularFile {
21
21
Self ( handle)
22
22
}
23
23
24
- /// Read data from file
24
+ /// Read data from a file, hence, a regular file or a directory.
25
25
///
26
- /// Try to read as much as possible into `buffer`. Returns the number of bytes that were
27
- /// actually read.
26
+ /// # Read from Regular Files
27
+ /// If `self` is not a directory, the function reads the requested number of bytes from the file
28
+ /// at the file’s current position and returns them in `buffer`. If the read goes beyond the end
29
+ /// of the file, the read length is truncated to the end of the file. The file’s current
30
+ /// position is increased by the number of bytes returned.
31
+ ///
32
+ /// # Read from Directory
33
+ /// If `self` is a directory, the function reads the directory entry at the file’s current
34
+ /// position and returns the entry in `buffer`. If the `buffer` is not large enough to hold the
35
+ /// current directory entry, then `EFI_BUFFER_TOO_SMALL` is returned and the current file
36
+ /// position is not updated. `buffer_size` is set to be the size of the buffer needed to read
37
+ /// the entry. On success, the current position is updated to the next directory entry. If there
38
+ /// are no more directory entries, the read returns a zero-length buffer. `EFI_FILE_INFO` is the
39
+ /// structure returned as the directory entry.
28
40
///
29
41
/// # Arguments
30
42
/// * `buffer` The target buffer of the read operation
31
43
///
32
- /// # Errors
44
+ /// # Return Value
45
+ /// This either returns the size of read bytes in the success case or a tuple of the UEFI
46
+ /// status and the required buffer size, if the buffer was too small. The status code can
47
+ /// signalize one of the following errors:
48
+ ///
49
+ /// ## Status Error Codes
33
50
/// * `uefi::Status::NO_MEDIA` The device has no media
34
51
/// * `uefi::Status::DEVICE_ERROR` The device reported an error, the file was deleted,
35
52
/// or the end of the file was reached before the `read()`.
36
53
/// * `uefi::Status::VOLUME_CORRUPTED` The filesystem structures are corrupted
37
54
/// * `uefi::Status::BUFFER_TOO_SMALL` The buffer is too small to hold a directory entry,
38
55
/// and the required buffer size is provided as output.
39
- pub fn read ( & mut self , buffer : & mut [ u8 ] ) -> Result < usize , Option < usize > > {
56
+ pub fn read ( & mut self , buffer : & mut [ u8 ] ) -> Result < usize , ( Status , Option < usize > ) > {
40
57
let mut buffer_size = buffer. len ( ) ;
41
- unsafe { ( self . imp ( ) . read ) ( self . imp ( ) , & mut buffer_size, buffer. as_mut_ptr ( ) ) } . into_with (
58
+ let status =
59
+ unsafe { ( self . imp ( ) . read ) ( self . imp ( ) , & mut buffer_size, buffer. as_mut_ptr ( ) ) } ;
60
+
61
+ // Now, buffer_size is updated. It either contains the number of read bytes or the number
62
+ // of required bytes to read the whole entry.
63
+ status. into_with (
42
64
|| buffer_size,
43
- |s| {
44
- if s == Status :: BUFFER_TOO_SMALL {
65
+ |s : Status | {
66
+ let required_buffer_size = if s == Status :: BUFFER_TOO_SMALL {
45
67
Some ( buffer_size)
46
68
} else {
47
69
None
48
- }
70
+ } ;
71
+ ( status, required_buffer_size)
49
72
} ,
50
73
)
51
74
}
0 commit comments