コード例 #1
0
 public bool SetMetadata(ImageInfo metadata) => true;
コード例 #2
0
ファイル: Write.cs プロジェクト: colombod/DiscImageChef
        public bool Create(string path, MediaType mediaType, Dictionary <string, string> options, ulong sectors,
                           uint sectorSize)
        {
            if (sectorSize != 512)
            {
                ErrorMessage = "Unsupported sector size";
                return(false);
            }

            if (!SupportedMediaTypes.Contains(mediaType))
            {
                ErrorMessage = $"Unsupport media format {mediaType}";
                return(false);
            }

            if (sectors * sectorSize / DEFAULT_BLOCK_SIZE > uint.MaxValue)
            {
                ErrorMessage = "Too many sectors for selected cluster size";
                return(false);
            }

            imageInfo = new ImageInfo {
                MediaType = mediaType, SectorSize = sectorSize, Sectors = sectors
            };

            try { writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); }
            catch (IOException e)
            {
                ErrorMessage = $"Could not create new image file, exception {e.Message}";
                return(false);
            }

            uint ibmEntries = (uint)(sectors * sectorSize / DEFAULT_BLOCK_SIZE);

            if (sectors * sectorSize % DEFAULT_BLOCK_SIZE > 0)
            {
                ibmEntries++;
            }

            uint headerSectors = 1 + ibmEntries * 4 / sectorSize;

            if (ibmEntries * 4 % sectorSize != 0)
            {
                headerSectors++;
            }
            ibm = new uint[ibmEntries];
            currentWritingPosition = headerSectors * sectorSize;

            vHdr = new VdiHeader
            {
                creator      = DIC_VDI,
                magic        = VDI_MAGIC,
                majorVersion = 1,
                minorVersion = 1,
                headerSize   = Marshal.SizeOf <VdiHeader>() - 72,
                imageType    = VdiImageType.Normal,
                offsetBlocks = sectorSize,
                offsetData   = currentWritingPosition,
                sectorSize   = sectorSize,
                size         = sectors * sectorSize,
                blockSize    = DEFAULT_BLOCK_SIZE,
                blocks       = ibmEntries,
                uuid         = Guid.NewGuid(),
                snapshotUuid = Guid.NewGuid()
            };

            for (uint i = 0; i < ibmEntries; i++)
            {
                ibm[i] = VDI_EMPTY;
            }

            IsWriting    = true;
            ErrorMessage = null;
            return(true);
        }
コード例 #3
0
ファイル: Write.cs プロジェクト: colombod/DiscImageChef
 public bool SetMetadata(ImageInfo metadata)
 {
     imageInfo.Comments = metadata.Comments;
     return(true);
 }
コード例 #4
0
        public bool Create(string path, MediaType mediaType, Dictionary <string, string> options, ulong sectors,
                           uint sectorSize)
        {
            if (sectorSize != 512)
            {
                ErrorMessage = "Unsupported sector size";
                return(false);
            }

            if (!SupportedMediaTypes.Contains(mediaType))
            {
                ErrorMessage = $"Unsupport media format {mediaType}";
                return(false);
            }

            // TODO: Correct this calculation
            if (sectors * sectorSize / 65536 > uint.MaxValue)
            {
                ErrorMessage = "Too many sectors for selected cluster size";
                return(false);
            }

            imageInfo = new ImageInfo {
                MediaType = mediaType, SectorSize = sectorSize, Sectors = sectors
            };

            try { writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); }
            catch (IOException e)
            {
                ErrorMessage = $"Could not create new image file, exception {e.Message}";
                return(false);
            }

            qHdr = new QCowHeader
            {
                magic           = QCOW_MAGIC,
                version         = QCOW_VERSION,
                size            = sectors * sectorSize,
                cluster_bits    = 12,
                l2_bits         = 9,
                l1_table_offset = (ulong)Marshal.SizeOf <QCowHeader>()
            };

            int shift = qHdr.cluster_bits + qHdr.l2_bits;

            clusterSize    = 1 << qHdr.cluster_bits;
            clusterSectors = 1 << (qHdr.cluster_bits - 9);
            l1Size         = (uint)((qHdr.size + (ulong)(1 << shift) - 1) >> shift);
            l2Size         = 1 << qHdr.l2_bits;

            l1Table = new ulong[l1Size];

            l1Mask = 0;
            int c = 0;

            l1Shift = qHdr.l2_bits + qHdr.cluster_bits;

            for (int i = 0; i < 64; i++)
            {
                l1Mask <<= 1;

                if (c >= 64 - l1Shift)
                {
                    continue;
                }

                l1Mask += 1;
                c++;
            }

            l2Mask = 0;
            for (int i = 0; i < qHdr.l2_bits; i++)
            {
                l2Mask = (l2Mask << 1) + 1;
            }

            l2Mask <<= qHdr.cluster_bits;

            sectorMask = 0;
            for (int i = 0; i < qHdr.cluster_bits; i++)
            {
                sectorMask = (sectorMask << 1) + 1;
            }

            byte[] empty = new byte[qHdr.l1_table_offset + l1Size * 8];
            writingStream.Write(empty, 0, empty.Length);

            IsWriting    = true;
            ErrorMessage = null;
            return(true);
        }
コード例 #5
0
ファイル: Write.cs プロジェクト: fossabot/DiscImageChef
        public bool Create(string path, MediaType mediaType, Dictionary <string, string> options, ulong sectors,
                           uint sectorSize)
        {
            if (options != null)
            {
                if (options.TryGetValue("separate", out string tmpValue))
                {
                    if (!bool.TryParse(tmpValue, out separateTracksWriting))
                    {
                        ErrorMessage = "Invalid value for split option";
                        return(false);
                    }

                    if (separateTracksWriting)
                    {
                        ErrorMessage = "Separate tracksnot yet implemented";
                        return(false);
                    }
                }
            }
            else
            {
                separateTracksWriting = false;
            }

            if (!SupportedMediaTypes.Contains(mediaType))
            {
                ErrorMessage = $"Unsupport media format {mediaType}";
                return(false);
            }

            imageInfo = new ImageInfo {
                MediaType = mediaType, SectorSize = sectorSize, Sectors = sectors
            };

            // TODO: Separate tracks
            try
            {
                writingBaseName  = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));
                descriptorStream = new StreamWriter(path, false, Encoding.ASCII);
            }
            catch (IOException e)
            {
                ErrorMessage = $"Could not create new image file, exception {e.Message}";
                return(false);
            }

            discimage = new CdrWinDisc
            {
                Disktype = mediaType,
                Sessions = new List <Session>(),
                Tracks   = new List <CdrWinTrack>()
            };

            trackFlags = new Dictionary <byte, byte>();
            trackIsrcs = new Dictionary <byte, string>();

            IsWriting    = true;
            ErrorMessage = null;
            return(true);
        }
コード例 #6
0
ファイル: Write.cs プロジェクト: fossabot/DiscImageChef
 public bool SetMetadata(ImageInfo metadata)
 {
     return(true);
 }