⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 RTEMS (Real-Time Executive for Multiprocessor Systems) is a free open source real-time operating sys
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  This test exercises stat() via fstat() and generates as many of the *  path evaluation cases as possible. * *  COPYRIGHT (c) 1989-1999. *  On-Line Applications Research Corporation (OAR). * *  The license and distribution terms for this file may be *  found in the file LICENSE in this distribution or at *  http://www.rtems.com/license/LICENSE. * *  $Id: test.c,v 1.12.2.1 2003/09/04 18:46:27 joel Exp $ */#include <tmacros.h>#include <assert.h>#include <sys/stat.h>#include <fcntl.h>#include <limits.h>#include <stdio.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <rtems.h>#include <rtems/libio.h>#include <imfs.h>#include <pmacros.h>#define MAXSYMLINK 5   /* There needs to be a better way of getting this. */#define TIMEOUT_VALUE  ( 5 * TICKS_PER_SECOND )/* *  List of files which should exist. */char *Files[] = {  "/////my_mount_point/dir1/\\//file1\\\\//",  "/my_mount_point/dir1/file2",  "/my_mount_point/dir1/file3",  "/my_mount_point/dir1/file4",  "/my_mount_point/dir1/dir1/file1",  "../../..//my_mount_point/dir1/./././dir1/ file1",  "main.c",  0};/* *  List of directories which should exist. */char *Directories[] = {  "/my_mount_point/dir1",  "/my_mount_point/dir2",  "/my_mount_point/dir3",  "/my_mount_point/dir4",  "/my_mount_point/dir1/dir1",  "/./././my_mount_point/dir1/ dir1",  "/./././my_mount_point/links",    "///my_mount_point/dir1/dir1/../../dir1/../symlinks/////",  0};char *Links_to_Dirs[]= {  "dir1/dir1/../../links/dir1",  "links/dir2",  "links/dir3",  "links/dir4",  "links/dir1_dir1",  "links/dir1_ dir1",  "links/../links/../links/links",  0};char *Links_to_Files[]= {  "links/dir1_file1",  "links/dir1_file2",  "links/dir1_file3",  "links/dir1_file4",  "links/dir1_dir1_f1",  "links/dir1_dir1 f1",  0};char *Links_to_dirlinks[]= {  "links/links/links/links_dir1",  "links//links_dir2",  "links//links_dir3",  "links//links_dir4",  "links//links_dir1_d1",  "links//links_dir1 d1",  "links//links_links",  0};char *Links_to_filelinks[]= {  "links///links_d1_file1",  "links///links_d1_file2",  "links///links_d1_file3",  "links///links_d1_file4",  "links///links_d1_d1_f1",  "links///links_r1_d1 f1",  0};char *SymLinks[]= {  "/my_mount_point/symlinks/a_file_symlink",  "/my_mount_point/symlinks/a_dir_symlink",  "/my_mount_point/symlinks/a_link_symlink",  "../symlinks/no_file",  "/my_mount_point/symlinks/a_dir_symlink/a_file_symlink",  0};/* *  List of absolute paths to stat. */char *Good_absolute_paths[] = {  "/my_mount_point/dev",  "////my_mount_point/dir1/\\//file1\\\\//",  "/my_mount_point/dir1/\\\\/file2",  "/my_mount_point/dir1/file3/////\\\\\\",  "/my_mount_point/dir1/file4",  "/my_mount_point/dir1/dir1/file1",  "/my_mount_point/dir1/dir1/ file1",  "/my_mount_point/dir1",  "/my_mount_point/dir2//////\\",  "/my_mount_point/dir3",  "/my_mount_point/dir4",  "/my_mount_point/dir1/dir1",  "/my_mount_point/dir1/ dir1///\\\\",  "/my_mount_point/\\/\\/\\/\\/\\/\\/links\\/\\/\\/\\/\\/\\",  0};char *Bad_paths[] = {  "/my_mount_point/links/ENAMETOOLONG__________________________",  "/my_mount_point/dir1/file4/NOTADIR",  "/my_mount_point/dir1/dir1/EACCES__",  0};/* *  List of relative paths to stat. */char *Good_relative_paths[] = {  "dev",  "dir1/\\//file1\\\\//",  "dir1/\\\\/file2",  "dir1/file3/////\\\\\\",  "dir1/file4",  "dir1/dir1/file1",  "dir1/dir1/ file1",  "dir1",  "dir2//////\\",  "dir3",  "dir4",  "dir1/dir1",  "dir1/ dir1///\\\\",  "main.c",  0};/* *  Do a stat on a single file and report the status. */void stat_a_file(  const char *file){  int         status;  struct stat statbuf;  int         major1;  int         minor1;  int         major2;  int         minor2;  assert( file );  printf( "stat( %s ) returned ", file );  fflush( stdout );  status = stat( file, &statbuf );  if ( status == -1 ) {    printf( ": %s\n", strerror( errno ) );  } else {    rtems_filesystem_split_dev_t( statbuf.st_dev, major1, minor1 );    rtems_filesystem_split_dev_t( statbuf.st_rdev, major2, minor2 );    printf("\n...st_dev     (0x%x:0x%x)\n", major1, minor1 );    printf(  "...st_ino     %x\n", (int) statbuf.st_ino );    printf(  "...st_mode    %o\n", statbuf.st_mode );    printf(  "...st_nlink   %x\n", statbuf.st_nlink );    printf(  "...st_uid     %d\n", statbuf.st_uid );    printf(  "...st_gid     %d\n", statbuf.st_gid );    printf(  "...st_rdev    (0x%x:0x%x)\n", major2, minor2 );    printf(  "...st_size    %d\n",(unsigned int) statbuf.st_size );    printf(  "...st_atime   %s", ctime( &statbuf.st_atime ) );    printf(  "...st_mtime   %s", ctime( &statbuf.st_mtime ) );    printf(  "...st_ctime   %s", ctime( &statbuf.st_ctime ) );#if defined(__svr4__) && !defined(__PPC__) && !defined(__sun__)    printf(  "...st_blksize %x\n", statbuf.st_blksize );    printf(  "...st_blocks  %x\n", statbuf.st_blocks );#endif  }}/* *  stat() multiple files at a time */void stat_multiple_files(  char **files){  int    i;  i = 0;  while ( files[i] ) {    stat_a_file( files[i] );    i++;  }}/* *  chown() multiple files at a time */void chown_multiple_files(  char **files){  int    i;  uid_t  st_uid;  gid_t  st_gid;  st_uid = geteuid();  st_gid = getegid();  i = 0;  while ( files[i] ) {    printf("Change group of %s\n", files[i]);    chown( files[i], st_uid, (st_gid+1) );    stat_a_file( files[i] );    printf("Change owner of %s\n", files[i]);    chown( files[i], (st_uid+1), st_gid );    stat_a_file( files[i] );    i++;  }}/* *  mknod() multiple files at a time */void make_multiple_files(  char **files){  int    i;  int    status;  i = 0;  while ( files[i] ) {    printf( "Making file %s\n", files[i] );    status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL );    assert( !status );    i++;  }  puts( "" );}void make_multiple_bad_files(  char **files){  int    i;  int    status;  i = 0;  while ( files[i] ) {    printf( "Making file %s ", files[i] );    status = mknod( files[i], ( S_IFREG | S_IROTH|S_IWOTH ), 0LL );    assert( status );    printf( ": %s\n", strerror( errno ) );    i++;  }  puts( "" );}void make_multiple_links(  char **existing,  char **new){  int    i;  int    status;  i = 0;  while ( new[i] && existing[i] ) {    printf( "Making file %s\n", new[i] );    status = link( existing[i], new[i] );    assert( !status );    i++;  }  puts( "" );  status = link( "fred", "bob" );  assert( status == -1 );  status = link( existing[1], "doug/bob" );  assert( status == -1 );}void make_too_many_links(){  int    i;  int    status;  char   name [20];  status = mkdir("/dummy", S_IRWXU );  assert( status == 0 );  for (i=1; i<= LINK_MAX; i++) {    sprintf(name,"/LinkName%d",i);    printf( "Making file %s\n", name );    status = link("/dummy" , name );    if( i < LINK_MAX )       assert( !status );    else       assert( status == -1 );  }}void make_a_symlink(  char *existing,  char *new){  int    status;  char   buf[100];  int    len;  memset( buf, 0, 100 );  printf( "Making file %s\n", new );  status = symlink( existing, new );  assert( !status );  printf( "Verify with readlink\n");  status = readlink( new, buf, 100 );  len = strlen( existing );  assert ( status == len );  status = readlink( new, buf, 3 );  len = strlen( existing );  if (len < 3 )    assert( status == len );  else    assert( status == 3 );  status = strcmp( existing, buf );  assert( !status );}void make_multiple_symlinks(){ int  status; make_a_symlink( Files[0],             SymLinks[0] ); make_a_symlink( Directories[0],       SymLinks[1] ); make_a_symlink( Links_to_dirlinks[0], SymLinks[2] ); make_a_symlink( "No_File",            SymLinks[3] ); make_a_symlink( SymLinks[1],          SymLinks[4] ); make_a_symlink( "//my_mount_point/links","/my_mount_point/symlinks/links" ); stat_a_file( SymLinks[0] ); stat_a_file( SymLinks[1] ); stat_a_file( SymLinks[2] ); stat_a_file( SymLinks[3] ); stat_a_file( SymLinks[4] ); status = symlink(  "//links", "bob/frank" ); assert (status == -1);}/*void make_too_many_symlinks(){  int  i, status;  char name1[8];  for (i=1; i <= MAXSYMLINK; i++) {    sprintf( name1, "SymLink%d", i );    status = symlink( "/dummy", name1 );    if( i < MAXSYMLINK )       assert( !status );    else       assert( status == -1 );  }}*/void make_many_symlinks(  char  *real_file,  int    link_count){  int  i;  char name1[5];  char name2[5];  char *link_file;  link_file = real_file;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -