Ejemplo n.º 1
0
        private Fat(BootSector bs, long offset)
        {
            this.bs = bs;
            fatType = bs.GetFatType();
            if (bs.GetSectorsPerFat() > int.MaxValue)
            {
                throw new ArgumentException("FAT too large");
            }

            if (bs.GetSectorsPerFat() <= 0)
            {
                throw new IOException(
                          "boot sector says there are " + bs.GetSectorsPerFat() +
                          " sectors per FAT");
            }

            if (bs.GetBytesPerSector() <= 0)
            {
                throw new IOException(
                          "boot sector says there are " + bs.GetBytesPerSector() +
                          " bytes per sector");
            }

            sectorCount          = (int)bs.GetSectorsPerFat();
            sectorSize           = bs.GetBytesPerSector();
            device               = bs.GetDevice();
            this.offset          = offset;
            lastAllocatedCluster = FIRST_CLUSTER;

            if (bs.GetDataClusterCount() > int.MaxValue)
            {
                throw
                    new IOException("too many data clusters");
            }

            if (bs.GetDataClusterCount() == 0)
            {
                throw
                    new IOException("no data clusters");
            }

            lastClusterIndex = (int)bs.GetDataClusterCount() + FIRST_CLUSTER;

            entries = new long[(int)((sectorCount * sectorSize) /
                                     fatType.GetEntrySize())];

            if (lastClusterIndex > entries.Length)
            {
                throw new IOException(
                          "file system has " + lastClusterIndex +
                          "clusters but only " + entries.Length + " FAT entries");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="Fat"/> as specified by a <see cref="BootSector"/>.
        /// </summary>
        /// <param name="bs">the boot sector specifying the <see cref="Fat"/> layout</param>
        /// <param name="fatNr">the number of the <see cref="Fat"/> to create</param>
        /// <returns>the <see cref="Fat"/> that was created</returns>
        /// <exception cref="IOException">IOException on write error</exception>
        /// <exception cref="ArgumentException">ArgumentException if fatNr is greater than
        ///     <see cref="BootSector.GetNrFats"/></exception>
        public static Fat Create(BootSector bs, int fatNr)
        {
            if (fatNr > bs.GetNrFats())
            {
                throw new ArgumentException(
                          "boot sector says there are only " + bs.GetNrFats() +
                          " FATs when creating FAT #" + fatNr);
            }

            var fatOffset = FatUtils.GetFatOffset(bs, fatNr);
            var result    = new Fat(bs, fatOffset);

            if (bs.GetDataClusterCount() > result.entries.Length)
            {
                throw new IOException("FAT too small for device");
            }

            result.Init(bs.GetMediumDescriptor());
            result.Write();
            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// This method is currently not implemented for <see cref="FatFileSystem"/> and
 /// always returns -1.
 /// </summary>
 /// <returns>always -1</returns>
 public override long GetTotalSpace()
 {
     return(bs.GetDataClusterCount() * bs.GetBytesPerCluster());
 }