xref: /dragonfly/sbin/hammer2/hammer2_subs.h (revision a765cedf)
1 /*
2  * Copyright (c) 2019 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@dragonflybsd.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef HAMMER2_HAMMER2_SUBS_H_
36 #define HAMMER2_HAMMER2_SUBS_H_
37 
38 #include <sys/types.h>
39 #include <uuid.h>
40 
41 #include <vfs/hammer2/hammer2_disk.h>
42 
43 typedef struct hammer2_volume {
44 	int fd;
45 	int id;
46 	char *path;
47 	hammer2_off_t offset;
48 	hammer2_off_t size;
49 } hammer2_volume_t;
50 
51 typedef struct hammer2_ondisk {
52 	int version;
53 	int nvolumes;
54 	hammer2_volume_t volumes[HAMMER2_MAX_VOLUMES];
55 	hammer2_off_t total_size;
56 	hammer2_off_t free_size;
57 	uuid_t fsid;
58 	uuid_t fstype;
59 } hammer2_ondisk_t;
60 
61 /*
62  * Misc functions
63  */
64 int hammer2_ioctl_handle(const char *sel_path);
65 const char *hammer2_time64_to_str(uint64_t htime64, char **strp);
66 const char *hammer2_uuid_to_str(const uuid_t *uuid, char **strp);
67 const char *hammer2_iptype_to_str(uint8_t type);
68 const char *hammer2_pfstype_to_str(uint8_t type);
69 const char *hammer2_pfssubtype_to_str(uint8_t subtype);
70 const char *hammer2_breftype_to_str(uint8_t type);
71 const char *sizetostr(hammer2_off_t size);
72 const char *counttostr(hammer2_off_t size);
73 hammer2_off_t check_volume(int fd);
74 hammer2_key_t dirhash(const char *aname, size_t len);
75 
76 #define hammer2_icrc32(buf, size)	iscsi_crc32((buf), (size))
77 #define hammer2_icrc32c(buf, size, crc)	iscsi_crc32_ext((buf), (size), (crc))
78 uint32_t iscsi_crc32(const void *buf, size_t size);
79 uint32_t iscsi_crc32_ext(const void *buf, size_t size, uint32_t ocrc);
80 
81 char **get_hammer2_mounts(int *acp);
82 void put_hammer2_mounts(int ac, char **av);
83 
84 void hammer2_init_ondisk(hammer2_ondisk_t *fsp);
85 void hammer2_install_volume(hammer2_volume_t *vol, int fd, int id,
86 	const char *path, hammer2_off_t offset, hammer2_off_t size);
87 void hammer2_uninstall_volume(hammer2_volume_t *vol);
88 void hammer2_verify_volumes(hammer2_ondisk_t *fsp,
89 	const hammer2_volume_data_t *rootvoldata);
90 void hammer2_print_volumes(const hammer2_ondisk_t *fsp);
91 void hammer2_init_volumes(const char *blkdevs, int rdonly);
92 void hammer2_cleanup_volumes(void);
93 
94 int hammer2_get_volume_fd(hammer2_off_t offset);
95 int hammer2_get_root_volume_fd(void);
96 int hammer2_get_volume_id(hammer2_off_t offset);
97 int hammer2_get_root_volume_id(void);
98 const char *hammer2_get_volume_path(hammer2_off_t offset);
99 const char *hammer2_get_root_volume_path(void);
100 hammer2_off_t hammer2_get_volume_offset(hammer2_off_t offset);
101 hammer2_off_t hammer2_get_root_volume_offset(void);
102 hammer2_off_t hammer2_get_volume_size(hammer2_off_t offset);
103 hammer2_off_t hammer2_get_root_volume_size(void);
104 
105 hammer2_off_t hammer2_get_total_size(void);
106 hammer2_volume_data_t* hammer2_read_root_volume_header(void);
107 
108 #endif /* !HAMMER2_HAMMER2_SUBS_H_ */
109