ctree.c (097b8a7c9e48e2cb50fd0eb9315791921beaf484) | ctree.c (2f38b3e1900634e64a186873b3388b1bf85dabc0) |
---|---|
1/* 2 * Copyright (C) 2007,2008 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 2775 unchanged lines hidden (view full) --- 2784 btrfs_set_path_blocking(p); 2785 if (ret < 0) 2786 btrfs_release_path(p); 2787 2788 return ret; 2789} 2790 2791/* | 1/* 2 * Copyright (C) 2007,2008 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 2775 unchanged lines hidden (view full) --- 2784 btrfs_set_path_blocking(p); 2785 if (ret < 0) 2786 btrfs_release_path(p); 2787 2788 return ret; 2789} 2790 2791/* |
2792 * helper to use instead of search slot if no exact match is needed but 2793 * instead the next or previous item should be returned. 2794 * When find_higher is true, the next higher item is returned, the next lower 2795 * otherwise. 2796 * When return_any and find_higher are both true, and no higher item is found, 2797 * return the next lower instead. 2798 * When return_any is true and find_higher is false, and no lower item is found, 2799 * return the next higher instead. 2800 * It returns 0 if any item is found, 1 if none is found (tree empty), and 2801 * < 0 on error 2802 */ 2803int btrfs_search_slot_for_read(struct btrfs_root *root, 2804 struct btrfs_key *key, struct btrfs_path *p, 2805 int find_higher, int return_any) 2806{ 2807 int ret; 2808 struct extent_buffer *leaf; 2809 2810again: 2811 ret = btrfs_search_slot(NULL, root, key, p, 0, 0); 2812 if (ret <= 0) 2813 return ret; 2814 /* 2815 * a return value of 1 means the path is at the position where the 2816 * item should be inserted. Normally this is the next bigger item, 2817 * but in case the previous item is the last in a leaf, path points 2818 * to the first free slot in the previous leaf, i.e. at an invalid 2819 * item. 2820 */ 2821 leaf = p->nodes[0]; 2822 2823 if (find_higher) { 2824 if (p->slots[0] >= btrfs_header_nritems(leaf)) { 2825 ret = btrfs_next_leaf(root, p); 2826 if (ret <= 0) 2827 return ret; 2828 if (!return_any) 2829 return 1; 2830 /* 2831 * no higher item found, return the next 2832 * lower instead 2833 */ 2834 return_any = 0; 2835 find_higher = 0; 2836 btrfs_release_path(p); 2837 goto again; 2838 } 2839 } else { 2840 if (p->slots[0] >= btrfs_header_nritems(leaf)) { 2841 /* we're sitting on an invalid slot */ 2842 if (p->slots[0] == 0) { 2843 ret = btrfs_prev_leaf(root, p); 2844 if (ret <= 0) 2845 return ret; 2846 if (!return_any) 2847 return 1; 2848 /* 2849 * no lower item found, return the next 2850 * higher instead 2851 */ 2852 return_any = 0; 2853 find_higher = 1; 2854 btrfs_release_path(p); 2855 goto again; 2856 } 2857 --p->slots[0]; 2858 } 2859 } 2860 return 0; 2861} 2862 2863/* |
|
2792 * adjust the pointers going up the tree, starting at level 2793 * making sure the right key of each node is points to 'key'. 2794 * This is used after shifting pointers to the left, so it stops 2795 * fixing up pointers when a given leaf/node is not in slot 0 of the 2796 * higher levels 2797 * 2798 */ 2799static void fixup_low_keys(struct btrfs_trans_handle *trans, --- 2500 unchanged lines hidden --- | 2864 * adjust the pointers going up the tree, starting at level 2865 * making sure the right key of each node is points to 'key'. 2866 * This is used after shifting pointers to the left, so it stops 2867 * fixing up pointers when a given leaf/node is not in slot 0 of the 2868 * higher levels 2869 * 2870 */ 2871static void fixup_low_keys(struct btrfs_trans_handle *trans, --- 2500 unchanged lines hidden --- |