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.
39 #define FDS_TABLE_SIZE 1024
41 static fd_t
*fd_tbl
= NULL
;
44 static int fd_cnt_cur
;
45 static int fd_cnt_old
;
46 static fds_t
*fds_tbl
[FDS_TABLE_SIZE
];
52 fd_cnt
= fd_cnt_cur
= fd_cnt_old
= 0;
53 fd_tbl
= Zalloc(sizeof (fd_t
) * n
);
54 (void) memset(fds_tbl
, 0, sizeof (fds_t
*) * FDS_TABLE_SIZE
);
67 if (fdp
->fd_fd
>= 0 && fdp
->fd_name
[0] != '\0') {
68 (void) close(fdp
->fd_fd
);
72 (void) memset(fdp
, 0, sizeof (fd_t
));
83 for (i
= 0; i
< fd_max
; i
++) {
96 counter
= abs(fd_cnt_old
- fd_cnt
) + NUM_RESERVED_FD
;
98 for (i
= 0; i
< fd_max
; i
++, fdp
++) {
100 if (fdp
->fd_fd
== -1)
101 continue; /* skip recycled ones */
103 if (fdp
->fd_name
[0] != '\0') { /* file has name */
104 (void) close(fdp
->fd_fd
);
116 fd_open(char *name
, int flags
, fd_t
*fdp
)
121 if (fd_cnt
> fd_max
- NUM_RESERVED_FD
)
125 if ((strcmp(fdp
->fd_name
, name
) == 0) && (fdp
->fd_fd
>= 0)) {
131 again
: fd
= open(name
, flags
);
134 if ((errno
== EMFILE
) || (errno
== ENFILE
)) {
140 fdp_new
= &fd_tbl
[fd
];
142 fdp_new
->fd_flags
= flags
;
143 (void) strcpy(fdp_new
->fd_name
, name
);
159 fd_cnt_old
= fd_cnt_cur
;
167 int hash
= pid
% FDS_TABLE_SIZE
;
169 for (fdsp
= fds_tbl
[hash
]; fdsp
; fdsp
= fdsp
->fds_next
)
170 if (fdsp
->fds_pid
== pid
) /* searching for pid */
173 fdsp
= Zalloc(sizeof (fds_t
)); /* adding new if pid was not found */
175 fdsp
->fds_next
= fds_tbl
[hash
];
176 fds_tbl
[hash
] = fdsp
;
184 fds_t
*fds_prev
= NULL
;
185 int hash
= pid
% FDS_TABLE_SIZE
;
187 for (fds
= fds_tbl
[hash
]; fds
&& fds
->fds_pid
!= pid
;
188 fds
= fds
->fds_next
) /* finding pid */
191 if (fds
) { /* if pid was found */
193 fd_close(fds
->fds_psinfo
);
194 fd_close(fds
->fds_usage
);
195 fd_close(fds
->fds_lpsinfo
);
196 fd_close(fds
->fds_lusage
);
199 fds_prev
->fds_next
= fds
->fds_next
;
201 fds_tbl
[hash
] = fds
->fds_next
;