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/>.
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"
29 #include "libcli/security/security.h"
30 #include "nfs4_acls.h"
32 #include "system/filesys.h"
34 #include "lib/util/tevent_unix.h"
37 #define DBGC_CLASS DBGC_VFS
39 #ifndef GPFS_GETACL_NATIVE
40 #define GPFS_GETACL_NATIVE 0x00000004
43 struct gpfs_config_data {
58 static inline unsigned int gpfs_acl_flags(gpfs_acl_t *gacl)
60 if (gacl->acl_level == 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
61 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
62 return *(unsigned int *)&gacl->ace_v4;
67 static inline gpfs_ace_v4_t *gpfs_ace_ptr(gpfs_acl_t *gacl, unsigned int i)
69 if (gacl->acl_level == 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
70 /* &gacl->v4Level1.ace_v4[i] requires gpfs 3.5 */
71 char *ptr = (char *)&gacl->ace_v4[i] + sizeof(unsigned int);
72 return (gpfs_ace_v4_t *)ptr;
74 return &gacl->ace_v4[i];
77 static bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
80 unsigned int allow = GPFS_SHARE_NONE;
81 unsigned int deny = GPFS_DENY_NONE;
84 if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
85 /* No real file, don't disturb */
89 allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
90 DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
91 allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
94 if (allow == GPFS_SHARE_NONE) {
95 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
98 deny |= (share_access & FILE_SHARE_WRITE) ?
100 deny |= (share_access & (FILE_SHARE_READ)) ?
103 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
104 access_mask, allow, share_access, deny));
106 result = gpfswrap_set_share(fsp->fh->fd, allow, deny);
108 if (errno == ENOSYS) {
109 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
110 "set_share function support not available. "
111 "Allowing access\n"));
114 DEBUG(10, ("gpfs_set_share failed: %s\n",
119 return (result == 0);
122 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
123 uint32 share_mode, uint32 access_mask)
126 struct gpfs_config_data *config;
129 START_PROFILE(syscall_kernel_flock);
131 SMB_VFS_HANDLE_GET_DATA(handle, config,
132 struct gpfs_config_data,
135 if(!config->sharemodes) {
139 kernel_flock(fsp->fh->fd, share_mode, access_mask);
141 if (!set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
145 END_PROFILE(syscall_kernel_flock);
150 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
153 struct gpfs_config_data *config;
155 SMB_VFS_HANDLE_GET_DATA(handle, config,
156 struct gpfs_config_data,
159 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
160 set_gpfs_sharemode(fsp, 0, 0);
163 return SMB_VFS_NEXT_CLOSE(handle, fsp);
166 static int set_gpfs_lease(int fd, int leasetype)
168 int gpfs_type = GPFS_LEASE_NONE;
170 if (leasetype == F_RDLCK) {
171 gpfs_type = GPFS_LEASE_READ;
173 if (leasetype == F_WRLCK) {
174 gpfs_type = GPFS_LEASE_WRITE;
177 /* we unconditionally set CAP_LEASE, rather than looking for
178 -1/EACCES as there is a bug in some versions of
179 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
180 each time we try this with the wrong capabilities set
182 linux_set_lease_capability();
183 return gpfswrap_set_lease(fd, gpfs_type);
186 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
189 struct gpfs_config_data *config;
192 START_PROFILE(syscall_linux_setlease);
194 SMB_VFS_HANDLE_GET_DATA(handle, config,
195 struct gpfs_config_data,
198 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
201 if (config->leases) {
203 * Ensure the lease owner is root to allow
204 * correct delivery of lease-break signals.
207 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
211 END_PROFILE(syscall_linux_setlease);
216 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
224 char real_pathname[PATH_MAX+1];
227 struct gpfs_config_data *config;
229 SMB_VFS_HANDLE_GET_DATA(handle, config,
230 struct gpfs_config_data,
233 if (!config->getrealfilename) {
234 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
235 mem_ctx, found_name);
238 mangled = mangle_is_mangled(name, handle->conn->params);
240 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
241 mem_ctx, found_name);
244 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
245 if (full_path == NULL) {
250 buflen = sizeof(real_pathname) - 1;
252 result = gpfswrap_get_realfilename_path(full_path, real_pathname,
255 TALLOC_FREE(full_path);
257 if ((result == -1) && (errno == ENOSYS)) {
258 return SMB_VFS_NEXT_GET_REAL_FILENAME(
259 handle, path, name, mem_ctx, found_name);
263 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
269 * GPFS does not necessarily null-terminate the returned path
270 * but instead returns the buffer length in buflen.
273 if (buflen < sizeof(real_pathname)) {
274 real_pathname[buflen] = '\0';
276 real_pathname[sizeof(real_pathname)-1] = '\0';
279 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
280 path, name, real_pathname));
282 name = strrchr_m(real_pathname, '/');
288 *found_name = talloc_strdup(mem_ctx, name+1);
289 if (*found_name == NULL) {
297 static void sd2gpfs_control(uint16_t control, struct gpfs_acl *gacl)
299 unsigned int gpfs_aclflags = 0;
300 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
301 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
302 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
303 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
304 gpfs_aclflags = control << 8;
305 if (!(control & SEC_DESC_DACL_PRESENT))
306 gpfs_aclflags |= 0x00800000; /* ACL4_FLAG_NULL_DACL; */
307 if (!(control & SEC_DESC_SACL_PRESENT))
308 gpfs_aclflags |= 0x01000000; /* ACL4_FLAG_NULL_SACL; */
309 gacl->acl_level = 1; /* GPFS_ACL_LEVEL_V4FLAGS*/
310 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
311 *(unsigned int *)&gacl->ace_v4 = gpfs_aclflags;
314 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags)
316 uint16_t control = gpfs_aclflags >> 8;
317 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
318 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
319 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
320 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
321 control |= SEC_DESC_SELF_RELATIVE;
325 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
330 DEBUG(0, ("gpfs acl is NULL\n"));
334 DEBUG(level, ("len: %d, level: %d, version: %d, nace: %d, "
336 gacl->acl_len, gacl->acl_level, gacl->acl_version,
337 gacl->acl_nace, gpfs_acl_flags(gacl)));
339 for(i=0; i<gacl->acl_nace; i++)
341 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
342 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
343 "iflags:0x%x, who:%u\n",
344 i, gace->aceType, gace->aceFlags, gace->aceMask,
345 gace->aceIFlags, gace->aceWho));
350 * get the ACL from GPFS, allocated on the specified mem_ctx
351 * internally retries when initial buffer was too small
353 * caller needs to cast result to either
354 * raw = yes: struct gpfs_opaque_acl
355 * raw = no: struct gpfs_acl
358 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
361 const gpfs_aclType_t type)
372 aclbuf = talloc_zero_size(mem_ctx, size);
373 if (aclbuf == NULL) {
379 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
380 buf->acl_type = type;
381 flags = GPFS_GETACL_NATIVE;
382 len = (unsigned int *) &(buf->acl_buffer_len);
383 struct_size = sizeof(struct gpfs_opaque_acl);
385 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
386 buf->acl_type = type;
387 buf->acl_level = 1; /* GPFS_ACL_LEVEL_V4FLAGS */
388 flags = GPFS_GETACL_STRUCT;
389 len = &(buf->acl_len);
390 /* reserve space for control flags in gpfs 3.5 and beyond */
391 struct_size = sizeof(struct gpfs_acl) + sizeof(unsigned int);
394 /* set the length of the buffer as input value */
398 ret = gpfswrap_getacl(discard_const_p(char, fname), flags, aclbuf);
399 if ((ret != 0) && (errno == ENOSPC)) {
401 * get the size needed to accommodate the complete buffer
403 * the value returned only applies to the ACL blob in the
404 * struct so make sure to also have headroom for the first
405 * struct members by adding room for the complete struct
406 * (might be a few bytes too much then)
408 size = *len + struct_size;
410 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
415 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
424 /* Tries to get nfs4 acls and returns SMB ACL allocated.
425 * On failure returns 1 if it got non-NFSv4 ACL to prompt
426 * retry with POSIX ACL checks.
427 * On failure returns -1 if there is system (GPFS) error, check errno.
428 * Returns 0 on success
430 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname, SMB4ACL_T **ppacl)
433 struct gpfs_acl *gacl = NULL;
434 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
437 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
440 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
441 fname, strerror(errno)));
445 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
446 DEBUG(10, ("Got non-nfsv4 acl\n"));
447 /* Retry with POSIX ACLs check */
452 *ppacl = smb_create_smb4acl(mem_ctx);
454 if (gacl->acl_level == 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
455 uint16_t control = gpfs2sd_control(gpfs_acl_flags(gacl));
456 smbacl4_set_controlflags(*ppacl, control);
459 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
460 gacl->acl_len, gacl->acl_level, gacl->acl_version,
461 gacl->acl_nace, gpfs_acl_flags(gacl)));
463 for (i=0; i<gacl->acl_nace; i++) {
464 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
465 SMB_ACE4PROP_T smbace;
466 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
467 "who: %d\n", gace->aceType, gace->aceIFlags,
468 gace->aceFlags, gace->aceMask, gace->aceWho));
471 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
472 smbace.flags |= SMB_ACE4_ID_SPECIAL;
473 switch (gace->aceWho) {
474 case ACE4_SPECIAL_OWNER:
475 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
477 case ACE4_SPECIAL_GROUP:
478 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
480 case ACE4_SPECIAL_EVERYONE:
481 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
484 DEBUG(8, ("invalid special gpfs id %d "
485 "ignored\n", gace->aceWho));
486 continue; /* don't add it */
489 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
490 smbace.who.gid = gace->aceWho;
492 smbace.who.uid = gace->aceWho;
495 /* remove redundant deny entries */
496 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
497 struct gpfs_ace_v4 *prev = gpfs_ace_ptr(gacl, i - 1);
498 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
499 prev->aceFlags == gace->aceFlags &&
500 prev->aceIFlags == gace->aceIFlags &&
501 (gace->aceMask & prev->aceMask) == 0 &&
502 gace->aceWho == prev->aceWho) {
503 /* it's redundant - skip it */
508 smbace.aceType = gace->aceType;
509 smbace.aceFlags = gace->aceFlags;
510 smbace.aceMask = gace->aceMask;
511 smb_add_ace4(*ppacl, &smbace);
519 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
520 files_struct *fsp, uint32 security_info,
522 struct security_descriptor **ppdesc)
524 SMB4ACL_T *pacl = NULL;
526 struct gpfs_config_data *config;
527 TALLOC_CTX *frame = talloc_stackframe();
532 SMB_VFS_HANDLE_GET_DATA(handle, config,
533 struct gpfs_config_data,
534 return NT_STATUS_INTERNAL_ERROR);
537 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
543 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
546 status = smb_fget_nt_acl_nfs4(fsp, security_info, mem_ctx,
553 DEBUG(10, ("retrying with posix acl...\n"));
554 status = posix_fget_nt_acl(fsp, security_info,
562 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
563 return map_nt_error_from_unix(errno);
566 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
568 uint32 security_info,
569 TALLOC_CTX *mem_ctx, struct security_descriptor **ppdesc)
571 SMB4ACL_T *pacl = NULL;
573 struct gpfs_config_data *config;
574 TALLOC_CTX *frame = talloc_stackframe();
579 SMB_VFS_HANDLE_GET_DATA(handle, config,
580 struct gpfs_config_data,
581 return NT_STATUS_INTERNAL_ERROR);
584 status = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
590 result = gpfs_get_nfs4_acl(frame, name, &pacl);
593 status = smb_get_nt_acl_nfs4(handle->conn, name, security_info,
594 mem_ctx, ppdesc, pacl);
600 DEBUG(10, ("retrying with posix acl...\n"));
601 status = posix_get_nt_acl(handle->conn, name, security_info,
607 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
609 return map_nt_error_from_unix(errno);
612 static struct gpfs_acl *vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX *mem_ctx,
617 struct gpfs_acl *gacl;
618 gpfs_aclLen_t gacl_len;
621 gacl_len = offsetof(gpfs_acl_t, ace_v4) + sizeof(unsigned int)
622 + smb_get_naces(smbacl) * sizeof(gpfs_ace_v4_t);
624 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
626 DEBUG(0, ("talloc failed\n"));
631 gacl->acl_level = 0; /* GPFS_ACL_LEVEL_BASE */
632 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
633 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
634 gacl->acl_nace = 0; /* change later... */
637 gacl->acl_level = 1; /* GPFS_ACL_LEVEL_V4FLAGS */
638 sd2gpfs_control(smbacl4_get_controlflags(smbacl), gacl);
641 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
642 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, gacl->acl_nace);
643 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
645 gace->aceType = aceprop->aceType;
646 gace->aceFlags = aceprop->aceFlags;
647 gace->aceMask = aceprop->aceMask;
650 * GPFS can't distinguish between WRITE and APPEND on
651 * files, so one being set without the other is an
652 * error. Sorry for the many ()'s :-)
655 if (!fsp->is_directory
657 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
658 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
660 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
661 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
663 lp_parm_bool(fsp->conn->params->service, "gpfs",
664 "merge_writeappend", True)) {
665 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
666 "WRITE^APPEND, setting WRITE|APPEND\n",
668 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
671 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
673 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
675 switch(aceprop->who.special_id)
677 case SMB_ACE4_WHO_EVERYONE:
678 gace->aceWho = ACE4_SPECIAL_EVERYONE;
680 case SMB_ACE4_WHO_OWNER:
681 gace->aceWho = ACE4_SPECIAL_OWNER;
683 case SMB_ACE4_WHO_GROUP:
684 gace->aceWho = ACE4_SPECIAL_GROUP;
687 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
688 continue; /* don't add it !!! */
691 /* just only for the type safety... */
692 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
693 gace->aceWho = aceprop->who.gid;
695 gace->aceWho = aceprop->who.uid;
700 gacl->acl_len = (char *)gpfs_ace_ptr(gacl, gacl->acl_nace)
705 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle,
710 struct gpfs_acl *gacl;
711 TALLOC_CTX *mem_ctx = talloc_tos();
713 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, true);
714 if (gacl == NULL) { /* out of memory */
717 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
718 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
720 if ((ret != 0) && (errno == EINVAL)) {
721 DEBUG(10, ("Retry without nfs41 control flags\n"));
723 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, false);
724 if (gacl == NULL) { /* out of memory */
727 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
728 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA,
733 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
734 gpfs_dumpacl(8, gacl);
738 DEBUG(10, ("gpfs_putacl succeeded\n"));
742 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
744 struct gpfs_acl *acl;
745 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
747 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
748 fsp->fsp_name->base_name,
751 return map_nt_error_from_unix(errno);
754 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
755 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
756 "refuse_dacl_protected", false)
757 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
758 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
760 return NT_STATUS_NOT_SUPPORTED;
763 result = smb_set_nt_acl_nfs4(handle,
764 fsp, security_info_sent, psd,
765 gpfsacl_process_smbacl);
766 } else { /* assume POSIX ACL - by default... */
767 result = set_nt_acl(fsp, security_info_sent, psd);
774 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
776 struct gpfs_config_data *config;
778 SMB_VFS_HANDLE_GET_DATA(handle, config,
779 struct gpfs_config_data,
780 return NT_STATUS_INTERNAL_ERROR);
783 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
786 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
789 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
794 result = sys_acl_init(mem_ctx);
795 if (result == NULL) {
800 result->count = pacl->acl_nace;
801 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
803 if (result->acl == NULL) {
809 for (i=0; i<pacl->acl_nace; i++) {
810 struct smb_acl_entry *ace = &result->acl[i];
811 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
813 DEBUG(10, ("Converting type %d id %lu perm %x\n",
814 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
815 (int)g_ace->ace_perm));
817 switch (g_ace->ace_type) {
819 ace->a_type = SMB_ACL_USER;
820 ace->info.user.uid = (uid_t)g_ace->ace_who;
822 case GPFS_ACL_USER_OBJ:
823 ace->a_type = SMB_ACL_USER_OBJ;
826 ace->a_type = SMB_ACL_GROUP;
827 ace->info.group.gid = (gid_t)g_ace->ace_who;
829 case GPFS_ACL_GROUP_OBJ:
830 ace->a_type = SMB_ACL_GROUP_OBJ;
833 ace->a_type = SMB_ACL_OTHER;
836 ace->a_type = SMB_ACL_MASK;
839 DEBUG(10, ("Got invalid ace_type: %d\n",
847 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
849 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
851 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
854 DEBUGADD(10, ("Converted to %d perm %x\n",
855 ace->a_type, ace->a_perm));
861 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
864 struct gpfs_acl *pacl;
865 SMB_ACL_T result = NULL;
867 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
870 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
871 path, strerror(errno)));
878 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
879 DEBUG(10, ("Got acl version %d, expected %d\n",
880 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
885 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
886 pacl->acl_len, pacl->acl_level, pacl->acl_version,
889 result = gpfs2smb_acl(pacl, mem_ctx);
890 if (result != NULL) {
905 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
910 gpfs_aclType_t gpfs_type;
911 struct gpfs_config_data *config;
913 SMB_VFS_HANDLE_GET_DATA(handle, config,
914 struct gpfs_config_data,
918 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p,
923 case SMB_ACL_TYPE_ACCESS:
924 gpfs_type = GPFS_ACL_TYPE_ACCESS;
926 case SMB_ACL_TYPE_DEFAULT:
927 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
930 DEBUG(0, ("Got invalid type: %d\n", type));
931 smb_panic("exiting");
934 return gpfsacl_get_posix_acl(path_p, gpfs_type, mem_ctx);
937 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
941 struct gpfs_config_data *config;
943 SMB_VFS_HANDLE_GET_DATA(handle, config,
944 struct gpfs_config_data,
948 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
951 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
952 GPFS_ACL_TYPE_ACCESS, mem_ctx);
955 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
958 char **blob_description,
961 struct gpfs_config_data *config;
962 struct gpfs_opaque_acl *acl = NULL;
966 SMB_VFS_HANDLE_GET_DATA(handle, config,
967 struct gpfs_config_data,
971 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p,
978 acl = (struct gpfs_opaque_acl *)
979 vfs_gpfs_getacl(mem_ctx,
985 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
986 errno, strerror(errno)));
988 /* EINVAL means POSIX ACL, bail out on other cases */
989 if (errno != EINVAL) {
998 * we only need the actual ACL blob here
999 * acl_version will always be NFS4 because we asked
1001 * acl_type is only used for POSIX ACLs
1003 aclblob.data = (uint8_t*) acl->acl_var_data;
1004 aclblob.length = acl->acl_buffer_len;
1006 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1007 if (!*blob_description) {
1013 result = non_posix_sys_acl_blob_get_file_helper(handle, path_p,
1021 /* fall back to POSIX ACL */
1022 return posix_sys_acl_blob_get_file(handle, path_p, mem_ctx,
1023 blob_description, blob);
1026 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1028 TALLOC_CTX *mem_ctx,
1029 char **blob_description,
1032 struct gpfs_config_data *config;
1033 struct gpfs_opaque_acl *acl = NULL;
1037 SMB_VFS_HANDLE_GET_DATA(handle, config,
1038 struct gpfs_config_data,
1042 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1043 blob_description, blob);
1047 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
1048 fsp->fsp_name->base_name,
1050 GPFS_ACL_TYPE_NFS4);
1053 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1054 errno, strerror(errno)));
1056 /* EINVAL means POSIX ACL, bail out on other cases */
1057 if (errno != EINVAL) {
1064 * file has NFSv4 ACL
1066 * we only need the actual ACL blob here
1067 * acl_version will always be NFS4 because we asked
1069 * acl_type is only used for POSIX ACLs
1071 aclblob.data = (uint8_t*) acl->acl_var_data;
1072 aclblob.length = acl->acl_buffer_len;
1074 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1075 if (!*blob_description) {
1081 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
1089 /* fall back to POSIX ACL */
1090 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
1091 blob_description, blob);
1094 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
1095 SMB_ACL_TYPE_T type)
1098 struct gpfs_acl *result;
1101 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
1103 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
1104 sizeof(gpfs_ace_v1_t);
1106 result = (struct gpfs_acl *)SMB_MALLOC(len);
1107 if (result == NULL) {
1112 result->acl_len = len;
1113 result->acl_level = 0;
1114 result->acl_version = GPFS_ACL_VERSION_POSIX;
1115 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
1116 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
1117 result->acl_nace = pacl->count;
1119 for (i=0; i<pacl->count; i++) {
1120 const struct smb_acl_entry *ace = &pacl->acl[i];
1121 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
1123 DEBUG(10, ("Converting type %d perm %x\n",
1124 (int)ace->a_type, (int)ace->a_perm));
1126 g_ace->ace_perm = 0;
1128 switch(ace->a_type) {
1130 g_ace->ace_type = GPFS_ACL_USER;
1131 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
1133 case SMB_ACL_USER_OBJ:
1134 g_ace->ace_type = GPFS_ACL_USER_OBJ;
1135 g_ace->ace_perm |= ACL_PERM_CONTROL;
1139 g_ace->ace_type = GPFS_ACL_GROUP;
1140 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
1142 case SMB_ACL_GROUP_OBJ:
1143 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
1147 g_ace->ace_type = GPFS_ACL_MASK;
1148 g_ace->ace_perm = 0x8f;
1152 g_ace->ace_type = GPFS_ACL_OTHER;
1156 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
1162 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1164 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1166 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1167 ACL_PERM_EXECUTE : 0;
1169 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1170 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1176 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1178 SMB_ACL_TYPE_T type,
1181 struct gpfs_acl *gpfs_acl;
1183 struct gpfs_config_data *config;
1185 SMB_VFS_HANDLE_GET_DATA(handle, config,
1186 struct gpfs_config_data,
1190 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, type, theacl);
1193 gpfs_acl = smb2gpfs_acl(theacl, type);
1194 if (gpfs_acl == NULL) {
1198 result = gpfswrap_putacl(discard_const_p(char, name),
1199 GPFS_PUTACL_STRUCT|GPFS_ACL_SAMBA, gpfs_acl);
1201 SAFE_FREE(gpfs_acl);
1205 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1209 struct gpfs_config_data *config;
1211 SMB_VFS_HANDLE_GET_DATA(handle, config,
1212 struct gpfs_config_data,
1216 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1219 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
1220 SMB_ACL_TYPE_ACCESS, theacl);
1223 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1226 struct gpfs_config_data *config;
1228 SMB_VFS_HANDLE_GET_DATA(handle, config,
1229 struct gpfs_config_data,
1233 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1241 * Assumed: mode bits are shiftable and standard
1242 * Output: the new aceMask field for an smb nfs4 ace
1244 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
1246 const uint32 posix_nfs4map[3] = {
1247 SMB_ACE4_EXECUTE, /* execute */
1248 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1249 SMB_ACE4_READ_DATA /* read */
1252 uint32_t posix_mask = 0x01;
1256 for(i=0; i<3; i++) {
1257 nfs4_bits = posix_nfs4map[i];
1258 posix_bit = rwx & posix_mask;
1260 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1262 aceMask |= nfs4_bits;
1264 aceMask &= ~nfs4_bits;
1266 /* add deny bits when suitable */
1268 aceMask |= nfs4_bits;
1270 aceMask &= ~nfs4_bits;
1271 } /* other ace types are unexpected */
1279 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1280 const char *path, mode_t mode)
1282 SMB4ACL_T *pacl = NULL;
1284 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1286 files_struct fake_fsp; /* TODO: rationalize parametrization */
1288 TALLOC_CTX *frame = talloc_stackframe();
1290 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1292 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1298 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1299 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1302 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1303 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1304 uint32_t specid = ace->who.special_id;
1306 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1307 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1308 specid <= SMB_ACE4_WHO_EVERYONE) {
1312 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1313 haveAllowEntry[specid] = True;
1315 /* mode >> 6 for @owner, mode >> 3 for @group,
1316 * mode >> 0 for @everyone */
1317 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1318 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1319 if (ace->aceMask!=newMask) {
1320 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1321 path, ace->aceMask, newMask, specid));
1323 ace->aceMask = newMask;
1327 /* make sure we have at least ALLOW entries
1328 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1331 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1334 if (haveAllowEntry[i]==True)
1338 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1339 ace.flags |= SMB_ACE4_ID_SPECIAL;
1340 ace.who.special_id = i;
1342 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1343 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1345 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1346 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1348 /* don't add unnecessary aces */
1352 /* we add it to the END - as windows expects allow aces */
1353 smb_add_ace4(pacl, &ace);
1354 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1355 path, mode, i, ace.aceMask));
1358 /* don't add complementary DENY ACEs here */
1359 ZERO_STRUCT(fake_fsp);
1360 fake_fsp.fsp_name = synthetic_smb_fname(
1361 frame, path, NULL, NULL);
1362 if (fake_fsp.fsp_name == NULL) {
1368 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1374 return 0; /* ok for [f]chmod */
1377 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1379 struct smb_filename *smb_fname_cpath;
1382 smb_fname_cpath = synthetic_smb_fname(talloc_tos(), path, NULL, NULL);
1383 if (smb_fname_cpath == NULL) {
1388 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1392 /* avoid chmod() if possible, to preserve acls */
1393 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1397 rc = gpfsacl_emu_chmod(handle, path, mode);
1399 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
1403 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1408 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1412 /* avoid chmod() if possible, to preserve acls */
1413 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1417 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1420 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1424 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
1425 const char *name, const void *value, size_t size, int flags){
1426 struct xattr_DOSATTRIB dosattrib;
1427 enum ndr_err_code ndr_err;
1429 unsigned int dosmode=0;
1430 struct gpfs_winattr attrs;
1432 struct gpfs_config_data *config;
1434 SMB_VFS_HANDLE_GET_DATA(handle, config,
1435 struct gpfs_config_data,
1438 if (!config->winattr) {
1439 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
1440 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1443 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
1445 /* Only handle DOS Attributes */
1446 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1447 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
1448 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1451 blob.data = discard_const_p(uint8_t, value);
1454 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
1455 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
1457 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1458 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1459 "from EA on file %s: Error = %s\n",
1460 path, ndr_errstr(ndr_err)));
1464 if (dosattrib.version != 3) {
1465 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1466 "%d\n", (int)dosattrib.version));
1469 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
1470 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1471 "valid, ignoring\n"));
1475 dosmode = dosattrib.info.info3.attrib;
1478 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1479 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1480 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1482 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1483 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1485 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1486 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1488 if (dosmode & FILE_ATTRIBUTE_READONLY){
1489 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1491 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1492 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1496 ret = gpfswrap_set_winattrs_path(discard_const_p(char, path),
1497 GPFS_WINATTR_SET_ATTRS, &attrs);
1499 if (errno == ENOSYS) {
1500 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1504 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1508 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1512 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1513 const char *name, void *value, size_t size){
1514 char *attrstr = value;
1515 unsigned int dosmode = 0;
1516 struct gpfs_winattr attrs;
1518 struct gpfs_config_data *config;
1520 SMB_VFS_HANDLE_GET_DATA(handle, config,
1521 struct gpfs_config_data,
1524 if (!config->winattr) {
1525 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1526 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1529 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1531 /* Only handle DOS Attributes */
1532 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1533 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1534 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1537 ret = gpfswrap_get_winattrs_path(discard_const_p(char, path), &attrs);
1541 if (errno == ENOSYS) {
1542 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1546 if (errno != EPERM && errno != EACCES) {
1551 DEBUG(dbg_lvl, ("gpfs_get_xattr: Get GPFS attributes failed: "
1552 "%d (%s)\n", ret, strerror(errno)));
1556 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1558 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1559 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1560 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1562 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1563 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1565 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1566 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1568 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1569 dosmode |= FILE_ATTRIBUTE_READONLY;
1571 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1572 dosmode |= FILE_ATTRIBUTE_SPARSE;
1575 snprintf(attrstr, size, "0x%2.2x",
1576 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1577 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1581 #if defined(HAVE_FSTATAT)
1582 static int stat_with_capability(struct vfs_handle_struct *handle,
1583 struct smb_filename *smb_fname, int flag)
1588 const char *rel_name = NULL;
1592 b = parent_dirname(talloc_tos(), smb_fname->base_name,
1593 &dir_name, &rel_name);
1599 fd = open(dir_name, O_RDONLY, 0);
1600 TALLOC_FREE(dir_name);
1605 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1606 ret = fstatat(fd, rel_name, &st, flag);
1607 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1612 init_stat_ex_from_stat(
1613 &smb_fname->st, &st,
1614 lp_fake_directory_create_times(SNUM(handle->conn)));
1621 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1622 struct smb_filename *smb_fname)
1624 struct gpfs_winattr attrs;
1628 struct gpfs_config_data *config;
1630 SMB_VFS_HANDLE_GET_DATA(handle, config,
1631 struct gpfs_config_data,
1634 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1635 #if defined(HAVE_FSTATAT)
1636 if (ret == -1 && errno == EACCES) {
1637 DEBUG(10, ("Trying stat with capability for %s\n",
1638 smb_fname->base_name));
1639 ret = stat_with_capability(handle, smb_fname, 0);
1646 if (!config->winattr) {
1650 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1651 if (!NT_STATUS_IS_OK(status)) {
1652 errno = map_errno_from_nt_status(status);
1655 ret = gpfswrap_get_winattrs_path(discard_const_p(char, fname), &attrs);
1658 smb_fname->st.st_ex_calculated_birthtime = false;
1659 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1660 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1665 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1666 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1668 struct gpfs_winattr attrs;
1670 struct gpfs_config_data *config;
1672 SMB_VFS_HANDLE_GET_DATA(handle, config,
1673 struct gpfs_config_data,
1676 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1680 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1683 if (!config->winattr) {
1687 ret = gpfswrap_get_winattrs(fsp->fh->fd, &attrs);
1689 sbuf->st_ex_calculated_birthtime = false;
1690 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1691 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1696 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1697 struct smb_filename *smb_fname)
1699 struct gpfs_winattr attrs;
1703 struct gpfs_config_data *config;
1705 SMB_VFS_HANDLE_GET_DATA(handle, config,
1706 struct gpfs_config_data,
1709 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1710 #if defined(HAVE_FSTATAT)
1711 if (ret == -1 && errno == EACCES) {
1712 DEBUG(10, ("Trying lstat with capability for %s\n",
1713 smb_fname->base_name));
1714 ret = stat_with_capability(handle, smb_fname,
1715 AT_SYMLINK_NOFOLLOW);
1722 if (!config->winattr) {
1726 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1727 if (!NT_STATUS_IS_OK(status)) {
1728 errno = map_errno_from_nt_status(status);
1731 ret = gpfswrap_get_winattrs_path(discard_const_p(char, path), &attrs);
1734 smb_fname->st.st_ex_calculated_birthtime = false;
1735 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1736 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1741 static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
1742 int idx, int *flags)
1744 if (!null_timespec(ts)) {
1746 gt[idx].tv_sec = ts.tv_sec;
1747 gt[idx].tv_nsec = ts.tv_nsec;
1748 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
1752 static int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
1754 gpfs_timestruc_t gpfs_times[4];
1758 ZERO_ARRAY(gpfs_times);
1759 timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
1760 timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
1761 /* No good mapping from LastChangeTime to ctime, not storing */
1762 timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
1765 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1769 rc = gpfswrap_set_times_path(path, flags, gpfs_times);
1771 if (rc != 0 && errno != ENOSYS) {
1772 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1779 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1780 const struct smb_filename *smb_fname,
1781 struct smb_file_time *ft)
1784 struct gpfs_winattr attrs;
1788 struct gpfs_config_data *config;
1790 SMB_VFS_HANDLE_GET_DATA(handle, config,
1791 struct gpfs_config_data,
1794 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1795 if (!NT_STATUS_IS_OK(status)) {
1796 errno = map_errno_from_nt_status(status);
1800 /* Try to use gpfs_set_times if it is enabled and available */
1801 if (config->settimes) {
1802 ret = smbd_gpfs_set_times_path(path, ft);
1804 if (ret == 0 || (ret == -1 && errno != ENOSYS)) {
1809 DEBUG(10,("gpfs_set_times() not available or disabled, "
1810 "use ntimes and winattr\n"));
1812 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1814 /* don't complain if access was denied */
1815 if (errno != EPERM && errno != EACCES) {
1816 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1817 "%s", strerror(errno)));
1822 if(null_timespec(ft->create_time)){
1823 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1827 if (!config->winattr) {
1832 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1833 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1835 ret = gpfswrap_set_winattrs_path(discard_const_p(char, path),
1836 GPFS_WINATTR_SET_CREATION_TIME,
1838 if(ret == -1 && errno != ENOSYS){
1839 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1846 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1847 struct files_struct *fsp, enum vfs_fallocate_mode mode,
1848 off_t offset, off_t len)
1851 struct gpfs_config_data *config;
1853 SMB_VFS_HANDLE_GET_DATA(handle, config,
1854 struct gpfs_config_data,
1857 if (!config->prealloc) {
1858 /* you should better not run fallocate() on GPFS at all */
1863 if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1864 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1869 ret = gpfswrap_prealloc(fsp->fh->fd, offset, len);
1871 if (ret == -1 && errno != ENOSYS) {
1872 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
1873 } else if (ret == -1 && errno == ENOSYS) {
1874 DEBUG(10, ("GPFS prealloc not supported.\n"));
1876 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1882 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1886 struct gpfs_config_data *config;
1888 SMB_VFS_HANDLE_GET_DATA(handle, config,
1889 struct gpfs_config_data,
1892 if (!config->ftruncate) {
1893 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1896 result = gpfswrap_ftruncate(fsp->fh->fd, len);
1897 if ((result == -1) && (errno == ENOSYS)) {
1898 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1903 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1904 const struct smb_filename *fname,
1905 SMB_STRUCT_STAT *sbuf)
1907 struct gpfs_winattr attrs;
1910 struct gpfs_config_data *config;
1913 SMB_VFS_HANDLE_GET_DATA(handle, config,
1914 struct gpfs_config_data,
1917 if (!config->winattr) {
1918 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1921 status = get_full_smb_filename(talloc_tos(), fname, &path);
1922 if (!NT_STATUS_IS_OK(status)) {
1923 errno = map_errno_from_nt_status(status);
1927 ret = gpfswrap_get_winattrs_path(path, &attrs);
1933 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1934 DEBUG(10, ("%s is offline\n", path));
1938 DEBUG(10, ("%s is online\n", path));
1940 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1943 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1944 struct files_struct *fsp)
1946 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1949 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1950 files_struct *fsp, const DATA_BLOB *hdr,
1951 off_t offset, size_t n)
1953 if (SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name, &fsp->fsp_name->st))
1958 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1961 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
1962 const char *service, const char *user)
1964 struct gpfs_config_data *config;
1967 gpfswrap_lib_init(0);
1969 config = talloc_zero(handle->conn, struct gpfs_config_data);
1971 DEBUG(0, ("talloc_zero() failed\n"));
1976 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1978 TALLOC_FREE(config);
1982 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1983 "sharemodes", true);
1985 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1988 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1991 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1994 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1997 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
2000 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
2001 "getrealfilename", true);
2003 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
2004 "dfreequota", false);
2006 config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
2009 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
2011 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2013 config->recalls = lp_parm_bool(SNUM(handle->conn), "gpfs",
2016 SMB_VFS_HANDLE_SET_DATA(handle, config,
2017 NULL, struct gpfs_config_data,
2020 if (config->leases) {
2022 * GPFS lease code is based on kernel oplock code
2023 * so make sure it is turned on
2025 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
2026 DEBUG(5, ("Enabling kernel oplocks for "
2027 "gpfs:leases to work\n"));
2028 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
2033 * as the kernel does not properly support Level II oplocks
2034 * and GPFS leases code is based on kernel infrastructure, we
2035 * need to turn off Level II oplocks if gpfs:leases is enabled
2037 if (lp_level2_oplocks(SNUM(handle->conn))) {
2038 DEBUG(5, ("gpfs:leases are enabled, disabling "
2039 "Level II oplocks\n"));
2040 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
2048 static int get_gpfs_fset_id(const char *pathname, int *fset_id)
2050 int err, fd, errno_fcntl;
2053 gpfsFcntlHeader_t hdr;
2054 gpfsGetFilesetName_t fsn;
2057 arg.hdr.totalLength = sizeof(arg);
2058 arg.hdr.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
2059 arg.hdr.fcntlReserved = 0;
2060 arg.fsn.structLen = sizeof(arg.fsn);
2061 arg.fsn.structType = GPFS_FCNTL_GET_FILESETNAME;
2063 fd = open(pathname, O_RDONLY);
2065 DEBUG(1, ("Could not open %s: %s\n",
2066 pathname, strerror(errno)));
2070 err = gpfswrap_fcntl(fd, &arg);
2071 errno_fcntl = errno;
2075 errno = errno_fcntl;
2076 if (errno != ENOSYS) {
2077 DEBUG(1, ("GPFS_FCNTL_GET_FILESETNAME for %s failed: "
2078 "%s\n", pathname, strerror(errno)));
2083 err = gpfswrap_getfilesetid(discard_const_p(char, pathname),
2084 arg.fsn.buffer, fset_id);
2085 if (err && errno != ENOSYS) {
2086 DEBUG(1, ("gpfs_getfilesetid for %s failed: %s\n",
2087 pathname, strerror(errno)));
2092 static int get_gpfs_quota(const char *pathname, int type, int id,
2093 struct gpfs_quotaInfo *qi)
2098 ret = gpfswrap_quotactl(discard_const_p(char, pathname),
2099 GPFS_QCMD(Q_GETQUOTA, type), id, qi);
2102 if (errno == GPFS_E_NO_QUOTA_INST) {
2103 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2104 } else if (errno != ENOSYS) {
2105 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2106 "errno %d.\n", type, id, errno));
2112 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2113 type, id, qi->blockUsage, qi->blockHardLimit,
2114 qi->blockSoftLimit, qi->blockGraceTime));
2119 static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
2121 struct gpfs_quotaInfo *qi_user,
2122 struct gpfs_quotaInfo *qi_group,
2123 struct gpfs_quotaInfo *qi_fset)
2130 * We want to always use the directory to get the fileset id,
2131 * because files might have a share mode. We also do not want
2132 * to get the parent directory when there is already a
2133 * directory to avoid stepping in a different fileset. The
2134 * path passed here is currently either "." or a filename, so
2135 * this is ok. The proper solution would be having a way to
2136 * query the fileset id without opening the file.
2138 b = parent_dirname(talloc_tos(), path, &dir_path, NULL);
2144 DEBUG(10, ("path %s, directory %s\n", path, dir_path));
2146 err = get_gpfs_fset_id(dir_path, fset_id);
2148 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
2149 path, dir_path, errno));
2153 err = get_gpfs_quota(path, GPFS_USRQUOTA, uid, qi_user);
2158 err = get_gpfs_quota(path, GPFS_GRPQUOTA, gid, qi_group);
2163 err = get_gpfs_quota(path, GPFS_FILESETQUOTA, *fset_id, qi_fset);
2171 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
2172 uint64_t *dfree, uint64_t *dsize)
2174 uint64_t usage, limit;
2177 * The quota reporting is done in units of 1024 byte blocks, but
2178 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2179 * accordingly. Also filter possibly negative usage counts from gpfs.
2181 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
2182 limit = (uint64_t)qi.blockHardLimit * 2;
2185 * When the grace time for the exceeded soft block quota has been
2186 * exceeded, the soft block quota becomes an additional hard limit.
2188 if (qi.blockSoftLimit &&
2189 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
2190 /* report disk as full */
2192 *dsize = MIN(*dsize, usage);
2195 if (!qi.blockHardLimit)
2198 if (usage >= limit) {
2199 /* report disk as full */
2201 *dsize = MIN(*dsize, usage);
2204 /* limit has not been reached, determine "free space" */
2205 *dfree = MIN(*dfree, limit - usage);
2206 *dsize = MIN(*dsize, limit);
2210 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle, const char *path,
2212 uint64_t *dfree, uint64_t *dsize)
2214 struct security_unix_token *utok;
2215 struct gpfs_quotaInfo qi_user, qi_group, qi_fset;
2216 struct gpfs_config_data *config;
2220 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
2221 return (uint64_t)-1);
2222 if (!config->dfreequota) {
2223 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2224 bsize, dfree, dsize);
2227 err = sys_fsusage(path, dfree, dsize);
2229 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
2230 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2231 bsize, dfree, dsize);
2234 /* sys_fsusage returns units of 512 bytes */
2237 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2238 (unsigned long long)*dfree, (unsigned long long)*dsize));
2240 utok = handle->conn->session_info->unix_token;
2241 err = vfs_gpfs_get_quotas(path, utok->uid, utok->gid, &fset_id,
2242 &qi_user, &qi_group, &qi_fset);
2244 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2245 bsize, dfree, dsize);
2248 cur_time = time(NULL);
2250 /* Adjust free space and size according to quota limits. */
2251 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
2252 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
2254 /* Id 0 indicates the default quota, not an actual quota */
2256 vfs_gpfs_disk_free_quota(qi_fset, cur_time, dfree, dsize);
2259 disk_norm(bsize, dfree, dsize);
2263 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
2264 enum timestamp_set_resolution *p_ts_res)
2266 struct gpfs_config_data *config;
2269 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
2271 SMB_VFS_HANDLE_GET_DATA(handle, config,
2272 struct gpfs_config_data,
2276 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2281 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
2282 struct smb_filename *smb_fname, files_struct *fsp,
2283 int flags, mode_t mode)
2285 struct gpfs_config_data *config;
2287 SMB_VFS_HANDLE_GET_DATA(handle, config,
2288 struct gpfs_config_data,
2291 if (config->hsm && !config->recalls) {
2292 if (SMB_VFS_IS_OFFLINE(handle->conn, smb_fname, &smb_fname->st))
2294 DEBUG(10, ("Refusing access to offline file %s\n",
2301 if (config->syncio) {
2304 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2307 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2308 void *data, size_t n, off_t offset)
2313 was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2314 &fsp->fsp_name->st);
2316 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2318 if ((ret != -1) && was_offline) {
2319 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2320 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2321 fsp->fsp_name->base_name);
2327 struct vfs_gpfs_pread_state {
2328 struct files_struct *fsp;
2334 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2336 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2337 TALLOC_CTX *mem_ctx,
2338 struct tevent_context *ev,
2339 struct files_struct *fsp,
2340 void *data, size_t n,
2343 struct tevent_req *req, *subreq;
2344 struct vfs_gpfs_pread_state *state;
2346 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2350 state->was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2351 &fsp->fsp_name->st);
2353 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2355 if (tevent_req_nomem(subreq, req)) {
2356 return tevent_req_post(req, ev);
2358 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2362 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2364 struct tevent_req *req = tevent_req_callback_data(
2365 subreq, struct tevent_req);
2366 struct vfs_gpfs_pread_state *state = tevent_req_data(
2367 req, struct vfs_gpfs_pread_state);
2369 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
2370 TALLOC_FREE(subreq);
2371 tevent_req_done(req);
2374 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req, int *err)
2376 struct vfs_gpfs_pread_state *state = tevent_req_data(
2377 req, struct vfs_gpfs_pread_state);
2378 struct files_struct *fsp = state->fsp;
2380 if (tevent_req_is_unix_error(req, err)) {
2385 if ((state->ret != -1) && state->was_offline) {
2386 DEBUG(10, ("sending notify\n"));
2387 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2388 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2389 fsp->fsp_name->base_name);
2395 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2396 const void *data, size_t n, off_t offset)
2401 was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2402 &fsp->fsp_name->st);
2404 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2406 if ((ret != -1) && was_offline) {
2407 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2408 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2409 fsp->fsp_name->base_name);
2415 struct vfs_gpfs_pwrite_state {
2416 struct files_struct *fsp;
2422 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2424 static struct tevent_req *vfs_gpfs_pwrite_send(
2425 struct vfs_handle_struct *handle,
2426 TALLOC_CTX *mem_ctx,
2427 struct tevent_context *ev,
2428 struct files_struct *fsp,
2429 const void *data, size_t n,
2432 struct tevent_req *req, *subreq;
2433 struct vfs_gpfs_pwrite_state *state;
2435 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2439 state->was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2440 &fsp->fsp_name->st);
2442 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2444 if (tevent_req_nomem(subreq, req)) {
2445 return tevent_req_post(req, ev);
2447 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2451 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2453 struct tevent_req *req = tevent_req_callback_data(
2454 subreq, struct tevent_req);
2455 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2456 req, struct vfs_gpfs_pwrite_state);
2458 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
2459 TALLOC_FREE(subreq);
2460 tevent_req_done(req);
2463 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req, int *err)
2465 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2466 req, struct vfs_gpfs_pwrite_state);
2467 struct files_struct *fsp = state->fsp;
2469 if (tevent_req_is_unix_error(req, err)) {
2474 if ((state->ret != -1) && state->was_offline) {
2475 DEBUG(10, ("sending notify\n"));
2476 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2477 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2478 fsp->fsp_name->base_name);
2485 static struct vfs_fn_pointers vfs_gpfs_fns = {
2486 .connect_fn = vfs_gpfs_connect,
2487 .disk_free_fn = vfs_gpfs_disk_free,
2488 .fs_capabilities_fn = vfs_gpfs_capabilities,
2489 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2490 .linux_setlease_fn = vfs_gpfs_setlease,
2491 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2492 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2493 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2494 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2495 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2496 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2497 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2498 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2499 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2500 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2501 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2502 .chmod_fn = vfs_gpfs_chmod,
2503 .fchmod_fn = vfs_gpfs_fchmod,
2504 .close_fn = vfs_gpfs_close,
2505 .setxattr_fn = gpfs_set_xattr,
2506 .getxattr_fn = gpfs_get_xattr,
2507 .stat_fn = vfs_gpfs_stat,
2508 .fstat_fn = vfs_gpfs_fstat,
2509 .lstat_fn = vfs_gpfs_lstat,
2510 .ntimes_fn = vfs_gpfs_ntimes,
2511 .is_offline_fn = vfs_gpfs_is_offline,
2512 .aio_force_fn = vfs_gpfs_aio_force,
2513 .sendfile_fn = vfs_gpfs_sendfile,
2514 .fallocate_fn = vfs_gpfs_fallocate,
2515 .open_fn = vfs_gpfs_open,
2516 .pread_fn = vfs_gpfs_pread,
2517 .pread_send_fn = vfs_gpfs_pread_send,
2518 .pread_recv_fn = vfs_gpfs_pread_recv,
2519 .pwrite_fn = vfs_gpfs_pwrite,
2520 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2521 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2522 .ftruncate_fn = vfs_gpfs_ftruncate
2525 NTSTATUS vfs_gpfs_init(void);
2526 NTSTATUS vfs_gpfs_init(void)
2530 ret = gpfswrap_init();
2532 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2535 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",