s3: Add statvfs implementation to the onefs vfs module
[samba.git] / source3 / modules / vfs_onefs.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * Support for OneFS
4  *
5  * Copyright (C) Tim Prouty, 2008
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 #include "onefs.h"
23
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_VFS
26
27 static int onefs_mkdir(vfs_handle_struct *handle, const char *path,
28                        mode_t mode)
29 {
30         DEBUG(0, ("SMB_VFS_MKDIR should never be called in vfs_onefs"));
31         return SMB_VFS_NEXT_MKDIR(handle, path, mode);
32 }
33
34 static int onefs_open(vfs_handle_struct *handle, const char *fname,
35                       files_struct *fsp, int flags, mode_t mode)
36 {
37         DEBUG(0, ("SMB_VFS_OPEN should never be called in vfs_onefs"));
38         return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
39 }
40
41 static int onefs_statvfs(vfs_handle_struct *handle, const char *path,
42                          vfs_statvfs_struct *statbuf)
43 {
44         struct statvfs statvfs_buf;
45         int result;
46
47         DEBUG(5, ("Calling SMB_STAT_VFS \n"));
48         result = statvfs(path, &statvfs_buf);
49         ZERO_STRUCTP(statbuf);
50
51         if (!result) {
52                 statbuf->OptimalTransferSize = statvfs_buf.f_iosize;
53                 statbuf->BlockSize = statvfs_buf.f_bsize;
54                 statbuf->TotalBlocks = statvfs_buf.f_blocks;
55                 statbuf->BlocksAvail = statvfs_buf.f_bfree;
56                 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
57                 statbuf->TotalFileNodes = statvfs_buf.f_files;
58                 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
59                 statbuf->FsIdentifier =
60                     (((uint64_t)statvfs_buf.f_fsid.val[0]<<32) &
61                         0xffffffff00000000LL) |
62                     (uint64_t)statvfs_buf.f_fsid.val[1];
63         }
64         return result;
65 }
66
67 static vfs_op_tuple onefs_ops[] = {
68         {SMB_VFS_OP(onefs_mkdir), SMB_VFS_OP_MKDIR,
69          SMB_VFS_LAYER_OPAQUE},
70         {SMB_VFS_OP(onefs_open), SMB_VFS_OP_OPEN,
71          SMB_VFS_LAYER_OPAQUE},
72         {SMB_VFS_OP(onefs_create_file), SMB_VFS_OP_CREATE_FILE,
73          SMB_VFS_LAYER_OPAQUE},
74         {SMB_VFS_OP(onefs_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
75          SMB_VFS_LAYER_OPAQUE},
76         {SMB_VFS_OP(onefs_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
77          SMB_VFS_LAYER_OPAQUE},
78         {SMB_VFS_OP(onefs_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
79          SMB_VFS_LAYER_OPAQUE},
80         {SMB_VFS_OP(onefs_statvfs), SMB_VFS_OP_STATVFS,
81          SMB_VFS_LAYER_OPAQUE},
82         {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
83 };
84
85 NTSTATUS vfs_onefs_init(void)
86 {
87         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "onefs",
88                                 onefs_ops);
89 }