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
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]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
41 #define FDS_TABLE_SIZE 1024
43 static fd_t
*fd_tbl
= NULL
;
46 static int fd_cnt_cur
;
47 static int fd_cnt_old
;
48 static fds_t
*fds_tbl
[FDS_TABLE_SIZE
];
54 fd_cnt
= fd_cnt_cur
= fd_cnt_old
= 0;
55 fd_tbl
= Zalloc(sizeof (fd_t
) * n
);
56 (void) memset(fds_tbl
, 0, sizeof (fds_t
*) * FDS_TABLE_SIZE
);
70 if (fdp
->fd_fd
>= 0 && fdp
->fd_name
[0] != '\0') {
71 (void) close(fdp
->fd_fd
);
75 (void) memset(fdp
, 0, sizeof (fd_t
));
86 for (i
= 0; i
< fd_max
; i
++) {
99 counter
= abs(fd_cnt_old
- fd_cnt
) + NUM_RESERVED_FD
;
101 for (i
= 0; i
< fd_max
; i
++, fdp
++) {
103 if (fdp
->fd_fd
== -1)
104 continue; /* skip recycled ones */
106 if (fdp
->fd_name
[0] != '\0') { /* file has name */
107 (void) close(fdp
->fd_fd
);
119 fd_open(char *name
, int flags
, fd_t
*fdp
)
124 if (fd_cnt
> fd_max
- NUM_RESERVED_FD
)
128 if ((strcmp(fdp
->fd_name
, name
) == 0) && (fdp
->fd_fd
>= 0)) {
134 again
: fd
= open(name
, flags
);
137 if ((errno
== EMFILE
) || (errno
== ENFILE
)) {
143 fdp_new
= &fd_tbl
[fd
];
145 fdp_new
->fd_flags
= flags
;
146 (void) strcpy(fdp_new
->fd_name
, name
);
162 fd_cnt_old
= fd_cnt_cur
;
170 int hash
= pid
% FDS_TABLE_SIZE
;
172 for (fdsp
= fds_tbl
[hash
]; fdsp
; fdsp
= fdsp
->fds_next
)
173 if (fdsp
->fds_pid
== pid
) /* searching for pid */
176 fdsp
= Zalloc(sizeof (fds_t
)); /* adding new if pid was not found */
178 fdsp
->fds_next
= fds_tbl
[hash
];
179 fds_tbl
[hash
] = fdsp
;
187 fds_t
*fds_prev
= NULL
;
188 int hash
= pid
% FDS_TABLE_SIZE
;
190 for (fds
= fds_tbl
[hash
]; fds
&& fds
->fds_pid
!= pid
;
191 fds
= fds
->fds_next
) /* finding pid */
194 if (fds
) { /* if pid was found */
196 fd_close(fds
->fds_psinfo
);
197 fd_close(fds
->fds_usage
);
198 fd_close(fds
->fds_lpsinfo
);
199 fd_close(fds
->fds_lusage
);
202 fds_prev
->fds_next
= fds
->fds_next
;
204 fds_tbl
[hash
] = fds
->fds_next
;