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
;
57 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
58 struct gpfs_config_data
,
61 START_PROFILE(syscall_kernel_flock
);
63 kernel_flock(fsp
->fh
->fd
, share_mode
, access_mask
);
65 if (config
->sharemodes
66 && !set_gpfs_sharemode(fsp
, access_mask
, fsp
->share_access
)) {
70 END_PROFILE(syscall_kernel_flock
);
75 static int vfs_gpfs_close(vfs_handle_struct
*handle
, files_struct
*fsp
)
78 struct gpfs_config_data
*config
;
80 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
81 struct gpfs_config_data
,
84 if (config
->sharemodes
&& (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
85 set_gpfs_sharemode(fsp
, 0, 0);
88 return SMB_VFS_NEXT_CLOSE(handle
, fsp
);
91 static int vfs_gpfs_setlease(vfs_handle_struct
*handle
, files_struct
*fsp
,
94 struct gpfs_config_data
*config
;
97 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
98 struct gpfs_config_data
,
101 START_PROFILE(syscall_linux_setlease
);
103 if (linux_set_lease_sighandler(fsp
->fh
->fd
) == -1)
106 if (config
->leases
) {
107 ret
= set_gpfs_lease(fsp
->fh
->fd
,leasetype
);
111 /* This must have come from GPFS not being available */
112 /* or some other error, hence call the default */
113 ret
= linux_setlease(fsp
->fh
->fd
, leasetype
);
116 END_PROFILE(syscall_linux_setlease
);
121 static int vfs_gpfs_get_real_filename(struct vfs_handle_struct
*handle
,
129 char real_pathname
[PATH_MAX
+1];
132 struct gpfs_config_data
*config
;
134 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
135 struct gpfs_config_data
,
138 if (!config
->getrealfilename
) {
139 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
140 mem_ctx
, found_name
);
143 mangled
= mangle_is_mangled(name
, handle
->conn
->params
);
145 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
146 mem_ctx
, found_name
);
149 full_path
= talloc_asprintf(talloc_tos(), "%s/%s", path
, name
);
150 if (full_path
== NULL
) {
155 buflen
= sizeof(real_pathname
) - 1;
157 result
= smbd_gpfs_get_realfilename_path(full_path
, real_pathname
,
160 TALLOC_FREE(full_path
);
162 if ((result
== -1) && (errno
== ENOSYS
)) {
163 return SMB_VFS_NEXT_GET_REAL_FILENAME(
164 handle
, path
, name
, mem_ctx
, found_name
);
168 DEBUG(10, ("smbd_gpfs_get_realfilename_path returned %s\n",
174 * GPFS does not necessarily null-terminate the returned path
175 * but instead returns the buffer length in buflen.
178 if (buflen
< sizeof(real_pathname
)) {
179 real_pathname
[buflen
] = '\0';
181 real_pathname
[sizeof(real_pathname
)-1] = '\0';
184 DEBUG(10, ("smbd_gpfs_get_realfilename_path: %s/%s -> %s\n",
185 path
, name
, real_pathname
));
187 name
= strrchr_m(real_pathname
, '/');
193 *found_name
= talloc_strdup(mem_ctx
, name
+1);
194 if (*found_name
== NULL
) {
202 static void gpfs_dumpacl(int level
, struct gpfs_acl
*gacl
)
207 DEBUG(0, ("gpfs acl is NULL\n"));
211 DEBUG(level
, ("gpfs acl: nace: %d, type:%d, version:%d, level:%d, len:%d\n",
212 gacl
->acl_nace
, gacl
->acl_type
, gacl
->acl_version
, gacl
->acl_level
, gacl
->acl_len
));
213 for(i
=0; i
<gacl
->acl_nace
; i
++)
215 struct gpfs_ace_v4
*gace
= gacl
->ace_v4
+ i
;
216 DEBUG(level
, ("\tace[%d]: type:%d, flags:0x%x, mask:0x%x, iflags:0x%x, who:%u\n",
217 i
, gace
->aceType
, gace
->aceFlags
, gace
->aceMask
,
218 gace
->aceIFlags
, gace
->aceWho
));
222 static struct gpfs_acl
*gpfs_getacl_alloc(const char *fname
, gpfs_aclType_t type
)
224 struct gpfs_acl
*acl
;
227 TALLOC_CTX
*mem_ctx
= talloc_tos();
229 acl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, len
);
237 acl
->acl_version
= 0;
238 acl
->acl_type
= type
;
240 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
241 if ((ret
!= 0) && (errno
== ENOSPC
)) {
242 struct gpfs_acl
*new_acl
= (struct gpfs_acl
*)TALLOC_SIZE(
243 mem_ctx
, acl
->acl_len
+ sizeof(struct gpfs_acl
));
244 if (new_acl
== NULL
) {
249 new_acl
->acl_len
= acl
->acl_len
;
250 new_acl
->acl_level
= acl
->acl_level
;
251 new_acl
->acl_version
= acl
->acl_version
;
252 new_acl
->acl_type
= acl
->acl_type
;
255 ret
= smbd_gpfs_getacl((char *)fname
, GPFS_GETACL_STRUCT
| GPFS_ACL_SAMBA
, acl
);
259 DEBUG(8, ("smbd_gpfs_getacl failed with %s\n",strerror(errno
)));
266 /* Tries to get nfs4 acls and returns SMB ACL allocated.
267 * On failure returns 1 if it got non-NFSv4 ACL to prompt
268 * retry with POSIX ACL checks.
269 * On failure returns -1 if there is system (GPFS) error, check errno.
270 * Returns 0 on success
272 static int gpfs_get_nfs4_acl(const char *fname
, SMB4ACL_T
**ppacl
)
275 struct gpfs_acl
*gacl
= NULL
;
276 DEBUG(10, ("gpfs_get_nfs4_acl invoked for %s\n", fname
));
278 /* First get the real acl length */
279 gacl
= gpfs_getacl_alloc(fname
, 0);
281 DEBUG(9, ("gpfs_getacl failed for %s with %s\n",
282 fname
, strerror(errno
)));
286 if (gacl
->acl_type
!= GPFS_ACL_TYPE_NFS4
) {
287 DEBUG(10, ("Got non-nfsv4 acl\n"));
288 /* Retry with POSIX ACLs check */
292 *ppacl
= smb_create_smb4acl();
294 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
295 gacl
->acl_len
, gacl
->acl_level
, gacl
->acl_version
,
298 for (i
=0; i
<gacl
->acl_nace
; i
++) {
299 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[i
];
300 SMB_ACE4PROP_T smbace
;
301 DEBUG(10, ("type: %d, iflags: %x, flags: %x, mask: %x, "
302 "who: %d\n", gace
->aceType
, gace
->aceIFlags
,
303 gace
->aceFlags
, gace
->aceMask
, gace
->aceWho
));
306 if (gace
->aceIFlags
& ACE4_IFLAG_SPECIAL_ID
) {
307 smbace
.flags
|= SMB_ACE4_ID_SPECIAL
;
308 switch (gace
->aceWho
) {
309 case ACE4_SPECIAL_OWNER
:
310 smbace
.who
.special_id
= SMB_ACE4_WHO_OWNER
;
312 case ACE4_SPECIAL_GROUP
:
313 smbace
.who
.special_id
= SMB_ACE4_WHO_GROUP
;
315 case ACE4_SPECIAL_EVERYONE
:
316 smbace
.who
.special_id
= SMB_ACE4_WHO_EVERYONE
;
319 DEBUG(8, ("invalid special gpfs id %d "
320 "ignored\n", gace
->aceWho
));
321 continue; /* don't add it */
324 if (gace
->aceFlags
& ACE4_FLAG_GROUP_ID
)
325 smbace
.who
.gid
= gace
->aceWho
;
327 smbace
.who
.uid
= gace
->aceWho
;
330 /* remove redundent deny entries */
331 if (i
> 0 && gace
->aceType
== SMB_ACE4_ACCESS_DENIED_ACE_TYPE
) {
332 struct gpfs_ace_v4
*prev
= &gacl
->ace_v4
[i
-1];
333 if (prev
->aceType
== SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
&&
334 prev
->aceFlags
== gace
->aceFlags
&&
335 prev
->aceIFlags
== gace
->aceIFlags
&&
336 (gace
->aceMask
& prev
->aceMask
) == 0 &&
337 gace
->aceWho
== prev
->aceWho
) {
338 /* its redundent - skip it */
343 smbace
.aceType
= gace
->aceType
;
344 smbace
.aceFlags
= gace
->aceFlags
;
345 smbace
.aceMask
= gace
->aceMask
;
346 smb_add_ace4(*ppacl
, &smbace
);
352 static NTSTATUS
gpfsacl_fget_nt_acl(vfs_handle_struct
*handle
,
353 files_struct
*fsp
, uint32 security_info
,
354 struct security_descriptor
**ppdesc
)
356 SMB4ACL_T
*pacl
= NULL
;
360 result
= gpfs_get_nfs4_acl(fsp
->fsp_name
->base_name
, &pacl
);
363 return smb_fget_nt_acl_nfs4(fsp
, security_info
, ppdesc
, pacl
);
366 DEBUG(10, ("retrying with posix acl...\n"));
367 return posix_fget_nt_acl(fsp
, security_info
, ppdesc
);
370 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
371 return map_nt_error_from_unix(errno
);
374 static NTSTATUS
gpfsacl_get_nt_acl(vfs_handle_struct
*handle
,
376 uint32 security_info
, struct security_descriptor
**ppdesc
)
378 SMB4ACL_T
*pacl
= NULL
;
382 result
= gpfs_get_nfs4_acl(name
, &pacl
);
385 return smb_get_nt_acl_nfs4(handle
->conn
, name
, security_info
, ppdesc
, pacl
);
388 DEBUG(10, ("retrying with posix acl...\n"));
389 return posix_get_nt_acl(handle
->conn
, name
, security_info
, ppdesc
);
392 /* GPFS ACL was not read, something wrong happened, error code is set in errno */
393 return map_nt_error_from_unix(errno
);
396 static bool gpfsacl_process_smbacl(files_struct
*fsp
, SMB4ACL_T
*smbacl
)
399 gpfs_aclLen_t gacl_len
;
401 struct gpfs_acl
*gacl
;
402 TALLOC_CTX
*mem_ctx
= talloc_tos();
404 gacl_len
= sizeof(struct gpfs_acl
) +
405 (smb_get_naces(smbacl
)-1)*sizeof(gpfs_ace_v4_t
);
407 gacl
= (struct gpfs_acl
*)TALLOC_SIZE(mem_ctx
, gacl_len
);
409 DEBUG(0, ("talloc failed\n"));
414 gacl
->acl_len
= gacl_len
;
416 gacl
->acl_version
= GPFS_ACL_VERSION_NFS4
;
417 gacl
->acl_type
= GPFS_ACL_TYPE_NFS4
;
418 gacl
->acl_nace
= 0; /* change later... */
420 for (smbace
=smb_first_ace4(smbacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
421 struct gpfs_ace_v4
*gace
= &gacl
->ace_v4
[gacl
->acl_nace
];
422 SMB_ACE4PROP_T
*aceprop
= smb_get_ace4(smbace
);
424 gace
->aceType
= aceprop
->aceType
;
425 gace
->aceFlags
= aceprop
->aceFlags
;
426 gace
->aceMask
= aceprop
->aceMask
;
429 * GPFS can't distinguish between WRITE and APPEND on
430 * files, so one being set without the other is an
431 * error. Sorry for the many ()'s :-)
434 if (!fsp
->is_directory
436 ((((gace
->aceMask
& ACE4_MASK_WRITE
) == 0)
437 && ((gace
->aceMask
& ACE4_MASK_APPEND
) != 0))
439 (((gace
->aceMask
& ACE4_MASK_WRITE
) != 0)
440 && ((gace
->aceMask
& ACE4_MASK_APPEND
) == 0)))
442 lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
443 "merge_writeappend", True
)) {
444 DEBUG(2, ("vfs_gpfs.c: file [%s]: ACE contains "
445 "WRITE^APPEND, setting WRITE|APPEND\n",
447 gace
->aceMask
|= ACE4_MASK_WRITE
|ACE4_MASK_APPEND
;
450 gace
->aceIFlags
= (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
) ? ACE4_IFLAG_SPECIAL_ID
: 0;
452 if (aceprop
->flags
&SMB_ACE4_ID_SPECIAL
)
454 switch(aceprop
->who
.special_id
)
456 case SMB_ACE4_WHO_EVERYONE
:
457 gace
->aceWho
= ACE4_SPECIAL_EVERYONE
;
459 case SMB_ACE4_WHO_OWNER
:
460 gace
->aceWho
= ACE4_SPECIAL_OWNER
;
462 case SMB_ACE4_WHO_GROUP
:
463 gace
->aceWho
= ACE4_SPECIAL_GROUP
;
466 DEBUG(8, ("unsupported special_id %d\n", aceprop
->who
.special_id
));
467 continue; /* don't add it !!! */
470 /* just only for the type safety... */
471 if (aceprop
->aceFlags
&SMB_ACE4_IDENTIFIER_GROUP
)
472 gace
->aceWho
= aceprop
->who
.gid
;
474 gace
->aceWho
= aceprop
->who
.uid
;
480 ret
= smbd_gpfs_putacl(fsp
->fsp_name
->base_name
,
481 GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gacl
);
483 DEBUG(8, ("gpfs_putacl failed with %s\n", strerror(errno
)));
484 gpfs_dumpacl(8, gacl
);
488 DEBUG(10, ("gpfs_putacl succeeded\n"));
492 static NTSTATUS
gpfsacl_set_nt_acl_internal(files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
494 struct gpfs_acl
*acl
;
495 NTSTATUS result
= NT_STATUS_ACCESS_DENIED
;
497 acl
= gpfs_getacl_alloc(fsp
->fsp_name
->base_name
, 0);
501 if (acl
->acl_version
&GPFS_ACL_VERSION_NFS4
)
503 if (lp_parm_bool(fsp
->conn
->params
->service
, "gpfs",
504 "refuse_dacl_protected", false)
505 && (psd
->type
&SEC_DESC_DACL_PROTECTED
)) {
506 DEBUG(2, ("Rejecting unsupported ACL with DACL_PROTECTED bit set\n"));
507 return NT_STATUS_NOT_SUPPORTED
;
510 result
= smb_set_nt_acl_nfs4(
511 fsp
, security_info_sent
, psd
,
512 gpfsacl_process_smbacl
);
513 } else { /* assume POSIX ACL - by default... */
514 result
= set_nt_acl(fsp
, security_info_sent
, psd
);
520 static NTSTATUS
gpfsacl_fset_nt_acl(vfs_handle_struct
*handle
, files_struct
*fsp
, uint32 security_info_sent
, const struct security_descriptor
*psd
)
522 return gpfsacl_set_nt_acl_internal(fsp
, security_info_sent
, psd
);
525 static SMB_ACL_T
gpfs2smb_acl(const struct gpfs_acl
*pacl
)
530 result
= sys_acl_init(pacl
->acl_nace
);
531 if (result
== NULL
) {
536 result
->count
= pacl
->acl_nace
;
538 for (i
=0; i
<pacl
->acl_nace
; i
++) {
539 struct smb_acl_entry
*ace
= &result
->acl
[i
];
540 const struct gpfs_ace_v1
*g_ace
= &pacl
->ace_v1
[i
];
542 DEBUG(10, ("Converting type %d id %lu perm %x\n",
543 (int)g_ace
->ace_type
, (unsigned long)g_ace
->ace_who
,
544 (int)g_ace
->ace_perm
));
546 switch (g_ace
->ace_type
) {
548 ace
->a_type
= SMB_ACL_USER
;
549 ace
->uid
= (uid_t
)g_ace
->ace_who
;
551 case GPFS_ACL_USER_OBJ
:
552 ace
->a_type
= SMB_ACL_USER_OBJ
;
555 ace
->a_type
= SMB_ACL_GROUP
;
556 ace
->gid
= (gid_t
)g_ace
->ace_who
;
558 case GPFS_ACL_GROUP_OBJ
:
559 ace
->a_type
= SMB_ACL_GROUP_OBJ
;
562 ace
->a_type
= SMB_ACL_OTHER
;
565 ace
->a_type
= SMB_ACL_MASK
;
568 DEBUG(10, ("Got invalid ace_type: %d\n",
576 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_READ
) ?
578 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_WRITE
) ?
580 ace
->a_perm
|= (g_ace
->ace_perm
& ACL_PERM_EXECUTE
) ?
583 DEBUGADD(10, ("Converted to %d perm %x\n",
584 ace
->a_type
, ace
->a_perm
));
590 static SMB_ACL_T
gpfsacl_get_posix_acl(const char *path
, gpfs_aclType_t type
)
592 struct gpfs_acl
*pacl
;
593 SMB_ACL_T result
= NULL
;
595 pacl
= gpfs_getacl_alloc(path
, type
);
598 DEBUG(10, ("gpfs_getacl failed for %s with %s\n",
599 path
, strerror(errno
)));
606 if (pacl
->acl_version
!= GPFS_ACL_VERSION_POSIX
) {
607 DEBUG(10, ("Got acl version %d, expected %d\n",
608 pacl
->acl_version
, GPFS_ACL_VERSION_POSIX
));
613 DEBUG(10, ("len: %d, level: %d, version: %d, nace: %d\n",
614 pacl
->acl_len
, pacl
->acl_level
, pacl
->acl_version
,
617 result
= gpfs2smb_acl(pacl
);
618 if (result
== NULL
) {
630 static SMB_ACL_T
gpfsacl_sys_acl_get_file(vfs_handle_struct
*handle
,
634 gpfs_aclType_t gpfs_type
;
637 case SMB_ACL_TYPE_ACCESS
:
638 gpfs_type
= GPFS_ACL_TYPE_ACCESS
;
640 case SMB_ACL_TYPE_DEFAULT
:
641 gpfs_type
= GPFS_ACL_TYPE_DEFAULT
;
644 DEBUG(0, ("Got invalid type: %d\n", type
));
645 smb_panic("exiting");
648 return gpfsacl_get_posix_acl(path_p
, gpfs_type
);
651 static SMB_ACL_T
gpfsacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
654 return gpfsacl_get_posix_acl(fsp
->fsp_name
->base_name
,
655 GPFS_ACL_TYPE_ACCESS
);
658 static struct gpfs_acl
*smb2gpfs_acl(const SMB_ACL_T pacl
,
662 struct gpfs_acl
*result
;
666 gpfs_ace_v1_t ace_v1
[1]; /* when GPFS_ACL_VERSION_POSIX */
667 gpfs_ace_v4_t ace_v4
[1]; /* when GPFS_ACL_VERSION_NFS4 */
670 DEBUG(10, ("smb2gpfs_acl: Got ACL with %d entries\n", pacl
->count
));
672 len
= sizeof(struct gpfs_acl
) - sizeof(union gpfs_ace_union
) +
673 (pacl
->count
)*sizeof(gpfs_ace_v1_t
);
675 result
= (struct gpfs_acl
*)SMB_MALLOC(len
);
676 if (result
== NULL
) {
681 result
->acl_len
= len
;
682 result
->acl_level
= 0;
683 result
->acl_version
= GPFS_ACL_VERSION_POSIX
;
684 result
->acl_type
= (type
== SMB_ACL_TYPE_DEFAULT
) ?
685 GPFS_ACL_TYPE_DEFAULT
: GPFS_ACL_TYPE_ACCESS
;
686 result
->acl_nace
= pacl
->count
;
688 for (i
=0; i
<pacl
->count
; i
++) {
689 const struct smb_acl_entry
*ace
= &pacl
->acl
[i
];
690 struct gpfs_ace_v1
*g_ace
= &result
->ace_v1
[i
];
692 DEBUG(10, ("Converting type %d perm %x\n",
693 (int)ace
->a_type
, (int)ace
->a_perm
));
697 switch(ace
->a_type
) {
699 g_ace
->ace_type
= GPFS_ACL_USER
;
700 g_ace
->ace_who
= (gpfs_uid_t
)ace
->uid
;
702 case SMB_ACL_USER_OBJ
:
703 g_ace
->ace_type
= GPFS_ACL_USER_OBJ
;
704 g_ace
->ace_perm
|= ACL_PERM_CONTROL
;
708 g_ace
->ace_type
= GPFS_ACL_GROUP
;
709 g_ace
->ace_who
= (gpfs_uid_t
)ace
->gid
;
711 case SMB_ACL_GROUP_OBJ
:
712 g_ace
->ace_type
= GPFS_ACL_GROUP_OBJ
;
716 g_ace
->ace_type
= GPFS_ACL_MASK
;
717 g_ace
->ace_perm
= 0x8f;
721 g_ace
->ace_type
= GPFS_ACL_OTHER
;
725 DEBUG(10, ("Got invalid ace_type: %d\n", ace
->a_type
));
731 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_READ
) ?
733 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_WRITE
) ?
735 g_ace
->ace_perm
|= (ace
->a_perm
& SMB_ACL_EXECUTE
) ?
736 ACL_PERM_EXECUTE
: 0;
738 DEBUGADD(10, ("Converted to %d id %d perm %x\n",
739 g_ace
->ace_type
, g_ace
->ace_who
, g_ace
->ace_perm
));
745 static int gpfsacl_sys_acl_set_file(vfs_handle_struct
*handle
,
750 struct gpfs_acl
*gpfs_acl
;
753 gpfs_acl
= smb2gpfs_acl(theacl
, type
);
754 if (gpfs_acl
== NULL
) {
758 result
= smbd_gpfs_putacl((char *)name
, GPFS_PUTACL_STRUCT
| GPFS_ACL_SAMBA
, gpfs_acl
);
764 static int gpfsacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
768 return gpfsacl_sys_acl_set_file(handle
, fsp
->fsp_name
->base_name
,
769 SMB_ACL_TYPE_ACCESS
, theacl
);
772 static int gpfsacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
780 * Assumed: mode bits are shiftable and standard
781 * Output: the new aceMask field for an smb nfs4 ace
783 static uint32
gpfsacl_mask_filter(uint32 aceType
, uint32 aceMask
, uint32 rwx
)
785 const uint32 posix_nfs4map
[3] = {
786 SMB_ACE4_EXECUTE
, /* execute */
787 SMB_ACE4_WRITE_DATA
| SMB_ACE4_APPEND_DATA
, /* write; GPFS specific */
788 SMB_ACE4_READ_DATA
/* read */
791 uint32_t posix_mask
= 0x01;
796 nfs4_bits
= posix_nfs4map
[i
];
797 posix_bit
= rwx
& posix_mask
;
799 if (aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
) {
801 aceMask
|= nfs4_bits
;
803 aceMask
&= ~nfs4_bits
;
805 /* add deny bits when suitable */
807 aceMask
|= nfs4_bits
;
809 aceMask
&= ~nfs4_bits
;
810 } /* other ace types are unexpected */
818 static int gpfsacl_emu_chmod(const char *path
, mode_t mode
)
820 SMB4ACL_T
*pacl
= NULL
;
822 bool haveAllowEntry
[SMB_ACE4_WHO_EVERYONE
+ 1] = {False
, False
, False
, False
};
824 files_struct fake_fsp
; /* TODO: rationalize parametrization */
828 DEBUG(10, ("gpfsacl_emu_chmod invoked for %s mode %o\n", path
, mode
));
830 result
= gpfs_get_nfs4_acl(path
, &pacl
);
834 if (mode
& ~(S_IRWXU
| S_IRWXG
| S_IRWXO
)) {
835 DEBUG(2, ("WARNING: cutting extra mode bits %o on %s\n", mode
, path
));
838 for (smbace
=smb_first_ace4(pacl
); smbace
!=NULL
; smbace
= smb_next_ace4(smbace
)) {
839 SMB_ACE4PROP_T
*ace
= smb_get_ace4(smbace
);
840 uint32_t specid
= ace
->who
.special_id
;
842 if (ace
->flags
&SMB_ACE4_ID_SPECIAL
&&
843 ace
->aceType
<=SMB_ACE4_ACCESS_DENIED_ACE_TYPE
&&
844 specid
<= SMB_ACE4_WHO_EVERYONE
) {
848 if (ace
->aceType
==SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
)
849 haveAllowEntry
[specid
] = True
;
851 /* mode >> 6 for @owner, mode >> 3 for @group,
852 * mode >> 0 for @everyone */
853 newMask
= gpfsacl_mask_filter(ace
->aceType
, ace
->aceMask
,
854 mode
>> ((SMB_ACE4_WHO_EVERYONE
- specid
) * 3));
855 if (ace
->aceMask
!=newMask
) {
856 DEBUG(10, ("ace changed for %s (%o -> %o) id=%d\n",
857 path
, ace
->aceMask
, newMask
, specid
));
859 ace
->aceMask
= newMask
;
863 /* make sure we have at least ALLOW entries
864 * for all the 3 special ids (@EVERYONE, @OWNER, @GROUP)
867 for(i
= SMB_ACE4_WHO_OWNER
; i
<=SMB_ACE4_WHO_EVERYONE
; i
++) {
870 if (haveAllowEntry
[i
]==True
)
874 ace
.aceType
= SMB_ACE4_ACCESS_ALLOWED_ACE_TYPE
;
875 ace
.flags
|= SMB_ACE4_ID_SPECIAL
;
876 ace
.who
.special_id
= i
;
878 if (i
==SMB_ACE4_WHO_GROUP
) /* not sure it's necessary... */
879 ace
.aceFlags
|= SMB_ACE4_IDENTIFIER_GROUP
;
881 ace
.aceMask
= gpfsacl_mask_filter(ace
.aceType
, ace
.aceMask
,
882 mode
>> ((SMB_ACE4_WHO_EVERYONE
- i
) * 3));
884 /* don't add unnecessary aces */
888 /* we add it to the END - as windows expects allow aces */
889 smb_add_ace4(pacl
, &ace
);
890 DEBUG(10, ("Added ALLOW ace for %s, mode=%o, id=%d, aceMask=%x\n",
891 path
, mode
, i
, ace
.aceMask
));
894 /* don't add complementary DENY ACEs here */
895 ZERO_STRUCT(fake_fsp
);
896 status
= create_synthetic_smb_fname(talloc_tos(), path
, NULL
, NULL
,
898 if (!NT_STATUS_IS_OK(status
)) {
899 errno
= map_errno_from_nt_status(status
);
903 if (gpfsacl_process_smbacl(&fake_fsp
, pacl
) == False
) {
904 TALLOC_FREE(fake_fsp
.fsp_name
);
908 TALLOC_FREE(fake_fsp
.fsp_name
);
909 return 0; /* ok for [f]chmod */
912 static int vfs_gpfs_chmod(vfs_handle_struct
*handle
, const char *path
, mode_t mode
)
914 struct smb_filename
*smb_fname_cpath
;
918 status
= create_synthetic_smb_fname(
919 talloc_tos(), path
, NULL
, NULL
, &smb_fname_cpath
);
921 if (SMB_VFS_NEXT_STAT(handle
, smb_fname_cpath
) != 0) {
925 /* avoid chmod() if possible, to preserve acls */
926 if ((smb_fname_cpath
->st
.st_ex_mode
& ~S_IFMT
) == mode
) {
930 rc
= gpfsacl_emu_chmod(path
, mode
);
932 return SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
936 static int vfs_gpfs_fchmod(vfs_handle_struct
*handle
, files_struct
*fsp
, mode_t mode
)
941 if (SMB_VFS_NEXT_FSTAT(handle
, fsp
, &st
) != 0) {
945 /* avoid chmod() if possible, to preserve acls */
946 if ((st
.st_ex_mode
& ~S_IFMT
) == mode
) {
950 rc
= gpfsacl_emu_chmod(fsp
->fsp_name
->base_name
, mode
);
952 return SMB_VFS_NEXT_FCHMOD(handle
, fsp
, mode
);
956 static int gpfs_set_xattr(struct vfs_handle_struct
*handle
, const char *path
,
957 const char *name
, const void *value
, size_t size
, int flags
){
958 struct xattr_DOSATTRIB dosattrib
;
959 enum ndr_err_code ndr_err
;
961 const char *attrstr
= value
;
962 unsigned int dosmode
=0;
963 struct gpfs_winattr attrs
;
965 struct gpfs_config_data
*config
;
967 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
968 struct gpfs_config_data
,
971 if (!config
->winattr
) {
972 DEBUG(10, ("gpfs_set_xattr:name is %s -> next\n",name
));
973 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
976 DEBUG(10, ("gpfs_set_xattr: %s \n",path
));
978 /* Only handle DOS Attributes */
979 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
980 DEBUG(5, ("gpfs_set_xattr:name is %s\n",name
));
981 return SMB_VFS_NEXT_SETXATTR(handle
,path
,name
,value
,size
,flags
);
984 blob
.data
= (uint8_t *)attrstr
;
987 ndr_err
= ndr_pull_struct_blob(&blob
, talloc_tos(), &dosattrib
,
988 (ndr_pull_flags_fn_t
)ndr_pull_xattr_DOSATTRIB
);
990 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
991 DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
992 "from EA on file %s: Error = %s\n",
993 path
, ndr_errstr(ndr_err
)));
997 if (dosattrib
.version
!= 3) {
998 DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
999 "%d\n", (int)dosattrib
.version
));
1002 if (!(dosattrib
.info
.info3
.valid_flags
& XATTR_DOSINFO_ATTRIB
)) {
1003 DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
1004 "valid, ignoring\n"));
1008 dosmode
= dosattrib
.info
.info3
.attrib
;
1011 /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
1012 if (dosmode
& FILE_ATTRIBUTE_ARCHIVE
){
1013 attrs
.winAttrs
|= GPFS_WINATTR_ARCHIVE
;
1015 if (dosmode
& FILE_ATTRIBUTE_HIDDEN
){
1016 attrs
.winAttrs
|= GPFS_WINATTR_HIDDEN
;
1018 if (dosmode
& FILE_ATTRIBUTE_SYSTEM
){
1019 attrs
.winAttrs
|= GPFS_WINATTR_SYSTEM
;
1021 if (dosmode
& FILE_ATTRIBUTE_READONLY
){
1022 attrs
.winAttrs
|= GPFS_WINATTR_READONLY
;
1024 if (dosmode
& FILE_ATTRIBUTE_SPARSE
) {
1025 attrs
.winAttrs
|= GPFS_WINATTR_SPARSE_FILE
;
1029 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1030 GPFS_WINATTR_SET_ATTRS
, &attrs
);
1032 if (errno
== ENOSYS
) {
1033 return SMB_VFS_NEXT_SETXATTR(handle
, path
, name
, value
,
1037 DEBUG(1, ("gpfs_set_xattr:Set GPFS attributes failed %d\n",ret
));
1041 DEBUG(10, ("gpfs_set_xattr:Set attributes: 0x%x\n",attrs
.winAttrs
));
1045 static ssize_t
gpfs_get_xattr(struct vfs_handle_struct
*handle
, const char *path
,
1046 const char *name
, void *value
, size_t size
){
1047 char *attrstr
= value
;
1048 unsigned int dosmode
= 0;
1049 struct gpfs_winattr attrs
;
1051 struct gpfs_config_data
*config
;
1053 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1054 struct gpfs_config_data
,
1057 if (!config
->winattr
) {
1058 DEBUG(10, ("gpfs_get_xattr:name is %s -> next\n",name
));
1059 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1062 DEBUG(10, ("gpfs_get_xattr: %s \n",path
));
1064 /* Only handle DOS Attributes */
1065 if (strcmp(name
,SAMBA_XATTR_DOS_ATTRIB
) != 0){
1066 DEBUG(5, ("gpfs_get_xattr:name is %s\n",name
));
1067 return SMB_VFS_NEXT_GETXATTR(handle
,path
,name
,value
,size
);
1070 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1072 if (errno
== ENOSYS
) {
1073 return SMB_VFS_NEXT_GETXATTR(handle
, path
, name
, value
,
1077 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
1078 "%d (%s)\n", ret
, strerror(errno
)));
1082 DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs
.winAttrs
));
1084 /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
1085 if (attrs
.winAttrs
& GPFS_WINATTR_ARCHIVE
){
1086 dosmode
|= FILE_ATTRIBUTE_ARCHIVE
;
1088 if (attrs
.winAttrs
& GPFS_WINATTR_HIDDEN
){
1089 dosmode
|= FILE_ATTRIBUTE_HIDDEN
;
1091 if (attrs
.winAttrs
& GPFS_WINATTR_SYSTEM
){
1092 dosmode
|= FILE_ATTRIBUTE_SYSTEM
;
1094 if (attrs
.winAttrs
& GPFS_WINATTR_READONLY
){
1095 dosmode
|= FILE_ATTRIBUTE_READONLY
;
1097 if (attrs
.winAttrs
& GPFS_WINATTR_SPARSE_FILE
) {
1098 dosmode
|= FILE_ATTRIBUTE_SPARSE
;
1101 snprintf(attrstr
, size
, "0x%2.2x",
1102 (unsigned int)(dosmode
& SAMBA_ATTRIBUTES_MASK
));
1103 DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr
));
1107 static int vfs_gpfs_stat(struct vfs_handle_struct
*handle
,
1108 struct smb_filename
*smb_fname
)
1110 struct gpfs_winattr attrs
;
1114 struct gpfs_config_data
*config
;
1116 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1117 struct gpfs_config_data
,
1120 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
1125 if (!config
->winattr
) {
1129 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &fname
);
1130 if (!NT_STATUS_IS_OK(status
)) {
1131 errno
= map_errno_from_nt_status(status
);
1134 ret
= get_gpfs_winattrs(discard_const_p(char, fname
), &attrs
);
1137 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1138 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1139 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1140 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1145 static int vfs_gpfs_fstat(struct vfs_handle_struct
*handle
,
1146 struct files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1148 struct gpfs_winattr attrs
;
1150 struct gpfs_config_data
*config
;
1152 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1153 struct gpfs_config_data
,
1156 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1160 if ((fsp
->fh
== NULL
) || (fsp
->fh
->fd
== -1)) {
1163 if (!config
->winattr
) {
1167 ret
= smbd_fget_gpfs_winattrs(fsp
->fh
->fd
, &attrs
);
1169 sbuf
->st_ex_calculated_birthtime
= false;
1170 sbuf
->st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1171 sbuf
->st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1176 static int vfs_gpfs_lstat(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_LSTAT(handle
, smb_fname
);
1193 if (!config
->winattr
) {
1197 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1198 if (!NT_STATUS_IS_OK(status
)) {
1199 errno
= map_errno_from_nt_status(status
);
1202 ret
= get_gpfs_winattrs(discard_const_p(char, path
), &attrs
);
1205 smb_fname
->st
.st_ex_calculated_birthtime
= false;
1206 smb_fname
->st
.st_ex_btime
.tv_sec
= attrs
.creationTime
.tv_sec
;
1207 smb_fname
->st
.st_ex_btime
.tv_nsec
= attrs
.creationTime
.tv_nsec
;
1208 smb_fname
->st
.vfs_private
= attrs
.winAttrs
;
1213 static int vfs_gpfs_ntimes(struct vfs_handle_struct
*handle
,
1214 const struct smb_filename
*smb_fname
,
1215 struct smb_file_time
*ft
)
1218 struct gpfs_winattr attrs
;
1222 struct gpfs_config_data
*config
;
1224 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1225 struct gpfs_config_data
,
1228 ret
= SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1230 /* don't complain if access was denied */
1231 if (errno
!= EPERM
&& errno
!= EACCES
) {
1232 DEBUG(1,("vfs_gpfs_ntimes: SMB_VFS_NEXT_NTIMES failed:"
1233 "%s", strerror(errno
)));
1238 if(null_timespec(ft
->create_time
)){
1239 DEBUG(10,("vfs_gpfs_ntimes:Create Time is NULL\n"));
1243 if (!config
->winattr
) {
1247 status
= get_full_smb_filename(talloc_tos(), smb_fname
, &path
);
1248 if (!NT_STATUS_IS_OK(status
)) {
1249 errno
= map_errno_from_nt_status(status
);
1254 attrs
.creationTime
.tv_sec
= ft
->create_time
.tv_sec
;
1255 attrs
.creationTime
.tv_nsec
= ft
->create_time
.tv_nsec
;
1257 ret
= set_gpfs_winattrs(discard_const_p(char, path
),
1258 GPFS_WINATTR_SET_CREATION_TIME
, &attrs
);
1259 if(ret
== -1 && errno
!= ENOSYS
){
1260 DEBUG(1,("vfs_gpfs_ntimes: set GPFS ntimes failed %d\n",ret
));
1267 int vfs_gpfs_fallocate(struct vfs_handle_struct
*handle
,
1268 struct files_struct
*fsp
, enum vfs_fallocate_mode mode
,
1269 SMB_OFF_T offset
, SMB_OFF_T len
)
1272 struct gpfs_config_data
*config
;
1274 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1275 struct gpfs_config_data
,
1278 if (!config
->prealloc
) {
1279 /* you should better not run fallocate() on GPFS at all */
1284 if (mode
== VFS_FALLOCATE_KEEP_SIZE
) {
1285 DEBUG(10, ("Unsupported VFS_FALLOCATE_KEEP_SIZE\n"));
1290 ret
= smbd_gpfs_prealloc(fsp
->fh
->fd
, offset
, len
);
1292 if (ret
== -1 && errno
!= ENOSYS
) {
1293 DEBUG(0, ("GPFS prealloc failed: %s\n", strerror(errno
)));
1294 } else if (ret
== -1 && errno
== ENOSYS
) {
1295 DEBUG(10, ("GPFS prealloc not supported.\n"));
1297 DEBUG(10, ("GPFS prealloc succeeded.\n"));
1303 static int vfs_gpfs_ftruncate(vfs_handle_struct
*handle
, files_struct
*fsp
,
1307 struct gpfs_config_data
*config
;
1309 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1310 struct gpfs_config_data
,
1313 if (!config
->ftruncate
) {
1314 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1317 result
= smbd_gpfs_ftruncate(fsp
->fh
->fd
, len
);
1318 if ((result
== -1) && (errno
== ENOSYS
)) {
1319 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, len
);
1324 static bool vfs_gpfs_is_offline(struct vfs_handle_struct
*handle
,
1325 const struct smb_filename
*fname
,
1326 SMB_STRUCT_STAT
*sbuf
)
1328 struct gpfs_winattr attrs
;
1331 struct gpfs_config_data
*config
;
1333 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1334 struct gpfs_config_data
,
1337 if (!config
->winattr
) {
1338 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1341 status
= get_full_smb_filename(talloc_tos(), fname
, &path
);
1342 if (!NT_STATUS_IS_OK(status
)) {
1343 errno
= map_errno_from_nt_status(status
);
1347 if (VALID_STAT(*sbuf
)) {
1348 attrs
.winAttrs
= sbuf
->vfs_private
;
1351 ret
= get_gpfs_winattrs(path
, &attrs
);
1358 if ((attrs
.winAttrs
& GPFS_WINATTR_OFFLINE
) != 0) {
1359 DEBUG(10, ("%s is offline\n", path
));
1363 DEBUG(10, ("%s is online\n", path
));
1365 return SMB_VFS_NEXT_IS_OFFLINE(handle
, fname
, sbuf
);
1368 static bool vfs_gpfs_aio_force(struct vfs_handle_struct
*handle
,
1369 struct files_struct
*fsp
)
1371 return vfs_gpfs_is_offline(handle
, fsp
->fsp_name
, &fsp
->fsp_name
->st
);
1374 static ssize_t
vfs_gpfs_sendfile(vfs_handle_struct
*handle
, int tofd
,
1375 files_struct
*fsp
, const DATA_BLOB
*hdr
,
1376 SMB_OFF_T offset
, size_t n
)
1378 if ((fsp
->fsp_name
->st
.vfs_private
& GPFS_WINATTR_OFFLINE
) != 0) {
1382 return SMB_VFS_NEXT_SENDFILE(handle
, tofd
, fsp
, hdr
, offset
, n
);
1385 int vfs_gpfs_connect(struct vfs_handle_struct
*handle
, const char *service
,
1388 struct gpfs_config_data
*config
;
1391 smbd_gpfs_lib_init();
1393 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1399 config
= talloc_zero(handle
->conn
, struct gpfs_config_data
);
1401 SMB_VFS_NEXT_DISCONNECT(handle
);
1402 DEBUG(0, ("talloc_zero() failed\n"));
1406 config
->sharemodes
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1407 "sharemodes", true);
1409 config
->leases
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1412 config
->hsm
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1415 config
->syncio
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1418 config
->winattr
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1421 config
->ftruncate
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1424 config
->getrealfilename
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1425 "getrealfilename", true);
1427 config
->dfreequota
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1428 "dfreequota", false);
1430 config
->prealloc
= lp_parm_bool(SNUM(handle
->conn
), "gpfs",
1433 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1434 NULL
, struct gpfs_config_data
,
1440 static int vfs_gpfs_get_quotas(const char *path
, uid_t uid
, gid_t gid
,
1442 struct gpfs_quotaInfo
*qi_user
,
1443 struct gpfs_quotaInfo
*qi_group
,
1444 struct gpfs_quotaInfo
*qi_fset
)
1448 err
= get_gpfs_fset_id(path
, fset_id
);
1450 DEBUG(0, ("Get fset id failed, errno %d.\n", errno
));
1454 err
= get_gpfs_quota(path
, GPFS_USRQUOTA
, uid
, qi_user
);
1459 err
= get_gpfs_quota(path
, GPFS_GRPQUOTA
, gid
, qi_group
);
1464 err
= get_gpfs_quota(path
, GPFS_FILESETQUOTA
, *fset_id
, qi_fset
);
1472 static void vfs_gpfs_disk_free_quota(struct gpfs_quotaInfo qi
, time_t cur_time
,
1473 uint64_t *dfree
, uint64_t *dsize
)
1475 uint64_t usage
, limit
;
1478 * The quota reporting is done in units of 1024 byte blocks, but
1479 * sys_fsusage uses units of 512 byte blocks, adjust the block number
1480 * accordingly. Also filter possibly negative usage counts from gpfs.
1482 usage
= qi
.blockUsage
< 0 ? 0 : (uint64_t)qi
.blockUsage
* 2;
1483 limit
= (uint64_t)qi
.blockHardLimit
* 2;
1486 * When the grace time for the exceeded soft block quota has been
1487 * exceeded, the soft block quota becomes an additional hard limit.
1489 if (qi
.blockGraceTime
&& cur_time
> qi
.blockGraceTime
) {
1490 /* report disk as full */
1492 *dsize
= MIN(*dsize
, usage
);
1495 if (!qi
.blockHardLimit
)
1498 if (usage
>= limit
) {
1499 /* report disk as full */
1501 *dsize
= MIN(*dsize
, usage
);
1504 /* limit has not been reached, determine "free space" */
1505 *dfree
= MIN(*dfree
, limit
- usage
);
1506 *dsize
= MIN(*dsize
, limit
);
1510 static uint64_t vfs_gpfs_disk_free(vfs_handle_struct
*handle
, const char *path
,
1511 bool small_query
, uint64_t *bsize
,
1512 uint64_t *dfree
, uint64_t *dsize
)
1514 struct security_unix_token
*utok
;
1515 struct gpfs_quotaInfo qi_user
, qi_group
, qi_fset
;
1516 struct gpfs_config_data
*config
;
1520 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct gpfs_config_data
,
1521 return (uint64_t)-1);
1522 if (!config
->dfreequota
) {
1523 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1524 bsize
, dfree
, dsize
);
1527 err
= sys_fsusage(path
, dfree
, dsize
);
1529 DEBUG (0, ("Could not get fs usage, errno %d\n", errno
));
1530 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1531 bsize
, dfree
, dsize
);
1534 /* sys_fsusage returns units of 512 bytes */
1537 DEBUG(10, ("fs dfree %llu, dsize %llu\n",
1538 (unsigned long long)*dfree
, (unsigned long long)*dsize
));
1540 utok
= handle
->conn
->session_info
->unix_token
;
1541 err
= vfs_gpfs_get_quotas(path
, utok
->uid
, utok
->gid
, &fset_id
,
1542 &qi_user
, &qi_group
, &qi_fset
);
1544 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1545 bsize
, dfree
, dsize
);
1548 cur_time
= time(NULL
);
1550 /* Adjust free space and size according to quota limits. */
1551 vfs_gpfs_disk_free_quota(qi_user
, cur_time
, dfree
, dsize
);
1552 vfs_gpfs_disk_free_quota(qi_group
, cur_time
, dfree
, dsize
);
1554 /* Id 0 indicates the default quota, not an actual quota */
1556 vfs_gpfs_disk_free_quota(qi_fset
, cur_time
, dfree
, dsize
);
1559 disk_norm(small_query
, bsize
, dfree
, dsize
);
1563 static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct
*handle
,
1564 enum timestamp_set_resolution
*p_ts_res
)
1566 struct gpfs_config_data
*config
;
1569 next
= SMB_VFS_NEXT_FS_CAPABILITIES(handle
, p_ts_res
);
1571 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1572 struct gpfs_config_data
,
1576 next
|= FILE_SUPPORTS_REMOTE_STORAGE
;
1581 static int vfs_gpfs_open(struct vfs_handle_struct
*handle
,
1582 struct smb_filename
*smb_fname
, files_struct
*fsp
,
1583 int flags
, mode_t mode
)
1585 struct gpfs_config_data
*config
;
1587 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1588 struct gpfs_config_data
,
1591 if (config
->syncio
) {
1594 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
1598 static struct vfs_fn_pointers vfs_gpfs_fns
= {
1599 .connect_fn
= vfs_gpfs_connect
,
1600 .disk_free_fn
= vfs_gpfs_disk_free
,
1601 .fs_capabilities_fn
= vfs_gpfs_capabilities
,
1602 .kernel_flock_fn
= vfs_gpfs_kernel_flock
,
1603 .linux_setlease_fn
= vfs_gpfs_setlease
,
1604 .get_real_filename_fn
= vfs_gpfs_get_real_filename
,
1605 .fget_nt_acl_fn
= gpfsacl_fget_nt_acl
,
1606 .get_nt_acl_fn
= gpfsacl_get_nt_acl
,
1607 .fset_nt_acl_fn
= gpfsacl_fset_nt_acl
,
1608 .sys_acl_get_file_fn
= gpfsacl_sys_acl_get_file
,
1609 .sys_acl_get_fd_fn
= gpfsacl_sys_acl_get_fd
,
1610 .sys_acl_set_file_fn
= gpfsacl_sys_acl_set_file
,
1611 .sys_acl_set_fd_fn
= gpfsacl_sys_acl_set_fd
,
1612 .sys_acl_delete_def_file_fn
= gpfsacl_sys_acl_delete_def_file
,
1613 .chmod_fn
= vfs_gpfs_chmod
,
1614 .fchmod_fn
= vfs_gpfs_fchmod
,
1615 .close_fn
= vfs_gpfs_close
,
1616 .setxattr_fn
= gpfs_set_xattr
,
1617 .getxattr_fn
= gpfs_get_xattr
,
1618 .stat_fn
= vfs_gpfs_stat
,
1619 .fstat_fn
= vfs_gpfs_fstat
,
1620 .lstat_fn
= vfs_gpfs_lstat
,
1621 .ntimes_fn
= vfs_gpfs_ntimes
,
1622 .is_offline_fn
= vfs_gpfs_is_offline
,
1623 .aio_force_fn
= vfs_gpfs_aio_force
,
1624 .sendfile_fn
= vfs_gpfs_sendfile
,
1625 .fallocate_fn
= vfs_gpfs_fallocate
,
1626 .open_fn
= vfs_gpfs_open
,
1627 .ftruncate_fn
= vfs_gpfs_ftruncate
1630 NTSTATUS
vfs_gpfs_init(void);
1631 NTSTATUS
vfs_gpfs_init(void)
1635 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "gpfs",