]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - logprint/log_copy.c
libxfs: warn about deprecation of irix, freebsd, darwin
[thirdparty/xfsprogs-dev.git] / logprint / log_copy.c
CommitLineData
873b7c85 1/*
da23017d
NS
2 * Copyright (c) 2004-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
873b7c85 4 *
da23017d
NS
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
873b7c85
GO
7 * published by the Free Software Foundation.
8 *
da23017d
NS
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.
873b7c85 13 *
da23017d
NS
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
873b7c85 17 */
6b803e5a
CH
18#include "libxfs.h"
19#include "libxlog.h"
873b7c85
GO
20
21#include "logprint.h"
22
23/*
24 * Extract a log and write it out to a file
25 */
26
27void
28xfs_log_copy(
999f0b9c 29 struct xlog *log,
873b7c85
GO
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) {
9ee7055c 46 fprintf(stderr, _("%s: read error (%lld): %s\n"),
873b7c85
GO
47 __FUNCTION__, (long long)blkno,
48 strerror(errno));
49 continue;
50 } else if (r == 0) {
9ee7055c 51 printf(_("%s: physical end of log at %lld\n"),
873b7c85
GO
52 __FUNCTION__, (long long)blkno);
53 break;
54 } else if (r != sizeof(buf)) {
9ee7055c 55 fprintf(stderr, _("%s: short read? (%lld)\n"),
873b7c85
GO
56 __FUNCTION__, (long long)blkno);
57 continue;
58 }
59
60 r = write(ofd, buf, sizeof(buf));
61 if (r < 0) {
9ee7055c 62 fprintf(stderr, _("%s: write error (%lld): %s\n"),
873b7c85
GO
63 __FUNCTION__, (long long)blkno,
64 strerror(errno));
65 break;
66 } else if (r != sizeof(buf)) {
9ee7055c 67 fprintf(stderr, _("%s: short write? (%lld)\n"),
873b7c85
GO
68 __FUNCTION__, (long long)blkno);
69 continue;
70 }
71 }
72
73 close(ofd);
74}