2 Unix SMB/CIFS implementation.
3 VFS API's statvfs abstraction
4 Copyright (C) Alexander Bokovoy 2005
5 Copyright (C) Steve French 2005
6 Copyright (C) James Peach 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "system/filesys.h"
24 #include "smbd/smbd.h"
30 static int darwin_fs_capabilities(const char * path
)
33 vol_capabilities_attr_t
*vcaps
;
34 struct attrlist attrlist
;
35 char attrbuf
[sizeof(u_int32_t
) + sizeof(vol_capabilities_attr_t
)];
37 #define FORMAT_CAP(vinfo, cap) \
38 ( ((vinfo)->valid[VOL_CAPABILITIES_FORMAT] & (cap)) && \
39 ((vinfo)->capabilities[VOL_CAPABILITIES_FORMAT] & (cap)) )
41 #define INTERFACE_CAP(vinfo, cap) \
42 ( ((vinfo)->valid[VOL_CAPABILITIES_INTERFACES] & (cap)) && \
43 ((vinfo)->capabilities[VOL_CAPABILITIES_INTERFACES] & (cap)) )
45 ZERO_STRUCT(attrlist
);
46 attrlist
.bitmapcount
= ATTR_BIT_MAP_COUNT
;
47 attrlist
.volattr
= ATTR_VOL_CAPABILITIES
;
49 if (getattrlist(path
, &attrlist
, attrbuf
, sizeof(attrbuf
), 0) != 0) {
50 DEBUG(0, ("getattrlist for %s capabilities failed: %s\n",
51 path
, strerror(errno
)));
52 /* Return no capabilities on failure. */
57 (vol_capabilities_attr_t
*)(attrbuf
+ sizeof(u_int32_t
));
59 if (FORMAT_CAP(vcaps
, VOL_CAP_FMT_SPARSE_FILES
)) {
60 caps
|= FILE_SUPPORTS_SPARSE_FILES
;
63 if (FORMAT_CAP(vcaps
, VOL_CAP_FMT_CASE_SENSITIVE
)) {
64 caps
|= FILE_CASE_SENSITIVE_SEARCH
;
67 if (FORMAT_CAP(vcaps
, VOL_CAP_FMT_CASE_PRESERVING
)) {
68 caps
|= FILE_CASE_PRESERVED_NAMES
;
71 if (INTERFACE_CAP(vcaps
, VOL_CAP_INT_EXTENDED_SECURITY
)) {
72 caps
|= FILE_PERSISTENT_ACLS
;
78 static int darwin_statvfs(const char *path
, vfs_statvfs_struct
*statbuf
)
83 ret
= statfs(path
, &sbuf
);
88 statbuf
->OptimalTransferSize
= sbuf
.f_iosize
;
89 statbuf
->BlockSize
= sbuf
.f_bsize
;
90 statbuf
->TotalBlocks
= sbuf
.f_blocks
;
91 statbuf
->BlocksAvail
= sbuf
.f_bfree
;
92 statbuf
->UserBlocksAvail
= sbuf
.f_bavail
;
93 statbuf
->TotalFileNodes
= sbuf
.f_files
;
94 statbuf
->FreeFileNodes
= sbuf
.f_ffree
;
95 statbuf
->FsIdentifier
= *(uint64_t *)(&sbuf
.f_fsid
); /* Ick. */
96 statbuf
->FsCapabilities
= darwin_fs_capabilities(sbuf
.f_mntonname
);
100 #elif defined(BSD) && defined(BSD_STATVFS_BSIZE)
101 static int bsd_statvfs(const char *path
, vfs_statvfs_struct
*statbuf
)
103 struct statfs statfs_buf
;
106 result
= statfs(path
, &statfs_buf
);
111 statbuf
->OptimalTransferSize
= statfs_buf
.f_iosize
;
112 statbuf
->BlockSize
= statfs_buf
.f_bsize
;
113 statbuf
->TotalBlocks
= statfs_buf
.f_blocks
;
114 statbuf
->BlocksAvail
= statfs_buf
.f_bfree
;
115 statbuf
->UserBlocksAvail
= statfs_buf
.f_bavail
;
116 statbuf
->TotalFileNodes
= statfs_buf
.f_files
;
117 statbuf
->FreeFileNodes
= statfs_buf
.f_ffree
;
118 statbuf
->FsIdentifier
=
119 (((uint64_t) statfs_buf
.f_fsid
.val
[0] << 32) & 0xffffffff00000000LL
) |
120 (uint64_t) statfs_buf
.f_fsid
.val
[1];
121 /* Try to extrapolate some of the fs flags into the
124 statbuf
->FsCapabilities
=
125 FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
127 if (statfs_buf
.f_flags
& MNT_ACLS
)
128 statbuf
->FsCapabilities
|= FILE_PERSISTENT_ACLS
;
130 if (statfs_buf
.f_flags
& MNT_QUOTA
)
131 statbuf
->FsCapabilities
|= FILE_VOLUME_QUOTAS
;
132 if (statfs_buf
.f_flags
& MNT_RDONLY
)
133 statbuf
->FsCapabilities
|= FILE_READ_ONLY_VOLUME
;
137 #elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
138 static int linux_statvfs(const char *path
, vfs_statvfs_struct
*statbuf
)
140 struct statvfs statvfs_buf
;
143 result
= statvfs(path
, &statvfs_buf
);
146 statbuf
->OptimalTransferSize
= statvfs_buf
.f_frsize
;
147 statbuf
->BlockSize
= statvfs_buf
.f_bsize
;
148 statbuf
->TotalBlocks
= statvfs_buf
.f_blocks
;
149 statbuf
->BlocksAvail
= statvfs_buf
.f_bfree
;
150 statbuf
->UserBlocksAvail
= statvfs_buf
.f_bavail
;
151 statbuf
->TotalFileNodes
= statvfs_buf
.f_files
;
152 statbuf
->FreeFileNodes
= statvfs_buf
.f_ffree
;
153 statbuf
->FsIdentifier
= statvfs_buf
.f_fsid
;
154 /* Try to extrapolate some of the fs flags into the
157 statbuf
->FsCapabilities
=
158 FILE_CASE_SENSITIVE_SEARCH
| FILE_CASE_PRESERVED_NAMES
;
160 if (statvfs_buf
.f_flag
& ST_QUOTA
)
161 statbuf
->FsCapabilities
|= FILE_VOLUME_QUOTAS
;
163 if (statvfs_buf
.f_flag
& ST_RDONLY
)
164 statbuf
->FsCapabilities
|= FILE_READ_ONLY_VOLUME
;
171 sys_statvfs() is an abstraction layer over system-dependent statvfs()/statfs()
172 for particular POSIX systems. Due to controversy of what is considered more important
173 between LSB and FreeBSD/POSIX.1 (IEEE Std 1003.1-2001) we need to abstract the interface
174 so that particular OS would use its prefered interface.
176 int sys_statvfs(const char *path
, vfs_statvfs_struct
*statbuf
)
178 #if defined(DARWINOS)
179 return darwin_statvfs(path
, statbuf
);
180 #elif defined(BSD) && defined(BSD_STATVFS_BSIZE)
181 return bsd_statvfs(path
, statbuf
);
182 #elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
183 return linux_statvfs(path
, statbuf
);
185 /* BB change this to return invalid level */
190 #endif /* EOPNOTSUPP */