Lines Matching defs:of

4  * The contents of this file are subject to the terms of the
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
17 * information: Portions Copyright [yyyy] [name of copyright owner]
31 * This is a simplified diagram showing the relationship between most of the
93 * - The ofile is queued in the list of ofiles of its tree.
99 * - The ofile is queued in the list of ofiles of its tree.
107 * - The ofile is queued in the list of ofiles of its tree.
114 * added to the list of ofiles of a tree.
130 * The state machine of the ofile structures is controlled by 3 elements:
131 * - The list of ofiles of the tree it belongs to.
136 * and there's a lock embedded in the list of ofiles of a tree. To
138 * To insert the ofile into the list of ofiles of the tree and to remove
141 * Rules of access to a ofile structure:
143 * 1) In order to avoid deadlocks, when both (mutex and lock of the ofile
148 * 3) There are 2 ways of getting a reference count. One is when the ofile
152 * It should be noted that the reference count of an ofile registers the
153 * number of references to the ofile in other structures (such as an smb
158 * of that ofile is zero.
160 * 2) The ofile is queued in the list of ofiles of its tree. The fact of
187 smb_ofile_t *of;
202 of = kmem_cache_alloc(smb_cache_ofile, KM_SLEEP);
203 bzero(of, sizeof (smb_ofile_t));
204 of->f_magic = SMB_OFILE_MAGIC;
205 of->f_refcnt = 1;
206 of->f_fid = fid;
207 of->f_uniqid = uniqid;
208 of->f_opened_by_pid = sr->smb_pid;
209 of->f_granted_access = op->desired_access;
210 of->f_share_access = op->share_access;
211 of->f_create_options = op->create_options;
212 of->f_cr = (op->create_options & FILE_OPEN_FOR_BACKUP_INTENT) ?
214 crhold(of->f_cr);
216 of->f_ftype = ftype;
217 of->f_server = tree->t_server;
218 of->f_session = tree->t_session;
220 * grab a ref for of->f_user
224 of->f_user = sr->uid_user;
225 of->f_tree = tree;
226 of->f_node = node;
228 mutex_init(&of->f_mutex, NULL, MUTEX_DEFAULT, NULL);
230 of->f_state = SMB_OFILE_STATE_OPEN;
234 of->f_pipe = op->pipe;
235 smb_server_inc_pipes(of->f_server);
245 if ((of->f_granted_access & FILE_DATA_ALL) == FILE_EXECUTE)
246 of->f_flags |= SMB_OFLAGS_EXECONLY;
250 rc = smb_node_getattr(NULL, node, of->f_cr, NULL, &attr);
257 if (crgetuid(of->f_cr) == attr.sa_vattr.va_uid) {
262 of->f_granted_access |= FILE_READ_ATTRIBUTES;
266 of->f_mode =
267 smb_fsop_amask_to_omode(of->f_granted_access);
268 if (smb_fsop_open(node, of->f_mode, of->f_cr) != 0) {
277 of->f_flags |= SMB_OFLAGS_READONLY;
286 of->f_flags |= SMB_OFLAGS_READONLY;
289 smb_node_add_ofile(node, of);
291 smb_server_inc_files(of->f_server);
294 smb_llist_insert_tail(&tree->t_ofile_list, of);
297 atomic_inc_32(&of->f_session->s_file_cnt);
298 return (of);
303 mutex_destroy(&of->f_mutex);
304 smb_user_release(of->f_user);
307 crfree(of->f_cr);
308 of->f_magic = 0;
309 kmem_cache_free(smb_cache_ofile, of);
324 smb_ofile_close(smb_ofile_t *of, int32_t mtime_sec)
330 SMB_OFILE_VALID(of);
332 mutex_enter(&of->f_mutex);
333 ASSERT(of->f_refcnt);
334 if (of->f_state != SMB_OFILE_STATE_OPEN) {
335 mutex_exit(&of->f_mutex);
338 of->f_state = SMB_OFILE_STATE_CLOSING;
339 mutex_exit(&of->f_mutex);
341 switch (of->f_ftype) {
344 smb_opipe_close(of);
345 smb_server_dec_pipes(of->f_server);
351 * In here we make changes to of->f_pending_attr
352 * while not holding of->f_mutex. This is OK
356 pa = &of->f_pending_attr;
369 if (of->f_written &&
376 if (of->f_flags & SMB_OFLAGS_SET_DELETE_ON_CLOSE) {
377 if (smb_tree_has_feature(of->f_tree,
381 (void) smb_node_set_delete_on_close(of->f_node,
382 of->f_cr, flags);
384 smb_fsop_unshrlock(of->f_cr, of->f_node, of->f_uniqid);
385 smb_node_destroy_lock_by_ofile(of->f_node, of);
387 if (smb_node_is_file(of->f_node)) {
388 (void) smb_fsop_close(of->f_node, of->f_mode,
389 of->f_cr);
390 smb_oplock_release(of->f_node, of);
395 if (of->f_odir != NULL)
396 smb_odir_close(of->f_odir);
398 if (smb_node_dec_open_ofiles(of->f_node) == 0) {
406 of->f_node->n_pending_dosattr;
410 of->f_node->n_allocsz = 0;
423 (void) smb_node_setattr(NULL, of->f_node,
424 of->f_cr, NULL, pa);
431 if (of->f_node->n_fcn.fcn_count)
432 smb_notify_file_closed(of);
434 smb_server_dec_files(of->f_server);
437 atomic_dec_32(&of->f_tree->t_open_files);
439 mutex_enter(&of->f_mutex);
440 ASSERT(of->f_refcnt);
441 ASSERT(of->f_state == SMB_OFILE_STATE_CLOSING);
442 of->f_state = SMB_OFILE_STATE_CLOSED;
443 mutex_exit(&of->f_mutex);
455 smb_ofile_t *of;
461 of = smb_llist_head(&tree->t_ofile_list);
462 while (of) {
463 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
464 ASSERT(of->f_tree == tree);
465 of = smb_ofile_close_and_next(of);
480 smb_ofile_t *of;
486 of = smb_llist_head(&tree->t_ofile_list);
487 while (of) {
488 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
489 ASSERT(of->f_tree == tree);
490 if (of->f_opened_by_pid == pid) {
491 of = smb_ofile_close_and_next(of);
493 of = smb_llist_next(&tree->t_ofile_list, of);
506 smb_ofile_enum(smb_ofile_t *of, smb_svcenum_t *svcenum)
512 ASSERT(of);
513 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
514 ASSERT(of->f_refcnt);
531 rc = smb_ofile_netinfo_encode(of, pb, svcenum->se_bavail,
546 smb_ofile_hold(smb_ofile_t *of)
548 ASSERT(of);
549 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
551 mutex_enter(&of->f_mutex);
553 if (of->f_state != SMB_OFILE_STATE_OPEN) {
554 mutex_exit(&of->f_mutex);
557 of->f_refcnt++;
559 mutex_exit(&of->f_mutex);
570 smb_ofile_release(smb_ofile_t *of)
572 SMB_OFILE_VALID(of);
574 mutex_enter(&of->f_mutex);
575 ASSERT(of->f_refcnt);
576 of->f_refcnt--;
577 switch (of->f_state) {
583 if (of->f_refcnt == 0)
584 smb_tree_post_ofile(of->f_tree, of);
591 mutex_exit(&of->f_mutex);
607 smb_ofile_request_complete(smb_ofile_t *of)
609 SMB_OFILE_VALID(of);
611 switch (of->f_ftype) {
613 ASSERT(of->f_node);
614 smb_oplock_broadcast(of->f_node);
637 smb_ofile_t *of;
644 of = smb_llist_head(of_list);
645 while (of) {
646 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
647 ASSERT(of->f_tree == tree);
648 if (of->f_fid == fid)
650 of = smb_llist_next(of_list, of);
652 if (of == NULL)
656 * Only allow use of a given FID with the same UID that
659 if (of->f_user != sr->uid_user) {
660 of = NULL;
664 mutex_enter(&of->f_mutex);
665 if (of->f_state != SMB_OFILE_STATE_OPEN) {
666 mutex_exit(&of->f_mutex);
667 of = NULL;
670 of->f_refcnt++;
671 mutex_exit(&of->f_mutex);
675 return (of);
687 smb_ofile_t *of;
693 of = smb_llist_head(of_list);
695 while (of) {
696 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
697 ASSERT(of->f_tree == tree);
699 if (of->f_uniqid == uniqid) {
700 if (smb_ofile_hold(of)) {
702 return (of);
706 of = smb_llist_next(of_list, of);
720 smb_ofile_disallow_fclose(smb_ofile_t *of)
722 ASSERT(of);
723 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
724 ASSERT(of->f_refcnt);
726 switch (of->f_ftype) {
728 ASSERT(of->f_tree);
729 return (of->f_node == of->f_tree->t_snode);
732 ASSERT(of->f_pipe);
733 if (smb_strcasecmp(of->f_pipe->p_name, "SRVSVC", 0) == 0)
753 smb_ofile_t *of,
756 ASSERT(of);
757 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
758 ASSERT(of->f_refcnt);
760 mutex_enter(&of->f_mutex);
761 of->f_flags |= flags;
762 mutex_exit(&of->f_mutex);
777 smb_ofile_t *of,
786 ASSERT(of);
787 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
788 ASSERT(of->f_refcnt);
790 mutex_enter(&of->f_mutex);
800 if (off < 0 && (-off) > of->f_seek_pos)
803 newoff = of->f_seek_pos + (u_offset_t)off;
809 rc = smb_fsop_getattr(NULL, zone_kcred(), of->f_node, &attr);
811 mutex_exit(&of->f_mutex);
821 mutex_exit(&of->f_mutex);
826 * See comments at the beginning of smb_seek.c.
833 of->f_seek_pos = newoff;
836 mutex_exit(&of->f_mutex);
849 smb_ofile_flush(struct smb_request *sr, struct smb_ofile *of)
851 switch (of->f_ftype) {
853 if ((of->f_node->flags & NODE_FLAGS_WRITE_THROUGH) == 0)
854 (void) smb_fsop_commit(sr, of->f_cr, of->f_node);
865 smb_ofile_is_open(smb_ofile_t *of)
869 SMB_OFILE_VALID(of);
871 mutex_enter(&of->f_mutex);
872 rc = smb_ofile_is_open_locked(of);
873 mutex_exit(&of->f_mutex);
884 smb_ofile_is_open_locked(smb_ofile_t *of)
886 switch (of->f_state) {
902 * next open file in the list of open files of the tree of the open file passed
903 * in. It requires that the list of open files of the tree be entered in
907 smb_ofile_close_and_next(smb_ofile_t *of)
912 ASSERT(of);
913 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
915 mutex_enter(&of->f_mutex);
916 switch (of->f_state) {
919 of->f_refcnt++;
920 ASSERT(of->f_refcnt);
921 tree = of->f_tree;
922 mutex_exit(&of->f_mutex);
923 smb_llist_exit(&of->f_tree->t_ofile_list);
924 smb_ofile_close(of, 0);
925 smb_ofile_release(of);
935 mutex_exit(&of->f_mutex);
936 next_of = smb_llist_next(&of->f_tree->t_ofile_list, of);
940 mutex_exit(&of->f_mutex);
941 next_of = smb_llist_next(&of->f_tree->t_ofile_list, of);
957 smb_ofile_t *of = (smb_ofile_t *)arg;
959 SMB_OFILE_VALID(of);
960 ASSERT(of->f_refcnt == 0);
961 ASSERT(of->f_state == SMB_OFILE_STATE_CLOSED);
962 ASSERT(!SMB_OFILE_OPLOCK_GRANTED(of));
964 tree = of->f_tree;
966 smb_llist_remove(&tree->t_ofile_list, of);
967 smb_idpool_free(&tree->t_fid_pool, of->f_fid);
971 mutex_enter(&of->f_mutex);
972 mutex_exit(&of->f_mutex);
974 switch (of->f_ftype) {
977 smb_opipe_dealloc(of->f_pipe);
978 of->f_pipe = NULL;
981 if (of->f_odir != NULL)
982 smb_odir_release(of->f_odir);
983 smb_node_rem_ofile(of->f_node, of);
984 smb_node_release(of->f_node);
991 of->f_magic = (uint32_t)~SMB_OFILE_MAGIC;
992 mutex_destroy(&of->f_mutex);
993 crfree(of->f_cr);
994 smb_user_release(of->f_user);
995 kmem_cache_free(smb_cache_ofile, of);
1005 smb_ofile_access(smb_ofile_t *of, cred_t *cr, uint32_t access)
1008 if ((of == NULL) || (cr == zone_kcred()))
1015 if (~(of->f_granted_access) & access) {
1016 if (!(of->f_granted_access & ACCESS_SYSTEM_SECURITY) &&
1034 smb_ofile_share_check(smb_ofile_t *of)
1036 return (!SMB_DENY_ALL(of->f_share_access));
1041 * against existing open instances of the same file
1047 smb_ofile_open_check(smb_ofile_t *of, uint32_t desired_access,
1050 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
1052 mutex_enter(&of->f_mutex);
1054 if (of->f_state != SMB_OFILE_STATE_OPEN) {
1055 mutex_exit(&of->f_mutex);
1060 if ((of->f_granted_access & FILE_DATA_ALL) == 0) {
1061 mutex_exit(&of->f_mutex);
1069 if (SMB_DENY_DELETE(share_access) && (of->f_granted_access & DELETE)) {
1070 mutex_exit(&of->f_mutex);
1075 (of->f_granted_access & (FILE_READ_DATA | FILE_EXECUTE))) {
1076 mutex_exit(&of->f_mutex);
1081 (of->f_granted_access & (FILE_WRITE_DATA | FILE_APPEND_DATA))) {
1082 mutex_exit(&of->f_mutex);
1087 if (SMB_DENY_DELETE(of->f_share_access) && (desired_access & DELETE)) {
1088 mutex_exit(&of->f_mutex);
1092 if (SMB_DENY_READ(of->f_share_access) &&
1094 mutex_exit(&of->f_mutex);
1098 if (SMB_DENY_WRITE(of->f_share_access) &&
1100 mutex_exit(&of->f_mutex);
1104 mutex_exit(&of->f_mutex);
1121 smb_ofile_rename_check(smb_ofile_t *of)
1123 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
1125 mutex_enter(&of->f_mutex);
1127 if (of->f_state != SMB_OFILE_STATE_OPEN) {
1128 mutex_exit(&of->f_mutex);
1132 if (of->f_granted_access &
1134 mutex_exit(&of->f_mutex);
1138 if ((of->f_share_access & FILE_SHARE_DELETE) == 0) {
1139 if (of->f_granted_access &
1141 mutex_exit(&of->f_mutex);
1146 mutex_exit(&of->f_mutex);
1169 smb_ofile_delete_check(smb_ofile_t *of)
1171 ASSERT(of->f_magic == SMB_OFILE_MAGIC);
1173 mutex_enter(&of->f_mutex);
1175 if (of->f_state != SMB_OFILE_STATE_OPEN) {
1176 mutex_exit(&of->f_mutex);
1180 if (of->f_granted_access &
1183 mutex_exit(&of->f_mutex);
1187 mutex_exit(&of->f_mutex);
1192 smb_ofile_getcred(smb_ofile_t *of)
1194 return (of->f_cr);
1205 * reject subsequent open requests for the file. Observation of Windows
1211 smb_ofile_set_delete_on_close(smb_ofile_t *of)
1213 mutex_enter(&of->f_mutex);
1214 of->f_flags |= SMB_OFLAGS_SET_DELETE_ON_CLOSE;
1215 mutex_exit(&of->f_mutex);
1223 smb_ofile_netinfo_encode(smb_ofile_t *of, uint8_t *buf, size_t buflen,
1229 rc = smb_ofile_netinfo_init(of, &fi);
1239 smb_ofile_netinfo_init(smb_ofile_t *of, smb_netfileinfo_t *fi)
1248 ASSERT(of);
1249 user = of->f_user;
1250 tree = of->f_tree;
1256 switch (of->f_ftype) {
1258 node = of->f_node;
1261 fi->fi_permissions = of->f_granted_access;
1262 fi->fi_numlocks = smb_lock_get_lock_count(node, of);
1278 ASSERT(of->f_pipe);
1284 of->f_pipe->p_name);
1292 fi->fi_fid = of->f_fid;
1293 fi->fi_uniqid = of->f_uniqid;
1320 * A query of user and group quotas may span multiple requests.
1323 * the SID of the last quota entry returned to the client.