source: mainline/uspace/srv/volsrv/empty.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: 3.6 KB
RevLine 
[4b6635a7]1/*
[7ae01d5]2 * Copyright (c) 2024 Jiri Svoboda
[4b6635a7]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup volsrv
30 * @{
31 */
32/**
33 * @file Empty partition handling
34 * @brief
35 */
36
37#include <block.h>
38#include <errno.h>
39#include <io/log.h>
[5772aa1]40#include <label/empty.h>
[4b6635a7]41#include <loc.h>
42#include <stdlib.h>
43
44#include "empty.h"
45
[b7fd2a0]46static errno_t empty_get_bsize(void *, size_t *);
47static errno_t empty_get_nblocks(void *, aoff64_t *);
48static errno_t empty_read(void *, aoff64_t, size_t, void *);
49static errno_t empty_write(void *, aoff64_t, size_t, const void *);
[5772aa1]50
51/** Provide disk access to liblabel */
52static label_bd_ops_t empty_bd_ops = {
53 .get_bsize = empty_get_bsize,
54 .get_nblocks = empty_get_nblocks,
55 .read = empty_read,
56 .write = empty_write
[363a504]57};
58
[b7fd2a0]59errno_t volsrv_part_is_empty(service_id_t sid, bool *rempty)
[4b6635a7]60{
[b7fd2a0]61 errno_t rc;
[5772aa1]62 label_bd_t lbd;
[4b6635a7]63
[7ae01d5]64 rc = block_init(sid);
[4b6635a7]65 if (rc != EOK) {
66 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening "
67 "block device service %zu", sid);
[5772aa1]68 return EIO;
[4b6635a7]69 }
70
[5772aa1]71 lbd.ops = &empty_bd_ops;
72 lbd.arg = (void *)&sid;
[4b6635a7]73
[5772aa1]74 rc = label_bd_is_empty(&lbd, rempty);
[4b6635a7]75
76 block_fini(sid);
77 return rc;
78}
79
[b7fd2a0]80errno_t volsrv_part_empty(service_id_t sid)
[ea0ff6b]81{
[b7fd2a0]82 errno_t rc;
[5772aa1]83 label_bd_t lbd;
[ea0ff6b]84
[7ae01d5]85 rc = block_init(sid);
[ea0ff6b]86 if (rc != EOK) {
87 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening "
88 "block device service %zu", sid);
[5772aa1]89 return EIO;
[ea0ff6b]90 }
91
[5772aa1]92 lbd.ops = &empty_bd_ops;
93 lbd.arg = (void *)&sid;
[ea0ff6b]94
[5772aa1]95 rc = label_bd_empty(&lbd);
[ea0ff6b]96
[5772aa1]97 block_fini(sid);
98 return rc;
99}
[ea0ff6b]100
[5772aa1]101/** Get block size wrapper for liblabel */
[b7fd2a0]102static errno_t empty_get_bsize(void *arg, size_t *bsize)
[5772aa1]103{
104 service_id_t svc_id = *(service_id_t *)arg;
105 return block_get_bsize(svc_id, bsize);
106}
[ea0ff6b]107
[5772aa1]108/** Get number of blocks wrapper for liblabel */
[b7fd2a0]109static errno_t empty_get_nblocks(void *arg, aoff64_t *nblocks)
[5772aa1]110{
111 service_id_t svc_id = *(service_id_t *)arg;
112 return block_get_nblocks(svc_id, nblocks);
113}
[ea0ff6b]114
[5772aa1]115/** Read blocks wrapper for liblabel */
[b7fd2a0]116static errno_t empty_read(void *arg, aoff64_t ba, size_t cnt, void *buf)
[5772aa1]117{
118 service_id_t svc_id = *(service_id_t *)arg;
119 return block_read_direct(svc_id, ba, cnt, buf);
120}
[ea0ff6b]121
[5772aa1]122/** Write blocks wrapper for liblabel */
[b7fd2a0]123static errno_t empty_write(void *arg, aoff64_t ba, size_t cnt, const void *data)
[5772aa1]124{
125 service_id_t svc_id = *(service_id_t *)arg;
126 return block_write_direct(svc_id, ba, cnt, data);
[ea0ff6b]127}
128
[4b6635a7]129/** @}
130 */
Note: See TracBrowser for help on using the repository browser.