comments: containers IsoBmff Mux / Meta, Iso9660
This commit is contained in:
1 parent
3cda652143
commit
24cbddaafa
3 files changed
+8
-44
No files matched your search
@@ -1,18 +1,8 @@
|
||||
--!strict
|
||||
-- containers/Iso9660: ISO 9660 (ECMA-119) CD / DVD images, read. The volume descriptors from sector 16 (primary,
|
||||
-- supplementary, boot record, terminator); the directory tree walked through directory records (records never cross
|
||||
-- a sector; multi-extent files are joined; associated files skipped; interleaved files listed, their read is
|
||||
-- Err.UNSUPPORTED). Three name sets: plain ISO 9660 (";1" versions and a lone trailing "." dropped), Joliet (UCS-2 names
|
||||
-- of a supplementary descriptor with the %/@, %/C or %/E escape) and Rock Ridge (SUSP 1.12 / RRIP 1.12 in the
|
||||
-- primary tree: SP, CE continuation areas, NM names, PX modes / links / ids, PN devices, TF times, SL symlinks, CL / RE
|
||||
-- / PL relocated deep directories, with the rr_moved directory hidden when it ends up empty). The tree used is Rock
|
||||
-- Ridge when present, else Joliet, else plain (opts.prefer overrides). El Torito: the boot record's catalog
|
||||
-- (validation entry, initial / default entry) in info.boot. Written from ECMA-119, the SUSP / RRIP 1.12 and Joliet
|
||||
-- specifications and El Torito 1.0; no code ported. Not supported: zisofs (ZF) compressed files (listed; read returns
|
||||
-- the stored bytes), UDF, writing.
|
||||
--
|
||||
-- local entries, info = Iso9660.read(buf, offset?, length?, opts?) -- { Entry }, Info | nil, Err
|
||||
-- local data, err = Iso9660.extract(buf, base, entry) -- the entry's bytes (a copy of its extents)
|
||||
-- containers/Iso9660: ISO 9660 (ECMA-119) images, read; from ECMA-119, SUSP / RRIP 1.12, Joliet and El Torito 1.0, no
|
||||
-- code ported. Name sets: Rock Ridge, else Joliet (%/@, %/C, %/E), else plain (";1" and a trailing "." dropped);
|
||||
-- multi-extent files joined, CL / RE / PL relocations resolved, El Torito catalog in info.boot. Not supported: zisofs
|
||||
-- (read returns the stored bytes), interleaved files (Err.UNSUPPORTED), UDF, writing.
|
||||
local Err = require("@rosetta/core/Err")
|
||||
local Types = require("@rosetta/Types")
|
||||
local Text = require("@rosetta/codecs/text/Text")
|
||||
@@ -45,7 +35,6 @@ export type ReadOptions = {
|
||||
local SECTOR = 2048
|
||||
local S_TYPES: { [number]: string } = { [0x8000] = "0", [0x4000] = "5", [0xA000] = "2", [0x2000] = "3", [0x6000] = "4", [0x1000] = "6", [0xC000] = "s" }
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ fields
|
||||
local function u16(b: buffer, o: number): number
|
||||
return buffer.readu16(b, o)
|
||||
end
|
||||
@@ -78,10 +67,8 @@ local function longDate(b: buffer, o: number): number?
|
||||
return Types.Date.toUnix({ kind = "datetime", year = tonumber(y), month = tonumber(mo), day = tonumber(d), hour = tonumber(h), minute = tonumber(mi), second = tonumber(se), offset = off * 15 })
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ SUSP / Rock Ridge
|
||||
type Susp = { [string]: any }
|
||||
|
||||
-- the SUSP entries of a system use area (following CE continuation areas) -> { { sig, at, len } }
|
||||
local function suspEntries(b: buffer, base: number, limit: number, o: number, e: number, bs: number, budget: { number }): { { any } }
|
||||
local out = {}
|
||||
while o + 4 <= e do
|
||||
@@ -116,7 +103,6 @@ local function suspEntries(b: buffer, base: number, limit: number, o: number, e:
|
||||
return out
|
||||
end
|
||||
|
||||
-- Rock Ridge fields of a record: { name, mode, uid, gid, nlink, mtime, link, rdev, child, relocated, zisofs }
|
||||
local function rockRidge(b: buffer, base: number, limit: number, o: number, e: number, bs: number): Susp
|
||||
local rr: Susp = {}
|
||||
local name: { string }? = nil
|
||||
@@ -189,7 +175,6 @@ local function rockRidge(b: buffer, base: number, limit: number, o: number, e: n
|
||||
return rr
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ directories
|
||||
type Record = {
|
||||
name: string,
|
||||
dir: boolean,
|
||||
@@ -202,7 +187,6 @@ type Record = {
|
||||
rr: Susp?,
|
||||
}
|
||||
|
||||
-- the records of a directory extent (without "." and "..") | nil, Err
|
||||
local function records(b: buffer, base: number, limit: number, at: number, size: number, bs: number, joliet: boolean, rrSkip: number?): ({ Record }?, Err.Err?)
|
||||
if at + size > limit then
|
||||
return nil, Err.new(Err.TRUNCATED, "directory past the end", at)
|
||||
@@ -258,7 +242,6 @@ local function records(b: buffer, base: number, limit: number, at: number, size:
|
||||
return out, nil
|
||||
end
|
||||
|
||||
-- the root record of a volume descriptor at vd -> lba, size
|
||||
local function root(b: buffer, vd: number): (number, number)
|
||||
return u32(b, vd + 156 + 2), u32(b, vd + 156 + 10)
|
||||
end
|
||||
@@ -281,7 +264,6 @@ local function rockRidgeSkip(b: buffer, base: number, limit: number, lba: number
|
||||
return nil
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ El Torito
|
||||
local function boot(b: buffer, base: number, limit: number, vd: number, bs: number): { [string]: any }?
|
||||
if str(b, vd + 7, 32) ~= "EL TORITO SPECIFICATION" then
|
||||
return nil
|
||||
@@ -309,8 +291,6 @@ local function boot(b: buffer, base: number, limit: number, vd: number, bs: numb
|
||||
return info
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ read
|
||||
-- read(buf, offset?, length?, opts?) -> { Entry }, Info | nil, Err
|
||||
function Iso9660.read(b: buffer, offset: number?, length: number?, opts: ReadOptions?): ({ Entry }?, any)
|
||||
local base = offset or 0
|
||||
local limit = math.min(buffer.len(b), base + (length or (buffer.len(b) - base)))
|
||||
@@ -498,7 +478,6 @@ function Iso9660.read(b: buffer, offset: number?, length: number?, opts: ReadOpt
|
||||
return out, info
|
||||
end
|
||||
|
||||
-- extract(buf, entry, limit?) -> a copy of the entry's data | nil, Err
|
||||
function Iso9660.extract(b: buffer, e: Entry, limit: number?): (buffer?, Err.Err?)
|
||||
if e.interleaved then
|
||||
return nil, Err.new(Err.UNSUPPORTED, "interleaved file " .. e.name)
|
||||
@@ -516,7 +495,6 @@ function Iso9660.extract(b: buffer, e: Entry, limit: number?): (buffer?, Err.Err
|
||||
return out, nil
|
||||
end
|
||||
|
||||
-- valid(buf, offset?) -> true when a volume descriptor "CD001" sits at sector 16
|
||||
function Iso9660.valid(b: buffer, offset: number?): boolean
|
||||
local p = (offset or 0) + 16 * SECTOR
|
||||
return p + 6 <= buffer.len(b) and buffer.readstring(b, p + 1, 5) == "CD001"
|
||||
|
||||
Reference in new issue
Block a user