]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - logprint/log_copy.c
xfsprogs: Remove trailing blanks on various places
[thirdparty/xfsprogs-dev.git] / logprint / log_copy.c
1 /*
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #include "libxfs.h"
19 #include "libxlog.h"
20
21 #include "logprint.h"
22
23 /*
24 * Extract a log and write it out to a file
25 */
26
27 void
28 xfs_log_copy(
29 struct xlog *log,
30 int fd,
31 char *filename)
32 {
33 int ofd, r;
34 xfs_daddr_t blkno;
35 char buf[XLOG_HEADER_SIZE];
36
37 if ((ofd = open(filename, O_CREAT|O_EXCL|O_RDWR|O_TRUNC, 0666)) == -1) {
38 perror("open");
39 exit(1);
40 }
41
42 xlog_print_lseek(log, fd, 0, SEEK_SET);
43 for (blkno = 0; blkno < log->l_logBBsize; blkno++) {
44 r = read(fd, buf, sizeof(buf));
45 if (r < 0) {
46 fprintf(stderr, _("%s: read error (%lld): %s\n"),
47 __FUNCTION__, (long long)blkno,
48 strerror(errno));
49 continue;
50 } else if (r == 0) {
51 printf(_("%s: physical end of log at %lld\n"),
52 __FUNCTION__, (long long)blkno);
53 break;
54 } else if (r != sizeof(buf)) {
55 fprintf(stderr, _("%s: short read? (%lld)\n"),
56 __FUNCTION__, (long long)blkno);
57 continue;
58 }
59
60 r = write(ofd, buf, sizeof(buf));
61 if (r < 0) {
62 fprintf(stderr, _("%s: write error (%lld): %s\n"),
63 __FUNCTION__, (long long)blkno,
64 strerror(errno));
65 break;
66 } else if (r != sizeof(buf)) {
67 fprintf(stderr, _("%s: short write? (%lld)\n"),
68 __FUNCTION__, (long long)blkno);
69 continue;
70 }
71 }
72
73 close(ofd);
74 }