/// <summary> /// Initializes a new FAT directory. /// </summary> /// <param name="aFileSystem">The FAT file system to which the directory belongs.</param> /// <param name="parent">The FAT directory which is the parent of the directory. Null for the root directory.</param> /// <param name="aName">The name of the directory.</param> /// <param name="aFirstCluster">The first cluster number of the directory.</param> public FATDirectory(FATFileSystem aFileSystem, FATDirectory parent, FOS_System.String aName, UInt32 aFirstCluster) : base(aFileSystem, parent, aName) { _theFile = new FATFile(aFileSystem, parent, Name, 0, aFirstCluster) { IsDirectoryFile = true }; }
/// <summary> /// Initializes a new FAT file stream for the specified file. /// </summary> /// <param name="aFile">The file to create a stream to.</param> /// <param name="ignoreFileSize">Whether to ignore the file size or not. True for directories.</param> public FATFileStream(FATFile aFile, bool ignoreFileSize) : base(aFile) { IgnoreFileSize = ignoreFileSize; if (TheFATFile == null) { ExceptionMethods.Throw(new Exception("Could not create FATFileStream. Specified file object was null!")); } GetClusterNums(); }
/// <summary> /// Creates a new file within the file system. /// </summary> /// <param name="name">The name of the file to create.</param> /// <param name="parent">The parent directory of the new file.</param> /// <returns>The new file listing.</returns> public override File NewFile(String name, Directory parent) { if (FATType != FATTypeEnum.FAT32) { ExceptionMethods.Throw(new Exceptions.NotSupportedException("FATFileSystem.NewFile for non-FAT32 not supported!")); } if (parent == null) { ExceptionMethods.Throw(new Exceptions.NullReferenceException()); } if (!(parent is FATDirectory)) { ExceptionMethods.Throw(new Exceptions.NotSupportedException("FATFileSystem.NewFile parent directory must be of type FATDirectory!")); } //BasicConsole.WriteLine("Getting directory listings..."); List listings = null; if (parent == null) { listings = GetRootDirectoryListings(); } else { listings = parent.GetListings(); } //BasicConsole.WriteLine("Got directory listings. Converting name..."); name = name.ToUpper(); //BasicConsole.WriteLine("Converted name. Checking if file exists..."); bool exists = Directory.ListingExists(name, listings); //BasicConsole.WriteLine("Check done."); if (!exists) { //BasicConsole.WriteLine("Getting next free cluster..."); UInt32 freeCluster = GetNextFreeCluster(2); //BasicConsole.WriteLine("Got next free. Clearing cluster..."); WriteCluster(freeCluster, null); //BasicConsole.WriteLine("Cleared. Setting FAT entry..."); SetFATEntryAndSave(freeCluster, GetFATEntryEOFValue(FATType)); //BasicConsole.WriteLine("Set FAT entry. Creating new file..."); File newFile = new FATFile(this, (FATDirectory)parent, name, 0, freeCluster); //BasicConsole.WriteLine("File created. Adding listing to parent..."); if (parent == null) { listings.Add(newFile); //BasicConsole.WriteLine("Added. Writing listings..."); _rootDirectoryFAT32.WriteListings(); } else { parent.AddListing(newFile); //BasicConsole.WriteLine("Added. Writing listings..."); parent.WriteListings(); } //BasicConsole.WriteLine("Written listings."); return newFile; } else { ExceptionMethods.Throw(new IOException("Listing (directory/file) with specified name already exists!")); } return null; }