//This method reads the Inodes in the Inode block in my file system public void read(InodeBlock inodeBlock) //public void read(int blockNumber, InodeBlock inodeBlock) { try { ////myPFS = System.IO.File.Open(path, FileMode.Open); ////seekBlock(blockNumber); for (int i = 0; i < inodeBlock.iNode.Length; i++) { myPFS = System.IO.File.Open(path, FileMode.Open); seekBlock(i + 1); using (StreamReader sReader = new StreamReader(myPFS)) { inodeBlock.iNode[i].InodeFlag = Convert.ToInt32(sReader.Read()); inodeBlock.iNode[i].FileOwner = Convert.ToInt32(sReader.Read()); inodeBlock.iNode[i].FileCreatedDate = Convert.ToDateTime(sReader.Read()); inodeBlock.iNode[i].FileCreatedTime = Convert.ToDateTime(sReader.Read()); inodeBlock.iNode[i].FileSize = Convert.ToInt32(sReader.Read()); inodeBlock.iNode[i].Remarks = Convert.ToString(sReader.Read()); for (int j = 0; j < 13; j++) { inodeBlock.iNode[i][j] = Convert.ToInt32(sReader.Read()); } } } } catch (Exception exception) { //Console.WriteLine(exception.Message); } }
//This method writes the required data in the respective Inodes in the Inode block public void write(InodeBlock iNodeBlock) ////public void write(int blockNumber, InodeBlock iNodeBlock) { ////myPFS = System.IO.File.Open(path, FileMode.Open); ////seekBlock(blockNumber); ////using (StreamWriter sWriter = new StreamWriter(myPFS)) ////{ try { for (int i = 0; i < iNodeBlock.iNode.Length; i++) { myPFS = System.IO.File.Open(path, FileMode.Open); seekBlock(i + 1); using (StreamWriter sWriter = new StreamWriter(myPFS)) { //Console.WriteLine(i); sWriter.Write(iNodeBlock.iNode[i].InodeFlag); sWriter.Write(iNodeBlock.iNode[i].FileOwner); sWriter.Write(iNodeBlock.iNode[i].FileCreatedDate); sWriter.Write(iNodeBlock.iNode[i].FileCreatedTime); sWriter.Write(iNodeBlock.iNode[i].FileSize); sWriter.Write(iNodeBlock.iNode[i].Remarks); for (int j = 0; j < 13; j++) { sWriter.Write(iNodeBlock.iNode[i][j]); } foreach (var item in iNodeBlock.iNode[i].dataBlocks) { sWriter.Write(item); } } } } catch (Exception exception) { //Console.WriteLine(exception.Message); } //// } }
//This method initializes the file system with the data for the super block as well as //data for the inode blocks public void initializeDisk(int size) { //This sets the total blocks available in the file system superBlock.FileSystemBlocks = size; //This sets the total available data blocks in the file system superBlock.FreeBlocks = size - 5; //This method writes the first block in the file which is the super block //with the required data about the file system myDisk.write(0, superBlock); inodeBlock = new InodeBlock(); //int count = 0; ////for(int i = 1; i <= inodeBlock.iNode.Length; i++) ////{ //This method creates the inode block with the required inode data in each block ////myDisk.write(i, inodeBlock.iNode[count]); myDisk.write(inodeBlock); ////count++; ////} for (int i = 5; i < superBlock.FreeBlocks; i++) { myDisk.initializeDataBlocks(i); } }