source: mainline/uspace/app/init/untar.c

Last change on this file was 7ae01d5, checked in by Jiri Svoboda <jiri@…>, 14 months ago

Remove unused comm_size parameter of block_init()

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * Copyright (c) 2024 Jiri Svoboda
3 * Copyright (c) 2018 Martin Decky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup init
31 * @{
32 */
33/**
34 * @file
35 */
36
37#include <stdio.h>
38#include <stdbool.h>
39#include <errno.h>
40#include <loc.h>
41#include <untar.h>
42#include <block.h>
43#include "init.h"
44#include "untar.h"
45
46typedef struct {
47 const char *dev;
48
49 service_id_t sid;
50 aoff64_t offset;
51} tar_state_t;
52
53static int bd_tar_open(tar_file_t *tar)
54{
55 tar_state_t *state = (tar_state_t *) tar->data;
56
57 errno_t ret = loc_service_get_id(state->dev, &state->sid,
58 IPC_FLAG_BLOCKING);
59 if (ret != EOK)
60 return ret;
61
62 ret = block_init(state->sid);
63 if (ret != EOK)
64 return ret;
65
66 state->offset = 0;
67 return EOK;
68}
69
70static void bd_tar_close(tar_file_t *tar)
71{
72 tar_state_t *state = (tar_state_t *) tar->data;
73 block_fini(state->sid);
74}
75
76static size_t bd_tar_read(tar_file_t *tar, void *data, size_t size)
77{
78 tar_state_t *state = (tar_state_t *) tar->data;
79
80 if (block_read_bytes_direct(state->sid, state->offset, size,
81 data) != EOK)
82 return 0;
83
84 state->offset += size;
85 return size;
86}
87
88static void bd_tar_vreport(tar_file_t *tar, const char *fmt, va_list args)
89{
90 vprintf(fmt, args);
91}
92
93tar_file_t tar = {
94 .open = bd_tar_open,
95 .close = bd_tar_close,
96
97 .read = bd_tar_read,
98 .vreport = bd_tar_vreport
99};
100
101bool bd_untar(const char *dev)
102{
103 tar_state_t state;
104 state.dev = dev;
105
106 tar.data = (void *) &state;
107 return (untar(&tar) == EOK);
108}
109
110/** @}
111 */
Note: See TracBrowser for help on using the repository browser.