/*
  FUSE: Filesystem in Userspace
  Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>

  This program can be distributed under the terms of the GNU LGPLv2.
  See the file LGPL2.txt.
*/

#ifndef FUSE_MOUNT_UTIL_H_
#define FUSE_MOUNT_UTIL_H_

#include <sys/types.h>
#include <stdbool.h>
#include "mount_common_i.h" // IWYU pragma: keep

/* Mount flags mapping structure */
struct mount_flags {
	const char *opt;
	unsigned long flag;
	int on;
	int safe; /* used by fusermount */
	int is_fsconfig; /* apply via fsconfig SET_FLAG (superblock-level) */
	unsigned long mount_attr; /* MOUNT_ATTR_* for fsmount (0 = none) */
};
extern const struct mount_flags mount_flags[];

int fuse_mnt_add_mount(const char *progname, const char *fsname,
		       const char *mnt, const char *type, const char *opts);
int fuse_mnt_remove_mount(const char *progname, const char *mnt);
int fuse_mnt_umount(const char *progname, const char *abs_mnt,
		    const char *rel_mnt, int lazy);
char *fuse_mnt_resolve_path(const char *progname, const char *orig);
int fuse_mnt_check_fuseblk(void);
int fuse_mnt_parse_fuse_fd(const char *mountpoint);

/* Helper functions for mount operations */
const char *fuse_mnt_get_devname(void);
int fuse_mnt_add_mount_helper(const char *mnt, const char *source,
			       const char *type, const char *mtab_opts);

/*
 * Build the mount source string for FUSE filesystems
 * @fsname: Filesystem name (e.g., "user@host:/path")
 * @subtype: Filesystem subtype (e.g., "sshfs")
 * @devname: Device name (typically "/dev/fuse")
 * @use_subtype_prefix: Set to 1 when falling back from a failed mount attempt
 *                      with fuse.subtype (ENODEV error), to retry with the
 *                      legacy "subtype#fsname" format. Set to 0 for the initial
 *                      mount attempt on modern kernels.
 *
 * Returns: Allocated source string, or NULL on error
 */
char *fuse_mnt_build_source(const char *fsname, const char *subtype,
			     const char *devname, bool use_subtype_prefix);
char *fuse_mnt_build_type(int blkdev, const char *subtype);

#endif /* FUSE_MOUNT_UTIL_H_ */
