r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[vlendec/samba-autobuild/.git] / source3 / smbd / statvfs.c
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    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22
23 #if defined(LINUX) && defined(HAVE_FSID_INT)
24 static int linux_statvfs(const char *path, vfs_statvfs_struct *statbuf)
25 {
26         struct statvfs statvfs_buf;
27         int result;
28
29         result = statvfs(path, &statvfs_buf);
30
31         if (!result) {
32                 statbuf->OptimalTransferSize = statvfs_buf.f_frsize;
33                 statbuf->BlockSize = statvfs_buf.f_bsize;
34                 statbuf->TotalBlocks = statvfs_buf.f_blocks;
35                 statbuf->BlocksAvail = statvfs_buf.f_bfree;
36                 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
37                 statbuf->TotalFileNodes = statvfs_buf.f_files;
38                 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
39                 statbuf->FsIdentifier = statvfs_buf.f_fsid;
40         }
41         return result;
42 }
43 #endif
44
45 /* 
46  sys_statvfs() is an abstraction layer over system-dependent statvfs()/statfs()
47  for particular POSIX systems. Due to controversy of what is considered more important
48  between LSB and FreeBSD/POSIX.1 (IEEE Std 1003.1-2001) we need to abstract the interface
49  so that particular OS would use its preffered interface.
50 */
51 int sys_statvfs(const char *path, vfs_statvfs_struct *statbuf)
52 {
53 #if defined(LINUX) && defined(HAVE_FSID_INT)
54         return linux_statvfs(path, statbuf);
55 #else
56         /* BB change this to return invalid level */
57 #ifdef EOPNOTSUPP
58         return EOPNOTSUPP;
59 #else
60         return -1;
61 #endif /* EOPNOTSUPP */
62 #endif /* LINUX */
63
64 }