1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * 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.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "@(#)rename_dir.c 1.1 07/05/25 SMI" 28 29 /* 30 * Assertion: 31 * Create two directory trees in zfs filesystem, and rename 32 * directory across the directory structure. ZFS can handle 33 * the race situation. 34 */ 35 36 /* 37 * Need to create the following directory structures before 38 * running this program: 39 * 40 * mkdir -p 1/2/3/4/5 a/b/c/d/e 41 */ 42 43 44 #include <stdlib.h> 45 #include <unistd.h> 46 #include <stdio.h> 47 #include <string.h> 48 49 int 50 main() 51 { 52 int i = 1; 53 char buf[256]; 54 char *msg = "rename() fails to handle race situation\n"; 55 56 switch (fork()) { 57 case -1: 58 perror("fork"); 59 exit(1); 60 break; 61 case 0: 62 while (i > 0) { 63 int c_count = 0; 64 if (rename("a/b/c", "1/2/3/c") == 0) 65 c_count++; 66 if (rename("1/2/3/c", "a/b/c") == 0) 67 c_count++; 68 if (c_count) { 69 (void) strlcat(buf, "c_count: %d,", 256); 70 (void) strlcat(buf, msg, 256); 71 (void) fprintf(stderr, buf, c_count); 72 } 73 } 74 break; 75 default: 76 while (i > 0) { 77 int p_count = 0; 78 if (rename("1", "a/b/c/d/e/1") == 0) 79 p_count++; 80 if (rename("a/b/c/d/e/1", "1") == 0) 81 p_count++; 82 if (p_count) { 83 (void) strlcat(buf, "p_count: %d,", 256); 84 (void) strlcat(buf, msg, 256); 85 (void) fprintf(stderr, buf, p_count); 86 } 87 } 88 break; 89 } 90 return (0); 91 } 92