1 /*
2 This file contains routines for buffer management.
3 */
4
5 #include "inet.h"
6
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "generic/assert.h"
11 #include "generic/buf.h"
12 #include "generic/type.h"
13
14 INIT_PANIC();
15
16 #if TRACE_ENQUEUE_PROBLEM
17 extern enqueue_problem;
18 #endif
19
20 #define USE_MALLOCS 0
21
22 #ifndef BUF512_NR
23 #define BUF512_NR (sizeof(int) == 2 ? 40 : 128)
24 #endif
25
26 #define ACC_NR 200
27 #define CLIENT_NR 5
28
29 typedef struct buf512
30 {
31 buf_t buf_header;
32 char buf_data[512];
33 } buf512_t;
34
35 #if USE_MALLOCS
36 PRIVATE buf512_t *buffers512;
37 PRIVATE acc_t *accessors;
38 #else
39 PRIVATE buf512_t buffers512[BUF512_NR];
40 PRIVATE acc_t accessors[ACC_NR];
41 #endif
42
43 PRIVATE buf512_t *buf512_free;
44
45 PRIVATE bf_freereq_t freereq[CLIENT_NR];
46 PRIVATE size_t bf_buf_gran;
47 PRIVATE acc_t *acc_free_list;
48
49 PUBLIC size_t bf_free_buffsize;
50 PUBLIC acc_t *bf_temporary_acc;
51
52
53 #ifdef bf_memreq
54 PUBLIC char *bf_memreq_file;
55 PUBLIC int bf_memreq_line;
56 #endif
57 #ifdef bf_cut
58 PUBLIC char *bf_cut_file;
59 PUBLIC int bf_cut_line;
60 #endif
61 #ifdef bf_packIffLess
62 PUBLIC char *bf_pack_file;
63 PUBLIC int bf_pack_line;
64 #endif
65 #ifdef bf_bufsize
66 PUBLIC char *bf_bufsize_file;
67 PUBLIC int bf_bufsize_line;
68 #endif
69
70 FORWARD acc_t *bf_small_memreq ARGS(( size_t size ));
71 FORWARD void bf_512free ARGS(( buf_t *buffer ));
72
73 PUBLIC void bf_init()
74 {
75 int i;
76 size_t size;
77 size_t buf_s;
78
79 bf_buf_gran= BUF_S;
80 buf_s= 0;
81
82 #if USE_MALLOCS
83 printf("buf.c: malloc %d 32K-buffers (%dK)\n", BUF32K_NR,
84 sizeof(*buffers32K) * BUF32K_NR / 1024);
85 buffers32K= malloc(sizeof(*buffers32K) * BUF32K_NR);
86 if (!buffers32K)
87 ip_panic(( "unable to alloc 32K-buffers" ));
88 printf("buf.c: malloc %d 2K-buffers (%dK)\n", BUF2K_NR,
89 sizeof(*buffers2K) * BUF2K_NR / 1024);
90 buffers2K= malloc(sizeof(*buffers2K) * BUF2K_NR);
91 if (!buffers2K)
92 ip_panic(( "unable to alloc 2K-buffers" ));
93 printf("buf.c: malloc %d 512-buffers (%dK)\n", BUF512_NR,
94 sizeof(*buffers512) * BUF512_NR / 1024);
95 buffers512= malloc(sizeof(*buffers512) * BUF512_NR);
96 if (!buffers512)
97 ip_panic(( "unable to alloc 512-buffers" ));
98 printf("buf.c: malloc %d accessors (%dK)\n", ACC_NR,
99 sizeof(*accessors) * ACC_NR / 1024);
100 accessors= malloc(sizeof(*accessors) * ACC_NR);
101 if (!accessors)
102 ip_panic(( "unable to alloc accessors" ));
103 #endif
104
105 for (i=0;i<BUF512_NR;i++)
106 {
107 buffers512[i].buf_header.buf_linkC= 0;
108 buffers512[i].buf_header.buf_next= &buffers512[i+1];
109 buffers512[i].buf_header.buf_free= bf_512free;
110 buffers512[i].buf_header.buf_size= sizeof(buffers512[i].
111 buf_data);
112 buffers512[i].buf_header.buf_data_p= buffers512[i].buf_data;
113 }
114 buffers512[i-1].buf_header.buf_next= 0;
115 buf512_free= &buffers512[0];
116 if (sizeof(buffers512[0].buf_data) < bf_buf_gran)
117 bf_buf_gran= sizeof(buffers512[0].buf_data);
118 if (sizeof(buffers512[0].buf_data) > buf_s)
119 buf_s= sizeof(buffers512[0].buf_data);
120
121 for (i=0;i<ACC_NR;i++)
122 {
123 accessors[i].acc_linkC= 0;
124 accessors[i].acc_next= &accessors[i+1];
125 }
126 acc_free_list= accessors;
127 accessors[i-1].acc_next= 0;
128
129 for (i=0;i<CLIENT_NR;i++)
130 freereq[i]=0;
131
132 assert (buf_s == BUF_S);
133 }
134
135 PUBLIC void bf_logon(func)
136 bf_freereq_t func;
137 {
138 int i;
139
140 for (i=0;i<CLIENT_NR;i++)
141 if (!freereq[i])
142 {
143 freereq[i]=func;
144 return;
145 }
146
147 ip_panic(( "buf.c: to many clients" ));
148 }
149
150 /*
151 bf_memreq
152 */
153
154 #ifndef bf_memreq
155 PUBLIC acc_t *bf_memreq(size)
156 #else
157 PUBLIC acc_t *_bf_memreq(size)
158 #endif
159 size_t size;
160 {
161 acc_t *head, *tail, *new_acc;
162 int i,j;
163 size_t count;
164
165 #if TRACE_ENQUEUE_PROBLEM
166 { if (enqueue_problem)
167 { where(); printf("bf_memreq(%d) called with enqueue_problem\n", size); } }
168 #endif
169 #ifdef bf_memreq
170 { where(); printf("bf_memreq(%d) called by %s, %d\n", size, bf_memreq_file,
171 bf_memreq_line); }
172 #endif
173 assert (size>0);
174
175 head= NULL;
176 while (size)
177 {
178 if (!acc_free_list)
179 {
180 #if DEBUG
181 { where(); printf("freeing accessors\n"); }
182 #endif
183 for (i=0; !acc_free_list && i<MAX_BUFREQ_PRI; i++)
184 {
185 for (j=0; !acc_free_list && j<CLIENT_NR; j++)
186 {
187 bf_free_buffsize= 0;
188 if (freereq[j])
189 (*freereq[j])(i, BUF_S);
190 }
191 }
192 }
193 if (!acc_free_list)
194 ip_panic(( "To few accessors" ));
195 new_acc= acc_free_list;
196 acc_free_list= acc_free_list->acc_next;
197 #if DEBUG & 256
198 { where(); printf("got accessor %d\n", new_acc-accessors); }
199 #endif
200 new_acc->acc_linkC= 1;
201 new_acc->acc_buffer= 0;
202
203 #if DEBUG & 256
204 { where(); printf("looking for 512 byte buffer\n"); }
205 #endif
206 if (buf512_free)
207 {
208 buf512_t *buf512;
209
210 #if DEBUG & 256
211 { where(); printf("found a 512 byte buffer\n"); }
212 #endif
213 buf512= buf512_free;
214 buf512_free= buf512->buf_header.buf_next;
215 assert (!buf512->buf_header.buf_linkC);
216 buf512->buf_header.buf_linkC= 1;
217 assert (buf512->buf_header.buf_free == bf_512free);
218 assert (buf512->buf_header.buf_size == sizeof(buf512->buf_data));
219 assert (buf512->buf_header.buf_data_p == buf512->buf_data);
220 new_acc->acc_buffer= &buf512->buf_header;
221 buf512->buf_header.buf_next= buf512;
222 }
223 #if DEBUG
224 else
225 { where(); printf("unable to find a 512 byte buffer\n"); }
226 #endif
227 if (!new_acc->acc_buffer)
228 {
229 #if DEBUG
230 { where(); printf("freeing buffers\n"); }
231 #endif
232 bf_free_buffsize= 0;
233 for (i=0; bf_free_buffsize<size && i<MAX_BUFREQ_PRI;
234 i++)
235 for (j=0; bf_free_buffsize<size && j<CLIENT_NR;
236 j++)
237 if (freereq[j])
238 (*freereq[j])(i, size);
239
240 if (bf_free_buffsize<size)
241 ip_panic(( "not enough buffers freed" ));
242
243 continue;
244 }
245
246
247 if (!head)
248 head= new_acc;
249 else
250 tail->acc_next= new_acc;
251 tail= new_acc;
252
253 count= tail->acc_buffer->buf_size;
254 if (count > size)
255 count= size;
256
257 tail->acc_offset= 0;
258 tail->acc_length= count;
259 size -= count;
260 }
261 tail->acc_next= 0;
262 #if DEBUG
263 bf_chkbuf(head);
264 #endif
265 #if DEBUG & 256
266 { where(); printf("acc 0x%x has buffer 0x%x\n", head, head->acc_buffer); }
267 #endif
268 return head;
269 }
270
271 /*
272 bf_small_memreq
273 */
274
275 PRIVATE acc_t *bf_small_memreq(size)
276 size_t size;
277 {
278 acc_t *head, *tail, *new_acc;
279 int i,j;
280 size_t count;
281
282 #if TRACE_ENQUEUE_PROBLEM
283 { if (enqueue_problem)
284 { where(); printf("bf_small_memreq(%d) called with enqueue_problem\n", size);
285 } }
286 #endif
287 #if DEBUG & 256
288 { where(); printf("bf_small_memreq(%d)\n", size); }
289 #endif
290
291 assert (size>0);
292
293 head= NULL;
294 while (size)
295 {
296 if (!acc_free_list)
297 {
298 #if DEBUG
299 { where(); printf("freeing accessors\n"); }
300 #endif
301 for (i=0; !acc_free_list && i<MAX_BUFREQ_PRI; i++)
302 {
303 for (j=0; !acc_free_list && j<CLIENT_NR; j++)
304 {
305 bf_free_buffsize= 0;
306 if (freereq[j])
307 (*freereq[j])(i, BUF_S);
308 }
309 }
310 }
311 new_acc= acc_free_list;
312 if (!new_acc)
313 ip_panic(( "buf.c: out of accessors" ));
314 acc_free_list= new_acc->acc_next;
315 #if DEBUG & 256
316 { where(); printf("got accessor %d\n", new_acc-accessors); }
317 #endif
318 new_acc->acc_linkC= 1;
319
320 if (size >= sizeof(buf512_free->buf_data))
321 {
322 if (buf512_free)
323 {
324 buf512_t *buf512;
325
326 #if DEBUG & 256
327 { where(); printf("found a 512 byte buffer\n"); }
328 #endif
329 buf512= buf512_free;
330 buf512_free= buf512->buf_header.buf_next;
331 assert (!buf512->buf_header.buf_linkC);
332 buf512->buf_header.buf_linkC= 1;
333 assert (buf512->buf_header.buf_free == bf_512free);
334 assert (buf512->buf_header.buf_size == sizeof(buf512->buf_data));
335 assert (buf512->buf_header.buf_data_p == buf512->buf_data);
336 new_acc->acc_buffer= &buf512->buf_header;
337 buf512->buf_header.buf_next= buf512;
338 }
339 else
340 break;
341 }
342 else
343 break;
344
345 if (!head)
346 head= new_acc;
347 else
348 tail->acc_next= new_acc;
349 tail= new_acc;
350
351 count= tail->acc_buffer->buf_size;
352 if (count > size)
353 count= size;
354
355 tail->acc_offset= 0;
356 tail->acc_length= count;
357 size -= count;
358 }
359 if (size)
360 {
361 new_acc->acc_linkC= 0;
362 new_acc->acc_next= acc_free_list;
363 acc_free_list= new_acc;
364 new_acc= bf_memreq(size);
365 if (!head)
366 head= new_acc;
367 else
368 tail->acc_next= new_acc;
369 }
370 else
371 tail->acc_next= 0;
372 return head;
373 }
374
375 PUBLIC void bf_afree(acc_ptr)
376 acc_t *acc_ptr;
377 {
378 acc_t *tmp_acc;
379 buf_t *tmp_buf;
380
381 while (acc_ptr)
382 {
383 assert (acc_ptr->acc_linkC);
384 acc_ptr->acc_linkC--;
385 if (!acc_ptr->acc_linkC)
386 {
387 tmp_buf= acc_ptr->acc_buffer;
388 assert (tmp_buf);
389 assert (tmp_buf->buf_linkC);
390 if (!--tmp_buf->buf_linkC)
391 {
392 bf_free_buffsize += tmp_buf->buf_size;
393 tmp_buf->buf_free(tmp_buf);
394 }
395 tmp_acc= acc_ptr;
396 acc_ptr= acc_ptr->acc_next;
397 tmp_acc->acc_next= acc_free_list;
398 acc_free_list= tmp_acc;
399 }
400 else
401 break;
402 }
403 }
404
405 PUBLIC acc_t *bf_dupacc(acc_ptr)
406 register acc_t *acc_ptr;
407 {
408 register acc_t *new_acc;
409 int i, j;
410
411 #if TRACE_ENQUEUE_PROBLEM
412 { if (enqueue_problem)
413 { where(); printf("bf_dupacc(0x%x) called with enqueue_problem\n", acc_ptr);
414 } }
415 #endif
416
417
418 if (!acc_free_list)
419 {
420 #if DEBUG
421 { where(); printf("freeing accessors\n"); }
422 #endif
423 for (i=0; !acc_free_list && i<MAX_BUFREQ_PRI; i++)
424 {
425 for (j=0; !acc_free_list && j<CLIENT_NR; j++)
426 {
427 bf_free_buffsize= 0;
428 if (freereq[j])
429 (*freereq[j])(i, BUF_S);
430 }
431 }
432 }
433 new_acc= acc_free_list;
434 if (!new_acc)
435 ip_panic(( "buf.c: out of accessors" ));
436 acc_free_list= new_acc->acc_next;
437 #if DEBUG & 256
438 { where(); printf("got accessor %d\n", new_acc-accessors); }
439 #endif
440
441 *new_acc= *acc_ptr;
442 if (acc_ptr->acc_next)
443 acc_ptr->acc_next->acc_linkC++;
444 if (acc_ptr->acc_buffer)
445 acc_ptr->acc_buffer->buf_linkC++;
446 new_acc->acc_linkC= 1;
447 return new_acc;
448 }
449
450 #ifdef bf_bufsize
451 PUBLIC size_t _bf_bufsize(acc_ptr)
452 #else
453 PUBLIC size_t bf_bufsize(acc_ptr)
454 #endif
455 register acc_t *acc_ptr;
456 {
457 register size_t size;
458
459 #ifdef bf_bufsize
460 { where(); printf("bf_bufsize(0x%x) called by %s, %d\n", acc_ptr,
461 bf_bufsize_file, bf_bufsize_line); }
462 #endif
463
464 assert(acc_ptr);
465
466 size=0;
467
468 while (acc_ptr)
469 {
470 assert(acc_ptr >= accessors && acc_ptr <= &accessors[ACC_NR-1]);
471 size += acc_ptr->acc_length;
472 acc_ptr= acc_ptr->acc_next;
473 }
474 #if DEBUG & 256
475 { where(); printf("bf_bufsize(...)= %d\n", size); }
476 #endif
477 return size;
478 }
479
480 #ifndef bf_packIffLess
481 PUBLIC acc_t *bf_packIffLess(pack, min_len)
482 #else
483 PUBLIC acc_t *_bf_packIffLess(pack, min_len)
484 #endif
485 acc_t *pack;
486 int min_len;
487 {
488 if (!pack || pack->acc_length >= min_len)
489 return pack;
490
491 #ifdef bf_packIffLess
492 { where(); printf("calling bf_pack because of %s %d: %d\n", bf_pack_file,
493 bf_pack_line, min_len); }
494 #endif
495 return bf_pack(pack);
496 }
497
498 PUBLIC acc_t *bf_pack(old_acc)
499 acc_t *old_acc;
500 {
501 acc_t *new_acc, *acc_ptr_old, *acc_ptr_new;
502 size_t size, offset_old, offset_new, block_size, block_size_old;
503
504 /* Check if old acc is good enough. */
505 if (!old_acc || !old_acc->acc_next && old_acc->acc_linkC == 1 &&
506 (!old_acc->acc_buffer || old_acc->acc_buffer->buf_linkC == 1))
507 return old_acc;
508
509 size= bf_bufsize(old_acc);
510 new_acc= bf_memreq(size);
511 acc_ptr_old= old_acc;
512 acc_ptr_new= new_acc;
513 offset_old= 0;
514 offset_new= 0;
515 while (size)
516 {
517 assert (acc_ptr_old);
518 if (offset_old == acc_ptr_old->acc_length)
519 {
520 offset_old= 0;
521 acc_ptr_old= acc_ptr_old->acc_next;
522 continue;
523 }
524 assert (offset_old < acc_ptr_old->acc_length);
525 block_size_old= acc_ptr_old->acc_length - offset_old;
526 assert (acc_ptr_new);
527 if (offset_new == acc_ptr_new->acc_length)
528 {
529 offset_new= 0;
530 acc_ptr_new= acc_ptr_new->acc_next;
531 continue;
532 }
533 assert (offset_new < acc_ptr_new->acc_length);
534 block_size= acc_ptr_new->acc_length - offset_new;
535 if (block_size > block_size_old)
536 block_size= block_size_old;
537 memcpy(ptr2acc_data(acc_ptr_new)+offset_new,
538 ptr2acc_data(acc_ptr_old)+offset_old, block_size);
539 offset_new += block_size;
540 offset_old += block_size;
541 size -= block_size;
542 }
543 bf_afree(old_acc);
544 return new_acc;
545 }
546
547 #ifndef bf_cut
548 PUBLIC acc_t *bf_cut (data, offset, length)
549 #else
550 PUBLIC acc_t *_bf_cut (data, offset, length)
551 #endif
552 register acc_t *data;
553 register unsigned offset;
554 register unsigned length;
555 {
556 register acc_t *head, *tail;
557
558 #if DEBUG & 256
559 { where(); printf("bf_cut(.., %u, %u) called\n", offset, length); }
560 #ifdef bf_cut
561 { where(); printf("bf_cut_file= %s, bf_cut_line= %d\n", bf_cut_file,
562 bf_cut_line); }
563 #endif
564 #endif
565 if (!data && !offset && !length)
566 return 0;
567 #ifdef bf_cut
568 if (!data)
569 { where(); printf("bf_cut_file= %s, bf_cut_line= %d\n", bf_cut_file,
570 bf_cut_line); }
571 #endif
572 assert(data);
573 #if DEBUG
574 bf_chkbuf(data);
575 #endif
576 if (!length)
577 {
578 head= bf_dupacc(data);
579 bf_afree(head->acc_next);
580 head->acc_next= 0;
581 head->acc_length= 0;
582 #if DEBUG
583 bf_chkbuf(data);
584 #endif
585 return head;
586 }
587 while (data && offset>=data->acc_length)
588 {
589 offset -= data->acc_length;
590 data= data->acc_next;
591 }
592 #ifdef bf_cut
593 if (!data)
594 { where(); printf("bf_cut_file= %s, bf_cut_line= %d\n", bf_cut_file,
595 bf_cut_line); }
596 #endif
597 assert (data);
598 head= bf_dupacc(data);
599 bf_afree(head->acc_next);
600 head->acc_next= 0;
601 head->acc_offset += offset;
602 head->acc_length -= offset;
603 if (length >= head->acc_length)
604 length -= head->acc_length;
605 else
606 {
607 head->acc_length= length;
608 length= 0;
609 }
610 tail= head;
611 data= data->acc_next;
612 while (data && length && length>=data->acc_length)
613 {
614 tail->acc_next= bf_dupacc(data);
615 tail= tail->acc_next;
616 bf_afree(tail->acc_next);
617 tail->acc_next= 0;
618 data= data->acc_next;
619 length -= tail->acc_length;
620 }
621 if (length)
622 {
623 #ifdef bf_cut
624 if (!data)
625 { where(); printf("bf_cut_file= %s, bf_cut_line= %d\n", bf_cut_file,
626 bf_cut_line); }
627 #endif
628 assert (data);
629 tail->acc_next= bf_dupacc(data);
630 tail= tail->acc_next;
631 bf_afree(tail->acc_next);
632 tail->acc_next= 0;
633 tail->acc_length= length;
634 }
635 #if DEBUG
636 bf_chkbuf(data);
637 #endif
638 return head;
639 }
640
641 /*
642 bf_append
643 */
644
645 PUBLIC acc_t *bf_append(data_first, data_second)
646 acc_t *data_first;
647 acc_t *data_second;
648 {
649 acc_t *head, *tail, *new_acc, *acc_ptr_new, tmp_acc, *curr;
650 char *src_ptr, *dst_ptr;
651 size_t size, offset_old, offset_new, block_size_old, block_size;
652
653 #if TRACE_ENQUEUE_PROBLEM
654 { if (enqueue_problem)
655 { where(); printf("bf_append(0x%x, 0x%x) called with enqueue_problem\n",
656 data_first, data_second); } }
657 #endif
658 #if DEBUG & 256
659 { where(); printf("BF_Append(0x%x, 0x%x) called\n", data_first, data_second); }
660 #endif
661 if (!data_first)
662 return data_second;
663 if (!data_second)
664 return data_first;
665
666 head= 0;
667 while (data_first)
668 {
669 if (data_first->acc_linkC == 1)
670 curr= data_first;
671 else
672 {
673 curr= bf_dupacc(data_first);
674 assert (curr->acc_linkC == 1);
675 bf_afree(data_first);
676 }
677 data_first= curr->acc_next;
678 if (!curr->acc_length)
679 {
680 curr->acc_next= 0;
681 bf_afree(curr);
682 continue;
683 }
684 if (!head)
685 head= curr;
686 else
687 tail->acc_next= curr;
688 tail= curr;
689 }
690 if (!head)
691 return data_second;
692 tail->acc_next= 0;
693
694 while (data_second && !data_second->acc_length)
695 {
696 curr= data_second;
697 data_second= data_second->acc_next;
698 if (data_second)
699 data_second->acc_linkC++;
700 bf_afree(curr);
701 }
702 if (!data_second)
703 return head;
704
705 if (tail->acc_length + data_second->acc_length >
706 tail->acc_buffer->buf_size)
707 {
708 tail->acc_next= data_second;
709 return head;
710 }
711
712 if (tail->acc_buffer->buf_size == bf_buf_gran &&
713 tail->acc_buffer->buf_linkC == 1)
714 {
715 if (tail->acc_offset)
716 {
717 memmove(tail->acc_buffer->buf_data_p,
718 ptr2acc_data(tail), tail->acc_length);
719 tail->acc_offset= 0;
720 }
721 dst_ptr= ptr2acc_data(tail) + tail->acc_length;
722 src_ptr= ptr2acc_data(data_second);
723 memcpy(dst_ptr, src_ptr, data_second->acc_length);
724 tail->acc_length += data_second->acc_length;
725 tail->acc_next= data_second->acc_next;
726 if (data_second->acc_next)
727 data_second->acc_next->acc_linkC++;
728 bf_afree(data_second);
729 return head;
730 }
731
732 new_acc= bf_small_memreq(tail->acc_length+data_second->acc_length);
733 acc_ptr_new= new_acc;
734 offset_old= 0;
735 offset_new= 0;
736 size= tail->acc_length;
737 while (size)
738 {
739 assert (acc_ptr_new);
740 if (offset_new == acc_ptr_new->acc_length)
741 {
742 offset_new= 0;
743 acc_ptr_new= acc_ptr_new->acc_next;
744 continue;
745 }
746 assert (offset_new < acc_ptr_new->acc_length);
747 assert (offset_old < tail->acc_length);
748 block_size_old= tail->acc_length - offset_old;
749 block_size= acc_ptr_new->acc_length - offset_new;
750 if (block_size > block_size_old)
751 block_size= block_size_old;
752 memcpy(ptr2acc_data(acc_ptr_new)+offset_new,
753 ptr2acc_data(tail)+offset_old, block_size);
754 offset_new += block_size;
755 offset_old += block_size;
756 size -= block_size;
757 }
758 offset_old= 0;
759 size= data_second->acc_length;
760 while (size)
761 {
762 assert (acc_ptr_new);
763 if (offset_new == acc_ptr_new->acc_length)
764 {
765 offset_new= 0;
766 acc_ptr_new= acc_ptr_new->acc_next;
767 continue;
768 }
769 assert (offset_new < acc_ptr_new->acc_length);
770 assert (offset_old < data_second->acc_length);
771 block_size_old= data_second->acc_length - offset_old;
772 block_size= acc_ptr_new->acc_length - offset_new;
773 if (block_size > block_size_old)
774 block_size= block_size_old;
775 memcpy(ptr2acc_data(acc_ptr_new)+offset_new,
776 ptr2acc_data(data_second)+offset_old, block_size);
777 offset_new += block_size;
778 offset_old += block_size;
779 size -= block_size;
780 }
781 tmp_acc= *tail;
782 *tail= *new_acc;
783 *new_acc= tmp_acc;
784
785 bf_afree(new_acc);
786 while (tail->acc_next)
787 tail= tail->acc_next;
788
789 tail->acc_next= data_second->acc_next;
790 if (data_second->acc_next)
791 data_second->acc_next->acc_linkC++;
792 bf_afree(data_second);
793 return head;
794 }
795
796 PRIVATE void bf_512free(buffer)
797 buf_t *buffer;
798 {
799 buf512_t *buf512;
800
801 buf512= buffer->buf_next;
802 buf512->buf_header.buf_next= buf512_free;
803 buf512_free= buf512;
804 }
805
806 PUBLIC void bf_check_all_bufs()
807 {
808 int j;
809 int accs;
810 acc_t *acc;
811 int bufs;
812 buf512_t *buf512;
813
814 for (j=0; j<CLIENT_NR; j++)
815 {
816 if (freereq[j])
817 (*freereq[j])(-1, 0);
818 }
819
820 /* Check the number of accessors */
821 accs= 0;
822 for(acc= acc_free_list; acc; acc= acc->acc_next)
823 accs++;
824 printf("number of free accs is %d, expected %d\n", accs, ACC_NR);
825
826 /* Check the number of 512 byte buffers */
827 bufs= 0;
828 for(buf512= buf512_free; buf512; buf512=
829 (buf512_t *)buf512->buf_header.buf_next)
830 bufs++;
831
832 printf("number of free 512 byte buffers is %d, expected %d\n", bufs,
833 BUF512_NR);
834 }
835
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.