Changeset 988 for vendor/current/lib/util/idtree.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/lib/util/idtree.c
r740 r988 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 … … 7 7 Copyright (C) Andrew Tridgell 2004 8 8 9 This code is derived from lib/idr.c in the 2.6 Linux kernel, which was 9 This code is derived from lib/idr.c in the 2.6 Linux kernel, which was 10 10 written by Jim Houston jim.houston@ccur.com, and is 11 11 Copyright (C) 2002 by Concurrent Computer Corporation 12 12 13 13 This program is free software; you can redistribute it and/or modify 14 14 it under the terms of the GNU General Public License as published by 15 15 the Free Software Foundation; either version 2 of the License, or 16 16 (at your option) any later version. 17 17 18 18 This program is distributed in the hope that it will be useful, 19 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 21 GNU General Public License for more details. 22 22 23 23 You should have received a copy of the GNU General Public License 24 24 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 33 33 */ 34 34 35 #include "includes.h" 35 #include "replace.h" 36 #include <talloc.h> 37 #include "debug.h" 38 #include "idtree.h" 36 39 37 40 #define IDR_BITS 5 … … 51 54 #define clear_bit(bit, v) (v) &= ~(1<<(bit)) 52 55 #define test_bit(bit, v) ((v) & (1<<(bit))) 53 56 54 57 struct idr_layer { 55 58 uint32_t bitmap; … … 140 143 sh = IDR_BITS * (l + 1); 141 144 if (oid >> sh == id >> sh) 142 continue;145 continue; 143 146 else 144 147 goto restart; … … 179 182 n = id; 180 183 while (p->bitmap == IDR_FULL) { 181 if ( !(p = pa[++l]))184 if (l >= MAX_LEVEL) { 182 185 break; 186 } 187 p = pa[++l]; 188 if (p == NULL) { 189 break; 190 } 183 191 n = n >> IDR_BITS; 184 192 set_bit((n & IDR_MASK), p->bitmap); … … 193 201 194 202 idr_pre_get(idp); 195 203 196 204 id = starting_id; 197 205 build_up: … … 307 315 } 308 316 309 if ( idp->top && idp->top->count == 1 && 317 if ( idp->top && idp->top->count == 1 && 310 318 (idp->layers > 1) && 311 319 idp->top->ary[0]) { … … 367 375 368 376 /** 369 allocate a new id randomly in the given range370 */371 _PUBLIC_ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit)372 {373 int id;374 375 /* first try a random starting point in the whole range, and if that fails,376 then start randomly in the bottom half of the range. This can only377 fail if the range is over half full, and finally fallback to any378 free id */379 id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit);380 if (id == -1) {381 id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit);382 }383 if (id == -1) {384 id = idr_get_new_above(idp, ptr, 1, limit);385 }386 387 return id;388 }389 390 /**391 377 find a pointer value previously set with idr_get_new given an id 392 378 */
Note:
See TracChangeset
for help on using the changeset viewer.