Coverage Report

Created: 2026-09-01 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/util-linux/include/all-io.h
Line
Count
Source
1
/*
2
 * No copyright is claimed.  This code is in the public domain; do with
3
 * it what you wish.
4
 *
5
 * Written by Karel Zak <kzak@redhat.com>
6
 *            Petr Uzel <petr.uzel@suse.cz>
7
 */
8
9
#ifndef UTIL_LINUX_ALL_IO_H
10
#define UTIL_LINUX_ALL_IO_H
11
12
#include <string.h>
13
#include <unistd.h>
14
#include <errno.h>
15
#include <sys/types.h>
16
#ifdef HAVE_SYS_SENDFILE_H
17
# include <sys/sendfile.h>
18
#endif
19
20
#include "c.h"
21
#include "timeutils.h"
22
#include "vfs.h"
23
24
static inline int __write_all(const struct ul_vfs_ops *vfs, int fd,
25
            const void *buf, size_t count)
26
3.77k
{
27
7.55k
  while (count) {
28
3.77k
    ssize_t tmp;
29
30
3.77k
    errno = 0;
31
3.77k
    tmp = ul_vfs_write(vfs, fd, buf, count);
32
3.77k
    if (tmp > 0) {
33
3.77k
      count -= tmp;
34
3.77k
      if (count)
35
0
        buf = (const void *) ((const char *) buf + tmp);
36
3.77k
    } else if (errno != EINTR && errno != EAGAIN)
37
0
      return -1;
38
3.77k
    if (errno == EAGAIN)  /* Try later, *sigh* */
39
0
      xusleep(250000);
40
3.77k
  }
41
3.77k
  return 0;
42
3.77k
}
Unexecuted instantiation: last.c:__write_all
Unexecuted instantiation: fileutils.c:__write_all
Unexecuted instantiation: canonicalize.c:__write_all
Unexecuted instantiation: env.c:__write_all
Unexecuted instantiation: path.c:__write_all
Unexecuted instantiation: sysfs.c:__write_all
Unexecuted instantiation: blkdev.c:__write_all
Unexecuted instantiation: probe.c:__write_all
script.c:__write_all
Line
Count
Source
26
3.77k
{
27
7.55k
  while (count) {
28
3.77k
    ssize_t tmp;
29
30
3.77k
    errno = 0;
31
3.77k
    tmp = ul_vfs_write(vfs, fd, buf, count);
32
3.77k
    if (tmp > 0) {
33
3.77k
      count -= tmp;
34
3.77k
      if (count)
35
0
        buf = (const void *) ((const char *) buf + tmp);
36
3.77k
    } else if (errno != EINTR && errno != EAGAIN)
37
0
      return -1;
38
3.77k
    if (errno == EAGAIN)  /* Try later, *sigh* */
39
0
      xusleep(250000);
40
3.77k
  }
41
3.77k
  return 0;
42
3.77k
}
Unexecuted instantiation: sun.c:__write_all
Unexecuted instantiation: sgi.c:__write_all
Unexecuted instantiation: bsd.c:__write_all
Unexecuted instantiation: gpt.c:__write_all
Unexecuted instantiation: gen_uuid.c:__write_all
43
44
3.77k
#define ul_write_all(fd, buf, count)    __write_all(NULL, (fd), (buf), (count))
45
0
#define ul_vfs_write_all(vfs, fd, buf, count) __write_all((vfs), (fd), (buf), (count))
46
47
static inline int ul_fwrite_all(const void *ptr, size_t size,
48
           size_t nmemb, FILE *stream)
49
0
{
50
0
  while (nmemb) {
51
0
    size_t tmp;
52
0
53
0
    errno = 0;
54
0
    tmp = fwrite(ptr, size, nmemb, stream);
55
0
    if (tmp > 0) {
56
0
      nmemb -= tmp;
57
0
      if (nmemb)
58
0
        ptr = (const void *) ((const char *) ptr + (tmp * size));
59
0
    } else if (errno != EINTR && errno != EAGAIN)
60
0
      return -1;
61
0
    if (errno == EAGAIN)  /* Try later, *sigh* */
62
0
      xusleep(250000);
63
0
  }
64
0
  return 0;
65
0
}
Unexecuted instantiation: last.c:ul_fwrite_all
Unexecuted instantiation: fileutils.c:ul_fwrite_all
Unexecuted instantiation: canonicalize.c:ul_fwrite_all
Unexecuted instantiation: env.c:ul_fwrite_all
Unexecuted instantiation: path.c:ul_fwrite_all
Unexecuted instantiation: sysfs.c:ul_fwrite_all
Unexecuted instantiation: blkdev.c:ul_fwrite_all
Unexecuted instantiation: probe.c:ul_fwrite_all
Unexecuted instantiation: script.c:ul_fwrite_all
Unexecuted instantiation: sun.c:ul_fwrite_all
Unexecuted instantiation: sgi.c:ul_fwrite_all
Unexecuted instantiation: bsd.c:ul_fwrite_all
Unexecuted instantiation: gpt.c:ul_fwrite_all
Unexecuted instantiation: gen_uuid.c:ul_fwrite_all
66
67
static inline ssize_t __read_all(const struct ul_vfs_ops *vfs, int fd,
68
         char *buf, size_t count)
69
4.71k
{
70
4.71k
  ssize_t ret;
71
4.71k
  ssize_t c = 0;
72
4.71k
  int tries = 0;
73
74
4.71k
  memset(buf, 0, count);
75
9.42k
  while (count > 0) {
76
8.09k
    ret = ul_vfs_read(vfs, fd, buf, count);
77
8.09k
    if (ret < 0) {
78
0
      if ((errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
79
0
        xusleep(250000);
80
0
        continue;
81
0
      }
82
0
      return c ? c : -1;
83
0
    }
84
8.09k
    if (ret == 0)
85
3.38k
      return c;
86
4.71k
    tries = 0;
87
4.71k
    count -= ret;
88
4.71k
    buf += ret;
89
4.71k
    c += ret;
90
4.71k
  }
91
1.32k
  return c;
92
4.71k
}
Unexecuted instantiation: last.c:__read_all
Unexecuted instantiation: fileutils.c:__read_all
Unexecuted instantiation: canonicalize.c:__read_all
Unexecuted instantiation: env.c:__read_all
Unexecuted instantiation: path.c:__read_all
Unexecuted instantiation: sysfs.c:__read_all
Unexecuted instantiation: blkdev.c:__read_all
Unexecuted instantiation: probe.c:__read_all
Unexecuted instantiation: script.c:__read_all
Unexecuted instantiation: sun.c:__read_all
Unexecuted instantiation: sgi.c:__read_all
bsd.c:__read_all
Line
Count
Source
69
4.71k
{
70
4.71k
  ssize_t ret;
71
4.71k
  ssize_t c = 0;
72
4.71k
  int tries = 0;
73
74
4.71k
  memset(buf, 0, count);
75
9.42k
  while (count > 0) {
76
8.09k
    ret = ul_vfs_read(vfs, fd, buf, count);
77
8.09k
    if (ret < 0) {
78
0
      if ((errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
79
0
        xusleep(250000);
80
0
        continue;
81
0
      }
82
0
      return c ? c : -1;
83
0
    }
84
8.09k
    if (ret == 0)
85
3.38k
      return c;
86
4.71k
    tries = 0;
87
4.71k
    count -= ret;
88
4.71k
    buf += ret;
89
4.71k
    c += ret;
90
4.71k
  }
91
1.32k
  return c;
92
4.71k
}
Unexecuted instantiation: gpt.c:__read_all
Unexecuted instantiation: gen_uuid.c:__read_all
93
94
0
#define ul_read_all(fd, buf, count)   __read_all(NULL, (fd), (buf), (count))
95
4.71k
#define ul_vfs_read_all(vfs, fd, buf, count)  __read_all((vfs), (fd), (buf), (count))
96
97
static inline ssize_t ul_read_all_alloc(int fd, char **buf)
98
0
{
99
0
  size_t size = 1024, c = 0;
100
0
  ssize_t ret;
101
102
0
  *buf = malloc(size);
103
0
  if (!*buf)
104
0
    return -1;
105
106
0
  while (1) {
107
0
    ret = ul_read_all(fd, *buf + c, size - c);
108
0
    if (ret < 0) {
109
0
      free(*buf);
110
0
      *buf = NULL;
111
0
      return -1;
112
0
    }
113
114
0
    if (ret == 0)
115
0
      return c;
116
117
0
    c += ret;
118
0
    if (c == size) {
119
0
      size *= 2;
120
0
      *buf = realloc(*buf, size);
121
0
      if (!*buf)
122
0
        return -1;
123
0
    }
124
0
  }
125
0
}
Unexecuted instantiation: last.c:ul_read_all_alloc
Unexecuted instantiation: fileutils.c:ul_read_all_alloc
Unexecuted instantiation: canonicalize.c:ul_read_all_alloc
Unexecuted instantiation: env.c:ul_read_all_alloc
Unexecuted instantiation: path.c:ul_read_all_alloc
Unexecuted instantiation: sysfs.c:ul_read_all_alloc
Unexecuted instantiation: blkdev.c:ul_read_all_alloc
Unexecuted instantiation: probe.c:ul_read_all_alloc
Unexecuted instantiation: script.c:ul_read_all_alloc
Unexecuted instantiation: sun.c:ul_read_all_alloc
Unexecuted instantiation: sgi.c:ul_read_all_alloc
Unexecuted instantiation: bsd.c:ul_read_all_alloc
Unexecuted instantiation: gpt.c:ul_read_all_alloc
Unexecuted instantiation: gen_uuid.c:ul_read_all_alloc
126
127
static inline ssize_t ul_sendfile_all(int out __attribute__((__unused__)),
128
           int in __attribute__((__unused__)),
129
           off_t *off __attribute__((__unused__)),
130
           size_t count __attribute__((__unused__)))
131
0
{
132
0
#if defined(HAVE_SENDFILE) && defined(__linux__)
133
0
  ssize_t ret;
134
0
  ssize_t c = 0;
135
0
  int tries = 0;
136
0
  while (count) {
137
0
    ret = sendfile(out, in, off, count);
138
0
    if (ret < 0) {
139
0
      if ((errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
140
0
        xusleep(250000);
141
0
        continue;
142
0
      }
143
0
      return c ? c : -1;
144
0
    }
145
0
    if (ret == 0)
146
0
      return c;
147
0
    tries = 0;
148
0
    count -= ret;
149
0
    c += ret;
150
0
  }
151
0
  return c;
152
#else
153
  errno = ENOSYS;
154
  return -1;
155
#endif
156
0
}
Unexecuted instantiation: last.c:ul_sendfile_all
Unexecuted instantiation: fileutils.c:ul_sendfile_all
Unexecuted instantiation: canonicalize.c:ul_sendfile_all
Unexecuted instantiation: env.c:ul_sendfile_all
Unexecuted instantiation: path.c:ul_sendfile_all
Unexecuted instantiation: sysfs.c:ul_sendfile_all
Unexecuted instantiation: blkdev.c:ul_sendfile_all
Unexecuted instantiation: probe.c:ul_sendfile_all
Unexecuted instantiation: script.c:ul_sendfile_all
Unexecuted instantiation: sun.c:ul_sendfile_all
Unexecuted instantiation: sgi.c:ul_sendfile_all
Unexecuted instantiation: bsd.c:ul_sendfile_all
Unexecuted instantiation: gpt.c:ul_sendfile_all
Unexecuted instantiation: gen_uuid.c:ul_sendfile_all
157
#endif /* UTIL_LINUX_ALL_IO_H */