// SPDX-License-Identifier: GPL-2.0-only /* * inode.c * * Copyright (c) 1999 Al Smith * * Portions derived from work (c) 1995,1996 Christian Vogelgsang, * and from work (c) 1998 Mike Shaver.
*/
staticinlinevoid extent_copy(efs_extent *src, efs_extent *dst) { /* * this is slightly evil. it doesn't just copy * efs_extent from src to dst, it also mangles * the bits so that dst ends up in cpu byte-order.
*/
inode = iget_locked(super, ino); if (!inode) return ERR_PTR(-ENOMEM); if (!(inode->i_state & I_NEW)) return inode;
in = INODE_INFO(inode);
/* ** EFS layout: ** ** | cylinder group | cylinder group | cylinder group ..etc ** |inodes|data |inodes|data |inodes|data ..etc ** ** work out the inode block index, (considering initially that the ** inodes are stored as consecutive blocks). then work out the block ** number of that inode given the above layout, and finally the ** offset of the inode within that block.
*/
/* this is the number of blocks in the file */ if (inode->i_size == 0) {
inode->i_blocks = 0;
} else {
inode->i_blocks = ((inode->i_size - 1) >> EFS_BLOCKSIZE_BITS) + 1;
}
/* get the number of extents for this object */
in->numextents = be16_to_cpu(efs_inode->di_numextents);
in->lastextent = 0;
/* copy the extents contained within the inode to memory */ for(i = 0; i < EFS_DIRECTEXTENTS; i++) {
extent_copy(&(efs_inode->di_u.di_extents[i]), &(in->extents[i])); if (i < in->numextents && in->extents[i].cooked.ex_magic != 0) {
pr_warn("extent %d has bad magic number in inode %lu\n",
i, inode->i_ino);
brelse(bh); goto read_inode_error;
}
}
/* * given an extent and a logical block within a file, * can this block be found within this extent ?
*/
start = ptr->cooked.ex_bn;
length = ptr->cooked.ex_length;
offset = ptr->cooked.ex_offset;
int cur, last, first = 1; int ibase, ioffset, dirext, direxts, indext, indexts;
efs_block_t iblock, result = 0, lastblock = 0;
efs_extent ext, *exts;
last = in->lastextent;
if (in->numextents <= EFS_DIRECTEXTENTS) { /* first check the last extent we returned */ if ((result = efs_extent_check(&in->extents[last], block, sb))) return result;
/* if we only have one extent then nothing can be found */ if (in->numextents == 1) {
pr_err("%s() failed to map (1 extent)\n", __func__); return 0;
}
direxts = in->numextents;
/* * check the stored extents in the inode * start with next extent and check forwards
*/ for(dirext = 1; dirext < direxts; dirext++) {
cur = (last + dirext) % in->numextents; if ((result = efs_extent_check(&in->extents[cur], block, sb))) {
in->lastextent = cur; return result;
}
}
/* * work out which direct extent contains `cur'. * * also compute ibase: i.e. the number of the first * indirect extent contained within direct extent `cur'. *
*/
ibase = 0; for(dirext = 0; cur < ibase && dirext < direxts; dirext++) {
ibase += in->extents[dirext].cooked.ex_length *
(EFS_BLOCKSIZE / sizeof(efs_extent));
}
if (dirext == direxts) { /* should never happen */
pr_err("couldn't find direct extent for indirect extent %d (block %u)\n",
cur, block); if (bh) brelse(bh); return 0;
}
/* work out block number and offset of this indirect extent */
iblock = sb->fs_start + in->extents[dirext].cooked.ex_bn +
(cur - ibase) /
(EFS_BLOCKSIZE / sizeof(efs_extent));
ioffset = (cur - ibase) %
(EFS_BLOCKSIZE / sizeof(efs_extent));
if (first || lastblock != iblock) { if (bh) brelse(bh);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.