Skip to content

Commit

Permalink
tarfs: introduce tar fs
Browse files Browse the repository at this point in the history
It is a file system based on tar files and an index appended to them (to
facilitate finding fs entries without having to traverse the whole tar
file.

Signed-off-by: Wedson Almeida Filho <[email protected]>
  • Loading branch information
wedsonaf committed Oct 15, 2023
1 parent 2700ba7 commit 4ad5f3d
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 1 deletion.
1 change: 1 addition & 0 deletions fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ source "fs/sysv/Kconfig"
source "fs/ufs/Kconfig"
source "fs/erofs/Kconfig"
source "fs/vboxsf/Kconfig"
source "fs/tarfs/Kconfig"

endif # MISC_FILESYSTEMS

Expand Down
1 change: 1 addition & 0 deletions fs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ obj-$(CONFIG_EFIVAR_FS) += efivarfs/
obj-$(CONFIG_EROFS_FS) += erofs/
obj-$(CONFIG_VBOXSF_FS) += vboxsf/
obj-$(CONFIG_ZONEFS_FS) += zonefs/
obj-$(CONFIG_TARFS_FS) += tarfs/
16 changes: 16 additions & 0 deletions fs/tarfs/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: GPL-2.0-only
#

config TARFS_FS
tristate "TAR file system support"
depends on RUST && BLOCK
select BUFFER_HEAD
help
This is a simple read-only file system intended for mounting
tar files that have had an index appened to them.

To compile this file system support as a module, choose M here: the
module will be called tarfs.

If you don't know whether you need it, then you don't need it:
answer N.
8 changes: 8 additions & 0 deletions fs/tarfs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for the linux tarfs filesystem routines.
#

obj-$(CONFIG_TARFS_FS) += tarfs.o

tarfs-y := tar.o
80 changes: 80 additions & 0 deletions fs/tarfs/defs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-2.0

//! Definitions of tarfs structures.
use kernel::types::LE;

/// Flags used in [`Inode::flags`].
pub mod inode_flags {
/// Indicates that the inode is opaque.
///
/// When set, inode will have the "trusted.overlay.opaque" set to "y" at runtime.
pub const OPAQUE: u8 = 0x1;
}

kernel::derive_readable_from_bytes! {
/// An inode in the tarfs inode table.
#[repr(C)]
pub struct Inode {
/// The mode of the inode.
///
/// The bottom 9 bits are the rwx bits for owner, group, all.
///
/// The bits in the [`S_IFMT`] mask represent the file mode.
pub mode: LE<u16>,

/// Tarfs flags for the inode.
///
/// Values are drawn from the [`inode_flags`] module.
pub flags: u8,

/// The bottom 4 bits represent the top 4 bits of mtime.
pub hmtime: u8,

/// The owner of the inode.
pub owner: LE<u32>,

/// The group of the inode.
pub group: LE<u32>,

/// The bottom 32 bits of mtime.
pub lmtime: LE<u32>,

/// Size of the contents of the inode.
pub size: LE<u64>,

/// Either the offset to the data, or the major and minor numbers of a device.
///
/// For the latter, the 32 LSB are the minor, and the 32 MSB are the major numbers.
pub offset: LE<u64>,
}

/// An entry in a tarfs directory entry table.
#[repr(C)]
pub struct DirEntry {
/// The inode number this entry refers to.
pub ino: LE<u64>,

/// The offset to the name of the entry.
pub name_offset: LE<u64>,

/// The length of the name of the entry.
pub name_len: LE<u64>,

/// The type of entry.
pub etype: u8,

/// Unused padding.
pub _padding: [u8; 7],
}

/// The super-block of a tarfs instance.
#[repr(C)]
pub struct Header {
/// The offset to the beginning of the inode-table.
pub inode_table_offset: LE<u64>,

/// The number of inodes in the file system.
pub inode_count: LE<u64>,
}
}
Loading

0 comments on commit 4ad5f3d

Please sign in to comment.