# iso fixtures (tools/fixtures.py): ISO 9660 images of one tree built by xorriso (nixpkgs#xorriso: plain and Joliet # with -rockridge off, then the mkisofs emulation -R, -J -R, an El Torito no-emulation boot image) and genisoimage (nixpkgs#cdrkit, -J -R: deep directories # relocated to rr_moved, long names and symlink targets in CE continuation areas), plus a multi-extent file and an # interleaved file crafted here by splitting / editing a directory record. Expected listings: the source tree (os.lstat) # for Rock Ridge images, pycdlib (a second reader, run through nix python) for the plain and Joliet name sets. # tests/gen/iso.luau { images = { { name, data (or same = the index of the image with the same data), tree, entries = { { name, dir, size?, crc?, mode?, link?, mtime? } } } }, # boot = { data, lba, sectors, catalog }, multi = { data, name, size, crc }, interleaved = data } import json, os, shutil, stat, struct, subprocess, tempfile, zlib MTIME = 1650000000 DUMP = r""" import json, sys, io, zlib, pycdlib path, kind = sys.argv[1], sys.argv[2] iso = pycdlib.PyCdlib() iso.open(path) out = [] key = {"joliet": "joliet_path", "iso9660": "iso_path"}[kind] for d, dirs, files in iso.walk(**{key: "/"}): base = d.rstrip("/") for n in dirs: out.append({"name": (base + "/" + n).lstrip("/"), "dir": True}) for n in files: p = base + "/" + n b = io.BytesIO() iso.get_file_from_iso_fp(b, **{key: p}) name = p.lstrip("/") if ";" in name: name = name[:name.rindex(";")] if kind == "iso9660" and name.endswith("."): name = name[:-1] out.append({"name": name, "dir": False, "size": len(b.getvalue()), "crc": zlib.crc32(b.getvalue())}) iso.close() sys.stdout.write(json.dumps(out)) """ def sh(pkg, argv, cwd): return subprocess.run(["nix", "shell", "nixpkgs#" + pkg, "-c"] + argv, cwd=cwd, capture_output=True, check=True).stdout def tree_entries(root, skip_deep=False): out = [] for dirpath, dirs, files in os.walk(root): dirs.sort() for n in sorted(dirs + files): p = os.path.join(dirpath, n) rel = os.path.relpath(p, root) st = os.lstat(p) e = {"name": rel, "dir": stat.S_ISDIR(st.st_mode), "mode": stat.S_IMODE(st.st_mode), "mtime": MTIME} if stat.S_ISLNK(st.st_mode): e["link"] = os.readlink(p) elif stat.S_ISREG(st.st_mode): with open(p, "rb") as f: d = f.read() e["size"], e["crc"] = len(d), zlib.crc32(d) out.append(e) return out def split_record(data, name, at_bytes): """a multi-extent copy: the directory record of name split into two records (the first flagged 0x80)""" img = bytearray(data) root_lba = struct.unpack_from("I", a, 14, at_bytes) a[25] |= 0x80 struct.pack_into("I", b2, 6, lba + at_bytes // 2048) struct.pack_into("I", b2, 14, size - at_bytes) sector_end = (p // 2048 + 1) * 2048 used = sector_end q = p + ln while q < sector_end and img[q] != 0: q += img[q] assert q + ln <= sector_end, "no room in the directory sector" img[p:q + ln] = a + b2 + img[p + ln:q] return bytes(img), size p += ln raise Exception("record not found") def set_interleave(data, name): img = bytearray(data) root_lba = struct.unpack_from("