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
{
51 static int vfs_gpfs_kernel_flock(vfs_handle_struct
*handle
, files_struct
*fsp
,
52 uint32 share_mode
, uint32 access_mask
)
55 struct gpfs_config_data
*config
;
58 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
59 struct gpfs_config_data
,
62 START_PROFILE(syscall_kernel_flock
);
64 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
66 if (config
->sharemodes
67 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
71 END_PROFILE(syscall_kernel_flock
);
76 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
79 struct gpfs_config_data
*config
;
81 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
82 struct gpfs_config_data
,
85 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
86 set_gpfs_sharemode(fsp
, 0, 0);
89 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
92 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
95 struct gpfs_config_data
*config
;
98 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
99 struct gpfs_config_data
,
102 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
105 START_PROFILE(syscall_linux_setlease
);
107 if (config
->leases
) {
108 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
111 END_PROFILE(syscall_linux_setlease
);
116 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
124 char real_pathname
[PATH_MAX
+1];
127 struct gpfs_config_data
*config
;
129 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
130 struct gpfs_config_data
,
133 if (!config
->getrealfilename
) {
134 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
135 mem_ctx
, found_name
);
138 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
140 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
141 mem_ctx
, found_name
);
144 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
145 if (full_path
== NULL
) {
150 buflen
= sizeof(real_pathname
) - 1;
152 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
155 TALLOC_FREE(full_path
);
157 if ((result
== -1) && (errno
== ENOSYS
)) {
158 return SMB_VFS_NEXT_GET_REAL_FILENAME(
159 handle
, path
, name
, mem_ctx
, found_name
);
163 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
169 * GPFS does not necessarily null-terminate the returned path
170 * but instead returns the buffer length in buflen.
173 if (buflen
< sizeof(real_pathname
)) {
174 real_pathname
[buflen
] = '\0';
176 real_pathname
[sizeof(real_pathname
)-1] = '\0';
179 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
180 path
, name
, real_pathname
));
182 name
= strrchr_m(real_pathname
, '/');
188 *found_name
= talloc_strdup(mem_ctx
, name
+1);
189 if (*found_name
== NULL
) {
197 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
202 DEBUG(0, ("gpfs acl is NULL\n"));
206 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
207 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
208 for(i
=0; i
<gacl
->acl_nace
; i
++)
210 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
211 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
212 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
213 gace
->aceIFlags
, gace
->aceWho
));
217 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
219 struct gpfs_acl
*acl
;
222 TALLOC_CTX
*mem_ctx
= talloc_tos();
224 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
232 acl
->acl_version
= 0;
233 acl
->acl_type
= type
;
235 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
236 if ((ret
!= 0) && (errno
== ENOSPC
)) {
237 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
238 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
239 if (new_acl
== NULL
) {
244 new_acl
->acl_len
= acl
->acl_len
;
245 new_acl
->acl_level
= acl
->acl_level
;
246 new_acl
->acl_version
= acl
->acl_version
;
247 new_acl
->acl_type
= acl
->acl_type
;
250 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
, acl
);
254 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
261 /* Tries to get nfs4 acls and returns SMB ACL allocated.
262 * On failure returns 1 if it got non-NFSv4 ACL to prompt
263 * retry with POSIX ACL checks.
264 * On failure returns -1 if there is system (GPFS) error, check errno.
265 * Returns 0 on success
267 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
270 struct gpfs_acl
*gacl
= NULL
;
271 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
273 /* First get the real acl length */
274 gacl
= gpfs_getacl_alloc(fname
, 0);
276 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
277 fname
, strerror(errno
)));
281 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
282 DEBUG(10, ("Got non-nfsv4 acl\n"));
283 /* Retry with POSIX ACLs check */
287 *ppacl
= smb_create_smb4acl();
289 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
290 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
293 for (i
=0; i
<gacl
->acl_nace
; i
++) {
294 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
295 SMB_ACE4PROP_T smbace
;
296 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
297 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
298 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
301 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
302 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
303 switch (gace
->aceWho
) {
304 case ACE4_SPECIAL_OWNER
:
305 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
307 case ACE4_SPECIAL_GROUP
:
308 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
310 case ACE4_SPECIAL_EVERYONE
:
311 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
314 DEBUG(8, ("invalid special gpfs id %d "
315 "ignored\n", gace
->aceWho
));
316 continue; /* don't add it */
319 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
320 smbace
.who
.gid
= gace
->aceWho
;
322 smbace
.who
.uid
= gace
->aceWho
;
325 /* remove redundent deny entries */
326 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
327 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
328 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
329 prev
->aceFlags
== gace
->aceFlags
&&
330 prev
->aceIFlags
== gace
->aceIFlags
&&
331 (gace
->aceMask
& prev
->aceMask
) == 0 &&
332 gace
->aceWho
== prev
->aceWho
) {
333 /* its redundent - skip it */
338 smbace
.aceType
= gace
->aceType
;
339 smbace
.aceFlags
= gace
->aceFlags
;
340 smbace
.aceMask
= gace
->aceMask
;
341 smb_add_ace4(*ppacl
, &smbace
);
347 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
348 files_struct
*fsp
, uint32 security_info
,
349 struct security_descriptor
**ppdesc
)
351 SMB4ACL_T
*pacl
= NULL
;
355 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
358 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
361 DEBUG(10, ("retrying with posix acl...\n"));
362 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
365 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
366 return map_nt_error_from_unix(errno
);
369 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
371 uint32 security_info
, struct security_descriptor
**ppdesc
)
373 SMB4ACL_T
*pacl
= NULL
;
377 result
= gpfs_get_nfs4_acl(name
, &pacl
);
380 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
, pacl
);
383 DEBUG(10, ("retrying with posix acl...\n"));
384 return posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
387 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
388 return map_nt_error_from_unix(errno
);
391 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
394 gpfs_aclLen_t gacl_len
;
396 struct gpfs_acl
*gacl
;
397 TALLOC_CTX
*mem_ctx
= talloc_tos();
399 gacl_len
= sizeof(struct gpfs_acl
) +
400 (smb_get_naces(smbacl
)-1)*sizeof(gpfs_ace_v4_t
);
402 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
404 DEBUG(0, ("talloc failed\n"));
409 gacl
->acl_len
= gacl_len
;
411 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
412 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
413 gacl
->acl_nace
= 0; /* change later... */
415 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
416 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
417 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
419 gace
->aceType
= aceprop
->aceType
;
420 gace
->aceFlags
= aceprop
->aceFlags
;
421 gace
->aceMask
= aceprop
->aceMask
;
424 * GPFS can't distinguish between WRITE and APPEND on
425 * files, so one being set without the other is an
426 * error. Sorry for the many ()'s :-)
429 if (!fsp
->is_directory
431 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
432 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
434 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
435 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
437 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
438 "merge_writeappend", True
)) {
439 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
440 "WRITE^APPEND, setting WRITE|APPEND\n",
442 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
445 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
447 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
449 switch(aceprop
->who
.special_id
)
451 case SMB_ACE4_WHO_EVERYONE
:
452 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
454 case SMB_ACE4_WHO_OWNER
:
455 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
457 case SMB_ACE4_WHO_GROUP
:
458 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
461 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
462 continue; /* don't add it !!! */
465 /* just only for the type safety... */
466 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
467 gace
->aceWho
= aceprop
->who
.gid
;
469 gace
->aceWho
= aceprop
->who
.uid
;
475 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
476 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
478 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
479 gpfs_dumpacl(8, gacl
);
483 DEBUG(10, ("gpfs_putacl succeeded\n"));
487 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
489 struct gpfs_acl
*acl
;
490 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
492 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
496 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
498 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
499 "refuse_dacl_protected", false)
500 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
501 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
502 return NT_STATUS_NOT_SUPPORTED
;
505 result
= smb_set_nt_acl_nfs4(
506 fsp
, security_info_sent
, psd
,
507 gpfsacl_process_smbacl
);
508 } else { /* assume POSIX ACL - by default... */
509 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
515 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
517 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
520 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
525 result
= sys_acl_init(pacl
->acl_nace
);
526 if (result
== NULL
) {
531 result
->count
= pacl
->acl_nace
;
533 for (i
=0; i
<pacl
->acl_nace
; i
++) {
534 struct smb_acl_entry
*ace
= &result
->acl
[i
];
535 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
537 DEBUG(10, ("Converting type %d id %lu perm %x\n",
538 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
539 (int)g_ace
->ace_perm
));
541 switch (g_ace
->ace_type
) {
543 ace
->a_type
= SMB_ACL_USER
;
544 ace
->uid
= (uid_t
)g_ace
->ace_who
;
546 case GPFS_ACL_USER_OBJ
:
547 ace
->a_type
= SMB_ACL_USER_OBJ
;
550 ace
->a_type
= SMB_ACL_GROUP
;
551 ace
->gid
= (gid_t
)g_ace
->ace_who
;
553 case GPFS_ACL_GROUP_OBJ
:
554 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
557 ace
->a_type
= SMB_ACL_OTHER
;
560 ace
->a_type
= SMB_ACL_MASK
;
563 DEBUG(10, ("Got invalid ace_type: %d\n",
571 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
573 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
575 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
578 DEBUGADD(10, ("Converted to %d perm %x\n",
579 ace
->a_type
, ace
->a_perm
));
585 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
587 struct gpfs_acl
*pacl
;
588 SMB_ACL_T result
= NULL
;
590 pacl
= gpfs_getacl_alloc(path
, type
);
593 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
594 path
, strerror(errno
)));
601 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
602 DEBUG(10, ("Got acl version %d, expected %d\n",
603 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
608 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
609 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
612 result
= gpfs2smb_acl(pacl
);
613 if (result
== NULL
) {
625 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
629 gpfs_aclType_t gpfs_type
;
632 case SMB_ACL_TYPE_ACCESS
:
633 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
635 case SMB_ACL_TYPE_DEFAULT
:
636 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
639 DEBUG(0, ("Got invalid type: %d\n", type
));
640 smb_panic("exiting");
643 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
646 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
649 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
650 GPFS_ACL_TYPE_ACCESS
);
653 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
657 struct gpfs_acl
*result
;
661 gpfs_ace_v1_t ace_v1
[1]; /* when GPFS_ACL_VERSION_POSIX */
662 gpfs_ace_v4_t ace_v4
[1]; /* when GPFS_ACL_VERSION_NFS4 */
665 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
667 len
= sizeof(struct gpfs_acl
) - sizeof(union gpfs_ace_union
) +
668 (pacl
->count
)*sizeof(gpfs_ace_v1_t
);
670 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
671 if (result
== NULL
) {
676 result
->acl_len
= len
;
677 result
->acl_level
= 0;
678 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
679 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
680 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
681 result
->acl_nace
= pacl
->count
;
683 for (i
=0; i
<pacl
->count
; i
++) {
684 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
685 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
687 DEBUG(10, ("Converting type %d perm %x\n",
688 (int)ace
->a_type
, (int)ace
->a_perm
));
692 switch(ace
->a_type
) {
694 g_ace
->ace_type
= GPFS_ACL_USER
;
695 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
697 case SMB_ACL_USER_OBJ
:
698 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
699 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
703 g_ace
->ace_type
= GPFS_ACL_GROUP
;
704 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
706 case SMB_ACL_GROUP_OBJ
:
707 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
711 g_ace
->ace_type
= GPFS_ACL_MASK
;
712 g_ace
->ace_perm
= 0x8f;
716 g_ace
->ace_type
= GPFS_ACL_OTHER
;
720 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
726 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
728 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
730 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
731 ACL_PERM_EXECUTE
: 0;
733 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
734 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
740 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
745 struct gpfs_acl
*gpfs_acl
;
748 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
749 if (gpfs_acl
== NULL
) {
753 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
759 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
763 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
764 SMB_ACL_TYPE_ACCESS
, theacl
);
767 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
775 * Assumed: mode bits are shiftable and standard
776 * Output: the new aceMask field for an smb nfs4 ace
778 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
780 const uint32 posix_nfs4map
[3] = {
781 SMB_ACE4_EXECUTE
, /* execute */
782 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
783 SMB_ACE4_READ_DATA
/* read */
786 uint32_t posix_mask
= 0x01;
791 nfs4_bits
= posix_nfs4map
[i
];
792 posix_bit
= rwx
& posix_mask
;
794 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
796 aceMask
|= nfs4_bits
;
798 aceMask
&= ~nfs4_bits
;
800 /* add deny bits when suitable */
802 aceMask
|= nfs4_bits
;
804 aceMask
&= ~nfs4_bits
;
805 } /* other ace types are unexpected */
813 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
815 SMB4ACL_T
*pacl
= NULL
;
817 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
819 files_struct fake_fsp
; /* TODO: rationalize parametrization */
823 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
825 result
= gpfs_get_nfs4_acl(path
, &pacl
);
829 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
830 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
833 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
834 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
835 uint32_t specid
= ace
->who
.special_id
;
837 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
838 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
839 specid
<= SMB_ACE4_WHO_EVERYONE
) {
843 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
844 haveAllowEntry
[specid
] = True
;
846 /* mode >> 6 for @owner, mode >> 3 for @group,
847 * mode >> 0 for @everyone */
848 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
849 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
850 if (ace
->aceMask
!=newMask
) {
851 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
852 path
, ace
->aceMask
, newMask
, specid
));
854 ace
->aceMask
= newMask
;
858 /* make sure we have at least ALLOW entries
859 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
862 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
865 if (haveAllowEntry
[i
]==True
)
869 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
870 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
871 ace
.who
.special_id
= i
;
873 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
874 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
876 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
877 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
879 /* don't add unnecessary aces */
883 /* we add it to the END - as windows expects allow aces */
884 smb_add_ace4(pacl
, &ace
);
885 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
886 path
, mode
, i
, ace
.aceMask
));
889 /* don't add complementary DENY ACEs here */
890 ZERO_STRUCT(fake_fsp
);
891 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
893 if (!NT_STATUS_IS_OK(status
)) {
894 errno
= map_errno_from_nt_status(status
);
898 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
899 TALLOC_FREE(fake_fsp
.fsp_name
);
903 TALLOC_FREE(fake_fsp
.fsp_name
);
904 return 0; /* ok for [f]chmod */
907 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
909 struct smb_filename
*smb_fname_cpath
;
913 status
= create_synthetic_smb_fname(
914 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
916 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
920 /* avoid chmod() if possible, to preserve acls */
921 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
925 rc
= gpfsacl_emu_chmod(path
, mode
);
927 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
931 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
936 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
940 /* avoid chmod() if possible, to preserve acls */
941 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
945 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
947 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
951 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
952 const char *name
, const void *value
, size_t size
, int flags
){
953 struct xattr_DOSATTRIB dosattrib
;
954 enum ndr_err_code ndr_err
;
956 const char *attrstr
= value
;
957 unsigned int dosmode
=0;
958 struct gpfs_winattr attrs
;
960 struct gpfs_config_data
*config
;
962 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
963 struct gpfs_config_data
,
966 if (!config
->winattr
) {
967 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
968 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
971 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
973 /* Only handle DOS Attributes */
974 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
975 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
976 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
979 blob
.data
= (uint8_t *)attrstr
;
982 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
983 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
985 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
986 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
987 "from EA on file %s: Error = %s\n",
988 path
, ndr_errstr(ndr_err
)));
992 if (dosattrib
.version
!= 3) {
993 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
994 "%d\n", (int)dosattrib
.version
));
997 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
998 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
999 "valid, ignoring\n"));
1003 dosmode
= dosattrib
.info
.info3
.attrib
;
1006 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1007 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1008 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1010 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1011 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1013 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1014 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1016 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1017 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1019 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1020 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1024 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1025 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1027 if (errno
== ENOSYS
) {
1028 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1032 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1036 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1040 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1041 const char *name
, void *value
, size_t size
){
1042 char *attrstr
= value
;
1043 unsigned int dosmode
= 0;
1044 struct gpfs_winattr attrs
;
1046 struct gpfs_config_data
*config
;
1048 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1049 struct gpfs_config_data
,
1052 if (!config
->winattr
) {
1053 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1054 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1057 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1059 /* Only handle DOS Attributes */
1060 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1061 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1062 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1065 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1067 if (errno
== ENOSYS
) {
1068 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1072 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1073 "%d (%s)\n", ret
, strerror(errno
)));
1077 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1079 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1080 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1081 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1083 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1084 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1086 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1087 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1089 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1090 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1092 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1093 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1096 snprintf(attrstr
, size
, "0x%2.2x",
1097 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1098 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1102 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1103 struct smb_filename
*smb_fname
)
1105 struct gpfs_winattr attrs
;
1109 struct gpfs_config_data
*config
;
1111 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1112 struct gpfs_config_data
,
1115 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1120 if (!config
->winattr
) {
1124 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1125 if (!NT_STATUS_IS_OK(status
)) {
1126 errno
= map_errno_from_nt_status(status
);
1129 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1132 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1133 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1134 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1135 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1140 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1141 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1143 struct gpfs_winattr attrs
;
1145 struct gpfs_config_data
*config
;
1147 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1148 struct gpfs_config_data
,
1151 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1155 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1158 if (!config
->winattr
) {
1162 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1164 sbuf
->st_ex_calculated_birthtime
= false;
1165 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1166 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1171 static int vfs_gpfs_lstat(struct vfs_handle_struct
*handle
,
1172 struct smb_filename
*smb_fname
)
1174 struct gpfs_winattr attrs
;
1178 struct gpfs_config_data
*config
;
1180 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1181 struct gpfs_config_data
,
1184 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1188 if (!config
->winattr
) {
1192 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1193 if (!NT_STATUS_IS_OK(status
)) {
1194 errno
= map_errno_from_nt_status(status
);
1197 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1200 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1201 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1202 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1203 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1208 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1209 const struct smb_filename
*smb_fname
,
1210 struct smb_file_time
*ft
)
1213 struct gpfs_winattr attrs
;
1217 struct gpfs_config_data
*config
;
1219 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1220 struct gpfs_config_data
,
1223 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1225 /* don't complain if access was denied */
1226 if (errno
!= EPERM
&& errno
!= EACCES
) {
1227 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1228 "%s", strerror(errno
)));
1233 if(null_timespec(ft
->create_time
)){
1234 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1238 if (!config
->winattr
) {
1242 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1243 if (!NT_STATUS_IS_OK(status
)) {
1244 errno
= map_errno_from_nt_status(status
);
1249 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1250 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1252 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1253 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1254 if(ret
== -1 && errno
!= ENOSYS
){
1255 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1262 static int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1263 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1264 off_t offset
, off_t len
)
1267 struct gpfs_config_data
*config
;
1269 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1270 struct gpfs_config_data
,
1273 if (!config
->prealloc
) {
1274 /* you should better not run fallocate() on GPFS at all */
1279 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1280 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1285 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1287 if (ret
== -1 && errno
!= ENOSYS
) {
1288 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1289 } else if (ret
== -1 && errno
== ENOSYS
) {
1290 DEBUG(10, ("GPFS prealloc not supported.\n"));
1292 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1298 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1302 struct gpfs_config_data
*config
;
1304 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1305 struct gpfs_config_data
,
1308 if (!config
->ftruncate
) {
1309 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1312 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1313 if ((result
== -1) && (errno
== ENOSYS
)) {
1314 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1319 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1320 const struct smb_filename
*fname
,
1321 SMB_STRUCT_STAT
*sbuf
)
1323 struct gpfs_winattr attrs
;
1326 struct gpfs_config_data
*config
;
1328 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1329 struct gpfs_config_data
,
1332 if (!config
->winattr
) {
1333 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1336 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1337 if (!NT_STATUS_IS_OK(status
)) {
1338 errno
= map_errno_from_nt_status(status
);
1342 if (VALID_STAT(*sbuf
)) {
1343 attrs
.winAttrs
= sbuf
->vfs_private
;
1346 ret
= get_gpfs_winattrs(path
, &attrs
);
1353 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1354 DEBUG(10, ("%s is offline\n", path
));
1358 DEBUG(10, ("%s is online\n", path
));
1360 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1363 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1364 struct files_struct
*fsp
)
1366 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1369 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1370 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1371 off_t offset
, size_t n
)
1373 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1377 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1380 static int vfs_gpfs_connect(struct vfs_handle_struct
*handle
,
1381 const char *service
, const char *user
)
1383 struct gpfs_config_data
*config
;
1386 smbd_gpfs_lib_init();
1388 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1394 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1396 SMB_VFS_NEXT_DISCONNECT(handle
);
1397 DEBUG(0, ("talloc_zero() failed\n"));
1401 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1402 "sharemodes", true);
1404 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1407 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1410 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1413 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1416 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1419 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1420 "getrealfilename", true);
1422 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1423 "dfreequota", false);
1425 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1428 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1429 NULL
, struct gpfs_config_data
,
1435 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1437 struct gpfs_quotaInfo
*qi_user
,
1438 struct gpfs_quotaInfo
*qi_group
,
1439 struct gpfs_quotaInfo
*qi_fset
)
1443 err
= get_gpfs_fset_id(path
, fset_id
);
1445 DEBUG(0, ("Get fset id failed, errno %d.\n", errno
));
1449 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1454 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1459 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1467 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1468 uint64_t *dfree
, uint64_t *dsize
)
1470 uint64_t usage
, limit
;
1473 * The quota reporting is done in units of 1024 byte blocks, but
1474 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1475 * accordingly. Also filter possibly negative usage counts from gpfs.
1477 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1478 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1481 * When the grace time for the exceeded soft block quota has been
1482 * exceeded, the soft block quota becomes an additional hard limit.
1484 if (qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1485 /* report disk as full */
1487 *dsize
= MIN(*dsize
, usage
);
1490 if (!qi
.blockHardLimit
)
1493 if (usage
>= limit
) {
1494 /* report disk as full */
1496 *dsize
= MIN(*dsize
, usage
);
1499 /* limit has not been reached, determine "free space" */
1500 *dfree
= MIN(*dfree
, limit
- usage
);
1501 *dsize
= MIN(*dsize
, limit
);
1505 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1506 bool small_query
, uint64_t *bsize
,
1507 uint64_t *dfree
, uint64_t *dsize
)
1509 struct security_unix_token
*utok
;
1510 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1511 struct gpfs_config_data
*config
;
1515 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1516 return (uint64_t)-1);
1517 if (!config
->dfreequota
) {
1518 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1519 bsize
, dfree
, dsize
);
1522 err
= sys_fsusage(path
, dfree
, dsize
);
1524 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1525 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1526 bsize
, dfree
, dsize
);
1529 /* sys_fsusage returns units of 512 bytes */
1532 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1533 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1535 utok
= handle
->conn
->session_info
->unix_token
;
1536 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1537 &qi_user
, &qi_group
, &qi_fset
);
1539 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1540 bsize
, dfree
, dsize
);
1543 cur_time
= time(NULL
);
1545 /* Adjust free space and size according to quota limits. */
1546 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1547 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1549 /* Id 0 indicates the default quota, not an actual quota */
1551 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1554 disk_norm(small_query
, bsize
, dfree
, dsize
);
1558 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1559 enum timestamp_set_resolution
*p_ts_res
)
1561 struct gpfs_config_data
*config
;
1564 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1566 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1567 struct gpfs_config_data
,
1571 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1576 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1577 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1578 int flags
, mode_t mode
)
1580 struct gpfs_config_data
*config
;
1582 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1583 struct gpfs_config_data
,
1586 if (config
->syncio
) {
1589 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1593 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1594 .connect_fn
= vfs_gpfs_connect
,
1595 .disk_free_fn
= vfs_gpfs_disk_free
,
1596 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
1597 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
1598 .linux_setlease_fn
= vfs_gpfs_setlease
,
1599 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
1600 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
1601 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
1602 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
1603 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
1604 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
1605 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
1606 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
1607 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
1608 .chmod_fn
= vfs_gpfs_chmod
,
1609 .fchmod_fn
= vfs_gpfs_fchmod
,
1610 .close_fn
= vfs_gpfs_close
,
1611 .setxattr_fn
= gpfs_set_xattr
,
1612 .getxattr_fn
= gpfs_get_xattr
,
1613 .stat_fn
= vfs_gpfs_stat
,
1614 .fstat_fn
= vfs_gpfs_fstat
,
1615 .lstat_fn
= vfs_gpfs_lstat
,
1616 .ntimes_fn
= vfs_gpfs_ntimes
,
1617 .is_offline_fn
= vfs_gpfs_is_offline
,
1618 .aio_force_fn
= vfs_gpfs_aio_force
,
1619 .sendfile_fn
= vfs_gpfs_sendfile
,
1620 .fallocate_fn
= vfs_gpfs_fallocate
,
1621 .open_fn
= vfs_gpfs_open
,
1622 .ftruncate_fn
= vfs_gpfs_ftruncate
1625 NTSTATUS
vfs_gpfs_init(void);
1626 NTSTATUS
vfs_gpfs_init(void)
1630 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",