auth: Make sure that creds_out is initialized with NULL.
[Samba.git] / source3 / smbd / statvfs.c
blob94ec2d5146de4f5053493518e0c4e5e4b8f95da6
1 /*
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/>.
22 #include "includes.h"
23 #include "system/filesys.h"
24 #include "smbd/smbd.h"
26 #if defined(DARWINOS)
27 #include <sys/attr.h>
29 static int darwin_fs_capabilities(const char * path)
31 int caps = 0;
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. */
52 return 0;
55 vcaps =
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;
74 return caps;
76 #endif /* DARWINOS */
78 #if defined(BSD_STYLE_STATVFS)
79 static int bsd_statvfs(const char *path, vfs_statvfs_struct *statbuf)
81 struct statfs sbuf;
82 int ret;
84 ret = statfs(path, &sbuf);
85 if (ret == 0) {
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];
96 #ifdef DARWINOS
97 statbuf->FsCapabilities = darwin_fs_capabilities(sbuf.f_mntonname);
98 #else
99 /* Try to extrapolate some of the fs flags into the
100 * capabilities
102 statbuf->FsCapabilities =
103 FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
104 #ifdef MNT_ACLS
105 if (sbuf.f_flags & MNT_ACLS)
106 statbuf->FsCapabilities |= FILE_PERSISTENT_ACLS;
107 #endif
108 #endif
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;
115 return ret;
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;
121 int result;
123 result = statvfs(path, &statvfs_buf);
125 if (!result) {
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
135 * capabilities
137 statbuf->FsCapabilities =
138 FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
139 #ifdef ST_QUOTA
140 if (statvfs_buf.f_flag & ST_QUOTA)
141 statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
142 #endif
143 if (statvfs_buf.f_flag & ST_RDONLY)
144 statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
146 return result;
148 #endif
151 sys_statvfs() is an abstraction layer over system-dependent statvfs()/statfs()
152 for particular POSIX systems. Due to controversy of what is considered more important
153 between LSB and FreeBSD/POSIX.1 (IEEE Std 1003.1-2001) we need to abstract the interface
154 so that particular OS would use its prefered interface.
156 int sys_statvfs(const char *path, vfs_statvfs_struct *statbuf)
158 #if defined(BSD_STYLE_STATVFS)
159 return bsd_statvfs(path, statbuf);
160 #elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
161 return linux_statvfs(path, statbuf);
162 #else
163 /* BB change this to return invalid level */
164 #ifdef EOPNOTSUPP
165 return EOPNOTSUPP;
166 #else
167 return -1;
168 #endif /* EOPNOTSUPP */
169 #endif /* LINUX */