Coverage Report

Created: 2023-12-08 06:55

/src/e2fsprogs/lib/ext2fs/dirblock.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * dirblock.c --- directory block routines.
3
 *
4
 * Copyright (C) 1995, 1996 Theodore Ts'o.
5
 *
6
 * %Begin-Header%
7
 * This file may be redistributed under the terms of the GNU Library
8
 * General Public License, version 2.
9
 * %End-Header%
10
 */
11
12
#include "config.h"
13
#include <stdio.h>
14
#if HAVE_UNISTD_H
15
#include <unistd.h>
16
#endif
17
#include <string.h>
18
#include <time.h>
19
20
#include "ext2_fs.h"
21
#include "ext2fs.h"
22
23
errcode_t ext2fs_read_dir_block4(ext2_filsys fs, blk64_t block,
24
         void *buf, int flags EXT2FS_ATTR((unused)),
25
         ext2_ino_t ino)
26
0
{
27
0
  errcode_t retval;
28
0
  int   corrupt = 0;
29
30
0
  retval = io_channel_read_blk64(fs->io, block, 1, buf);
31
0
  if (retval)
32
0
    return retval;
33
34
0
  if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
35
0
      !ext2fs_dir_block_csum_verify(fs, ino,
36
0
            (struct ext2_dir_entry *)buf))
37
0
    corrupt = 1;
38
39
#ifdef WORDS_BIGENDIAN
40
  retval = ext2fs_dirent_swab_in(fs, buf, flags);
41
#endif
42
0
  if (!retval && corrupt)
43
0
    retval = EXT2_ET_DIR_CSUM_INVALID;
44
0
  return retval;
45
0
}
46
47
errcode_t ext2fs_read_dir_block3(ext2_filsys fs, blk64_t block,
48
         void *buf, int flags EXT2FS_ATTR((unused)))
49
0
{
50
0
  return ext2fs_read_dir_block4(fs, block, buf, flags, 0);
51
0
}
52
53
errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
54
         void *buf, int flags EXT2FS_ATTR((unused)))
55
0
{
56
0
  return ext2fs_read_dir_block3(fs, block, buf, flags);
57
0
}
58
59
errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
60
         void *buf)
61
0
{
62
0
  return ext2fs_read_dir_block3(fs, block, buf, 0);
63
0
}
64
65
66
errcode_t ext2fs_write_dir_block4(ext2_filsys fs, blk64_t block,
67
          void *inbuf, int flags EXT2FS_ATTR((unused)),
68
          ext2_ino_t ino)
69
0
{
70
0
  errcode_t retval;
71
0
  char    *buf = inbuf;
72
73
#ifdef WORDS_BIGENDIAN
74
  retval = ext2fs_get_mem(fs->blocksize, &buf);
75
  if (retval)
76
    return retval;
77
  memcpy(buf, inbuf, fs->blocksize);
78
  retval = ext2fs_dirent_swab_out(fs, buf, flags);
79
  if (retval)
80
    return retval;
81
#endif
82
0
  retval = ext2fs_dir_block_csum_set(fs, ino,
83
0
             (struct ext2_dir_entry *)buf);
84
0
  if (retval)
85
0
    goto out;
86
87
0
  retval = io_channel_write_blk64(fs->io, block, 1, buf);
88
89
0
out:
90
#ifdef WORDS_BIGENDIAN
91
  ext2fs_free_mem(&buf);
92
#endif
93
0
  return retval;
94
0
}
95
96
errcode_t ext2fs_write_dir_block3(ext2_filsys fs, blk64_t block,
97
          void *inbuf, int flags EXT2FS_ATTR((unused)))
98
0
{
99
0
  return ext2fs_write_dir_block4(fs, block, inbuf, flags, 0);
100
0
}
101
102
errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
103
         void *inbuf, int flags EXT2FS_ATTR((unused)))
104
0
{
105
0
  return ext2fs_write_dir_block3(fs, block, inbuf, flags);
106
0
}
107
108
errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
109
         void *inbuf)
110
0
{
111
0
  return ext2fs_write_dir_block3(fs, block, inbuf, 0);
112
0
}
113