~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to lib/ext2fs/mkjournal.c

  • Committer: Daniel Mehrmann
  • Date: 2014-12-16 09:16:59 UTC
  • mfrom: (1.2.25)
  • Revision ID: daniel.mehrmann@gmx.de-20141216091659-ymhbl4ualba43vuc
Tags: 1.43-SN-2014-12-16-0ubuntu1
* Merge in snapshot from the maint branch 

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
 * attempt to free the static zeroizing buffer.  (This is to keep
149
149
 * programs that check for memory leaks happy.)
150
150
 */
151
 
#define STRIDE_LENGTH 8
 
151
#define MAX_STRIDE_LENGTH (4194304 / (int) fs->blocksize)
152
152
errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num,
153
153
                              blk64_t *ret_blk, int *ret_count)
154
154
{
155
155
        int             j, count;
156
 
        static char     *buf;
 
156
        static void     *buf;
 
157
        static int      stride_length;
157
158
        errcode_t       retval;
158
159
 
159
160
        /* If fs is null, clean up the static buffer and return */
164
165
                }
165
166
                return 0;
166
167
        }
 
168
 
 
169
        /* Deal with zeroing less than 1 block */
 
170
        if (num <= 0)
 
171
                return 0;
 
172
 
167
173
        /* Allocate the zeroizing buffer if necessary */
168
 
        if (!buf) {
169
 
                buf = malloc(fs->blocksize * STRIDE_LENGTH);
170
 
                if (!buf)
171
 
                        return ENOMEM;
172
 
                memset(buf, 0, fs->blocksize * STRIDE_LENGTH);
 
174
        if (num > stride_length && stride_length < MAX_STRIDE_LENGTH) {
 
175
                void *p;
 
176
                int new_stride = num;
 
177
 
 
178
                if (new_stride > MAX_STRIDE_LENGTH)
 
179
                        new_stride = MAX_STRIDE_LENGTH;
 
180
                p = realloc(buf, fs->blocksize * new_stride);
 
181
                if (!p)
 
182
                        return EXT2_ET_NO_MEMORY;
 
183
                buf = p;
 
184
                stride_length = new_stride;
 
185
                memset(buf, 0, fs->blocksize * stride_length);
173
186
        }
174
187
        /* OK, do the write loop */
175
188
        j=0;
176
189
        while (j < num) {
177
 
                if (blk % STRIDE_LENGTH) {
178
 
                        count = STRIDE_LENGTH - (blk % STRIDE_LENGTH);
 
190
                if (blk % stride_length) {
 
191
                        count = stride_length - (blk % stride_length);
179
192
                        if (count > (num - j))
180
193
                                count = num - j;
181
194
                } else {
182
195
                        count = num - j;
183
 
                        if (count > STRIDE_LENGTH)
184
 
                                count = STRIDE_LENGTH;
 
196
                        if (count > stride_length)
 
197
                                count = stride_length;
185
198
                }
186
199
                retval = io_channel_write_blk64(fs->io, blk, count, buf);
187
200
                if (retval) {
365
378
 
366
379
        retval = ext2fs_block_iterate3(fs, journal_ino, BLOCK_FLAG_APPEND,
367
380
                                       0, mkjournal_proc, &es);
 
381
        if (retval)
 
382
                goto out2;
368
383
        if (es.err) {
369
384
                retval = es.err;
370
 
                goto errout;
 
385
                goto out2;
371
386
        }
372
387
        if (es.zero_count) {
373
388
                retval = ext2fs_zero_blocks2(fs, es.blk_to_zero,
374
389
                                            es.zero_count, 0, 0);
375
390
                if (retval)
376
 
                        goto errout;
 
391
                        goto out2;
377
392
        }
378
393
 
379
394
        if ((retval = ext2fs_read_inode(fs, journal_ino, &inode)))
380
 
                goto errout;
 
395
                goto out2;
381
396
 
382
397
        inode_size = (unsigned long long)fs->blocksize * num_blocks;
383
398
        ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
386
401
        inode.i_mode = LINUX_S_IFREG | 0600;
387
402
        retval = ext2fs_inode_size_set(fs, &inode, inode_size);
388
403
        if (retval)
389
 
                goto errout;
 
404
                goto out2;
390
405
 
391
406
        if ((retval = ext2fs_write_new_inode(fs, journal_ino, &inode)))
392
 
                goto errout;
 
407
                goto out2;
393
408
        retval = 0;
394
409
 
395
410
        memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4);
398
413
        fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS;
399
414
        ext2fs_mark_super_dirty(fs);
400
415
 
401
 
errout:
402
 
        ext2fs_zero_blocks2(0, 0, 0, 0, 0);
403
416
out2:
404
417
        ext2fs_free_mem(&buf);
405
418
        return retval;
488
501
        fs->super->s_journal_dev = st.st_rdev;
489
502
        memcpy(fs->super->s_journal_uuid, jsb->s_uuid,
490
503
               sizeof(fs->super->s_journal_uuid));
 
504
        memset(fs->super->s_jnl_blocks, 0, sizeof(fs->super->s_jnl_blocks));
491
505
        fs->super->s_feature_compat |= EXT3_FEATURE_COMPAT_HAS_JOURNAL;
492
506
        ext2fs_mark_super_dirty(fs);
493
507
        return 0;
582
596
                        goto errout;
583
597
                }
584
598
                journal_ino = st.st_ino;
 
599
                memset(fs->super->s_jnl_blocks, 0,
 
600
                       sizeof(fs->super->s_jnl_blocks));
585
601
        } else {
586
602
                if ((mount_flags & EXT2_MF_BUSY) &&
587
603
                    !(fs->flags & EXT2_FLAG_EXCLUSIVE)) {