docs: change default of usershare path to use an entity
[Samba.git] / source3 / modules / vfs_gpfs.c
blob5c9981fea94fcfc3c7ba0423332eed93d42e9a1b
1 /*
2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
28 #include "modules/non_posix_acls.h"
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_VFS
33 #include <gpfs_gpl.h>
34 #include "nfs4_acls.h"
35 #include "vfs_gpfs.h"
36 #include "system/filesys.h"
37 #include "auth.h"
38 #include "lib/util/tevent_unix.h"
40 struct gpfs_config_data {
41 bool sharemodes;
42 bool leases;
43 bool hsm;
44 bool syncio;
45 bool winattr;
46 bool ftruncate;
47 bool getrealfilename;
48 bool dfreequota;
49 bool prealloc;
50 bool acl;
51 bool settimes;
55 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
56 uint32 share_mode, uint32 access_mask)
59 struct gpfs_config_data *config;
60 int ret = 0;
62 SMB_VFS_HANDLE_GET_DATA(handle, config,
63 struct gpfs_config_data,
64 return -1);
66 if(!config->sharemodes) {
67 return 0;
70 START_PROFILE(syscall_kernel_flock);
72 kernel_flock(fsp->fh->fd, share_mode, access_mask);
74 if (!set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
75 ret = -1;
78 END_PROFILE(syscall_kernel_flock);
80 return ret;
83 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
86 struct gpfs_config_data *config;
88 SMB_VFS_HANDLE_GET_DATA(handle, config,
89 struct gpfs_config_data,
90 return -1);
92 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
93 set_gpfs_sharemode(fsp, 0, 0);
96 return SMB_VFS_NEXT_CLOSE(handle, fsp);
99 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
100 int leasetype)
102 struct gpfs_config_data *config;
103 int ret=0;
105 SMB_VFS_HANDLE_GET_DATA(handle, config,
106 struct gpfs_config_data,
107 return -1);
109 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
110 return -1;
112 START_PROFILE(syscall_linux_setlease);
114 if (config->leases) {
116 * Ensure the lease owner is root to allow
117 * correct delivery of lease-break signals.
119 become_root();
120 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
121 unbecome_root();
124 END_PROFILE(syscall_linux_setlease);
126 return ret;
129 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
130 const char *path,
131 const char *name,
132 TALLOC_CTX *mem_ctx,
133 char **found_name)
135 int result;
136 char *full_path;
137 char real_pathname[PATH_MAX+1];
138 int buflen;
139 bool mangled;
140 struct gpfs_config_data *config;
142 SMB_VFS_HANDLE_GET_DATA(handle, config,
143 struct gpfs_config_data,
144 return -1);
146 if (!config->getrealfilename) {
147 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
148 mem_ctx, found_name);
151 mangled = mangle_is_mangled(name, handle->conn->params);
152 if (mangled) {
153 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
154 mem_ctx, found_name);
157 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
158 if (full_path == NULL) {
159 errno = ENOMEM;
160 return -1;
163 buflen = sizeof(real_pathname) - 1;
165 result = smbd_gpfs_get_realfilename_path(full_path, real_pathname,
166 &buflen);
168 TALLOC_FREE(full_path);
170 if ((result == -1) && (errno == ENOSYS)) {
171 return SMB_VFS_NEXT_GET_REAL_FILENAME(
172 handle, path, name, mem_ctx, found_name);
175 if (result == -1) {
176 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
177 strerror(errno)));
178 return -1;
182 * GPFS does not necessarily null-terminate the returned path
183 * but instead returns the buffer length in buflen.
186 if (buflen < sizeof(real_pathname)) {
187 real_pathname[buflen] = '\0';
188 } else {
189 real_pathname[sizeof(real_pathname)-1] = '\0';
192 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
193 path, name, real_pathname));
195 name = strrchr_m(real_pathname, '/');
196 if (name == NULL) {
197 errno = ENOENT;
198 return -1;
201 *found_name = talloc_strdup(mem_ctx, name+1);
202 if (*found_name == NULL) {
203 errno = ENOMEM;
204 return -1;
207 return 0;
210 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
212 gpfs_aclCount_t i;
213 if (gacl==NULL)
215 DEBUG(0, ("gpfs acl is NULL\n"));
216 return;
219 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
220 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
221 for(i=0; i<gacl->acl_nace; i++)
223 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
224 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
225 i, gace->aceType, gace->aceFlags, gace->aceMask,
226 gace->aceIFlags, gace->aceWho));
231 * get the ACL from GPFS, allocated on the specified mem_ctx
232 * internally retries when initial buffer was too small
234 * caller needs to cast result to either
235 * raw = yes: struct gpfs_opaque_acl
236 * raw = no: struct gpfs_acl
239 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
240 const char *fname,
241 const bool raw,
242 const gpfs_aclType_t type)
245 void *aclbuf;
246 size_t size = 512;
247 int ret, flags;
248 unsigned int *len;
249 size_t struct_size;
251 again:
253 aclbuf = talloc_zero_size(mem_ctx, size);
254 if (aclbuf == NULL) {
255 errno = ENOMEM;
256 return NULL;
259 if (raw) {
260 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
261 buf->acl_type = type;
262 flags = GPFS_GETACL_NATIVE;
263 len = (unsigned int *) &(buf->acl_buffer_len);
264 struct_size = sizeof(struct gpfs_opaque_acl);
265 } else {
266 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
267 buf->acl_type = type;
268 flags = GPFS_GETACL_STRUCT;
269 len = &(buf->acl_len);
270 struct_size = sizeof(struct gpfs_acl);
273 /* set the length of the buffer as input value */
274 *len = size;
276 errno = 0;
277 ret = smbd_gpfs_getacl((char *)fname, flags, aclbuf);
278 if ((ret != 0) && (errno == ENOSPC)) {
280 * get the size needed to accommodate the complete buffer
282 * the value returned only applies to the ACL blob in the
283 * struct so make sure to also have headroom for the first
284 * struct members by adding room for the complete struct
285 * (might be a few bytes too much then)
287 size = *len + struct_size;
288 talloc_free(aclbuf);
289 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
290 goto again;
293 if (ret != 0) {
294 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
295 strerror(errno)));
296 talloc_free(aclbuf);
297 return NULL;
300 return aclbuf;
303 /* Tries to get nfs4 acls and returns SMB ACL allocated.
304 * On failure returns 1 if it got non-NFSv4 ACL to prompt
305 * retry with POSIX ACL checks.
306 * On failure returns -1 if there is system (GPFS) error, check errno.
307 * Returns 0 on success
309 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname, SMB4ACL_T **ppacl)
311 gpfs_aclCount_t i;
312 struct gpfs_acl *gacl = NULL;
313 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
315 /* Get the ACL */
316 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
317 false, 0);
318 if (gacl == NULL) {
319 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
320 fname, strerror(errno)));
321 return -1;
324 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
325 DEBUG(10, ("Got non-nfsv4 acl\n"));
326 /* Retry with POSIX ACLs check */
327 talloc_free(gacl);
328 return 1;
331 *ppacl = smb_create_smb4acl(mem_ctx);
333 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
334 gacl->acl_len, gacl->acl_level, gacl->acl_version,
335 gacl->acl_nace));
337 for (i=0; i<gacl->acl_nace; i++) {
338 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
339 SMB_ACE4PROP_T smbace;
340 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
341 "who: %d\n", gace->aceType, gace->aceIFlags,
342 gace->aceFlags, gace->aceMask, gace->aceWho));
344 ZERO_STRUCT(smbace);
345 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
346 smbace.flags |= SMB_ACE4_ID_SPECIAL;
347 switch (gace->aceWho) {
348 case ACE4_SPECIAL_OWNER:
349 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
350 break;
351 case ACE4_SPECIAL_GROUP:
352 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
353 break;
354 case ACE4_SPECIAL_EVERYONE:
355 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
356 break;
357 default:
358 DEBUG(8, ("invalid special gpfs id %d "
359 "ignored\n", gace->aceWho));
360 continue; /* don't add it */
362 } else {
363 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
364 smbace.who.gid = gace->aceWho;
365 else
366 smbace.who.uid = gace->aceWho;
369 /* remove redundant deny entries */
370 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
371 struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
372 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
373 prev->aceFlags == gace->aceFlags &&
374 prev->aceIFlags == gace->aceIFlags &&
375 (gace->aceMask & prev->aceMask) == 0 &&
376 gace->aceWho == prev->aceWho) {
377 /* it's redundant - skip it */
378 continue;
382 smbace.aceType = gace->aceType;
383 smbace.aceFlags = gace->aceFlags;
384 smbace.aceMask = gace->aceMask;
385 smb_add_ace4(*ppacl, &smbace);
388 talloc_free(gacl);
390 return 0;
393 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
394 files_struct *fsp, uint32 security_info,
395 TALLOC_CTX *mem_ctx,
396 struct security_descriptor **ppdesc)
398 SMB4ACL_T *pacl = NULL;
399 int result;
400 struct gpfs_config_data *config;
401 TALLOC_CTX *frame = talloc_stackframe();
402 NTSTATUS status;
404 *ppdesc = NULL;
406 SMB_VFS_HANDLE_GET_DATA(handle, config,
407 struct gpfs_config_data,
408 return NT_STATUS_INTERNAL_ERROR);
410 if (!config->acl) {
411 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
412 mem_ctx, ppdesc);
413 TALLOC_FREE(frame);
414 return status;
417 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
419 if (result == 0) {
420 status = smb_fget_nt_acl_nfs4(fsp, security_info, mem_ctx,
421 ppdesc, pacl);
422 TALLOC_FREE(frame);
423 return status;
426 if (result > 0) {
427 DEBUG(10, ("retrying with posix acl...\n"));
428 status = posix_fget_nt_acl(fsp, security_info,
429 mem_ctx, ppdesc);
430 TALLOC_FREE(frame);
431 return status;
434 TALLOC_FREE(frame);
436 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
437 return map_nt_error_from_unix(errno);
440 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
441 const char *name,
442 uint32 security_info,
443 TALLOC_CTX *mem_ctx, struct security_descriptor **ppdesc)
445 SMB4ACL_T *pacl = NULL;
446 int result;
447 struct gpfs_config_data *config;
448 TALLOC_CTX *frame = talloc_stackframe();
449 NTSTATUS status;
451 *ppdesc = NULL;
453 SMB_VFS_HANDLE_GET_DATA(handle, config,
454 struct gpfs_config_data,
455 return NT_STATUS_INTERNAL_ERROR);
457 if (!config->acl) {
458 status = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
459 mem_ctx, ppdesc);
460 TALLOC_FREE(frame);
461 return status;
464 result = gpfs_get_nfs4_acl(frame, name, &pacl);
466 if (result == 0) {
467 status = smb_get_nt_acl_nfs4(handle->conn, name, security_info,
468 mem_ctx, ppdesc, pacl);
469 TALLOC_FREE(frame);
470 return status;
473 if (result > 0) {
474 DEBUG(10, ("retrying with posix acl...\n"));
475 status = posix_get_nt_acl(handle->conn, name, security_info,
476 mem_ctx, ppdesc);
477 TALLOC_FREE(frame);
478 return status;
481 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
482 TALLOC_FREE(frame);
483 return map_nt_error_from_unix(errno);
486 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle, files_struct *fsp, SMB4ACL_T *smbacl)
488 int ret;
489 gpfs_aclLen_t gacl_len;
490 SMB4ACE_T *smbace;
491 struct gpfs_acl *gacl;
492 TALLOC_CTX *mem_ctx = talloc_tos();
494 gacl_len = offsetof(gpfs_acl_t, ace_v4) + smb_get_naces(smbacl) *
495 sizeof(gpfs_ace_v4_t);
497 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
498 if (gacl == NULL) {
499 DEBUG(0, ("talloc failed\n"));
500 errno = ENOMEM;
501 return False;
504 gacl->acl_len = gacl_len;
505 gacl->acl_level = 0;
506 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
507 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
508 gacl->acl_nace = 0; /* change later... */
510 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
511 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
512 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
514 gace->aceType = aceprop->aceType;
515 gace->aceFlags = aceprop->aceFlags;
516 gace->aceMask = aceprop->aceMask;
519 * GPFS can't distinguish between WRITE and APPEND on
520 * files, so one being set without the other is an
521 * error. Sorry for the many ()'s :-)
524 if (!fsp->is_directory
526 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
527 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
529 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
530 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
532 lp_parm_bool(fsp->conn->params->service, "gpfs",
533 "merge_writeappend", True)) {
534 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
535 "WRITE^APPEND, setting WRITE|APPEND\n",
536 fsp_str_dbg(fsp)));
537 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
540 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
542 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
544 switch(aceprop->who.special_id)
546 case SMB_ACE4_WHO_EVERYONE:
547 gace->aceWho = ACE4_SPECIAL_EVERYONE;
548 break;
549 case SMB_ACE4_WHO_OWNER:
550 gace->aceWho = ACE4_SPECIAL_OWNER;
551 break;
552 case SMB_ACE4_WHO_GROUP:
553 gace->aceWho = ACE4_SPECIAL_GROUP;
554 break;
555 default:
556 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
557 continue; /* don't add it !!! */
559 } else {
560 /* just only for the type safety... */
561 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
562 gace->aceWho = aceprop->who.gid;
563 else
564 gace->aceWho = aceprop->who.uid;
567 gacl->acl_nace++;
570 ret = smbd_gpfs_putacl(fsp->fsp_name->base_name,
571 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
572 if (ret != 0) {
573 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
574 gpfs_dumpacl(8, gacl);
575 return False;
578 DEBUG(10, ("gpfs_putacl succeeded\n"));
579 return True;
582 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
584 struct gpfs_acl *acl;
585 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
587 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
588 fsp->fsp_name->base_name,
589 false, 0);
590 if (acl == NULL) {
591 return map_nt_error_from_unix(errno);
594 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
595 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
596 "refuse_dacl_protected", false)
597 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
598 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
599 talloc_free(acl);
600 return NT_STATUS_NOT_SUPPORTED;
603 result = smb_set_nt_acl_nfs4(handle,
604 fsp, security_info_sent, psd,
605 gpfsacl_process_smbacl);
606 } else { /* assume POSIX ACL - by default... */
607 result = set_nt_acl(fsp, security_info_sent, psd);
610 talloc_free(acl);
611 return result;
614 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
616 struct gpfs_config_data *config;
618 SMB_VFS_HANDLE_GET_DATA(handle, config,
619 struct gpfs_config_data,
620 return NT_STATUS_INTERNAL_ERROR);
622 if (!config->acl) {
623 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
626 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
629 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
631 SMB_ACL_T result;
632 gpfs_aclCount_t i;
634 result = sys_acl_init(mem_ctx);
635 if (result == NULL) {
636 errno = ENOMEM;
637 return NULL;
640 result->count = pacl->acl_nace;
641 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
642 result->count);
643 if (result->acl == NULL) {
644 TALLOC_FREE(result);
645 errno = ENOMEM;
646 return NULL;
649 for (i=0; i<pacl->acl_nace; i++) {
650 struct smb_acl_entry *ace = &result->acl[i];
651 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
653 DEBUG(10, ("Converting type %d id %lu perm %x\n",
654 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
655 (int)g_ace->ace_perm));
657 switch (g_ace->ace_type) {
658 case GPFS_ACL_USER:
659 ace->a_type = SMB_ACL_USER;
660 ace->info.user.uid = (uid_t)g_ace->ace_who;
661 break;
662 case GPFS_ACL_USER_OBJ:
663 ace->a_type = SMB_ACL_USER_OBJ;
664 break;
665 case GPFS_ACL_GROUP:
666 ace->a_type = SMB_ACL_GROUP;
667 ace->info.group.gid = (gid_t)g_ace->ace_who;
668 break;
669 case GPFS_ACL_GROUP_OBJ:
670 ace->a_type = SMB_ACL_GROUP_OBJ;
671 break;
672 case GPFS_ACL_OTHER:
673 ace->a_type = SMB_ACL_OTHER;
674 break;
675 case GPFS_ACL_MASK:
676 ace->a_type = SMB_ACL_MASK;
677 break;
678 default:
679 DEBUG(10, ("Got invalid ace_type: %d\n",
680 g_ace->ace_type));
681 TALLOC_FREE(result);
682 errno = EINVAL;
683 return NULL;
686 ace->a_perm = 0;
687 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
688 SMB_ACL_READ : 0;
689 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
690 SMB_ACL_WRITE : 0;
691 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
692 SMB_ACL_EXECUTE : 0;
694 DEBUGADD(10, ("Converted to %d perm %x\n",
695 ace->a_type, ace->a_perm));
698 return result;
701 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
702 TALLOC_CTX *mem_ctx)
704 struct gpfs_acl *pacl;
705 SMB_ACL_T result = NULL;
707 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
709 if (pacl == NULL) {
710 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
711 path, strerror(errno)));
712 if (errno == 0) {
713 errno = EINVAL;
715 goto done;
718 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
719 DEBUG(10, ("Got acl version %d, expected %d\n",
720 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
721 errno = EINVAL;
722 goto done;
725 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
726 pacl->acl_len, pacl->acl_level, pacl->acl_version,
727 pacl->acl_nace));
729 result = gpfs2smb_acl(pacl, mem_ctx);
730 if (result != NULL) {
731 errno = 0;
734 done:
736 if (pacl != NULL) {
737 talloc_free(pacl);
739 if (errno != 0) {
740 TALLOC_FREE(result);
742 return result;
745 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
746 const char *path_p,
747 SMB_ACL_TYPE_T type,
748 TALLOC_CTX *mem_ctx)
750 gpfs_aclType_t gpfs_type;
751 struct gpfs_config_data *config;
753 SMB_VFS_HANDLE_GET_DATA(handle, config,
754 struct gpfs_config_data,
755 return NULL);
757 if (!config->acl) {
758 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p,
759 type, mem_ctx);
762 switch(type) {
763 case SMB_ACL_TYPE_ACCESS:
764 gpfs_type = GPFS_ACL_TYPE_ACCESS;
765 break;
766 case SMB_ACL_TYPE_DEFAULT:
767 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
768 break;
769 default:
770 DEBUG(0, ("Got invalid type: %d\n", type));
771 smb_panic("exiting");
774 return gpfsacl_get_posix_acl(path_p, gpfs_type, mem_ctx);
777 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
778 files_struct *fsp,
779 TALLOC_CTX *mem_ctx)
781 struct gpfs_config_data *config;
783 SMB_VFS_HANDLE_GET_DATA(handle, config,
784 struct gpfs_config_data,
785 return NULL);
787 if (!config->acl) {
788 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
791 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
792 GPFS_ACL_TYPE_ACCESS, mem_ctx);
795 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
796 const char *path_p,
797 TALLOC_CTX *mem_ctx,
798 char **blob_description,
799 DATA_BLOB *blob)
801 struct gpfs_config_data *config;
802 struct gpfs_opaque_acl *acl = NULL;
803 DATA_BLOB aclblob;
804 int result;
806 SMB_VFS_HANDLE_GET_DATA(handle, config,
807 struct gpfs_config_data,
808 return -1);
810 if (!config->acl) {
811 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p,
812 mem_ctx,
813 blob_description,
814 blob);
817 errno = 0;
818 acl = (struct gpfs_opaque_acl *)
819 vfs_gpfs_getacl(mem_ctx,
820 path_p,
821 true,
822 GPFS_ACL_TYPE_NFS4);
824 if (errno) {
825 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
826 errno, strerror(errno)));
828 /* EINVAL means POSIX ACL, bail out on other cases */
829 if (errno != EINVAL) {
830 return -1;
834 if (acl != NULL) {
836 * file has NFSv4 ACL
838 * we only need the actual ACL blob here
839 * acl_version will always be NFS4 because we asked
840 * for NFS4
841 * acl_type is only used for POSIX ACLs
843 aclblob.data = (uint8_t*) acl->acl_var_data;
844 aclblob.length = acl->acl_buffer_len;
846 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
847 if (!*blob_description) {
848 talloc_free(acl);
849 errno = ENOMEM;
850 return -1;
853 result = non_posix_sys_acl_blob_get_file_helper(handle, path_p,
854 aclblob,
855 mem_ctx, blob);
857 talloc_free(acl);
858 return result;
861 /* fall back to POSIX ACL */
862 return posix_sys_acl_blob_get_file(handle, path_p, mem_ctx,
863 blob_description, blob);
866 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
867 files_struct *fsp,
868 TALLOC_CTX *mem_ctx,
869 char **blob_description,
870 DATA_BLOB *blob)
872 struct gpfs_config_data *config;
873 struct gpfs_opaque_acl *acl = NULL;
874 DATA_BLOB aclblob;
875 int result;
877 SMB_VFS_HANDLE_GET_DATA(handle, config,
878 struct gpfs_config_data,
879 return -1);
881 if (!config->acl) {
882 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
883 blob_description, blob);
886 errno = 0;
887 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
888 fsp->fsp_name->base_name,
889 true,
890 GPFS_ACL_TYPE_NFS4);
892 if (errno) {
893 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
894 errno, strerror(errno)));
896 /* EINVAL means POSIX ACL, bail out on other cases */
897 if (errno != EINVAL) {
898 return -1;
902 if (acl != NULL) {
904 * file has NFSv4 ACL
906 * we only need the actual ACL blob here
907 * acl_version will always be NFS4 because we asked
908 * for NFS4
909 * acl_type is only used for POSIX ACLs
911 aclblob.data = (uint8_t*) acl->acl_var_data;
912 aclblob.length = acl->acl_buffer_len;
914 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
915 if (!*blob_description) {
916 talloc_free(acl);
917 errno = ENOMEM;
918 return -1;
921 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
922 aclblob, mem_ctx,
923 blob);
925 talloc_free(acl);
926 return result;
929 /* fall back to POSIX ACL */
930 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
931 blob_description, blob);
934 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
935 SMB_ACL_TYPE_T type)
937 gpfs_aclLen_t len;
938 struct gpfs_acl *result;
939 int i;
941 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
943 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
944 sizeof(gpfs_ace_v1_t);
946 result = (struct gpfs_acl *)SMB_MALLOC(len);
947 if (result == NULL) {
948 errno = ENOMEM;
949 return result;
952 result->acl_len = len;
953 result->acl_level = 0;
954 result->acl_version = GPFS_ACL_VERSION_POSIX;
955 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
956 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
957 result->acl_nace = pacl->count;
959 for (i=0; i<pacl->count; i++) {
960 const struct smb_acl_entry *ace = &pacl->acl[i];
961 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
963 DEBUG(10, ("Converting type %d perm %x\n",
964 (int)ace->a_type, (int)ace->a_perm));
966 g_ace->ace_perm = 0;
968 switch(ace->a_type) {
969 case SMB_ACL_USER:
970 g_ace->ace_type = GPFS_ACL_USER;
971 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
972 break;
973 case SMB_ACL_USER_OBJ:
974 g_ace->ace_type = GPFS_ACL_USER_OBJ;
975 g_ace->ace_perm |= ACL_PERM_CONTROL;
976 g_ace->ace_who = 0;
977 break;
978 case SMB_ACL_GROUP:
979 g_ace->ace_type = GPFS_ACL_GROUP;
980 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
981 break;
982 case SMB_ACL_GROUP_OBJ:
983 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
984 g_ace->ace_who = 0;
985 break;
986 case SMB_ACL_MASK:
987 g_ace->ace_type = GPFS_ACL_MASK;
988 g_ace->ace_perm = 0x8f;
989 g_ace->ace_who = 0;
990 break;
991 case SMB_ACL_OTHER:
992 g_ace->ace_type = GPFS_ACL_OTHER;
993 g_ace->ace_who = 0;
994 break;
995 default:
996 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
997 errno = EINVAL;
998 SAFE_FREE(result);
999 return NULL;
1002 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1003 ACL_PERM_READ : 0;
1004 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1005 ACL_PERM_WRITE : 0;
1006 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1007 ACL_PERM_EXECUTE : 0;
1009 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1010 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1013 return result;
1016 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1017 const char *name,
1018 SMB_ACL_TYPE_T type,
1019 SMB_ACL_T theacl)
1021 struct gpfs_acl *gpfs_acl;
1022 int result;
1023 struct gpfs_config_data *config;
1025 SMB_VFS_HANDLE_GET_DATA(handle, config,
1026 struct gpfs_config_data,
1027 return -1);
1029 if (!config->acl) {
1030 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, type, theacl);
1033 gpfs_acl = smb2gpfs_acl(theacl, type);
1034 if (gpfs_acl == NULL) {
1035 return -1;
1038 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
1040 SAFE_FREE(gpfs_acl);
1041 return result;
1044 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1045 files_struct *fsp,
1046 SMB_ACL_T theacl)
1048 struct gpfs_config_data *config;
1050 SMB_VFS_HANDLE_GET_DATA(handle, config,
1051 struct gpfs_config_data,
1052 return -1);
1054 if (!config->acl) {
1055 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1058 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
1059 SMB_ACL_TYPE_ACCESS, theacl);
1062 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1063 const char *path)
1065 struct gpfs_config_data *config;
1067 SMB_VFS_HANDLE_GET_DATA(handle, config,
1068 struct gpfs_config_data,
1069 return -1);
1071 if (!config->acl) {
1072 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1075 errno = ENOTSUP;
1076 return -1;
1080 * Assumed: mode bits are shiftable and standard
1081 * Output: the new aceMask field for an smb nfs4 ace
1083 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
1085 const uint32 posix_nfs4map[3] = {
1086 SMB_ACE4_EXECUTE, /* execute */
1087 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1088 SMB_ACE4_READ_DATA /* read */
1090 int i;
1091 uint32_t posix_mask = 0x01;
1092 uint32_t posix_bit;
1093 uint32_t nfs4_bits;
1095 for(i=0; i<3; i++) {
1096 nfs4_bits = posix_nfs4map[i];
1097 posix_bit = rwx & posix_mask;
1099 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1100 if (posix_bit)
1101 aceMask |= nfs4_bits;
1102 else
1103 aceMask &= ~nfs4_bits;
1104 } else {
1105 /* add deny bits when suitable */
1106 if (!posix_bit)
1107 aceMask |= nfs4_bits;
1108 else
1109 aceMask &= ~nfs4_bits;
1110 } /* other ace types are unexpected */
1112 posix_mask <<= 1;
1115 return aceMask;
1118 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1119 const char *path, mode_t mode)
1121 SMB4ACL_T *pacl = NULL;
1122 int result;
1123 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1124 int i;
1125 files_struct fake_fsp; /* TODO: rationalize parametrization */
1126 SMB4ACE_T *smbace;
1127 TALLOC_CTX *frame = talloc_stackframe();
1128 NTSTATUS status;
1130 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1132 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1133 if (result) {
1134 TALLOC_FREE(frame);
1135 return result;
1138 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1139 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1142 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1143 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1144 uint32_t specid = ace->who.special_id;
1146 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1147 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1148 specid <= SMB_ACE4_WHO_EVERYONE) {
1150 uint32_t newMask;
1152 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1153 haveAllowEntry[specid] = True;
1155 /* mode >> 6 for @owner, mode >> 3 for @group,
1156 * mode >> 0 for @everyone */
1157 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1158 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1159 if (ace->aceMask!=newMask) {
1160 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1161 path, ace->aceMask, newMask, specid));
1163 ace->aceMask = newMask;
1167 /* make sure we have at least ALLOW entries
1168 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1169 * - if necessary
1171 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1172 SMB_ACE4PROP_T ace;
1174 if (haveAllowEntry[i]==True)
1175 continue;
1177 ZERO_STRUCT(ace);
1178 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1179 ace.flags |= SMB_ACE4_ID_SPECIAL;
1180 ace.who.special_id = i;
1182 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1183 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1185 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1186 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1188 /* don't add unnecessary aces */
1189 if (!ace.aceMask)
1190 continue;
1192 /* we add it to the END - as windows expects allow aces */
1193 smb_add_ace4(pacl, &ace);
1194 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1195 path, mode, i, ace.aceMask));
1198 /* don't add complementary DENY ACEs here */
1199 ZERO_STRUCT(fake_fsp);
1200 fake_fsp.fsp_name = synthetic_smb_fname(
1201 frame, path, NULL, NULL);
1202 if (fake_fsp.fsp_name == NULL) {
1203 errno = ENOMEM;
1204 TALLOC_FREE(frame);
1205 return -1;
1207 /* put the acl */
1208 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1209 TALLOC_FREE(frame);
1210 return -1;
1213 TALLOC_FREE(frame);
1214 return 0; /* ok for [f]chmod */
1217 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1219 struct smb_filename *smb_fname_cpath;
1220 int rc;
1222 smb_fname_cpath = synthetic_smb_fname(talloc_tos(), path, NULL, NULL);
1223 if (smb_fname_cpath == NULL) {
1224 errno = ENOMEM;
1225 return -1;
1228 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1229 return -1;
1232 /* avoid chmod() if possible, to preserve acls */
1233 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1234 return 0;
1237 rc = gpfsacl_emu_chmod(handle, path, mode);
1238 if (rc == 1)
1239 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
1240 return rc;
1243 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1245 SMB_STRUCT_STAT st;
1246 int rc;
1248 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1249 return -1;
1252 /* avoid chmod() if possible, to preserve acls */
1253 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1254 return 0;
1257 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1258 mode);
1259 if (rc == 1)
1260 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1261 return rc;
1264 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
1265 const char *name, const void *value, size_t size, int flags){
1266 struct xattr_DOSATTRIB dosattrib;
1267 enum ndr_err_code ndr_err;
1268 DATA_BLOB blob;
1269 const char *attrstr = value;
1270 unsigned int dosmode=0;
1271 struct gpfs_winattr attrs;
1272 int ret = 0;
1273 struct gpfs_config_data *config;
1275 SMB_VFS_HANDLE_GET_DATA(handle, config,
1276 struct gpfs_config_data,
1277 return -1);
1279 if (!config->winattr) {
1280 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
1281 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1284 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
1286 /* Only handle DOS Attributes */
1287 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1288 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
1289 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1292 blob.data = (uint8_t *)attrstr;
1293 blob.length = size;
1295 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
1296 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
1298 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1299 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1300 "from EA on file %s: Error = %s\n",
1301 path, ndr_errstr(ndr_err)));
1302 return false;
1305 if (dosattrib.version != 3) {
1306 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1307 "%d\n", (int)dosattrib.version));
1308 return false;
1310 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
1311 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1312 "valid, ignoring\n"));
1313 return true;
1316 dosmode = dosattrib.info.info3.attrib;
1318 attrs.winAttrs = 0;
1319 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1320 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1321 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1323 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1324 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1326 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1327 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1329 if (dosmode & FILE_ATTRIBUTE_READONLY){
1330 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1332 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1333 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1337 ret = set_gpfs_winattrs(discard_const_p(char, path),
1338 GPFS_WINATTR_SET_ATTRS, &attrs);
1339 if ( ret == -1){
1340 if (errno == ENOSYS) {
1341 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1342 size, flags);
1345 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1346 return -1;
1349 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1350 return 0;
1353 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1354 const char *name, void *value, size_t size){
1355 char *attrstr = value;
1356 unsigned int dosmode = 0;
1357 struct gpfs_winattr attrs;
1358 int ret = 0;
1359 struct gpfs_config_data *config;
1361 SMB_VFS_HANDLE_GET_DATA(handle, config,
1362 struct gpfs_config_data,
1363 return -1);
1365 if (!config->winattr) {
1366 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1367 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1370 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1372 /* Only handle DOS Attributes */
1373 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1374 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1375 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1378 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1379 if ( ret == -1){
1380 if (errno == ENOSYS) {
1381 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1382 size);
1385 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1386 "%d (%s)\n", ret, strerror(errno)));
1387 return -1;
1390 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1392 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1393 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1394 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1396 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1397 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1399 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1400 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1402 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1403 dosmode |= FILE_ATTRIBUTE_READONLY;
1405 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1406 dosmode |= FILE_ATTRIBUTE_SPARSE;
1409 snprintf(attrstr, size, "0x%2.2x",
1410 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1411 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1412 return 4;
1415 #if defined(HAVE_FSTATAT)
1416 static int stat_with_capability(struct vfs_handle_struct *handle,
1417 struct smb_filename *smb_fname, int flag)
1419 int fd = -1;
1420 bool b;
1421 char *dir_name;
1422 const char *rel_name = NULL;
1423 struct stat st;
1424 int ret = -1;
1426 b = parent_dirname(talloc_tos(), smb_fname->base_name,
1427 &dir_name, &rel_name);
1428 if (!b) {
1429 errno = ENOMEM;
1430 return -1;
1433 fd = open(dir_name, O_RDONLY, 0);
1434 TALLOC_FREE(dir_name);
1435 if (fd == -1) {
1436 return -1;
1439 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1440 ret = fstatat(fd, rel_name, &st, flag);
1441 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1443 close(fd);
1445 if (ret == 0) {
1446 init_stat_ex_from_stat(
1447 &smb_fname->st, &st,
1448 lp_fake_dir_create_times(SNUM(handle->conn)));
1451 return ret;
1453 #endif
1455 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1456 struct smb_filename *smb_fname)
1458 struct gpfs_winattr attrs;
1459 char *fname = NULL;
1460 NTSTATUS status;
1461 int ret;
1462 struct gpfs_config_data *config;
1464 SMB_VFS_HANDLE_GET_DATA(handle, config,
1465 struct gpfs_config_data,
1466 return -1);
1468 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1469 #if defined(HAVE_FSTATAT)
1470 if (ret == -1 && errno == EACCES) {
1471 DEBUG(10, ("Trying stat with capability for %s\n",
1472 smb_fname->base_name));
1473 ret = stat_with_capability(handle, smb_fname, 0);
1475 #endif
1476 if (ret == -1) {
1477 return -1;
1480 if (!config->winattr) {
1481 return 0;
1484 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1485 if (!NT_STATUS_IS_OK(status)) {
1486 errno = map_errno_from_nt_status(status);
1487 return -1;
1489 ret = get_gpfs_winattrs(discard_const_p(char, fname), &attrs);
1490 TALLOC_FREE(fname);
1491 if (ret == 0) {
1492 smb_fname->st.st_ex_calculated_birthtime = false;
1493 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1494 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1495 smb_fname->st.vfs_private = attrs.winAttrs;
1497 return 0;
1500 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1501 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1503 struct gpfs_winattr attrs;
1504 int ret;
1505 struct gpfs_config_data *config;
1507 SMB_VFS_HANDLE_GET_DATA(handle, config,
1508 struct gpfs_config_data,
1509 return -1);
1511 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1512 if (ret == -1) {
1513 return -1;
1515 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1516 return 0;
1518 if (!config->winattr) {
1519 return 0;
1522 ret = smbd_fget_gpfs_winattrs(fsp->fh->fd, &attrs);
1523 if (ret == 0) {
1524 sbuf->st_ex_calculated_birthtime = false;
1525 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1526 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1528 return 0;
1531 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1532 struct smb_filename *smb_fname)
1534 struct gpfs_winattr attrs;
1535 char *path = NULL;
1536 NTSTATUS status;
1537 int ret;
1538 struct gpfs_config_data *config;
1540 SMB_VFS_HANDLE_GET_DATA(handle, config,
1541 struct gpfs_config_data,
1542 return -1);
1544 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1545 #if defined(HAVE_FSTATAT)
1546 if (ret == -1 && errno == EACCES) {
1547 DEBUG(10, ("Trying lstat with capability for %s\n",
1548 smb_fname->base_name));
1549 ret = stat_with_capability(handle, smb_fname,
1550 AT_SYMLINK_NOFOLLOW);
1552 #endif
1554 if (ret == -1) {
1555 return -1;
1557 if (!config->winattr) {
1558 return 0;
1561 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1562 if (!NT_STATUS_IS_OK(status)) {
1563 errno = map_errno_from_nt_status(status);
1564 return -1;
1566 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1567 TALLOC_FREE(path);
1568 if (ret == 0) {
1569 smb_fname->st.st_ex_calculated_birthtime = false;
1570 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1571 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1572 smb_fname->st.vfs_private = attrs.winAttrs;
1574 return 0;
1577 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1578 const struct smb_filename *smb_fname,
1579 struct smb_file_time *ft)
1582 struct gpfs_winattr attrs;
1583 int ret;
1584 char *path = NULL;
1585 NTSTATUS status;
1586 struct gpfs_config_data *config;
1588 SMB_VFS_HANDLE_GET_DATA(handle, config,
1589 struct gpfs_config_data,
1590 return -1);
1592 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1593 if (!NT_STATUS_IS_OK(status)) {
1594 errno = map_errno_from_nt_status(status);
1595 return -1;
1598 /* Try to use gpfs_set_times if it is enabled and available */
1599 if (config->settimes) {
1600 ret = smbd_gpfs_set_times_path(path, ft);
1602 if (ret == 0 || (ret == -1 && errno != ENOSYS)) {
1603 return ret;
1607 DEBUG(10,("gpfs_set_times() not available or disabled, "
1608 "use ntimes and winattr\n"));
1610 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1611 if(ret == -1){
1612 /* don't complain if access was denied */
1613 if (errno != EPERM && errno != EACCES) {
1614 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1615 "%s", strerror(errno)));
1617 return -1;
1620 if(null_timespec(ft->create_time)){
1621 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1622 return 0;
1625 if (!config->winattr) {
1626 return 0;
1629 attrs.winAttrs = 0;
1630 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1631 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1633 ret = set_gpfs_winattrs(discard_const_p(char, path),
1634 GPFS_WINATTR_SET_CREATION_TIME, &attrs);
1635 if(ret == -1 && errno != ENOSYS){
1636 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1637 return -1;
1639 return 0;
1643 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1644 struct files_struct *fsp, enum vfs_fallocate_mode mode,
1645 off_t offset, off_t len)
1647 int ret;
1648 struct gpfs_config_data *config;
1650 SMB_VFS_HANDLE_GET_DATA(handle, config,
1651 struct gpfs_config_data,
1652 return -1);
1654 if (!config->prealloc) {
1655 /* you should better not run fallocate() on GPFS at all */
1656 errno = ENOTSUP;
1657 return -1;
1660 if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1661 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1662 errno = ENOTSUP;
1663 return -1;
1666 ret = smbd_gpfs_prealloc(fsp->fh->fd, offset, len);
1668 if (ret == -1 && errno != ENOSYS) {
1669 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
1670 } else if (ret == -1 && errno == ENOSYS) {
1671 DEBUG(10, ("GPFS prealloc not supported.\n"));
1672 } else {
1673 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1676 return ret;
1679 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1680 off_t len)
1682 int result;
1683 struct gpfs_config_data *config;
1685 SMB_VFS_HANDLE_GET_DATA(handle, config,
1686 struct gpfs_config_data,
1687 return -1);
1689 if (!config->ftruncate) {
1690 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1693 result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
1694 if ((result == -1) && (errno == ENOSYS)) {
1695 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1697 return result;
1700 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1701 const struct smb_filename *fname,
1702 SMB_STRUCT_STAT *sbuf)
1704 struct gpfs_winattr attrs;
1705 char *path = NULL;
1706 NTSTATUS status;
1707 struct gpfs_config_data *config;
1709 SMB_VFS_HANDLE_GET_DATA(handle, config,
1710 struct gpfs_config_data,
1711 return -1);
1713 if (!config->winattr) {
1714 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1717 status = get_full_smb_filename(talloc_tos(), fname, &path);
1718 if (!NT_STATUS_IS_OK(status)) {
1719 errno = map_errno_from_nt_status(status);
1720 return -1;
1723 if (VALID_STAT(*sbuf)) {
1724 attrs.winAttrs = sbuf->vfs_private;
1725 } else {
1726 int ret;
1727 ret = get_gpfs_winattrs(path, &attrs);
1729 if (ret == -1) {
1730 TALLOC_FREE(path);
1731 return false;
1734 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1735 DEBUG(10, ("%s is offline\n", path));
1736 TALLOC_FREE(path);
1737 return true;
1739 DEBUG(10, ("%s is online\n", path));
1740 TALLOC_FREE(path);
1741 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1744 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1745 struct files_struct *fsp)
1747 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1750 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1751 files_struct *fsp, const DATA_BLOB *hdr,
1752 off_t offset, size_t n)
1754 if ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0) {
1755 errno = ENOSYS;
1756 return -1;
1758 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1761 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
1762 const char *service, const char *user)
1764 struct gpfs_config_data *config;
1765 int ret;
1767 smbd_gpfs_lib_init();
1769 config = talloc_zero(handle->conn, struct gpfs_config_data);
1770 if (!config) {
1771 DEBUG(0, ("talloc_zero() failed\n"));
1772 errno = ENOMEM;
1773 return -1;
1776 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1777 if (ret < 0) {
1778 TALLOC_FREE(config);
1779 return ret;
1782 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1783 "sharemodes", true);
1785 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1786 "leases", true);
1788 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1789 "hsm", false);
1791 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1792 "syncio", false);
1794 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1795 "winattr", false);
1797 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
1798 "ftruncate", true);
1800 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
1801 "getrealfilename", true);
1803 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
1804 "dfreequota", false);
1806 config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
1807 "prealloc", true);
1809 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
1811 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1812 "settimes", true);
1814 SMB_VFS_HANDLE_SET_DATA(handle, config,
1815 NULL, struct gpfs_config_data,
1816 return -1);
1818 if (config->leases) {
1820 * GPFS lease code is based on kernel oplock code
1821 * so make sure it is turned on
1823 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
1824 DEBUG(5, ("Enabling kernel oplocks for "
1825 "gpfs:leases to work\n"));
1826 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
1827 "true");
1831 * as the kernel does not properly support Level II oplocks
1832 * and GPFS leases code is based on kernel infrastructure, we
1833 * need to turn off Level II oplocks if gpfs:leases is enabled
1835 if (lp_level2_oplocks(SNUM(handle->conn))) {
1836 DEBUG(5, ("gpfs:leases are enabled, disabling "
1837 "Level II oplocks\n"));
1838 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
1839 "false");
1843 return 0;
1846 static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
1847 int *fset_id,
1848 struct gpfs_quotaInfo *qi_user,
1849 struct gpfs_quotaInfo *qi_group,
1850 struct gpfs_quotaInfo *qi_fset)
1852 int err;
1853 char *dir_path;
1854 bool b;
1857 * We want to always use the directory to get the fileset id,
1858 * because files might have a share mode. We also do not want
1859 * to get the parent directory when there is already a
1860 * directory to avoid stepping in a different fileset. The
1861 * path passed here is currently either "." or a filename, so
1862 * this is ok. The proper solution would be having a way to
1863 * query the fileset id without opening the file.
1865 b = parent_dirname(talloc_tos(), path, &dir_path, NULL);
1866 if (!b) {
1867 errno = ENOMEM;
1868 return -1;
1871 DEBUG(10, ("path %s, directory %s\n", path, dir_path));
1873 err = get_gpfs_fset_id(dir_path, fset_id);
1874 if (err) {
1875 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1876 path, dir_path, errno));
1877 return err;
1880 err = get_gpfs_quota(path, GPFS_USRQUOTA, uid, qi_user);
1881 if (err) {
1882 return err;
1885 err = get_gpfs_quota(path, GPFS_GRPQUOTA, gid, qi_group);
1886 if (err) {
1887 return err;
1890 err = get_gpfs_quota(path, GPFS_FILESETQUOTA, *fset_id, qi_fset);
1891 if (err) {
1892 return err;
1895 return 0;
1898 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
1899 uint64_t *dfree, uint64_t *dsize)
1901 uint64_t usage, limit;
1904 * The quota reporting is done in units of 1024 byte blocks, but
1905 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1906 * accordingly. Also filter possibly negative usage counts from gpfs.
1908 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
1909 limit = (uint64_t)qi.blockHardLimit * 2;
1912 * When the grace time for the exceeded soft block quota has been
1913 * exceeded, the soft block quota becomes an additional hard limit.
1915 if (qi.blockSoftLimit &&
1916 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
1917 /* report disk as full */
1918 *dfree = 0;
1919 *dsize = MIN(*dsize, usage);
1922 if (!qi.blockHardLimit)
1923 return;
1925 if (usage >= limit) {
1926 /* report disk as full */
1927 *dfree = 0;
1928 *dsize = MIN(*dsize, usage);
1930 } else {
1931 /* limit has not been reached, determine "free space" */
1932 *dfree = MIN(*dfree, limit - usage);
1933 *dsize = MIN(*dsize, limit);
1937 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle, const char *path,
1938 bool small_query, uint64_t *bsize,
1939 uint64_t *dfree, uint64_t *dsize)
1941 struct security_unix_token *utok;
1942 struct gpfs_quotaInfo qi_user, qi_group, qi_fset;
1943 struct gpfs_config_data *config;
1944 int err, fset_id;
1945 time_t cur_time;
1947 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
1948 return (uint64_t)-1);
1949 if (!config->dfreequota) {
1950 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1951 bsize, dfree, dsize);
1954 err = sys_fsusage(path, dfree, dsize);
1955 if (err) {
1956 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
1957 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1958 bsize, dfree, dsize);
1961 /* sys_fsusage returns units of 512 bytes */
1962 *bsize = 512;
1964 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1965 (unsigned long long)*dfree, (unsigned long long)*dsize));
1967 utok = handle->conn->session_info->unix_token;
1968 err = vfs_gpfs_get_quotas(path, utok->uid, utok->gid, &fset_id,
1969 &qi_user, &qi_group, &qi_fset);
1970 if (err) {
1971 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1972 bsize, dfree, dsize);
1975 cur_time = time(NULL);
1977 /* Adjust free space and size according to quota limits. */
1978 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
1979 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
1981 /* Id 0 indicates the default quota, not an actual quota */
1982 if (fset_id != 0) {
1983 vfs_gpfs_disk_free_quota(qi_fset, cur_time, dfree, dsize);
1986 disk_norm(small_query, bsize, dfree, dsize);
1987 return *dfree;
1990 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
1991 enum timestamp_set_resolution *p_ts_res)
1993 struct gpfs_config_data *config;
1994 uint32_t next;
1996 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
1998 SMB_VFS_HANDLE_GET_DATA(handle, config,
1999 struct gpfs_config_data,
2000 return next);
2002 if (config->hsm) {
2003 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2005 return next;
2008 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
2009 struct smb_filename *smb_fname, files_struct *fsp,
2010 int flags, mode_t mode)
2012 struct gpfs_config_data *config;
2014 SMB_VFS_HANDLE_GET_DATA(handle, config,
2015 struct gpfs_config_data,
2016 return -1);
2018 if (config->syncio) {
2019 flags |= O_SYNC;
2021 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2024 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2025 void *data, size_t n, off_t offset)
2027 ssize_t ret;
2029 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2031 DEBUG(10, ("vfs_private = %x\n",
2032 (unsigned int)fsp->fsp_name->st.vfs_private));
2034 if ((ret != -1) &&
2035 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2036 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2037 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2038 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2039 fsp->fsp_name->base_name);
2042 return ret;
2045 struct vfs_gpfs_pread_state {
2046 struct files_struct *fsp;
2047 ssize_t ret;
2048 int err;
2051 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2053 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2054 TALLOC_CTX *mem_ctx,
2055 struct tevent_context *ev,
2056 struct files_struct *fsp,
2057 void *data, size_t n,
2058 off_t offset)
2060 struct tevent_req *req, *subreq;
2061 struct vfs_gpfs_pread_state *state;
2063 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2064 if (req == NULL) {
2065 return NULL;
2067 state->fsp = fsp;
2068 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2069 n, offset);
2070 if (tevent_req_nomem(subreq, req)) {
2071 return tevent_req_post(req, ev);
2073 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2074 return req;
2077 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2079 struct tevent_req *req = tevent_req_callback_data(
2080 subreq, struct tevent_req);
2081 struct vfs_gpfs_pread_state *state = tevent_req_data(
2082 req, struct vfs_gpfs_pread_state);
2084 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
2085 TALLOC_FREE(subreq);
2086 tevent_req_done(req);
2089 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req, int *err)
2091 struct vfs_gpfs_pread_state *state = tevent_req_data(
2092 req, struct vfs_gpfs_pread_state);
2093 struct files_struct *fsp = state->fsp;
2095 if (tevent_req_is_unix_error(req, err)) {
2096 return -1;
2098 *err = state->err;
2100 DEBUG(10, ("vfs_private = %x\n",
2101 (unsigned int)fsp->fsp_name->st.vfs_private));
2103 if ((state->ret != -1) &&
2104 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2105 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2106 DEBUG(10, ("sending notify\n"));
2107 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2108 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2109 fsp->fsp_name->base_name);
2112 return state->ret;
2115 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2116 const void *data, size_t n, off_t offset)
2118 ssize_t ret;
2120 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2122 DEBUG(10, ("vfs_private = %x\n",
2123 (unsigned int)fsp->fsp_name->st.vfs_private));
2125 if ((ret != -1) &&
2126 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2127 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2128 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2129 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2130 fsp->fsp_name->base_name);
2133 return ret;
2136 struct vfs_gpfs_pwrite_state {
2137 struct files_struct *fsp;
2138 ssize_t ret;
2139 int err;
2142 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2144 static struct tevent_req *vfs_gpfs_pwrite_send(
2145 struct vfs_handle_struct *handle,
2146 TALLOC_CTX *mem_ctx,
2147 struct tevent_context *ev,
2148 struct files_struct *fsp,
2149 const void *data, size_t n,
2150 off_t offset)
2152 struct tevent_req *req, *subreq;
2153 struct vfs_gpfs_pwrite_state *state;
2155 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2156 if (req == NULL) {
2157 return NULL;
2159 state->fsp = fsp;
2160 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2161 n, offset);
2162 if (tevent_req_nomem(subreq, req)) {
2163 return tevent_req_post(req, ev);
2165 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2166 return req;
2169 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2171 struct tevent_req *req = tevent_req_callback_data(
2172 subreq, struct tevent_req);
2173 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2174 req, struct vfs_gpfs_pwrite_state);
2176 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
2177 TALLOC_FREE(subreq);
2178 tevent_req_done(req);
2181 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req, int *err)
2183 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2184 req, struct vfs_gpfs_pwrite_state);
2185 struct files_struct *fsp = state->fsp;
2187 if (tevent_req_is_unix_error(req, err)) {
2188 return -1;
2190 *err = state->err;
2192 DEBUG(10, ("vfs_private = %x\n",
2193 (unsigned int)fsp->fsp_name->st.vfs_private));
2195 if ((state->ret != -1) &&
2196 ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0)) {
2197 fsp->fsp_name->st.vfs_private &= ~GPFS_WINATTR_OFFLINE;
2198 DEBUG(10, ("sending notify\n"));
2199 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2200 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2201 fsp->fsp_name->base_name);
2204 return state->ret;
2208 static struct vfs_fn_pointers vfs_gpfs_fns = {
2209 .connect_fn = vfs_gpfs_connect,
2210 .disk_free_fn = vfs_gpfs_disk_free,
2211 .fs_capabilities_fn = vfs_gpfs_capabilities,
2212 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2213 .linux_setlease_fn = vfs_gpfs_setlease,
2214 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2215 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2216 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2217 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2218 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2219 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2220 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2221 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2222 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2223 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2224 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2225 .chmod_fn = vfs_gpfs_chmod,
2226 .fchmod_fn = vfs_gpfs_fchmod,
2227 .close_fn = vfs_gpfs_close,
2228 .setxattr_fn = gpfs_set_xattr,
2229 .getxattr_fn = gpfs_get_xattr,
2230 .stat_fn = vfs_gpfs_stat,
2231 .fstat_fn = vfs_gpfs_fstat,
2232 .lstat_fn = vfs_gpfs_lstat,
2233 .ntimes_fn = vfs_gpfs_ntimes,
2234 .is_offline_fn = vfs_gpfs_is_offline,
2235 .aio_force_fn = vfs_gpfs_aio_force,
2236 .sendfile_fn = vfs_gpfs_sendfile,
2237 .fallocate_fn = vfs_gpfs_fallocate,
2238 .open_fn = vfs_gpfs_open,
2239 .pread_fn = vfs_gpfs_pread,
2240 .pread_send_fn = vfs_gpfs_pread_send,
2241 .pread_recv_fn = vfs_gpfs_pread_recv,
2242 .pwrite_fn = vfs_gpfs_pwrite,
2243 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2244 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2245 .ftruncate_fn = vfs_gpfs_ftruncate
2248 NTSTATUS vfs_gpfs_init(void);
2249 NTSTATUS vfs_gpfs_init(void)
2251 init_gpfs();
2253 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
2254 &vfs_gpfs_fns);