root/branches/windows-client/src/common/misc/extent-utils.c @ 8638

Revision 8638, 4.2 KB (checked in by sampson, 2 years ago)

Testing client

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <errno.h>
11#include <ctype.h>
12#include <assert.h>
13
14#include "pvfs2-types.h"
15#include "str-utils.h"
16#include "extent-utils.h"
17
18/* PINT_create_extent_list()
19 *
20 * Return an extent llist based on extent string input
21 *
22 * Parameters:
23 * extent_str   - pointer to string
24 *
25 * Returns an extent list matching structure of
26 * the input extent_str on success; returns NULL
27 * the extent_str is invalid, or an error occurs
28 *
29 */
30PINT_llist *PINT_create_extent_list(char *extent_str)
31{
32    PVFS_handle_extent cur_extent, *new_extent = NULL;
33    PINT_llist *extent_list = NULL;
34    int status = 0;
35
36    if (extent_str)
37    {
38        extent_list = PINT_llist_new();
39        assert(extent_list);
40
41        while(PINT_parse_handle_ranges(extent_str,&cur_extent,&status))
42        {
43            new_extent = malloc(sizeof(PVFS_handle_extent));
44            assert(new_extent);
45
46            new_extent->first = cur_extent.first;
47            new_extent->last = cur_extent.last;
48
49            PINT_llist_add_to_tail(extent_list,(void *)new_extent);
50        }
51    }
52    return extent_list;
53}
54
55/* PINT_handle_in_extent()
56 *
57 * Parameters:
58 * PVFS_handle_extent   - extent structure
59 * PVFS_handle     - a handle
60 *
61 * Returns 1 if the specified handle is within the
62 * range of the specified extent.  Returns 0 otherwise.
63 *
64 */
65int PINT_handle_in_extent(PVFS_handle_extent *ext, PVFS_handle handle)
66{
67    /*
68    return ((handle > ext->first-1) &&
69            (handle < ext->last+1));
70    */
71    /* ext->last may be max, 2^64 - 1 */   
72    return ((handle >= ext->first) &&
73            (handle <= ext->last));
74}
75
76/* PINT_handle_in_extent_array()
77 *
78 * Parameters:
79 * PVFS_handle_extent_array    - array of extents
80 * PVFS_handle                 - a handle
81 *
82 * Returns 1 if the specified handle is within any of the
83 * extents in the specified list of extents.  Returns 0
84 * otherwise.
85 *
86 */
87int PINT_handle_in_extent_array(
88    PVFS_handle_extent_array *ext_array, PVFS_handle handle)
89{
90    int i, ret;
91    for(i = 0; i < ext_array->extent_count; ++i)
92    {
93        ret = PINT_handle_in_extent(&ext_array->extent_array[i], handle);
94        if(ret)
95        {
96            return ret;
97        }
98    }
99    return 0;
100}
101
102
103/* PINT_handle_in_extent_list()
104 *
105 * Parameters:
106 * PINT_llist *extent_list   - PINT_llist of extent structures
107 * PVFS_handle                 - a handle
108 *
109 * Returns 1 if the specified handle is within any of the
110 * extents in the specified list of extents.  Returns 0
111 * otherwise.
112 *
113 */
114int PINT_handle_in_extent_list(
115    PINT_llist *extent_list,
116    PVFS_handle handle)
117{
118    int ret = 0;
119    PINT_llist *cur = NULL;
120    PVFS_handle_extent *cur_extent = NULL;
121
122    if (extent_list)
123    {
124        cur = extent_list;
125        while(cur)
126        {
127            cur_extent = PINT_llist_head(cur);
128            if (!cur_extent)
129            {
130                break;
131            }
132            if (PINT_handle_in_extent(cur_extent,handle))
133            {
134                ret = 1;
135                break;
136            }
137            cur = PINT_llist_next(cur);
138        }
139    }
140    return ret;
141}
142
143/* PINT_extent_list_count_total()
144 *
145 * counts the total number of handles represented in an extent list
146 *
147 * returns the 0 on success and fills in the specified count argument
148 * with the extent count total.  returns -PVFS_error on error
149 */
150uint64_t PINT_extent_array_count_total(
151    PVFS_handle_extent_array *extent_array)
152{
153    int i;
154    uint64_t count = 0;
155
156    for(i = 0; i < extent_array->extent_count; ++i)
157    {
158        count += (extent_array->extent_array[i].last -
159                  extent_array->extent_array[i].first + 1);
160    }
161    return count;
162}
163
164/* PINT_release_extent_list()
165 *
166 * Parameters:
167 * PINT_llist *extent_list   - PINT_llist of extent structures
168 *
169 * Frees extent objects within the specified extent_list if any.
170 *
171 */
172void PINT_release_extent_list(PINT_llist *extent_list)
173{
174    if (extent_list)
175    {
176        PINT_llist_free(extent_list,free);
177    }
178}
179
180/*
181 * Local variables:
182 *  c-indent-level: 4
183 *  c-basic-offset: 4
184 * End:
185 *
186 * vim: ts=8 sts=4 sw=4 expandtab
187 */
Note: See TracBrowser for help on using the browser.