-
Notifications
You must be signed in to change notification settings - Fork 8
/
shfs_tools.h
111 lines (102 loc) · 3.77 KB
/
shfs_tools.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* MicroShell Tools for Simple hash filesystem (SHFS)
*
* Authors: Simon Kuenzer <[email protected]>
*
*
* Copyright (c) 2013-2017, NEC Europe Ltd., NEC Corporation All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef _SHFS_TOOLS_H_
#define _SHFS_TOOLS_H_
#include "shfs_defs.h"
#ifdef HAVE_CTLDIR
#include <target/ctldir.h>
#endif
/**
* Registers shfs tools to micro shell + ctldir (if *cd is not NULL)
*/
#ifdef HAVE_CTLDIR
int register_shfs_tools(struct ctldir *cd);
#else
int register_shfs_tools(void);
#endif
/**
* Prints an uuid/hash number to a buffer
* Note: The target buffer for the UUID has to be at least 37 bytes long
* Note: The target buffer for the hash has to be at least ((2 * hlen) + 1) bytes long
*/
#ifdef __MINIOS__
void uuid_unparse(const uuid_t uu, char *out);
int shfs_prefetch_bgnd(unsigned int delay_ms);
#endif
void hash_unparse(const hash512_t h, uint8_t hlen, char *out);
size_t strftimestamp_s(char *s, size_t slen, const char *fmt, uint64_t ts_sec);
size_t strshfshost(char *s, size_t slen, struct shfs_host *h);
#ifdef HAVE_LWIP
#include <lwip/err.h>
#include <lwip/ip_addr.h>
#include <lwip/dns.h>
#if LWIP_DNS
static inline int shfshost2ipaddr(const struct shfs_host *h, ip_addr_t *out, dns_found_callback dns_cb, void *dns_cb_argp)
#else
static inline int shfshost2ipaddr(const struct shfs_host *h, ip_addr_t *out)
#endif
{
err_t err;
char hname[sizeof(h->name) + 1];
switch(h->type) {
#if !(defined LWIP_IPV4) || LWIP_IPV4
case SHFS_HOST_TYPE_IPV4:
IP4_ADDR(out, h->addr[0], h->addr[1], h->addr[2], h->addr[3]);
return 0;
#endif
#if LWIP_IPV6
case SHFS_HOST_TYPE_IPV6:
IP6_ADDR(out, h->addr[0], h->addr[1], h->addr[2], h->addr[3],
h->addr[4], h->addr[5], h->addr[6], h->addr[7]);
return 0;
#endif
#if LWIP_DNS
case SHFS_HOST_TYPE_NAME:
/* FIXME: remove this workaround for null-terminating hostname in SHFS field */
strncpy(hname, h->name, sizeof(h->name));
hname[sizeof(hname) - 1] = '\0';
err = dns_gethostbyname(h->name, out, dns_cb, dns_cb_argp);
if (err == ERR_OK)
return 0; /* hostname found in local table */
if (err == ERR_INPROGRESS)
return 1; /* query sent, callback will be called on answer */
return -EINVAL; /* general error */
#endif
default:
return -ENOTSUP;
}
}
#endif /* HAVE_LWIP */
#endif /* _SHFS_TOOLS_H_ */