public void Mount(DiskDriver disk, string mountPoint) { // for the first mounted drive, expect mountPoint to be named FSConstants.PATH_SEPARATOR as the root if (drives.Count == 0 && mountPoint != FSConstants.PATH_SEPARATOR.ToString()) { throw new Exception("Expected first mounted dist to be at root directory!"); } // read drive info from disk, load root node and connect to mountPoint DRIVE_INFO driveInfo = DRIVE_INFO.CreateFromBytes(disk.ReadSector(DRIVE_INFO_SECTOR)); VirtualDrive drive = new VirtualDrive(disk, DRIVE_INFO_SECTOR, driveInfo); DIR_NODE rootSector = DIR_NODE.CreateFromBytes(disk.ReadSector(ROOT_DIR_SECTOR)); rootNode = new VirtualNode(drive, ROOT_DIR_SECTOR, rootSector, null); drives.Add(mountPoint, drive); }
public void Mount(DiskDriver disk, string mountPoint) { // read drive info from disk, load root node and connect to mountPoint // for the first mounted drive, expect mountPoint to be named FSConstants.ROOT_DIR_NAME as the root //read drive info for disk to determin what sector contains its root node DRIVE_INFO diSector = DRIVE_INFO.CreateFromBytes(disk.ReadSector(DRIVE_INFO_SECTOR)); int rootNodeAt = diSector.RootNodeAt; VirtualDrive drive = new VirtualDrive(disk, DRIVE_INFO_SECTOR, diSector); DIR_NODE rootNodeSector = DIR_NODE.CreateFromBytes(disk.ReadSector(rootNodeAt)); if (rootNode == null) { rootNode = new VirtualNode(drive, rootNodeAt, rootNodeSector, null); } drives.Add(mountPoint, drive); }
public void Mount(DiskDriver disk, string mountPoint) { // read drive info from disk, load root node and connect to mountPoint // for the first mounted drive, expect mountPoint to be named "/", FSConstants.ROOT_DIR_NAME, as the root try { // Step 1: Read infor from the disk to understand it's directory structure // Read DRIVE_INFO from FRIVE_INFO_SECTOR DRIVE_INFO di = DRIVE_INFO.CreateFromBytes(disk.ReadSector(DRIVE_INFO_SECTOR)); DIR_NODE dn = DIR_NODE.CreateFromBytes(disk.ReadSector(di.RootNodeAt)); DATA_SECTOR ds = DATA_SECTOR.CreateFromBytes(disk.ReadSector(dn.FirstDataAt)); // Step 2: Join th new disk into the virtual file system structure, at the mount point. // Create a VistualDrive for the disk VirtualDrive vd = new VirtualDrive(disk, DRIVE_INFO_SECTOR, di); if (rootNode == null) { // Create a VirtualNode to represent the root dictionaru, at the mount point. // Set the VFS's root node, if this is the first disk to be mounted. rootNode = new VirtualNode(vd, di.RootNodeAt, dn, null); } else { // TODO: Extra Credit: Handle 2nd dick mounted to exsisting VFS // Create a virtual node for this new disk's root // "join" the new node to the exsisting node structure at the mount point } // Add a new VirtualDrive to drives dictionary, using te mountPoint as the key drives.Add(mountPoint, vd); } catch (Exception ex) { throw new Exception("Failed to mount disk"); } }