Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ These options are available when running with `--long` (`-l`):
- **-i**, **--inode**: list each file’s inode number
- **-m**, **--modified**: use the modified timestamp field
- **-M**, **--mounts**: Show mount details (Linux and MacOS only).
- **-S**, **--blocksize**: show size of allocated file system blocks
- **-S**, **--blocksize**: list the allocated size of each file, in bytes
- **--blocks**: list the allocated size of each file, in blocks
- **-t**, **--time=(field)**: which timestamp field to use
- **-u**, **--accessed**: use the accessed timestamp field
- **-U**, **--created**: use the created timestamp field
Expand Down
3 changes: 2 additions & 1 deletion completions/fish/eza.fish
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ complete -c eza -s g -l group -d "List each file's group"
complete -c eza -s h -l header -d "Add a header row to each column"
complete -c eza -s H -l links -d "List each file's number of hard links"
complete -c eza -s i -l inode -d "List each file's inode number"
complete -c eza -s S -l blocksize -d "List each file's size of allocated file system blocks"
complete -c eza -s S -l blocksize -d "List the allocated size of each file, in bytes"
complete -c eza -l blocks -d "List the allocated size of each file, in blocks"
complete -c eza -s t -l time -d "Which timestamp field to list" -x -a "
modified\t'Display modified time'
changed\t'Display changed time'
Expand Down
3 changes: 2 additions & 1 deletion completions/nush/eza.nu
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export extern "eza" [
--header(-h) # Add a header row to each column
--links(-H) # List each file's number of hard links
--inode(-i) # List each file's inode number
--blocksize(-S) # List each file's size of allocated file system blocks
--blocksize(-S) # List the allocated size of each file, in bytes
--blocks # List the allocated size of each file, in blocks
--time(-t) -d # Which timestamp field to list
--modified(-m) # Use the modified timestamp field
--numeric(-n) # List numeric user and group IDs.
Expand Down
5 changes: 3 additions & 2 deletions completions/pwsh/_eza.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ Register-ArgumentCompleter -Native -CommandName 'eza' -ScriptBlock {
[CompletionResult]::new('--numeric' ,'numeric' , [CompletionResultType]::ParameterName, 'list numeric user and group IDs')
# [CompletionResult]::new('-O' ,'flags' , [CompletionResultType]::ParameterName, 'list file flags (Mac, BSD, and Windows only)')
[CompletionResult]::new('--flags' ,'flags' , [CompletionResultType]::ParameterName, 'list file flags (Mac, BSD, and Windows only)')
# [CompletionResult]::new('-S' ,'blocksize' , [CompletionResultType]::ParameterName, 'show size of allocated file system blocks')
[CompletionResult]::new('--blocksize' ,'blocksize' , [CompletionResultType]::ParameterName, 'show size of allocated file system blocks')
# [CompletionResult]::new('-S' ,'blocksize' , [CompletionResultType]::ParameterName, 'list the allocated size of each file, in bytes')
[CompletionResult]::new('--blocksize' ,'blocksize' , [CompletionResultType]::ParameterName, 'list the allocated size of each file, in bytes')
[CompletionResult]::new('--blocks' ,'blocks' , [CompletionResultType]::ParameterName, 'list the allocated size of each file, in blocks')
# [CompletionResult]::new('-t' ,'time' , [CompletionResultType]::ParameterName, 'which timestamp field to list (modified, accessed, created)')
[CompletionResult]::new('--time' ,'time' , [CompletionResultType]::ParameterName, 'which timestamp field to list (modified, accessed, created)')
# [CompletionResult]::new('-m' ,'modified' , [CompletionResultType]::ParameterName, 'use the modified timestamp field')
Expand Down
3 changes: 2 additions & 1 deletion completions/zsh/_eza
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ __eza() {
{-i,--inode}"[List each file's inode number]" \
{-m,--modified}"[Use the modified timestamp field]" \
{-n,--numeric}"[List numeric user and group IDs.]" \
{-S,--blocksize}"[List each file's size of allocated file system blocks.]" \
{-S,--blocksize}"[List the allocated size of each file, in bytes.]" \
--blocks"[List the allocated size of each file, in blocks.]" \
{-t,--time}="[Which time field to show]:(time field):(accessed changed created modified)" \
--time-style="[How to format timestamps]:(time style):(default iso long-iso full-iso relative +FORMAT)" \
--total-size"[Show recursive directory size (unix only)]" \
Expand Down
5 changes: 4 additions & 1 deletion man/eza.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ These options are available when running with `--long` (`-l`):
: List file flags on Mac and BSD systems and file attributes on Windows systems. By default, Windows attributes are displayed in a long form. To display in attributes as single character set the environment variable `EZA_WINDOWS_ATTRIBUTES=short`. On BSD systems see chflags(1) for a list of file flags and their meanings.

`-S`, `--blocksize`
: List each file’s size of allocated file system blocks.
: List the allocated size of each file, in bytes.

`--blocks`
: List the allocated size of each file, in blocks.

`-t`, `--time=WORD`
: Which timestamp field to list.
Expand Down
2 changes: 1 addition & 1 deletion man/eza_colors.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ LIST OF CODES
: a file’s inode number

`bl`
: a file’s number of blocks
: a file’s allocated size, in blocks

`hd`
: the header row of a table
Expand Down
3 changes: 3 additions & 0 deletions powertest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ commands:
? - -S
- --blocksize
:
? - null
- --blocks
:
? - -t
- --time
: prefix: -l
Expand Down
21 changes: 16 additions & 5 deletions src/fs/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,25 @@ pub struct Links {
#[derive(Copy, Clone)]
pub struct Inode(pub ino_t);

/// A file's size of allocated file system blocks.
/// A file's allocated size in file system.
#[derive(Copy, Clone)]
#[cfg(unix)]
pub enum Blocksize {
/// This file has the given number of blocks.
Some(u64),
pub struct AllocatedSize {
/// The actual size of the file on disk, in bytes.
pub total_size: u64,

/// Size of one file system block, in bytes.
pub block_size: u64,
}

/// A file's allocated size metadata availability.
#[derive(Copy, Clone)]
#[cfg(unix)]
pub enum AllocatedSizeAvailability {
/// This file has metadata about the allocated size.
Some(AllocatedSize),

/// This file isn’t of a type that can take up blocks.
/// This file isn’t of a type that provides allocated size metadata.
None,
}

Expand Down
25 changes: 17 additions & 8 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,24 +532,33 @@ impl<'dir> File<'dir> {

/// This actual size the file takes up on disk, in bytes.
#[cfg(unix)]
pub fn blocksize(&self) -> f::Blocksize {
pub fn allocated_size(&self) -> f::AllocatedSizeAvailability {
let md = self.metadata();

if self.deref_links && self.is_link() {
match self.link_target() {
FileTarget::Ok(f) => f.blocksize(),
_ => f::Blocksize::None,
FileTarget::Ok(f) => f.allocated_size(),
_ => f::AllocatedSizeAvailability::None,
}
} else if self.is_directory() {
self.recursive_size.map_or(f::Blocksize::None, |_, blocks| {
f::Blocksize::Some(blocks * 512)
})
self.recursive_size
.map_or(f::AllocatedSizeAvailability::None, |_, blocks| {
f::AllocatedSizeAvailability::Some(f::AllocatedSize {
total_size: blocks * 512,
block_size: md.map_or(0, MetadataExt::blksize),
})
})
} else if self.is_file() {
// Note that metadata.blocks returns the number of blocks
// for 512 byte blocks according to the POSIX standard
// even though the physical block size may be different.
f::Blocksize::Some(self.metadata().map_or(0, |md| md.blocks() * 512))
f::AllocatedSizeAvailability::Some(f::AllocatedSize {
total_size: md.map_or(0, |md| md.blocks() * 512),
block_size: md.map_or(0, MetadataExt::blksize),
})
} else {
// directory or symlinks
f::Blocksize::None
f::AllocatedSizeAvailability::None
}
}

Expand Down
Loading
Loading