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"
32 #define DBGC_CLASS DBGC_VFS
34 #include "nfs4_acls.h"
36 #include "system/filesys.h"
38 #include "lib/util/tevent_unix.h"
40 #ifndef GPFS_GETACL_NATIVE
41 #define GPFS_GETACL_NATIVE 0x00000004
44 struct gpfs_config_data {
59 static inline unsigned int gpfs_acl_flags(gpfs_acl_t *gacl)
61 if (gacl->acl_level == 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
62 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
63 return *(unsigned int *)&gacl->ace_v4;
68 static inline gpfs_ace_v4_t *gpfs_ace_ptr(gpfs_acl_t *gacl, unsigned int i)
70 if (gacl->acl_level == 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
71 /* &gacl->v4Level1.ace_v4[i] requires gpfs 3.5 */
72 char *ptr = (char *)&gacl->ace_v4[i] + sizeof(unsigned int);
73 return (gpfs_ace_v4_t *)ptr;
75 return &gacl->ace_v4[i];
78 static bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
81 unsigned int allow = GPFS_SHARE_NONE;
82 unsigned int deny = GPFS_DENY_NONE;
85 if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
86 /* No real file, don't disturb */
90 allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
91 DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
92 allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
95 if (allow == GPFS_SHARE_NONE) {
96 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
99 deny |= (share_access & FILE_SHARE_WRITE) ?
101 deny |= (share_access & (FILE_SHARE_READ)) ?
104 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
105 access_mask, allow, share_access, deny));
107 result = gpfswrap_set_share(fsp->fh->fd, allow, deny);
109 if (errno == ENOSYS) {
110 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
111 "set_share function support not available. "
112 "Allowing access\n"));
115 DEBUG(10, ("gpfs_set_share failed: %s\n",
120 return (result == 0);
123 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
124 uint32 share_mode, uint32 access_mask)
127 struct gpfs_config_data *config;
130 START_PROFILE(syscall_kernel_flock);
132 SMB_VFS_HANDLE_GET_DATA(handle, config,
133 struct gpfs_config_data,
136 if(!config->sharemodes) {
140 kernel_flock(fsp->fh->fd, share_mode, access_mask);
142 if (!set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
146 END_PROFILE(syscall_kernel_flock);
151 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
154 struct gpfs_config_data *config;
156 SMB_VFS_HANDLE_GET_DATA(handle, config,
157 struct gpfs_config_data,
160 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
161 set_gpfs_sharemode(fsp, 0, 0);
164 return SMB_VFS_NEXT_CLOSE(handle, fsp);
167 static int set_gpfs_lease(int fd, int leasetype)
169 int gpfs_type = GPFS_LEASE_NONE;
171 if (leasetype == F_RDLCK) {
172 gpfs_type = GPFS_LEASE_READ;
174 if (leasetype == F_WRLCK) {
175 gpfs_type = GPFS_LEASE_WRITE;
178 /* we unconditionally set CAP_LEASE, rather than looking for
179 -1/EACCES as there is a bug in some versions of
180 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
181 each time we try this with the wrong capabilities set
183 linux_set_lease_capability();
184 return gpfswrap_set_lease(fd, gpfs_type);
187 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
190 struct gpfs_config_data *config;
193 START_PROFILE(syscall_linux_setlease);
195 SMB_VFS_HANDLE_GET_DATA(handle, config,
196 struct gpfs_config_data,
199 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
202 if (config->leases) {
204 * Ensure the lease owner is root to allow
205 * correct delivery of lease-break signals.
208 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
212 END_PROFILE(syscall_linux_setlease);
217 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
225 char real_pathname[PATH_MAX+1];
228 struct gpfs_config_data *config;
230 SMB_VFS_HANDLE_GET_DATA(handle, config,
231 struct gpfs_config_data,
234 if (!config->getrealfilename) {
235 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
236 mem_ctx, found_name);
239 mangled = mangle_is_mangled(name, handle->conn->params);
241 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
242 mem_ctx, found_name);
245 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
246 if (full_path == NULL) {
251 buflen = sizeof(real_pathname) - 1;
253 result = gpfswrap_get_realfilename_path(full_path, real_pathname,
256 TALLOC_FREE(full_path);
258 if ((result == -1) && (errno == ENOSYS)) {
259 return SMB_VFS_NEXT_GET_REAL_FILENAME(
260 handle, path, name, mem_ctx, found_name);
264 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
270 * GPFS does not necessarily null-terminate the returned path
271 * but instead returns the buffer length in buflen.
274 if (buflen < sizeof(real_pathname)) {
275 real_pathname[buflen] = '\0';
277 real_pathname[sizeof(real_pathname)-1] = '\0';
280 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
281 path, name, real_pathname));
283 name = strrchr_m(real_pathname, '/');
289 *found_name = talloc_strdup(mem_ctx, name+1);
290 if (*found_name == NULL) {
298 static void sd2gpfs_control(uint16_t control, struct gpfs_acl *gacl)
300 unsigned int gpfs_aclflags = 0;
301 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
302 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
303 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
304 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
305 gpfs_aclflags = control << 8;
306 if (!(control & SEC_DESC_DACL_PRESENT))
307 gpfs_aclflags |= 0x00800000; /* ACL4_FLAG_NULL_DACL; */
308 if (!(control & SEC_DESC_SACL_PRESENT))
309 gpfs_aclflags |= 0x01000000; /* ACL4_FLAG_NULL_SACL; */
310 gacl->acl_level = 1; /* GPFS_ACL_LEVEL_V4FLAGS*/
311 /* gacl->v4Level1.acl_flags requires gpfs 3.5 */
312 *(unsigned int *)&gacl->ace_v4 = gpfs_aclflags;
315 static uint16_t gpfs2sd_control(unsigned int gpfs_aclflags)
317 uint16_t control = gpfs_aclflags >> 8;
318 control &= SEC_DESC_DACL_PROTECTED | SEC_DESC_SACL_PROTECTED |
319 SEC_DESC_DACL_AUTO_INHERITED | SEC_DESC_SACL_AUTO_INHERITED |
320 SEC_DESC_DACL_DEFAULTED | SEC_DESC_SACL_DEFAULTED |
321 SEC_DESC_DACL_PRESENT | SEC_DESC_SACL_PRESENT;
322 control |= SEC_DESC_SELF_RELATIVE;
326 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
331 DEBUG(0, ("gpfs acl is NULL\n"));
335 DEBUG(level, ("len: %d, level: %d, version: %d, nace: %d, "
337 gacl->acl_len, gacl->acl_level, gacl->acl_version,
338 gacl->acl_nace, gpfs_acl_flags(gacl)));
340 for(i=0; i<gacl->acl_nace; i++)
342 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
343 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, "
344 "iflags:0x%x, who:%u\n",
345 i, gace->aceType, gace->aceFlags, gace->aceMask,
346 gace->aceIFlags, gace->aceWho));
351 * get the ACL from GPFS, allocated on the specified mem_ctx
352 * internally retries when initial buffer was too small
354 * caller needs to cast result to either
355 * raw = yes: struct gpfs_opaque_acl
356 * raw = no: struct gpfs_acl
359 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
362 const gpfs_aclType_t type)
373 aclbuf = talloc_zero_size(mem_ctx, size);
374 if (aclbuf == NULL) {
380 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
381 buf->acl_type = type;
382 flags = GPFS_GETACL_NATIVE;
383 len = (unsigned int *) &(buf->acl_buffer_len);
384 struct_size = sizeof(struct gpfs_opaque_acl);
386 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
387 buf->acl_type = type;
388 buf->acl_level = 1; /* GPFS_ACL_LEVEL_V4FLAGS */
389 flags = GPFS_GETACL_STRUCT;
390 len = &(buf->acl_len);
391 /* reserve space for control flags in gpfs 3.5 and beyond */
392 struct_size = sizeof(struct gpfs_acl) + sizeof(unsigned int);
395 /* set the length of the buffer as input value */
399 ret = gpfswrap_getacl(discard_const_p(char, fname), flags, aclbuf);
400 if ((ret != 0) && (errno == ENOSPC)) {
402 * get the size needed to accommodate the complete buffer
404 * the value returned only applies to the ACL blob in the
405 * struct so make sure to also have headroom for the first
406 * struct members by adding room for the complete struct
407 * (might be a few bytes too much then)
409 size = *len + struct_size;
411 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
416 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
425 /* Tries to get nfs4 acls and returns SMB ACL allocated.
426 * On failure returns 1 if it got non-NFSv4 ACL to prompt
427 * retry with POSIX ACL checks.
428 * On failure returns -1 if there is system (GPFS) error, check errno.
429 * Returns 0 on success
431 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname, SMB4ACL_T **ppacl)
434 struct gpfs_acl *gacl = NULL;
435 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
438 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
441 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
442 fname, strerror(errno)));
446 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
447 DEBUG(10, ("Got non-nfsv4 acl\n"));
448 /* Retry with POSIX ACLs check */
453 *ppacl = smb_create_smb4acl(mem_ctx);
455 if (gacl->acl_level == 1) { /* GPFS_ACL_LEVEL_V4FLAGS */
456 uint16_t control = gpfs2sd_control(gpfs_acl_flags(gacl));
457 smbacl4_set_controlflags(*ppacl, control);
460 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d, control: %x\n",
461 gacl->acl_len, gacl->acl_level, gacl->acl_version,
462 gacl->acl_nace, gpfs_acl_flags(gacl)));
464 for (i=0; i<gacl->acl_nace; i++) {
465 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, i);
466 SMB_ACE4PROP_T smbace;
467 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
468 "who: %d\n", gace->aceType, gace->aceIFlags,
469 gace->aceFlags, gace->aceMask, gace->aceWho));
472 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
473 smbace.flags |= SMB_ACE4_ID_SPECIAL;
474 switch (gace->aceWho) {
475 case ACE4_SPECIAL_OWNER:
476 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
478 case ACE4_SPECIAL_GROUP:
479 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
481 case ACE4_SPECIAL_EVERYONE:
482 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
485 DEBUG(8, ("invalid special gpfs id %d "
486 "ignored\n", gace->aceWho));
487 continue; /* don't add it */
490 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
491 smbace.who.gid = gace->aceWho;
493 smbace.who.uid = gace->aceWho;
496 /* remove redundant deny entries */
497 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
498 struct gpfs_ace_v4 *prev = gpfs_ace_ptr(gacl, i - 1);
499 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
500 prev->aceFlags == gace->aceFlags &&
501 prev->aceIFlags == gace->aceIFlags &&
502 (gace->aceMask & prev->aceMask) == 0 &&
503 gace->aceWho == prev->aceWho) {
504 /* it's redundant - skip it */
509 smbace.aceType = gace->aceType;
510 smbace.aceFlags = gace->aceFlags;
511 smbace.aceMask = gace->aceMask;
512 smb_add_ace4(*ppacl, &smbace);
520 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
521 files_struct *fsp, uint32 security_info,
523 struct security_descriptor **ppdesc)
525 SMB4ACL_T *pacl = NULL;
527 struct gpfs_config_data *config;
528 TALLOC_CTX *frame = talloc_stackframe();
533 SMB_VFS_HANDLE_GET_DATA(handle, config,
534 struct gpfs_config_data,
535 return NT_STATUS_INTERNAL_ERROR);
538 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
544 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
547 status = smb_fget_nt_acl_nfs4(fsp, security_info, mem_ctx,
554 DEBUG(10, ("retrying with posix acl...\n"));
555 status = posix_fget_nt_acl(fsp, security_info,
563 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
564 return map_nt_error_from_unix(errno);
567 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
569 uint32 security_info,
570 TALLOC_CTX *mem_ctx, struct security_descriptor **ppdesc)
572 SMB4ACL_T *pacl = NULL;
574 struct gpfs_config_data *config;
575 TALLOC_CTX *frame = talloc_stackframe();
580 SMB_VFS_HANDLE_GET_DATA(handle, config,
581 struct gpfs_config_data,
582 return NT_STATUS_INTERNAL_ERROR);
585 status = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
591 result = gpfs_get_nfs4_acl(frame, name, &pacl);
594 status = smb_get_nt_acl_nfs4(handle->conn, name, security_info,
595 mem_ctx, ppdesc, pacl);
601 DEBUG(10, ("retrying with posix acl...\n"));
602 status = posix_get_nt_acl(handle->conn, name, security_info,
608 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
610 return map_nt_error_from_unix(errno);
613 static struct gpfs_acl *vfs_gpfs_smbacl2gpfsacl(TALLOC_CTX *mem_ctx,
618 struct gpfs_acl *gacl;
619 gpfs_aclLen_t gacl_len;
622 gacl_len = offsetof(gpfs_acl_t, ace_v4) + sizeof(unsigned int)
623 + smb_get_naces(smbacl) * sizeof(gpfs_ace_v4_t);
625 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
627 DEBUG(0, ("talloc failed\n"));
632 gacl->acl_level = 0; /* GPFS_ACL_LEVEL_BASE */
633 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
634 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
635 gacl->acl_nace = 0; /* change later... */
638 gacl->acl_level = 1; /* GPFS_ACL_LEVEL_V4FLAGS */
639 sd2gpfs_control(smbacl4_get_controlflags(smbacl), gacl);
642 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
643 struct gpfs_ace_v4 *gace = gpfs_ace_ptr(gacl, gacl->acl_nace);
644 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
646 gace->aceType = aceprop->aceType;
647 gace->aceFlags = aceprop->aceFlags;
648 gace->aceMask = aceprop->aceMask;
651 * GPFS can't distinguish between WRITE and APPEND on
652 * files, so one being set without the other is an
653 * error. Sorry for the many ()'s :-)
656 if (!fsp->is_directory
658 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
659 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
661 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
662 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
664 lp_parm_bool(fsp->conn->params->service, "gpfs",
665 "merge_writeappend", True)) {
666 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
667 "WRITE^APPEND, setting WRITE|APPEND\n",
669 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
672 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
674 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
676 switch(aceprop->who.special_id)
678 case SMB_ACE4_WHO_EVERYONE:
679 gace->aceWho = ACE4_SPECIAL_EVERYONE;
681 case SMB_ACE4_WHO_OWNER:
682 gace->aceWho = ACE4_SPECIAL_OWNER;
684 case SMB_ACE4_WHO_GROUP:
685 gace->aceWho = ACE4_SPECIAL_GROUP;
688 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
689 continue; /* don't add it !!! */
692 /* just only for the type safety... */
693 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
694 gace->aceWho = aceprop->who.gid;
696 gace->aceWho = aceprop->who.uid;
701 gacl->acl_len = (char *)gpfs_ace_ptr(gacl, gacl->acl_nace)
706 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle,
711 struct gpfs_acl *gacl;
712 TALLOC_CTX *mem_ctx = talloc_tos();
714 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, true);
715 if (gacl == NULL) { /* out of memory */
718 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
719 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
721 if ((ret != 0) && (errno == EINVAL)) {
722 DEBUG(10, ("Retry without nfs41 control flags\n"));
724 gacl = vfs_gpfs_smbacl2gpfsacl(mem_ctx, fsp, smbacl, false);
725 if (gacl == NULL) { /* out of memory */
728 ret = gpfswrap_putacl(fsp->fsp_name->base_name,
729 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA,
734 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
735 gpfs_dumpacl(8, gacl);
739 DEBUG(10, ("gpfs_putacl succeeded\n"));
743 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
745 struct gpfs_acl *acl;
746 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
748 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
749 fsp->fsp_name->base_name,
752 return map_nt_error_from_unix(errno);
755 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
756 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
757 "refuse_dacl_protected", false)
758 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
759 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
761 return NT_STATUS_NOT_SUPPORTED;
764 result = smb_set_nt_acl_nfs4(handle,
765 fsp, security_info_sent, psd,
766 gpfsacl_process_smbacl);
767 } else { /* assume POSIX ACL - by default... */
768 result = set_nt_acl(fsp, security_info_sent, psd);
775 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
777 struct gpfs_config_data *config;
779 SMB_VFS_HANDLE_GET_DATA(handle, config,
780 struct gpfs_config_data,
781 return NT_STATUS_INTERNAL_ERROR);
784 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
787 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
790 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
795 result = sys_acl_init(mem_ctx);
796 if (result == NULL) {
801 result->count = pacl->acl_nace;
802 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
804 if (result->acl == NULL) {
810 for (i=0; i<pacl->acl_nace; i++) {
811 struct smb_acl_entry *ace = &result->acl[i];
812 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
814 DEBUG(10, ("Converting type %d id %lu perm %x\n",
815 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
816 (int)g_ace->ace_perm));
818 switch (g_ace->ace_type) {
820 ace->a_type = SMB_ACL_USER;
821 ace->info.user.uid = (uid_t)g_ace->ace_who;
823 case GPFS_ACL_USER_OBJ:
824 ace->a_type = SMB_ACL_USER_OBJ;
827 ace->a_type = SMB_ACL_GROUP;
828 ace->info.group.gid = (gid_t)g_ace->ace_who;
830 case GPFS_ACL_GROUP_OBJ:
831 ace->a_type = SMB_ACL_GROUP_OBJ;
834 ace->a_type = SMB_ACL_OTHER;
837 ace->a_type = SMB_ACL_MASK;
840 DEBUG(10, ("Got invalid ace_type: %d\n",
848 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
850 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
852 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
855 DEBUGADD(10, ("Converted to %d perm %x\n",
856 ace->a_type, ace->a_perm));
862 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
865 struct gpfs_acl *pacl;
866 SMB_ACL_T result = NULL;
868 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
871 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
872 path, strerror(errno)));
879 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
880 DEBUG(10, ("Got acl version %d, expected %d\n",
881 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
886 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
887 pacl->acl_len, pacl->acl_level, pacl->acl_version,
890 result = gpfs2smb_acl(pacl, mem_ctx);
891 if (result != NULL) {
906 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
911 gpfs_aclType_t gpfs_type;
912 struct gpfs_config_data *config;
914 SMB_VFS_HANDLE_GET_DATA(handle, config,
915 struct gpfs_config_data,
919 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p,
924 case SMB_ACL_TYPE_ACCESS:
925 gpfs_type = GPFS_ACL_TYPE_ACCESS;
927 case SMB_ACL_TYPE_DEFAULT:
928 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
931 DEBUG(0, ("Got invalid type: %d\n", type));
932 smb_panic("exiting");
935 return gpfsacl_get_posix_acl(path_p, gpfs_type, mem_ctx);
938 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
942 struct gpfs_config_data *config;
944 SMB_VFS_HANDLE_GET_DATA(handle, config,
945 struct gpfs_config_data,
949 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
952 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
953 GPFS_ACL_TYPE_ACCESS, mem_ctx);
956 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
959 char **blob_description,
962 struct gpfs_config_data *config;
963 struct gpfs_opaque_acl *acl = NULL;
967 SMB_VFS_HANDLE_GET_DATA(handle, config,
968 struct gpfs_config_data,
972 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p,
979 acl = (struct gpfs_opaque_acl *)
980 vfs_gpfs_getacl(mem_ctx,
986 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
987 errno, strerror(errno)));
989 /* EINVAL means POSIX ACL, bail out on other cases */
990 if (errno != EINVAL) {
999 * we only need the actual ACL blob here
1000 * acl_version will always be NFS4 because we asked
1002 * acl_type is only used for POSIX ACLs
1004 aclblob.data = (uint8_t*) acl->acl_var_data;
1005 aclblob.length = acl->acl_buffer_len;
1007 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1008 if (!*blob_description) {
1014 result = non_posix_sys_acl_blob_get_file_helper(handle, path_p,
1022 /* fall back to POSIX ACL */
1023 return posix_sys_acl_blob_get_file(handle, path_p, mem_ctx,
1024 blob_description, blob);
1027 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1029 TALLOC_CTX *mem_ctx,
1030 char **blob_description,
1033 struct gpfs_config_data *config;
1034 struct gpfs_opaque_acl *acl = NULL;
1038 SMB_VFS_HANDLE_GET_DATA(handle, config,
1039 struct gpfs_config_data,
1043 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1044 blob_description, blob);
1048 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
1049 fsp->fsp_name->base_name,
1051 GPFS_ACL_TYPE_NFS4);
1054 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
1055 errno, strerror(errno)));
1057 /* EINVAL means POSIX ACL, bail out on other cases */
1058 if (errno != EINVAL) {
1065 * file has NFSv4 ACL
1067 * we only need the actual ACL blob here
1068 * acl_version will always be NFS4 because we asked
1070 * acl_type is only used for POSIX ACLs
1072 aclblob.data = (uint8_t*) acl->acl_var_data;
1073 aclblob.length = acl->acl_buffer_len;
1075 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
1076 if (!*blob_description) {
1082 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
1090 /* fall back to POSIX ACL */
1091 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
1092 blob_description, blob);
1095 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
1096 SMB_ACL_TYPE_T type)
1099 struct gpfs_acl *result;
1102 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
1104 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
1105 sizeof(gpfs_ace_v1_t);
1107 result = (struct gpfs_acl *)SMB_MALLOC(len);
1108 if (result == NULL) {
1113 result->acl_len = len;
1114 result->acl_level = 0;
1115 result->acl_version = GPFS_ACL_VERSION_POSIX;
1116 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
1117 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
1118 result->acl_nace = pacl->count;
1120 for (i=0; i<pacl->count; i++) {
1121 const struct smb_acl_entry *ace = &pacl->acl[i];
1122 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
1124 DEBUG(10, ("Converting type %d perm %x\n",
1125 (int)ace->a_type, (int)ace->a_perm));
1127 g_ace->ace_perm = 0;
1129 switch(ace->a_type) {
1131 g_ace->ace_type = GPFS_ACL_USER;
1132 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
1134 case SMB_ACL_USER_OBJ:
1135 g_ace->ace_type = GPFS_ACL_USER_OBJ;
1136 g_ace->ace_perm |= ACL_PERM_CONTROL;
1140 g_ace->ace_type = GPFS_ACL_GROUP;
1141 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
1143 case SMB_ACL_GROUP_OBJ:
1144 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
1148 g_ace->ace_type = GPFS_ACL_MASK;
1149 g_ace->ace_perm = 0x8f;
1153 g_ace->ace_type = GPFS_ACL_OTHER;
1157 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
1163 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1165 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1167 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1168 ACL_PERM_EXECUTE : 0;
1170 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1171 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1177 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1179 SMB_ACL_TYPE_T type,
1182 struct gpfs_acl *gpfs_acl;
1184 struct gpfs_config_data *config;
1186 SMB_VFS_HANDLE_GET_DATA(handle, config,
1187 struct gpfs_config_data,
1191 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, type, theacl);
1194 gpfs_acl = smb2gpfs_acl(theacl, type);
1195 if (gpfs_acl == NULL) {
1199 result = gpfswrap_putacl(discard_const_p(char, name),
1200 GPFS_PUTACL_STRUCT|GPFS_ACL_SAMBA, gpfs_acl);
1202 SAFE_FREE(gpfs_acl);
1206 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1210 struct gpfs_config_data *config;
1212 SMB_VFS_HANDLE_GET_DATA(handle, config,
1213 struct gpfs_config_data,
1217 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1220 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
1221 SMB_ACL_TYPE_ACCESS, theacl);
1224 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1227 struct gpfs_config_data *config;
1229 SMB_VFS_HANDLE_GET_DATA(handle, config,
1230 struct gpfs_config_data,
1234 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1242 * Assumed: mode bits are shiftable and standard
1243 * Output: the new aceMask field for an smb nfs4 ace
1245 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
1247 const uint32 posix_nfs4map[3] = {
1248 SMB_ACE4_EXECUTE, /* execute */
1249 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1250 SMB_ACE4_READ_DATA /* read */
1253 uint32_t posix_mask = 0x01;
1257 for(i=0; i<3; i++) {
1258 nfs4_bits = posix_nfs4map[i];
1259 posix_bit = rwx & posix_mask;
1261 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1263 aceMask |= nfs4_bits;
1265 aceMask &= ~nfs4_bits;
1267 /* add deny bits when suitable */
1269 aceMask |= nfs4_bits;
1271 aceMask &= ~nfs4_bits;
1272 } /* other ace types are unexpected */
1280 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1281 const char *path, mode_t mode)
1283 SMB4ACL_T *pacl = NULL;
1285 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1287 files_struct fake_fsp; /* TODO: rationalize parametrization */
1289 TALLOC_CTX *frame = talloc_stackframe();
1291 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1293 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1299 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1300 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1303 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1304 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1305 uint32_t specid = ace->who.special_id;
1307 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1308 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1309 specid <= SMB_ACE4_WHO_EVERYONE) {
1313 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1314 haveAllowEntry[specid] = True;
1316 /* mode >> 6 for @owner, mode >> 3 for @group,
1317 * mode >> 0 for @everyone */
1318 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1319 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1320 if (ace->aceMask!=newMask) {
1321 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1322 path, ace->aceMask, newMask, specid));
1324 ace->aceMask = newMask;
1328 /* make sure we have at least ALLOW entries
1329 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1332 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1335 if (haveAllowEntry[i]==True)
1339 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1340 ace.flags |= SMB_ACE4_ID_SPECIAL;
1341 ace.who.special_id = i;
1343 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1344 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1346 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1347 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1349 /* don't add unnecessary aces */
1353 /* we add it to the END - as windows expects allow aces */
1354 smb_add_ace4(pacl, &ace);
1355 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1356 path, mode, i, ace.aceMask));
1359 /* don't add complementary DENY ACEs here */
1360 ZERO_STRUCT(fake_fsp);
1361 fake_fsp.fsp_name = synthetic_smb_fname(
1362 frame, path, NULL, NULL);
1363 if (fake_fsp.fsp_name == NULL) {
1369 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1375 return 0; /* ok for [f]chmod */
1378 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1380 struct smb_filename *smb_fname_cpath;
1383 smb_fname_cpath = synthetic_smb_fname(talloc_tos(), path, NULL, NULL);
1384 if (smb_fname_cpath == NULL) {
1389 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1393 /* avoid chmod() if possible, to preserve acls */
1394 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1398 rc = gpfsacl_emu_chmod(handle, path, mode);
1400 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
1404 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1409 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1413 /* avoid chmod() if possible, to preserve acls */
1414 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1418 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1421 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1425 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
1426 const char *name, const void *value, size_t size, int flags){
1427 struct xattr_DOSATTRIB dosattrib;
1428 enum ndr_err_code ndr_err;
1430 unsigned int dosmode=0;
1431 struct gpfs_winattr attrs;
1433 struct gpfs_config_data *config;
1435 SMB_VFS_HANDLE_GET_DATA(handle, config,
1436 struct gpfs_config_data,
1439 if (!config->winattr) {
1440 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
1441 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1444 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
1446 /* Only handle DOS Attributes */
1447 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1448 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
1449 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1452 blob.data = discard_const_p(uint8_t, value);
1455 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
1456 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
1458 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1459 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1460 "from EA on file %s: Error = %s\n",
1461 path, ndr_errstr(ndr_err)));
1465 if (dosattrib.version != 3) {
1466 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1467 "%d\n", (int)dosattrib.version));
1470 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
1471 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1472 "valid, ignoring\n"));
1476 dosmode = dosattrib.info.info3.attrib;
1479 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1480 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1481 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1483 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1484 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1486 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1487 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1489 if (dosmode & FILE_ATTRIBUTE_READONLY){
1490 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1492 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1493 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1497 ret = gpfswrap_set_winattrs_path(discard_const_p(char, path),
1498 GPFS_WINATTR_SET_ATTRS, &attrs);
1500 if (errno == ENOSYS) {
1501 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1505 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1509 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1513 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1514 const char *name, void *value, size_t size){
1515 char *attrstr = value;
1516 unsigned int dosmode = 0;
1517 struct gpfs_winattr attrs;
1519 struct gpfs_config_data *config;
1521 SMB_VFS_HANDLE_GET_DATA(handle, config,
1522 struct gpfs_config_data,
1525 if (!config->winattr) {
1526 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1527 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1530 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1532 /* Only handle DOS Attributes */
1533 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1534 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1535 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1538 ret = gpfswrap_get_winattrs_path(discard_const_p(char, path), &attrs);
1542 if (errno == ENOSYS) {
1543 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1547 if (errno != EPERM && errno != EACCES) {
1552 DEBUG(dbg_lvl, ("gpfs_get_xattr: Get GPFS attributes failed: "
1553 "%d (%s)\n", ret, strerror(errno)));
1557 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1559 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1560 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1561 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1563 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1564 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1566 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1567 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1569 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1570 dosmode |= FILE_ATTRIBUTE_READONLY;
1572 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1573 dosmode |= FILE_ATTRIBUTE_SPARSE;
1576 snprintf(attrstr, size, "0x%2.2x",
1577 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1578 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1582 #if defined(HAVE_FSTATAT)
1583 static int stat_with_capability(struct vfs_handle_struct *handle,
1584 struct smb_filename *smb_fname, int flag)
1589 const char *rel_name = NULL;
1593 b = parent_dirname(talloc_tos(), smb_fname->base_name,
1594 &dir_name, &rel_name);
1600 fd = open(dir_name, O_RDONLY, 0);
1601 TALLOC_FREE(dir_name);
1606 set_effective_capability(DAC_OVERRIDE_CAPABILITY);
1607 ret = fstatat(fd, rel_name, &st, flag);
1608 drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
1613 init_stat_ex_from_stat(
1614 &smb_fname->st, &st,
1615 lp_fake_directory_create_times(SNUM(handle->conn)));
1622 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1623 struct smb_filename *smb_fname)
1625 struct gpfs_winattr attrs;
1629 struct gpfs_config_data *config;
1631 SMB_VFS_HANDLE_GET_DATA(handle, config,
1632 struct gpfs_config_data,
1635 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1636 #if defined(HAVE_FSTATAT)
1637 if (ret == -1 && errno == EACCES) {
1638 DEBUG(10, ("Trying stat with capability for %s\n",
1639 smb_fname->base_name));
1640 ret = stat_with_capability(handle, smb_fname, 0);
1647 if (!config->winattr) {
1651 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1652 if (!NT_STATUS_IS_OK(status)) {
1653 errno = map_errno_from_nt_status(status);
1656 ret = gpfswrap_get_winattrs_path(discard_const_p(char, fname), &attrs);
1659 smb_fname->st.st_ex_calculated_birthtime = false;
1660 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1661 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1666 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1667 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1669 struct gpfs_winattr attrs;
1671 struct gpfs_config_data *config;
1673 SMB_VFS_HANDLE_GET_DATA(handle, config,
1674 struct gpfs_config_data,
1677 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1681 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1684 if (!config->winattr) {
1688 ret = gpfswrap_get_winattrs(fsp->fh->fd, &attrs);
1690 sbuf->st_ex_calculated_birthtime = false;
1691 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1692 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1697 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1698 struct smb_filename *smb_fname)
1700 struct gpfs_winattr attrs;
1704 struct gpfs_config_data *config;
1706 SMB_VFS_HANDLE_GET_DATA(handle, config,
1707 struct gpfs_config_data,
1710 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1711 #if defined(HAVE_FSTATAT)
1712 if (ret == -1 && errno == EACCES) {
1713 DEBUG(10, ("Trying lstat with capability for %s\n",
1714 smb_fname->base_name));
1715 ret = stat_with_capability(handle, smb_fname,
1716 AT_SYMLINK_NOFOLLOW);
1723 if (!config->winattr) {
1727 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1728 if (!NT_STATUS_IS_OK(status)) {
1729 errno = map_errno_from_nt_status(status);
1732 ret = gpfswrap_get_winattrs_path(discard_const_p(char, path), &attrs);
1735 smb_fname->st.st_ex_calculated_birthtime = false;
1736 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1737 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1742 static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
1743 int idx, int *flags)
1745 if (!null_timespec(ts)) {
1747 gt[idx].tv_sec = ts.tv_sec;
1748 gt[idx].tv_nsec = ts.tv_nsec;
1749 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
1753 static int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
1755 gpfs_timestruc_t gpfs_times[4];
1759 ZERO_ARRAY(gpfs_times);
1760 timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
1761 timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
1762 /* No good mapping from LastChangeTime to ctime, not storing */
1763 timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
1766 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
1770 rc = gpfswrap_set_times_path(path, flags, gpfs_times);
1772 if (rc != 0 && errno != ENOSYS) {
1773 DEBUG(1,("gpfs_set_times() returned with error %s\n",
1780 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1781 const struct smb_filename *smb_fname,
1782 struct smb_file_time *ft)
1785 struct gpfs_winattr attrs;
1789 struct gpfs_config_data *config;
1791 SMB_VFS_HANDLE_GET_DATA(handle, config,
1792 struct gpfs_config_data,
1795 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1796 if (!NT_STATUS_IS_OK(status)) {
1797 errno = map_errno_from_nt_status(status);
1801 /* Try to use gpfs_set_times if it is enabled and available */
1802 if (config->settimes) {
1803 ret = smbd_gpfs_set_times_path(path, ft);
1805 if (ret == 0 || (ret == -1 && errno != ENOSYS)) {
1810 DEBUG(10,("gpfs_set_times() not available or disabled, "
1811 "use ntimes and winattr\n"));
1813 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1815 /* don't complain if access was denied */
1816 if (errno != EPERM && errno != EACCES) {
1817 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1818 "%s", strerror(errno)));
1823 if(null_timespec(ft->create_time)){
1824 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1828 if (!config->winattr) {
1833 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1834 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1836 ret = gpfswrap_set_winattrs_path(discard_const_p(char, path),
1837 GPFS_WINATTR_SET_CREATION_TIME,
1839 if(ret == -1 && errno != ENOSYS){
1840 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1847 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1848 struct files_struct *fsp, enum vfs_fallocate_mode mode,
1849 off_t offset, off_t len)
1852 struct gpfs_config_data *config;
1854 SMB_VFS_HANDLE_GET_DATA(handle, config,
1855 struct gpfs_config_data,
1858 if (!config->prealloc) {
1859 /* you should better not run fallocate() on GPFS at all */
1864 if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1865 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1870 ret = gpfswrap_prealloc(fsp->fh->fd, offset, len);
1872 if (ret == -1 && errno != ENOSYS) {
1873 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
1874 } else if (ret == -1 && errno == ENOSYS) {
1875 DEBUG(10, ("GPFS prealloc not supported.\n"));
1877 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1883 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1887 struct gpfs_config_data *config;
1889 SMB_VFS_HANDLE_GET_DATA(handle, config,
1890 struct gpfs_config_data,
1893 if (!config->ftruncate) {
1894 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1897 result = gpfswrap_ftruncate(fsp->fh->fd, len);
1898 if ((result == -1) && (errno == ENOSYS)) {
1899 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1904 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1905 const struct smb_filename *fname,
1906 SMB_STRUCT_STAT *sbuf)
1908 struct gpfs_winattr attrs;
1911 struct gpfs_config_data *config;
1914 SMB_VFS_HANDLE_GET_DATA(handle, config,
1915 struct gpfs_config_data,
1918 if (!config->winattr) {
1919 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1922 status = get_full_smb_filename(talloc_tos(), fname, &path);
1923 if (!NT_STATUS_IS_OK(status)) {
1924 errno = map_errno_from_nt_status(status);
1928 ret = gpfswrap_get_winattrs_path(path, &attrs);
1934 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1935 DEBUG(10, ("%s is offline\n", path));
1939 DEBUG(10, ("%s is online\n", path));
1941 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1944 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1945 struct files_struct *fsp)
1947 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1950 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1951 files_struct *fsp, const DATA_BLOB *hdr,
1952 off_t offset, size_t n)
1954 if (SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name, &fsp->fsp_name->st))
1959 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1962 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
1963 const char *service, const char *user)
1965 struct gpfs_config_data *config;
1968 gpfswrap_lib_init(0);
1970 config = talloc_zero(handle->conn, struct gpfs_config_data);
1972 DEBUG(0, ("talloc_zero() failed\n"));
1977 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1979 TALLOC_FREE(config);
1983 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1984 "sharemodes", true);
1986 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1989 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1992 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1995 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1998 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
2001 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
2002 "getrealfilename", true);
2004 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
2005 "dfreequota", false);
2007 config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
2010 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
2012 config->settimes = lp_parm_bool(SNUM(handle->conn), "gpfs",
2014 config->recalls = lp_parm_bool(SNUM(handle->conn), "gpfs",
2017 SMB_VFS_HANDLE_SET_DATA(handle, config,
2018 NULL, struct gpfs_config_data,
2021 if (config->leases) {
2023 * GPFS lease code is based on kernel oplock code
2024 * so make sure it is turned on
2026 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
2027 DEBUG(5, ("Enabling kernel oplocks for "
2028 "gpfs:leases to work\n"));
2029 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
2034 * as the kernel does not properly support Level II oplocks
2035 * and GPFS leases code is based on kernel infrastructure, we
2036 * need to turn off Level II oplocks if gpfs:leases is enabled
2038 if (lp_level2_oplocks(SNUM(handle->conn))) {
2039 DEBUG(5, ("gpfs:leases are enabled, disabling "
2040 "Level II oplocks\n"));
2041 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
2049 static int get_gpfs_fset_id(const char *pathname, int *fset_id)
2051 int err, fd, errno_fcntl;
2054 gpfsFcntlHeader_t hdr;
2055 gpfsGetFilesetName_t fsn;
2058 arg.hdr.totalLength = sizeof(arg);
2059 arg.hdr.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
2060 arg.hdr.fcntlReserved = 0;
2061 arg.fsn.structLen = sizeof(arg.fsn);
2062 arg.fsn.structType = GPFS_FCNTL_GET_FILESETNAME;
2064 fd = open(pathname, O_RDONLY);
2066 DEBUG(1, ("Could not open %s: %s\n",
2067 pathname, strerror(errno)));
2071 err = gpfswrap_fcntl(fd, &arg);
2072 errno_fcntl = errno;
2076 errno = errno_fcntl;
2077 if (errno != ENOSYS) {
2078 DEBUG(1, ("GPFS_FCNTL_GET_FILESETNAME for %s failed: "
2079 "%s\n", pathname, strerror(errno)));
2084 err = gpfswrap_getfilesetid(discard_const_p(char, pathname),
2085 arg.fsn.buffer, fset_id);
2086 if (err && errno != ENOSYS) {
2087 DEBUG(1, ("gpfs_getfilesetid for %s failed: %s\n",
2088 pathname, strerror(errno)));
2093 static int get_gpfs_quota(const char *pathname, int type, int id,
2094 struct gpfs_quotaInfo *qi)
2099 ret = gpfswrap_quotactl(discard_const_p(char, pathname),
2100 GPFS_QCMD(Q_GETQUOTA, type), id, qi);
2103 if (errno == GPFS_E_NO_QUOTA_INST) {
2104 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
2105 } else if (errno != ENOSYS) {
2106 DEBUG(0, ("Get quota failed, type %d, id, %d, "
2107 "errno %d.\n", type, id, errno));
2113 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
2114 type, id, qi->blockUsage, qi->blockHardLimit,
2115 qi->blockSoftLimit, qi->blockGraceTime));
2120 static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
2122 struct gpfs_quotaInfo *qi_user,
2123 struct gpfs_quotaInfo *qi_group,
2124 struct gpfs_quotaInfo *qi_fset)
2131 * We want to always use the directory to get the fileset id,
2132 * because files might have a share mode. We also do not want
2133 * to get the parent directory when there is already a
2134 * directory to avoid stepping in a different fileset. The
2135 * path passed here is currently either "." or a filename, so
2136 * this is ok. The proper solution would be having a way to
2137 * query the fileset id without opening the file.
2139 b = parent_dirname(talloc_tos(), path, &dir_path, NULL);
2145 DEBUG(10, ("path %s, directory %s\n", path, dir_path));
2147 err = get_gpfs_fset_id(dir_path, fset_id);
2149 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
2150 path, dir_path, errno));
2154 err = get_gpfs_quota(path, GPFS_USRQUOTA, uid, qi_user);
2159 err = get_gpfs_quota(path, GPFS_GRPQUOTA, gid, qi_group);
2164 err = get_gpfs_quota(path, GPFS_FILESETQUOTA, *fset_id, qi_fset);
2172 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
2173 uint64_t *dfree, uint64_t *dsize)
2175 uint64_t usage, limit;
2178 * The quota reporting is done in units of 1024 byte blocks, but
2179 * sys_fsusage uses units of 512 byte blocks, adjust the block number
2180 * accordingly. Also filter possibly negative usage counts from gpfs.
2182 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
2183 limit = (uint64_t)qi.blockHardLimit * 2;
2186 * When the grace time for the exceeded soft block quota has been
2187 * exceeded, the soft block quota becomes an additional hard limit.
2189 if (qi.blockSoftLimit &&
2190 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
2191 /* report disk as full */
2193 *dsize = MIN(*dsize, usage);
2196 if (!qi.blockHardLimit)
2199 if (usage >= limit) {
2200 /* report disk as full */
2202 *dsize = MIN(*dsize, usage);
2205 /* limit has not been reached, determine "free space" */
2206 *dfree = MIN(*dfree, limit - usage);
2207 *dsize = MIN(*dsize, limit);
2211 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle, const char *path,
2213 uint64_t *dfree, uint64_t *dsize)
2215 struct security_unix_token *utok;
2216 struct gpfs_quotaInfo qi_user, qi_group, qi_fset;
2217 struct gpfs_config_data *config;
2221 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
2222 return (uint64_t)-1);
2223 if (!config->dfreequota) {
2224 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2225 bsize, dfree, dsize);
2228 err = sys_fsusage(path, dfree, dsize);
2230 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
2231 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2232 bsize, dfree, dsize);
2235 /* sys_fsusage returns units of 512 bytes */
2238 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
2239 (unsigned long long)*dfree, (unsigned long long)*dsize));
2241 utok = handle->conn->session_info->unix_token;
2242 err = vfs_gpfs_get_quotas(path, utok->uid, utok->gid, &fset_id,
2243 &qi_user, &qi_group, &qi_fset);
2245 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2246 bsize, dfree, dsize);
2249 cur_time = time(NULL);
2251 /* Adjust free space and size according to quota limits. */
2252 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
2253 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
2255 /* Id 0 indicates the default quota, not an actual quota */
2257 vfs_gpfs_disk_free_quota(qi_fset, cur_time, dfree, dsize);
2260 disk_norm(bsize, dfree, dsize);
2264 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
2265 enum timestamp_set_resolution *p_ts_res)
2267 struct gpfs_config_data *config;
2270 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
2272 SMB_VFS_HANDLE_GET_DATA(handle, config,
2273 struct gpfs_config_data,
2277 next |= FILE_SUPPORTS_REMOTE_STORAGE;
2282 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
2283 struct smb_filename *smb_fname, files_struct *fsp,
2284 int flags, mode_t mode)
2286 struct gpfs_config_data *config;
2288 SMB_VFS_HANDLE_GET_DATA(handle, config,
2289 struct gpfs_config_data,
2292 if (config->hsm && !config->recalls) {
2293 if (SMB_VFS_IS_OFFLINE(handle->conn, smb_fname, &smb_fname->st))
2295 DEBUG(10, ("Refusing access to offline file %s\n",
2302 if (config->syncio) {
2305 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2308 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
2309 void *data, size_t n, off_t offset)
2314 was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2315 &fsp->fsp_name->st);
2317 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2319 if ((ret != -1) && was_offline) {
2320 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2321 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2322 fsp->fsp_name->base_name);
2328 struct vfs_gpfs_pread_state {
2329 struct files_struct *fsp;
2335 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
2337 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
2338 TALLOC_CTX *mem_ctx,
2339 struct tevent_context *ev,
2340 struct files_struct *fsp,
2341 void *data, size_t n,
2344 struct tevent_req *req, *subreq;
2345 struct vfs_gpfs_pread_state *state;
2347 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
2351 state->was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2352 &fsp->fsp_name->st);
2354 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
2356 if (tevent_req_nomem(subreq, req)) {
2357 return tevent_req_post(req, ev);
2359 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
2363 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2365 struct tevent_req *req = tevent_req_callback_data(
2366 subreq, struct tevent_req);
2367 struct vfs_gpfs_pread_state *state = tevent_req_data(
2368 req, struct vfs_gpfs_pread_state);
2370 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
2371 TALLOC_FREE(subreq);
2372 tevent_req_done(req);
2375 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req, int *err)
2377 struct vfs_gpfs_pread_state *state = tevent_req_data(
2378 req, struct vfs_gpfs_pread_state);
2379 struct files_struct *fsp = state->fsp;
2381 if (tevent_req_is_unix_error(req, err)) {
2386 if ((state->ret != -1) && state->was_offline) {
2387 DEBUG(10, ("sending notify\n"));
2388 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2389 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2390 fsp->fsp_name->base_name);
2396 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2397 const void *data, size_t n, off_t offset)
2402 was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2403 &fsp->fsp_name->st);
2405 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2407 if ((ret != -1) && was_offline) {
2408 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2409 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2410 fsp->fsp_name->base_name);
2416 struct vfs_gpfs_pwrite_state {
2417 struct files_struct *fsp;
2423 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2425 static struct tevent_req *vfs_gpfs_pwrite_send(
2426 struct vfs_handle_struct *handle,
2427 TALLOC_CTX *mem_ctx,
2428 struct tevent_context *ev,
2429 struct files_struct *fsp,
2430 const void *data, size_t n,
2433 struct tevent_req *req, *subreq;
2434 struct vfs_gpfs_pwrite_state *state;
2436 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2440 state->was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2441 &fsp->fsp_name->st);
2443 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2445 if (tevent_req_nomem(subreq, req)) {
2446 return tevent_req_post(req, ev);
2448 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2452 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2454 struct tevent_req *req = tevent_req_callback_data(
2455 subreq, struct tevent_req);
2456 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2457 req, struct vfs_gpfs_pwrite_state);
2459 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
2460 TALLOC_FREE(subreq);
2461 tevent_req_done(req);
2464 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req, int *err)
2466 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2467 req, struct vfs_gpfs_pwrite_state);
2468 struct files_struct *fsp = state->fsp;
2470 if (tevent_req_is_unix_error(req, err)) {
2475 if ((state->ret != -1) && state->was_offline) {
2476 DEBUG(10, ("sending notify\n"));
2477 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2478 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2479 fsp->fsp_name->base_name);
2486 static struct vfs_fn_pointers vfs_gpfs_fns = {
2487 .connect_fn = vfs_gpfs_connect,
2488 .disk_free_fn = vfs_gpfs_disk_free,
2489 .fs_capabilities_fn = vfs_gpfs_capabilities,
2490 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2491 .linux_setlease_fn = vfs_gpfs_setlease,
2492 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2493 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2494 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2495 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2496 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2497 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2498 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2499 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2500 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2501 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2502 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2503 .chmod_fn = vfs_gpfs_chmod,
2504 .fchmod_fn = vfs_gpfs_fchmod,
2505 .close_fn = vfs_gpfs_close,
2506 .setxattr_fn = gpfs_set_xattr,
2507 .getxattr_fn = gpfs_get_xattr,
2508 .stat_fn = vfs_gpfs_stat,
2509 .fstat_fn = vfs_gpfs_fstat,
2510 .lstat_fn = vfs_gpfs_lstat,
2511 .ntimes_fn = vfs_gpfs_ntimes,
2512 .is_offline_fn = vfs_gpfs_is_offline,
2513 .aio_force_fn = vfs_gpfs_aio_force,
2514 .sendfile_fn = vfs_gpfs_sendfile,
2515 .fallocate_fn = vfs_gpfs_fallocate,
2516 .open_fn = vfs_gpfs_open,
2517 .pread_fn = vfs_gpfs_pread,
2518 .pread_send_fn = vfs_gpfs_pread_send,
2519 .pread_recv_fn = vfs_gpfs_pread_recv,
2520 .pwrite_fn = vfs_gpfs_pwrite,
2521 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2522 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2523 .ftruncate_fn = vfs_gpfs_ftruncate
2526 NTSTATUS vfs_gpfs_init(void);
2527 NTSTATUS vfs_gpfs_init(void)
2531 ret = gpfswrap_init();
2533 DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
2536 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",