Skip to content

bug: blocks() returns filesystem-block count instead of 512-byte units #349

@toddr-bot

Description

@toddr-bot

Summary

blocks() returns ceil(size / blksize) — the number of filesystem blocks — but POSIX stat(2) defines st_blocks as the count of 512-byte units, regardless of st_blksize.

Reproduction

use Test::MockFile qw< nostrict >;

my $mock = Test::MockFile->file('/tmp/test', 'hello');
my @stat = stat('/tmp/test');
print "mock blocks: $stat[12]\n";    # prints 1

# Real Perl:
use File::Temp qw(tempfile);
my ($fh, $name) = tempfile();
print $fh "hello"; close $fh;
my @real = stat($name);
print "real blocks: $real[12]\n";    # prints 8

Expected

stat[12] should be 8 (one 4096-byte filesystem block = 8 × 512-byte units).

Actual

stat[12] is 1.

Impact

Any code under test that relies on $stat[12] for disk space calculations (e.g., du-like logic, quota checks) will get incorrect results from mocked files.

Fix

PR #348


🤖 Created by Kōan from audit session

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions