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"
29 static int darwin_fs_capabilities(const char * path)
32 vol_capabilities_attr_t *vcaps;
33 struct attrlist attrlist;
34 char attrbuf[sizeof(u_int32_t) + sizeof(vol_capabilities_attr_t)];
36 #define FORMAT_CAP(vinfo, cap) \
37 ( ((vinfo)->valid[VOL_CAPABILITIES_FORMAT] & (cap)) && \
38 ((vinfo)->capabilities[VOL_CAPABILITIES_FORMAT] & (cap)) )
40 #define INTERFACE_CAP(vinfo, cap) \
41 ( ((vinfo)->valid[VOL_CAPABILITIES_INTERFACES] & (cap)) && \
42 ((vinfo)->capabilities[VOL_CAPABILITIES_INTERFACES] & (cap)) )
44 ZERO_STRUCT(attrlist);
45 attrlist.bitmapcount = ATTR_BIT_MAP_COUNT;
46 attrlist.volattr = ATTR_VOL_CAPABILITIES;
48 if (getattrlist(path, &attrlist, attrbuf, sizeof(attrbuf), 0) != 0) {
49 DEBUG(0, ("getattrlist for %s capabilities failed: %s\n",
50 path, strerror(errno)));
51 /* Return no capabilities on failure. */
56 (vol_capabilities_attr_t *)(attrbuf + sizeof(u_int32_t));
58 if (FORMAT_CAP(vcaps, VOL_CAP_FMT_SPARSE_FILES)) {
59 caps |= FILE_SUPPORTS_SPARSE_FILES;
62 if (FORMAT_CAP(vcaps, VOL_CAP_FMT_CASE_SENSITIVE)) {
63 caps |= FILE_CASE_SENSITIVE_SEARCH;
66 if (FORMAT_CAP(vcaps, VOL_CAP_FMT_CASE_PRESERVING)) {
67 caps |= FILE_CASE_PRESERVED_NAMES;
70 if (INTERFACE_CAP(vcaps, VOL_CAP_INT_EXTENDED_SECURITY)) {
71 caps |= FILE_PERSISTENT_ACLS;
78 #if defined(BSD_STYLE_STATVFS)
79 static int bsd_statvfs(const char *path, vfs_statvfs_struct *statbuf)
84 ret = statfs(path, &sbuf);
86 statbuf->OptimalTransferSize = sbuf.f_iosize;
87 statbuf->BlockSize = sbuf.f_bsize;
88 statbuf->TotalBlocks = sbuf.f_blocks;
89 statbuf->BlocksAvail = sbuf.f_bfree;
90 statbuf->UserBlocksAvail = sbuf.f_bavail;
91 statbuf->TotalFileNodes = sbuf.f_files;
92 statbuf->FreeFileNodes = sbuf.f_ffree;
93 statbuf->FsIdentifier =
94 (((uint64_t) sbuf.f_fsid.val[0] << 32) & 0xffffffff00000000LL) |
95 (uint64_t) sbuf.f_fsid.val[1];
97 statbuf->FsCapabilities = darwin_fs_capabilities(sbuf.f_mntonname);
99 /* Try to extrapolate some of the fs flags into the
102 statbuf->FsCapabilities =
103 FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
105 if (sbuf.f_flags & MNT_ACLS)
106 statbuf->FsCapabilities |= FILE_PERSISTENT_ACLS;
109 if (sbuf.f_flags & MNT_QUOTA)
110 statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
111 if (sbuf.f_flags & MNT_RDONLY)
112 statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
117 #elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
118 static int linux_statvfs(const char *path, vfs_statvfs_struct *statbuf)
120 struct statvfs statvfs_buf;
123 result = statvfs(path, &statvfs_buf);
126 statbuf->OptimalTransferSize = statvfs_buf.f_frsize;
127 statbuf->BlockSize = statvfs_buf.f_bsize;
128 statbuf->TotalBlocks = statvfs_buf.f_blocks;
129 statbuf->BlocksAvail = statvfs_buf.f_bfree;
130 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
131 statbuf->TotalFileNodes = statvfs_buf.f_files;
132 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
133 statbuf->FsIdentifier = statvfs_buf.f_fsid;
134 /* Try to extrapolate some of the fs flags into the
137 statbuf->FsCapabilities =
138 FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
140 if (statvfs_buf.f_flag & ST_QUOTA)
141 statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
143 if (statvfs_buf.f_flag & ST_RDONLY)
144 statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
146 #if defined(HAVE_FALLOC_FL_PUNCH_HOLE) && defined(HAVE_LSEEK_HOLE_DATA)
148 * Only flag sparse file support if ZERO_DATA can be used to
149 * deallocate blocks, and SEEK_HOLE / SEEK_DATA can be used
150 * to provide QUERY_ALLOCATED_RANGES information.
152 statbuf->FsCapabilities |= FILE_SUPPORTS_SPARSE_FILES;
160 sys_statvfs() is an abstraction layer over system-dependent statvfs()/statfs()
161 for particular POSIX systems. Due to controversy of what is considered more important
162 between LSB and FreeBSD/POSIX.1 (IEEE Std 1003.1-2001) we need to abstract the interface
163 so that particular OS would use its preferred interface.
165 int sys_statvfs(const char *path, vfs_statvfs_struct *statbuf)
167 #if defined(BSD_STYLE_STATVFS)
168 return bsd_statvfs(path, statbuf);
169 #elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
170 return linux_statvfs(path, statbuf);
172 /* BB change this to return invalid level */
177 #endif /* EOPNOTSUPP */