예제 #1
0
파일: FATFile.cs 프로젝트: zrbruce/FlingOS
        /// <summary>
        /// Deletes the listing from the file system.
        /// </summary>
        /// <returns>True if the listing was deleted. Otherwise, false.</returns>
        public override bool Delete()
        {
            if (TheFATFileSystem.FATType != FATFileSystem.FATTypeEnum.FAT32)
            {
                ExceptionMethods.Throw(new Exceptions.NotSupportedException("FATFile.Delete for non-FAT32 not supported!"));
            }

#if FATFILE_TRACE
            BasicConsole.WriteLine("FATFile.Delete : Reading cluster chain...");
#endif
            UInt32List clusters = TheFATFileSystem.ReadClusterChain(Size, FirstClusterNum);
#if FATFILE_TRACE
            BasicConsole.WriteLine("FATFile.Delete : Processing cluster chain...");
#endif
            for (int i = 0; i < clusters.Count; i++)
            {
#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Writing cluster...");
#endif
                //Write 0s (null) to clusters
                TheFATFileSystem.WriteCluster(clusters[i], null);

#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Setting FAT entry...");
#endif
                //Write "empty" to FAT entries
                TheFATFileSystem.SetFATEntryAndSave(clusters[i], 0);
            }

            //If the file actually being used to read/write a FATDirectory,
            //      it will not be in the parent listings, the FATDirectory instance will be.
            //      So we should not attempt to edit the parent listings from within the
            //      FATFile instance.
            if (!IsDirectoryFile)
            {
#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Removing listing...");
#endif
                //Remove listing
                Parent.RemoveListing(this);

#if FATFILE_TRACE
                BasicConsole.WriteLine("FATFile.Delete : Writing listings...");
#endif
                //Write listings
                Parent.WriteListings();
            }

#if FATFILE_TRACE
            BasicConsole.WriteLine("FATFile.Delete : Complete.");
#endif

            return(true);
        }