2 * Unix SMB/CIFS implementation.
5 * Copyright (C) Tim Prouty, 2008
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.
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.
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/>.
25 #define DBGC_CLASS DBGC_VFS
27 #define ONEFS_DATA_FASTBUF 10
29 struct onefs_vfs_config share_config[ONEFS_DATA_FASTBUF];
30 struct onefs_vfs_config *pshare_config;
32 static void onefs_load_faketimestamp_config(struct vfs_handle_struct *handle,
33 struct onefs_vfs_config *cfg)
36 int snum = SNUM(handle->conn);
38 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_NOW,
42 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
43 set_namearray(&cfg->atime_now_list,*parm);
46 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_CTIME_NOW,
50 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
51 set_namearray(&cfg->ctime_now_list,*parm);
54 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_NOW,
58 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
59 set_namearray(&cfg->mtime_now_list,*parm);
62 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_ATIME_STATIC,
66 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
67 set_namearray(&cfg->atime_static_list,*parm);
70 parm = lp_parm_string_list(snum, PARM_ONEFS_TYPE, PARM_MTIME_STATIC,
74 cfg->init_flags |= ONEFS_VFS_CONFIG_FAKETIMESTAMPS;
75 set_namearray(&cfg->mtime_static_list,*parm);
78 cfg->atime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_ATIME_SLOP,0);
79 cfg->ctime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_CTIME_SLOP,0);
80 cfg->mtime_slop = lp_parm_int(snum, PARM_ONEFS_TYPE, PARM_MTIME_SLOP,0);
84 static int onefs_load_config(struct vfs_handle_struct *handle)
86 int snum = SNUM(handle->conn);
87 int share_count = lp_numservices();
91 if (share_count <= ONEFS_DATA_FASTBUF)
92 pshare_config = share_config;
94 pshare_config = SMB_MALLOC_ARRAY(struct onefs_vfs_config,
101 memset(pshare_config, 0,
102 (sizeof(struct onefs_vfs_config) * share_count));
106 if ((pshare_config[snum].init_flags &
107 ONEFS_VFS_CONFIG_INITIALIZED) == 0) {
108 pshare_config[snum].init_flags =
109 ONEFS_VFS_CONFIG_INITIALIZED;
110 onefs_load_faketimestamp_config(handle,
111 &pshare_config[snum]);
117 bool onefs_get_config(int snum, int config_type,
118 struct onefs_vfs_config *cfg)
120 if (share_config[snum].init_flags & config_type)
121 *cfg = share_config[snum];
128 static int onefs_connect(struct vfs_handle_struct *handle, const char *service,
131 int ret = onefs_load_config(handle);
136 return SMB_VFS_NEXT_CONNECT(handle, service, user);
139 static int onefs_mkdir(vfs_handle_struct *handle, const char *path,
142 /* SMB_VFS_MKDIR should never be called in vfs_onefs */
144 return SMB_VFS_NEXT_MKDIR(handle, path, mode);
147 static int onefs_open(vfs_handle_struct *handle, const char *fname,
148 files_struct *fsp, int flags, mode_t mode)
150 /* SMB_VFS_OPEN should never be called in vfs_onefs */
152 return SMB_VFS_NEXT_OPEN(handle, fname, fsp, flags, mode);
155 static uint64_t onefs_get_alloc_size(struct vfs_handle_struct *handle, files_struct *fsp,
156 const SMB_STRUCT_STAT *sbuf)
160 START_PROFILE(syscall_get_alloc_size);
162 if(S_ISDIR(sbuf->st_mode)) {
167 /* Just use the file size since st_blocks is unreliable on OneFS. */
168 result = get_file_size_stat(sbuf);
170 if (fsp && fsp->initial_allocation_size)
171 result = MAX(result,fsp->initial_allocation_size);
173 result = smb_roundup(handle->conn, result);
176 END_PROFILE(syscall_get_alloc_size);
180 static int onefs_statvfs(vfs_handle_struct *handle, const char *path,
181 vfs_statvfs_struct *statbuf)
183 struct statvfs statvfs_buf;
186 DEBUG(5, ("Calling SMB_STAT_VFS \n"));
187 result = statvfs(path, &statvfs_buf);
188 ZERO_STRUCTP(statbuf);
191 statbuf->OptimalTransferSize = statvfs_buf.f_iosize;
192 statbuf->BlockSize = statvfs_buf.f_bsize;
193 statbuf->TotalBlocks = statvfs_buf.f_blocks;
194 statbuf->BlocksAvail = statvfs_buf.f_bfree;
195 statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
196 statbuf->TotalFileNodes = statvfs_buf.f_files;
197 statbuf->FreeFileNodes = statvfs_buf.f_ffree;
198 statbuf->FsIdentifier =
199 (((uint64_t)statvfs_buf.f_fsid.val[0]<<32) &
200 0xffffffff00000000LL) |
201 (uint64_t)statvfs_buf.f_fsid.val[1];
206 static int onefs_ntimes(vfs_handle_struct *handle, const char *fname,
207 struct smb_file_time *ft)
210 struct timespec times[3];
212 if (!null_timespec(ft->atime)) {
214 times[0] = ft->atime;
215 DEBUG(6,("**** onefs_ntimes: actime: %s.%d\n",
216 time_to_asc(convert_timespec_to_time_t(ft->atime)),
220 if (!null_timespec(ft->mtime)) {
222 times[1] = ft->mtime;
223 DEBUG(6,("**** onefs_ntimes: modtime: %s.%d\n",
224 time_to_asc(convert_timespec_to_time_t(ft->mtime)),
228 if (!null_timespec(ft->create_time)) {
230 times[2] = ft->create_time;
231 DEBUG(6,("**** onefs_ntimes: createtime: %s.%d\n",
232 time_to_asc(convert_timespec_to_time_t(ft->create_time)),
233 ft->create_time.tv_nsec));
236 return onefs_vtimes_streams(handle, fname, flags, times);
239 static uint32_t onefs_fs_capabilities(struct vfs_handle_struct *handle)
241 return SMB_VFS_NEXT_FS_CAPABILITIES(handle) | FILE_NAMED_STREAMS;
244 static vfs_op_tuple onefs_ops[] = {
245 {SMB_VFS_OP(onefs_connect), SMB_VFS_OP_CONNECT,
246 SMB_VFS_LAYER_TRANSPARENT},
247 {SMB_VFS_OP(onefs_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
248 SMB_VFS_LAYER_TRANSPARENT},
249 {SMB_VFS_OP(onefs_mkdir), SMB_VFS_OP_MKDIR,
250 SMB_VFS_LAYER_OPAQUE},
251 {SMB_VFS_OP(onefs_open), SMB_VFS_OP_OPEN,
252 SMB_VFS_LAYER_OPAQUE},
253 {SMB_VFS_OP(onefs_create_file), SMB_VFS_OP_CREATE_FILE,
254 SMB_VFS_LAYER_OPAQUE},
255 {SMB_VFS_OP(onefs_close), SMB_VFS_OP_CLOSE,
256 SMB_VFS_LAYER_TRANSPARENT},
257 {SMB_VFS_OP(onefs_rename), SMB_VFS_OP_RENAME,
258 SMB_VFS_LAYER_TRANSPARENT},
259 {SMB_VFS_OP(onefs_stat), SMB_VFS_OP_STAT,
260 SMB_VFS_LAYER_TRANSPARENT},
261 {SMB_VFS_OP(onefs_fstat), SMB_VFS_OP_FSTAT,
262 SMB_VFS_LAYER_TRANSPARENT},
263 {SMB_VFS_OP(onefs_lstat), SMB_VFS_OP_LSTAT,
264 SMB_VFS_LAYER_TRANSPARENT},
265 {SMB_VFS_OP(onefs_get_alloc_size), SMB_VFS_OP_GET_ALLOC_SIZE,
266 SMB_VFS_LAYER_OPAQUE},
267 {SMB_VFS_OP(onefs_unlink), SMB_VFS_OP_UNLINK,
268 SMB_VFS_LAYER_TRANSPARENT},
269 {SMB_VFS_OP(onefs_ntimes), SMB_VFS_OP_NTIMES,
270 SMB_VFS_LAYER_OPAQUE},
271 {SMB_VFS_OP(onefs_chflags), SMB_VFS_OP_CHFLAGS,
272 SMB_VFS_LAYER_TRANSPARENT},
273 {SMB_VFS_OP(onefs_streaminfo), SMB_VFS_OP_STREAMINFO,
274 SMB_VFS_LAYER_OPAQUE},
275 {SMB_VFS_OP(onefs_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
276 SMB_VFS_LAYER_OPAQUE},
277 {SMB_VFS_OP(onefs_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
278 SMB_VFS_LAYER_OPAQUE},
279 {SMB_VFS_OP(onefs_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
280 SMB_VFS_LAYER_OPAQUE},
281 {SMB_VFS_OP(onefs_statvfs), SMB_VFS_OP_STATVFS,
282 SMB_VFS_LAYER_OPAQUE},
283 {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
286 NTSTATUS vfs_onefs_init(void)
288 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "onefs",