diff options
Diffstat (limited to 'vendor/github.com/hooklift')
-rw-r--r-- | vendor/github.com/hooklift/iso9660/LICENSE | 374 | ||||
-rw-r--r-- | vendor/github.com/hooklift/iso9660/README.md | 25 | ||||
-rw-r--r-- | vendor/github.com/hooklift/iso9660/iso9660.go | 418 | ||||
-rw-r--r-- | vendor/github.com/hooklift/iso9660/reader.go | 251 | ||||
-rw-r--r-- | vendor/github.com/hooklift/iso9660/writer.go | 1 |
5 files changed, 1069 insertions, 0 deletions
diff --git a/vendor/github.com/hooklift/iso9660/LICENSE b/vendor/github.com/hooklift/iso9660/LICENSE new file mode 100644 index 00000000..52d13511 --- /dev/null +++ b/vendor/github.com/hooklift/iso9660/LICENSE @@ -0,0 +1,374 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. + diff --git a/vendor/github.com/hooklift/iso9660/README.md b/vendor/github.com/hooklift/iso9660/README.md new file mode 100644 index 00000000..8a529a4a --- /dev/null +++ b/vendor/github.com/hooklift/iso9660/README.md @@ -0,0 +1,25 @@ +# iso9660 +[![GoDoc](https://godoc.org/github.com/hooklift/iso9660?status.svg)](https://godoc.org/github.com/hooklift/iso9660) +[![Build Status](https://travis-ci.org/hooklift/iso9660.svg?branch=master)](https://travis-ci.org/hooklift/iso9660) + +Go library and CLI to extract data from ISO9660 images. + +### CLI +``` +$ ./iso9660 +Usage: + iso9660 <image-path> <destination-path> + iso9660 -h | --help + iso9660 --version +``` + +### Library +An example on how to use the library to extract files and directories from an ISO image can be found in our CLI source code at: +https://github.com/hooklift/iso9660/blob/master/cmd/iso9660/main.go + +### Not supported +* Reading files recorded in interleave mode +* Multi-extent or reading individual files larger than 4GB +* Joliet extensions, meaning that file names longer than 32 characters are going to be truncated. Unicode characters are not going to be properly decoded either. +* Multisession extension +* Rock Ridge extension, making unable to return recorded POSIX permissions, timestamps as well as owner and group for files and directories. diff --git a/vendor/github.com/hooklift/iso9660/iso9660.go b/vendor/github.com/hooklift/iso9660/iso9660.go new file mode 100644 index 00000000..c5a114cd --- /dev/null +++ b/vendor/github.com/hooklift/iso9660/iso9660.go @@ -0,0 +1,418 @@ +// Package iso9660 implements ECMA-119 standard, also known as ISO 9660. +// +// References: +// +// * https://en.wikipedia.org/wiki/ISO_9660 +// +// * http://alumnus.caltech.edu/~pje/iso9660.html +// +// * http://users.telenet.be/it3.consultants.bvba/handouts/ISO9960.html +// +// * http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf +// +// * http://www.drdobbs.com/database/inside-the-iso-9660-filesystem-format/184408899 +// +// * http://www.cdfs.com +// +// * http://wiki.osdev.org/ISO_9660 +package iso9660 + +import ( + "io" + "os" + "strings" + "time" +) + +// File represents a concrete implementation of os.FileInfo interface for +// accessing ISO 9660 file data +type File struct { + DirectoryRecord + fileID string + // We have the raw image here only to be able to access file extents + image *os.File +} + +// Name returns the file's name. +func (f *File) Name() string { + name := strings.Split(f.fileID, ";")[0] + return strings.ToLower(name) +} + +// Size returns the file size in bytes +func (f *File) Size() int64 { + return int64(f.ExtentLengthBE) +} + +// Mode returns file's mode and permissions bits. Since we don't yet support +// Rock Ridge extensions we cannot extract POSIX permissions and the rest of the +// normal metadata. So, right we return 0740 for directories and 0640 for files. +func (f *File) Mode() os.FileMode { + if f.IsDir() { + return os.FileMode(0740) + } + return os.FileMode(0640) +} + +// ModTime returns file's modification time. +func (f *File) ModTime() time.Time { + return time.Now() +} + +// IsDir tells whether the file is a directory or not. +func (f *File) IsDir() bool { + if (f.FileFlags & 2) == 2 { + return true + } + return false +} + +// Sys returns io.Reader instance pointing to the file's content if it is not a directory, nil otherwise. +func (f *File) Sys() interface{} { + if f.IsDir() { + return nil + } + + return io.NewSectionReader(f.image, int64(f.ExtentLocationBE*sectorSize), int64(f.ExtentLengthBE)) +} + +const ( + bootRecord = 0 + primaryVol = 1 + supplementaryVol = 2 + volPartition = 3 + volSetTerminator = 255 + // System area goes from sectors 0x00 to 0x0F. Volume descriptors can be + // found starting at sector 0x10 + dataAreaSector = 0x10 + sectorSize = 2048 +) + +// VolumeDescriptor identify the volume, the partitions recorded on the volume, +// the volume creator(s), certain attributes of the volume, the location of +// other recorded descriptors and the version of the standard which applies +// to the volume descriptor. +// +// When preparing to mount a CD, your first action will be reading the volume +// descriptors (specifically, you will be looking for the Primary Volume Descriptor). +// Since sectors 0x00-0x0F of the CD are reserved as System Area, the Volume +// Descriptors can be found starting at sector 0x10. +type VolumeDescriptor struct { + // 0: BootRecord + // 1: Primary Volume Descriptor + // 2: Supplementary Volume Descriptor + // 3: Volume Partition Descriptor + // 4-254: Reserved + // 255: Volume Descriptor Set Terminator + Type byte + // Always "CD001". + StandardID [5]byte + //Volume Descriptor Version (0x01). + Version byte +} + +// BootRecord identifies a system which can recognize and act upon the content +// of the field reserved for boot system use in the Boot Record, and shall +// contain information which is used to achieve a specific state for a system or +// for an application. +type BootRecord struct { + VolumeDescriptor + SystemID [32]byte + ID [32]byte + SystemUse [1977]byte +} + +// Terminator indicates the termination of a Volume Descriptor Set. +type Terminator struct { + VolumeDescriptor + // All bytes of this field are set to (00). + Reserved [2041]byte +} + +// PrimaryVolumePart1 represents the Primary Volume Descriptor first half, before the +// root directory record. We are only reading big-endian values so placeholders +// are used for little-endian ones. +type PrimaryVolumePart1 struct { + VolumeDescriptor + // Unused + _ byte // 00 + // The name of the system that can act upon sectors 0x00-0x0F for the volume. + SystemID [32]byte + // Identification of this volume. + ID [32]byte + //Unused2 + _ [8]byte + // Amount of data available on the CD-ROM. Ignores little-endian order. + // Takes big-endian encoded value. + VolumeSpaceSizeLE int32 + VolumeSpaceSizeBE int32 + Unused2 [32]byte + // The size of the set in this logical volume (number of disks). Ignores + // little-endian order. Takes big-endian encoded value. + VolumeSetSizeLE int16 + VolumeSetSizeBE int16 + // The number of this disk in the Volume Set. Ignores little-endian order. + // Takes big-endian encoded value. + VolumeSeqNumberLE int16 + VolumeSeqNumberBE int16 + // The size in bytes of a logical block. NB: This means that a logical block + // on a CD could be something other than 2 KiB! + LogicalBlkSizeLE int16 + LogicalBlkSizeBE int16 + // The size in bytes of the path table. Ignores little-endian order. + // Takes big-endian encoded value. + PathTableSizeLE int32 + PathTableSizeBE int32 + // LBA location of the path table. The path table pointed to contains only + // little-endian values. + LocPathTableLE int32 + // LBA location of the optional path table. The path table pointed to contains + // only little-endian values. Zero means that no optional path table exists. + LocOptPathTableLE int32 + // LBA location of the path table. The path table pointed to contains + // only big-endian values. + LocPathTableBE int32 + // LBA location of the optional path table. The path table pointed to contains + // only big-endian values. Zero means that no optional path table exists. + LocOptPathTableBE int32 +} + +// DirectoryRecord describes the characteristics of a file or directory, +// beginning with a length octet describing the size of the entire entry. +// Entries themselves are of variable length, up to 255 octets in size. +// Attributes for the file described by the directory entry are stored in the +// directory entry itself (unlike UNIX). +// The root directory entry is a variable length object, so that the name can be of variable length. +// +// Important: before each entry there can be "fake entries" to support the Long File Name. +// +// Even if a directory spans multiple sectors, the directory entries are not +// permitted to cross the sector boundary (unlike the path table). Where there +// is not enough space to record an entire directory entry at the end of a sector, +// that sector is zero-padded and the next consecutive sector is used. +// Unfortunately, the date/time format is different from that used in the Primary +// Volume Descriptor. +type DirectoryRecord struct { + // Extended Attribute Record length, stored at the beginning of + // the file's extent. + ExtendedAttrLen byte + // Location of extent (Logical Block Address) in both-endian format. + ExtentLocationLE uint32 + ExtentLocationBE uint32 + // Data length (size of extent) in both-endian format. + ExtentLengthLE uint32 + ExtentLengthBE uint32 + // Date and the time of the day at which the information in the Extent + // described by the Directory Record was recorded. + RecordedTime [7]byte + // If this Directory Record identifies a directory then bit positions 2, 3 + // and 7 shall be set to ZERO. If no Extended Attribute Record is associated + // with the File Section identified by this Directory Record then bit + // positions 3 and 4 shall be set to ZERO. -- 9.1.6 + FileFlags byte + // File unit size for files recorded in interleaved mode, zero otherwise. + FileUnitSize byte + // Interleave gap size for files recorded in interleaved mode, zero otherwise. + InterleaveGapSize byte + // Volume sequence number - the volume that this extent is recorded on, in + // 16 bit both-endian format. + VolumeSeqNumberLE uint16 + VolumeSeqNumberBE uint16 + // Length of file identifier (file name). This terminates with a ';' + // character followed by the file ID number in ASCII coded decimal ('1'). + FileIDLength byte + // The interpretation of this field depends as follows on the setting of the + // Directory bit of the File Flags field. If set to ZERO, it shall mean: + // + // − The field shall specify an identification for the file. + // − The characters in this field shall be d-characters or d1-characters, SEPARATOR 1, SEPARATOR 2. + // − The field shall be recorded as specified in 7.5. If set to ONE, it shall mean: + // − The field shall specify an identification for the directory. + // − The characters in this field shall be d-characters or d1-characters, or only a (00) byte, or only a (01) byte. + // − The field shall be recorded as specified in 7.6. + // fileID string +} + +// PrimaryVolumePart2 represents the Primary Volume Descriptor half after the +// root directory record. +type PrimaryVolumePart2 struct { + // Identifier of the volume set of which this volume is a member. + VolumeSetID [128]byte + // The volume publisher. For extended publisher information, the first byte + // should be 0x5F, followed by the filename of a file in the root directory. + // If not specified, all bytes should be 0x20. + PublisherID [128]byte + // The identifier of the person(s) who prepared the data for this volume. + // For extended preparation information, the first byte should be 0x5F, + // followed by the filename of a file in the root directory. If not specified, + // all bytes should be 0x20. + DataPreparerID [128]byte + // Identifies how the data are recorded on this volume. For extended information, + // the first byte should be 0x5F, followed by the filename of a file in the root + // directory. If not specified, all bytes should be 0x20. + AppID [128]byte + // Filename of a file in the root directory that contains copyright + // information for this volume set. If not specified, all bytes should be 0x20. + CopyrightFileID [37]byte + // Filename of a file in the root directory that contains abstract information + // for this volume set. If not specified, all bytes should be 0x20. + AbstractFileID [37]byte + // Filename of a file in the root directory that contains bibliographic + // information for this volume set. If not specified, all bytes should be 0x20. + BibliographicFileID [37]byte + // The date and time of when the volume was created. + CreationTime [17]byte + // The date and time of when the volume was modified. + ModificationTime [17]byte + // The date and time after which this volume is considered to be obsolete. + // If not specified, then the volume is never considered to be obsolete. + ExpirationTime [17]byte + // The date and time after which the volume may be used. If not specified, + // the volume may be used immediately. + EffectiveTime [17]byte + // The directory records and path table version (always 0x01). + FileStructVersion byte + // Reserved. Always 0x00. + _ byte + // Contents not defined by ISO 9660. + AppUse [512]byte + // Reserved by ISO. + _ [653]byte +} + +// PrimaryVolume descriptor acts much like the superblock of the UNIX filesystem, providing +// details on the ISO-9660 compliant portions of the disk. While we can have +// many kinds of filesystems on a single ISO-9660 CD-ROM, we can have only one +// ISO-9660 file structure (found as the primary volume-descriptor type). +// +// Directory entries are successively stored within this region. Evaluation of +// the ISO 9660 filenames is begun at this location. The root directory is stored +// as an extent, or sequential series of sectors, that contains each of the +// directory entries appearing in the root. +// +// Since ISO 9660 works by segmenting the CD-ROM into logical blocks, the size +// of these blocks is found in the primary volume descriptor as well. +type PrimaryVolume struct { + PrimaryVolumePart1 + DirectoryRecord DirectoryRecord + PrimaryVolumePart2 +} + +// SupplementaryVolume is used by Joliet. +type SupplementaryVolume struct { + VolumeDescriptor + Flags int `struc:"int8"` + SystemID string `struc:"[32]byte"` + ID string `struc:"[32]byte"` + Unused byte + VolumeSpaceSize int `struc:"int32"` + EscapeSequences string `struc:"[32]byte"` + VolumeSetSize int `struc:"int16"` + VolumeSeqNumber int `struc:"int16"` + LogicalBlkSize int `struc:"int16"` + PathTableSize int `struc:"int32"` + LocLPathTable int `struc:"int32"` + LocOptLPathTable int `struc:"int32"` + LocMPathTable int `struc:"int32"` + LocOptMPathTable int `struc:"int32"` + RootDirRecord DirectoryRecord + VolumeSetID string `struc:"[128]byte"` + PublisherID string `struc:"[128]byte"` + DataPreparerID string `struc:"[128]byte"` + AppID string `struc:"[128]byte"` + CopyrightFileID string `struc:"[37]byte"` + AbstractFileID string `struc:"[37]byte"` + BibliographicFileID string `struc:"[37]byte"` + CreationTime Timestamp + ModificationTime Timestamp + ExpirationTime Timestamp + EffectiveTime Timestamp + FileStructVersion int `struc:"int8"` + Reserved byte + AppData [512]byte + Reserved2 byte +} + +// PartitionVolume ... +type PartitionVolume struct { + VolumeDescriptor + Unused byte + SystemID string `struc:"[32]byte"` + ID string `struc:"[32]byte"` + Location int `struc:"int8"` + Size int `struc:"int8"` + SystemUse [1960]byte +} + +// Timestamp ... +type Timestamp struct { + Year int `struc:"[4]byte"` + Month int `struc:"[2]byte"` + DayOfMonth int `struc:"[2]byte"` + Hour int `struc:"[2]byte"` + Minute int `struc:"[2]byte"` + Second int `struc:"[2]byte"` + Millisecond int `struc:"[2]byte"` + GMTOffset int `struc:"uint8"` +} + +// ExtendedAttrRecord are simply a way to extend the attributes of files. +// Since attributes vary according to the user, most everyone has a different +// opinion on what a file attribute should specify. +type ExtendedAttrRecord struct { + OwnerID int `struc:"int16"` + GroupID int `struc:"int16"` + Permissions int `struc:"int16"` + CreationTime Timestamp + ModificationTime Timestamp + ExpirationTime Timestamp + // Specifies the date and the time of the day at which the information in + // the file may be used. If the date and time are not specified then the + // information may be used at once. + EffectiveTime Timestamp + Format int `struc:"uint8"` + Attributes int `struc:"uint8"` + Length int `struc:"int16"` + SystemID string `struc:"[32]byte"` + SystemUse [64]byte + Version int `struc:"uint8"` + EscapeSeqLength int `struc:"uint8"` + Reserved [64]byte + AppUseLength int `struc:"int16,sizeof=AppUse"` + AppUse []byte + EscapeSequences []byte `struc:"sizefrom=AppUseLength"` +} + +// PathTable contains a well-ordered sequence of records describing every +// directory extent on the CD. There are some exceptions with this: the Path +// Table can only contain 65536 records, due to the length of the "Parent Directory Number" field. +// If there are more than this number of directories on the disc, some CD +// authoring software will ignore this limit and create a non-compliant +// CD (this applies to some earlier versions of Nero, for example). If your +// file system uses the path table, you should be aware of this possibility. +// Windows uses the Path Table and will fail with such non-compliant +// CD's (additional nodes exist but appear as zero-byte). Linux, which uses +// the directory tables is not affected by this issue. The location of the path +// tables can be found in the Primary Volume Descriptor. There are two table types +// - the L-Path table (relevant to x86) and the M-Path table. The only +// difference between these two tables is that multi-byte values in the L-Table +// are LSB-first and the values in the M-Table are MSB-first. +// +// The path table is in ascending order of directory level and is alphabetically +// sorted within each directory level. +type PathTable struct { + DirIDLength int `struc:"uint8,sizeof=DirName"` + ExtendedAttrsLen int `struc:"uint8"` + // Number the Logical Block Number of the first Logical Block allocated to + // the Extent in which the directory is recorded. + // This is in a different format depending on whether this is the L-Table or + // M-Table (see explanation above). + ExtentLocation int `struc:"int32"` + // Number of record for parent directory (or 1 for the root directory), as a + // word; the first record is number 1, the second record is number 2, etc. + // Directory number of parent directory (an index in to the path table). + // This is the field that limits the table to 65536 records. + ParentDirNumber int `struc:"int16"` + // Directory Identifier (name) in d-characters. + DirName string +} diff --git a/vendor/github.com/hooklift/iso9660/reader.go b/vendor/github.com/hooklift/iso9660/reader.go new file mode 100644 index 00000000..1c7d00a6 --- /dev/null +++ b/vendor/github.com/hooklift/iso9660/reader.go @@ -0,0 +1,251 @@ +package iso9660 + +import ( + "encoding/binary" + "errors" + "fmt" + "io" + "os" + "path/filepath" + + "github.com/c4milo/gotoolkit" +) + +var ( + // ErrInvalidImage is returned when an attempt to unpack the image Primary Volume Descriptor failed or + // when the end of the image was reached without finding a primary volume descriptor + ErrInvalidImage = func(err error) error { return fmt.Errorf("invalid-iso9660-image: %s", err) } + // ErrCorruptedImage is returned when a seek operation, on the image, failed. + ErrCorruptedImage = func(err error) error { return fmt.Errorf("corrupted-image: %s", err) } +) + +// Reader defines the state of the ISO9660 image reader. It needs to be instantiated +// from its constructor. +type Reader struct { + // File descriptor to the opened ISO image + image *os.File + // Copy of unencoded Primary Volume Descriptor + pvd PrimaryVolume + // Queue used to walk through file system iteratively + queue gotoolkit.Queue + // Current sector + sector uint32 + // Current bytes read from current sector. + read uint32 +} + +// NewReader creates a new ISO 9660 image reader. +func NewReader(rs *os.File) (*Reader, error) { + // Starts reading from image data area + sector := dataAreaSector + // Iterates over volume descriptors until it finds the primary volume descriptor + // or an error condition. + for { + offset, err := rs.Seek(int64(sector*sectorSize), os.SEEK_SET) + if err != nil { + return nil, ErrCorruptedImage(err) + } + + var volDesc VolumeDescriptor + if err := binary.Read(rs, binary.BigEndian, &volDesc); err != nil { + return nil, ErrCorruptedImage(err) + } + + if volDesc.Type == primaryVol { + // backs up to the beginning of the sector again in order to unpack + // the entire primary volume descriptor more easily. + if _, err := rs.Seek(offset, os.SEEK_SET); err != nil { + return nil, ErrCorruptedImage(err) + } + + reader := new(Reader) + reader.image = rs + reader.queue = new(gotoolkit.SliceQueue) + + if err := reader.unpackPVD(); err != nil { + return nil, ErrCorruptedImage(err) + } + + return reader, nil + } + + if volDesc.Type == volSetTerminator { + return nil, ErrInvalidImage(errors.New("Volume Set Terminator reached. A Primary Volume Descriptor was not found.")) + } + sector++ + } +} + +// Skip skips the given number of directory records. +func (r *Reader) Skip(n int) error { + var drecord File + var len byte + var err error + for i := 0; i < n; i++ { + if len, err = r.unpackDRecord(&drecord); err != nil { + return err + } + r.read += uint32(len) + } + return nil +} + +// Next moves onto the next directory record present in the image. +// It does not use the Path Table since the goal is to read everything +// from the ISO image. +func (r *Reader) Next() (os.FileInfo, error) { + if r.queue.IsEmpty() { + return nil, io.EOF + } + + // We only dequeue the directory when it does not contain more children + // or when it is empty and there is no children to iterate over. + item, err := r.queue.Peek() + if err != nil { + panic(err) + } + + f := item.(File) + if r.sector == 0 { + r.sector = f.ExtentLocationBE + _, err := r.image.Seek(int64(r.sector*sectorSize), os.SEEK_SET) + if err != nil { + return nil, ErrCorruptedImage(err) + } + + // Skips . and .. directories + if err = r.Skip(2); err != nil { + return nil, ErrCorruptedImage(err) + } + } + + var drecord File + var len byte + if (r.read % sectorSize) == 0 { + r.sector++ + _, err := r.image.Seek(int64(r.sector*sectorSize), os.SEEK_SET) + if err != nil { + return nil, ErrCorruptedImage(err) + } + } + + if len, err = r.unpackDRecord(&drecord); err != nil && err != io.EOF { + return nil, ErrCorruptedImage(err) + } + r.read += uint32(len) + + if err == io.EOF { + // directory record is empty, sector space wasted, move onto next sector. + rsize := (sectorSize - (r.read % sectorSize)) + buf := make([]byte, rsize) + if err := binary.Read(r.image, binary.BigEndian, buf); err != nil { + return nil, ErrCorruptedImage(err) + } + r.read += rsize + } + + // If there is no more entries in the current directory, dequeue it. + if r.read >= f.ExtentLengthBE { + r.read = 0 + r.sector = 0 + r.queue.Dequeue() + } + + // End of directory listing, drecord is empty so we don't bother + // to return it and keep iterating to look for the next actual + // directory or file. + if drecord.fileID == "" { + return r.Next() + } + + parent := f.Name() + if parent == "\x00" { + parent = "/" + } + drecord.fileID = filepath.Join(parent, drecord.fileID) + + if drecord.IsDir() { + r.queue.Enqueue(drecord) + } else { + drecord.image = r.image + } + + return &drecord, nil +} + +// unpackDRecord unpacks directory record bits into Go's struct +func (r *Reader) unpackDRecord(f *File) (byte, error) { + // Gets the directory record length + var len byte + if err := binary.Read(r.image, binary.BigEndian, &len); err != nil { + return len, ErrCorruptedImage(err) + } + + if len == 0 { + return len + 1, io.EOF + } + + // Reads directory record into Go struct + var drecord DirectoryRecord + if err := binary.Read(r.image, binary.BigEndian, &drecord); err != nil { + return len, ErrCorruptedImage(err) + } + + f.DirectoryRecord = drecord + // Gets the name + name := make([]byte, drecord.FileIDLength) + if err := binary.Read(r.image, binary.BigEndian, name); err != nil { + return len, ErrCorruptedImage(err) + } + f.fileID = string(name) + + // Padding field as per section 9.1.12 in ECMA-119 + if (drecord.FileIDLength % 2) == 0 { + var zero byte + if err := binary.Read(r.image, binary.BigEndian, &zero); err != nil { + return len, ErrCorruptedImage(err) + } + } + + // System use field as per section 9.1.13 in ECMA-119 + // Directory record has 34 bytes in addition to the name's + // variable length and the padding field mentioned in section 9.1.12 + totalLen := 34 + drecord.FileIDLength - (drecord.FileIDLength % 2) + sysUseLen := int64(len - totalLen) + if sysUseLen > 0 { + sysData := make([]byte, sysUseLen) + if err := binary.Read(r.image, binary.BigEndian, sysData); err != nil { + return len, ErrCorruptedImage(err) + } + } + return len, nil +} + +// unpackPVD unpacks Primary Volume Descriptor in three phases. This is +// because the root directory record is a variable-length record and Go's binary +// package doesn't support unpacking variable-length structs easily. +func (r *Reader) unpackPVD() error { + // Unpack first half + var pvd1 PrimaryVolumePart1 + if err := binary.Read(r.image, binary.BigEndian, &pvd1); err != nil { + return ErrCorruptedImage(err) + } + r.pvd.PrimaryVolumePart1 = pvd1 + + // Unpack root directory record + var drecord File + if _, err := r.unpackDRecord(&drecord); err != nil { + return ErrCorruptedImage(err) + } + r.pvd.DirectoryRecord = drecord.DirectoryRecord + r.queue.Enqueue(drecord) + + // Unpack second half + var pvd2 PrimaryVolumePart2 + if err := binary.Read(r.image, binary.BigEndian, &pvd2); err != nil { + return ErrCorruptedImage(err) + } + r.pvd.PrimaryVolumePart2 = pvd2 + + return nil +} diff --git a/vendor/github.com/hooklift/iso9660/writer.go b/vendor/github.com/hooklift/iso9660/writer.go new file mode 100644 index 00000000..f23a9f7f --- /dev/null +++ b/vendor/github.com/hooklift/iso9660/writer.go @@ -0,0 +1 @@ +package iso9660 |