~vertigo/forthbox

65d1eb5421c9690a8f04f98e49b988a93546b826 — Samuel A. Falvo II 7 months ago 9c7df57
cargo fmt
2 files changed, 51 insertions(+), 11 deletions(-)

M x/vdasd/src/control.rs
M x/vdasd/src/messages.rs
M x/vdasd/src/control.rs => x/vdasd/src/control.rs +50 -10
@@ 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::<Vec<&FSObject>>().get(0).unwrap();
            let fsobj = *self
                .directory_tree
                .iter()
                .filter(|&fso| fso.qid.path == fsobj_path)
                .collect::<Vec<&FSObject>>()
                .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"),
        }
    }

M x/vdasd/src/messages.rs => x/vdasd/src/messages.rs +1 -1
@@ 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 },