Created
October 20, 2023 10:14
-
-
Save sg-gs/9c623caac2b70ddecf4841ccf2c905be to your computer and use it in GitHub Desktop.
fuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fuse = require('fuse-bindings'); | |
| const path = require('path'); | |
| const fs = require('fs'); | |
| const mountPath = '/mnt/mi_sistema_de_archivos'; | |
| const fileSystem = { | |
| // Implementa las funciones de sistema de archivos FUSE | |
| readdir: (path, callback) => { | |
| if (path === '/') { | |
| // Listar las carpetas y archivos raíz | |
| callback(0, ['folder1', 'folder2', 'file1.txt', 'file2.txt']); | |
| } else { | |
| callback(fuse.ENOENT); | |
| } | |
| }, | |
| getattr: (path, callback) => { | |
| if (path === '/' || path.startsWith('/folder')) { | |
| // Atributos para carpetas virtuales | |
| callback(0, { | |
| mtime: Date.now(), | |
| atime: Date.now(), | |
| ctime: Date.now(), | |
| size: 4096, // Tamaño fijo para carpetas | |
| mode: 16877, // Permisos de carpeta | |
| }); | |
| } else if (path.startsWith('/file')) { | |
| // Atributos para archivos virtuales | |
| callback(0, { | |
| mtime: Date.now(), | |
| atime: Date.now(), | |
| ctime: Date.now(), | |
| size: 1024, // Tamaño fijo para archivos | |
| mode: 33188, // Permisos de archivo | |
| }); | |
| } else { | |
| callback(fuse.ENOENT); | |
| } | |
| }, | |
| open: (path, flags, callback) => { | |
| if (path.startsWith('/file')) { | |
| callback(0, 42); // Descriptor de archivo arbitrario (puede ser cualquier número) | |
| } else { | |
| callback(fuse.ENOENT); | |
| } | |
| }, | |
| read: (path, fd, buffer, len, offset, callback) => { | |
| if (path === '/file1.txt') { | |
| // Contenido del archivo 1 (puede ser dinámico) | |
| const content = 'Contenido del archivo 1\n'; | |
| buffer.write(content, 0, len, offset); | |
| callback(content.length); | |
| } else if (path === '/file2.txt') { | |
| // Contenido del archivo 2 (puede ser dinámico) | |
| const content = 'Contenido del archivo 2\n'; | |
| buffer.write(content, 0, len, offset); | |
| callback(content.length); | |
| } else { | |
| callback(0); | |
| } | |
| }, | |
| }; | |
| fuse.mount(mountPath, fileSystem, (err) => { | |
| if (err) { | |
| console.error(`Error al montar el sistema de archivos FUSE: ${err}`); | |
| } else { | |
| console.log(`Sistema de archivos FUSE montado en ${mountPath}`); | |
| } | |
| }); | |
| process.on('SIGINT', () => { | |
| fuse.unmount(mountPath, (err) => { | |
| if (err) { | |
| console.error(`Error al desmontar el sistema de archivos FUSE: ${err}`); | |
| } | |
| process.exit(); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment