2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #include "dir_stack.h"
35 #include "err_protos.h"
38 * a directory stack for holding directories while
39 * we traverse filesystem hierarchy subtrees.
40 * names are kind of misleading as this is really
41 * implemented as an inode stack. so sue me...
44 static dir_stack_t dirstack_freelist
;
45 static int dirstack_init
= 0;
48 dir_stack_init(dir_stack_t
*stack
)
53 if (dirstack_init
== 0) {
55 dir_stack_init(&dirstack_freelist
);
65 dir_stack_push(dir_stack_t
*stack
, dir_stack_elem_t
*elem
)
67 ASSERT(stack
->cnt
> 0 || (stack
->cnt
== 0 && stack
->head
== NULL
));
69 elem
->next
= stack
->head
;
76 static dir_stack_elem_t
*
77 dir_stack_pop(dir_stack_t
*stack
)
79 dir_stack_elem_t
*elem
;
81 if (stack
->cnt
== 0) {
82 ASSERT(stack
->head
== NULL
);
90 stack
->head
= elem
->next
;
98 push_dir(dir_stack_t
*stack
, xfs_ino_t ino
)
100 dir_stack_elem_t
*elem
;
102 if (dirstack_freelist
.cnt
== 0) {
103 if ((elem
= malloc(sizeof(dir_stack_elem_t
))) == NULL
) {
105 "couldn't malloc dir stack element, try more swap\n");
109 elem
= dir_stack_pop(&dirstack_freelist
);
114 dir_stack_push(stack
, elem
);
120 pop_dir(dir_stack_t
*stack
)
122 dir_stack_elem_t
*elem
;
125 elem
= dir_stack_pop(stack
);
131 elem
->ino
= NULLFSINO
;
133 dir_stack_push(&dirstack_freelist
, elem
);