-
Notifications
You must be signed in to change notification settings - Fork 72
/
fuse.js
650 lines (601 loc) · 22.4 KB
/
fuse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var bindings = require('./build/Release/fusejs.node');
var warn_not_implemented = false;
var FileSystem = function() {
};
(function() {
/**
* Initialize filesystem.
* Called before any other filesystem method.
*
* param {Object} connInfo Fuse connection information.
*
* There's no reply to this function.
**/
this.init = function(connInfo) {
if(warn_not_implemented){
console.log("init not implemented");
}
};
/**
* Clean up filesystem.
* Called on filesystem exit.
*
* There's no reply to this function.
**/
this.destroy = function() {
if(warn_not_implemented){
console.log("destroy not implemented");
}
};
/**
* Look up a directory entry by name and get its attributes.
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the parent directory.
* @param {String} name the name to look up.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.entry() or reply.err().
**/
this.lookup = function(context, parent, name, reply) {
if(warn_not_implemented){
console.log("lookup not implemented");
}
reply.err(38);
};
/**
* Forget about an inode
* The nlookup parameter indicates the number of
* lookups previously performed on this inode.
*
* If the filesystem implements inode lifetimes,
* it is recommended that inodes acquire a single
* reference on each lookup, and lose nlookup references
* on each forget.
*
* The filesystem may ignore forget calls, if the inodes
* don't need to have a limited lifetime.
*
* On unmount it is not guaranteed, that all referenced
* inodes will receive a forget message.
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode Inode number.
* @param {Number} nlookup The number of lookups to forget.
*
**/
this.forget = function(context, inode, nlookup,reply) {
if(warn_not_implemented){
console.log("forget not implemented");
}
reply.none();
};
/**
*
* like forget, except batched.
* here forget_data is an object with 2 fields: inode and nlookup
*
**/
this.multiforget = function(context, forget_data, reply){
if(warn_not_implemented){
console.log("forget not implemented");
}
reply.none();
}
/**
* Get file attributes
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode Inode number.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.attr() or reply.err()
**/
this.getattr = function(context, inode, reply) {
if(warn_not_implemented){
console.log("getattr not implemented");
}
reply.err(38);
};
/**
* Set file attributes
*
* In the 'attr' argument only members
* indicated by the 'toSet' bitmask contain
* valid values. Other members contain undefined values.
*
* If the setattr was invoked from the ftruncate() system call
* under Linux kernel versions 2.6.15 or later,
* the fi->fh will contain the value set by the open
* method or will be undefined if the open method
* didn't set any value. Otherwise (not ftruncate
* call, or kernel version earlier than 2.6.15)
* the fi parameter will be NULL.
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode Inode Number.
* @param {Object} attrs Attributes to be set.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.attr() or reply.err();
**/
this.setattr = function(context, inode, attrs, reply) {
if(warn_not_implemented){
console.log("setattr not implemented");
}
reply.err(38);
};
/**
* Read symbolic link
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode Inode number.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.readlink() or reply.err()
**/
this.readlink = function(context, inode, reply) {
if(warn_not_implemented){
console.log("readlink not implemented");
}
reply.err(38);
};
/**
* Create file node
* Create a regular file, character device,
* block device, fifo or socket node.
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the parent directory.
* @param {String} name Name to be created.
* @param {Number} mode File type and mode with which
* to create the new file.
* @param {Number} rdev The device number
* (only valid if created file is a device).
* @param {Object} reply Reply instance.
*
* Valid replies: reply.entry() or reply.err()
**/
this.mknod = function(context, parent, name, mode, rdev, reply) {
if(warn_not_implemented){
console.log("mknod not implemented");
}
reply.err(38);
};
/**
* Create a directory
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the parent directory.
* @param {String} name Name to be created.
* @param {Number} mode with which to create the new file.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.entry() or reply.err()
**/
this.mkdir = function(context, parent, name, mode, reply) {
if(warn_not_implemented){
console.log("mkdir not implemented");
}
reply.err(38);
};
/**
* Remove a file
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the parent directory.
* @param {String} name Name of the file to remove.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.err()
**/
this.unlink = function(context, parent, name, reply) {
if(warn_not_implemented){
console.log("unlink not implemented");
}
reply.err(38);
};
/**
* Remove a directory
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the parent directory.
* @param {String} name Name of the directory to remove.
*
* Valid replies: reply.err()
**/
this.rmdir = function(context, parent, name, reply) {
if(warn_not_implemented){
console.log("rmdir not implemented");
}
reply.err(38);
};
/**
* Create a symbolic link
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the parent directory.
* @param {String} link The contents of the symbolic link.
* @param {String} name Name of the symbolic link to create.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.entry() or reply.err()
**/
this.symlink = function(context, parent, link, name, reply) {
if(warn_not_implemented){
console.log("symlink not implemented");
}
reply.err(38);
};
/**
* Rename a file
*
* @param {Object} context Context info of the calling process.
* @param {Number} parent Inode number of the old parent directory.
* @param {String} name Old name.
* @param {Number} newParent Inode number of the new parent directory.
* @param {String} newName New name.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.err()
**/
this.rename = function(context, parent, name, newParent, newName, reply) {
if(warn_not_implemented){
console.log("rename not implemented");
}
reply.err(38);
};
/**
* Create a hard link
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode The old inode number.
* @param {Number} newparent Inode number of the new parent directory.
* @param {String} newname New name to create.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.entry() or reply.err()
**/
this.link = function(context, inode, newParent, newName, reply) {
if(warn_not_implemented){
console.log("link not implemented");
}
reply.err(38);
};
/**
* Open a file
*
* Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and O_TRUNC)
* are available in fileInfo.flags.
*
* Filesystem may store an arbitrary file handle (pointer, index, etc)
* in fileInfo.fh, and use this in other all other file operations
* (read, write, flush, release, fsync).
*
* Filesystem may also implement stateless file I/O and not store
* anything in fileInfo.fh.
*
* There are also some flags (direct_io, keep_cache) which the
* filesystem may set in fileInfo, to change the way the file is
* opened. See fuse_file_info structure in <fuse_common.h> for more details.
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode The inode number.
* @param {Object} fileInfo File information.
* @param {Object} reply Reply instance.
*
* Valid replies: reply.open() or reply.err()
**/
this.open = function(context, inode, fileInfo, reply) {
if(warn_not_implemented){
console.log("open not implemented");
}
reply.err(38);
};
/**
* Read data
*
* Read should send exactly the number of bytes requested
* except on EOF or error, otherwise the rest of the
* data will be substituted with zeroes. An exception to
* this is when the file has been opened in 'direct_io' mode,
* in which case the return value of the read system call
* will reflect the return value of this operation.
* fileInfo->fh will contain the value set by the open method,
* or will be undefined if the open method didn't set any value.
*
* @param {Object} context Context info of the calling process.
* @param {Number} inode The inode number.
* @param {}
* @param {}
* @param {}
*
* Valid replies: reply.buffer() or fuse.err()
**/
this.read = function(context, inode, len, offset, fileInfo, reply) {
if(warn_not_implemented){
console.log("read not implemented");
}
reply.err(38);
};
this.write = function() {
if(warn_not_implemented){
console.log("write not implemented");
}
reply.err(38);
};
this.flush = function(context, inode, fileInfo, reply) {
if(warn_not_implemented){
console.log("flush not implemented");
}
reply.err(0);
};
this.release = function(context, inode, fileInfo, reply) {
if(warn_not_implemented){
console.log("release not implemented");
}
reply.err(38);
};
this.fsync = function() {
if(warn_not_implemented){
console.log("fsync not implemented");
}
reply.err(38);
};
this.opendir = function(context, inode, fileInfo, reply) {
if(warn_not_implemented){
console.log("opendir not implemented");
}
reply.err(38);
};
this.readdir = function() {
if(warn_not_implemented){
console.log("readdir not implemented");
}
reply.err(38);
};
this.releasedir = function() {
if(warn_not_implemented){
console.log("releasedir not implemented");
}
reply.err(38);
};
this.fsyncdir = function(context, inode,datasync, fileInfo, reply) {
if(warn_not_implemented){
console.log("fsyncdir not implemented");
}
reply.err(38);
};
this.statfs = function(context, inode, reply) {
if(warn_not_implemented){
console.log("statfs not implemented");
}
reply.statfs( {
bsize: 65536,
iosize: 65536,
frsize: 65536,
blocks: 1000000,
bfree: 1000000,
bavail: 1000000,
files: 1000000,
ffree: 1000000,
favail: 1000000,
fsid: 1000000,
flag: 0
});
};
this.setxattr = function() {
if(warn_not_implemented){
console.log("setxattr not implemented");
}
reply.err(38);
};
this.getxattr = function(context, parentInode, name, size, position, reply) {
if(warn_not_implemented){
console.log("getxattr not implemented");
}
reply.err(38);
};
this.listxattr = function() {
if(warn_not_implemented){
console.log("listxattr not implemented");
}
reply.err(38);
};
this.removexattr = function() {
if(warn_not_implemented){
console.log("removexattr not implemented");
}
reply.err(38);
};
this.access = function(context, inode, mask, reply) {
if(warn_not_implemented){
console.log("access not implemented");
}
reply.err(0);
};
this.create = function() {
if(warn_not_implemented){
console.log("create not implemented");
}
reply.err(38);
};
this.getlk = function() {
if(warn_not_implemented){
console.log("getlk not implemented");
}
reply.err(38);
};
this.setlk = function() {
if(warn_not_implemented){
console.log("setlk not implemented");
}
reply.err(38);
};
this.bmap = function() {
if(warn_not_implemented){
console.log("bmap not implemented");
}
reply.err(38);
};
this.ioctl = function() {
if(warn_not_implemented){
console.log("ioctl not implemented");
}
reply.err(38);
};
this.poll = function() {
if(warn_not_implemented){
console.log("poll not implemented");
}
reply.err(38);
};
}).call(FileSystem.prototype);
var PosixError = {
//https://github.com/torvalds/linux/blob/master/include/asm-generic/errno-base.h
EPERM : 1,/* Operation not permitted */
ENOENT : 2,/* No such file or directory */
ESRCH : 3,/* No such process */
EINTR : 4,/* Interrupted system call */
EIO : 5,/* I/O error */
ENXIO : 6,/* No such device or address */
E2BIG : 7,/* Argument list too long */
ENOEXEC : 8,/* Exec format error */
EBADF : 9,/* Bad file number */
ECHILD : 10,/* No child processes */
EAGAIN : 11,/* Try again */
ENOMEM : 12,/* Out of memory */
EACCES : 13,/* Permission denied */
EFAULT : 14,/* Bad address */
ENOTBLK : 15,/* Block device required */
EBUSY : 16,/* Device or resource busy */
EEXIST : 17,/* File exists */
EXDEV : 18,/* Cross-device link */
ENODEV : 19,/* No such device */
ENOTDIR : 20,/* Not a directory */
EISDIR : 21,/* Is a directory */
EINVAL : 22,/* Invalid argument */
ENFILE : 23,/* File table overflow */
EMFILE : 24,/* Too many open files */
ENOTTY : 25,/* Not a typewriter */
ETXTBSY : 26,/* Text file busy */
EFBIG : 27,/* File too large */
ENOSPC : 28,/* No space left on device */
ESPIPE : 29,/* Illegal seek */
EROFS : 30,/* Read-only file system */
EMLINK : 31,/* Too many links */
EPIPE : 32,/* Broken pipe */
EDOM : 33,/* Math argument out of domain of func */
ERANGE : 34,/* Math result not representable */
//https://github.com/torvalds/linux/blob/master/include/asm-generic/errno.h
EDEADLK : 35,/* Resource deadlock would occur */
ENAMETOOLONG : 36,/* File name too long */
ENOLCK : 37,/* No record locks available */
ENOSYS : 38,/* Function not implemented */
ENOTEMPTY : 39,/* Directory not empty */
ELOOP : 40,/* Too many symbolic links encountered */
EWOULDBLOCK : 11,/* Operation would block */
ENOMSG : 42,/* No message of desired type */
EIDRM : 43,/* Identifier removed */
ECHRNG : 44,/* Channel number out of range */
EL2NSYNC : 45,/* Level 2 not synchronized */
EL3HLT : 46,/* Level 3 halted */
EL3RST : 47,/* Level 3 reset */
ELNRNG : 48,/* Link number out of range */
EUNATCH : 49,/* Protocol driver not attached */
ENOCSI : 50,/* No CSI structure available */
EL2HLT : 51,/* Level 2 halted */
EBADE : 52,/* Invalid exchange */
EBADR : 53,/* Invalid request descriptor */
EXFULL : 54,/* Exchange full */
ENOANO : 55,/* No anode */
EBADRQC : 56,/* Invalid request code */
EBADSLT : 57,/* Invalid slot */
EDEADLOCK : 35,
EBFONT : 59,/* Bad font file format */
ENOSTR : 60,/* Device not a stream */
ENODATA : 61,/* No data available */
ETIME : 62,/* Timer expired */
ENOSR : 63,/* Out of streams resources */
ENONET : 64,/* Machine is not on the network */
ENOPKG : 65,/* Package not installed */
EREMOTE : 66,/* Object is remote */
ENOLINK : 67,/* Link has been severed */
EADV : 68,/* Advertise error */
ESRMNT : 69,/* Srmount error */
ECOMM : 70,/* Communication error on send */
EPROTO : 71,/* Protocol error */
EMULTIHOP : 72,/* Multihop attempted */
EDOTDOT : 73,/* RFS specific error */
EBADMSG : 74,/* Not a data message */
EOVERFLOW : 75,/* Value too large for defined data type */
ENOTUNIQ : 76,/* Name not unique on network */
EBADFD : 77,/* File descriptor in bad state */
EREMCHG : 78,/* Remote address changed */
ELIBACC : 79,/* Can not access a needed shared library */
ELIBBAD : 80,/* Accessing a corrupted shared library */
ELIBSCN : 81,/* .lib section in a.out corrupted */
ELIBMAX : 82,/* Attempting to link in too many shared libraries */
ELIBEXEC : 83,/* Cannot exec a shared library directly */
EILSEQ : 84,/* Illegal byte sequence */
ERESTART : 85,/* Interrupted system call should be restarted */
ESTRPIPE : 86,/* Streams pipe error */
EUSERS : 87,/* Too many users */
ENOTSOCK : 88,/* Socket operation on non-socket */
EDESTADDRREQ : 89,/* Destination address required */
EMSGSIZE : 90,/* Message too long */
EPROTOTYPE : 91,/* Protocol wrong type for socket */
ENOPROTOOPT : 92,/* Protocol not available */
EPROTONOSUPPORT : 93,/* Protocol not supported */
ESOCKTNOSUPPORT : 94,/* Socket type not supported */
EOPNOTSUPP : 95,/* Operation not supported on transport endpoint */
EPFNOSUPPORT : 96,/* Protocol family not supported */
EAFNOSUPPORT : 97,/* Address family not supported by protocol */
EADDRINUSE : 98,/* Address already in use */
EADDRNOTAVAIL : 99,/* Cannot assign requested address */
ENETDOWN : 100,/* Network is down */
ENETUNREACH : 101,/* Network is unreachable */
ENETRESET : 102,/* Network dropped connection because of reset */
ECONNABORTED : 103,/* Software caused connection abort */
ECONNRESET : 104,/* Connection reset by peer */
ENOBUFS : 105,/* No buffer space available */
EISCONN : 106,/* Transport endpoint is already connected */
ENOTCONN : 107,/* Transport endpoint is not connected */
ESHUTDOWN : 108,/* Cannot send after transport endpoint shutdown */
ETOOMANYREFS : 109,/* Too many references: cannot splice */
ETIMEDOUT : 110,/* Connection timed out */
ECONNREFUSED : 111,/* Connection refused */
EHOSTDOWN : 112,/* Host is down */
EHOSTUNREACH : 113,/* No route to host */
EALREADY : 114,/* Operation already in progress */
EINPROGRESS : 115,/* Operation now in progress */
ESTALE : 116,/* Stale NFS file handle */
EUCLEAN : 117,/* Structure needs cleaning */
ENOTNAM : 118,/* Not a XENIX named type file */
ENAVAIL : 119,/* No XENIX semaphores available */
EISNAM : 120,/* Is a named type file */
EREMOTEIO : 121,/* Remote I/O error */
EDQUOT : 122,/* Quota exceeded */
ENOMEDIUM : 123,/* No medium found */
EMEDIUMTYPE : 124,/* Wrong medium type */
ECANCELED : 125,/* Operation Canceled */
ENOKEY : 126,/* Required key not available */
EKEYEXPIRED : 127,/* Key has expired */
EKEYREVOKED : 128,/* Key has been revoked */
EKEYREJECTED : 129,/* Key was rejected by service */
/* for robust mutexes */
EOWNERDEAD : 130,/* Owner died */
ENOTRECOVERABLE : 131,/* State not recoverable */
ERFKILL : 132,/* Operation not possible due to RF-kill */
EHWPOISON : 133/* Memory page has hardware error */
};
var fuse = new bindings.Fuse();
fuse.fuse_version = bindings.fuse_version;
module.exports = {
fuse: fuse,
FileSystem: FileSystem,
PosixError: PosixError
};