2 * Copyright (c) 2013 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
37 static int cmd_setcheck_core(uint8_t check_algo
, const char *path_str
,
41 cmd_setcheck(const char *check_str
, char **paths
)
43 static const char *checks
[] = HAMMER2_CHECK_STRINGS
;
51 if (isdigit(check_str
[0])) {
52 check_algo
= strtol(check_str
, NULL
, 0);
54 check_algo
= HAMMER2_CHECK_STRINGS_COUNT
;
55 while (--check_algo
>= 0) {
56 if (strcasecmp(check_str
, checks
[check_algo
]) == 0)
59 if (check_algo
< 0 && strcasecmp(check_str
, "default") == 0) {
60 check_algo
= HAMMER2_CHECK_XXHASH64
;
61 check_str
= "xxhash64";
63 if (check_algo
< 0 && strcasecmp(check_str
, "disabled") == 0) {
64 check_algo
= HAMMER2_CHECK_DISABLED
;
65 check_str
= "disabled";
69 "Unknown check code type: %s\n",
77 if (lstat(*paths
, &st
) == 0) {
78 res
= cmd_setcheck_core(
79 HAMMER2_ENC_ALGO(check_algo
),
85 printf("%s: %s\n", *paths
, strerror(errno
));
96 cmd_setcheck_core(uint8_t check_algo
, const char *path_str
, struct stat
*st
)
98 hammer2_ioc_inode_t inode
;
102 fd
= hammer2_ioctl_handle(path_str
);
107 res
= ioctl(fd
, HAMMER2IOC_INODE_GET
, &inode
);
110 "%s: HAMMER2IOC_INODE_GET: error %s\n",
111 path_str
, strerror(errno
));
115 printf("%s\tcheck_algo=0x%02x\n", path_str
, check_algo
);
116 inode
.flags
|= HAMMER2IOC_INODE_FLAG_CHECK
;
117 inode
.ip_data
.meta
.check_algo
= check_algo
;
118 res
= ioctl(fd
, HAMMER2IOC_INODE_SET
, &inode
);
121 "%s: HAMMER2IOC_INODE_SET: error %s\n",
122 path_str
, strerror(errno
));
128 if (RecurseOpt
&& S_ISDIR(st
->st_mode
)) {
133 if ((dir
= fdopendir(fd
)) != NULL
) {
134 while ((den
= readdir(dir
)) != NULL
) {
135 if (strcmp(den
->d_name
, ".") == 0 ||
136 strcmp(den
->d_name
, "..") == 0) {
139 asprintf(&path
, "%s/%s", path_str
, den
->d_name
);
140 if (lstat(path
, st
) == 0)
141 cmd_setcheck_core(check_algo
, path
, st
);