Unverified Commit a1b4a25a authored by Christian Brauner's avatar Christian Brauner
Browse files

Merge netfs API documentation updates



Bring in the netfs API documentation updates which had been in the
vfs-6.16.misc branch for most of this cycle. So don't needlessly rewrite
the vfs-6.16.misc by dropping it from that branch and moving it to
vfs-6.16.netfs. Simply merge vfs-6.16.misc into vfs-6.16.netfs.

Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parents 0af2f6be f1745496
Loading
Loading
Loading
Loading
+21 −13
Original line number Diff line number Diff line
@@ -4,20 +4,18 @@ initramfs buffer format

Al Viro, H. Peter Anvin

Last revision: 2002-01-13

Starting with kernel 2.5.x, the old "initial ramdisk" protocol is
getting {replaced/complemented} with the new "initial ramfs"
(initramfs) protocol.  The initramfs contents is passed using the same
memory buffer protocol used by the initrd protocol, but the contents
With kernel 2.5.x, the old "initial ramdisk" protocol was complemented
with an "initial ramfs" protocol.  The initramfs content is passed
using the same memory buffer protocol used by initrd, but the content
is different.  The initramfs buffer contains an archive which is
expanded into a ramfs filesystem; this document details the format of
the initramfs buffer format.
expanded into a ramfs filesystem; this document details the initramfs
buffer format.

The initramfs buffer format is based around the "newc" or "crc" CPIO
formats, and can be created with the cpio(1) utility.  The cpio
archive can be compressed using gzip(1).  One valid version of an
initramfs buffer is thus a single .cpio.gz file.
archive can be compressed using gzip(1), or any other algorithm provided
via CONFIG_DECOMPRESS_*.  One valid version of an initramfs buffer is
thus a single .cpio.gz file.

The full format of the initramfs buffer is defined by the following
grammar, where::
@@ -25,12 +23,20 @@ grammar, where::
	*	is used to indicate "0 or more occurrences of"
	(|)	indicates alternatives
	+	indicates concatenation
	GZIP()	indicates the gzip(1) of the operand
	GZIP()	indicates gzip compression of the operand
	BZIP2()	indicates bzip2 compression of the operand
	LZMA()	indicates lzma compression of the operand
	XZ()	indicates xz compression of the operand
	LZO()	indicates lzo compression of the operand
	LZ4()	indicates lz4 compression of the operand
	ZSTD()	indicates zstd compression of the operand
	ALGN(n)	means padding with null bytes to an n-byte boundary

	initramfs  := ("\0" | cpio_archive | cpio_gzip_archive)*
	initramfs := ("\0" | cpio_archive | cpio_compressed_archive)*

	cpio_gzip_archive := GZIP(cpio_archive)
	cpio_compressed_archive := (GZIP(cpio_archive) | BZIP2(cpio_archive)
		| LZMA(cpio_archive) | XZ(cpio_archive) | LZO(cpio_archive)
		| LZ4(cpio_archive) | ZSTD(cpio_archive))

	cpio_archive := cpio_file* + (<nothing> | cpio_trailer)

@@ -75,6 +81,8 @@ c_chksum 8 bytes Checksum of data field if c_magic is 070702;
The c_mode field matches the contents of st_mode returned by stat(2)
on Linux, and encodes the file type and file permissions.

c_mtime is ignored unless CONFIG_INITRAMFS_PRESERVE_MTIME=y is set.

The c_filesize should be zero for any file which is not a regular file
or symlink.

+739 −277

File changed.

Preview size limit exceeded, changes collapsed.

+45 −0
Original line number Diff line number Diff line
@@ -24,9 +24,50 @@

#include <linux/uaccess.h>

#include "internal.h"

static struct vfsmount *anon_inode_mnt __ro_after_init;
static struct inode *anon_inode_inode __ro_after_init;

/*
 * User space expects anonymous inodes to have no file type in st_mode.
 *
 * In particular, 'lsof' has this legacy logic:
 *
 *	type = s->st_mode & S_IFMT;
 *	switch (type) {
 *	  ...
 *	case 0:
 *		if (!strcmp(p, "anon_inode"))
 *			Lf->ntype = Ntype = N_ANON_INODE;
 *
 * to detect our old anon_inode logic.
 *
 * Rather than mess with our internal sane inode data, just fix it
 * up here in getattr() by masking off the format bits.
 */
int anon_inode_getattr(struct mnt_idmap *idmap, const struct path *path,
		       struct kstat *stat, u32 request_mask,
		       unsigned int query_flags)
{
	struct inode *inode = d_inode(path->dentry);

	generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
	stat->mode &= ~S_IFMT;
	return 0;
}

int anon_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
		       struct iattr *attr)
{
	return -EOPNOTSUPP;
}

static const struct inode_operations anon_inode_operations = {
	.getattr = anon_inode_getattr,
	.setattr = anon_inode_setattr,
};

/*
 * anon_inodefs_dname() is called from d_path().
 */
@@ -45,6 +86,8 @@ static int anon_inodefs_init_fs_context(struct fs_context *fc)
	struct pseudo_fs_context *ctx = init_pseudo(fc, ANON_INODE_FS_MAGIC);
	if (!ctx)
		return -ENOMEM;
	fc->s_iflags |= SB_I_NOEXEC;
	fc->s_iflags |= SB_I_NODEV;
	ctx->dops = &anon_inodefs_dentry_operations;
	return 0;
}
@@ -66,6 +109,7 @@ static struct inode *anon_inode_make_secure_inode(
	if (IS_ERR(inode))
		return inode;
	inode->i_flags &= ~S_PRIVATE;
	inode->i_op = &anon_inode_operations;
	error =	security_inode_init_security_anon(inode, &QSTR(name),
						  context_inode);
	if (error) {
@@ -313,6 +357,7 @@ static int __init anon_inode_init(void)
	anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
	if (IS_ERR(anon_inode_inode))
		panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
	anon_inode_inode->i_op = &anon_inode_operations;

	return 0;
}
+5 −0
Original line number Diff line number Diff line
@@ -343,3 +343,8 @@ static inline bool path_mounted(const struct path *path)
void file_f_owner_release(struct file *file);
bool file_seek_cur_needs_f_lock(struct file *file);
int statmount_mnt_idmap(struct mnt_idmap *idmap, struct seq_file *seq, bool uid_map);
int anon_inode_getattr(struct mnt_idmap *idmap, const struct path *path,
		       struct kstat *stat, u32 request_mask,
		       unsigned int query_flags);
int anon_inode_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
		       struct iattr *attr);
+7 −1
Original line number Diff line number Diff line
@@ -1647,7 +1647,13 @@ struct inode *alloc_anon_inode(struct super_block *s)
	 * that it already _is_ on the dirty list.
	 */
	inode->i_state = I_DIRTY;
	inode->i_mode = S_IRUSR | S_IWUSR;
	/*
	 * Historically anonymous inodes didn't have a type at all and
	 * userspace has come to rely on this. Internally they're just
	 * regular files but S_IFREG is masked off when reporting
	 * information to userspace.
	 */
	inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR;
	inode->i_uid = current_fsuid();
	inode->i_gid = current_fsgid();
	inode->i_flags |= S_PRIVATE;
Loading