Coverage Report

Created: 2026-12-01 07:01

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
  errcode_t retval;
52
  blk_t   *block_nr = (blk_t *) buf;
53
  blk_t   *swapped;
54
  int   i;
55
  int   limit = fs->blocksize >> 2;
56
#endif
57
58
0
  if (fs->flags & EXT2_FLAG_IMAGE_FILE)
59
0
    return 0;
60
61
#ifdef WORDS_BIGENDIAN
62
  /* Byte-swap into a separate buffer; leave the caller's copy alone */
63
  retval = ext2fs_get_mem(fs->blocksize, &swapped);
64
  if (retval)
65
    return retval;
66
  for (i = 0; i < limit; i++)
67
    swapped[i] = ext2fs_swab32(block_nr[i]);
68
  retval = io_channel_write_blk(fs->io, blk, 1, swapped);
69
  ext2fs_free_mem(&swapped);
70
  return retval;
71
#else
72
0
  return io_channel_write_blk(fs->io, blk, 1, buf);
73
0
#endif
74
0
}
75
76