Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor device drivers #464

Open
niklauslee opened this issue Dec 19, 2021 · 0 comments
Open

Refactor device drivers #464

niklauslee opened this issue Dec 19, 2021 · 0 comments

Comments

@niklauslee
Copy link
Member

niklauslee commented Dec 19, 2021

Registering device drivers

// character devices
global.__chrdev['stdin'] = ... (object)
global.__chrdev['stdout'] = ... (object)

// block devices
global.__blkdev['fs'] = ... (object)
global.__blkdev['storage'] = ... (object)

// network devices
global.__netdev['eth0'] = ... (object)

Character Device Driver and Stream

Character device driver should implement Stream interface.

interface Stream extends EventListener {
  readableFlowing: boolean; // flowing mode when 'data' event attached?
  readableEnded: boolean;
  readable(): boolean; // true if readable stream
  read(length: number): Uint8Array|null; // returns null when no data to read
  // event 'data'
  // event 'end'
  writableEnded: boolean; // end() called
  writableFinished: boolean; // end() called and all data flushed
  writable(): boolean; // true if writable stream
  write(data: Uint8Array): boolean; // returns true when need 'drain' event
  end();
  // event 'drain'
  // event 'finish'
  destroy();
}

Process object

Solution for #461

process.stdin // returns global.__chrdev['stdin'];
process.stdout // returns global.__chrdev['stdout'];
process.stderr // returns global.__chrdev['stderr'];

File system

Need support configurations instead of calling method?
Event we support configs, we still need functions like mount(), register(), etc.

// file systems
global.__fs['lfs'] = ... (constructor)
global.__fs['fat'] = ... (constructor)

// mounts
global.__mount['/'] = {blkdev: 'fs', fs: 'lfs', mkfs: true}
// if no mounts, we don't need fs commands in REPL (e.g. .ls, .cd, .pwd, ...)

Do we need to support even this?

fs.readSync(fd, ...); // if fd = 0, read from global.__chrdev['stdin']
fs.writeSync(fd, ...); // if fd = 1, write to global.__chrdev['stdout']
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant