Esempio n. 1
0
 public override FilesystemEntry[] GetDirectoryListing(ulong aId) {
     var xBaseINodeNumber = (uint)aId;
     INode xINode;
     GetINode(xBaseINodeNumber,
              out xINode);
     byte[] xFSBuffer = new byte[BlockSize];
     var xResult = new List<FilesystemEntry>(10);
     var xDirEntriesPerFSBlock = BlockSize / sizeof(DirectoryEntry);
     uint xBlockId = 0;
     while (ReadINodeBlock(ref xINode,
                           xBlockId,
                           xFSBuffer)) {
         //HW.DebugUtil.WriteBinary("Ext2",
         //                         "Directory Entry binary",
         //                         xFSBuffer,
         //                         0,
         //                         (int)BlockSize);
         //HW.DebugUtil.SendNumber("Ext2",
         //                        "First byte of datablock",
         //                        xFSBuffer[0],
         //                        8);
         int xIndex = 0;
         var xIteration = 0;
         while (xIndex < BlockSize) {
             var xINodeNumber = ToUInt32(xFSBuffer, xIndex);
             var xRecLength = ToUInt16(xFSBuffer, xIndex + 4);
             
             // only include used items
             if (xINodeNumber > 0) {
                 // only include non ".." or "." items
                 if (xINodeNumber != xBaseINodeNumber) {
                     var xNameLength = xFSBuffer[xIndex + 6];
                     var xFileType = xFSBuffer[xIndex + 7];
                     if (!(xNameLength == 2 && xFSBuffer[xIndex + 8] == (byte)'.' && xFSBuffer[xIndex + 9] == (byte)'.')) {
                         var xFSEntry = new FilesystemEntry
                         {
                             Id = xINodeNumber,
                             IsDirectory = (xFileType == 2),
                             IsReadonly = true,
                             Filesystem = this
                         };
                         //xFSEntry.Size = GetINode(xINodeNumber).Size;
                         char[] xName = new char[xNameLength];
                         for (int c = 0; c < xName.Length; c++)
                         {
                             xName[c] = (char)xFSBuffer[xIndex + 8 + c];
                         }
                         xFSEntry.Name = new string(xName);
                         if (!xFSEntry.Name.Equals("lost+found"))
                         {
                             xResult.Add(xFSEntry);
                         }
                     }
                 }
             }
             xIndex += xRecLength;
             xIteration++;
             if (xIteration == 5)
             {
                 break;
             }
             //break;
         }
         xBlockId++;
     }
     for (int i = 0; i < xResult.Count; i++) {
         INode xTheINode;
         GetINode((uint)xResult[i].Id,
                  out xTheINode);
         xResult[i].Size = xTheINode.Size;
     }
     return xResult.ToArray();
 }
Esempio n. 2
0
        /// <summary>
        /// Retrieves all files and directories in the given directory entry.
        /// </summary>
        /// <param name="aDirectory">Must be a Directory entry.</param>
        /// <returns></returns>
        public static FilesystemEntry[] GetDirectoryListing(FilesystemEntry aDirectory)
        {
            if (!aDirectory.IsDirectory)
                throw new ArgumentException("Only Directories are allowed");

            var xFS = aDirectory.Filesystem;
            //// Cosmos.Debug.Debugger.SendMessage("GetDirectorylisting", "ID is " + aDirectory.Id);
            //aDirectory.
            return xFS.GetDirectoryListing(aDirectory.Id);
        }
Esempio n. 3
0
        /// <summary>
        /// Get the files in the given Directory entry
        /// </summary>
        /// <param name="aDir">Must be a Directory</param>
        /// <returns></returns>
        public static FilesystemEntry[] GetFiles(FilesystemEntry aDir)
        {
            // Cosmos.Debug.Debugger.SendMessage("GetFiles(FileystemEntry)", aDir.Name);

            if (aDir == null)
                throw new ArgumentNullException("aDir in GetFiles(FilesystemEntry)");

            if (!aDir.IsDirectory)
                throw new Exception("Must be a directory");

            List<FilesystemEntry> xFiles = new List<FilesystemEntry>();
            foreach (FilesystemEntry xEntry in VFSManager.GetDirectoryListing(aDir))
            {
                // Cosmos.Debug.Debugger.SendMessage("GetFiles(FileystemEntry)", "Found " + xEntry.Name);
                if (!xEntry.IsDirectory)
                    xFiles.Add(xEntry);
            }

            return xFiles.ToArray();
        }
Esempio n. 4
0
        public static FilesystemEntry[] GetVolumes()
        {
            //if (aFilesystems == null)
            //    throw new ArgumentNullException("mFilesystems has not been initialized");

            //Get volumes
            var xResult = new FilesystemEntry[mFilesystems.Count];
            for (int i = 0; i < mFilesystems.Count; i++)
            {
                xResult[i] = GetVolumeEntry(i);
            }
            return xResult;
        }