| 52 | } |
| 53 | |
| 54 | static u64 copy_records(int oldfd, int newfd, u64 old_off, u64 limit, |
| 55 | bool keep_delete_chan) |
| 56 | { |
| 57 | u8 buffer[65535]; |
| 58 | |
| 59 | while (old_off < limit) { |
| 60 | size_t reclen; |
| 61 | struct gossip_hdr_and_type hdr; |
| 62 | |
| 63 | old_off += readx(oldfd, &hdr, GOSSIP_HDR_AND_TYPE_SIZE); |
| 64 | |
| 65 | /* We read 2 bytes already */ |
| 66 | reclen = be16_to_cpu(hdr.hdr.len) - 2; |
| 67 | |
| 68 | /* Skip old uuid and deleted records, */ |
| 69 | if (be16_to_cpu(hdr.type) == WIRE_GOSSIP_STORE_UUID |
| 70 | || (be16_to_cpu(hdr.hdr.flags) & GOSSIP_STORE_DELETED_BIT)) { |
| 71 | old_off += skipx(oldfd, reclen); |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | /* Are we supposed to skip deleted markers? */ |
| 76 | if (!keep_delete_chan |
| 77 | && be16_to_cpu(hdr.type) == WIRE_GOSSIP_STORE_DELETE_CHAN) { |
| 78 | old_off += skipx(oldfd, reclen); |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | if (!((be16_to_cpu(hdr.hdr.flags) & GOSSIP_STORE_COMPLETED_BIT))) |
| 83 | errx(1, "Incomplete gossip_store record at %"PRIu64, |
| 84 | old_off - GOSSIP_HDR_AND_TYPE_SIZE); |
| 85 | |
| 86 | old_off += readx(oldfd, buffer, reclen); |
| 87 | |
| 88 | writex(newfd, &hdr, GOSSIP_HDR_AND_TYPE_SIZE); |
| 89 | writex(newfd, buffer, reclen); |
| 90 | } |
| 91 | |
| 92 | return old_off; |
| 93 | } |
| 94 | |
| 95 | int main(int argc, char *argv[]) |
| 96 | { |