2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2018 by Delphix. All rights reserved.
22 #include <sys/param.h>
23 #include <sys/types.h>
28 usage(const char *msg
, int exit_value
)
30 (void) fprintf(stderr
, "usage: get_diff file redacted_file\n%s\n", msg
);
35 * This utility compares two files, an original and its redacted counterpart
36 * (in that order). It compares the files 512 bytes at a time, printing out
37 * any ranges (as offset and length) where the redacted file does not match
38 * the original. This output is used to verify that the expected ranges of
39 * a redacted file do not contain the original data.
42 main(int argc
, char *argv
[])
44 off_t diff_off
= 0, diff_len
= 0, off
= 0;
46 char *fname1
, *fname2
;
47 char buf1
[DEV_BSIZE
], buf2
[DEV_BSIZE
];
51 usage("Incorrect number of arguments.", 1);
53 if ((fname1
= argv
[1]) == NULL
)
54 usage("Filename missing.", 1);
55 if ((fd1
= open(fname1
, O_LARGEFILE
| O_RDONLY
)) < 0) {
56 perror("open1 failed");
60 if ((fname2
= argv
[2]) == NULL
)
61 usage("Redacted filename missing.", 1);
62 if ((fd2
= open(fname2
, O_LARGEFILE
| O_RDONLY
)) < 0) {
63 perror("open2 failed");
67 while ((bytes
= pread(fd1
, buf1
, DEV_BSIZE
, off
)) > 0) {
68 if (pread(fd2
, buf2
, DEV_BSIZE
, off
) < 0) {
71 * A read in a redacted section of a file will
72 * fail with EIO. If we get EIO, continue on
73 * but ensure that a comparison of buf1 and
74 * buf2 will fail, indicating a redacted block.
78 perror("pread failed");
82 if (memcmp(buf1
, buf2
, bytes
) == 0) {
84 (void) fprintf(stdout
, "%lld,%lld\n",
85 (long long)diff_off
, (long long)diff_len
);
86 assert(off
== diff_off
+ diff_len
);
93 assert(off
== diff_off
+ diff_len
);
100 (void) fprintf(stdout
, "%lld,%lld\n", (long long)diff_off
,
101 (long long)diff_len
);