source: mainline/uspace/lib/fmgt/src/verify.c@ 1ec732a

Last change on this file since 1ec732a was 1ec732a, checked in by Jiri Svoboda <jiri@…>, 3 weeks ago

Verify file - navigator operation and command-line utility.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2025 Jiri Svoboda
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 fmgt
30 * @{
31 */
32/** @file Verify files.
33 */
34
35//#include <dirent.h>
36#include <errno.h>
37#include <stdbool.h>
38//#include <stdio.h>
39#include <stdlib.h>
40//#include <stddef.h>
41//#include <str.h>
42#include <vfs/vfs.h>
43//#include <dirent.h>
44
45#include "fmgt.h"
46#include "fmgt/walk.h"
47#include "../private/fmgt.h"
48
49static errno_t fmgt_verify_file(void *, const char *);
50
51static fmgt_walk_cb_t fmgt_verify_cb = {
52 .file = fmgt_verify_file
53};
54
55static errno_t fmgt_verify_file(void *arg, const char *fname)
56{
57 fmgt_t *fmgt = (fmgt_t *)arg;
58 int fd;
59 size_t nr;
60 aoff64_t pos = 0;
61 char *buffer;
62 fmgt_io_error_t err;
63 fmgt_error_action_t action;
64 errno_t rc;
65
66 buffer = calloc(BUFFER_SIZE, 1);
67 if (buffer == NULL)
68 return ENOMEM;
69
70 rc = vfs_lookup_open(fname, WALK_REGULAR, MODE_READ, &fd);
71 if (rc != EOK) {
72 free(buffer);
73 return rc;
74 }
75
76 fmgt_progress_init_file(fmgt, fname);
77
78 do {
79 do {
80 rc = vfs_read(fd, &pos, buffer, BUFFER_SIZE, &nr);
81 if (rc == EOK)
82 break;
83
84 /* I/O error */
85 err.fname = fname;
86 err.optype = fmgt_io_read;
87 err.rc = rc;
88 fmgt_timer_stop(fmgt);
89 action = fmgt_io_error_query(fmgt, &err);
90 fmgt_timer_start(fmgt);
91 } while (action == fmgt_er_retry);
92
93 /* Not recovered? */
94 if (rc != EOK) {
95 free(buffer);
96 vfs_put(fd);
97 return rc;
98 }
99
100 fmgt_progress_incr_bytes(fmgt, nr);
101
102 /* User requested abort? */
103 if (fmgt_abort_query(fmgt)) {
104 free(buffer);
105 vfs_put(fd);
106 return EINTR;
107 }
108 } while (nr > 0);
109
110 free(buffer);
111 vfs_put(fd);
112 fmgt_progress_incr_files(fmgt);
113 return EOK;
114}
115
116/** Verify files.
117 *
118 * @param fmgt File management object
119 * @param flist File list
120 * @return EOK on success or an error code
121 */
122errno_t fmgt_verify(fmgt_t *fmgt, fmgt_flist_t *flist)
123{
124 fmgt_walk_params_t params;
125 errno_t rc;
126
127 fmgt_walk_params_init(&params);
128
129 params.flist = flist;
130 params.cb = &fmgt_verify_cb;
131 params.arg = (void *)fmgt;
132
133 fmgt_progress_init(fmgt);
134
135 fmgt_timer_start(fmgt);
136 fmgt_initial_progress_update(fmgt);
137 rc = fmgt_walk(&params);
138 fmgt_final_progress_update(fmgt);
139 return rc;
140}
141
142/** @}
143 */
Note: See TracBrowser for help on using the repository browser.