Path: blob/main/sys/contrib/openzfs/tests/zfs-tests/cmd/rename_dir.c
48529 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122/*23* Copyright 2007 Sun Microsystems, Inc. All rights reserved.24* Use is subject to license terms.25*/2627/*28* Copyright (c) 2012 by Delphix. All rights reserved.29*/3031/*32* Assertion:33* Create two directory trees in zfs filesystem, and rename34* directory across the directory structure. ZFS can handle35* the race situation.36*/3738/*39* Need to create the following directory structures before40* running this program:41*42* mkdir -p 1/2/3/4/5 a/b/c/d/e43*/444546#include <stdlib.h>47#include <unistd.h>48#include <stdio.h>4950int51main(void)52{53int i = 1;5455switch (fork()) {56case -1:57perror("fork");58exit(1);59break;6061case 0:62while (i > 0) {63int c_count = 0;64if (rename("a/b/c", "1/2/3/c") == 0)65c_count++;66if (rename("1/2/3/c", "a/b/c") == 0)67c_count++;68if (c_count)69(void) fprintf(stderr, "c_count: %d", c_count);70}71_exit(0);7273default:74while (i > 0) {75int p_count = 0;76if (rename("1", "a/b/c/d/e/1") == 0)77p_count++;78if (rename("a/b/c/d/e/1", "1") == 0)79p_count++;80if (p_count)81(void) fprintf(stderr, "p_count: %d", p_count);82}83return (0);84}85}868788