Path: blob/main/tests/sys/cddl/zfs/bin/rename_dir.c
39537 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License (the "License").5* You may not use this file except in compliance with the License.6*7* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE8* or http://www.opensolaris.org/os/licensing.9* See the License for the specific language governing permissions10* and limitations under the License.11*12* When distributing Covered Code, include this CDDL HEADER in each13* file and include the License file at usr/src/OPENSOLARIS.LICENSE.14* If applicable, add the following below this CDDL HEADER, with the15* fields enclosed by brackets "[]" replaced with your own identifying16* information: Portions Copyright [yyyy] [name of copyright owner]17*18* CDDL HEADER END19*/2021/*22* Copyright 2007 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/252627/*28* Assertion:29* Create two directory trees in zfs filesystem, and rename30* directory across the directory structure. ZFS can handle31* the race situation.32*/3334/*35* Need to create the following directory structures before36* running this program:37*38* mkdir -p 1/2/3/4/5 a/b/c/d/e39*/404142#include <stdlib.h>43#include <unistd.h>44#include <stdio.h>45#include <string.h>4647int48main()49{50int i = 1;51char buf[256];52char *msg = "rename() fails to handle race situation\n";5354switch (fork()) {55case -1:56perror("fork");57exit(1);58break;59case 0:60while (i > 0) {61int c_count = 0;62if (rename("a/b/c", "1/2/3/c") == 0)63c_count++;64if (rename("1/2/3/c", "a/b/c") == 0)65c_count++;66if (c_count) {67(void) strlcat(buf, "c_count: %d,", 256);68(void) strlcat(buf, msg, 256);69(void) fprintf(stderr, buf, c_count);70}71}72break;73default: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) strlcat(buf, "p_count: %d,", 256);82(void) strlcat(buf, msg, 256);83(void) fprintf(stderr, buf, p_count);84}85}86break;87}88return (0);89}909192