| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * block.c --- iterate over all blocks in an inode |
| 3 | * |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 4 | * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. |
| 5 | * |
| 6 | * %Begin-Header% |
| 7 | * This file may be redistributed under the terms of the GNU Public |
| 8 | * License. |
| 9 | * %End-Header% |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <string.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 14 | #if HAVE_UNISTD_H |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 15 | #include <unistd.h> |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 16 | #endif |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 17 | |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 18 | #include "ext2_fs.h" |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 19 | #include "ext2fs.h" |
| 20 | |
| 21 | struct block_context { |
| 22 | ext2_filsys fs; |
| 23 | int (*func)(ext2_filsys fs, |
| 24 | blk_t *blocknr, |
| Theodore Ts'o | 03673db | 1998-06-10 20:39:43 +0000 | [diff] [blame] | 25 | e2_blkcnt_t bcount, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 26 | blk_t ref_blk, |
| 27 | int ref_offset, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 28 | void *priv_data); |
| Theodore Ts'o | 03673db | 1998-06-10 20:39:43 +0000 | [diff] [blame] | 29 | e2_blkcnt_t bcount; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 30 | int bsize; |
| 31 | int flags; |
| 32 | errcode_t errcode; |
| 33 | char *ind_buf; |
| 34 | char *dind_buf; |
| 35 | char *tind_buf; |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 36 | void *priv_data; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 39 | static int block_iterate_ind(blk_t *ind_block, blk_t ref_block, |
| 40 | int ref_offset, struct block_context *ctx) |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 41 | { |
| 42 | int ret = 0, changed = 0; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 43 | int i, flags, limit, offset; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 44 | blk_t *block_nr; |
| 45 | |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 46 | limit = ctx->fs->blocksize >> 2; |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 47 | if (!(ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && |
| 48 | !(ctx->flags & BLOCK_FLAG_DATA_ONLY)) |
| 49 | ret = (*ctx->func)(ctx->fs, ind_block, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 50 | BLOCK_COUNT_IND, ref_block, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 51 | ref_offset, ctx->priv_data); |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 52 | if (!*ind_block || (ret & BLOCK_ABORT)) { |
| 53 | ctx->bcount += limit; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 54 | return ret; |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 55 | } |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 56 | if (*ind_block >= ctx->fs->super->s_blocks_count || |
| 57 | *ind_block < ctx->fs->super->s_first_data_block) { |
| 58 | ctx->errcode = EXT2_ET_BAD_IND_BLOCK; |
| 59 | ret |= BLOCK_ERROR; |
| 60 | return ret; |
| 61 | } |
| Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 62 | if (ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) { |
| 63 | ctx->errcode = 0; |
| 64 | memset(ctx->ind_buf, 0, ctx->fs->blocksize); |
| 65 | } else |
| 66 | ctx->errcode = io_channel_read_blk(ctx->fs->io, *ind_block, |
| 67 | 1, ctx->ind_buf); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 68 | if (ctx->errcode) { |
| 69 | ret |= BLOCK_ERROR; |
| 70 | return ret; |
| 71 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 72 | #ifdef EXT2FS_ENABLE_SWAPFS |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 73 | if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES | |
| 74 | EXT2_FLAG_SWAP_BYTES_READ)) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 75 | block_nr = (blk_t *) ctx->ind_buf; |
| 76 | for (i = 0; i < limit; i++, block_nr++) |
| 77 | *block_nr = ext2fs_swab32(*block_nr); |
| 78 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 79 | #endif |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 80 | block_nr = (blk_t *) ctx->ind_buf; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 81 | offset = 0; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 82 | if (ctx->flags & BLOCK_FLAG_APPEND) { |
| 83 | for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) { |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 84 | flags = (*ctx->func)(ctx->fs, block_nr, ctx->bcount, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 85 | *ind_block, offset, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 86 | ctx->priv_data); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 87 | changed |= flags; |
| 88 | if (flags & BLOCK_ABORT) { |
| 89 | ret |= BLOCK_ABORT; |
| 90 | break; |
| 91 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 92 | offset += sizeof(blk_t); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 93 | } |
| 94 | } else { |
| 95 | for (i = 0; i < limit; i++, ctx->bcount++, block_nr++) { |
| 96 | if (*block_nr == 0) |
| 97 | continue; |
| 98 | flags = (*ctx->func)(ctx->fs, block_nr, ctx->bcount, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 99 | *ind_block, offset, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 100 | ctx->priv_data); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 101 | changed |= flags; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 102 | if (flags & BLOCK_ABORT) { |
| 103 | ret |= BLOCK_ABORT; |
| 104 | break; |
| 105 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 106 | offset += sizeof(blk_t); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
| Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 109 | if (!(ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) && |
| 110 | (changed & BLOCK_CHANGED)) { |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 111 | #ifdef EXT2FS_ENABLE_SWAPFS |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 112 | if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES | |
| 113 | EXT2_FLAG_SWAP_BYTES_WRITE)) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 114 | block_nr = (blk_t *) ctx->ind_buf; |
| 115 | for (i = 0; i < limit; i++, block_nr++) |
| 116 | *block_nr = ext2fs_swab32(*block_nr); |
| 117 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 118 | #endif |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 119 | ctx->errcode = io_channel_write_blk(ctx->fs->io, *ind_block, |
| 120 | 1, ctx->ind_buf); |
| 121 | if (ctx->errcode) |
| 122 | ret |= BLOCK_ERROR | BLOCK_ABORT; |
| 123 | } |
| 124 | if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 125 | !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 126 | !(ret & BLOCK_ABORT)) |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 127 | ret |= (*ctx->func)(ctx->fs, ind_block, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 128 | BLOCK_COUNT_IND, ref_block, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 129 | ref_offset, ctx->priv_data); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 130 | return ret; |
| 131 | } |
| 132 | |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 133 | static int block_iterate_dind(blk_t *dind_block, blk_t ref_block, |
| 134 | int ref_offset, struct block_context *ctx) |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 135 | { |
| 136 | int ret = 0, changed = 0; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 137 | int i, flags, limit, offset; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 138 | blk_t *block_nr; |
| 139 | |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 140 | limit = ctx->fs->blocksize >> 2; |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 141 | if (!(ctx->flags & (BLOCK_FLAG_DEPTH_TRAVERSE | |
| 142 | BLOCK_FLAG_DATA_ONLY))) |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 143 | ret = (*ctx->func)(ctx->fs, dind_block, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 144 | BLOCK_COUNT_DIND, ref_block, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 145 | ref_offset, ctx->priv_data); |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 146 | if (!*dind_block || (ret & BLOCK_ABORT)) { |
| 147 | ctx->bcount += limit*limit; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 148 | return ret; |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 149 | } |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 150 | if (*dind_block >= ctx->fs->super->s_blocks_count || |
| 151 | *dind_block < ctx->fs->super->s_first_data_block) { |
| 152 | ctx->errcode = EXT2_ET_BAD_DIND_BLOCK; |
| 153 | ret |= BLOCK_ERROR; |
| 154 | return ret; |
| 155 | } |
| Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 156 | if (ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) { |
| 157 | ctx->errcode = 0; |
| 158 | memset(ctx->dind_buf, 0, ctx->fs->blocksize); |
| 159 | } else |
| 160 | ctx->errcode = io_channel_read_blk(ctx->fs->io, *dind_block, |
| 161 | 1, ctx->dind_buf); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 162 | if (ctx->errcode) { |
| 163 | ret |= BLOCK_ERROR; |
| 164 | return ret; |
| 165 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 166 | #ifdef EXT2FS_ENABLE_SWAPFS |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 167 | if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES | |
| 168 | EXT2_FLAG_SWAP_BYTES_READ)) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 169 | block_nr = (blk_t *) ctx->dind_buf; |
| 170 | for (i = 0; i < limit; i++, block_nr++) |
| 171 | *block_nr = ext2fs_swab32(*block_nr); |
| 172 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 173 | #endif |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 174 | block_nr = (blk_t *) ctx->dind_buf; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 175 | offset = 0; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 176 | if (ctx->flags & BLOCK_FLAG_APPEND) { |
| 177 | for (i = 0; i < limit; i++, block_nr++) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 178 | flags = block_iterate_ind(block_nr, |
| 179 | *dind_block, offset, |
| 180 | ctx); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 181 | changed |= flags; |
| 182 | if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { |
| 183 | ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); |
| 184 | break; |
| 185 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 186 | offset += sizeof(blk_t); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 187 | } |
| 188 | } else { |
| 189 | for (i = 0; i < limit; i++, block_nr++) { |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 190 | if (*block_nr == 0) { |
| 191 | ctx->bcount += limit; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 192 | continue; |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 193 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 194 | flags = block_iterate_ind(block_nr, |
| 195 | *dind_block, offset, |
| 196 | ctx); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 197 | changed |= flags; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 198 | if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { |
| 199 | ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); |
| 200 | break; |
| 201 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 202 | offset += sizeof(blk_t); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 203 | } |
| 204 | } |
| Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 205 | if (!(ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) && |
| 206 | (changed & BLOCK_CHANGED)) { |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 207 | #ifdef EXT2FS_ENABLE_SWAPFS |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 208 | if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES | |
| 209 | EXT2_FLAG_SWAP_BYTES_WRITE)) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 210 | block_nr = (blk_t *) ctx->dind_buf; |
| 211 | for (i = 0; i < limit; i++, block_nr++) |
| 212 | *block_nr = ext2fs_swab32(*block_nr); |
| 213 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 214 | #endif |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 215 | ctx->errcode = io_channel_write_blk(ctx->fs->io, *dind_block, |
| 216 | 1, ctx->dind_buf); |
| 217 | if (ctx->errcode) |
| 218 | ret |= BLOCK_ERROR | BLOCK_ABORT; |
| 219 | } |
| 220 | if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 221 | !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 222 | !(ret & BLOCK_ABORT)) |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 223 | ret |= (*ctx->func)(ctx->fs, dind_block, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 224 | BLOCK_COUNT_DIND, ref_block, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 225 | ref_offset, ctx->priv_data); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 226 | return ret; |
| 227 | } |
| 228 | |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 229 | static int block_iterate_tind(blk_t *tind_block, blk_t ref_block, |
| 230 | int ref_offset, struct block_context *ctx) |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 231 | { |
| 232 | int ret = 0, changed = 0; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 233 | int i, flags, limit, offset; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 234 | blk_t *block_nr; |
| 235 | |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 236 | limit = ctx->fs->blocksize >> 2; |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 237 | if (!(ctx->flags & (BLOCK_FLAG_DEPTH_TRAVERSE | |
| 238 | BLOCK_FLAG_DATA_ONLY))) |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 239 | ret = (*ctx->func)(ctx->fs, tind_block, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 240 | BLOCK_COUNT_TIND, ref_block, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 241 | ref_offset, ctx->priv_data); |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 242 | if (!*tind_block || (ret & BLOCK_ABORT)) { |
| 243 | ctx->bcount += limit*limit*limit; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 244 | return ret; |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 245 | } |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 246 | if (*tind_block >= ctx->fs->super->s_blocks_count || |
| 247 | *tind_block < ctx->fs->super->s_first_data_block) { |
| 248 | ctx->errcode = EXT2_ET_BAD_TIND_BLOCK; |
| 249 | ret |= BLOCK_ERROR; |
| 250 | return ret; |
| 251 | } |
| Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 252 | if (ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) { |
| 253 | ctx->errcode = 0; |
| 254 | memset(ctx->tind_buf, 0, ctx->fs->blocksize); |
| 255 | } else |
| 256 | ctx->errcode = io_channel_read_blk(ctx->fs->io, *tind_block, |
| 257 | 1, ctx->tind_buf); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 258 | if (ctx->errcode) { |
| 259 | ret |= BLOCK_ERROR; |
| 260 | return ret; |
| 261 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 262 | #ifdef EXT2FS_ENABLE_SWAPFS |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 263 | if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES | |
| 264 | EXT2_FLAG_SWAP_BYTES_READ)) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 265 | block_nr = (blk_t *) ctx->tind_buf; |
| 266 | for (i = 0; i < limit; i++, block_nr++) |
| 267 | *block_nr = ext2fs_swab32(*block_nr); |
| 268 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 269 | #endif |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 270 | block_nr = (blk_t *) ctx->tind_buf; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 271 | offset = 0; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 272 | if (ctx->flags & BLOCK_FLAG_APPEND) { |
| 273 | for (i = 0; i < limit; i++, block_nr++) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 274 | flags = block_iterate_dind(block_nr, |
| 275 | *tind_block, |
| 276 | offset, ctx); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 277 | changed |= flags; |
| 278 | if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { |
| 279 | ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); |
| 280 | break; |
| 281 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 282 | offset += sizeof(blk_t); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 283 | } |
| 284 | } else { |
| 285 | for (i = 0; i < limit; i++, block_nr++) { |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 286 | if (*block_nr == 0) { |
| 287 | ctx->bcount += limit*limit; |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 288 | continue; |
| Theodore Ts'o | a29f4d3 | 1997-04-29 21:26:48 +0000 | [diff] [blame] | 289 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 290 | flags = block_iterate_dind(block_nr, |
| 291 | *tind_block, |
| 292 | offset, ctx); |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 293 | changed |= flags; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 294 | if (flags & (BLOCK_ABORT | BLOCK_ERROR)) { |
| 295 | ret |= flags & (BLOCK_ABORT | BLOCK_ERROR); |
| 296 | break; |
| 297 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 298 | offset += sizeof(blk_t); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 299 | } |
| 300 | } |
| Theodore Ts'o | a78926e | 2001-05-03 04:02:29 +0000 | [diff] [blame] | 301 | if (!(ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) && |
| 302 | (changed & BLOCK_CHANGED)) { |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 303 | #ifdef EXT2FS_ENABLE_SWAPFS |
| Theodore Ts'o | 06af47f | 2000-04-03 13:51:00 +0000 | [diff] [blame] | 304 | if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES | |
| 305 | EXT2_FLAG_SWAP_BYTES_WRITE)) { |
| Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 306 | block_nr = (blk_t *) ctx->tind_buf; |
| 307 | for (i = 0; i < limit; i++, block_nr++) |
| 308 | *block_nr = ext2fs_swab32(*block_nr); |
| 309 | } |
| Theodore Ts'o | 5df55d7 | 2001-06-11 07:00:04 +0000 | [diff] [blame] | 310 | #endif |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 311 | ctx->errcode = io_channel_write_blk(ctx->fs->io, *tind_block, |
| 312 | 1, ctx->tind_buf); |
| 313 | if (ctx->errcode) |
| 314 | ret |= BLOCK_ERROR | BLOCK_ABORT; |
| 315 | } |
| 316 | if ((ctx->flags & BLOCK_FLAG_DEPTH_TRAVERSE) && |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 317 | !(ctx->flags & BLOCK_FLAG_DATA_ONLY) && |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 318 | !(ret & BLOCK_ABORT)) |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 319 | ret |= (*ctx->func)(ctx->fs, tind_block, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 320 | BLOCK_COUNT_TIND, ref_block, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 321 | ref_offset, ctx->priv_data); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 322 | |
| 323 | return ret; |
| 324 | } |
| 325 | |
| Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 326 | errcode_t ext2fs_block_iterate2(ext2_filsys fs, |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 327 | ext2_ino_t ino, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 328 | int flags, |
| 329 | char *block_buf, |
| 330 | int (*func)(ext2_filsys fs, |
| 331 | blk_t *blocknr, |
| Theodore Ts'o | 03673db | 1998-06-10 20:39:43 +0000 | [diff] [blame] | 332 | e2_blkcnt_t blockcnt, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 333 | blk_t ref_blk, |
| 334 | int ref_offset, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 335 | void *priv_data), |
| 336 | void *priv_data) |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 337 | { |
| 338 | int i; |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 339 | int got_inode = 0; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 340 | int ret = 0; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 341 | blk_t blocks[EXT2_N_BLOCKS]; /* directory data blocks */ |
| 342 | struct ext2_inode inode; |
| 343 | errcode_t retval; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 344 | struct block_context ctx; |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 345 | int limit; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 346 | |
| Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 347 | EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); |
| 348 | |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 349 | /* |
| 350 | * Check to see if we need to limit large files |
| 351 | */ |
| 352 | if (flags & BLOCK_FLAG_NO_LARGE) { |
| 353 | ctx.errcode = ext2fs_read_inode(fs, ino, &inode); |
| 354 | if (ctx.errcode) |
| Theodore Ts'o | 2eb374c | 1998-09-03 01:22:57 +0000 | [diff] [blame] | 355 | return ctx.errcode; |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 356 | got_inode = 1; |
| 357 | if (!LINUX_S_ISDIR(inode.i_mode) && |
| 358 | (inode.i_size_high != 0)) |
| 359 | return EXT2_ET_FILE_TOO_BIG; |
| 360 | } |
| 361 | |
| Theodore Ts'o | 4cbe8af | 1997-08-10 23:07:40 +0000 | [diff] [blame] | 362 | retval = ext2fs_get_blocks(fs, ino, blocks); |
| 363 | if (retval) |
| 364 | return retval; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 365 | |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 366 | limit = fs->blocksize >> 2; |
| 367 | |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 368 | ctx.fs = fs; |
| 369 | ctx.func = func; |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 370 | ctx.priv_data = priv_data; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 371 | ctx.flags = flags; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 372 | ctx.bcount = 0; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 373 | if (block_buf) { |
| 374 | ctx.ind_buf = block_buf; |
| 375 | } else { |
| Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 376 | retval = ext2fs_get_mem(fs->blocksize * 3, &ctx.ind_buf); |
| Theodore Ts'o | 7b4e453 | 1997-10-26 03:41:24 +0000 | [diff] [blame] | 377 | if (retval) |
| 378 | return retval; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 379 | } |
| 380 | ctx.dind_buf = ctx.ind_buf + fs->blocksize; |
| 381 | ctx.tind_buf = ctx.dind_buf + fs->blocksize; |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 382 | |
| 383 | /* |
| 384 | * Iterate over the HURD translator block (if present) |
| 385 | */ |
| 386 | if ((fs->super->s_creator_os == EXT2_OS_HURD) && |
| Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 387 | !(flags & BLOCK_FLAG_DATA_ONLY)) { |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 388 | ctx.errcode = ext2fs_read_inode(fs, ino, &inode); |
| 389 | if (ctx.errcode) |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 390 | goto abort_exit; |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 391 | got_inode = 1; |
| Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 392 | if (inode.osd1.hurd1.h_i_translator) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 393 | ret |= (*ctx.func)(fs, |
| 394 | &inode.osd1.hurd1.h_i_translator, |
| 395 | BLOCK_COUNT_TRANSLATOR, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 396 | 0, 0, priv_data); |
| Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 397 | if (ret & BLOCK_ABORT) |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 398 | goto abort_exit; |
| Theodore Ts'o | 5c57647 | 1997-04-29 15:29:49 +0000 | [diff] [blame] | 399 | } |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 400 | } |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 401 | |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 402 | /* |
| 403 | * Iterate over normal data blocks |
| 404 | */ |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 405 | for (i = 0; i < EXT2_NDIR_BLOCKS ; i++, ctx.bcount++) { |
| 406 | if (blocks[i] || (flags & BLOCK_FLAG_APPEND)) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 407 | ret |= (*ctx.func)(fs, &blocks[i], |
| Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 408 | ctx.bcount, 0, i, priv_data); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 409 | if (ret & BLOCK_ABORT) |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 410 | goto abort_exit; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | if (*(blocks + EXT2_IND_BLOCK) || (flags & BLOCK_FLAG_APPEND)) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 414 | ret |= block_iterate_ind(blocks + EXT2_IND_BLOCK, |
| Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 415 | 0, EXT2_IND_BLOCK, &ctx); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 416 | if (ret & BLOCK_ABORT) |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 417 | goto abort_exit; |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 418 | } else |
| 419 | ctx.bcount += limit; |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 420 | if (*(blocks + EXT2_DIND_BLOCK) || (flags & BLOCK_FLAG_APPEND)) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 421 | ret |= block_iterate_dind(blocks + EXT2_DIND_BLOCK, |
| Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 422 | 0, EXT2_DIND_BLOCK, &ctx); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 423 | if (ret & BLOCK_ABORT) |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 424 | goto abort_exit; |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 425 | } else |
| 426 | ctx.bcount += limit * limit; |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 427 | if (*(blocks + EXT2_TIND_BLOCK) || (flags & BLOCK_FLAG_APPEND)) { |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 428 | ret |= block_iterate_tind(blocks + EXT2_TIND_BLOCK, |
| Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 429 | 0, EXT2_TIND_BLOCK, &ctx); |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 430 | if (ret & BLOCK_ABORT) |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 431 | goto abort_exit; |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 432 | } |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 433 | |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 434 | abort_exit: |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 435 | if (ret & BLOCK_CHANGED) { |
| Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 436 | if (!got_inode) { |
| 437 | retval = ext2fs_read_inode(fs, ino, &inode); |
| 438 | if (retval) |
| 439 | return retval; |
| 440 | } |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 441 | for (i=0; i < EXT2_N_BLOCKS; i++) |
| 442 | inode.i_block[i] = blocks[i]; |
| 443 | retval = ext2fs_write_inode(fs, ino, &inode); |
| 444 | if (retval) |
| 445 | return retval; |
| 446 | } |
| 447 | |
| 448 | if (!block_buf) |
| Theodore Ts'o | c4e3d3f | 2003-08-01 09:41:07 -0400 | [diff] [blame] | 449 | ext2fs_free_mem(&ctx.ind_buf); |
| Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 450 | |
| 451 | return (ret & BLOCK_ERROR) ? ctx.errcode : 0; |
| 452 | } |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 453 | |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 454 | /* |
| 455 | * Emulate the old ext2fs_block_iterate function! |
| 456 | */ |
| 457 | |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 458 | struct xlate { |
| 459 | int (*func)(ext2_filsys fs, |
| 460 | blk_t *blocknr, |
| 461 | int bcount, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 462 | void *priv_data); |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 463 | void *real_private; |
| 464 | }; |
| 465 | |
| Theodore Ts'o | 3cb6c50 | 1997-08-11 20:29:22 +0000 | [diff] [blame] | 466 | #ifdef __TURBOC__ |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 467 | #pragma argsused |
| Theodore Ts'o | 3cb6c50 | 1997-08-11 20:29:22 +0000 | [diff] [blame] | 468 | #endif |
| Theodore Ts'o | 03673db | 1998-06-10 20:39:43 +0000 | [diff] [blame] | 469 | static int xlate_func(ext2_filsys fs, blk_t *blocknr, e2_blkcnt_t blockcnt, |
| Theodore Ts'o | 5443492 | 2003-12-07 01:28:50 -0500 | [diff] [blame^] | 470 | blk_t ref_block EXT2FS_ATTR((unused)), |
| 471 | int ref_offset EXT2FS_ATTR((unused)), |
| 472 | void *priv_data) |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 473 | { |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 474 | struct xlate *xl = (struct xlate *) priv_data; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 475 | |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 476 | return (*xl->func)(fs, blocknr, (int) blockcnt, xl->real_private); |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | errcode_t ext2fs_block_iterate(ext2_filsys fs, |
| Theodore Ts'o | 31dbecd | 2001-01-11 04:54:39 +0000 | [diff] [blame] | 480 | ext2_ino_t ino, |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 481 | int flags, |
| 482 | char *block_buf, |
| 483 | int (*func)(ext2_filsys fs, |
| 484 | blk_t *blocknr, |
| 485 | int blockcnt, |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 486 | void *priv_data), |
| 487 | void *priv_data) |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 488 | { |
| 489 | struct xlate xl; |
| 490 | |
| Theodore Ts'o | b5abe6f | 1998-01-19 14:47:53 +0000 | [diff] [blame] | 491 | xl.real_private = priv_data; |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 492 | xl.func = func; |
| 493 | |
| Theodore Ts'o | 36a43d6 | 1998-03-24 16:17:51 +0000 | [diff] [blame] | 494 | return ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_NO_LARGE | flags, |
| Theodore Ts'o | 674a4ee | 1998-03-23 02:06:52 +0000 | [diff] [blame] | 495 | block_buf, xlate_func, &xl); |
| Theodore Ts'o | 21c84b7 | 1997-04-29 16:15:03 +0000 | [diff] [blame] | 496 | } |
| 497 | |