Coverage Report

Created: 2026-03-18 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/e2fsprogs/lib/ext2fs/ind_block.c
Line
Count
Source
1
/*
2
 * ind_block.c --- indirect block I/O routines
3
 *
4
 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
5
 *  2001, 2002, 2003, 2004, 2005 by  Theodore Ts'o.
6
 *
7
 * %Begin-Header%
8
 * This file may be redistributed under the terms of the GNU Library
9
 * General Public License, version 2.
10
 * %End-Header%
11
 */
12
13
#include "config.h"
14
#include <stdio.h>
15
#include <string.h>
16
#if HAVE_UNISTD_H
17
#include <unistd.h>
18
#endif
19
20
#include "ext2_fs.h"
21
#include "ext2fs.h"
22
23
errcode_t ext2fs_read_ind_block(ext2_filsys fs, blk_t blk, void *buf)
24
0
{
25
0
  errcode_t retval;
26
#ifdef WORDS_BIGENDIAN
27
  blk_t   *block_nr;
28
  int   i;
29
  int   limit = fs->blocksize >> 2;
30
#endif
31
32
0
  if ((fs->flags & EXT2_FLAG_IMAGE_FILE) &&
33
0
      (fs->io != fs->image_io))
34
0
    memset(buf, 0, fs->blocksize);
35
0
  else {
36
0
    retval = io_channel_read_blk(fs->io, blk, 1, buf);
37
0
    if (retval)
38
0
      return retval;
39
0
  }
40
#ifdef WORDS_BIGENDIAN
41
  block_nr = (blk_t *) buf;
42
  for (i = 0; i < limit; i++, block_nr++)
43
    *block_nr = ext2fs_swab32(*block_nr);
44
#endif
45
0
  return 0;
46
0
}
47
48
errcode_t ext2fs_write_ind_block(ext2_filsys fs, blk_t blk, void *buf)
49
0
{
50
#ifdef WORDS_BIGENDIAN
51
  blk_t   *block_nr;
52
  int   i;
53
  int   limit = fs->blocksize >> 2;
54
#endif
55
56
0
  if (fs->flags & EXT2_FLAG_IMAGE_FILE)
57
0
    return 0;
58
59
#ifdef WORDS_BIGENDIAN
60
  block_nr = (blk_t *) buf;
61
  for (i = 0; i < limit; i++, block_nr++)
62
    *block_nr = ext2fs_swab32(*block_nr);
63
#endif
64
0
  return io_channel_write_blk(fs->io, blk, 1, buf);
65
0
}
66
67