1 /* $NetBSD: compat_statfs.c,v 1.7 2013/10/04 21:07:37 christos 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.7 2013/10/04 21:07:37 christos 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()")
60 __strong_alias(statfs
, __compat_statfs
)
61 __strong_alias(fstatfs
, __compat_fstatfs
)
62 __strong_alias(fhstatfs
, __compat_fhstatfs
)
63 __strong_alias(getfsstat
, __compat_getfsstat
)
66 * Convert from a new statvfs to an old statfs structure.
69 static void vfs2fs(struct statfs12
*, const struct statvfs
*);
71 #define MOUNTNO_NONE 0
72 #define MOUNTNO_UFS 1 /* UNIX "Fast" Filesystem */
73 #define MOUNTNO_NFS 2 /* Network Filesystem */
74 #define MOUNTNO_MFS 3 /* Memory Filesystem */
75 #define MOUNTNO_MSDOS 4 /* MSDOS Filesystem */
76 #define MOUNTNO_CD9660 5 /* iso9660 cdrom */
77 #define MOUNTNO_FDESC 6 /* /dev/fd filesystem */
78 #define MOUNTNO_KERNFS 7 /* kernel variable filesystem */
79 #define MOUNTNO_DEVFS 8 /* device node filesystem */
80 #define MOUNTNO_AFS 9 /* AFS 3.x */
85 { MOUNT_UFS
, MOUNTNO_UFS
},
86 { MOUNT_NFS
, MOUNTNO_NFS
},
87 { MOUNT_MFS
, MOUNTNO_MFS
},
88 { MOUNT_MSDOS
, MOUNTNO_MSDOS
},
89 { MOUNT_CD9660
, MOUNTNO_CD9660
},
90 { MOUNT_FDESC
, MOUNTNO_FDESC
},
91 { MOUNT_KERNFS
, MOUNTNO_KERNFS
},
92 { MOUNT_AFS
, MOUNTNO_AFS
},
96 vfs2fs(struct statfs12
*bfs
, const struct statvfs
*fs
)
100 bfs
->f_oflags
= (short)fs
->f_flag
;
102 for (i
= 0; i
< sizeof(nv
) / sizeof(nv
[0]); i
++) {
103 if (strcmp(nv
[i
].name
, fs
->f_fstypename
) == 0) {
104 bfs
->f_type
= nv
[i
].value
;
108 #define CLAMP(a) (long)(((a) & ~LONG_MAX) ? LONG_MAX : (a))
109 bfs
->f_bsize
= CLAMP(fs
->f_frsize
);
110 bfs
->f_iosize
= CLAMP(fs
->f_iosize
);
111 bfs
->f_blocks
= CLAMP(fs
->f_blocks
);
112 bfs
->f_bfree
= CLAMP(fs
->f_bfree
);
113 if (fs
->f_bfree
> fs
->f_bresvd
)
114 bfs
->f_bavail
= CLAMP(fs
->f_bfree
- fs
->f_bresvd
);
116 bfs
->f_bavail
= -CLAMP(fs
->f_bresvd
- fs
->f_bfree
);
117 bfs
->f_files
= CLAMP(fs
->f_files
);
118 bfs
->f_ffree
= CLAMP(fs
->f_ffree
);
119 bfs
->f_fsid
= fs
->f_fsidx
;
120 bfs
->f_owner
= fs
->f_owner
;
121 bfs
->f_flags
= (long)fs
->f_flag
;
122 bfs
->f_syncwrites
= CLAMP(fs
->f_syncwrites
);
123 bfs
->f_asyncwrites
= CLAMP(fs
->f_asyncwrites
);
124 (void)strncpy(bfs
->f_fstypename
, fs
->f_fstypename
,
125 sizeof(bfs
->f_fstypename
));
126 (void)strncpy(bfs
->f_mntonname
, fs
->f_mntonname
,
127 sizeof(bfs
->f_mntonname
));
128 (void)strncpy(bfs
->f_mntfromname
, fs
->f_mntfromname
,
129 sizeof(bfs
->f_mntfromname
));
133 __compat_statfs(const char *file
, struct statfs12
*ost
)
138 if ((ret
= statvfs(file
, &nst
)) == -1)
145 __compat_fstatfs(int f
, struct statfs12
*ost
)
150 if ((ret
= fstatvfs(f
, &nst
)) == -1)
156 int __fhstatvfs140(const void *fhp
, size_t fh_size
, struct statvfs
*buf
,
160 __compat_fhstatfs(const struct compat_30_fhandle
*fh
, struct statfs12
*ost
)
165 if ((ret
= __fhstatvfs140(fh
, FHANDLE30_SIZE
, &nst
, ST_WAIT
)) == -1)
172 __compat_getfsstat(struct statfs12
*ost
, long size
, int flags
)
176 size_t bsize
= (size_t)(size
/ sizeof(*ost
)) * sizeof(*nst
);
179 if ((nst
= malloc(bsize
)) == NULL
)
184 if ((ret
= getvfsstat(nst
, bsize
, flags
)) == -1)
187 for (i
= 0; i
< ret
; i
++)
188 vfs2fs(&ost
[i
], &nst
[i
]);