X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/b0d623f7f2ae71ed96e60569f61f9a9a27016e80..7ddcb079202367355dddccdfa4318e57d50318be:/tools/tests/xnu_quick_test/xattr_tests.c diff --git a/tools/tests/xnu_quick_test/xattr_tests.c b/tools/tests/xnu_quick_test/xattr_tests.c index b3248edc2..2b33d6387 100644 --- a/tools/tests/xnu_quick_test/xattr_tests.c +++ b/tools/tests/xnu_quick_test/xattr_tests.c @@ -3,7 +3,7 @@ * xnu_quick_test * * Created by Jerry Cottingham on 6/2/2005. - * Copyright 2005 Apple Computer Inc. All rights reserved. + * Copyright 2005 Apple Computer Inc. All& rights reserved. * */ @@ -28,17 +28,18 @@ int xattr_tests( void * the_argp ) char my_buffer[ 64 ]; char my_xattr_data[ ] = "xattr_foo"; kern_return_t my_kr; + int xattr_len = 0; my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); - if(my_kr != KERN_SUCCESS){ - printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto test_failed_exit; - } - + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto test_failed_exit; + } + *my_pathp = 0x00; strcat( my_pathp, &g_target_path[0] ); strcat( my_pathp, "/" ); - + /* create a test file */ my_err = create_random_name( my_pathp, 1 ); if ( my_err != 0 ) { @@ -58,41 +59,49 @@ int xattr_tests( void * the_argp ) printf( "listxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - if ( my_result != (strlen( XATTR_TEST_NAME ) + 1) ) { - printf( "listxattr did not get the attribute name length \n" ); + + if ( my_result < (strlen( XATTR_TEST_NAME ) + 1) ) { + printf( "listxattr did not get the attribute name length: my_result %d, strlen %zu \n", my_result, (strlen(XATTR_TEST_NAME)+1) ); goto test_failed_exit; } - + memset( &my_buffer[0], 0x00, sizeof( my_buffer ) ); + my_result = getxattr( my_pathp, XATTR_TEST_NAME, &my_buffer[0], sizeof(my_buffer), 0, 0 ); if ( my_err == -1 ) { printf( "getxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } + if ( my_result != (strlen( &my_xattr_data[0] ) + 1) || - strcmp( &my_buffer[0], &my_xattr_data[0] ) != 0 ) { + strcmp(&my_buffer[0], &my_xattr_data[0] ) != 0 ) { printf( "getxattr did not get the correct attribute data \n" ); goto test_failed_exit; } - + /* use removexattr to remove an attribute to our test file */ my_err = removexattr( my_pathp, XATTR_TEST_NAME, 0 ); if ( my_err == -1 ) { printf( "removexattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - + /* make sure it is gone */ my_result = listxattr( my_pathp, NULL, 0, 0 ); - if ( my_err == -1 ) { + if ( my_result == -1 ) { printf( "listxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - if ( my_result != 0 ) { - printf( "removexattr did not remove our test attribute \n" ); + + memset( &my_buffer[0], 0x00, sizeof( my_buffer ) ); + my_result = getxattr( my_pathp, XATTR_TEST_NAME, &my_buffer[0], sizeof(my_buffer), 0, 0 ); + if ( my_result != -1 && errno != ENOATTR) { + printf( "getxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - + + + /* repeat tests using file descriptor versions of the xattr system calls */ my_fd = open( my_pathp, O_RDONLY, 0 ); if ( my_fd == -1 ) { @@ -100,7 +109,7 @@ int xattr_tests( void * the_argp ) printf( "\t file we attempted to open -> \"%s\" \n", my_pathp ); goto test_failed_exit; } - + /* use fsetxattr to add an attribute to our test file */ my_err = fsetxattr( my_fd, XATTR_TEST_NAME, &my_xattr_data[0], sizeof(my_xattr_data), 0, 0 ); if ( my_err == -1 ) { @@ -114,11 +123,11 @@ int xattr_tests( void * the_argp ) printf( "flistxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - if ( my_result != (strlen( XATTR_TEST_NAME ) + 1) ) { + if ( my_result < (strlen( XATTR_TEST_NAME ) + 1) ) { printf( "flistxattr did not get the attribute name length \n" ); goto test_failed_exit; } - + memset( &my_buffer[0], 0x00, sizeof( my_buffer ) ); my_result = fgetxattr( my_fd, XATTR_TEST_NAME, &my_buffer[0], sizeof(my_buffer), 0, 0 ); if ( my_err == -1 ) { @@ -126,32 +135,35 @@ int xattr_tests( void * the_argp ) goto test_failed_exit; } if ( my_result != (strlen( &my_xattr_data[0] ) + 1) || - strcmp( &my_buffer[0], &my_xattr_data[0] ) != 0 ) { + strcmp( &my_buffer[0], &my_xattr_data[0] ) != 0 ) { printf( "fgetxattr did not get the correct attribute data \n" ); goto test_failed_exit; } - + /* use fremovexattr to remove an attribute to our test file */ my_err = fremovexattr( my_fd, XATTR_TEST_NAME, 0 ); if ( my_err == -1 ) { printf( "fremovexattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - + /* make sure it is gone */ my_result = flistxattr( my_fd, NULL, 0, 0 ); - if ( my_err == -1 ) { + if ( my_result == -1 ) { printf( "flistxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - if ( my_result != 0 ) { - printf( "fremovexattr did not remove our test attribute \n" ); + + memset( my_buffer, 0x00, sizeof( my_buffer ) ); + my_result = fgetxattr( my_fd, XATTR_TEST_NAME, &my_buffer[0], sizeof(my_buffer), 0, 0 ); + if ( my_result == -1 && (errno != ENOATTR) ) { + printf( "fgetxattr failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto test_failed_exit; } - + my_err = 0; goto test_passed_exit; - + test_failed_exit: my_err = -1; @@ -161,7 +173,7 @@ test_passed_exit: if ( my_pathp != NULL ) { remove( my_pathp ); vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); - } + } return( my_err ); }