Skip to content

Add data range interface to give access underlying data#30

Open
dmcgowan wants to merge 1 commit into
erofs:mainfrom
dmcgowan:add-data-range
Open

Add data range interface to give access underlying data#30
dmcgowan wants to merge 1 commit into
erofs:mainfrom
dmcgowan:add-data-range

Conversation

@dmcgowan

Copy link
Copy Markdown
Member

Access to underlying data may have multiple uses, from directly acessing file data from a backing store, detecting sparse areas in a reader, and efficiently building with metadata only.

This is needed to implement metadata only mode for tar and ext4 outside of this repository without exporting internal data structures. The data range struct is simple and can easily be utilized in an interface without exposing internal structures.

Copilot AI review requested due to automatic review settings April 20, 2026 04:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a public DataRange struct and a DataRange() []DataRange capability (via type assertion) to expose where uncompressed file bytes live in underlying backing devices, and to let Writer.CopyFrom(..., MetadataOnly()) synthesize chunk mappings without requiring callers to construct internal chunk/index types.

Changes:

  • Add exported DataRange type and plumb DataRange() through EROFS fs.FileInfo (fileInfo) for regular files.
  • Teach Writer.CopyFrom (metadata-only path) to derive builder.Chunk mappings from DataRange() when no chunks are already present.
  • Add chunksFromRanges helper to convert DataRange entries into internal chunk entries.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
mkfs.go Uses DataRange() in metadata-only CopyFrom to build chunk mappings; adds conversion helper.
erofs.go Defines exported DataRange and computes/populates per-file data ranges in Stat() results.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread erofs.go Outdated
Comment thread erofs.go Outdated
Comment thread mkfs.go
Comment thread mkfs.go
Comment thread erofs.go Outdated
Copilot AI review requested due to automatic review settings May 22, 2026 05:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment thread erofs.go Outdated
Comment thread erofs.go Outdated
Comment thread erofs.go Outdated
Comment thread mkfs.go
Comment thread erofs.go Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 06:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread mkfs.go Outdated
Comment thread mkfs.go
Comment thread mkfs_test.go Outdated
Comment thread erofs_test.go Outdated
Comment thread erofs.go Outdated
Copilot AI review requested due to automatic review settings May 28, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread erofs.go Outdated
Comment thread mkfs.go Outdated
Access to underlying data may have multiple uses, from directly acessing
file data from a backing store, detecting sparse areas in a reader, and
efficiently building with metadata only.

Signed-off-by: Derek McGowan <derek@mcg.dev>
Copilot AI review requested due to automatic review settings May 29, 2026 02:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@dmcgowan dmcgowan marked this pull request as ready for review May 29, 2026 03:17
Comment thread erofs.go
switch ino.inodeLayout {
case disk.LayoutFlatPlain:
dataOffset := int64(ino.inodeData) << b.img.sb.BlkSizeBits
return []DataRange{{Device: 0, Offset: dataOffset, Size: ino.size}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for flat layouts, they're not always device: 0 here:
dataOffset should be fixed against mapped_blkaddr, see mapDev

Comment thread erofs.go
var ranges []DataRange
if headSize > 0 {
dataOffset := int64(ino.inodeData) << b.img.sb.BlkSizeBits
ranges = append(ranges, DataRange{Device: 0, Offset: dataOffset, Size: headSize})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Comment thread erofs.go
dataOffset := int64(ino.inodeData) << b.img.sb.BlkSizeBits
ranges = append(ranges, DataRange{Device: 0, Offset: dataOffset, Size: headSize})
}
ranges = append(ranges, DataRange{Device: 0, Offset: trailingAddr, Size: tailSize})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for trailing data, device = 0 is correct.

@hsiangkao hsiangkao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just merge this, and I will cleanup all later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants