~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to debugfs/debugfs.c

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2014-10-27 09:44:27 UTC
  • mfrom: (8.4.29 sid)
  • Revision ID: package-import@ubuntu.com-20141027094427-g56dce6sg7pasdgm
Tags: 1.42.12-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/rules:
      Block pkg-create-dbgsym from operating on this package.
      Build without dietlibc-dev, which is in universe 
      Use the autotools-dev dh addon to update config.guess/config.sub for new
      ports.
  - debian/control:
      Regenerate with ./debian/rules debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
132
132
        return;
133
133
 
134
134
errout:
135
 
        retval = ext2fs_close(current_fs);
 
135
        retval = ext2fs_close_free(&current_fs);
136
136
        if (retval)
137
137
                com_err(device, retval, "while trying to close filesystem");
138
 
        current_fs = NULL;
139
138
}
140
139
 
141
140
void do_open_filesys(int argc, char **argv)
241
240
        }
242
241
        if (current_qctx)
243
242
                quota_release_context(&current_qctx);
244
 
        retval = ext2fs_close(current_fs);
 
243
        retval = ext2fs_close_free(&current_fs);
245
244
        if (retval)
246
245
                com_err("ext2fs_close", retval, 0);
247
 
        current_fs = NULL;
248
246
        return;
249
247
}
250
248
 
1578
1576
}
1579
1577
 
1580
1578
#ifndef READ_ONLY
1581
 
static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize, int make_holes)
 
1579
static errcode_t copy_file(int fd, ext2_ino_t newfile, int bufsize,
 
1580
                           int make_holes)
1582
1581
{
1583
1582
        ext2_file_t     e2_file;
1584
 
        errcode_t       retval;
 
1583
        errcode_t       retval, close_ret;
1585
1584
        int             got;
1586
1585
        unsigned int    written;
1587
1586
        char            *buf;
1597
1596
        retval = ext2fs_get_mem(bufsize, &buf);
1598
1597
        if (retval) {
1599
1598
                com_err("copy_file", retval, "can't allocate buffer\n");
1600
 
                return retval;
 
1599
                goto out_close;
1601
1600
        }
1602
1601
 
1603
1602
        /* This is used for checking whether the whole block is zero */
1604
1603
        retval = ext2fs_get_memzero(bufsize, &zero_buf);
1605
1604
        if (retval) {
1606
 
                com_err("copy_file", retval, "can't allocate buffer\n");
1607
 
                ext2fs_free_mem(&buf);
1608
 
                return retval;
 
1605
                com_err("copy_file", retval, "can't allocate zero buffer\n");
 
1606
                goto out_free_buf;
1609
1607
        }
1610
1608
 
1611
1609
        while (1) {
1624
1622
                        cmp = memcmp(ptr, zero_buf, got);
1625
1623
                        if (cmp == 0) {
1626
1624
                                 /* The whole block is zero, make a hole */
1627
 
                                retval = ext2fs_file_lseek(e2_file, got, EXT2_SEEK_CUR, NULL);
 
1625
                                retval = ext2fs_file_lseek(e2_file, got,
 
1626
                                                           EXT2_SEEK_CUR, NULL);
1628
1627
                                if (retval)
1629
1628
                                        goto fail;
1630
1629
                                got = 0;
1642
1641
                        ptr += written;
1643
1642
                }
1644
1643
        }
1645
 
        ext2fs_free_mem(&buf);
1646
 
        ext2fs_free_mem(&zero_buf);
1647
 
        retval = ext2fs_file_close(e2_file);
1648
 
        return retval;
1649
1644
 
1650
1645
fail:
 
1646
        ext2fs_free_mem(&zero_buf);
 
1647
out_free_buf:
1651
1648
        ext2fs_free_mem(&buf);
1652
 
        ext2fs_free_mem(&zero_buf);
1653
 
        (void) ext2fs_file_close(e2_file);
 
1649
out_close:
 
1650
        close_ret = ext2fs_file_close(e2_file);
 
1651
        if (retval == 0)
 
1652
                retval = close_ret;
1654
1653
        return retval;
1655
1654
}
1656
1655
 
1719
1718
        inode.i_atime = inode.i_ctime = inode.i_mtime =
1720
1719
                current_fs->now ? current_fs->now : time(0);
1721
1720
        inode.i_links_count = 1;
1722
 
        inode.i_size = statbuf.st_size;
 
1721
        retval = ext2fs_inode_size_set(current_fs, &inode, statbuf.st_size);
 
1722
        if (retval) {
 
1723
                com_err(argv[2], retval, 0);
 
1724
                close(fd);
 
1725
                return;
 
1726
        }
1723
1727
        if (current_fs->super->s_feature_incompat &
1724
1728
            EXT3_FEATURE_INCOMPAT_EXTENTS) {
1725
1729
                int i;
2146
2150
 
2147
2151
}
2148
2152
 
 
2153
void do_idump(int argc, char *argv[])
 
2154
{
 
2155
        ext2_ino_t      ino;
 
2156
        unsigned char   *buf;
 
2157
        errcode_t       err;
 
2158
        int             isize;
 
2159
 
 
2160
        if (common_args_process(argc, argv, 2, 2, argv[0],
 
2161
                                "<file>", 0))
 
2162
                return;
 
2163
        ino = string_to_inode(argv[1]);
 
2164
        if (!ino)
 
2165
                return;
 
2166
 
 
2167
        isize = EXT2_INODE_SIZE(current_fs->super);
 
2168
        err = ext2fs_get_mem(isize, &buf);
 
2169
        if (err) {
 
2170
                com_err(argv[0], err, "while allocating memory");
 
2171
                return;
 
2172
        }
 
2173
 
 
2174
        err = ext2fs_read_inode_full(current_fs, ino,
 
2175
                                     (struct ext2_inode *)buf, isize);
 
2176
        if (err) {
 
2177
                com_err(argv[0], err, "while reading inode %d", ino);
 
2178
                goto err;
 
2179
        }
 
2180
 
 
2181
        do_byte_hexdump(stdout, buf, isize);
 
2182
err:
 
2183
        ext2fs_free_mem(&buf);
 
2184
}
 
2185
 
2149
2186
#ifndef READ_ONLY
2150
2187
void do_set_current_time(int argc, char *argv[])
2151
2188
{
2315
2352
 
2316
2353
void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
2317
2354
{
2318
 
        struct ext2_super_block *sb;
2319
2355
        struct mmp_struct *mmp_s;
2320
2356
        time_t t;
2321
2357
        errcode_t retval = 0;
2323
2359
        if (check_fs_open(argv[0]))
2324
2360
                return;
2325
2361
 
2326
 
        sb  = current_fs->super;
2327
 
 
2328
2362
        if (current_fs->mmp_buf == NULL) {
2329
2363
                retval = ext2fs_get_mem(current_fs->blocksize,
2330
2364
                                        &current_fs->mmp_buf);