6253 F_GETLK doesn't always return lock owner
[illumos-gate.git] / usr / src / cmd / fs.d / cachefs / mdbug / flist.c
blob7a14876bace2bf6d5c6a342e2d6078bf3abea7ca
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
24 * flist.c
26 * Defines the flist class.
28 #pragma ident "%Z%%M% %I% %E% SMI"
29 /* Copyright (c) 1994 by Sun Microsystems, Inc. */
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include "flist.h"
34 #include "mdbug.h"
38 * flist_create
40 * Description:
41 * Constructor for the flist class.
42 * Arguments:
43 * Returns:
44 * Preconditions:
46 flist_object_t *
47 flist_create()
49 flist_object_t *flist_object_p;
51 flist_object_p = (flist_object_t *)calloc(sizeof (flist_object_t), 1);
53 if (flist_object_p == NULL)
54 doabort();
56 flist_object_p->f_count = 0;
57 flist_object_p->f_index = 0;
58 return (flist_object_p);
63 * flist_destroy
65 * Description:
66 * Destructor for the flist class.
67 * Arguments:
68 * Returns:
69 * Preconditions:
71 void
72 flist_destroy(flist_object_t *flist_object_p)
74 free(flist_object_p);
78 * fl_push
80 * Description:
81 * Adds the specified pointer to the top of the list
82 * if there is room. If there is no more room then
83 * nothing happens.
84 * Arguments:
85 * Returns:
86 * Preconditions:
88 void
89 fl_push(flist_object_t *flist_object_p, void *ptr)
91 if (flist_object_p->f_count < FLIST_SIZE) {
92 flist_object_p->f_items[flist_object_p->f_count] = (char *)ptr;
93 flist_object_p->f_count++;
99 * fl_pop
101 * Description:
102 * Removes the top item from the list.
103 * No action is taken if the list is empty.
104 * Arguments:
105 * Returns:
106 * Preconditions:
108 void
109 fl_pop(flist_object_t *flist_object_p)
111 if (flist_object_p->f_count > 0)
112 flist_object_p->f_count--;
117 * fl_top
119 * Description:
120 * Returns the top item on the list.
121 * Sets the internal state so that a following call to
122 * next() will return the second item on the list.
123 * Returns NULL if the list is empty.
124 * Arguments:
125 * Returns:
126 * Preconditions:
128 void *
129 fl_top(flist_object_t *flist_object_p)
131 flist_object_p->f_index = flist_object_p->f_count;
132 return (fl_next(flist_object_p));
137 * fl_next
139 * Description:
140 * Returns the next item on the list. NULL if there
141 * is no next item.
142 * Arguments:
143 * Returns:
144 * Preconditions:
146 void *
147 fl_next(flist_object_t *flist_object_p)
149 if (flist_object_p->f_index > 0) {
150 flist_object_p->f_index--;
151 return (flist_object_p->f_items[ flist_object_p->f_index ]);
152 } else {
153 return (NULL);
159 * fl_clear
161 * Description:
162 * Removes all items from the list and frees them.
163 * Arguments:
164 * Returns:
165 * Preconditions:
167 void
168 fl_clear(flist_object_t *flist_object_p)
170 void *p1;
171 while ((p1 = fl_top(flist_object_p)) != NULL) {
172 free(p1);
173 fl_pop(flist_object_p);
178 * fl_space
180 * Description:
181 * Arguments:
182 * Returns:
183 * Returns the number of free slots on the list.
184 * Errors:
185 * Preconditions:
188 fl_space(flist_object_t *flist_object_p)
190 return (FLIST_SIZE - flist_object_p->f_count);