Ejemplo n.º 1
0
        protected virtual void InitializeFileSystems()
        {
            for (int i = 0; i < mPartitions.Count; i++)
            {
                string xRootPath = string.Concat(i, VolumeSeparatorChar, DirectorySeparatorChar);
                Cosmos.System.FileSystem.FileSystem xFileSystem = null;
                switch (Cosmos.System.FileSystem.FileSystem.GetFileSystemType(mPartitions[i]))
                {
                case FileSystemType.FAT:
                    xFileSystem = new FatFileSystem(mPartitions[i]);
                    mFileSystems.Add(new KVP <string, Cosmos.System.FileSystem.FileSystem>(xRootPath, xFileSystem));
                    break;

                default:
                    FatHelpers.Debug("Unknown filesystem type!");
                    return;
                }

                //global::System.Console.Write("i = ");
                //global::System.Console.WriteLine(i.ToString());
                //global::System.Console.Write("mFileSystems.Count = ");
                //global::System.Console.WriteLine(mFileSystems.Count);
                var xEntry = mFileSystems[i];
                if (xEntry.Key == xRootPath)
                {
                    var xFatFS = (FatFileSystem)xFileSystem;
                    FatHelpers.Debug("-------File System--------");
                    FatHelpers.Debug("Bytes per Cluster: " + xFatFS.BytesPerCluster);
                    FatHelpers.Debug("Bytes per Sector: " + xFatFS.BytesPerSector);
                    FatHelpers.Debug("Cluster Count: " + xFatFS.ClusterCount);
                    FatHelpers.Debug("Data Sector: " + xFatFS.DataSector);
                    FatHelpers.Debug("Data Sector Count: " + xFatFS.DataSectorCount);
                    FatHelpers.Debug("FAT Sector Count: " + xFatFS.FatSectorCount);
                    FatHelpers.Debug("FAT Type: " + xFatFS.FatType);
                    FatHelpers.Debug("Number of FATS: " + xFatFS.NumberOfFATs);
                    FatHelpers.Debug("Reserved Sector Count: " + xFatFS.ReservedSectorCount);
                    FatHelpers.Debug("Root Cluster: " + xFatFS.RootCluster);
                    FatHelpers.Debug("Root Entry Count: " + xFatFS.RootEntryCount);
                    FatHelpers.Debug("Root Sector: " + xFatFS.RootSector);
                    FatHelpers.Debug("Root Sector Count: " + xFatFS.RootSectorCount);
                    FatHelpers.Debug("Sectors per Cluster: " + xFatFS.SectorsPerCluster);
                    FatHelpers.Debug("Total Sector Count: " + xFatFS.TotalSectorCount);

                    //Console.WriteLine();
                    //Console.WriteLine("Mapping Drive C...");
                    //FatFileSystem.AddMapping("C", mFileSystem);
                    //SentinelKernel.System.Filesystem.FAT.Listing.FatDirectory dir = new Sys.Filesystem.FAT.Listing.FatDirectory(mFileSystem, "Sentinel");
                }
                else
                {
                    FatHelpers.Debug("No filesystem found.");
                }
            }
        }
Ejemplo n.º 2
0
        private Directory DoGetDirectory(string aPath, Cosmos.System.FileSystem.FileSystem aFS)
        {
            if (aFS == null)
            {
                throw new Exception("File system can not be null.");
            }
            FatHelpers.Debug("In SentinelVFS.DoGetDirectory");
            FatHelpers.Debug("Path = " + aPath);
            string[] xPathParts = VFSManager.SplitPath(aPath);

            if (xPathParts.Length == 1)
            {
                return(GetVolume(aFS, aPath));
            }

            Directory xBaseDirectory = null;

            // start at index 1, because 0 is the volume
            for (int i = 1; i < xPathParts.Length; i++)
            {
                var xPathPart  = xPathParts[i];
                var xPartFound = false;
                var xListing   = aFS.GetDirectoryListing(xBaseDirectory);

                for (int j = 0; j < xListing.Count; j++)
                {
                    var xListingItem = xListing[j];
                    if (String.Equals(xListingItem.Name, xPathPart, StringComparison.OrdinalIgnoreCase))
                    {
                        if (xListingItem is Directory)
                        {
                            xBaseDirectory = (Directory)xListingItem;
                            xPartFound     = true;
                        }
                        else
                        {
                            throw new Exception("Path part '" + xPathPart + "' found, but not a directory!");
                        }
                    }
                }

                if (!xPartFound)
                {
                    throw new Exception("Path part '" + xPathPart + "' not found!");
                }
            }
            return(xBaseDirectory);
        }
Ejemplo n.º 3
0
 public Directory GetVolume(Cosmos.System.FileSystem.FileSystem filesystem, string name)
 {
     return(filesystem.GetRootDirectory(name));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to get a directory entry for a path in a file system.
        /// </summary>
        /// <param name="aPath">The path.</param>
        /// <param name="aFS">The file system.</param>
        /// <returns>A directory entry for the path.</returns>
        /// <exception cref="ArgumentException">
        /// <list type="bullet">
        /// <item>Thrown if aPath is null or empty.</item>
        /// <item>Thrown when aFS root path is null or empty.</item>
        /// <item>Thrown on memory error.</item>
        /// <item>Fatal error.</item>
        /// </list>
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <list type="bullet">
        /// <item>Thrown if aFS is null.</item>
        /// <item>Thrown when root directory is null.</item>
        /// <item>Thrown on memory error.</item>
        /// </list>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <list type="bullet">
        /// <item>Thrown when root directory address is smaller then root directory address.</item>
        /// <item>Thrown on memory error.</item>
        /// </list>
        /// </exception>
        /// <exception cref="OverflowException">
        /// <list type="bullet">
        /// <item>Thrown when aPath is too deep.</item>
        /// <item>Thrown when data lenght is greater then Int32.MaxValue.</item>
        /// </list>
        /// </exception>
        /// <exception cref="Exception">
        /// <list type="bullet">
        /// <item>Thrown when data size invalid.</item>
        /// <item>Thrown on invalid directory entry type.</item>
        /// <item>Thrown when aPath entry not found.</item>
        /// </list>
        /// </exception>
        /// <exception cref="DecoderFallbackException">Thrown on memory error.</exception>
        private DirectoryEntry DoGetDirectoryEntry(string aPath, FileSystem aFS)
        {
            Global.mFileSystemDebugger.SendInternal("--- CosmosVFS.DoGetDirectoryEntry ---");

            if (String.IsNullOrEmpty(aPath))
            {
                throw new ArgumentException("Argument is null or empty", nameof(aPath));
            }

            if (aFS == null)
            {
                throw new ArgumentNullException(nameof(aFS));
            }

            Global.mFileSystemDebugger.SendInternal("aPath = " + aPath);

            string[] xPathParts = VFSManager.SplitPath(aPath);

            DirectoryEntry xBaseDirectory = GetVolume(aFS);

            if (xPathParts.Length == 1)
            {
                Global.mFileSystemDebugger.SendInternal("Returning the volume.");
                return(xBaseDirectory);
            }

            // start at index 1, because 0 is the volume
            for (int i = 1; i < xPathParts.Length; i++)
            {
                var xPathPart = xPathParts[i].ToLower();

                var xPartFound = false;
                var xListing   = aFS.GetDirectoryListing(xBaseDirectory);

                Global.mFileSystemDebugger.SendInternal("xPathPart = " + xPathPart);

                for (int j = 0; j < xListing.Count; j++)
                {
                    var    xListingItem     = xListing[j];
                    string xListingItemName = xListingItem.mName.ToLower();
                    xPathPart = xPathPart.ToLower();

                    Global.mFileSystemDebugger.SendInternal(xListingItemName);

                    if (xListingItemName == xPathPart)
                    {
                        xBaseDirectory = xListingItem;
                        Global.mFileSystemDebugger.SendInternal("Now checking: " + xBaseDirectory.mFullPath);
                        xPartFound = true;
                        break;
                    }
                }

                if (!xPartFound)
                {
                    throw new Exception("Path part '" + xPathPart + "' not found!");
                }
            }

            Global.mFileSystemDebugger.SendInternal("Returning: " + xBaseDirectory.mFullPath);
            return(xBaseDirectory);
        }