summaryrefslogtreecommitdiff
path: root/btrfs-corrupt-block.c
Commit message (Collapse)AuthorAge
* btrfs-progs: corrupt-block: Fix -D optionNikolay Borisov2018-06-07
| | | | | | | | | | | | | | Currently the -D option is essentially defunct since it's the root, where we are going to corrupt a dir item is always set to the tree root. Fix this by passing the root from the "-r" option. Aditionally convert the interface for this option to the new format. So if one wants to corrupt a dir item in the default fs tree, they should now invoke: btrfs-corrupt-block -r 5 -D <objectid,DIR_ITEM,offset> -f name Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Change format of -d optionNikolay Borisov2018-06-07
| | | | | | | | | | | | | | Currently if we want to delete an item we need to invoke corrupt block like so: btrfs-corrupt-block [-r <numeric id of root>] -K <objectid,type,offset> -d Instead, this patch converts the format to: btrfs-corrupt-block [-r <numeric id of root>] -d <objectid,type,offset> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Add support for handling specific root when ↵Nikolay Borisov2018-06-07
| | | | | | | | | | | | using -K option Currently the -K option supports corrupting items only in the default root (which is the root tree). This makes it impossible to test the free-space recovery (or any other) code for that matter. Fix it by using the root corresponding to the one passed in -r (if any). Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Factor out common "-r" handling codeNikolay Borisov2018-06-07
| | | | | | | | | Since more and more of the "corrupt XXX" options are going to support combination with -r option, let's extract the common code needed for this. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Convert -K flag argument handling to common functionNikolay Borisov2018-06-07
| | | | | | | | There is now a common function used to parse btrfs keys triplets so use that one. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Change -I flag parameter formatNikolay Borisov2018-06-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Presently, if we want to corrupt a particular item we need to call corrupt block like so: btrfs-corrupt-block -I -K <objectid,type,offset> -r "numeric rootid" This is problematic because the -K option not only sets the key to the item that the -I option should corrupt but it also signals that we want to corrupt the key itself. This way we cannot really use the program with the following semantics: "Corrupt only the item which corresponds to this key but leave the key intact" This patch aims to fix this by changing the format of the -I flag. So if one wants to corrupt only an item (and leave the key intact) they should use: btrfs-corrupt-block -r <numeric rootid> -I <objectid,type,offset> In addition to this problem, -K doesn't really understand the the "-r" argument, so when using it in conjunction with -I to corrupt an item, not part of the root tree, it will always produce an error: Couldn't find the key to corrupt Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Factor out key parsing functionNikolay Borisov2018-06-07
| | | | | | | | | | | | Currently passing a key with -K handling is open coded. I intend on changing the interface a bit to make the program more usable. To aid in this factor out common code which parses a triplet of the "u64,u8,u64" format, corresponding to a btrfs key. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> [ print optarg too ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Correctly handle -r when passing -INikolay Borisov2018-06-07
| | | | | | | | | | | | | | | The documentation for the -I option (corrupt an item) states: An item to corrupt (must also specify the field to corrupt and a root+key for the item) The code on the other hand doesn't check whether -r is in fact passed, and even if it is it's not handled at all. This means presently -I is possible to corrupt items only in the root tree. Fix this by correctly checking -r is passed and fail otherwise and passing the correct root to corrupt_btrfs_item. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Factor out specific-root codeNikolay Borisov2018-06-07
| | | | | | | | Some options operate on a specific root so let's extract the code which deals with this. No functional change. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove fs_info parameter from btrfs_leaf_free_space()Qu Wenruo2018-06-07
| | | | | | | | | | | | | | | | | For btrfs_leaf_free_space(), to get leaf data size, we have two way to get it: 1) leaf->fs_info->nodesize 2) leaf->len Anyway, we could get rid of @fs_info parameter for btrfs_leaf_free_space(). And here we choose method 2), as it provides extra benefit to get leaf free space without initializing a real fs_info. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Unify btrfs_leaf_free_space() parameter with kernelQu Wenruo2018-04-24
| | | | | | | | | | Instead of struct btrfs_root, use struct btrfs_fs_info, since nodesize is now a per-fs setting, and with the need to pass a @root, caller don't need to wonder which root should be passed. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add crude error handling when transaction start failsDavid Sterba2017-09-08
| | | | | | | | | | Currently transaction bugs out insided btrfs_start_transaction in case of error, we want to lift the error handling to the callers. This patch adds the BUG_ON anywhere it's been missing so far. This is not the best way of course. Transforming BUG_ON to a proper error handling highly depends on the caller and should be dealt with case by case. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop blocksize argument from btrfs_find_create_tree_blockDavid Sterba2017-09-08
| | | | | | | | Metadata blocks are always nodesize. When reading the superblock::sys_array, the actual size of data is fixed to 4k and smaller than nodesize, but otherwise everything works as before. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop blocksize from read_tree_blockDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_num_copies to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_map_block and its variants to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | | | | | Just to keep the 1st paramter the same as kernel. We can also save a few lines since the parameter is shorter now. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor read_tree_block to get rid of btrfs_rootQu Wenruo2017-07-03
| | | | | | | | | | | | | The only reasom read_tree_block() needs a btrfs_root parameter is to get its node/sector size. And long ago, I have already introduced a compactible interface, read_tree_block_fs_info() to pass btrfs_fs_info instead of btrfs_root. Since we have cleaned up all root->sector/node/stripesize users, we should be OK to refactor read_tree_block() function. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Refactor btrfs_root paramters in btrfs-corrupt-block.cQu Wenruo2017-07-03
| | | | | | | | | | | | Refactor the following functions and its callers to get rid of incorrectly passed btrfs_root parameters: 1) corrupt_keys() 2) corrupt_metadata_block() The only reason passing btrfs_root for them is to get block sizes. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.cQu Wenruo2017-07-03
| | | | | | | | | Convert root->sectorsize/nodesize users in btrfs-corrupt-block. This provides the basis to further refactor incorrect btrfs_root parameter to btrfs_fs_info parameter. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: corrupt-block: remove unused argument from corrupt_extentDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Include more inode fieldsLakshmipathi.G2017-01-25
| | | | | Signed-off-by: Lakshmipathi.G <Lakshmipathi.G@giis.co.in> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Include inode nlink fieldLakshmipathi.G2017-01-25
| | | | | Signed-off-by: Lakshmipathi.G <Lakshmipathi.G@giis.co.in> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: fix assertion conditionDavid Sterba2016-10-03
| | | | | | | The ->data is no longer a pointer but an embedded array. Resolves-coverity-id: 1372671 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: use standard allocation functions in non-kenrel codeDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: improved error handling in corrupt_item_nocowDavid Sterba2016-10-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: print help test to stdoutDavid Sterba2016-09-05
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt block: handle eb read and write errorsDavid Sterba2016-07-15
| | | | | Resolves-coverity-id: 1261558 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt block: handle block mapping errors in debug_corrupt_blockDavid Sterba2016-07-15
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt block: pass eb as argument to debug_corrupt_blockDavid Sterba2016-07-15
| | | | | | Allocate the eb externally so we can handle the easy errors in advance. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use new random number APIQu Wenruo2016-06-03
| | | | | | | | | | | | | Replace old and not so informal srand()/rand() calls to new random number API. Including btrfs-corrupt-block(main user), btrfs-image and btrfs-crc. Some tests like dir-test/random-test/quick-test is not modified. As random-test itself can't even pass build. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: Add support to corrupt extent for skinny metadataQu Wenruo2016-06-01
| | | | | | | | For skinny metadata case, btrfs-corrupt-block can't corrupt a metadata extent due to the type check missing BTRFS_METADATA_ITEM_KEY. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: typo review of strings and commentsNicholas D Steeves2016-06-01
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: replace leafsize with nodesizeDavid Sterba2016-05-02
| | | | | | | | Nodesize is used in kernel, the values are always equal. We have to keep leafsize in headers, similarly the tree setting functions still take and set leafsize, but it's effectively a no-op. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify argc min/max checkingDavid Sterba2016-03-14
| | | | | | We don't want to modify argc. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: unify naming of argc and argvDavid Sterba2016-03-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add support for tree block operations on fs_info without rootsQu Wenruo2016-02-26
| | | | | | | | | | | | | Since open_ctree_fs_info() now may return a fs_info even without any roots, modify functions like read_tree_block() to operate with such fs_info. This provides the basis for btrfs-find-root to operate on chunk tree with corrupted fs. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> [ coding style adjustments, unified declarations ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfsprogs: corrupt-blocks: include limits.h to define PATH_MAXKhem Raj2016-01-12
| | | | | | | | | | | | | limits.h is needed for PATH_MAX definition Fixes | btrfs-corrupt-block.c: In function 'corrupt_dir_item': | btrfs-corrupt-block.c:478:12: error: 'PATH_MAX' undeclared (first use in this function) | char name[PATH_MAX]; Signed-off-by: Khem Raj <raj.khem@gmail.com> [ minor changelog edits ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: corrupt-block: use on-stack path buffer in corrupt_dir_itemDavid Sterba2015-11-13
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: simplify empty stirngs checkDavid Sterba2015-11-06
| | | | | | We can do a strlen(str) == 0 in a simpler way. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, mark more functions staticDavid Sterba2015-09-14
| | | | | | Reported by sparse. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add newline to some error messagesTsutomu Itoh2015-08-31
| | | | | | | | | Added a missing newline to some error messages. Also printf() was changed to fprintf(stderr) for error messages. Signed-off-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com> Reviewed-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: let corrupt-block kill nbytesDavid Sterba2015-07-03
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: accept --help as option in the standalone utilitiesDavid Sterba2015-06-11
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: corrupt-block: add the ability to remove csumsJosef Bacik2015-05-26
| | | | | | | | Sometimes we need to test what happens when we're missing a csum for a range, so add an option to btrfs-corrupt-block to be able to remove a csum range. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: getopt, use symbolic name for argument requirementsDavid Sterba2015-04-08
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup option index argument from getopt_longDavid Sterba2015-04-08
| | | | | | | We're not using it anywhere. The best practice is to add enums with values > 255 for the long options, option index counting is error prone. Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: let btrfs-corrupt-block specify a rootJosef Bacik2015-02-09
| | | | | | | | Sometimes we want to corrupt specific keys or delete items on different roots, so allow btrfs-corrupt-block to take a root objectid so we can corrupt a specific root. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com>
* btrfs-progs: read_tree_block() and read_node_slot() cleanup.Qu Wenruo2015-02-02
| | | | | | | | | | | | Allow read_tree_block() and read_node_slot() to return error pointer. This should help caller to get more specified error number. For existing callers, change (!eb) judgmentt to (!extent_buffer_uptodate(eb)) to keep the compatibility, and for caller missing the check, use PTR_ERR(eb) if possible. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: autoconf: use standard PACKAGE_* macrosKarel Zak2015-01-28
| | | | | | | | | | | | | - use standard PACKAGE_{NAME,VERSION,STRING,URL,...} autoconf macros rather than homemade BTRFS_BUILD_VERSION - don't #include version.h, now the file is necessary for library API only Note that "btrfs version" returns "btrfs-progs <version>" instead of the original confusing "btrfs <version>". Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>