Files
Linux.js---javascript-OS/rootfs overrides/core/mount.js
T
Marc 721c919c7b ChibraxOS 2
Changes:
- kernel 6.0.2
- Broken init scripts
- Switch to bun for better peroformance an easier ffi
- Removed grup
- Efi support without graphics (at least graphics werent tested)
- Suppression de toutes les dépendance non libc
- new splash
- broken audio
- typescript support
- ls rewritten to be more reliable
2022-10-22 13:47:33 +02:00

68 lines
2.3 KiB
JavaScript

//@ts-check
import * as fs from 'fs'
import { dlopen, FFIType } from 'bun:ffi'
import { filesystems } from './suportedFilesystems'
/* These are the fs-independent mount-flags: up to 16 flags are
supported */
export const flags = {
MS_RDONLY: 1, /* Mount read-only. */
MS_NOSUID: 2, /* Ignore suid and sgid bits. */
MS_NODEV: 4, /* Disallow access to device special files. */
MS_NOEXEC: 8, /* Disallow program execution. */
MS_SYNCHRONOUS: 16, /* Writes are synced at once. */
MS_REMOUNT: 32, /* Alter flags of a mounted FS. */
MS_MANDLOCK: 64, /* Allow mandatory locks on an FS. */
MS_DIRSYNC: 128, /* Directory modifications are synchronous. */
MS_NOATIME: 1024, /* Do not update access times. */
MS_NODIRATIME: 2048, /* Do not update directory access times. */
MS_BIND: 4096, /* Bind directory at different place. */
MS_MOVE: 8192,
MS_REC: 16384,
MS_SILENT: 32768,
MS_POSIXACL: 1 << 16, /* VFS does not apply the umask. */
MS_UNBINDABLE: 1 << 17, /* Change to unbindable. */
MS_PRIVATE: 1 << 18, /* Change to private. */
MS_SLAVE: 1 << 19, /* Change to slave. */
MS_SHARED: 1 << 20, /* Change to shared. */
MS_RELATIME: 1 << 21, /* Update atime relative to mtime/ctime. */
MS_KERNMOUNT: 1 << 22, /* This is a kern_mount call. */
MS_I_VERSION: 1 << 23, /* Update inode I_version field. */
MS_STRICTATIME: 1 << 24, /* Always perform atime updates. */
MS_LAZYTIME: 1 << 25, /* Update the on-disk [acm]times lazily. */
MS_ACTIVE: 1 << 30,
MS_NOUSER: 1 << 31
};
const {
symbols: {
mount,
},
} = dlopen('/usr/lib/libc.so.6', {
mount: {
args: [ FFIType.cstring, FFIType.cstring, FFIType.cstring, FFIType.u64, FFIType.cstring ],
returns: FFIType.int,
},
});
/**
* @param {string} devicePath
* @param {string} mountPoint
* @param {string} fstype
* @param {number} flags
* @param {string} fsparams
* @returns {number}
*/
export function JSmount(devicePath, mountPoint, fstype, flags, fsparams) {
const filesystem = filesystems.find( v => v.name === fstype)
if(! filesystem) {
throw "Invalid filesystem"
}
if(! fs.existsSync(devicePath) && filesystem.hasdev)
throw "Device don't exist"
return mount(Buffer.from(devicePath), Buffer.from(mountPoint), Buffer.from(fstype), flags, Buffer.from(fsparams))
}