Coverage Report

Created: 2026-09-04 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/e2fsprogs/lib/ext2fs/valid_blk.c
Line
Count
Source
1
/*
2
 * valid_blk.c --- does the inode have valid blocks?
3
 *
4
 * Copyright 1997 by 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
/*
24
 * This function returns 1 if the inode's block entries actually
25
 * contain block entries.
26
 */
27
int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode)
28
0
{
29
  /*
30
   * Only directories, regular files, and some symbolic links
31
   * have valid block entries.
32
   */
33
0
  if (!LINUX_S_ISDIR(inode->i_mode) && !LINUX_S_ISREG(inode->i_mode) &&
34
0
      !LINUX_S_ISLNK(inode->i_mode))
35
0
    return 0;
36
37
  /*
38
   * If the symbolic link is a "fast symlink", then the symlink
39
   * target is stored in the block entries.
40
   */
41
0
  if (LINUX_S_ISLNK (inode->i_mode)) {
42
0
    if (ext2fs_file_acl_block(fs, inode) == 0) {
43
      /* With no EA block, we can rely on i_blocks */
44
0
      if (inode->i_blocks == 0)
45
0
        return 0;
46
0
      return !ext2fs_is_fast_symlink(inode);
47
0
    } else {
48
      /* With an EA block, life gets more tricky */
49
0
      if (inode->i_size >= EXT2_N_BLOCKS*4)
50
0
        return 1; /* definitely using i_block[] */
51
0
      if (inode->i_size > 4 && inode->i_block[1] == 0)
52
0
        return 1; /* definitely using i_block[] */
53
0
      return 0; /* Probably a fast symlink */
54
0
    }
55
0
  }
56
57
  /*
58
   * If this inode has inline data, it shouldn't have valid block
59
   * entries.
60
   */
61
0
  if (inode->i_flags & EXT4_INLINE_DATA_FL)
62
0
    return 0;
63
0
  return 1;
64
0
}
65
66
int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode)
67
0
{
68
  return ext2fs_inode_has_valid_blocks2(NULL, inode);
69
0
}