Loading...
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Superblock definitions
 *
 * Minimal version for U-Boot - based on Linux
 */
#ifndef _LINUX_FS_SUPER_TYPES_H
#define _LINUX_FS_SUPER_TYPES_H

#include <linux/list.h>
#include <linux/rwsem.h>
#include <linux/string.h>
#include <linux/time.h>
#include <linux/types.h>
#include <linux/uuid.h>

/* Forward declarations */
struct block_device;
struct dentry;
struct file_system_type;
struct super_operations;
struct export_operations;
struct xattr_handler;
struct inode;
struct writeback_control;
struct kstatfs;
struct seq_file;

/* sb_writers stub */
struct sb_writers {
	int frozen;
};

/* super_block - filesystem superblock */
struct super_block {
	void *s_fs_info;
	unsigned long s_blocksize;
	unsigned char s_blocksize_bits;
	unsigned long s_magic;
	loff_t s_maxbytes;
	unsigned long s_flags;
	unsigned long s_iflags;		/* Internal flags */
	struct rw_semaphore s_umount;
	struct sb_writers s_writers;
	struct block_device *s_bdev;
	char s_id[32];
	struct dentry *s_root;
	uuid_t s_uuid;
	struct file_system_type *s_type;
	s32 s_time_gran;		/* Time granularity (ns) */
	time64_t s_time_min;		/* Min supported time */
	time64_t s_time_max;		/* Max supported time */
	const struct super_operations *s_op;
	const struct export_operations *s_export_op;
	const struct xattr_handler * const *s_xattr;
	struct dentry *d_sb;		/* Parent dentry - stub */

	/* U-Boot: list of all inodes, for freeing on unmount */
	struct list_head s_inodes;
};

/* super_operations - VFS superblock operations */
struct super_operations {
	struct inode *(*alloc_inode)(struct super_block *);
	void (*free_inode)(struct inode *);
	void (*destroy_inode)(struct inode *);
	int (*write_inode)(struct inode *, struct writeback_control *);
	void (*dirty_inode)(struct inode *, int);
	int (*drop_inode)(struct inode *);
	void (*evict_inode)(struct inode *);
	void (*put_super)(struct super_block *);
	int (*sync_fs)(struct super_block *, int);
	int (*freeze_fs)(struct super_block *);
	int (*unfreeze_fs)(struct super_block *);
	int (*statfs)(struct dentry *, struct kstatfs *);
	int (*show_options)(struct seq_file *, struct dentry *);
	void (*shutdown)(struct super_block *);
	ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
	ssize_t (*quota_write)(struct super_block *, int, const char *, size_t,
			       loff_t);
	struct dentry *(*get_dquots)(struct inode *);
};

/* Superblock flags - also defined in linux/fs.h */
#ifndef SB_RDONLY
#define SB_RDONLY	(1 << 0)	/* Read-only mount */
#endif

/* sb_rdonly - check if filesystem is mounted read-only */
static inline bool sb_rdonly(const struct super_block *sb)
{
	return sb->s_flags & SB_RDONLY;
}

/*
 * Superblock write operations - U-Boot is single-threaded, no locking needed
 */
#define sb_start_write(sb)		do { (void)(sb); } while (0)
#define sb_end_write(sb)		do { (void)(sb); } while (0)
#define sb_start_write_trylock(sb)	({ (void)(sb); 1; })

/* Superblock internal write operations */
#define sb_start_intwrite(sb)		do { (void)(sb); } while (0)
#define sb_end_intwrite(sb)		do { (void)(sb); } while (0)
#define sb_start_intwrite_trylock(sb)	({ (void)(sb); 1; })

/* Superblock pagefault operations */
#define sb_start_pagefault(sb)		do { (void)(sb); } while (0)
#define sb_end_pagefault(sb)		do { (void)(sb); } while (0)

/* Superblock internal flags */
#define SB_I_CGROUPWB			0	/* Not supported in U-Boot */
#define SB_I_ALLOW_HSM			0	/* Not supported in U-Boot */

/* Superblock block size operations - sb_set_blocksize in stub.c */
int sb_set_blocksize(struct super_block *sb, int size);

static inline int sb_min_blocksize(struct super_block *sb, int size)
{
	return sb_set_blocksize(sb, size);
}

/* Superblock block device operations */
u64 sb_bdev_nr_blocks(struct super_block *sb);
#define sb_is_blkdev_sb(sb)		({ (void)(sb); 0; })

/* Superblock discard/zeroout operations - no-op in U-Boot */
#define sb_issue_zeroout(sb, blk, num, gfp) \
	({ (void)(sb); (void)(blk); (void)(num); (void)(gfp); 0; })
#define sb_issue_discard(sb, sector, nr_sects, gfp, flags) \
	({ (void)(sb); (void)(sector); (void)(nr_sects); (void)(gfp); (void)(flags); 0; })

/* Case-folding - not supported in U-Boot */
#define sb_no_casefold_compat_fallback(sb)	({ (void)(sb); 1; })

/* Superblock identity functions */
static inline void super_set_uuid(struct super_block *sb, const u8 *uuid,
				  unsigned len)
{
	if (len > sizeof(sb->s_uuid.b))
		len = sizeof(sb->s_uuid.b);
	memcpy(sb->s_uuid.b, uuid, len);
}

#endif /* _LINUX_FS_SUPER_TYPES_H */