summaryrefslogtreecommitdiff
path: root/cmds-restore.c
Commit message (Collapse)AuthorAge
* 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_node_slot function to get rid of btrfs_rootQu Wenruo2017-07-03
| | | | | | parameter Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.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 block sizes users in cmds-restore.cQu Wenruo2017-07-03
| | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove extra newline from messagesDavid Sterba2016-12-14
| | | | | | The common message helpers add the newline. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in find_first_dirDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in do_list_rootsDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in search_dirDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in copy_symlinkDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in copy_fileDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in copy_metadataDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: use on-stack path buffer in set_file_xattrsDavid Sterba2016-11-09
| | | | | | | We don't need to conserve stack space too much unlike kernel, also remove one error condition. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: update help textDavid Sterba2016-10-03
| | | | | | | Make it clear that --xattr restores the xattrs. Fix some whitespace damage and add an enum for the long-only option. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: cleanup, kill trivial btrfs_key_type helperDavid Sterba2016-10-03
| | | | 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: 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: Replace hardcoded PAGE_CACHE_SIZE with sectorsize.Feifei Xu2016-03-14
| | | | | | | | | PAGE_CACHE_SIZE is hardcoded to 4K in cmds-restore.c. Correct value should be sector size. Fix this through replacing hardcoded 4K to sectorsize. Signed-off-by: Feifei Xu <xufeifei@linux.vnet.ibm.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add new option for specify chunk root bytenrLu Fengqi2016-03-14
| | | | | | | | | | Add new btrfsck option, '--chunk-root', to specify chunk root bytenr. And allow open_ctree_fs_info() function accept chunk_root_bytenr to override the bytenr in superblock. This will be mainly used when chunk tree corruption. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: update error messagesDavid Sterba2016-03-14
| | | | | | Switch to common helpers, message wording changed. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unnecessary errno temp variablesDavid Sterba2016-01-12
| | | | | | | We can read errno directly if it's not clobbered by any intermediate calls. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: fix off-by-one len checkVincent Stehlé2015-10-16
| | | | | | | | | Fix a check of len versus PATH_MAX in function copy_symlink(), to account for the terminating null byte. Resolves-Coverity-CID: 1296749 Signed-off-by: Vincent Stehlé <vincent.stehle@freescale.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: restore: add more long option variantsDavid Sterba2015-05-14
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: shift option textsDavid Sterba2015-05-14
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: use bigger buffer for output path nameDavid Sterba2015-05-14
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: optionally restore symlinks.Dan Merillat2015-05-14
| | | | | | | Restore symlinks, optionally with owner/times. Signed-off-by: Dan Merillat <dan.merillat@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: separate the overwrite checkDan Merillat2015-04-29
| | | | | | | | | Symlink restore needs this, but the cut&paste became too complicated. Simplify everything. Signed-off-by: Dan Merillat <dan.merillat@gmail.com> [message wording adjustments] Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: don't misreport errors from search_dirDavid Sterba2015-04-29
| | | | | | | | The logic around return value has changed in the metadata restore patches. The return value from btrfs_search_slot may remain non-zero and is returned. This is incorrectly interpreted as an error. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix typos in restore help/docDavid Sterba2015-04-24
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: cleanup, use PATH_MAXDavid Sterba2015-04-24
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: convert copy_file exit paths to a single returnDavid Sterba2015-04-24
| | | | | Resolves-coverity-id: 1295365 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: convert search_dir exit paths to a single returnDavid Sterba2015-04-24
| | | | | Resolves-coverity-id: 1295366 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: fix path leak in copy_metadataDavid Sterba2015-04-24
| | | | | | | The path lifecycle spans only this function and we have to free it. Resolves-coverity-id: 1295367 Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: restore: optionally restore metadataDan Merillat2015-04-24
| | | | | | | | | | As long as the inode is intact, the file metadata can be restored. Directory data is restored at the end of search_dir. Errors are checked and returned, unless ignore_errors is requested. Signed-off-by: Dan Merillat <dan.merillat@gmail.com> [minor style fixes, error message updates] 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: restore, fix page alignment issue for lzo compressionGui Hecheng2015-03-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When runing restore under lzo compression, "bad compress length" problems are encountered. It is because there is a page alignment problem with the @decompress_lzo, as follows: |------| |----|-| |------|...|------| page ^ page page | 3 bytes left When lzo pages are compressed in memory, we will ensure that the 4 bytes length header will not cross a page boundary. There is a situation that 3 (or less) bytes are left at the end of a page, and then the 4 bytes len is stored at the start of the next page. But the @decompress_lzo doesn't go to the start of the next page and continue to read the next 4 bytes which crosses two pages, so a random value is fetched as a "bad compress length". So we check page alignment every time before we are going to fetch the next @len and after the former piece of data is decompressed. If the current page that we reach has less than 4 bytes left, then we should fetch the next @len at the start of next page. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> [simplifed and moved into decompress_lzo] Signed-off-by: David Sterba <dsterba@suse.cz>
* 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>
* btrfs-progs: drop feature defines from C files, in favour of CFLAGS definesDimitri John Ledkov2015-01-27
| | | | | | | | | | | | | | | | | | | | | | glibc 2.10+ (5+ years old) enables all the desired features: _XOPEN_SOURCE 700, __XOPEN2K8, POSIX_C_SOURCE, DEFAULT_SOURCE; with a single _GNU_SOURCE define in the makefile alone. For portability to other libc implementations (e.g. dietlibc) _XOPEN_SOURCE=700 is also defined. This also resolves Debian bug report filed by Michael Tautschnig - "Inconsistent use of _XOPEN_SOURCE results in conflicting declarations". Whilst I was not able to reproduce the results, the reported fact is that _XOPEN_SOURCE set to 500 in one set of files (e.g. cmds-filesystem.c) generates/defines different struct stat from other files (cmds-replace.c). This patch thus cleans up all feature defines, and sets them at a consistent level. Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=747969 Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: make getopt tables static constDavid Sterba2015-01-19
| | | | Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup, move getop long options close to their useDavid Sterba2015-01-19
| | | | | | Move long_option defintions just before getopt_long everywhere. Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: cleanup duplicate assignment of variable leaf for btrfs-restoreGui Hecheng2014-12-04
| | | | | | | | The value of variable leaf in while loop don't have to be set for every round. Just move it outside. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix compiler warningChristian Hesse2014-11-18
| | | | | | | | | | | | | | gcc 4.9.0 gives a warning: array subscript is above array bounds Checking for "greater or equal" instead of just "equal" fixes this. The warning is a false positive, appears with -ftree-vrp, but we'd rather fix it to avoid noise during build. http://www.mail-archive.com/linux-btrfs%40vger.kernel.org/msg34338.html Signed-off-by: Christian Hesse <mail@eworm.de> Signed-off-by: David Sterba <dsterba@suse.cz>
* Btrfs-progs: spit out the broken file when ignoring errorsJosef Bacik2014-11-14
| | | | | | | | It's nice to ignore errors on restore, but spit out the filename so the user knows which files of his aren't going to look right. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: remove wrong set_argv0 for restoreGui Hecheng2014-09-14
| | | | | | | | | | | | | | | | | | | | | | | Before this patch, you could see the following after exec restore # :too few arguments The tool name "btrfs restore" is missing. The @set_argv0() function is introduced by: commit a184abc70f7b1468e6036ab576f1587ee0574668 btrfs-progs: move the check_argc_* functions into utils.c ... Also add a new function "set_argv0" to set the correct tool name: *btrfs-image*: too few arguments But @set_argv0() only applies to the independent tools with the name pattern btrfs-***. Since restore is now is subcommand under "btrfs", there is no need to use @set_argv0() before check_argc_* to repair the prompt tool name before "too few arguments". Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix next_leaf in restore as it improperly skips some slotsGui Hecheng2014-09-14
| | | | | | | | When entering the next level node, the @next_leaf in restore forgets to start at the first slot. Just reset it to the first one. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix len of read_extent_buffer for inline extent in restoreGui Hecheng2014-09-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Steps to reproduce: # mkfs.btrfs -f <dev> # mount -o compress-force=lzo <dev> <mnt> # for ((i=0;i<4000;i++)); do echo -n 'A' >> <mnt>/inline_data done # umount <mnt> # valgrind --tool=memcheck --leak-check=full \ btrfs restore <dev> <dest_dir> output: ==32118== Invalid read of size 1 ==32118== at 0x4A0A4E4: memcpy@@GLIBC_2.14 ==32118== by 0x43DC91: read_extent_buffer ==32118== by 0x421401: search_dir (cmds-restore.c:240) ==32118== by 0x422CBB: cmd_restore (cmds-restore.c:1317) ==32118== by 0x404709: main (btrfs.c:248) ==32118== Address 0x4c4f4ac is not stack'd, malloc'd or... It is because when deal with inline extent, the read_extent_buffer is now reading a len of @ram_bytes which is the len of the uncompressed data. But actually here we want the len of the inline item. So in the compressed situation, use the len of the inline item. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: init uninitialized output buf for btrfs-restoreGui Hecheng2014-09-14
| | | | | | | | | | | | | | | | | A memory problem reported by valgrind as follows: === Syscall param pwrite64(buf) points to uninitialised byte(s) When running: # valgrind --leak-check=yes btrfs restore /dev/sda9 /mnt/backup Because the output buf size is alloced with malloc, but the length of output data is shorter than the sizeof(buf), so valgrind report uninitialised byte(s). We could use calloc to repalce malloc and clear this WARNING away. Reported-by: Marc Dietrich <marvin24@gmx.de> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>