Merge branch 'master' of ssh://jra@git.samba.org/data/git/samba
[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         /* SMB_VFS_MKDIR should never be called in vfs_onefs */
31         SMB_ASSERT(false);
32         return SMB_VFS_NEXT_MKDIR(handle, path, mode);
33 }
34
35 static int onefs_open(vfs_handle_struct *handle, const char *fname,
36                       files_struct *fsp, int flags, mode_t mode)
37 {
38         /* SMB_VFS_OPEN should never be called in vfs_onefs */
39         SMB_ASSERT(false);
40         return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
41 }
42
43 static uint64_t onefs_get_alloc_size(struct vfs_handle_struct *handle,  files_struct *fsp,
44                                 const SMB_STRUCT_STAT *sbuf)
45 {
46         uint64_t result;
47
48         START_PROFILE(syscall_get_alloc_size);
49
50         if(S_ISDIR(sbuf->st_mode)) {
51                 result = 0;
52                 goto out;
53         }
54
55         /* Just use the file size since st_blocks is unreliable on OneFS. */
56         result = get_file_size_stat(sbuf);
57
58         if (fsp && fsp->initial_allocation_size)
59                 result = MAX(result,fsp->initial_allocation_size);
60
61         result = smb_roundup(handle->conn, result);
62
63  out:
64         END_PROFILE(syscall_get_alloc_size);
65         return result;
66 }
67
68 static int onefs_statvfs(vfs_handle_struct *handle, const char *path,
69                          vfs_statvfs_struct *statbuf)
70 {
71         struct statvfs statvfs_buf;
72         int result;
73
74         DEBUG(5, ("Calling SMB_STAT_VFS \n"));
75         result = statvfs(path, &statvfs_buf);
76         ZERO_STRUCTP(statbuf);
77
78         if (!result) {
79                 statbuf->OptimalTransferSize = statvfs_buf.f_iosize;
80                 statbuf->BlockSize = statvfs_buf.f_bsize;
81                 statbuf->TotalBlocks = statvfs_buf.f_blocks;
82                 statbuf->BlocksAvail = statvfs_buf.f_bfree;
83                 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
84                 statbuf->TotalFileNodes = statvfs_buf.f_files;
85                 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
86                 statbuf->FsIdentifier =
87                     (((uint64_t)statvfs_buf.f_fsid.val[0]<<32) &
88                         0xffffffff00000000LL) |
89                     (uint64_t)statvfs_buf.f_fsid.val[1];
90         }
91         return result;
92 }
93
94 static int onefs_ntimes(vfs_handle_struct *handle, const char *fname,
95                         struct smb_file_time *ft)
96 {
97         int flags = 0;
98         struct timespec times[3];
99
100         if (!null_timespec(ft->atime)) {
101                 flags |= VT_ATIME;
102                 times[0] = ft->atime;
103                 DEBUG(6,("**** onefs_ntimes: actime: %s.%d\n",
104                         time_to_asc(convert_timespec_to_time_t(ft->atime)),
105                         ft->atime.tv_nsec));
106         }
107
108         if (!null_timespec(ft->mtime)) {
109                 flags |= VT_MTIME;
110                 times[1] = ft->mtime;
111                 DEBUG(6,("**** onefs_ntimes: modtime: %s.%d\n",
112                         time_to_asc(convert_timespec_to_time_t(ft->mtime)),
113                         ft->mtime.tv_nsec));
114         }
115
116         if (!null_timespec(ft->create_time)) {
117                 flags |= VT_BTIME;
118                 times[2] = ft->create_time;
119                 DEBUG(6,("**** onefs_ntimes: createtime: %s.%d\n",
120                    time_to_asc(convert_timespec_to_time_t(ft->create_time)),
121                    ft->create_time.tv_nsec));
122         }
123
124         return onefs_vtimes_streams(handle, fname, flags, times);
125 }
126
127 static uint32_t onefs_fs_capabilities(struct vfs_handle_struct *handle)
128 {
129         return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
130 }
131
132 static vfs_op_tuple onefs_ops[] = {
133         {SMB_VFS_OP(onefs_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
134          SMB_VFS_LAYER_TRANSPARENT},
135         {SMB_VFS_OP(onefs_mkdir), SMB_VFS_OP_MKDIR,
136          SMB_VFS_LAYER_OPAQUE},
137         {SMB_VFS_OP(onefs_open), SMB_VFS_OP_OPEN,
138          SMB_VFS_LAYER_OPAQUE},
139         {SMB_VFS_OP(onefs_create_file), SMB_VFS_OP_CREATE_FILE,
140          SMB_VFS_LAYER_OPAQUE},
141         {SMB_VFS_OP(onefs_close), SMB_VFS_OP_CLOSE,
142          SMB_VFS_LAYER_TRANSPARENT},
143         {SMB_VFS_OP(onefs_rename), SMB_VFS_OP_RENAME,
144          SMB_VFS_LAYER_TRANSPARENT},
145         {SMB_VFS_OP(onefs_stat), SMB_VFS_OP_STAT,
146          SMB_VFS_LAYER_TRANSPARENT},
147         {SMB_VFS_OP(onefs_fstat), SMB_VFS_OP_FSTAT,
148          SMB_VFS_LAYER_TRANSPARENT},
149         {SMB_VFS_OP(onefs_lstat), SMB_VFS_OP_LSTAT,
150          SMB_VFS_LAYER_TRANSPARENT},
151         {SMB_VFS_OP(onefs_get_alloc_size), SMB_VFS_OP_GET_ALLOC_SIZE,
152          SMB_VFS_LAYER_OPAQUE},
153         {SMB_VFS_OP(onefs_unlink), SMB_VFS_OP_UNLINK,
154          SMB_VFS_LAYER_TRANSPARENT},
155         {SMB_VFS_OP(onefs_ntimes), SMB_VFS_OP_NTIMES,
156          SMB_VFS_LAYER_OPAQUE},
157         {SMB_VFS_OP(onefs_chflags), SMB_VFS_OP_CHFLAGS,
158          SMB_VFS_LAYER_TRANSPARENT},
159         {SMB_VFS_OP(onefs_streaminfo), SMB_VFS_OP_STREAMINFO,
160          SMB_VFS_LAYER_OPAQUE},
161         {SMB_VFS_OP(onefs_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
162          SMB_VFS_LAYER_OPAQUE},
163         {SMB_VFS_OP(onefs_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
164          SMB_VFS_LAYER_OPAQUE},
165         {SMB_VFS_OP(onefs_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
166          SMB_VFS_LAYER_OPAQUE},
167         {SMB_VFS_OP(onefs_statvfs), SMB_VFS_OP_STATVFS,
168          SMB_VFS_LAYER_OPAQUE},
169         {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
170 };
171
172 NTSTATUS vfs_onefs_init(void)
173 {
174         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "onefs",
175                                 onefs_ops);
176 }