Exemplo n.º 1
0
        /// <summary>
        /// Constructor for FatFileSystem in specified readOnly mode
        /// </summary>
        /// <param name="device">the <see cref="IBlockDevice"/> holding the file system</param>
        /// <param name="readOnly"></param>
        /// <param name="ignoreFatDifferences"></param>
        /// <exception cref="IOException">IOException on read error</exception>
        private FatFileSystem(IBlockDevice device, bool readOnly,
                              bool ignoreFatDifferences) : base(readOnly)
        {
            bs = BootSector.Read(device);

            if (bs.GetNrFats() <= 0)
            {
                throw new IOException(
                          "boot sector says there are no FATs");
            }

            filesOffset = FatUtils.GetFilesOffset(bs);
            fatType     = bs.GetFatType();
            fat         = Fat.Read(bs, 0);

            if (!ignoreFatDifferences)
            {
                for (var i = 1; i < bs.GetNrFats(); i++)
                {
                    var tmpFat = Fat.Read(bs, i);
                    if (!fat.Equals(tmpFat))
                    {
                        throw new IOException("FAT " + i + " differs from FAT 0");
                    }
                }
            }

            if (fatType == FatType.BaseFat32)
            {
                var f32Bs       = (Fat32BootSector)bs;
                var rootDirFile = new ClusterChain(fat,
                                                   f32Bs.GetRootDirFirstCluster(), IsReadOnly());
                rootDirStore = ClusterChainDirectory.ReadRoot(rootDirFile);
                fsiSector    = FsInfoSector.Read(f32Bs);

                if (fsiSector.GetFreeClusterCount() != fat.GetFreeClusterCount())
                {
                    throw new IOException("free cluster count mismatch - fat: " +
                                          fat.GetFreeClusterCount() + " - fsinfo: " +
                                          fsiSector.GetFreeClusterCount());
                }
            }
            else
            {
                rootDirStore =
                    Fat16RootDirectory.Read((Fat16BootSector)bs, readOnly);
                fsiSector = null;
            }

            rootDir = new FatLfnDirectory(rootDirStore, fat, IsReadOnly());
        }
Exemplo n.º 2
0
        public ClusterChain(Fat fat, long startCluster, bool readOnly) : base(readOnly)
        {
            this.fat = fat;

            if (startCluster != 0)
            {
                this.fat.TestCluster(startCluster);

                if (this.fat.IsFreeCluster(startCluster))
                {
                    throw new ArgumentException(
                              "cluster " + startCluster + " is free");
                }
            }

            device            = fat.GetDevice();
            dataOffset        = FatUtils.GetFilesOffset(fat.GetBootSector());
            this.startCluster = startCluster;
            clusterSize       = fat.GetBootSector().GetBytesPerCluster();
        }
Exemplo n.º 3
0
 /**
  * Returns the size of the data-containing portion of the file system.
  *
  * @return the number of bytes usable for storing user data
  */
 private long GetDataSize()
 {
     return((GetSectorCount() * GetBytesPerSector()) -
            FatUtils.GetFilesOffset(this));
 }