Skip to content

Commit fe05b9f

Browse files
committed
Rename SearchId to Handle.
1 parent 011726b commit fe05b9f

File tree

6 files changed

+73
-62
lines changed

6 files changed

+73
-62
lines changed

src/filesystem/directory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::convert::TryFrom;
22

33
use crate::blockdevice::BlockIdx;
44
use crate::fat::{FatType, OnDiskDirEntry};
5-
use crate::filesystem::{Attributes, ClusterId, SearchId, ShortFileName, Timestamp};
5+
use crate::filesystem::{Attributes, ClusterId, Handle, ShortFileName, Timestamp};
66
use crate::{Error, RawVolume, VolumeManager};
77

88
use super::ToShortFileName;
@@ -47,7 +47,7 @@ pub struct DirEntry {
4747
/// and there's a reason we did it this way.
4848
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
4949
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
50-
pub struct RawDirectory(pub(crate) SearchId);
50+
pub struct RawDirectory(pub(crate) Handle);
5151

5252
impl RawDirectory {
5353
/// Convert a raw directory into a droppable [`Directory`]
@@ -240,9 +240,9 @@ where
240240
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
241241
#[derive(Debug, Clone)]
242242
pub(crate) struct DirectoryInfo {
243-
/// Unique ID for this directory.
243+
/// The handle for this directory.
244244
pub(crate) directory_id: RawDirectory,
245-
/// The unique ID for the volume this directory is on
245+
/// The handle for the volume this directory is on
246246
pub(crate) volume_id: RawVolume,
247247
/// The starting point of the directory listing.
248248
pub(crate) cluster: ClusterId,

src/filesystem/files.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::TimeSource;
22
use crate::{
3-
filesystem::{ClusterId, DirEntry, SearchId},
3+
filesystem::{ClusterId, DirEntry, Handle},
44
BlockDevice, Error, RawVolume, VolumeManager,
55
};
66
use embedded_io::{ErrorType, Read, Seek, SeekFrom, Write};
@@ -23,7 +23,7 @@ use embedded_io::{ErrorType, Read, Seek, SeekFrom, Write};
2323
/// reason we did it this way.
2424
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
2525
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
26-
pub struct RawFile(pub(crate) SearchId);
26+
pub struct RawFile(pub(crate) Handle);
2727

2828
impl RawFile {
2929
/// Convert a raw file into a droppable [`File`]
@@ -283,10 +283,10 @@ pub enum Mode {
283283
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
284284
#[derive(Debug, Clone)]
285285
pub(crate) struct FileInfo {
286-
/// Unique ID for this file
287-
pub(crate) file_id: RawFile,
288-
/// The unique ID for the volume this directory is on
289-
pub(crate) volume_id: RawVolume,
286+
/// Handle for this file
287+
pub(crate) raw_file: RawFile,
288+
/// The handle for the volume this directory is on
289+
pub(crate) raw_volume: RawVolume,
290290
/// The last cluster we accessed, and how many bytes that short-cuts us.
291291
///
292292
/// This saves us walking from the very start of the FAT chain when we move

src/filesystem/search_id.rs renamed to src/filesystem/handles.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1+
//! Contains the Handles and the HandleGenerator.
2+
13
use core::num::Wrapping;
24

35
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
46
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
5-
/// Unique ID used to search for files and directories in the open Volume/File/Directory lists
6-
pub struct SearchId(pub(crate) u32);
7+
/// Unique ID used to identify things in the open Volume/File/Directory lists
8+
pub struct Handle(pub(crate) u32);
79

8-
/// A Search ID generator.
10+
/// A Handle Generator.
911
///
1012
/// This object will always return a different ID.
1113
///
1214
/// Well, it will wrap after `2**32` IDs. But most systems won't open that many
1315
/// files, and if they do, they are unlikely to hold one file open and then
1416
/// open/close `2**32 - 1` others.
1517
#[derive(Debug)]
16-
pub struct SearchIdGenerator {
18+
pub struct HandleGenerator {
1719
next_id: Wrapping<u32>,
1820
}
1921

20-
impl SearchIdGenerator {
21-
/// Create a new generator of Search IDs.
22+
impl HandleGenerator {
23+
/// Create a new generator of Handles.
2224
pub const fn new(offset: u32) -> Self {
2325
Self {
2426
next_id: Wrapping(offset),
2527
}
2628
}
2729

28-
/// Generate a new, unique [`SearchId`].
29-
pub fn get(&mut self) -> SearchId {
30+
/// Generate a new, unique [`Handle`].
31+
pub fn generate(&mut self) -> Handle {
3032
let id = self.next_id;
3133
self.next_id += 1;
32-
SearchId(id.0)
34+
Handle(id.0)
3335
}
3436
}
3537

src/filesystem/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ mod cluster;
1111
mod directory;
1212
mod filename;
1313
mod files;
14-
mod search_id;
14+
mod handles;
1515
mod timestamp;
1616

1717
pub use self::attributes::Attributes;
1818
pub use self::cluster::ClusterId;
1919
pub use self::directory::{DirEntry, Directory, RawDirectory};
2020
pub use self::filename::{FilenameError, ShortFileName, ToShortFileName};
2121
pub use self::files::{File, FileError, Mode, RawFile};
22-
pub use self::search_id::{SearchId, SearchIdGenerator};
22+
pub use self::handles::{Handle, HandleGenerator};
2323
pub use self::timestamp::{TimeSource, Timestamp};
2424

2525
pub(crate) use self::directory::DirectoryInfo;

src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub mod sdcard;
7575

7676
use core::fmt::Debug;
7777
use embedded_io::ErrorKind;
78-
use filesystem::SearchId;
78+
use filesystem::Handle;
7979

8080
#[doc(inline)]
8181
pub use crate::blockdevice::{Block, BlockCount, BlockDevice, BlockIdx};
@@ -247,10 +247,19 @@ where
247247
}
248248
}
249249

250-
/// A partition with a filesystem within it.
250+
/// A handle to a volume.
251+
///
252+
/// A volume is a partition with a filesystem within it.
253+
///
254+
/// Do NOT drop this object! It doesn't hold a reference to the Volume Manager
255+
/// it was created from and the VolumeManager will think you still have the
256+
/// volume open if you just drop it, and it won't let you open the file again.
257+
///
258+
/// Instead you must pass it to [`crate::VolumeManager::close_volume`] to close
259+
/// it cleanly.
251260
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
252261
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
253-
pub struct RawVolume(SearchId);
262+
pub struct RawVolume(Handle);
254263

255264
impl RawVolume {
256265
/// Convert a raw volume into a droppable [`Volume`]
@@ -272,7 +281,7 @@ impl RawVolume {
272281
}
273282
}
274283

275-
/// An open volume on disk, which closes on drop.
284+
/// A handle for an open volume on disk, which closes on drop.
276285
///
277286
/// In contrast to a `RawVolume`, a `Volume` holds a mutable reference to its
278287
/// parent `VolumeManager`, which restricts which operations you can perform.
@@ -373,9 +382,9 @@ where
373382
#[cfg_attr(feature = "defmt-log", derive(defmt::Format))]
374383
#[derive(Debug, PartialEq, Eq)]
375384
pub(crate) struct VolumeInfo {
376-
/// Search ID for this volume.
377-
volume_id: RawVolume,
378-
/// TODO: some kind of index
385+
/// Handle for this volume.
386+
raw_volume: RawVolume,
387+
/// Which volume (i.e. partition) we opened on the disk
379388
idx: VolumeIdx,
380389
/// What kind of volume this is
381390
volume_type: VolumeType,

0 commit comments

Comments
 (0)