smb_rename.c revision b89a8333f5e1f75ec0c269b22524bd2eccb972ba
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego#pragma ident "@(#)smb_rename.c 1.6 08/08/04 SMI"
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United Statesstatic int smb_do_rename(smb_request_t *, smb_fqi_t *, smb_fqi_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_com_rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Rename a file. Files OldFileName must exist and NewFileName must not.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Both pathnames must be relative to the Tid specified in the request.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Open files may be renamed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Multiple files may be renamed in response to a single request as Rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * File supports wildcards in the file name (last component of the path).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * NOTE: we don't support rename with wildcards.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * SearchAttributes indicates the attributes that the target file(s) must
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * have. If SearchAttributes is zero then only normal files are renamed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If the system file or hidden attributes are specified then the rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is inclusive - both the specified type(s) of files and normal files are
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * renamed. The encoding of SearchAttributes is described in section 3.10
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * - File Attribute Encoding.
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_fqi_t *src_fqi = &sr->arg.dirop.fqi;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_fqi_t *dst_fqi = &sr->arg.dirop.dst_fqi;
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb if ((rc = smbsr_decode_vwv(sr, "w", &src_fqi->srch_attr)) == 0) {
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_fqi_t *src_fqi = &sr->arg.dirop.fqi;
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_fqi_t *dst_fqi = &sr->arg.dirop.dst_fqi;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * The following values are based on observed WFWG,
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Windows 9x, NT and Windows 2000 behaviour.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * ERROR_FILE_EXISTS doesn't work for Windows 98 clients.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * Windows 95 clients don't see the problem because the
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb * target is deleted before the rename request.
faa1795a28a5c712eed6d0a3f84d98c368a316c6jb switch (rc) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_do_rename
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Backend to smb_com_rename to ensure that the rename operation is atomic.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function should be called within a mutual exclusion region. If the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * source and destination are identical, we don't actually do a rename, we
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * just check that the conditions are right. If the source and destination
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * files differ only in case, we a case-sensitive rename. Otherwise, we do
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a full case-insensitive rename.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This function should always return errno values.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Upon success, the last_snode's and dir_snode's of both src_fqi and dst_fqi
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * are not released in this routine but in smb_com_rename().
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_fqi_t *src_fqi,
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_fqi_t *dst_fqi)
b89a8333f5e1f75ec0c269b22524bd2eccb972banatalie li - Sun Microsystems - Irvine United States smb_node_t *src_node;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((rc = smbd_fs_query(sr, src_fqi, FQM_PATH_MUST_EXIST)) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Break the oplock before access checks. If a client
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * has a file open, this will force a flush or close,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * which may affect the outcome of any share checking.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego status = smb_range_check(sr, src_node, 0, UINT64_MAX, B_TRUE);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (utf8_strcasecmp(src_fqi->path, dst_fqi->path) == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Because the fqm parameter to smbd_fs_query() was 0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * a successful return value means that dst_fqi->last_snode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * may be NULL.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc == 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return (0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rc = smbd_fs_query(sr, dst_fqi, FQM_PATH_MUST_NOT_EXIST);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Because of FQM_PATH_MUST_NOT_EXIST and the successful return
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * value, only dst_fqi->dir_snode is valid (dst_fqi->last_snode
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * is NULL).
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use the unmangled form of the destination name if the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * source and destination names are the same and the source
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * name is mangled. (We are taking a chance here, assuming
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * that this is what the user wants.)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (strcmp(src_fqi->last_comp, dst_fqi->last_comp) == 0)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rc != 0) {