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"
30 #define DBGC_CLASS DBGC_VFS
33 #include "nfs4_acls.h"
35 #include "system/filesys.h"
38 struct gpfs_config_data
{
52 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
53 uint32 share_mode
, uint32 access_mask
)
56 struct gpfs_config_data
*config
;
59 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
60 struct gpfs_config_data
,
63 START_PROFILE(syscall_kernel_flock
);
65 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
67 if (config
->sharemodes
68 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
72 END_PROFILE(syscall_kernel_flock
);
77 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
80 struct gpfs_config_data
*config
;
82 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
83 struct gpfs_config_data
,
86 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
87 set_gpfs_sharemode(fsp
, 0, 0);
90 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
93 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
96 struct gpfs_config_data
*config
;
99 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
100 struct gpfs_config_data
,
103 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
106 START_PROFILE(syscall_linux_setlease
);
108 if (config
->leases
) {
109 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
112 END_PROFILE(syscall_linux_setlease
);
117 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
125 char real_pathname
[PATH_MAX
+1];
128 struct gpfs_config_data
*config
;
130 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
131 struct gpfs_config_data
,
134 if (!config
->getrealfilename
) {
135 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
136 mem_ctx
, found_name
);
139 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
141 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
142 mem_ctx
, found_name
);
145 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
146 if (full_path
== NULL
) {
151 buflen
= sizeof(real_pathname
) - 1;
153 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
156 TALLOC_FREE(full_path
);
158 if ((result
== -1) && (errno
== ENOSYS
)) {
159 return SMB_VFS_NEXT_GET_REAL_FILENAME(
160 handle
, path
, name
, mem_ctx
, found_name
);
164 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
170 * GPFS does not necessarily null-terminate the returned path
171 * but instead returns the buffer length in buflen.
174 if (buflen
< sizeof(real_pathname
)) {
175 real_pathname
[buflen
] = '\0';
177 real_pathname
[sizeof(real_pathname
)-1] = '\0';
180 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
181 path
, name
, real_pathname
));
183 name
= strrchr_m(real_pathname
, '/');
189 *found_name
= talloc_strdup(mem_ctx
, name
+1);
190 if (*found_name
== NULL
) {
198 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
203 DEBUG(0, ("gpfs acl is NULL\n"));
207 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
208 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
209 for(i
=0; i
<gacl
->acl_nace
; i
++)
211 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
212 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
213 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
214 gace
->aceIFlags
, gace
->aceWho
));
218 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
220 struct gpfs_acl
*acl
;
223 TALLOC_CTX
*mem_ctx
= talloc_tos();
225 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
233 acl
->acl_version
= 0;
234 acl
->acl_type
= type
;
236 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
237 if ((ret
!= 0) && (errno
== ENOSPC
)) {
238 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
239 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
240 if (new_acl
== NULL
) {
245 new_acl
->acl_len
= acl
->acl_len
;
246 new_acl
->acl_level
= acl
->acl_level
;
247 new_acl
->acl_version
= acl
->acl_version
;
248 new_acl
->acl_type
= acl
->acl_type
;
251 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
255 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
262 /* Tries to get nfs4 acls and returns SMB ACL allocated.
263 * On failure returns 1 if it got non-NFSv4 ACL to prompt
264 * retry with POSIX ACL checks.
265 * On failure returns -1 if there is system (GPFS) error, check errno.
266 * Returns 0 on success
268 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
271 struct gpfs_acl
*gacl
= NULL
;
272 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
274 /* First get the real acl length */
275 gacl
= gpfs_getacl_alloc(fname
, 0);
277 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
278 fname
, strerror(errno
)));
282 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
283 DEBUG(10, ("Got non-nfsv4 acl\n"));
284 /* Retry with POSIX ACLs check */
288 *ppacl
= smb_create_smb4acl();
290 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
291 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
294 for (i
=0; i
<gacl
->acl_nace
; i
++) {
295 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
296 SMB_ACE4PROP_T smbace
;
297 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
298 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
299 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
302 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
303 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
304 switch (gace
->aceWho
) {
305 case ACE4_SPECIAL_OWNER
:
306 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
308 case ACE4_SPECIAL_GROUP
:
309 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
311 case ACE4_SPECIAL_EVERYONE
:
312 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
315 DEBUG(8, ("invalid special gpfs id %d "
316 "ignored\n", gace
->aceWho
));
317 continue; /* don't add it */
320 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
321 smbace
.who
.gid
= gace
->aceWho
;
323 smbace
.who
.uid
= gace
->aceWho
;
326 /* remove redundent deny entries */
327 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
328 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
329 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
330 prev
->aceFlags
== gace
->aceFlags
&&
331 prev
->aceIFlags
== gace
->aceIFlags
&&
332 (gace
->aceMask
& prev
->aceMask
) == 0 &&
333 gace
->aceWho
== prev
->aceWho
) {
334 /* its redundent - skip it */
339 smbace
.aceType
= gace
->aceType
;
340 smbace
.aceFlags
= gace
->aceFlags
;
341 smbace
.aceMask
= gace
->aceMask
;
342 smb_add_ace4(*ppacl
, &smbace
);
348 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
349 files_struct
*fsp
, uint32 security_info
,
350 struct security_descriptor
**ppdesc
)
352 SMB4ACL_T
*pacl
= NULL
;
354 struct gpfs_config_data
*config
;
358 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
359 struct gpfs_config_data
,
360 return NT_STATUS_INTERNAL_ERROR
);
363 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
, ppdesc
);
366 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
369 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
372 DEBUG(10, ("retrying with posix acl...\n"));
373 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
376 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
377 return map_nt_error_from_unix(errno
);
380 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
382 uint32 security_info
, struct security_descriptor
**ppdesc
)
384 SMB4ACL_T
*pacl
= NULL
;
386 struct gpfs_config_data
*config
;
390 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
391 struct gpfs_config_data
,
392 return NT_STATUS_INTERNAL_ERROR
);
395 return SMB_VFS_NEXT_GET_NT_ACL(handle
, name
, security_info
, ppdesc
);
398 result
= gpfs_get_nfs4_acl(name
, &pacl
);
401 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
, pacl
);
404 DEBUG(10, ("retrying with posix acl...\n"));
405 return posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
408 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
409 return map_nt_error_from_unix(errno
);
412 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
415 gpfs_aclLen_t gacl_len
;
417 struct gpfs_acl
*gacl
;
418 TALLOC_CTX
*mem_ctx
= talloc_tos();
420 gacl_len
= offsetof(gpfs_acl_t
, ace_v4
) + smb_get_naces(smbacl
) *
421 sizeof(gpfs_ace_v4_t
);
423 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
425 DEBUG(0, ("talloc failed\n"));
430 gacl
->acl_len
= gacl_len
;
432 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
433 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
434 gacl
->acl_nace
= 0; /* change later... */
436 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
437 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
438 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
440 gace
->aceType
= aceprop
->aceType
;
441 gace
->aceFlags
= aceprop
->aceFlags
;
442 gace
->aceMask
= aceprop
->aceMask
;
445 * GPFS can't distinguish between WRITE and APPEND on
446 * files, so one being set without the other is an
447 * error. Sorry for the many ()'s :-)
450 if (!fsp
->is_directory
452 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
453 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
455 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
456 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
458 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
459 "merge_writeappend", True
)) {
460 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
461 "WRITE^APPEND, setting WRITE|APPEND\n",
463 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
466 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
468 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
470 switch(aceprop
->who
.special_id
)
472 case SMB_ACE4_WHO_EVERYONE
:
473 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
475 case SMB_ACE4_WHO_OWNER
:
476 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
478 case SMB_ACE4_WHO_GROUP
:
479 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
482 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
483 continue; /* don't add it !!! */
486 /* just only for the type safety... */
487 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
488 gace
->aceWho
= aceprop
->who
.gid
;
490 gace
->aceWho
= aceprop
->who
.uid
;
496 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
497 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
499 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
500 gpfs_dumpacl(8, gacl
);
504 DEBUG(10, ("gpfs_putacl succeeded\n"));
508 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
510 struct gpfs_acl
*acl
;
511 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
513 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
517 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
519 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
520 "refuse_dacl_protected", false)
521 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
522 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
523 return NT_STATUS_NOT_SUPPORTED
;
526 result
= smb_set_nt_acl_nfs4(
527 fsp
, security_info_sent
, psd
,
528 gpfsacl_process_smbacl
);
529 } else { /* assume POSIX ACL - by default... */
530 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
536 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
538 struct gpfs_config_data
*config
;
540 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
541 struct gpfs_config_data
,
542 return NT_STATUS_INTERNAL_ERROR
);
545 return SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
548 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
551 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
556 result
= sys_acl_init(pacl
->acl_nace
);
557 if (result
== NULL
) {
562 result
->count
= pacl
->acl_nace
;
564 for (i
=0; i
<pacl
->acl_nace
; i
++) {
565 struct smb_acl_entry
*ace
= &result
->acl
[i
];
566 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
568 DEBUG(10, ("Converting type %d id %lu perm %x\n",
569 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
570 (int)g_ace
->ace_perm
));
572 switch (g_ace
->ace_type
) {
574 ace
->a_type
= SMB_ACL_USER
;
575 ace
->uid
= (uid_t
)g_ace
->ace_who
;
577 case GPFS_ACL_USER_OBJ
:
578 ace
->a_type
= SMB_ACL_USER_OBJ
;
581 ace
->a_type
= SMB_ACL_GROUP
;
582 ace
->gid
= (gid_t
)g_ace
->ace_who
;
584 case GPFS_ACL_GROUP_OBJ
:
585 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
588 ace
->a_type
= SMB_ACL_OTHER
;
591 ace
->a_type
= SMB_ACL_MASK
;
594 DEBUG(10, ("Got invalid ace_type: %d\n",
602 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
604 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
606 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
609 DEBUGADD(10, ("Converted to %d perm %x\n",
610 ace
->a_type
, ace
->a_perm
));
616 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
618 struct gpfs_acl
*pacl
;
619 SMB_ACL_T result
= NULL
;
621 pacl
= gpfs_getacl_alloc(path
, type
);
624 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
625 path
, strerror(errno
)));
632 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
633 DEBUG(10, ("Got acl version %d, expected %d\n",
634 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
639 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
640 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
643 result
= gpfs2smb_acl(pacl
);
644 if (result
!= NULL
) {
656 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
660 gpfs_aclType_t gpfs_type
;
661 struct gpfs_config_data
*config
;
663 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
664 struct gpfs_config_data
,
668 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, path_p
, type
);
672 case SMB_ACL_TYPE_ACCESS
:
673 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
675 case SMB_ACL_TYPE_DEFAULT
:
676 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
679 DEBUG(0, ("Got invalid type: %d\n", type
));
680 smb_panic("exiting");
683 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
686 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
689 struct gpfs_config_data
*config
;
691 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
692 struct gpfs_config_data
,
696 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle
, fsp
);
699 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
700 GPFS_ACL_TYPE_ACCESS
);
703 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
707 struct gpfs_acl
*result
;
710 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
712 len
= offsetof(gpfs_acl_t
, ace_v1
) + (pacl
->count
) *
713 sizeof(gpfs_ace_v1_t
);
715 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
716 if (result
== NULL
) {
721 result
->acl_len
= len
;
722 result
->acl_level
= 0;
723 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
724 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
725 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
726 result
->acl_nace
= pacl
->count
;
728 for (i
=0; i
<pacl
->count
; i
++) {
729 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
730 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
732 DEBUG(10, ("Converting type %d perm %x\n",
733 (int)ace
->a_type
, (int)ace
->a_perm
));
737 switch(ace
->a_type
) {
739 g_ace
->ace_type
= GPFS_ACL_USER
;
740 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
742 case SMB_ACL_USER_OBJ
:
743 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
744 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
748 g_ace
->ace_type
= GPFS_ACL_GROUP
;
749 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
751 case SMB_ACL_GROUP_OBJ
:
752 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
756 g_ace
->ace_type
= GPFS_ACL_MASK
;
757 g_ace
->ace_perm
= 0x8f;
761 g_ace
->ace_type
= GPFS_ACL_OTHER
;
765 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
771 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
773 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
775 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
776 ACL_PERM_EXECUTE
: 0;
778 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
779 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
785 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
790 struct gpfs_acl
*gpfs_acl
;
792 struct gpfs_config_data
*config
;
794 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
795 struct gpfs_config_data
,
799 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, name
, type
, theacl
);
802 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
803 if (gpfs_acl
== NULL
) {
807 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
813 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
817 struct gpfs_config_data
*config
;
819 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
820 struct gpfs_config_data
,
824 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle
, fsp
, theacl
);
827 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
828 SMB_ACL_TYPE_ACCESS
, theacl
);
831 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
834 struct gpfs_config_data
*config
;
836 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
837 struct gpfs_config_data
,
841 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, path
);
849 * Assumed: mode bits are shiftable and standard
850 * Output: the new aceMask field for an smb nfs4 ace
852 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
854 const uint32 posix_nfs4map
[3] = {
855 SMB_ACE4_EXECUTE
, /* execute */
856 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
857 SMB_ACE4_READ_DATA
/* read */
860 uint32_t posix_mask
= 0x01;
865 nfs4_bits
= posix_nfs4map
[i
];
866 posix_bit
= rwx
& posix_mask
;
868 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
870 aceMask
|= nfs4_bits
;
872 aceMask
&= ~nfs4_bits
;
874 /* add deny bits when suitable */
876 aceMask
|= nfs4_bits
;
878 aceMask
&= ~nfs4_bits
;
879 } /* other ace types are unexpected */
887 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
889 SMB4ACL_T
*pacl
= NULL
;
891 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
893 files_struct fake_fsp
; /* TODO: rationalize parametrization */
897 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
899 result
= gpfs_get_nfs4_acl(path
, &pacl
);
903 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
904 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
907 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
908 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
909 uint32_t specid
= ace
->who
.special_id
;
911 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
912 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
913 specid
<= SMB_ACE4_WHO_EVERYONE
) {
917 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
918 haveAllowEntry
[specid
] = True
;
920 /* mode >> 6 for @owner, mode >> 3 for @group,
921 * mode >> 0 for @everyone */
922 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
923 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
924 if (ace
->aceMask
!=newMask
) {
925 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
926 path
, ace
->aceMask
, newMask
, specid
));
928 ace
->aceMask
= newMask
;
932 /* make sure we have at least ALLOW entries
933 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
936 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
939 if (haveAllowEntry
[i
]==True
)
943 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
944 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
945 ace
.who
.special_id
= i
;
947 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
948 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
950 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
951 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
953 /* don't add unnecessary aces */
957 /* we add it to the END - as windows expects allow aces */
958 smb_add_ace4(pacl
, &ace
);
959 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
960 path
, mode
, i
, ace
.aceMask
));
963 /* don't add complementary DENY ACEs here */
964 ZERO_STRUCT(fake_fsp
);
965 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
967 if (!NT_STATUS_IS_OK(status
)) {
968 errno
= map_errno_from_nt_status(status
);
972 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
973 TALLOC_FREE(fake_fsp
.fsp_name
);
977 TALLOC_FREE(fake_fsp
.fsp_name
);
978 return 0; /* ok for [f]chmod */
981 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
983 struct smb_filename
*smb_fname_cpath
;
987 status
= create_synthetic_smb_fname(
988 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
990 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
994 /* avoid chmod() if possible, to preserve acls */
995 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
999 rc
= gpfsacl_emu_chmod(path
, mode
);
1001 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
1005 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
1010 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
1014 /* avoid chmod() if possible, to preserve acls */
1015 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
1019 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
1021 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
1025 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1026 const char *name
, const void *value
, size_t size
, int flags
){
1027 struct xattr_DOSATTRIB dosattrib
;
1028 enum ndr_err_code ndr_err
;
1030 const char *attrstr
= value
;
1031 unsigned int dosmode
=0;
1032 struct gpfs_winattr attrs
;
1034 struct gpfs_config_data
*config
;
1036 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1037 struct gpfs_config_data
,
1040 if (!config
->winattr
) {
1041 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
1042 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1045 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
1047 /* Only handle DOS Attributes */
1048 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1049 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
1050 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
1053 blob
.data
= (uint8_t *)attrstr
;
1056 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
1057 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
1059 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1060 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
1061 "from EA on file %s: Error = %s\n",
1062 path
, ndr_errstr(ndr_err
)));
1066 if (dosattrib
.version
!= 3) {
1067 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
1068 "%d\n", (int)dosattrib
.version
));
1071 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1072 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1073 "valid, ignoring\n"));
1077 dosmode
= dosattrib
.info
.info3
.attrib
;
1080 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1081 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1082 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1084 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1085 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1087 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1088 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1090 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1091 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1093 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1094 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1098 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1099 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1101 if (errno
== ENOSYS
) {
1102 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1106 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1110 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1114 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1115 const char *name
, void *value
, size_t size
){
1116 char *attrstr
= value
;
1117 unsigned int dosmode
= 0;
1118 struct gpfs_winattr attrs
;
1120 struct gpfs_config_data
*config
;
1122 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1123 struct gpfs_config_data
,
1126 if (!config
->winattr
) {
1127 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1128 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1131 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1133 /* Only handle DOS Attributes */
1134 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1135 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1136 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1139 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1141 if (errno
== ENOSYS
) {
1142 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1146 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1147 "%d (%s)\n", ret
, strerror(errno
)));
1151 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1153 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1154 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1155 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1157 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1158 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1160 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1161 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1163 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1164 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1166 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1167 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1170 snprintf(attrstr
, size
, "0x%2.2x",
1171 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1172 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1176 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1177 struct smb_filename
*smb_fname
)
1179 struct gpfs_winattr attrs
;
1183 struct gpfs_config_data
*config
;
1185 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1186 struct gpfs_config_data
,
1189 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1194 if (!config
->winattr
) {
1198 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1199 if (!NT_STATUS_IS_OK(status
)) {
1200 errno
= map_errno_from_nt_status(status
);
1203 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1206 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1207 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1208 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1209 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1214 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1215 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1217 struct gpfs_winattr attrs
;
1219 struct gpfs_config_data
*config
;
1221 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1222 struct gpfs_config_data
,
1225 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1229 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1232 if (!config
->winattr
) {
1236 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1238 sbuf
->st_ex_calculated_birthtime
= false;
1239 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1240 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1245 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1246 struct smb_filename
*smb_fname
)
1248 struct gpfs_winattr attrs
;
1252 struct gpfs_config_data
*config
;
1254 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1255 struct gpfs_config_data
,
1258 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1262 if (!config
->winattr
) {
1266 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1267 if (!NT_STATUS_IS_OK(status
)) {
1268 errno
= map_errno_from_nt_status(status
);
1271 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1274 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1275 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1276 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1277 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1282 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1283 const struct smb_filename
*smb_fname
,
1284 struct smb_file_time
*ft
)
1287 struct gpfs_winattr attrs
;
1291 struct gpfs_config_data
*config
;
1293 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1294 struct gpfs_config_data
,
1297 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1299 /* don't complain if access was denied */
1300 if (errno
!= EPERM
&& errno
!= EACCES
) {
1301 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1302 "%s", strerror(errno
)));
1307 if(null_timespec(ft
->create_time
)){
1308 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1312 if (!config
->winattr
) {
1316 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1317 if (!NT_STATUS_IS_OK(status
)) {
1318 errno
= map_errno_from_nt_status(status
);
1323 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1324 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1326 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1327 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1328 if(ret
== -1 && errno
!= ENOSYS
){
1329 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1336 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1337 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1338 off_t offset
, off_t len
)
1341 struct gpfs_config_data
*config
;
1343 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1344 struct gpfs_config_data
,
1347 if (!config
->prealloc
) {
1348 /* you should better not run fallocate() on GPFS at all */
1353 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1354 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1359 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1361 if (ret
== -1 && errno
!= ENOSYS
) {
1362 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1363 } else if (ret
== -1 && errno
== ENOSYS
) {
1364 DEBUG(10, ("GPFS prealloc not supported.\n"));
1366 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1372 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1376 struct gpfs_config_data
*config
;
1378 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1379 struct gpfs_config_data
,
1382 if (!config
->ftruncate
) {
1383 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1386 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1387 if ((result
== -1) && (errno
== ENOSYS
)) {
1388 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1393 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1394 const struct smb_filename
*fname
,
1395 SMB_STRUCT_STAT
*sbuf
)
1397 struct gpfs_winattr attrs
;
1400 struct gpfs_config_data
*config
;
1402 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1403 struct gpfs_config_data
,
1406 if (!config
->winattr
) {
1407 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1410 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1411 if (!NT_STATUS_IS_OK(status
)) {
1412 errno
= map_errno_from_nt_status(status
);
1416 if (VALID_STAT(*sbuf
)) {
1417 attrs
.winAttrs
= sbuf
->vfs_private
;
1420 ret
= get_gpfs_winattrs(path
, &attrs
);
1427 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1428 DEBUG(10, ("%s is offline\n", path
));
1432 DEBUG(10, ("%s is online\n", path
));
1434 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1437 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1438 struct files_struct
*fsp
)
1440 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1443 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1444 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1445 off_t offset
, size_t n
)
1447 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1451 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1454 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1455 const char *service
, const char *user
)
1457 struct gpfs_config_data
*config
;
1460 smbd_gpfs_lib_init();
1462 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1468 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1470 SMB_VFS_NEXT_DISCONNECT(handle
);
1471 DEBUG(0, ("talloc_zero() failed\n"));
1475 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1476 "sharemodes", true);
1478 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1481 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1484 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1487 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1490 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1493 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1494 "getrealfilename", true);
1496 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1497 "dfreequota", false);
1499 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1502 config
->acl
= lp_parm_bool(SNUM(handle
->conn
), "gpfs", "acl", true);
1504 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1505 NULL
, struct gpfs_config_data
,
1511 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1513 struct gpfs_quotaInfo
*qi_user
,
1514 struct gpfs_quotaInfo
*qi_group
,
1515 struct gpfs_quotaInfo
*qi_fset
)
1519 err
= get_gpfs_fset_id(path
, fset_id
);
1521 DEBUG(0, ("Get fset id failed, errno %d.\n", errno
));
1525 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1530 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1535 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1543 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1544 uint64_t *dfree
, uint64_t *dsize
)
1546 uint64_t usage
, limit
;
1549 * The quota reporting is done in units of 1024 byte blocks, but
1550 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1551 * accordingly. Also filter possibly negative usage counts from gpfs.
1553 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1554 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1557 * When the grace time for the exceeded soft block quota has been
1558 * exceeded, the soft block quota becomes an additional hard limit.
1560 if (qi
.blockSoftLimit
&&
1561 qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1562 /* report disk as full */
1564 *dsize
= MIN(*dsize
, usage
);
1567 if (!qi
.blockHardLimit
)
1570 if (usage
>= limit
) {
1571 /* report disk as full */
1573 *dsize
= MIN(*dsize
, usage
);
1576 /* limit has not been reached, determine "free space" */
1577 *dfree
= MIN(*dfree
, limit
- usage
);
1578 *dsize
= MIN(*dsize
, limit
);
1582 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1583 bool small_query
, uint64_t *bsize
,
1584 uint64_t *dfree
, uint64_t *dsize
)
1586 struct security_unix_token
*utok
;
1587 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1588 struct gpfs_config_data
*config
;
1592 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1593 return (uint64_t)-1);
1594 if (!config
->dfreequota
) {
1595 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1596 bsize
, dfree
, dsize
);
1599 err
= sys_fsusage(path
, dfree
, dsize
);
1601 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1602 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1603 bsize
, dfree
, dsize
);
1606 /* sys_fsusage returns units of 512 bytes */
1609 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1610 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1612 utok
= handle
->conn
->session_info
->unix_token
;
1613 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1614 &qi_user
, &qi_group
, &qi_fset
);
1616 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1617 bsize
, dfree
, dsize
);
1620 cur_time
= time(NULL
);
1622 /* Adjust free space and size according to quota limits. */
1623 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1624 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1626 /* Id 0 indicates the default quota, not an actual quota */
1628 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1631 disk_norm(small_query
, bsize
, dfree
, dsize
);
1635 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1636 enum timestamp_set_resolution
*p_ts_res
)
1638 struct gpfs_config_data
*config
;
1641 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1643 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1644 struct gpfs_config_data
,
1648 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1653 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1654 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1655 int flags
, mode_t mode
)
1657 struct gpfs_config_data
*config
;
1659 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1660 struct gpfs_config_data
,
1663 if (config
->syncio
) {
1666 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1670 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1671 .connect_fn
= vfs_gpfs_connect
,
1672 .disk_free_fn
= vfs_gpfs_disk_free
,
1673 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
1674 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
1675 .linux_setlease_fn
= vfs_gpfs_setlease
,
1676 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
1677 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
1678 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
1679 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
1680 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
1681 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
1682 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
1683 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
1684 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
1685 .chmod_fn
= vfs_gpfs_chmod
,
1686 .fchmod_fn
= vfs_gpfs_fchmod
,
1687 .close_fn
= vfs_gpfs_close
,
1688 .setxattr_fn
= gpfs_set_xattr
,
1689 .getxattr_fn
= gpfs_get_xattr
,
1690 .stat_fn
= vfs_gpfs_stat
,
1691 .fstat_fn
= vfs_gpfs_fstat
,
1692 .lstat_fn
= vfs_gpfs_lstat
,
1693 .ntimes_fn
= vfs_gpfs_ntimes
,
1694 .is_offline_fn
= vfs_gpfs_is_offline
,
1695 .aio_force_fn
= vfs_gpfs_aio_force
,
1696 .sendfile_fn
= vfs_gpfs_sendfile
,
1697 .fallocate_fn
= vfs_gpfs_fallocate
,
1698 .open_fn
= vfs_gpfs_open
,
1699 .ftruncate_fn
= vfs_gpfs_ftruncate
1702 NTSTATUS
vfs_gpfs_init(void);
1703 NTSTATUS
vfs_gpfs_init(void)
1707 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",