Coverage Report

Created: 2026-04-12 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-fs/istream-fs-file.c
Line
Count
Source
1
/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
2
3
#include "lib.h"
4
#include "istream-private.h"
5
#include "fs-api-private.h"
6
#include "istream-fs-file.h"
7
8
struct fs_file_istream {
9
  struct istream_private istream;
10
  struct fs_file *file;
11
};
12
13
static void i_stream_fs_file_close(struct iostream_private *stream,
14
           bool close_parent ATTR_UNUSED)
15
0
{
16
0
  struct fs_file_istream *fstream = (struct fs_file_istream *)stream;
17
18
0
  i_stream_destroy(&fstream->istream.parent);
19
0
  fs_file_deinit(&fstream->file);
20
0
}
21
22
static ssize_t i_stream_fs_file_read(struct istream_private *stream)
23
0
{
24
0
  struct fs_file_istream *fstream = (struct fs_file_istream *)stream;
25
0
  struct istream *input;
26
27
0
  if (fstream->istream.parent == NULL) {
28
0
    input = fs_read_stream(fstream->file,
29
0
      i_stream_get_max_buffer_size(&stream->istream));
30
0
    i_stream_init_parent(stream, input);
31
0
    i_stream_unref(&input);
32
0
  }
33
34
0
  i_stream_seek(stream->parent, stream->parent_start_offset +
35
0
          stream->istream.v_offset);
36
0
  return i_stream_read_copy_from_parent(&stream->istream);
37
0
}
38
39
struct istream *
40
i_stream_create_fs_file(struct fs_file **file, size_t max_buffer_size)
41
0
{
42
0
  struct fs_file_istream *fstream;
43
0
  struct istream *input;
44
45
0
  fstream = i_new(struct fs_file_istream, 1);
46
0
  fstream->file = *file;
47
0
  fstream->istream.iostream.close = i_stream_fs_file_close;
48
0
  fstream->istream.max_buffer_size = max_buffer_size;
49
0
  fstream->istream.read = i_stream_fs_file_read;
50
0
  fstream->istream.stream_size_passthrough = TRUE;
51
52
0
  fstream->istream.istream.blocking =
53
0
    ((*file)->flags & FS_OPEN_FLAG_ASYNC) == 0;
54
0
  fstream->istream.istream.seekable =
55
0
    ((*file)->flags & FS_OPEN_FLAG_SEEKABLE) != 0;
56
57
0
  input = i_stream_create(&fstream->istream, NULL, -1, 0);
58
0
  i_stream_set_name(input, fs_file_path(*file));
59
0
  *file = NULL;
60
0
  return input;
61
0
}