Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 103fa21

Browse files
committed
Use int64-buffer for disk sector ops
1 parent 906e5e7 commit 103fa21

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

js/driver/virtio/blk.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,11 @@
1515
'use strict';
1616
const VirtioDevice = require('./device');
1717
const runtime = require('../../core');
18+
const { Uint64LE } = require('int64-buffer');
1819

1920
const VIRTIO_BLK_T_IN = 0;
2021
const VIRTIO_BLK_T_OUT = 1;
2122

22-
function split64(num) {
23-
let str = num.toString(2);
24-
for (let i = 0; i < 64 - str.length; i++) str = '0' + str;
25-
return [parseInt(str.substr(0, 32), 2), parseInt(str.substr(32), 2)];
26-
}
27-
2823
function initializeBlockDevice(pciDevice) {
2924
const ioSpace = pciDevice.getBAR(0).resource;
3025
const irq = pciDevice.getIRQ();
@@ -73,9 +68,7 @@ function initializeBlockDevice(pciDevice) {
7368
const view = new DataView(u8.buffer);
7469
view.setUint32(0, type, true);
7570
view.setUint32(4, 0, true); // priority: low
76-
const split = split64(sector);
77-
view.setUint32(8, split[1], true); // lo
78-
view.setUint32(12, split[0], true); // hi
71+
u8.set((new Uint64LE(sector)).toArray(), 8);
7972
return u8;
8073
}
8174

@@ -84,7 +77,7 @@ function initializeBlockDevice(pciDevice) {
8477
return new Promise((resolve, reject) => {
8578
if (sector > totalSectorCount) {
8679
setImmediate(() => {
87-
reject(new RangeError(`sector out of bounds (max: ${totalSectorCount})`));
80+
reject(new RangeError(`sector ${sector} out of bounds (max ${totalSectorCount}, non-inclusive)`));
8881
});
8982
return;
9083
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"constants-browserify": "^1.0.0",
3939
"event-controller": "^1.0.1",
4040
"events": "^1.1.0",
41+
"int64-buffer": "^0.1.9",
4142
"isint": "^1.0.0",
4243
"module-singleton": "^2.0.0",
4344
"path-browserify": "0.0.0",

0 commit comments

Comments
 (0)