Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/lib/util/idtree.c

    r740 r988  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33
     
    77   Copyright (C) Andrew Tridgell 2004
    88
    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
    1010   written by Jim Houston jim.houston@ccur.com, and is
    1111   Copyright (C) 2002 by Concurrent Computer Corporation
    12    
     12
    1313   This program is free software; you can redistribute it and/or modify
    1414   it under the terms of the GNU General Public License as published by
    1515   the Free Software Foundation; either version 2 of the License, or
    1616   (at your option) any later version.
    17    
     17
    1818   This program is distributed in the hope that it will be useful,
    1919   but WITHOUT ANY WARRANTY; without even the implied warranty of
    2020   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2121   GNU General Public License for more details.
    22    
     22
    2323   You should have received a copy of the GNU General Public License
    2424   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    3333 */
    3434
    35 #include "includes.h"
     35#include "replace.h"
     36#include <talloc.h>
     37#include "debug.h"
     38#include "idtree.h"
    3639
    3740#define IDR_BITS 5
     
    5154#define clear_bit(bit, v) (v) &= ~(1<<(bit))
    5255#define test_bit(bit, v) ((v) & (1<<(bit)))
    53                                    
     56
    5457struct idr_layer {
    5558        uint32_t                 bitmap;
     
    140143                        sh = IDR_BITS * (l + 1);
    141144                        if (oid >> sh == id >> sh)
    142                         continue;
     145                                continue;
    143146                        else
    144147                                goto restart;
     
    179182        n = id;
    180183        while (p->bitmap == IDR_FULL) {
    181                 if (!(p = pa[++l]))
     184                if (l >= MAX_LEVEL) {
    182185                        break;
     186                }
     187                p = pa[++l];
     188                if (p == NULL) {
     189                        break;
     190                }
    183191                n = n >> IDR_BITS;
    184192                set_bit((n & IDR_MASK), p->bitmap);
     
    193201
    194202        idr_pre_get(idp);
    195        
     203
    196204        id = starting_id;
    197205build_up:
     
    307315        }
    308316
    309         if ( idp->top && idp->top->count == 1 && 
     317        if ( idp->top && idp->top->count == 1 &&
    310318             (idp->layers > 1) &&
    311319             idp->top->ary[0]) {
     
    367375
    368376/**
    369   allocate a new id randomly in the given range
    370 */
    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 only
    377            fail if the range is over half full, and finally fallback to any
    378            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 /**
    391377  find a pointer value previously set with idr_get_new given an id
    392378*/
Note: See TracChangeset for help on using the changeset viewer.