]>
Commit | Line | Data |
---|---|---|
59e0d9fe A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
59e0d9fe A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | /* | |
25 | * sys/statvfs.c | |
26 | */ | |
27 | #include <sys/param.h> | |
28 | #include <sys/mount.h> | |
29 | ||
30 | #include <sys/statvfs.h> /* glue header */ | |
31 | ||
32 | ||
33 | /* Internal common conversion function */ | |
34 | static void | |
35 | cvt_statfs_to_statvfs(struct statfs *from, struct statvfs *to) | |
36 | { | |
37 | to->f_bsize = from->f_iosize; | |
38 | to->f_frsize = from->f_bsize; | |
39 | to->f_blocks = from->f_blocks; | |
40 | to->f_bfree = from->f_bfree; | |
41 | to->f_bavail = from->f_bavail; | |
42 | to->f_files = from->f_files; | |
43 | to->f_ffree = from->f_ffree; | |
44 | to->f_favail = from->f_ffree; | |
45 | to->f_fsid = from->f_fsid.val[0]; /* XXX bad if non-root */ | |
46 | to->f_namemax = NAME_MAX; /* XXX should be per FS */ | |
47 | ||
48 | /* Conver FS flags */ | |
49 | to->f_flag = 0; | |
50 | if( from->f_flags & MNT_RDONLY) | |
51 | to->f_flag |= ST_RDONLY; | |
52 | if( from->f_flags & MNT_NOSUID) | |
53 | to->f_flag |= ST_NOSUID; | |
54 | ||
55 | return; | |
56 | } | |
57 | ||
58 | ||
59 | int | |
60 | fstatvfs(int fildes, struct statvfs *buf) | |
61 | { | |
62 | int rv; | |
63 | struct statfs cvt; | |
64 | ||
65 | if ((rv = fstatfs(fildes, &cvt)) == 0) | |
66 | cvt_statfs_to_statvfs(&cvt, buf); | |
67 | ||
68 | return(rv); | |
69 | } | |
70 | ||
71 | ||
72 | int | |
73 | statvfs(const char * __restrict path, struct statvfs * __restrict buf) | |
74 | { | |
75 | int rv; | |
76 | struct statfs cvt; | |
77 | ||
78 | if ((rv = statfs(path, &cvt)) == 0) | |
79 | cvt_statfs_to_statvfs(&cvt, buf); | |
80 | ||
81 | return(rv); | |
82 | } | |
83 | ||
84 | /* EOF */ |