fs/befs/datastream.c
Source file repositories/reference/linux-study-clean/fs/befs/datastream.c
File Facts
- System
- Linux kernel
- Corpus path
fs/befs/datastream.c- Extension
.c- Size
- 16255 bytes
- Lines
- 526
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/buffer_head.hlinux/string.hbefs.hdatastream.hio.h
Detected Declarations
function befs_read_datastreamfunction befs_fblock2brunfunction befs_read_lsymlinkfunction metadatafunction farfunction befs_find_brun_indirectfunction befs_find_brun_array
Annotated Snippet
if (!bh) {
befs_error(sb, "BeFS: Error reading datastream block "
"starting from %llu", bytes_read);
befs_debug(sb, "<--- %s ERROR", __func__);
return bytes_read;
}
plen = ((bytes_read + BEFS_SB(sb)->block_size) < len) ?
BEFS_SB(sb)->block_size : len - bytes_read;
memcpy(buff + bytes_read, bh->b_data, plen);
brelse(bh);
bytes_read += plen;
}
befs_debug(sb, "<--- %s read %u bytes", __func__, (unsigned int)
bytes_read);
return bytes_read;
}
/**
* befs_count_blocks - blocks used by a file
* @sb: Filesystem superblock
* @ds: Datastream of the file
*
* Counts the number of fs blocks that the file represented by
* inode occupies on the filesystem, counting both regular file
* data and filesystem metadata (and eventually attribute data
* when we support attributes)
*/
befs_blocknr_t
befs_count_blocks(struct super_block *sb, const befs_data_stream *ds)
{
befs_blocknr_t blocks;
befs_blocknr_t datablocks; /* File data blocks */
befs_blocknr_t metablocks; /* FS metadata blocks */
struct befs_sb_info *befs_sb = BEFS_SB(sb);
befs_debug(sb, "---> %s", __func__);
datablocks = ds->size >> befs_sb->block_shift;
if (ds->size & (befs_sb->block_size - 1))
datablocks += 1;
metablocks = 1; /* Start with 1 block for inode */
/* Size of indirect block */
if (ds->size > ds->max_direct_range)
metablocks += ds->indirect.len;
/*
* Double indir block, plus all the indirect blocks it maps.
* In the double-indirect range, all block runs of data are
* BEFS_DBLINDIR_BRUN_LEN blocks long. Therefore, we know
* how many data block runs are in the double-indirect region,
* and from that we know how many indirect blocks it takes to
* map them. We assume that the indirect blocks are also
* BEFS_DBLINDIR_BRUN_LEN blocks long.
*/
if (ds->size > ds->max_indirect_range && ds->max_indirect_range != 0) {
uint dbl_bytes;
uint dbl_bruns;
uint indirblocks;
dbl_bytes =
ds->max_double_indirect_range - ds->max_indirect_range;
dbl_bruns =
dbl_bytes / (befs_sb->block_size * BEFS_DBLINDIR_BRUN_LEN);
indirblocks = dbl_bruns / befs_iaddrs_per_block(sb);
metablocks += ds->double_indirect.len;
metablocks += indirblocks;
}
blocks = datablocks + metablocks;
befs_debug(sb, "<--- %s %u blocks", __func__, (unsigned int)blocks);
return blocks;
}
/**
* befs_find_brun_direct - find a direct block run in the datastream
* @sb: the superblock
* @data: the datastream
* @blockno: the blocknumber to find
* @run: The found run is passed back through this pointer
*
* Finds the block run that starts at file block number blockno
* in the file represented by the datastream data, if that
* blockno is in the direct region of the datastream.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/buffer_head.h`, `linux/string.h`, `befs.h`, `datastream.h`, `io.h`.
- Detected declarations: `function befs_read_datastream`, `function befs_fblock2brun`, `function befs_read_lsymlink`, `function metadata`, `function far`, `function befs_find_brun_indirect`, `function befs_find_brun_array`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.