s4:dlz_bind9: avoid some compiler warnings
[Samba.git] / source3 / modules / vfs_gpfs.c
blobf9eb7e86b123827c7ff6f0c1d40909bc5005ffd3
1 /*
2 Unix SMB/CIFS implementation.
3 Wrap gpfs calls in vfs functions.
5 Copyright (C) Christian Ambach <cambach1@de.ibm.com> 2006
7 Major code contributions by Chetan Shringarpure <chetan.sh@in.ibm.com>
8 and Gomati Mohanan <gomati.mohanan@in.ibm.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "smbd/smbd.h"
26 #include "librpc/gen_ndr/ndr_xattr.h"
27 #include "include/smbprofile.h"
28 #include "modules/non_posix_acls.h"
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_VFS
33 #include <gpfs_gpl.h>
34 #include "nfs4_acls.h"
35 #include "vfs_gpfs.h"
36 #include "system/filesys.h"
37 #include "auth.h"
38 #include "lib/util/tevent_unix.h"
40 struct gpfs_config_data {
41 bool sharemodes;
42 bool leases;
43 bool hsm;
44 bool syncio;
45 bool winattr;
46 bool ftruncate;
47 bool getrealfilename;
48 bool dfreequota;
49 bool prealloc;
50 bool acl;
54 static int vfs_gpfs_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
55 uint32 share_mode, uint32 access_mask)
58 struct gpfs_config_data *config;
59 int ret = 0;
61 SMB_VFS_HANDLE_GET_DATA(handle, config,
62 struct gpfs_config_data,
63 return -1);
65 if(!config->sharemodes) {
66 return 0;
69 START_PROFILE(syscall_kernel_flock);
71 kernel_flock(fsp->fh->fd, share_mode, access_mask);
73 if (!set_gpfs_sharemode(fsp, access_mask, fsp->share_access)) {
74 ret = -1;
77 END_PROFILE(syscall_kernel_flock);
79 return ret;
82 static int vfs_gpfs_close(vfs_handle_struct *handle, files_struct *fsp)
85 struct gpfs_config_data *config;
87 SMB_VFS_HANDLE_GET_DATA(handle, config,
88 struct gpfs_config_data,
89 return -1);
91 if (config->sharemodes && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
92 set_gpfs_sharemode(fsp, 0, 0);
95 return SMB_VFS_NEXT_CLOSE(handle, fsp);
98 static int vfs_gpfs_setlease(vfs_handle_struct *handle, files_struct *fsp,
99 int leasetype)
101 struct gpfs_config_data *config;
102 int ret=0;
104 SMB_VFS_HANDLE_GET_DATA(handle, config,
105 struct gpfs_config_data,
106 return -1);
108 if (linux_set_lease_sighandler(fsp->fh->fd) == -1)
109 return -1;
111 START_PROFILE(syscall_linux_setlease);
113 if (config->leases) {
115 * Ensure the lease owner is root to allow
116 * correct delivery of lease-break signals.
118 become_root();
119 ret = set_gpfs_lease(fsp->fh->fd,leasetype);
120 unbecome_root();
123 END_PROFILE(syscall_linux_setlease);
125 return ret;
128 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct *handle,
129 const char *path,
130 const char *name,
131 TALLOC_CTX *mem_ctx,
132 char **found_name)
134 int result;
135 char *full_path;
136 char real_pathname[PATH_MAX+1];
137 int buflen;
138 bool mangled;
139 struct gpfs_config_data *config;
141 SMB_VFS_HANDLE_GET_DATA(handle, config,
142 struct gpfs_config_data,
143 return -1);
145 if (!config->getrealfilename) {
146 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
147 mem_ctx, found_name);
150 mangled = mangle_is_mangled(name, handle->conn->params);
151 if (mangled) {
152 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
153 mem_ctx, found_name);
156 full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
157 if (full_path == NULL) {
158 errno = ENOMEM;
159 return -1;
162 buflen = sizeof(real_pathname) - 1;
164 result = smbd_gpfs_get_realfilename_path(full_path, real_pathname,
165 &buflen);
167 TALLOC_FREE(full_path);
169 if ((result == -1) && (errno == ENOSYS)) {
170 return SMB_VFS_NEXT_GET_REAL_FILENAME(
171 handle, path, name, mem_ctx, found_name);
174 if (result == -1) {
175 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
176 strerror(errno)));
177 return -1;
181 * GPFS does not necessarily null-terminate the returned path
182 * but instead returns the buffer length in buflen.
185 if (buflen < sizeof(real_pathname)) {
186 real_pathname[buflen] = '\0';
187 } else {
188 real_pathname[sizeof(real_pathname)-1] = '\0';
191 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
192 path, name, real_pathname));
194 name = strrchr_m(real_pathname, '/');
195 if (name == NULL) {
196 errno = ENOENT;
197 return -1;
200 *found_name = talloc_strdup(mem_ctx, name+1);
201 if (*found_name == NULL) {
202 errno = ENOMEM;
203 return -1;
206 return 0;
209 static void gpfs_dumpacl(int level, struct gpfs_acl *gacl)
211 gpfs_aclCount_t i;
212 if (gacl==NULL)
214 DEBUG(0, ("gpfs acl is NULL\n"));
215 return;
218 DEBUG(level, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
219 gacl->acl_nace, gacl->acl_type, gacl->acl_version, gacl->acl_level, gacl->acl_len));
220 for(i=0; i<gacl->acl_nace; i++)
222 struct gpfs_ace_v4 *gace = gacl->ace_v4 + i;
223 DEBUG(level, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
224 i, gace->aceType, gace->aceFlags, gace->aceMask,
225 gace->aceIFlags, gace->aceWho));
230 * get the ACL from GPFS, allocated on the specified mem_ctx
231 * internally retries when initial buffer was too small
233 * caller needs to cast result to either
234 * raw = yes: struct gpfs_opaque_acl
235 * raw = no: struct gpfs_acl
238 static void *vfs_gpfs_getacl(TALLOC_CTX *mem_ctx,
239 const char *fname,
240 const bool raw,
241 const gpfs_aclType_t type)
244 void *aclbuf;
245 size_t size = 512;
246 int ret, flags;
247 unsigned int *len;
248 size_t struct_size;
250 again:
252 aclbuf = talloc_zero_size(mem_ctx, size);
253 if (aclbuf == NULL) {
254 errno = ENOMEM;
255 return NULL;
258 if (raw) {
259 struct gpfs_opaque_acl *buf = (struct gpfs_opaque_acl *) aclbuf;
260 buf->acl_type = type;
261 flags = GPFS_GETACL_NATIVE;
262 len = (unsigned int *) &(buf->acl_buffer_len);
263 struct_size = sizeof(struct gpfs_opaque_acl);
264 } else {
265 struct gpfs_acl *buf = (struct gpfs_acl *) aclbuf;
266 buf->acl_type = type;
267 flags = GPFS_GETACL_STRUCT;
268 len = &(buf->acl_len);
269 struct_size = sizeof(struct gpfs_acl);
272 /* set the length of the buffer as input value */
273 *len = size;
275 errno = 0;
276 ret = smbd_gpfs_getacl((char *)fname, flags, aclbuf);
277 if ((ret != 0) && (errno == ENOSPC)) {
279 * get the size needed to accommodate the complete buffer
281 * the value returned only applies to the ACL blob in the
282 * struct so make sure to also have headroom for the first
283 * struct members by adding room for the complete struct
284 * (might be a few bytes too much then)
286 size = *len + struct_size;
287 talloc_free(aclbuf);
288 DEBUG(10, ("Increasing ACL buffer size to %zu\n", size));
289 goto again;
292 if (ret != 0) {
293 DEBUG(5, ("smbd_gpfs_getacl failed with %s\n",
294 strerror(errno)));
295 talloc_free(aclbuf);
296 return NULL;
299 return aclbuf;
302 /* Tries to get nfs4 acls and returns SMB ACL allocated.
303 * On failure returns 1 if it got non-NFSv4 ACL to prompt
304 * retry with POSIX ACL checks.
305 * On failure returns -1 if there is system (GPFS) error, check errno.
306 * Returns 0 on success
308 static int gpfs_get_nfs4_acl(TALLOC_CTX *mem_ctx, const char *fname, SMB4ACL_T **ppacl)
310 gpfs_aclCount_t i;
311 struct gpfs_acl *gacl = NULL;
312 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname));
314 /* Get the ACL */
315 gacl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(), fname,
316 false, 0);
317 if (gacl == NULL) {
318 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
319 fname, strerror(errno)));
320 return -1;
323 if (gacl->acl_type != GPFS_ACL_TYPE_NFS4) {
324 DEBUG(10, ("Got non-nfsv4 acl\n"));
325 /* Retry with POSIX ACLs check */
326 talloc_free(gacl);
327 return 1;
330 *ppacl = smb_create_smb4acl(mem_ctx);
332 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
333 gacl->acl_len, gacl->acl_level, gacl->acl_version,
334 gacl->acl_nace));
336 for (i=0; i<gacl->acl_nace; i++) {
337 struct gpfs_ace_v4 *gace = &gacl->ace_v4[i];
338 SMB_ACE4PROP_T smbace;
339 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
340 "who: %d\n", gace->aceType, gace->aceIFlags,
341 gace->aceFlags, gace->aceMask, gace->aceWho));
343 ZERO_STRUCT(smbace);
344 if (gace->aceIFlags & ACE4_IFLAG_SPECIAL_ID) {
345 smbace.flags |= SMB_ACE4_ID_SPECIAL;
346 switch (gace->aceWho) {
347 case ACE4_SPECIAL_OWNER:
348 smbace.who.special_id = SMB_ACE4_WHO_OWNER;
349 break;
350 case ACE4_SPECIAL_GROUP:
351 smbace.who.special_id = SMB_ACE4_WHO_GROUP;
352 break;
353 case ACE4_SPECIAL_EVERYONE:
354 smbace.who.special_id = SMB_ACE4_WHO_EVERYONE;
355 break;
356 default:
357 DEBUG(8, ("invalid special gpfs id %d "
358 "ignored\n", gace->aceWho));
359 continue; /* don't add it */
361 } else {
362 if (gace->aceFlags & ACE4_FLAG_GROUP_ID)
363 smbace.who.gid = gace->aceWho;
364 else
365 smbace.who.uid = gace->aceWho;
368 /* remove redundant deny entries */
369 if (i > 0 && gace->aceType == SMB_ACE4_ACCESS_DENIED_ACE_TYPE) {
370 struct gpfs_ace_v4 *prev = &gacl->ace_v4[i-1];
371 if (prev->aceType == SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE &&
372 prev->aceFlags == gace->aceFlags &&
373 prev->aceIFlags == gace->aceIFlags &&
374 (gace->aceMask & prev->aceMask) == 0 &&
375 gace->aceWho == prev->aceWho) {
376 /* it's redundant - skip it */
377 continue;
381 smbace.aceType = gace->aceType;
382 smbace.aceFlags = gace->aceFlags;
383 smbace.aceMask = gace->aceMask;
384 smb_add_ace4(*ppacl, &smbace);
387 talloc_free(gacl);
389 return 0;
392 static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
393 files_struct *fsp, uint32 security_info,
394 TALLOC_CTX *mem_ctx,
395 struct security_descriptor **ppdesc)
397 SMB4ACL_T *pacl = NULL;
398 int result;
399 struct gpfs_config_data *config;
400 TALLOC_CTX *frame = talloc_stackframe();
401 NTSTATUS status;
403 *ppdesc = NULL;
405 SMB_VFS_HANDLE_GET_DATA(handle, config,
406 struct gpfs_config_data,
407 return NT_STATUS_INTERNAL_ERROR);
409 if (!config->acl) {
410 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
411 mem_ctx, ppdesc);
412 TALLOC_FREE(frame);
413 return status;
416 result = gpfs_get_nfs4_acl(frame, fsp->fsp_name->base_name, &pacl);
418 if (result == 0) {
419 status = smb_fget_nt_acl_nfs4(fsp, security_info, mem_ctx,
420 ppdesc, pacl);
421 TALLOC_FREE(frame);
422 return status;
425 if (result > 0) {
426 DEBUG(10, ("retrying with posix acl...\n"));
427 status = posix_fget_nt_acl(fsp, security_info,
428 mem_ctx, ppdesc);
429 TALLOC_FREE(frame);
430 return status;
433 TALLOC_FREE(frame);
435 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
436 return map_nt_error_from_unix(errno);
439 static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
440 const char *name,
441 uint32 security_info,
442 TALLOC_CTX *mem_ctx, struct security_descriptor **ppdesc)
444 SMB4ACL_T *pacl = NULL;
445 int result;
446 struct gpfs_config_data *config;
447 TALLOC_CTX *frame = talloc_stackframe();
448 NTSTATUS status;
450 *ppdesc = NULL;
452 SMB_VFS_HANDLE_GET_DATA(handle, config,
453 struct gpfs_config_data,
454 return NT_STATUS_INTERNAL_ERROR);
456 if (!config->acl) {
457 status = SMB_VFS_NEXT_GET_NT_ACL(handle, name, security_info,
458 mem_ctx, ppdesc);
459 TALLOC_FREE(frame);
460 return status;
463 result = gpfs_get_nfs4_acl(frame, name, &pacl);
465 if (result == 0) {
466 status = smb_get_nt_acl_nfs4(handle->conn, name, security_info,
467 mem_ctx, ppdesc, pacl);
468 TALLOC_FREE(frame);
469 return status;
472 if (result > 0) {
473 DEBUG(10, ("retrying with posix acl...\n"));
474 status = posix_get_nt_acl(handle->conn, name, security_info,
475 mem_ctx, ppdesc);
476 TALLOC_FREE(frame);
477 return status;
480 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
481 TALLOC_FREE(frame);
482 return map_nt_error_from_unix(errno);
485 static bool gpfsacl_process_smbacl(vfs_handle_struct *handle, files_struct *fsp, SMB4ACL_T *smbacl)
487 int ret;
488 gpfs_aclLen_t gacl_len;
489 SMB4ACE_T *smbace;
490 struct gpfs_acl *gacl;
491 TALLOC_CTX *mem_ctx = talloc_tos();
493 gacl_len = offsetof(gpfs_acl_t, ace_v4) + smb_get_naces(smbacl) *
494 sizeof(gpfs_ace_v4_t);
496 gacl = (struct gpfs_acl *)TALLOC_SIZE(mem_ctx, gacl_len);
497 if (gacl == NULL) {
498 DEBUG(0, ("talloc failed\n"));
499 errno = ENOMEM;
500 return False;
503 gacl->acl_len = gacl_len;
504 gacl->acl_level = 0;
505 gacl->acl_version = GPFS_ACL_VERSION_NFS4;
506 gacl->acl_type = GPFS_ACL_TYPE_NFS4;
507 gacl->acl_nace = 0; /* change later... */
509 for (smbace=smb_first_ace4(smbacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
510 struct gpfs_ace_v4 *gace = &gacl->ace_v4[gacl->acl_nace];
511 SMB_ACE4PROP_T *aceprop = smb_get_ace4(smbace);
513 gace->aceType = aceprop->aceType;
514 gace->aceFlags = aceprop->aceFlags;
515 gace->aceMask = aceprop->aceMask;
518 * GPFS can't distinguish between WRITE and APPEND on
519 * files, so one being set without the other is an
520 * error. Sorry for the many ()'s :-)
523 if (!fsp->is_directory
525 ((((gace->aceMask & ACE4_MASK_WRITE) == 0)
526 && ((gace->aceMask & ACE4_MASK_APPEND) != 0))
528 (((gace->aceMask & ACE4_MASK_WRITE) != 0)
529 && ((gace->aceMask & ACE4_MASK_APPEND) == 0)))
531 lp_parm_bool(fsp->conn->params->service, "gpfs",
532 "merge_writeappend", True)) {
533 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
534 "WRITE^APPEND, setting WRITE|APPEND\n",
535 fsp_str_dbg(fsp)));
536 gace->aceMask |= ACE4_MASK_WRITE|ACE4_MASK_APPEND;
539 gace->aceIFlags = (aceprop->flags&SMB_ACE4_ID_SPECIAL) ? ACE4_IFLAG_SPECIAL_ID : 0;
541 if (aceprop->flags&SMB_ACE4_ID_SPECIAL)
543 switch(aceprop->who.special_id)
545 case SMB_ACE4_WHO_EVERYONE:
546 gace->aceWho = ACE4_SPECIAL_EVERYONE;
547 break;
548 case SMB_ACE4_WHO_OWNER:
549 gace->aceWho = ACE4_SPECIAL_OWNER;
550 break;
551 case SMB_ACE4_WHO_GROUP:
552 gace->aceWho = ACE4_SPECIAL_GROUP;
553 break;
554 default:
555 DEBUG(8, ("unsupported special_id %d\n", aceprop->who.special_id));
556 continue; /* don't add it !!! */
558 } else {
559 /* just only for the type safety... */
560 if (aceprop->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)
561 gace->aceWho = aceprop->who.gid;
562 else
563 gace->aceWho = aceprop->who.uid;
566 gacl->acl_nace++;
569 ret = smbd_gpfs_putacl(fsp->fsp_name->base_name,
570 GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gacl);
571 if (ret != 0) {
572 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno)));
573 gpfs_dumpacl(8, gacl);
574 return False;
577 DEBUG(10, ("gpfs_putacl succeeded\n"));
578 return True;
581 static NTSTATUS gpfsacl_set_nt_acl_internal(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
583 struct gpfs_acl *acl;
584 NTSTATUS result = NT_STATUS_ACCESS_DENIED;
586 acl = (struct gpfs_acl*) vfs_gpfs_getacl(talloc_tos(),
587 fsp->fsp_name->base_name,
588 false, 0);
589 if (acl == NULL) {
590 return map_nt_error_from_unix(errno);
593 if (acl->acl_version == GPFS_ACL_VERSION_NFS4) {
594 if (lp_parm_bool(fsp->conn->params->service, "gpfs",
595 "refuse_dacl_protected", false)
596 && (psd->type&SEC_DESC_DACL_PROTECTED)) {
597 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
598 talloc_free(acl);
599 return NT_STATUS_NOT_SUPPORTED;
602 result = smb_set_nt_acl_nfs4(handle,
603 fsp, security_info_sent, psd,
604 gpfsacl_process_smbacl);
605 } else { /* assume POSIX ACL - by default... */
606 result = set_nt_acl(fsp, security_info_sent, psd);
609 talloc_free(acl);
610 return result;
613 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
615 struct gpfs_config_data *config;
617 SMB_VFS_HANDLE_GET_DATA(handle, config,
618 struct gpfs_config_data,
619 return NT_STATUS_INTERNAL_ERROR);
621 if (!config->acl) {
622 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
625 return gpfsacl_set_nt_acl_internal(handle, fsp, security_info_sent, psd);
628 static SMB_ACL_T gpfs2smb_acl(const struct gpfs_acl *pacl, TALLOC_CTX *mem_ctx)
630 SMB_ACL_T result;
631 gpfs_aclCount_t i;
633 result = sys_acl_init(mem_ctx);
634 if (result == NULL) {
635 errno = ENOMEM;
636 return NULL;
639 result->count = pacl->acl_nace;
640 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
641 result->count);
642 if (result->acl == NULL) {
643 TALLOC_FREE(result);
644 errno = ENOMEM;
645 return NULL;
648 for (i=0; i<pacl->acl_nace; i++) {
649 struct smb_acl_entry *ace = &result->acl[i];
650 const struct gpfs_ace_v1 *g_ace = &pacl->ace_v1[i];
652 DEBUG(10, ("Converting type %d id %lu perm %x\n",
653 (int)g_ace->ace_type, (unsigned long)g_ace->ace_who,
654 (int)g_ace->ace_perm));
656 switch (g_ace->ace_type) {
657 case GPFS_ACL_USER:
658 ace->a_type = SMB_ACL_USER;
659 ace->info.user.uid = (uid_t)g_ace->ace_who;
660 break;
661 case GPFS_ACL_USER_OBJ:
662 ace->a_type = SMB_ACL_USER_OBJ;
663 break;
664 case GPFS_ACL_GROUP:
665 ace->a_type = SMB_ACL_GROUP;
666 ace->info.group.gid = (gid_t)g_ace->ace_who;
667 break;
668 case GPFS_ACL_GROUP_OBJ:
669 ace->a_type = SMB_ACL_GROUP_OBJ;
670 break;
671 case GPFS_ACL_OTHER:
672 ace->a_type = SMB_ACL_OTHER;
673 break;
674 case GPFS_ACL_MASK:
675 ace->a_type = SMB_ACL_MASK;
676 break;
677 default:
678 DEBUG(10, ("Got invalid ace_type: %d\n",
679 g_ace->ace_type));
680 TALLOC_FREE(result);
681 errno = EINVAL;
682 return NULL;
685 ace->a_perm = 0;
686 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_READ) ?
687 SMB_ACL_READ : 0;
688 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_WRITE) ?
689 SMB_ACL_WRITE : 0;
690 ace->a_perm |= (g_ace->ace_perm & ACL_PERM_EXECUTE) ?
691 SMB_ACL_EXECUTE : 0;
693 DEBUGADD(10, ("Converted to %d perm %x\n",
694 ace->a_type, ace->a_perm));
697 return result;
700 static SMB_ACL_T gpfsacl_get_posix_acl(const char *path, gpfs_aclType_t type,
701 TALLOC_CTX *mem_ctx)
703 struct gpfs_acl *pacl;
704 SMB_ACL_T result = NULL;
706 pacl = vfs_gpfs_getacl(talloc_tos(), path, false, type);
708 if (pacl == NULL) {
709 DEBUG(10, ("vfs_gpfs_getacl failed for %s with %s\n",
710 path, strerror(errno)));
711 if (errno == 0) {
712 errno = EINVAL;
714 goto done;
717 if (pacl->acl_version != GPFS_ACL_VERSION_POSIX) {
718 DEBUG(10, ("Got acl version %d, expected %d\n",
719 pacl->acl_version, GPFS_ACL_VERSION_POSIX));
720 errno = EINVAL;
721 goto done;
724 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
725 pacl->acl_len, pacl->acl_level, pacl->acl_version,
726 pacl->acl_nace));
728 result = gpfs2smb_acl(pacl, mem_ctx);
729 if (result != NULL) {
730 errno = 0;
733 done:
735 if (pacl != NULL) {
736 talloc_free(pacl);
738 if (errno != 0) {
739 TALLOC_FREE(result);
741 return result;
744 static SMB_ACL_T gpfsacl_sys_acl_get_file(vfs_handle_struct *handle,
745 const char *path_p,
746 SMB_ACL_TYPE_T type,
747 TALLOC_CTX *mem_ctx)
749 gpfs_aclType_t gpfs_type;
750 struct gpfs_config_data *config;
752 SMB_VFS_HANDLE_GET_DATA(handle, config,
753 struct gpfs_config_data,
754 return NULL);
756 if (!config->acl) {
757 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p,
758 type, mem_ctx);
761 switch(type) {
762 case SMB_ACL_TYPE_ACCESS:
763 gpfs_type = GPFS_ACL_TYPE_ACCESS;
764 break;
765 case SMB_ACL_TYPE_DEFAULT:
766 gpfs_type = GPFS_ACL_TYPE_DEFAULT;
767 break;
768 default:
769 DEBUG(0, ("Got invalid type: %d\n", type));
770 smb_panic("exiting");
773 return gpfsacl_get_posix_acl(path_p, gpfs_type, mem_ctx);
776 static SMB_ACL_T gpfsacl_sys_acl_get_fd(vfs_handle_struct *handle,
777 files_struct *fsp,
778 TALLOC_CTX *mem_ctx)
780 struct gpfs_config_data *config;
782 SMB_VFS_HANDLE_GET_DATA(handle, config,
783 struct gpfs_config_data,
784 return NULL);
786 if (!config->acl) {
787 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
790 return gpfsacl_get_posix_acl(fsp->fsp_name->base_name,
791 GPFS_ACL_TYPE_ACCESS, mem_ctx);
794 static int gpfsacl_sys_acl_blob_get_file(vfs_handle_struct *handle,
795 const char *path_p,
796 TALLOC_CTX *mem_ctx,
797 char **blob_description,
798 DATA_BLOB *blob)
800 struct gpfs_config_data *config;
801 struct gpfs_opaque_acl *acl = NULL;
802 DATA_BLOB aclblob;
803 int result;
805 SMB_VFS_HANDLE_GET_DATA(handle, config,
806 struct gpfs_config_data,
807 return -1);
809 if (!config->acl) {
810 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p,
811 mem_ctx,
812 blob_description,
813 blob);
816 errno = 0;
817 acl = (struct gpfs_opaque_acl *)
818 vfs_gpfs_getacl(mem_ctx,
819 path_p,
820 true,
821 GPFS_ACL_TYPE_NFS4);
823 if (errno) {
824 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
825 errno, strerror(errno)));
827 /* EINVAL means POSIX ACL, bail out on other cases */
828 if (errno != EINVAL) {
829 return -1;
833 if (acl != NULL) {
835 * file has NFSv4 ACL
837 * we only need the actual ACL blob here
838 * acl_version will always be NFS4 because we asked
839 * for NFS4
840 * acl_type is only used for POSIX ACLs
842 aclblob.data = (uint8_t*) acl->acl_var_data;
843 aclblob.length = acl->acl_buffer_len;
845 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
846 if (!*blob_description) {
847 talloc_free(acl);
848 errno = ENOMEM;
849 return -1;
852 result = non_posix_sys_acl_blob_get_file_helper(handle, path_p,
853 aclblob,
854 mem_ctx, blob);
856 talloc_free(acl);
857 return result;
860 /* fall back to POSIX ACL */
861 return posix_sys_acl_blob_get_file(handle, path_p, mem_ctx,
862 blob_description, blob);
865 static int gpfsacl_sys_acl_blob_get_fd(vfs_handle_struct *handle,
866 files_struct *fsp,
867 TALLOC_CTX *mem_ctx,
868 char **blob_description,
869 DATA_BLOB *blob)
871 struct gpfs_config_data *config;
872 struct gpfs_opaque_acl *acl = NULL;
873 DATA_BLOB aclblob;
874 int result;
876 SMB_VFS_HANDLE_GET_DATA(handle, config,
877 struct gpfs_config_data,
878 return -1);
880 if (!config->acl) {
881 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
882 blob_description, blob);
885 errno = 0;
886 acl = (struct gpfs_opaque_acl *) vfs_gpfs_getacl(mem_ctx,
887 fsp->fsp_name->base_name,
888 true,
889 GPFS_ACL_TYPE_NFS4);
891 if (errno) {
892 DEBUG(5, ("vfs_gpfs_getacl finished with errno %d: %s\n",
893 errno, strerror(errno)));
895 /* EINVAL means POSIX ACL, bail out on other cases */
896 if (errno != EINVAL) {
897 return -1;
901 if (acl != NULL) {
903 * file has NFSv4 ACL
905 * we only need the actual ACL blob here
906 * acl_version will always be NFS4 because we asked
907 * for NFS4
908 * acl_type is only used for POSIX ACLs
910 aclblob.data = (uint8_t*) acl->acl_var_data;
911 aclblob.length = acl->acl_buffer_len;
913 *blob_description = talloc_strdup(mem_ctx, "gpfs_nfs4_acl");
914 if (!*blob_description) {
915 talloc_free(acl);
916 errno = ENOMEM;
917 return -1;
920 result = non_posix_sys_acl_blob_get_fd_helper(handle, fsp,
921 aclblob, mem_ctx,
922 blob);
924 talloc_free(acl);
925 return result;
928 /* fall back to POSIX ACL */
929 return posix_sys_acl_blob_get_fd(handle, fsp, mem_ctx,
930 blob_description, blob);
933 static struct gpfs_acl *smb2gpfs_acl(const SMB_ACL_T pacl,
934 SMB_ACL_TYPE_T type)
936 gpfs_aclLen_t len;
937 struct gpfs_acl *result;
938 int i;
940 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl->count));
942 len = offsetof(gpfs_acl_t, ace_v1) + (pacl->count) *
943 sizeof(gpfs_ace_v1_t);
945 result = (struct gpfs_acl *)SMB_MALLOC(len);
946 if (result == NULL) {
947 errno = ENOMEM;
948 return result;
951 result->acl_len = len;
952 result->acl_level = 0;
953 result->acl_version = GPFS_ACL_VERSION_POSIX;
954 result->acl_type = (type == SMB_ACL_TYPE_DEFAULT) ?
955 GPFS_ACL_TYPE_DEFAULT : GPFS_ACL_TYPE_ACCESS;
956 result->acl_nace = pacl->count;
958 for (i=0; i<pacl->count; i++) {
959 const struct smb_acl_entry *ace = &pacl->acl[i];
960 struct gpfs_ace_v1 *g_ace = &result->ace_v1[i];
962 DEBUG(10, ("Converting type %d perm %x\n",
963 (int)ace->a_type, (int)ace->a_perm));
965 g_ace->ace_perm = 0;
967 switch(ace->a_type) {
968 case SMB_ACL_USER:
969 g_ace->ace_type = GPFS_ACL_USER;
970 g_ace->ace_who = (gpfs_uid_t)ace->info.user.uid;
971 break;
972 case SMB_ACL_USER_OBJ:
973 g_ace->ace_type = GPFS_ACL_USER_OBJ;
974 g_ace->ace_perm |= ACL_PERM_CONTROL;
975 g_ace->ace_who = 0;
976 break;
977 case SMB_ACL_GROUP:
978 g_ace->ace_type = GPFS_ACL_GROUP;
979 g_ace->ace_who = (gpfs_uid_t)ace->info.group.gid;
980 break;
981 case SMB_ACL_GROUP_OBJ:
982 g_ace->ace_type = GPFS_ACL_GROUP_OBJ;
983 g_ace->ace_who = 0;
984 break;
985 case SMB_ACL_MASK:
986 g_ace->ace_type = GPFS_ACL_MASK;
987 g_ace->ace_perm = 0x8f;
988 g_ace->ace_who = 0;
989 break;
990 case SMB_ACL_OTHER:
991 g_ace->ace_type = GPFS_ACL_OTHER;
992 g_ace->ace_who = 0;
993 break;
994 default:
995 DEBUG(10, ("Got invalid ace_type: %d\n", ace->a_type));
996 errno = EINVAL;
997 SAFE_FREE(result);
998 return NULL;
1001 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_READ) ?
1002 ACL_PERM_READ : 0;
1003 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_WRITE) ?
1004 ACL_PERM_WRITE : 0;
1005 g_ace->ace_perm |= (ace->a_perm & SMB_ACL_EXECUTE) ?
1006 ACL_PERM_EXECUTE : 0;
1008 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
1009 g_ace->ace_type, g_ace->ace_who, g_ace->ace_perm));
1012 return result;
1015 static int gpfsacl_sys_acl_set_file(vfs_handle_struct *handle,
1016 const char *name,
1017 SMB_ACL_TYPE_T type,
1018 SMB_ACL_T theacl)
1020 struct gpfs_acl *gpfs_acl;
1021 int result;
1022 struct gpfs_config_data *config;
1024 SMB_VFS_HANDLE_GET_DATA(handle, config,
1025 struct gpfs_config_data,
1026 return -1);
1028 if (!config->acl) {
1029 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, type, theacl);
1032 gpfs_acl = smb2gpfs_acl(theacl, type);
1033 if (gpfs_acl == NULL) {
1034 return -1;
1037 result = smbd_gpfs_putacl((char *)name, GPFS_PUTACL_STRUCT | GPFS_ACL_SAMBA, gpfs_acl);
1039 SAFE_FREE(gpfs_acl);
1040 return result;
1043 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct *handle,
1044 files_struct *fsp,
1045 SMB_ACL_T theacl)
1047 struct gpfs_config_data *config;
1049 SMB_VFS_HANDLE_GET_DATA(handle, config,
1050 struct gpfs_config_data,
1051 return -1);
1053 if (!config->acl) {
1054 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
1057 return gpfsacl_sys_acl_set_file(handle, fsp->fsp_name->base_name,
1058 SMB_ACL_TYPE_ACCESS, theacl);
1061 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
1062 const char *path)
1064 struct gpfs_config_data *config;
1066 SMB_VFS_HANDLE_GET_DATA(handle, config,
1067 struct gpfs_config_data,
1068 return -1);
1070 if (!config->acl) {
1071 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
1074 errno = ENOTSUP;
1075 return -1;
1079 * Assumed: mode bits are shiftable and standard
1080 * Output: the new aceMask field for an smb nfs4 ace
1082 static uint32 gpfsacl_mask_filter(uint32 aceType, uint32 aceMask, uint32 rwx)
1084 const uint32 posix_nfs4map[3] = {
1085 SMB_ACE4_EXECUTE, /* execute */
1086 SMB_ACE4_WRITE_DATA | SMB_ACE4_APPEND_DATA, /* write; GPFS specific */
1087 SMB_ACE4_READ_DATA /* read */
1089 int i;
1090 uint32_t posix_mask = 0x01;
1091 uint32_t posix_bit;
1092 uint32_t nfs4_bits;
1094 for(i=0; i<3; i++) {
1095 nfs4_bits = posix_nfs4map[i];
1096 posix_bit = rwx & posix_mask;
1098 if (aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE) {
1099 if (posix_bit)
1100 aceMask |= nfs4_bits;
1101 else
1102 aceMask &= ~nfs4_bits;
1103 } else {
1104 /* add deny bits when suitable */
1105 if (!posix_bit)
1106 aceMask |= nfs4_bits;
1107 else
1108 aceMask &= ~nfs4_bits;
1109 } /* other ace types are unexpected */
1111 posix_mask <<= 1;
1114 return aceMask;
1117 static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
1118 const char *path, mode_t mode)
1120 SMB4ACL_T *pacl = NULL;
1121 int result;
1122 bool haveAllowEntry[SMB_ACE4_WHO_EVERYONE + 1] = {False, False, False, False};
1123 int i;
1124 files_struct fake_fsp; /* TODO: rationalize parametrization */
1125 SMB4ACE_T *smbace;
1126 TALLOC_CTX *frame = talloc_stackframe();
1127 NTSTATUS status;
1129 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path, mode));
1131 result = gpfs_get_nfs4_acl(frame, path, &pacl);
1132 if (result) {
1133 TALLOC_FREE(frame);
1134 return result;
1137 if (mode & ~(S_IRWXU | S_IRWXG | S_IRWXO)) {
1138 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode, path));
1141 for (smbace=smb_first_ace4(pacl); smbace!=NULL; smbace = smb_next_ace4(smbace)) {
1142 SMB_ACE4PROP_T *ace = smb_get_ace4(smbace);
1143 uint32_t specid = ace->who.special_id;
1145 if (ace->flags&SMB_ACE4_ID_SPECIAL &&
1146 ace->aceType<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE &&
1147 specid <= SMB_ACE4_WHO_EVERYONE) {
1149 uint32_t newMask;
1151 if (ace->aceType==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE)
1152 haveAllowEntry[specid] = True;
1154 /* mode >> 6 for @owner, mode >> 3 for @group,
1155 * mode >> 0 for @everyone */
1156 newMask = gpfsacl_mask_filter(ace->aceType, ace->aceMask,
1157 mode >> ((SMB_ACE4_WHO_EVERYONE - specid) * 3));
1158 if (ace->aceMask!=newMask) {
1159 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
1160 path, ace->aceMask, newMask, specid));
1162 ace->aceMask = newMask;
1166 /* make sure we have at least ALLOW entries
1167 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
1168 * - if necessary
1170 for(i = SMB_ACE4_WHO_OWNER; i<=SMB_ACE4_WHO_EVERYONE; i++) {
1171 SMB_ACE4PROP_T ace;
1173 if (haveAllowEntry[i]==True)
1174 continue;
1176 ZERO_STRUCT(ace);
1177 ace.aceType = SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE;
1178 ace.flags |= SMB_ACE4_ID_SPECIAL;
1179 ace.who.special_id = i;
1181 if (i==SMB_ACE4_WHO_GROUP) /* not sure it's necessary... */
1182 ace.aceFlags |= SMB_ACE4_IDENTIFIER_GROUP;
1184 ace.aceMask = gpfsacl_mask_filter(ace.aceType, ace.aceMask,
1185 mode >> ((SMB_ACE4_WHO_EVERYONE - i) * 3));
1187 /* don't add unnecessary aces */
1188 if (!ace.aceMask)
1189 continue;
1191 /* we add it to the END - as windows expects allow aces */
1192 smb_add_ace4(pacl, &ace);
1193 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
1194 path, mode, i, ace.aceMask));
1197 /* don't add complementary DENY ACEs here */
1198 ZERO_STRUCT(fake_fsp);
1199 fake_fsp.fsp_name = synthetic_smb_fname(
1200 frame, path, NULL, NULL);
1201 if (fake_fsp.fsp_name == NULL) {
1202 errno = ENOMEM;
1203 TALLOC_FREE(frame);
1204 return -1;
1206 /* put the acl */
1207 if (gpfsacl_process_smbacl(handle, &fake_fsp, pacl) == False) {
1208 TALLOC_FREE(frame);
1209 return -1;
1212 TALLOC_FREE(frame);
1213 return 0; /* ok for [f]chmod */
1216 static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
1218 struct smb_filename *smb_fname_cpath;
1219 int rc;
1221 smb_fname_cpath = synthetic_smb_fname(talloc_tos(), path, NULL, NULL);
1222 if (smb_fname_cpath == NULL) {
1223 errno = ENOMEM;
1224 return -1;
1227 if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
1228 return -1;
1231 /* avoid chmod() if possible, to preserve acls */
1232 if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
1233 return 0;
1236 rc = gpfsacl_emu_chmod(handle, path, mode);
1237 if (rc == 1)
1238 return SMB_VFS_NEXT_CHMOD(handle, path, mode);
1239 return rc;
1242 static int vfs_gpfs_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
1244 SMB_STRUCT_STAT st;
1245 int rc;
1247 if (SMB_VFS_NEXT_FSTAT(handle, fsp, &st) != 0) {
1248 return -1;
1251 /* avoid chmod() if possible, to preserve acls */
1252 if ((st.st_ex_mode & ~S_IFMT) == mode) {
1253 return 0;
1256 rc = gpfsacl_emu_chmod(handle, fsp->fsp_name->base_name,
1257 mode);
1258 if (rc == 1)
1259 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
1260 return rc;
1263 static int gpfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
1264 const char *name, const void *value, size_t size, int flags){
1265 struct xattr_DOSATTRIB dosattrib;
1266 enum ndr_err_code ndr_err;
1267 DATA_BLOB blob;
1268 const char *attrstr = value;
1269 unsigned int dosmode=0;
1270 struct gpfs_winattr attrs;
1271 int ret = 0;
1272 struct gpfs_config_data *config;
1274 SMB_VFS_HANDLE_GET_DATA(handle, config,
1275 struct gpfs_config_data,
1276 return -1);
1278 if (!config->winattr) {
1279 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name));
1280 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1283 DEBUG(10, ("gpfs_set_xattr: %s \n",path));
1285 /* Only handle DOS Attributes */
1286 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1287 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name));
1288 return SMB_VFS_NEXT_SETXATTR(handle,path,name,value,size,flags);
1291 blob.data = (uint8_t *)attrstr;
1292 blob.length = size;
1294 ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
1295 (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
1297 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
1298 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1299 "from EA on file %s: Error = %s\n",
1300 path, ndr_errstr(ndr_err)));
1301 return false;
1304 if (dosattrib.version != 3) {
1305 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1306 "%d\n", (int)dosattrib.version));
1307 return false;
1309 if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
1310 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1311 "valid, ignoring\n"));
1312 return true;
1315 dosmode = dosattrib.info.info3.attrib;
1317 attrs.winAttrs = 0;
1318 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1319 if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
1320 attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
1322 if (dosmode & FILE_ATTRIBUTE_HIDDEN){
1323 attrs.winAttrs |= GPFS_WINATTR_HIDDEN;
1325 if (dosmode & FILE_ATTRIBUTE_SYSTEM){
1326 attrs.winAttrs |= GPFS_WINATTR_SYSTEM;
1328 if (dosmode & FILE_ATTRIBUTE_READONLY){
1329 attrs.winAttrs |= GPFS_WINATTR_READONLY;
1331 if (dosmode & FILE_ATTRIBUTE_SPARSE) {
1332 attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
1336 ret = set_gpfs_winattrs(discard_const_p(char, path),
1337 GPFS_WINATTR_SET_ATTRS, &attrs);
1338 if ( ret == -1){
1339 if (errno == ENOSYS) {
1340 return SMB_VFS_NEXT_SETXATTR(handle, path, name, value,
1341 size, flags);
1344 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret));
1345 return -1;
1348 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs.winAttrs));
1349 return 0;
1352 static ssize_t gpfs_get_xattr(struct vfs_handle_struct *handle, const char *path,
1353 const char *name, void *value, size_t size){
1354 char *attrstr = value;
1355 unsigned int dosmode = 0;
1356 struct gpfs_winattr attrs;
1357 int ret = 0;
1358 struct gpfs_config_data *config;
1360 SMB_VFS_HANDLE_GET_DATA(handle, config,
1361 struct gpfs_config_data,
1362 return -1);
1364 if (!config->winattr) {
1365 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name));
1366 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1369 DEBUG(10, ("gpfs_get_xattr: %s \n",path));
1371 /* Only handle DOS Attributes */
1372 if (strcmp(name,SAMBA_XATTR_DOS_ATTRIB) != 0){
1373 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name));
1374 return SMB_VFS_NEXT_GETXATTR(handle,path,name,value,size);
1377 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1378 if ( ret == -1){
1379 if (errno == ENOSYS) {
1380 return SMB_VFS_NEXT_GETXATTR(handle, path, name, value,
1381 size);
1384 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1385 "%d (%s)\n", ret, strerror(errno)));
1386 return -1;
1389 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
1391 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1392 if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
1393 dosmode |= FILE_ATTRIBUTE_ARCHIVE;
1395 if (attrs.winAttrs & GPFS_WINATTR_HIDDEN){
1396 dosmode |= FILE_ATTRIBUTE_HIDDEN;
1398 if (attrs.winAttrs & GPFS_WINATTR_SYSTEM){
1399 dosmode |= FILE_ATTRIBUTE_SYSTEM;
1401 if (attrs.winAttrs & GPFS_WINATTR_READONLY){
1402 dosmode |= FILE_ATTRIBUTE_READONLY;
1404 if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
1405 dosmode |= FILE_ATTRIBUTE_SPARSE;
1408 snprintf(attrstr, size, "0x%2.2x",
1409 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
1410 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
1411 return 4;
1414 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
1415 struct smb_filename *smb_fname)
1417 struct gpfs_winattr attrs;
1418 char *fname = NULL;
1419 NTSTATUS status;
1420 int ret;
1421 struct gpfs_config_data *config;
1423 SMB_VFS_HANDLE_GET_DATA(handle, config,
1424 struct gpfs_config_data,
1425 return -1);
1427 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1428 if (ret == -1) {
1429 return -1;
1432 if (!config->winattr) {
1433 return 0;
1436 status = get_full_smb_filename(talloc_tos(), smb_fname, &fname);
1437 if (!NT_STATUS_IS_OK(status)) {
1438 errno = map_errno_from_nt_status(status);
1439 return -1;
1441 ret = get_gpfs_winattrs(discard_const_p(char, fname), &attrs);
1442 TALLOC_FREE(fname);
1443 if (ret == 0) {
1444 smb_fname->st.st_ex_calculated_birthtime = false;
1445 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1446 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1448 return 0;
1451 static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
1452 struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1454 struct gpfs_winattr attrs;
1455 int ret;
1456 struct gpfs_config_data *config;
1458 SMB_VFS_HANDLE_GET_DATA(handle, config,
1459 struct gpfs_config_data,
1460 return -1);
1462 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1463 if (ret == -1) {
1464 return -1;
1466 if ((fsp->fh == NULL) || (fsp->fh->fd == -1)) {
1467 return 0;
1469 if (!config->winattr) {
1470 return 0;
1473 ret = smbd_fget_gpfs_winattrs(fsp->fh->fd, &attrs);
1474 if (ret == 0) {
1475 sbuf->st_ex_calculated_birthtime = false;
1476 sbuf->st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1477 sbuf->st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1479 return 0;
1482 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
1483 struct smb_filename *smb_fname)
1485 struct gpfs_winattr attrs;
1486 char *path = NULL;
1487 NTSTATUS status;
1488 int ret;
1489 struct gpfs_config_data *config;
1491 SMB_VFS_HANDLE_GET_DATA(handle, config,
1492 struct gpfs_config_data,
1493 return -1);
1495 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1496 if (ret == -1) {
1497 return -1;
1499 if (!config->winattr) {
1500 return 0;
1503 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1504 if (!NT_STATUS_IS_OK(status)) {
1505 errno = map_errno_from_nt_status(status);
1506 return -1;
1508 ret = get_gpfs_winattrs(discard_const_p(char, path), &attrs);
1509 TALLOC_FREE(path);
1510 if (ret == 0) {
1511 smb_fname->st.st_ex_calculated_birthtime = false;
1512 smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
1513 smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
1515 return 0;
1518 static int vfs_gpfs_ntimes(struct vfs_handle_struct *handle,
1519 const struct smb_filename *smb_fname,
1520 struct smb_file_time *ft)
1523 struct gpfs_winattr attrs;
1524 int ret;
1525 char *path = NULL;
1526 NTSTATUS status;
1527 struct gpfs_config_data *config;
1529 SMB_VFS_HANDLE_GET_DATA(handle, config,
1530 struct gpfs_config_data,
1531 return -1);
1533 ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1534 if(ret == -1){
1535 /* don't complain if access was denied */
1536 if (errno != EPERM && errno != EACCES) {
1537 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1538 "%s", strerror(errno)));
1540 return -1;
1543 if(null_timespec(ft->create_time)){
1544 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1545 return 0;
1548 if (!config->winattr) {
1549 return 0;
1552 status = get_full_smb_filename(talloc_tos(), smb_fname, &path);
1553 if (!NT_STATUS_IS_OK(status)) {
1554 errno = map_errno_from_nt_status(status);
1555 return -1;
1558 attrs.winAttrs = 0;
1559 attrs.creationTime.tv_sec = ft->create_time.tv_sec;
1560 attrs.creationTime.tv_nsec = ft->create_time.tv_nsec;
1562 ret = set_gpfs_winattrs(discard_const_p(char, path),
1563 GPFS_WINATTR_SET_CREATION_TIME, &attrs);
1564 if(ret == -1 && errno != ENOSYS){
1565 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret));
1566 return -1;
1568 return 0;
1572 static int vfs_gpfs_fallocate(struct vfs_handle_struct *handle,
1573 struct files_struct *fsp, enum vfs_fallocate_mode mode,
1574 off_t offset, off_t len)
1576 int ret;
1577 struct gpfs_config_data *config;
1579 SMB_VFS_HANDLE_GET_DATA(handle, config,
1580 struct gpfs_config_data,
1581 return -1);
1583 if (!config->prealloc) {
1584 /* you should better not run fallocate() on GPFS at all */
1585 errno = ENOTSUP;
1586 return -1;
1589 if (mode == VFS_FALLOCATE_KEEP_SIZE) {
1590 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1591 errno = ENOTSUP;
1592 return -1;
1595 ret = smbd_gpfs_prealloc(fsp->fh->fd, offset, len);
1597 if (ret == -1 && errno != ENOSYS) {
1598 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno)));
1599 } else if (ret == -1 && errno == ENOSYS) {
1600 DEBUG(10, ("GPFS prealloc not supported.\n"));
1601 } else {
1602 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1605 return ret;
1608 static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
1609 off_t len)
1611 int result;
1612 struct gpfs_config_data *config;
1614 SMB_VFS_HANDLE_GET_DATA(handle, config,
1615 struct gpfs_config_data,
1616 return -1);
1618 if (!config->ftruncate) {
1619 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1622 result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
1623 if ((result == -1) && (errno == ENOSYS)) {
1624 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
1626 return result;
1629 static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
1630 const struct smb_filename *fname,
1631 SMB_STRUCT_STAT *sbuf)
1633 struct gpfs_winattr attrs;
1634 char *path = NULL;
1635 NTSTATUS status;
1636 struct gpfs_config_data *config;
1637 int ret;
1639 SMB_VFS_HANDLE_GET_DATA(handle, config,
1640 struct gpfs_config_data,
1641 return -1);
1643 if (!config->winattr) {
1644 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1647 status = get_full_smb_filename(talloc_tos(), fname, &path);
1648 if (!NT_STATUS_IS_OK(status)) {
1649 errno = map_errno_from_nt_status(status);
1650 return -1;
1653 ret = get_gpfs_winattrs(path, &attrs);
1654 if (ret == -1) {
1655 TALLOC_FREE(path);
1656 return false;
1659 if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
1660 DEBUG(10, ("%s is offline\n", path));
1661 TALLOC_FREE(path);
1662 return true;
1664 DEBUG(10, ("%s is online\n", path));
1665 TALLOC_FREE(path);
1666 return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
1669 static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
1670 struct files_struct *fsp)
1672 return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
1675 static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
1676 files_struct *fsp, const DATA_BLOB *hdr,
1677 off_t offset, size_t n)
1679 if (SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name, &fsp->fsp_name->st))
1681 errno = ENOSYS;
1682 return -1;
1684 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
1687 static int vfs_gpfs_connect(struct vfs_handle_struct *handle,
1688 const char *service, const char *user)
1690 struct gpfs_config_data *config;
1691 int ret;
1693 smbd_gpfs_lib_init();
1695 config = talloc_zero(handle->conn, struct gpfs_config_data);
1696 if (!config) {
1697 DEBUG(0, ("talloc_zero() failed\n"));
1698 errno = ENOMEM;
1699 return -1;
1702 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1703 if (ret < 0) {
1704 TALLOC_FREE(config);
1705 return ret;
1708 config->sharemodes = lp_parm_bool(SNUM(handle->conn), "gpfs",
1709 "sharemodes", true);
1711 config->leases = lp_parm_bool(SNUM(handle->conn), "gpfs",
1712 "leases", true);
1714 config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
1715 "hsm", false);
1717 config->syncio = lp_parm_bool(SNUM(handle->conn), "gpfs",
1718 "syncio", false);
1720 config->winattr = lp_parm_bool(SNUM(handle->conn), "gpfs",
1721 "winattr", false);
1723 config->ftruncate = lp_parm_bool(SNUM(handle->conn), "gpfs",
1724 "ftruncate", true);
1726 config->getrealfilename = lp_parm_bool(SNUM(handle->conn), "gpfs",
1727 "getrealfilename", true);
1729 config->dfreequota = lp_parm_bool(SNUM(handle->conn), "gpfs",
1730 "dfreequota", false);
1732 config->prealloc = lp_parm_bool(SNUM(handle->conn), "gpfs",
1733 "prealloc", true);
1735 config->acl = lp_parm_bool(SNUM(handle->conn), "gpfs", "acl", true);
1737 SMB_VFS_HANDLE_SET_DATA(handle, config,
1738 NULL, struct gpfs_config_data,
1739 return -1);
1741 if (config->leases) {
1743 * GPFS lease code is based on kernel oplock code
1744 * so make sure it is turned on
1746 if (!lp_kernel_oplocks(SNUM(handle->conn))) {
1747 DEBUG(5, ("Enabling kernel oplocks for "
1748 "gpfs:leases to work\n"));
1749 lp_do_parameter(SNUM(handle->conn), "kernel oplocks",
1750 "true");
1754 * as the kernel does not properly support Level II oplocks
1755 * and GPFS leases code is based on kernel infrastructure, we
1756 * need to turn off Level II oplocks if gpfs:leases is enabled
1758 if (lp_level2_oplocks(SNUM(handle->conn))) {
1759 DEBUG(5, ("gpfs:leases are enabled, disabling "
1760 "Level II oplocks\n"));
1761 lp_do_parameter(SNUM(handle->conn), "level2 oplocks",
1762 "false");
1766 return 0;
1769 static int vfs_gpfs_get_quotas(const char *path, uid_t uid, gid_t gid,
1770 int *fset_id,
1771 struct gpfs_quotaInfo *qi_user,
1772 struct gpfs_quotaInfo *qi_group,
1773 struct gpfs_quotaInfo *qi_fset)
1775 int err;
1776 char *dir_path;
1777 bool b;
1780 * We want to always use the directory to get the fileset id,
1781 * because files might have a share mode. We also do not want
1782 * to get the parent directory when there is already a
1783 * directory to avoid stepping in a different fileset. The
1784 * path passed here is currently either "." or a filename, so
1785 * this is ok. The proper solution would be having a way to
1786 * query the fileset id without opening the file.
1788 b = parent_dirname(talloc_tos(), path, &dir_path, NULL);
1789 if (!b) {
1790 errno = ENOMEM;
1791 return -1;
1794 DEBUG(10, ("path %s, directory %s\n", path, dir_path));
1796 err = get_gpfs_fset_id(dir_path, fset_id);
1797 if (err) {
1798 DEBUG(0, ("Get fset id failed path %s, dir %s, errno %d.\n",
1799 path, dir_path, errno));
1800 return err;
1803 err = get_gpfs_quota(path, GPFS_USRQUOTA, uid, qi_user);
1804 if (err) {
1805 return err;
1808 err = get_gpfs_quota(path, GPFS_GRPQUOTA, gid, qi_group);
1809 if (err) {
1810 return err;
1813 err = get_gpfs_quota(path, GPFS_FILESETQUOTA, *fset_id, qi_fset);
1814 if (err) {
1815 return err;
1818 return 0;
1821 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi, time_t cur_time,
1822 uint64_t *dfree, uint64_t *dsize)
1824 uint64_t usage, limit;
1827 * The quota reporting is done in units of 1024 byte blocks, but
1828 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1829 * accordingly. Also filter possibly negative usage counts from gpfs.
1831 usage = qi.blockUsage < 0 ? 0 : (uint64_t)qi.blockUsage * 2;
1832 limit = (uint64_t)qi.blockHardLimit * 2;
1835 * When the grace time for the exceeded soft block quota has been
1836 * exceeded, the soft block quota becomes an additional hard limit.
1838 if (qi.blockSoftLimit &&
1839 qi.blockGraceTime && cur_time > qi.blockGraceTime) {
1840 /* report disk as full */
1841 *dfree = 0;
1842 *dsize = MIN(*dsize, usage);
1845 if (!qi.blockHardLimit)
1846 return;
1848 if (usage >= limit) {
1849 /* report disk as full */
1850 *dfree = 0;
1851 *dsize = MIN(*dsize, usage);
1853 } else {
1854 /* limit has not been reached, determine "free space" */
1855 *dfree = MIN(*dfree, limit - usage);
1856 *dsize = MIN(*dsize, limit);
1860 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle, const char *path,
1861 bool small_query, uint64_t *bsize,
1862 uint64_t *dfree, uint64_t *dsize)
1864 struct security_unix_token *utok;
1865 struct gpfs_quotaInfo qi_user, qi_group, qi_fset;
1866 struct gpfs_config_data *config;
1867 int err, fset_id;
1868 time_t cur_time;
1870 SMB_VFS_HANDLE_GET_DATA(handle, config, struct gpfs_config_data,
1871 return (uint64_t)-1);
1872 if (!config->dfreequota) {
1873 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1874 bsize, dfree, dsize);
1877 err = sys_fsusage(path, dfree, dsize);
1878 if (err) {
1879 DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
1880 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1881 bsize, dfree, dsize);
1884 /* sys_fsusage returns units of 512 bytes */
1885 *bsize = 512;
1887 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1888 (unsigned long long)*dfree, (unsigned long long)*dsize));
1890 utok = handle->conn->session_info->unix_token;
1891 err = vfs_gpfs_get_quotas(path, utok->uid, utok->gid, &fset_id,
1892 &qi_user, &qi_group, &qi_fset);
1893 if (err) {
1894 return SMB_VFS_NEXT_DISK_FREE(handle, path, small_query,
1895 bsize, dfree, dsize);
1898 cur_time = time(NULL);
1900 /* Adjust free space and size according to quota limits. */
1901 vfs_gpfs_disk_free_quota(qi_user, cur_time, dfree, dsize);
1902 vfs_gpfs_disk_free_quota(qi_group, cur_time, dfree, dsize);
1904 /* Id 0 indicates the default quota, not an actual quota */
1905 if (fset_id != 0) {
1906 vfs_gpfs_disk_free_quota(qi_fset, cur_time, dfree, dsize);
1909 disk_norm(small_query, bsize, dfree, dsize);
1910 return *dfree;
1913 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
1914 enum timestamp_set_resolution *p_ts_res)
1916 struct gpfs_config_data *config;
1917 uint32_t next;
1919 next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
1921 SMB_VFS_HANDLE_GET_DATA(handle, config,
1922 struct gpfs_config_data,
1923 return next);
1925 if (config->hsm) {
1926 next |= FILE_SUPPORTS_REMOTE_STORAGE;
1928 return next;
1931 static int vfs_gpfs_open(struct vfs_handle_struct *handle,
1932 struct smb_filename *smb_fname, files_struct *fsp,
1933 int flags, mode_t mode)
1935 struct gpfs_config_data *config;
1937 SMB_VFS_HANDLE_GET_DATA(handle, config,
1938 struct gpfs_config_data,
1939 return -1);
1941 if (config->syncio) {
1942 flags |= O_SYNC;
1944 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1947 static ssize_t vfs_gpfs_pread(vfs_handle_struct *handle, files_struct *fsp,
1948 void *data, size_t n, off_t offset)
1950 ssize_t ret;
1951 bool was_offline;
1953 was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
1954 &fsp->fsp_name->st);
1956 ret = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
1958 if ((ret != -1) && was_offline) {
1959 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
1960 FILE_NOTIFY_CHANGE_ATTRIBUTES,
1961 fsp->fsp_name->base_name);
1964 return ret;
1967 struct vfs_gpfs_pread_state {
1968 struct files_struct *fsp;
1969 ssize_t ret;
1970 int err;
1971 bool was_offline;
1974 static void vfs_gpfs_pread_done(struct tevent_req *subreq);
1976 static struct tevent_req *vfs_gpfs_pread_send(struct vfs_handle_struct *handle,
1977 TALLOC_CTX *mem_ctx,
1978 struct tevent_context *ev,
1979 struct files_struct *fsp,
1980 void *data, size_t n,
1981 off_t offset)
1983 struct tevent_req *req, *subreq;
1984 struct vfs_gpfs_pread_state *state;
1986 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pread_state);
1987 if (req == NULL) {
1988 return NULL;
1990 state->was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
1991 &fsp->fsp_name->st);
1992 state->fsp = fsp;
1993 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
1994 n, offset);
1995 if (tevent_req_nomem(subreq, req)) {
1996 return tevent_req_post(req, ev);
1998 tevent_req_set_callback(subreq, vfs_gpfs_pread_done, req);
1999 return req;
2002 static void vfs_gpfs_pread_done(struct tevent_req *subreq)
2004 struct tevent_req *req = tevent_req_callback_data(
2005 subreq, struct tevent_req);
2006 struct vfs_gpfs_pread_state *state = tevent_req_data(
2007 req, struct vfs_gpfs_pread_state);
2009 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->err);
2010 TALLOC_FREE(subreq);
2011 tevent_req_done(req);
2014 static ssize_t vfs_gpfs_pread_recv(struct tevent_req *req, int *err)
2016 struct vfs_gpfs_pread_state *state = tevent_req_data(
2017 req, struct vfs_gpfs_pread_state);
2018 struct files_struct *fsp = state->fsp;
2020 if (tevent_req_is_unix_error(req, err)) {
2021 return -1;
2023 *err = state->err;
2025 if ((state->ret != -1) && state->was_offline) {
2026 DEBUG(10, ("sending notify\n"));
2027 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2028 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2029 fsp->fsp_name->base_name);
2032 return state->ret;
2035 static ssize_t vfs_gpfs_pwrite(vfs_handle_struct *handle, files_struct *fsp,
2036 const void *data, size_t n, off_t offset)
2038 ssize_t ret;
2039 bool was_offline;
2041 was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2042 &fsp->fsp_name->st);
2044 ret = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2046 if ((ret != -1) && was_offline) {
2047 notify_fname(handle->conn, NOTIFY_ACTION_MODIFIED,
2048 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2049 fsp->fsp_name->base_name);
2052 return ret;
2055 struct vfs_gpfs_pwrite_state {
2056 struct files_struct *fsp;
2057 ssize_t ret;
2058 int err;
2059 bool was_offline;
2062 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq);
2064 static struct tevent_req *vfs_gpfs_pwrite_send(
2065 struct vfs_handle_struct *handle,
2066 TALLOC_CTX *mem_ctx,
2067 struct tevent_context *ev,
2068 struct files_struct *fsp,
2069 const void *data, size_t n,
2070 off_t offset)
2072 struct tevent_req *req, *subreq;
2073 struct vfs_gpfs_pwrite_state *state;
2075 req = tevent_req_create(mem_ctx, &state, struct vfs_gpfs_pwrite_state);
2076 if (req == NULL) {
2077 return NULL;
2079 state->was_offline = SMB_VFS_IS_OFFLINE(handle->conn, fsp->fsp_name,
2080 &fsp->fsp_name->st);
2081 state->fsp = fsp;
2082 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
2083 n, offset);
2084 if (tevent_req_nomem(subreq, req)) {
2085 return tevent_req_post(req, ev);
2087 tevent_req_set_callback(subreq, vfs_gpfs_pwrite_done, req);
2088 return req;
2091 static void vfs_gpfs_pwrite_done(struct tevent_req *subreq)
2093 struct tevent_req *req = tevent_req_callback_data(
2094 subreq, struct tevent_req);
2095 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2096 req, struct vfs_gpfs_pwrite_state);
2098 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->err);
2099 TALLOC_FREE(subreq);
2100 tevent_req_done(req);
2103 static ssize_t vfs_gpfs_pwrite_recv(struct tevent_req *req, int *err)
2105 struct vfs_gpfs_pwrite_state *state = tevent_req_data(
2106 req, struct vfs_gpfs_pwrite_state);
2107 struct files_struct *fsp = state->fsp;
2109 if (tevent_req_is_unix_error(req, err)) {
2110 return -1;
2112 *err = state->err;
2114 if ((state->ret != -1) && state->was_offline) {
2115 DEBUG(10, ("sending notify\n"));
2116 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
2117 FILE_NOTIFY_CHANGE_ATTRIBUTES,
2118 fsp->fsp_name->base_name);
2121 return state->ret;
2125 static struct vfs_fn_pointers vfs_gpfs_fns = {
2126 .connect_fn = vfs_gpfs_connect,
2127 .disk_free_fn = vfs_gpfs_disk_free,
2128 .fs_capabilities_fn = vfs_gpfs_capabilities,
2129 .kernel_flock_fn = vfs_gpfs_kernel_flock,
2130 .linux_setlease_fn = vfs_gpfs_setlease,
2131 .get_real_filename_fn = vfs_gpfs_get_real_filename,
2132 .fget_nt_acl_fn = gpfsacl_fget_nt_acl,
2133 .get_nt_acl_fn = gpfsacl_get_nt_acl,
2134 .fset_nt_acl_fn = gpfsacl_fset_nt_acl,
2135 .sys_acl_get_file_fn = gpfsacl_sys_acl_get_file,
2136 .sys_acl_get_fd_fn = gpfsacl_sys_acl_get_fd,
2137 .sys_acl_blob_get_file_fn = gpfsacl_sys_acl_blob_get_file,
2138 .sys_acl_blob_get_fd_fn = gpfsacl_sys_acl_blob_get_fd,
2139 .sys_acl_set_file_fn = gpfsacl_sys_acl_set_file,
2140 .sys_acl_set_fd_fn = gpfsacl_sys_acl_set_fd,
2141 .sys_acl_delete_def_file_fn = gpfsacl_sys_acl_delete_def_file,
2142 .chmod_fn = vfs_gpfs_chmod,
2143 .fchmod_fn = vfs_gpfs_fchmod,
2144 .close_fn = vfs_gpfs_close,
2145 .setxattr_fn = gpfs_set_xattr,
2146 .getxattr_fn = gpfs_get_xattr,
2147 .stat_fn = vfs_gpfs_stat,
2148 .fstat_fn = vfs_gpfs_fstat,
2149 .lstat_fn = vfs_gpfs_lstat,
2150 .ntimes_fn = vfs_gpfs_ntimes,
2151 .is_offline_fn = vfs_gpfs_is_offline,
2152 .aio_force_fn = vfs_gpfs_aio_force,
2153 .sendfile_fn = vfs_gpfs_sendfile,
2154 .fallocate_fn = vfs_gpfs_fallocate,
2155 .open_fn = vfs_gpfs_open,
2156 .pread_fn = vfs_gpfs_pread,
2157 .pread_send_fn = vfs_gpfs_pread_send,
2158 .pread_recv_fn = vfs_gpfs_pread_recv,
2159 .pwrite_fn = vfs_gpfs_pwrite,
2160 .pwrite_send_fn = vfs_gpfs_pwrite_send,
2161 .pwrite_recv_fn = vfs_gpfs_pwrite_recv,
2162 .ftruncate_fn = vfs_gpfs_ftruncate
2165 NTSTATUS vfs_gpfs_init(void);
2166 NTSTATUS vfs_gpfs_init(void)
2168 init_gpfs();
2170 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
2171 &vfs_gpfs_fns);