1 /* $NetBSD: compat_statfs.c,v 1.4 2008/04/28 20:22:59 martin Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 __RCSID("$NetBSD: compat_statfs.c,v 1.4 2008/04/28 20:22:59 martin Exp $");
35 #endif /* LIBC_SCCS and not lint */
37 #define __LIBC12_SOURCE__
39 #include "namespace.h"
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/mount.h>
43 #include <compat/sys/mount.h>
44 #include <compat/include/fstypes.h>
48 __warn_references(statfs
,
49 "warning: reference to obsolete statfs(); use statvfs()")
51 __warn_references(fstatfs
,
52 "warning: reference to obsolete fstatfs(); use fstatvfs()")
54 __warn_references(fhstatfs
,
55 "warning: reference to obsolete fhstatfs(); use fhstatvfs()")
57 __warn_references(getfsstat
,
58 "warning: reference to obsolete getfsstat(); use getvfsstat()")
61 * Convert from a new statvfs to an old statfs structure.
64 static void vfs2fs(struct statfs12
*, const struct statvfs
*);
66 #define MOUNTNO_NONE 0
67 #define MOUNTNO_UFS 1 /* UNIX "Fast" Filesystem */
68 #define MOUNTNO_NFS 2 /* Network Filesystem */
69 #define MOUNTNO_MFS 3 /* Memory Filesystem */
70 #define MOUNTNO_MSDOS 4 /* MSDOS Filesystem */
71 #define MOUNTNO_CD9660 5 /* iso9660 cdrom */
72 #define MOUNTNO_FDESC 6 /* /dev/fd filesystem */
73 #define MOUNTNO_KERNFS 7 /* kernel variable filesystem */
74 #define MOUNTNO_DEVFS 8 /* device node filesystem */
75 #define MOUNTNO_AFS 9 /* AFS 3.x */
80 { MOUNT_UFS
, MOUNTNO_UFS
},
81 { MOUNT_NFS
, MOUNTNO_NFS
},
82 { MOUNT_MFS
, MOUNTNO_MFS
},
83 { MOUNT_MSDOS
, MOUNTNO_MSDOS
},
84 { MOUNT_CD9660
, MOUNTNO_CD9660
},
85 { MOUNT_FDESC
, MOUNTNO_FDESC
},
86 { MOUNT_KERNFS
, MOUNTNO_KERNFS
},
87 { MOUNT_AFS
, MOUNTNO_AFS
},
91 vfs2fs(struct statfs12
*bfs
, const struct statvfs
*fs
)
95 bfs
->f_oflags
= (short)fs
->f_flag
;
97 for (i
= 0; i
< sizeof(nv
) / sizeof(nv
[0]); i
++) {
98 if (strcmp(nv
[i
].name
, fs
->f_fstypename
) == 0) {
99 bfs
->f_type
= nv
[i
].value
;
103 #define CLAMP(a) (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
104 bfs
->f_bsize
= CLAMP(fs
->f_frsize
);
105 bfs
->f_iosize
= CLAMP(fs
->f_iosize
);
106 bfs
->f_blocks
= CLAMP(fs
->f_blocks
);
107 bfs
->f_bfree
= CLAMP(fs
->f_bfree
);
108 if (fs
->f_bfree
> fs
->f_bresvd
)
109 bfs
->f_bavail
= CLAMP(fs
->f_bfree
- fs
->f_bresvd
);
111 bfs
->f_bavail
= -CLAMP(fs
->f_bresvd
- fs
->f_bfree
);
112 bfs
->f_files
= CLAMP(fs
->f_files
);
113 bfs
->f_ffree
= CLAMP(fs
->f_ffree
);
114 bfs
->f_fsid
= fs
->f_fsidx
;
115 bfs
->f_owner
= fs
->f_owner
;
116 bfs
->f_flags
= (long)fs
->f_flag
;
117 bfs
->f_syncwrites
= CLAMP(fs
->f_syncwrites
);
118 bfs
->f_asyncwrites
= CLAMP(fs
->f_asyncwrites
);
119 (void)strncpy(bfs
->f_fstypename
, fs
->f_fstypename
,
120 sizeof(bfs
->f_fstypename
));
121 (void)strncpy(bfs
->f_mntonname
, fs
->f_mntonname
,
122 sizeof(bfs
->f_mntonname
));
123 (void)strncpy(bfs
->f_mntfromname
, fs
->f_mntfromname
,
124 sizeof(bfs
->f_mntfromname
));
128 statfs(const char *file
, struct statfs12
*ost
)
133 if ((ret
= statvfs(file
, &nst
)) == -1)
140 fstatfs(int f
, struct statfs12
*ost
)
145 if ((ret
= fstatvfs(f
, &nst
)) == -1)
151 int __fhstatvfs140(const void *fhp
, size_t fh_size
, struct statvfs
*buf
,
155 fhstatfs(const struct compat_30_fhandle
*fh
, struct statfs12
*ost
)
160 if ((ret
= __fhstatvfs140(fh
, FHANDLE30_SIZE
, &nst
, ST_WAIT
)) == -1)
167 getfsstat(struct statfs12
*ost
, long size
, int flags
)
171 size_t bsize
= (size_t)(size
/ sizeof(*ost
)) * sizeof(*nst
);
174 if ((nst
= malloc(bsize
)) == NULL
)
179 if ((ret
= getvfsstat(nst
, bsize
, flags
)) == -1)
182 for (i
= 0; i
< ret
; i
++)
183 vfs2fs(&ost
[i
], &nst
[i
]);