UNPKG

nufatfs

Version:

A new async-friendly library for accessing FAT16 and FAT32 filesystems

29 lines (28 loc) 1.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createMBRPartitionDriver = exports.getNthPartitionFromMBR = exports.getLEUint32 = void 0; function getLEUint32(data, offset = 0) { return (data[offset + 0] << 0) | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24); } exports.getLEUint32 = getLEUint32; function getNthPartitionFromMBR(mbrSector, n) { return { firstLBA: getLEUint32(mbrSector, 0x01BE + 0x10 * n + 8), sectorCount: getLEUint32(mbrSector, 0x01BE + 0x10 * n + 12), }; } exports.getNthPartitionFromMBR = getNthPartitionFromMBR; async function createMBRPartitionDriver(rootDriver, partition, mbrSector) { mbrSector !== null && mbrSector !== void 0 ? mbrSector : (mbrSector = await rootDriver.readSectors(0, 1)); const info = getNthPartitionFromMBR(mbrSector, partition); return { ...rootDriver, numSectors: info.sectorCount, readSectors: (start, read) => rootDriver.readSectors(start + info.firstLBA, read), writeSectors: rootDriver.writeSectors ? (start, data) => rootDriver.writeSectors(start + info.firstLBA, data) : null, }; } exports.createMBRPartitionDriver = createMBRPartitionDriver;