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) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
30 #include <sys/statvfs.h>
31 #include <sys/param.h>
42 minfree_open(const char *dir
, int oflags
, const char *fmode
)
44 char path
[MAXPATHLEN
];
47 (void) snprintf(path
, sizeof (path
), "%s/minfree", dir
);
49 if ((fd
= open(path
, oflags
, S_IRUSR
| S_IWUSR
)) >= 0)
50 return (fdopen(fd
, fmode
));
56 minfree_read(const char *dir
, unsigned long long *ullp
)
58 FILE *fp
= minfree_open(dir
, O_RDONLY
, "r");
64 if (fgets(buf
, BUFSIZ
, fp
) != NULL
) {
65 if (valid_str2ull(buf
, ullp
))
68 warn(gettext("\"%s/minfree\": invalid minfree "
69 "value -- %s\n"), dir
, buf
);
80 minfree_write(const char *dir
, unsigned long long ull
)
82 FILE *fp
= minfree_open(dir
, O_WRONLY
| O_CREAT
| O_TRUNC
, "w");
85 int status
= fprintf(fp
, "%llu\n", ull
);
94 minfree_compute(const char *dir
, char *s
, unsigned long long *ullp
)
96 size_t len
= strlen(s
);
97 unsigned long long m
= 1;
102 switch (s
[len
- 1]) {
106 if (!valid_str2int(s
, &pct
) || pct
> 100) {
107 warn(gettext("invalid minfree %% -- %s\n"), s
);
111 if (statvfs64(dir
, &fsb
) == -1) {
112 warn(gettext("failed to statvfs %s"), dir
);
116 *ullp
= fsb
.f_blocks
* fsb
.f_frsize
*
117 (u_longlong_t
)pct
/ 100ULL / 1024ULL;
130 if (valid_str2ull(s
, ullp
)) {
135 warn(gettext("invalid minfree value -- %s\n"), s
);
139 warn(gettext("expected m, k, or %% unit after "
140 "minfree -- %s\n"), s
);