smb_rename.c revision 8c10a8659ac31335ed870a1711c0182623f72fd6
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CDDL HEADER START
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Common Development and Distribution License (the "License").
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You may not use this file except in compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing permissions
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL HEADER in each
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below this CDDL HEADER, with the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * fields enclosed by brackets "[]" replaced with your own identifying
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * information: Portions Copyright [yyyy] [name of copyright owner]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * CDDL HEADER END
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Use is subject to license terms.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster#pragma ident "%Z%%M% %I% %E% SMI"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterstatic int smb_do_rename(smb_request_t *, struct smb_fqi *, struct smb_fqi *);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * smb_com_rename
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Rename a file. Files OldFileName must exist and NewFileName must not.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Both pathnames must be relative to the Tid specified in the request.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Open files may be renamed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Multiple files may be renamed in response to a single request as Rename
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * File supports wildcards in the file name (last component of the path).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * NOTE: we don't support rename with wildcards.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SearchAttributes indicates the attributes that the target file(s) must
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * have. If SearchAttributes is zero then only normal files are renamed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If the system file or hidden attributes are specified then the rename
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is inclusive - both the specified type(s) of files and normal files are
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * renamed. The encoding of SearchAttributes is described in section 3.10
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * - File Attribute Encoding.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster struct smb_fqi *dst_fqi = &sr->arg.dirop.dst_fqi;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((rc = smbsr_decode_vwv(sr, "w", &src_fqi->srch_attr)) == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster rc = smbsr_decode_data(sr, "%SS", sr, &src_fqi->path,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DTRACE_SMB_2(op__Rename__start, smb_request_t *, sr,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DTRACE_SMB_1(op__Rename__done, smb_request_t *, sr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster struct smb_fqi *dst_fqi = &sr->arg.dirop.dst_fqi;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The following values are based on observed WFWG,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Windows 9x, NT and Windows 2000 behaviour.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ERROR_FILE_EXISTS doesn't work for Windows 98 clients.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Windows 95 clients don't see the problem because the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * target is deleted before the rename request.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster smbsr_error(sr, NT_STATUS_OBJECT_NAME_COLLISION,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster smbsr_error(sr, NT_STATUS_OBJECT_NAME_NOT_FOUND,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dst_node->flags & NODE_FLAGS_NOTIFY_CHANGE) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster smb_process_node_notify_change_queue(dst_node);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return ((rc == 0) ? SDRC_SUCCESS : SDRC_ERROR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * smb_do_rename
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Backend to smb_com_rename to ensure that the rename operation is atomic.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This function should be called within a mutual exclusion region. If the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * source and destination are identical, we don't actually do a rename, we
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * just check that the conditions are right. If the source and destination
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * files differ only in case, we a case-sensitive rename. Otherwise, we do
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * a full case-insensitive rename.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This function should always return errno values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Upon success, the last_snode's and dir_snode's of both src_fqi and dst_fqi
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * are not released in this routine but in smb_com_rename().
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((rc = smbd_fs_query(sr, src_fqi, FQM_PATH_MUST_EXIST)) != 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Break the oplock before access checks. If a client
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * has a file open, this will force a flush or close,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * which may affect the outcome of any share checking.
B_TRUE);
return (EACCES);
return (rc);
if (rc == 0) {
if (rc != 0) {
return (rc);
if (rc != 0) {
return (rc);
dstname);
if (rc != 0) {
return (rc);