15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifndef LIBRARIES_NACL_IO_FUSE_H_
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#define LIBRARIES_NACL_IO_FUSE_H_
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "osinttypes.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ostypes.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// These interfaces are copied from the FUSE library.
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// FUSE has two interfaces that can be implemented: low-level and high-level.
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// In nacl_io, we only support the high-level interface.
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// See http://fuse.sourceforge.net/ for more information.
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This struct is typically passed to functions that would normally use return
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// or receive an fd; that is, operations to open/create a node, or operations
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// that act on an already opened node.
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct fuse_file_info {
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This is filled with the flags passed to open()
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int flags;
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Deprecated in FUSE. Use fh instead.
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned long fh_old;
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int writepage;
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int direct_io : 1;
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int keep_cache : 1;
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int flush : 1;
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int nonseekable : 1;
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int padding : 27;
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This value is not used by nacl_io. It can be filled by the developer when
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // open() is called, and reused for subsequent calls on the same node.
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  uint64_t fh;
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  uint64_t lock_owner;
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  uint32_t poll_events;
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// A dummy structure that currently exists only to match the FUSE interface.
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct fuse_conn_info {};
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// A function of this type will be passed to readdir (see below). The developer
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// should call this function once for each directory entry.
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// See the documentation for readdir() below for more information on how to use
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// this function.
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef int (*fuse_fill_dir_t)(void* buf,
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const char* name,
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const struct stat* stbuf,
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               off_t off);
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// This structure defines the interface to create a user filesystem. Pass this
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// to
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// nacl_io_register_fs_type(). (see nacl_io.h)
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Example:
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//     struct fuse_operations g_my_fuse_operations = { ... };
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//     ...
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//     nacl_io_register_fs_type("myfusefs", &g_my_fuse_operations);
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//     ...
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//     mount("", "/fs/fuse", "myfusefs", 0, NULL);
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// It is not necessary to implement every function -- nacl_io will first check
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// if the function pointer is NULL before calling it. If it is NULL and
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// required by the current operation, the call will fail and return ENOSYS in
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// errno.
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Except where specified below, each function should return one of the
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// following values:
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// == 0: operation completed successfully.
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// <  0: operation failed. The error is a negative errno. e.g. -EACCES, -EPERM,
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//       etc. The sign will be flipped when the error is actually set.
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Some functions (e.g. read, write) also return a positive count, which is the
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// number of bytes read/written.
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct fuse_operations {
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Currently unsupported
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int flag_nopath : 1;
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  unsigned int flag_reserved : 31;
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by stat()/fstat(), but only when fuse_operations.fgetattr is NULL.
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Also called by open() to determine if the path is a directory or a regular
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // file.
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int (*getattr)(const char* path, struct stat*);
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*readlink)(const char*, char*, size_t);
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called when O_CREAT is passed to open(), but only if fuse_operations.create
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is non-NULL.
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int (*mknod)(const char* path, mode_t, dev_t);
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by mkdir()
1001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*mkdir)(const char* path, mode_t);
1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by unlink()
1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*unlink)(const char* path);
1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by rmdir()
1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*rmdir)(const char* path);
1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*symlink)(const char*, const char*);
1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by rename()
1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*rename)(const char* path, const char* new_path);
1091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*link)(const char*, const char*);
1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by chmod()/fchmod()
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*chmod)(const char*, mode_t);
1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*chown)(const char*, uid_t, gid_t);
1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by truncate(), as well as open() when O_TRUNC is passed.
1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*truncate)(const char* path, off_t);
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by open()
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int (*open)(const char* path, struct fuse_file_info*);
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by read(). Note that FUSE specifies that all reads will fill the
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // entire requested buffer. If this function returns less than that, the
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // remainder of the buffer is zeroed.
12246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int (*read)(const char* path,
12346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)              char* buf,
12446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)              size_t count,
12546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)              off_t,
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)              struct fuse_file_info*);
1271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by write(). Note that FUSE specifies that a write should always
1281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // return the full count, unless an error occurs.
1291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*write)(const char* path,
1301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               const char* buf,
1311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               size_t count,
1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               off_t,
1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               struct fuse_file_info*);
1341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*statfs)(const char*, struct statvfs*);
1361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*flush)(const char*, struct fuse_file_info*);
1381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called when the last reference to this node is released. This is only
1391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // called for regular files. For directories, fuse_operations.releasedir is
1401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // called instead.
1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*release)(const char* path, struct fuse_file_info*);
1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by fsync(). The datasync paramater is not currently supported.
1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*fsync)(const char* path, int datasync, struct fuse_file_info*);
1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*setxattr)(const char*, const char*, const char*, size_t, int);
1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*getxattr)(const char*, const char*, char*, size_t);
1481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*listxattr)(const char*, char*, size_t);
1501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
1511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*removexattr)(const char*, const char*);
1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by getdents(), which is called by the more standard functions
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // opendir()/readdir().
1541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*opendir)(const char* path, struct fuse_file_info*);
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called by getdents(), which is called by the more standard function
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // readdir().
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // NOTE: it is the responsibility of this function to add the "." and ".."
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // entries.
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This function can be implemented one of two ways:
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 1) Ignore the offset, and always write every entry in a given directory.
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //    In this case, you should always call filler() with an offset of 0. You
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //    can ignore the return value of the filler.
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   int my_readdir(const char* path, void* buf, fuse_fill_dir_t filler,
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //                  off_t offset, struct fuse_file_info*) {
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     ...
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     filler(buf, ".", NULL, 0);
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     filler(buf, "..", NULL, 0);
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     filler(buf, "file1", &file1stat, 0);
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     filler(buf, "file2", &file2stat, 0);
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     return 0;
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   }
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 2) Only write entries starting from offset. Always pass the correct offset
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //    to the filler function. When the filler function returns 1, the buffer
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //    is full so you can exit readdir.
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   int my_readdir(const char* path, void* buf, fuse_fill_dir_t filler,
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //                  off_t offset, struct fuse_file_info*) {
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     ...
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     size_t kNumEntries = 4;
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     const char* my_entries[] = { ".", "..", "file1", "file2" };
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     int entry_index = offset / sizeof(dirent);
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     offset = entry_index * sizeof(dirent);
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     while (entry_index < kNumEntries) {
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //       int result = filler(buf, my_entries[entry_index], NULL, offset);
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //       if (filler == 1) {
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //         // buffer filled, we're done.
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //         return 0;
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //       }
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //       offset += sizeof(dirent);
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //       entry_index++;
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     }
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     // No more entries, we're done.
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //     return 0;
1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   }
2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
20146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int (*readdir)(const char* path,
20246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                 void* buf,
20346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                 fuse_fill_dir_t filldir,
20446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                 off_t,
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 struct fuse_file_info*);
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Called when the last reference to this node is released. This is only
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // called for directories. For regular files, fuse_operations.release is
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // called instead.
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int (*releasedir)(const char* path, struct fuse_file_info*);
2101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int (*fsyncdir)(const char*, int, struct fuse_file_info*);
2121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called when a filesystem of this type is initialized.
2131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void* (*init)(struct fuse_conn_info* conn);
2141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called when a filesystem of this type is unmounted.
2151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void (*destroy)(void*);
2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by access()
2171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*access)(const char* path, int mode);
2181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called when O_CREAT is passed to open()
2191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*create)(const char* path, mode_t mode, struct fuse_file_info*);
2201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by ftruncate()
2211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*ftruncate)(const char* path, off_t, struct fuse_file_info*);
2221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by stat()/fstat(). If this function pointer is non-NULL, it is
2231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // called, otherwise fuse_operations.getattr will be called.
2241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*fgetattr)(const char* path, struct stat*, struct fuse_file_info*);
2251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
2261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*lock)(const char*, struct fuse_file_info*, int cmd, struct flock*);
2271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called by utime()/utimes()/futimes()/futimens() etc.
2281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*utimens)(const char*, const struct timespec tv[2]);
2291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
2301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*bmap)(const char*, size_t blocksize, uint64_t* idx);
2311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
23246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int (*ioctl)(const char*,
23346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)               int cmd,
23446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)               void* arg,
23546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)               struct fuse_file_info*,
23646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)               unsigned int flags,
23746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)               void* data);
2381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
23946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int (*poll)(const char*,
24046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)              struct fuse_file_info*,
24146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)              struct fuse_pollhandle* ph,
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)              unsigned* reventsp);
2431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
2441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*write_buf)(const char*,
2451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                   struct fuse_bufvec* buf,
2461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                   off_t off,
2471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                   struct fuse_file_info*);
2481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
24946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int (*read_buf)(const char*,
25046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                  struct fuse_bufvec** bufp,
25146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                  size_t size,
25246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                  off_t off,
25346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                  struct fuse_file_info*);
2541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
2551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*flock)(const char*, struct fuse_file_info*, int op);
2561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Not called currently.
2571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int (*fallocate)(const char*, int, off_t, off_t, struct fuse_file_info*);
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif  // LIBRARIES_NACL_IO_FUSE_H_
261