STRUCT EXPORT_OPERATIONS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

okay so bestie πŸ’– welcome to the struct export_operations(9) page from the Kernel API Manual β€” manual name folded in near the top like a lil ribbon πŸŽ€. this struct is the main character for nfsd talking to filesystems, and we are gonna go through every single member, flag, and caveat. no cap.

🌸 NAME 🌸

struct export_operations β€” for nfsd to communicate with file systems. that's the whole point, periodt πŸ’….

✨ SYNOPSIS ✨

here's the struct layout, bestie β€” every signature and macro is below 🫢:

struct export_operations {
    int (*encode_fh)(struct inode *inode, __u32 *fh, int *max_len,
                     struct inode *parent);
    struct dentry * (*fh_to_dentry)(struct super_block *sb, struct fid *fid,
                                    int fh_len, int fh_type);
    struct dentry * (*fh_to_parent)(struct super_block *sb, struct fid *fid,
                                    int fh_len, int fh_type);
    int (*get_name)(struct dentry *parent, char *name,
                    struct dentry *child);
    struct dentry * (*get_parent)(struct dentry *child);
    int (*commit_metadata)(struct inode *inode);
    int (*permission)(struct handle_to_path_ctx *ctx, unsigned int oflags);
    struct file * (*open)(const struct path *path, unsigned int oflags);
    #define EXPORT_OP_NOWCC                 (0x1) ;
    #define EXPORT_OP_NOSUBTREECHK          (0x2) ;
    #define EXPORT_OP_CLOSE_BEFORE_UNLINK   (0x4) ;
    #define EXPORT_OP_REMOTE_FS             (0x8) ;
    #define EXPORT_OP_NOATOMIC_ATTR         (0x10)  #define EXPORT_OP_FLUSH_ON_CLOSE        (0x20) ;
    #define EXPORT_OP_NOLOCKS               (0x40) ;
    unsigned long   flags;
    #ifdef CONFIG_EXPORTFS_BLOCK_OPS;
    const struct exportfs_block_ops *block_ops;
    #endif;
};

🧚 Members 🧚

  • encode_fh β€” encode_fh should store in the file handle fragment fh (using at most max_len bytes) information that can be used by decode_fh to recover the file referred to by the struct dentry de. If flag has the CONNECTABLE bit set, encode_fh should store sufficient information so that a good attempt can be made to find not only the file but also its place in the filesystem. This typically means storing a reference to de->d_parent in the filehandle fragment. encode_fh should return the fileid_type on success and on error returns 255 (if the space needed to encode fh is greater than max_len*4 bytes). On error max_len contains the minimum size (in 4 byte unit) needed to encode the file handle.
  • fh_to_dentry β€” fh_to_dentry is given a struct super_block (sb) and a file handle fragment (fh, fh_len). It should return a struct dentry which refers to the same file that the file handle fragment refers to. If it cannot, it should return a NULL pointer if the file cannot be found, or an ERR_PTR error code of ENOMEM if a memory allocation failure occurred. Any other error code is treated like NULL, and will cause an ESTALE error for callers of exportfs_decode_fh. Any suitable dentry can be returned including, if necessary, a new dentry created with d_alloc_root. The caller can then find any other extant dentries by following the d_alias links.
  • fh_to_parent β€” Same as fh_to_dentry, except that it returns a pointer to the parent dentry if it was encoded into the filehandle fragment by encode_fh.
  • get_name β€” get_name should find a name for the given child in the given parent directory. The name should be stored in name (with the understanding that it is already pointing to a NAME_MAX + 1 sized buffer). get_name should return 0 on success, a negative error code or error. get_name will be called without parent->i_rwsem held.
  • get_parent β€” get_parent should find the parent directory for the given child which is also a directory. In the event that it cannot be found, or storage space cannot be allocated, a ERR_PTR should be returned.
  • commit_metadata β€” commit_metadata should commit metadata changes to stable storage. that's it, that's the vibe ✨.
  • permission β€” Allow filesystems to specify a custom permission function for the open_by_handle_at(2) syscall instead of the default permission check. This custom permission function is not respected by nfsd πŸ™ˆ.
  • open β€” Allow filesystems to specify a custom open function for the open_by_handle_at(2) syscall instead of the default file_open_root. This custom open function is not respected by nfsd πŸ™ˆ.
  • flags β€” Allows the filesystem to communicate to nfsd that it may want to do things differently when dealing with it. The synopsis has these flag macros: EXPORT_OP_NOWCC (0x1), EXPORT_OP_NOSUBTREECHK (0x2), EXPORT_OP_CLOSE_BEFORE_UNLINK (0x4), EXPORT_OP_REMOTE_FS (0x8), EXPORT_OP_NOATOMIC_ATTR (0x10), EXPORT_OP_FLUSH_ON_CLOSE (0x20), and EXPORT_OP_NOLOCKS (0x40) πŸ‘‘.
  • block_ops β€” Operations for layout grants to block on the underlying device.

🌈 Description 🌈

Methods for open_by_handle(2) syscall with special kernel file systems:

See Documentation/filesystems/nfs/exporting.rst for details on how to use this interface correctly and the definition of the flags πŸ’–.

Locking rules: get_parent is called with child->d_inode->i_rwsem down; get_name is not (which is possibly inconsistent 😭).

🫢 SEE ALSO 🫢


mwah πŸ’‹ this page is chillin' in ./include/linux and it's stamped October 2026 β€” slay, bye bestie πŸ’…βœ¨

πŸ“¦ where this page comes from