From 65d1eb5421c9690a8f04f98e49b988a93546b826 Mon Sep 17 00:00:00 2001 From: "Samuel A. Falvo II" Date: Sun, 25 Feb 2024 22:28:27 -0800 Subject: [PATCH] cargo fmt --- x/vdasd/src/control.rs | 60 ++++++++++++++++++++++++++++++++++------- x/vdasd/src/messages.rs | 2 +- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/x/vdasd/src/control.rs b/x/vdasd/src/control.rs index b8cc361..782e2f5 100644 --- a/x/vdasd/src/control.rs +++ b/x/vdasd/src/control.rs @@ -2,10 +2,12 @@ use std::collections::HashMap; +use crate::constants::SECTOR_SIZE; use crate::errors::Error; use crate::messages::{RMsg, Request, TMsg}; -use crate::structs::{FidBinding, Qid, PathString, FSObject, QTDIR, QTFILE, QTAUTH, OREAD, ORCLOSE, OTRUNC}; -use crate::constants::SECTOR_SIZE; +use crate::structs::{ + FSObject, FidBinding, PathString, Qid, ORCLOSE, OREAD, OTRUNC, QTAUTH, QTDIR, QTFILE, +}; const NOFID: u32 = !0; @@ -27,9 +29,33 @@ impl Control { Control { fid_bindings: HashMap::new(), directory_tree: vec![ - FSObject { qid: Qid { qtype: QTDIR, version: 0, path: QID_ROOT_PATH }, parent: QID_ROOT_PATH, name: "/".to_string() }, - FSObject { qid: Qid { qtype: QTDIR, version: 0, path: QID_0_PATH }, parent: QID_ROOT_PATH, name: "0".to_string() }, - FSObject { qid: Qid { qtype: QTFILE, version: 0, path: QID_MEDIA_PATH }, parent: QID_0_PATH, name: "media".to_string() }, + FSObject { + qid: Qid { + qtype: QTDIR, + version: 0, + path: QID_ROOT_PATH, + }, + parent: QID_ROOT_PATH, + name: "/".to_string(), + }, + FSObject { + qid: Qid { + qtype: QTDIR, + version: 0, + path: QID_0_PATH, + }, + parent: QID_ROOT_PATH, + name: "0".to_string(), + }, + FSObject { + qid: Qid { + qtype: QTFILE, + version: 0, + path: QID_MEDIA_PATH, + }, + parent: QID_0_PATH, + name: "media".to_string(), + }, ], } } @@ -126,13 +152,19 @@ impl Control { None => { req.r = Some(Err(Error::Fid)); return; - }, + } Some(fid_binding) => fid_binding, }; let fsobj_path = currently_addressed_object(binding); - let fsobj = *self.directory_tree.iter().filter(|&fso| fso.qid.path == fsobj_path).collect::>().get(0).unwrap(); + let fsobj = *self + .directory_tree + .iter() + .filter(|&fso| fso.qid.path == fsobj_path) + .collect::>() + .get(0) + .unwrap(); // What follows assumes we're opening the root directory if is_directory(fsobj.qid.qtype) { @@ -149,7 +181,11 @@ impl Control { // If we were implementing a real filesystem here, we would add checks for RWX permissions, // username/groupname checks, etc. here. - req.r = Some(Ok(RMsg::Open { tag: *tag, qid: fsobj.qid, iounit: SECTOR_SIZE as u32})); + req.r = Some(Ok(RMsg::Open { + tag: *tag, + qid: fsobj.qid, + iounit: SECTOR_SIZE as u32, + })); return; } @@ -325,12 +361,16 @@ mod tests { match r.r { None => panic!("Control ignored message"), Some(Err(e)) => panic!("Unexpected error {:?}", e), - Some(Ok(RMsg::Open { tag, qid, iounit: _ })) => { + Some(Ok(RMsg::Open { + tag, + qid, + iounit: _, + })) => { assert_eq!(tag, 1); assert_eq!(qid.qtype, QTDIR); assert_eq!(qid.version, 0); assert_eq!(qid.path, QID_ROOT_PATH); - }, + } Some(Ok(_)) => panic!("Unexpected success"), } } diff --git a/x/vdasd/src/messages.rs b/x/vdasd/src/messages.rs index 079004d..82ceca5 100644 --- a/x/vdasd/src/messages.rs +++ b/x/vdasd/src/messages.rs @@ -84,7 +84,7 @@ pub enum TMsg { #[derive(Debug, PartialEq)] pub enum RMsg { Attach { tag: u16, qid: Qid }, - Auth { tag: u16, aqid: Qid }, // unused, but defined for completeness + Auth { tag: u16, aqid: Qid }, // unused, but defined for completeness Clunk { tag: u16 }, Open { tag: u16, qid: Qid, iounit: u32 }, Read { tag: u16, count: u32 }, -- 2.45.2