import assert from 'node:assert/strict'; import {createHash} from 'node:crypto'; import {readFileSync, writeFileSync} from 'node:fs'; import {join} from 'node:path'; const root = process.cwd(); const directory = join(root, 'userspace/tests/fixtures'); const source = readFileSync(join(directory, 'core-tools.raw')); const disk = Buffer.from(source); const block = 512; assert.equal(disk.length, 2048 * block); assert.equal(disk.readUInt32LE(16 * block + 32), 5); for (const [lba, slot] of [[17, 5], [18, 5], [18, 6], [18, 7], [25, 0], [25, 1]]) { const at = lba * block + slot * 32; assert.ok(disk.subarray(at, at + 32).every(byte => byte === 0), `unused fixture slot ${lba}:${slot}`); } const entry = (at, id, name) => { disk[at] = 1; disk[at + 1] = name.length; disk.writeUInt32LE(id, at + 4); disk.write(name, at + 8, 'ascii'); }; disk.writeUInt32LE(6, 16 * block + 32); entry(17 * block + 5 * 32, 6, 'SUB'); const sub = 18 * block + 5 * 32; disk.writeUInt32LE(6, sub); disk.writeUInt32LE(2, sub + 4); disk.writeBigUInt64LE(512n, sub + 8); disk.writeBigUInt64LE(25n, sub + 16); disk.writeUInt32LE(2, sub + 24); entry(25 * block, 7, 'INNER'); entry(25 * block + 32, 8, 'HIDDEN'); disk.writeUInt32LE(7, 18 * block + 6 * 32); disk.writeUInt32LE(8, 18 * block + 7 * 32); const sha256 = bytes => createHash('sha256').update(bytes).digest('hex'); const image = join(directory, 'core-tools-ls.raw'); const manifest = join(directory, 'core-tools-ls.json'); writeFileSync(image, disk); writeFileSync(manifest, JSON.stringify({ schema: 'turkos-k1295-ls-fixture/v1', image: 'core-tools-ls.raw', bytes: disk.length, sha256: sha256(disk), parent: {image: 'core-tools.raw', sha256: sha256(source)}, directories: [ {path: '/', entries: ['README', 'KERNEL', 'MULTI', 'TAIL', 'ONE', 'SUB']}, {path: '/SUB', entries: ['INNER', 'HIDDEN']}, ], visibility: {hidden: ['HIDDEN'], deniedPaths: ['/SUB']}, }, null, 2) + '\n'); console.log(JSON.stringify({image, manifest, sha256: sha256(disk)}));