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 28 /* 29 * Assertion: 30 * Create two directory trees in zfs filesystem, and rename 31 * directory across the directory structure. ZFS can handle 32 * the race situation. 33 */ 34 35 /* 36 * Need to create the following directory structures before 37 * running this program: 38 * 39 * mkdir -p 1/2/3/4/5 a/b/c/d/e 40 */ 41 42 43 #include <stdlib.h> 44 #include <unistd.h> 45 #include <stdio.h> 46 #include <string.h> 47 48 int 49 main() 50 { 51 int i = 1; 52 char buf[256]; 53 char *msg = "rename() fails to handle race situation\n"; 54 55 switch (fork()) { 56 case -1: 57 perror("fork"); 58 exit(1); 59 break; 60 case 0: 61 while (i > 0) { 62 int c_count = 0; 63 if (rename("a/b/c", "1/2/3/c") == 0) 64 c_count++; 65 if (rename("1/2/3/c", "a/b/c") == 0) 66 c_count++; 67 if (c_count) { 68 (void) strlcat(buf, "c_count: %d,", 256); 69 (void) strlcat(buf, msg, 256); 70 (void) fprintf(stderr, buf, c_count); 71 } 72 } 73 break; 74 default: 75 while (i > 0) { 76 int p_count = 0; 77 if (rename("1", "a/b/c/d/e/1") == 0) 78 p_count++; 79 if (rename("a/b/c/d/e/1", "1") == 0) 80 p_count++; 81 if (p_count) { 82 (void) strlcat(buf, "p_count: %d,", 256); 83 (void) strlcat(buf, msg, 256); 84 (void) fprintf(stderr, buf, p_count); 85 } 86 } 87 break; 88 } 89 return (0); 90 } 91