Coverage Report

Created: 2025-11-11 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/libblkid/src/superblocks/zonefs.c
Line
Count
Source
1
/*
2
 * Copyright (C) 2020 Western Digital Corporation or its affiliates.
3
 *
4
 * This file may be redistributed under the terms of the
5
 * GNU Lesser General Public License
6
 */
7
#include <stddef.h>
8
#include <string.h>
9
10
#include "superblocks.h"
11
#include "crc32.h"
12
13
#define ZONEFS_MAGIC    "SFOZ" /* 0x5a4f4653 'Z' 'O' 'F' 'S' */
14
#define ZONEFS_MAGIC_SIZE 4
15
#define ZONEFS_MAGIC_OFST 0
16
#define ZONEFS_UUID_SIZE  16
17
#define ZONEFS_LABEL_SIZE 32
18
66
#define ZONEFS_SB_OFST    0
19
20
2
#define ZONEFS_BLOCK_SIZE 4096U
21
22
/* All in little-endian */
23
struct zonefs_super {
24
25
  /* Magic number */
26
  int32_t   s_magic;
27
28
  /* Checksum */
29
  int32_t   s_crc;
30
31
  /* Volume label */
32
  char    s_label[ZONEFS_LABEL_SIZE];
33
34
  /* 128-bit uuid */
35
  uint8_t   s_uuid[ZONEFS_UUID_SIZE];
36
37
  /* Features */
38
  int64_t   s_features;
39
40
  /* UID/GID to use for files */
41
  int32_t   s_uid;
42
  int32_t   s_gid;
43
44
  /* File permissions */
45
  int32_t   s_perm;
46
47
  /* Padding to 4096 bytes */
48
  uint8_t   s_reserved[4020];
49
50
} __attribute__ ((packed));
51
52
static int zonefs_verify_csum(blkid_probe pr, const struct zonefs_super *sb)
53
66
{
54
66
  uint32_t expected = le32_to_cpu(sb->s_crc);
55
66
  uint32_t crc = ul_crc32_exclude_offset(
56
66
      ~0LL, (unsigned char *) sb, sizeof(*sb),
57
66
           offsetof(__typeof__(*sb), s_crc), sizeof(sb->s_crc), 0);
58
66
  return blkid_probe_verify_csum(pr, crc, expected);
59
66
}
60
61
static int probe_zonefs(blkid_probe pr,
62
    const struct blkid_idmag *mag  __attribute__((__unused__)))
63
66
{
64
66
  const struct zonefs_super *sb;
65
66
66
  sb = (struct zonefs_super *)
67
66
    blkid_probe_get_buffer(pr, ZONEFS_SB_OFST,
68
66
               sizeof(struct zonefs_super));
69
66
  if (!sb)
70
0
    return errno ? -errno : 1;
71
72
66
  if (!zonefs_verify_csum(pr, sb))
73
65
    return 1;
74
75
1
  if (sb->s_label[0])
76
0
    blkid_probe_set_label(pr, (unsigned char *) sb->s_label,
77
0
              sizeof(sb->s_label));
78
79
1
  blkid_probe_set_uuid(pr, sb->s_uuid);
80
1
  blkid_probe_set_fsblocksize(pr, ZONEFS_BLOCK_SIZE);
81
1
  blkid_probe_set_block_size(pr, ZONEFS_BLOCK_SIZE);
82
83
1
  return 0;
84
66
}
85
86
const struct blkid_idinfo zonefs_idinfo =
87
{
88
  .name           = "zonefs",
89
  .usage          = BLKID_USAGE_FILESYSTEM,
90
  .probefunc      = probe_zonefs,
91
  .magics         =
92
        {
93
    {
94
      .magic = (char *)ZONEFS_MAGIC,
95
      .len = ZONEFS_MAGIC_SIZE,
96
      .kboff = ZONEFS_SB_OFST,
97
      .sboff = ZONEFS_MAGIC_OFST,
98
    },
99
    { NULL }
100
  }
101
};