Пример #1
0
void test27c()
{				/* Test error response. */
  struct stat st;
  int fd, i;

  subtest = 3;

  System("echo Hi > foo");	/* Make a file called foo. */
  /* Check if a un searchable dir is handled ok. */
  Chdir("..");			/* cd .. */
  System("chmod 677 DIR_27");	/* no search permission */
  if (stat("DIR_27/nono", &st) != -1) e(1);
  if (superuser) {
	if (errno != ENOENT) e(2);	/* su has access */
  }
  if (!superuser) {
	if (errno != EACCES) e(3);	/* we don't ;-) */
  }
  System("chmod 777 DIR_27");
  Chdir("DIR_27");		/* back to test dir */

  /* Check on ToLongName etc. */
#ifdef _POSIX_NO_TRUNC
# if _POSIX_NO_TRUNC - 0 != -1
  if (stat(ToLongName, &st) != -1) e(4);	/* name is too long */
  if (errno != ENAMETOOLONG) e(5);
# endif
#else
# include "error, this case requires dynamic checks and is not handled"
#endif
  if (stat(ToLongPath, &st) != -1) e(6);	/* path is too long */
  if (errno != ENAMETOOLONG) e(7);

  /* Test some common errors. */
  if (stat("nono", &st) != -1) e(8);	/* nono nonexistent */
  if (errno != ENOENT) e(9);
  if (stat("", &st) != -1) e(10);	/* try empty */
  if (errno != ENOENT) e(11);
  if (stat("foo/bar", &st) != -1) e(12);	/* foo is a file */
  if (errno != ENOTDIR) e(13);

  /* Test fstat on file descriptors that are not open. */
  for (i = 3; i < 6; i++) {
	if (fstat(i, &st) != -1) e(14);
	if (errno != EBADF) e(15);
  }

  /* Test if a just closed file is `fstat()'-able. */
  if ((fd = open("foo", O_RDONLY)) != 3) e(16);	/* open foo */
  if (fstat(fd, &st) != 0) e(17);	/* get stat */
  if (close(fd) != 0) e(18);	/* close it */
  if (fstat(fd, &st) != -1) e(19);	/* get stat */
  if (errno != EBADF) e(20);
  System("rm -rf ../DIR_27/*");
}
Пример #2
0
static void Test1() {
    Init(NULL);
  //  std::vector<StackEntry> stack;
    StackEntry ent;
    ent.dirname = "/";
    Check(OpenDir(ent.dirname, &ent.file_info));
    stack.push_back(ent);
    char cmd[256];
    while (true) {
        int ret = scanf("%s", cmd);
        if (strcmp(cmd, "exit") == 0) {
                break;
        }
        else if (StartsWith(cmd, "cd", 2)) {
                scanf("%s", cmd);
                Chdir(stack, cmd);
        }
        else if (StartsWith(cmd, "mkdir", 5)) {
                scanf("%s", cmd);
                Mkdir(Combine(stack.back().dirname,cmd));
        }
        else if (StartsWith(cmd, "rmdir", 5)) {
                scanf("%s", cmd);
                Rmdir(Combine(stack.back().dirname,cmd));
        }
        else if (strcmp(cmd, "ls") == 0) {
                List(stack);
        }
    }
}
Пример #3
0
void
cerebrod_daemon_init(void)
{
  /* Based on code in Unix network programming by R. Stevens */
  pid_t pid;
  int i;
 
  pid = Fork();
  if (pid != 0)			/* Terminate Parent */
    exit(0);
 
  setsid();
 
  Signal(SIGHUP, SIG_IGN);
   
  pid = Fork();
  if (pid != 0)			/* Terminate 1st Child */
    exit(0);

  Chdir("/");
 
  Umask(0);
   
  /* Don't use Close() wrapper, we don't want to exit on error */
  for (i = 0; i < 64; i++)
    close(i);			
}
Пример #4
0
void main(int argc, char *argv[]){

  char *dirname;

  //get the path name from argv

  if (argc > 2 | argc < 1) {
    prints("Usage cd path\n" );
  }
  
  dirname = argv[1];

  Chdir( dirname);
//Lsdir();


}
Пример #5
0
/*----------------------------------------------------------------------------
>  Function Name: RtStatus_t DeleteTree(uint8_t *filePath)

   FunctionType:  Reentrant

   Inputs:        1) Pointer to the directory path

   Outputs:       Returns 0 on success else an error code
                   
   Description:   Deletes all the files and directories of the specified path
<
----------------------------------------------------------------------------*/
RtStatus_t DeleteTree(uint8_t * filePath)
{
    RtStatus_t RetValue = SUCCESS;
    int32_t HandleNumber = 0;
    int32_t StartingCluster;
    FindData_t _finddata;
    uint8_t Buf[32];
    HandleTable_t TempHandle;
//  int64_t lTemp;

    if ((RetValue = Chdir(filePath)) < 0)
        return RetValue;

    TempHandle = Handle[CWD_HANDLE];

    if ((HandleNumber = Searchfreehandleallocate()) < 0)
        return (RtStatus_t) HandleNumber;

    Handle[HandleNumber] = Handle[CWD_HANDLE];

    if ((Handle[HandleNumber].StartingCluster) ==
        MediaTable[Handle[HandleNumber].Device].RootdirCluster)
        return ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE;

    if ((ReadDirectoryRecord(HandleNumber, 1, Buf)) <= 0)
        return ERROR_OS_FILESYSTEM_INVALID_RECORD_NUMBER;

    // sdk 2.6 first corrected the shift direction to left instead of right.  3.095 release had left since it had fix from sdk2.6.
    StartingCluster =
        ((FSGetWord(Buf, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buf, DIR_FSTCLUSHIOFFSET) << 16));

    if ((RetValue = Fseek(HandleNumber, 0, SEEK_SET)) < 0)
        return RetValue;

    Freehandle(HandleNumber);

    if ((RetValue =
         DeleteAllRecords(StartingCluster, &_finddata)) == ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE) {
        Handle[CWD_HANDLE] = TempHandle;
        return SUCCESS;
    } else {
        Handle[CWD_HANDLE] = TempHandle;
        return RetValue;
    }
}
Пример #6
0
void test23b()
{				/* Test critical values. */
  int does_truncate;
  subtest = 2;

  System("rm -rf ../DIR_23/*");

  /* Fiddle with the size (2nd) parameter of `getcwd ()'. */
  if (getcwd(cwd, PATH_MAX) != cwd) e(1);	/* get cwd */
  if (getcwd(buf, strlen(cwd)) != (char *) 0) e(2);   /* size 1 to small */
  if (errno != ERANGE) e(3);
  if (getcwd(buf, PATH_MAX) != buf) e(4);
  if (strcmp(buf, cwd) != 0) e(5);
  Chdir(cwd);			/* getcwd might cd / */
  if (getcwd(buf, strlen(cwd) + 1) != buf) e(6);	/* size just ok */
  if (getcwd(buf, PATH_MAX) != buf) e(7);
  if (strcmp(buf, cwd) != 0) e(8);

  /* Let's see how "MaxName" and "ToLongName" are handled. */
  if (mkdir(MaxName, 0777) != 0) e(9);
  if (chdir(MaxName) != 0) e(10);
  if (chdir("..") != 0) e(11);
  if (rmdir(MaxName) != 0) e(12);
  if (getcwd(buf, PATH_MAX) != buf) e(13);
  if (strcmp(buf, cwd) != 0) e(14);
  if (chdir(MaxPath) != 0) e(15);
  if (getcwd(buf, PATH_MAX) != buf) e(16);
  if (strcmp(buf, cwd) != 0) e(17);

  does_truncate = does_fs_truncate();
  if (chdir(ToLongName) != -1) e(18);
  if (does_truncate) {
	if (errno != ENOENT) e(19);
  } else {
  	if (errno != ENAMETOOLONG) e(20);
  }

  if (getcwd(buf, PATH_MAX) != buf) e(21);
  if (strcmp(buf, cwd) != 0) e(22);
  if (chdir(ToLongPath) != -1) e(23);
  if (errno != ENAMETOOLONG) e(24);
  if (getcwd(buf, PATH_MAX) != buf) e(25);
  if (strcmp(buf, cwd) != 0) e(26);
}
_reentrant RETCODE Fast_Playlist_GetLFN(INT iEntryType,INT pEntry,INT* pName){
	_packed BYTE sFileSpec[SFN_LENGTH];
	Finddata finddata;
	int find_handle ;
	int iDirHandle;
	int i;
	WORD iStrLen;
	RETCODE	rtn = PLAYLIST_TRACK_NOT_FOUND;

	sFileSpec[0] = 0;
	packed_strcpy((_packed BYTE *)pName,g_CurrentSongName);
	iStrLen= packed_strlen((_packed BYTE *)pName);
	while(iStrLen--)
	{
	    if(packed_get((_packed BYTE *)pName,iStrLen)=='/')
		{
	        for (i = 0; i < SFN_LENGTH; i++)
				packed_set(sFileSpec,i,packed_get((_packed BYTE *)pName,iStrLen+1+i));
			packed_set((_packed BYTE *)pName,iStrLen+1,0);
			break;
		}
	}

	Chdir((_packed char *)pName);
	iDirHandle = GetCWDHandle();
	_memset(&finddata,0,sizeof(finddata));
	finddata.device = 0;
	finddata.startrecord = 0;//start at the 0th record.
	find_handle = FindFirst(&finddata,(_packed char*) sFileSpec);
	if( find_handle > 0 )
	{
		g_FileKey = finddata.Key;
		song_info.g_songFastKey=g_FileKey;
        packed_strcpy((_packed BYTE *)g_shortname, (_packed BYTE *)finddata.name);

		if (ConstructLongFileName(iDirHandle, finddata.startrecord - 1, pName ) > 0)
			rtn = PLAYLIST_SUCCESS;
		Fclose(iDirHandle);
		Fclose(find_handle);
	}

	return rtn;
}
INT	_reentrant AASetActivationRecords( INT iNumRecords, INT unused2, INT * pActivationBuf )
{
	int	fp;
	int	bytesToWrite;
    int iFileAttribute;

    iNumRecords = 8;

	// Do a little error checking
	if ( (iNumRecords != 8) && !pActivationBuf )
		return -1;

    //Change to activation folder directory.  It may already exist if 
    //user has previously activated the account.  
    if( Chdir((_packed char *)ActivationFolder) != FS_SUCCESS )
    {
        //If there was an error, the folder may not exist.  Try to create it.  If 
        //it fails, something is wrong so return an error.
        if (Mkdir ((_packed char *)ActivationFolder) != FS_SUCCESS)
            return -2; 
    } 
	// Activation records are always stored in file on internal Flash
	fp = FSFileCreate( (_packed BYTE *) ActivationFilename, 0 );
	if ( fp < 0 ) {
		return -2;
	}

	// Write all the activation records at once
	bytesToWrite = 560;
	if ( FSFileWrite( bytesToWrite, fp, MEM_SPACE_Y, -1, (WORD *) pActivationBuf ) != bytesToWrite ) {
		return -3;
	}
    //Set the hidden attribute so the activation data will not be added to the database.
    iFileAttribute = filegetattrib ((_packed BYTE *) ActivationFilename);
    filesetattrib (fp, iFileAttribute | ATTR_HIDDEN );

	// Close the file and make sure stuff is saved off to Flash
	FSFileClose( fp );
	FlushCache( );

	return 0;
}
Пример #9
0
int main(int argc, char *argv[])
{
  int i, m = 0xFFFF;

  sync();
  if (argc == 2) m = atoi(argv[1]);
  printf("Test 27 ");
  fflush(stdout);
  System("rm -rf DIR_27; mkdir DIR_27");
  Chdir("DIR_27");
  superuser = (getuid() == 0);
  makelongnames();

  for (i = 0; i < ITERATIONS; i++) {
	if (m & 0001) test27a();
	if (m & 0002) test27b();
	if (m & 0004) test27c();
  }
  quit();
}
int main(int argc, char *argv[])
{
  const char *argv0 = argv[0];
  int opt, optidx;

  bool separate_read_write = false;

  bool proxy = false;
  struct sockaddr_in proxy_sin;

  bool join = false;

#ifdef HAVE_SECCOMP
  int nrules = 0;
  uint32_t def_action = SCMP_ACT_ALLOW;
  char *fixed = (char *)mmap((void *)0x800000, 0x1000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
#endif

  struct option longopts[] = {
    {"abstract"    , no_argument       , 0 , 'a'} ,
    {"directory"   , required_argument , 0 , 'd'} ,
    {"environment" , required_argument , 0 , 'e'} ,
    {"join"        , no_argument       , 0 , 'j'} ,
    {"policy"      , required_argument , 0 , 'o'} ,
    {"proxy"       , required_argument , 0 , 'p'} ,
    {"seccomp"     , required_argument , 0 , 'c'} ,
    {"separate"    , no_argument       , 0 , 's'} ,
    {0             , 0                 , 0 , 0}   ,
  };
  while ((opt = getopt_long(argc, argv, "+0ac:d:e:hjo:p:s", longopts, &optidx)) != -1) {
    switch (opt) {
    case 'a':
      af_unix = true;
      break;
    case 'c': {
#ifdef HAVE_SECCOMP
      char *pp = optarg, *p, *qq, *q, *saved0, *saved1;
      for (; ; pp = NULL) {
        p = strtok_r(pp, " \t,", &saved0);
        if (! p) break;

        bool negative = false;
        int num, pos, nfilters = 0;
        enum scmp_compare op;
        if (nrules >= SIZE(scmp_rules))
          errx(BAD_ARG, "too many rules");
        if (*p == '+')
          p++;
        else if (*p == '-')
          p++, negative = true;
        scmp_rules[nrules].action = negative ? SCMP_ACT_TRAP : SCMP_ACT_ALLOW;

        for (qq = p; ; qq = NULL) {
          q = strtok_r(qq, ":", &saved1);
          if (! q) break;
          if (qq) {
            num = seccomp_syscall_resolve_name(q);
            if (num < 0)
              errx(BAD_ARG, "unknown syscall \"%s\"", q);
            scmp_rules[nrules].syscall = num;
          } else {
            if (nfilters >= SIZE(scmp_rules[0].arg_array))
              errx(BAD_ARG, "too many filters");
            if (! ('0' <= *q && *q <= '5'))
              errx(BAD_ARG, "argument position should be 0-5");
            pos = *q-'0';
            REP(i, nfilters)
              if (pos == scmp_rules[nrules].arg_array[i].arg)
                errx(BAD_ARG, "duplicate argument position %d", pos);
            q++;
            if (*q == '=')
              q++, op = SCMP_CMP_EQ;
            else if (*q == '!' && q[1] == '=')
              q += 2, op = SCMP_CMP_NE;
            else if (*q == '<') {
              if (q[1] == '=')
                q += 2, op = SCMP_CMP_LE;
              else
                q++, op = SCMP_CMP_LT;
            } else if (*q == '>') {
              if (q[1] == '=')
                q += 2, op = SCMP_CMP_GE;
              else
                q++, op = SCMP_CMP_GT;
            }
            else
              errx(BAD_ARG, "unknown operator \"%c\"", *q);
            scmp_datum_t val = strtol(q, &q, 0);
            if (*q)
              errx(BAD_ARG, "invalid number");
            scmp_rules[nrules].arg_array[nfilters++] = SCMP_CMP(pos, op, val);
          }
        }
        scmp_rules[nrules].arg_cnt = nfilters;
        nrules++;
      }
#else
      errx(ERR_SYSCALL, "HAVE_SECCOMP not enabled");
#endif
      break;
    }
    case 'd':
      Chdir(optarg);
      break;
    case 'h':
      show_help(STDOUT_FILENO, argv0);
      break;
    case 'j':
      join = true;
      break;
    case 'e':
      putenv(optarg);
      break;
    case 'o':
#ifdef HAVE_SECCOMP
      if (optarg[0] == 'k')
        def_action = SCMP_ACT_KILL;
      else if (optarg[0] == 't')
        def_action = SCMP_ACT_TRAP;
      else if (optarg[0] == 'a')
        def_action = SCMP_ACT_ALLOW;
#else
      errx(ERR_SYSCALL, "HAVE_SECCOMP not enabled");
#endif
      break;
    case 'p': // proxy
      {
        char *p = strchr(optarg, ':');
        if (! p)
          errx(BAD_ARG, "no semicolon");
        *p = '\0';
        proxy_sin.sin_family = AF_INET;
        if (inet_aton(optarg, &proxy_sin.sin_addr) < 0)
          errx(BAD_ARG, "gethostbyname: %s", strerror(errno));
        proxy_sin.sin_port = htons(strtol(p+1, &p, 10));
        if (*p)
          errx(BAD_ARG, "port");
        proxy = true;
      }
      break;
    case 's':
      separate_read_write = true;
      break;
    default:
      show_help(STDERR_FILENO, argv0);
      break;
    }
  }

  argc -= optind;
  argv += optind;

  if (argc < 1) {
    show_help(STDERR_FILENO, argv0);
    return BAD_ARG;
  }

  char buf[4096];
  int pipe_p2c[2], pipe_c2p1[2], pipe_c2p2[2];
  if (af_unix) {
    unix_p2c.sun_family = AF_UNIX; 
    unix_c2p1.sun_family = AF_UNIX;
    unix_c2p2.sun_family = AF_UNIX;
    unix_p2c.sun_path[0] = '\0';
    unix_c2p1.sun_path[0] = '\0';
    unix_c2p2.sun_path[0] = '\0';
    sprintf(unix_p2c.sun_path+1, "/tmp/unix/%d-%d.in", getuid(), getpid());
    sprintf(unix_c2p1.sun_path+1, "/tmp/unix/%d-%d.out", getuid(), getpid());
    sprintf(unix_c2p2.sun_path+1, "/tmp/unix/%d-%d.err", getuid(), getpid());
    pipe_p2c[0] = socket(AF_UNIX, SOCK_STREAM, 0);
    pipe_c2p1[1] = socket(AF_UNIX, SOCK_STREAM, 0);
    if (! join)
      pipe_c2p2[1] = socket(AF_UNIX, SOCK_STREAM, 0);
    atexit(atexit_rm);
    if (bind(pipe_p2c[0], &unix_p2c, sizeof unix_p2c) < 0 ||
        bind(pipe_c2p1[1], &unix_c2p1, sizeof unix_c2p1) < 0)
      return perror(""), 0;
    if (! join && bind(pipe_c2p2[1], &unix_c2p2, sizeof unix_c2p2) < 0)
      return perror(""), 0;
    if (listen(pipe_p2c[0], 1) < 0 ||
        listen(pipe_c2p1[1], 1) < 0)
      return perror(""), 0;
    if (! join && listen(pipe_c2p2[1], 1) < 0)
      return perror(""), 0;
  } else {
    Pipe(pipe_p2c);
    Pipe(pipe_c2p1);
    if (! join)
      Pipe(pipe_c2p2);
  }

  child = Fork();
  if (! child) {
    // child
    if (af_unix) {
      // close bound sockets
      close(pipe_p2c[0]);
      close(pipe_c2p1[1]);
      close(pipe_c2p2[1]);

      // domain sockets for client
      pipe_p2c[1] = socket(AF_UNIX, SOCK_STREAM, 0);
      pipe_c2p1[0] = socket(AF_UNIX, SOCK_STREAM, 0);
      if (! join)
        pipe_c2p2[0] = socket(AF_UNIX, SOCK_STREAM, 0);

      if (connect(pipe_p2c[1], &unix_p2c, sizeof unix_p2c) < 0 ||
          connect(pipe_c2p1[0], &unix_c2p1, sizeof unix_c2p1) < 0)
        return 0;
      dup2(pipe_p2c[1], STDIN_FILENO); close(pipe_p2c[1]);
      dup2(pipe_c2p1[0], STDOUT_FILENO); close(pipe_c2p1[0]);
      if (join)
        dup2(STDOUT_FILENO, STDERR_FILENO);
      else {
        connect(pipe_c2p2[0], &unix_c2p2, sizeof unix_c2p2);
        dup2(pipe_c2p2[0], STDERR_FILENO); close(pipe_c2p2[0]);
      }
    } else {
      close(pipe_p2c[1]); dup2(pipe_p2c[0], STDIN_FILENO); close(pipe_p2c[0]);
      close(pipe_c2p1[0]); dup2(pipe_c2p1[1], STDOUT_FILENO); close(pipe_c2p1[1]);
      if (join)
        dup2(STDOUT_FILENO, STDERR_FILENO);
      else {
        close(pipe_c2p2[0]); dup2(pipe_c2p2[1], STDERR_FILENO); close(pipe_c2p2[1]);
      }
    }

#ifdef HAVE_SECCOMP
    scmp_filter_ctx ctx = seccomp_init(def_action);
    if (ctx == NULL)
      return 1;
    REP(i, nrules) {
      int ret = seccomp_rule_add_array(ctx, scmp_rules[i].action, scmp_rules[i].syscall,
                                       scmp_rules[i].arg_cnt, scmp_rules[i].arg_array);
      if (ret < 0)
        return 1;
    }
    if (seccomp_load(ctx) < 0)
      return 1;
    seccomp_release(ctx);

    strcpy(fixed, *argv);
    execv(fixed, argv); // execve will change the first argument
#else
    execvp(*argv, argv);
#endif
  } else {
Пример #11
0
int main(void)
{
 static unsigned char buffer[BUFFER_SIZE];
 unsigned short i;

 unsigned char timeout = 3;

 RTCTime local_time;

 SystemInit();

// IODIR0 |= (P0_15|P0_16|P0_17); // some outputs for debugging and measures
//P0_16 ReadSector() in mmc_spi.c
//P0_17 enc28j60 write packet
//P0_15 general purpose, BE AWARE !

// uart1Init(B38400, UART_8N1, UART_FIFO_8); // setup the UART
 uart1Init(B115200, UART_8N1, UART_FIFO_8); // setup the UART
 rprintf_devopen( uart1_sendchar ); /* init rprintf */

 VICIntEnClear = 0xFFFFFFFF;
 VICIntSelect = 0x00000000;

 RTCInit();
/* current date 05.08.2007 20:45:00*/
 local_time.RTC_Sec = 0;
 local_time.RTC_Min = 45;
 local_time.RTC_Hour = 20;
 local_time.RTC_Mday = 5;
 local_time.RTC_Wday = 3; // My monday has 0
 local_time.RTC_Yday = 1;
 local_time.RTC_Mon = 8;
 local_time.RTC_Year = 2007;
 RTCSetTime( local_time );		/* Set local time */
// RTCStart();

 init_timer();

 enableIRQ();

 printf("Holgi's ARM7 LPC213x MultiFAT Speed Test\n\r");

 MMC_IO_Init();
 enc28j60_io_init(); // You don't need this ! It's for my board only.

 while (GetDriveInformation() != F_OK && timeout--)
  {
   printf ("MMC/SD-Card not found !\n\r");
   HaltCPU();
  }

 ShowDOSConfig(); // show selected DOS details from dosdefs.h

/*
// test time measurement
 StartTimer();
 timer_value = SetDelay10ms(1000); // delay 10 seconds
 while(CheckDelay10ms(timer_value)==0);
 StopTimer(); // stop measure and show results
// result is 2MB in 10s -> 200kB/s
// end test time measurement
*/

 printf("\nTest directory functions\n");
 Chdir("dir1");
 Remove("dir4");
 Chdir("/"); // Back to root
 Remove("dir1");

 Mkdir("dir1");
 Chdir("dir1");
 Mkdir("dir2");
 Mkdir("dir3");
 Rename("dir3","dir4");
 Remove("dir2");

 // You should have now:
 // dir1/dir4

 Chdir("/"); // Back to root

 printf("\nDeleting files\n");
 Remove("01.bin"); //Remove last data
 Remove("02.bin");
 Remove("04.bin");
 Remove("08.bin");
 Remove("16.bin");
 Remove("32.bin");
 Remove("64.bin");
 Remove("77.bin");
 Remove("128.bin");
 Remove("MAX.bin");

 //Fill the test buffer
 for(i=0; i<BUFFER_SIZE; i++) buffer[i]=(unsigned char)(i);

 printf("\nStart writing files\n");
 WriteTestFile("01.bin",buffer,1);
 WriteTestFile("02.bin",buffer,2);
 WriteTestFile("04.bin",buffer,4);
 WriteTestFile("08.bin",buffer,8);
 WriteTestFile("16.bin",buffer,16);
 WriteTestFile("32.bin",buffer,32);
 WriteTestFile("64.bin",buffer,64);
 WriteTestFile("77.bin",buffer,77);
 WriteTestFile("128.bin",buffer,128);
 WriteTestFile("MAX.bin",buffer,BUFFER_SIZE);

 printf("\nStart reading files\n");
 ReadTestFile("01.bin",buffer,1);
 ReadTestFile("02.bin",buffer,2);
 ReadTestFile("04.bin",buffer,4);
 ReadTestFile("08.bin",buffer,8);
 ReadTestFile("16.bin",buffer,16);
 ReadTestFile("32.bin",buffer,32);
 ReadTestFile("64.bin",buffer,64);
 ReadTestFile("77.bin",buffer,77);
 ReadTestFile("128.bin",buffer,128);
 ReadTestFile("MAX.bin",buffer,BUFFER_SIZE);

 printf("\nVerifying files\n");
 VerifyTestFile("32.bin",buffer,32);
 VerifyTestFile("64.bin",buffer,64);
 VerifyTestFile("77.bin",buffer,77);
 VerifyTestFile("128.bin",buffer,128);
 VerifyTestFile("MAX.bin",buffer,BUFFER_SIZE);

 printf("Test done.\n");

// test if RTC is running
     local_time=RTCGetTime();
     printf("%02u:%02u:%02u %02u.%02u.%04u\n\r",local_time.RTC_Hour,local_time.RTC_Min,local_time.RTC_Sec
                                          ,local_time.RTC_Mday,local_time.RTC_Mon,local_time.RTC_Year );
 while(1)
  {
/*
   if(CheckDelay10ms(timer_value))
    {
     timer_value = SetDelay10ms(1000); // delay 10 seconds

// test if RTC is running
     local_time=RTCGetTime();
     printf("%02u:%02u:%02u %02u.%02u.%04u\n\r",local_time.RTC_Hour,local_time.RTC_Min,local_time.RTC_Sec
                                          ,local_time.RTC_Mday,local_time.RTC_Mon,local_time.RTC_Year );
    }
*/
  }

 return(0);
}
/*
;///////////////////////////////////////////////////////////////////////////////
;> Name:            FSChangeDir
; Type:             Function
; Description:      C wrapper for ChangeDirectory
; Inputs:
;                   a = Device Number
;                   r0 = Pointer to Directory Name String
; Outputs:
;                   a = -1 if function failed
;
; Notes:
;                   see ChangeDirectory for further information.
;                   Directory name must be in Y memory
;<
;///////////////////////////////////////////////////////////////////////////////
*/
INT _reentrant FSChangeDir( _packed BYTE *dirname,INT DeviceNumber)
{
    ConvName(dirname, DeviceNumber);
    return Chdir(namebuffer);
}
Пример #13
0
bool DVfs::gotoBookmark()
{
  bool ret=false;
  if(bookmark) Chdir(bookmark);
  return ret;
}
Пример #14
0
void test24a()
{				/* Test normal operations. */
  int fd3, fd4, fd5;
  DIR *dirp;
  int j, ret, fd, flags;
  struct stat st1, st2;
  int stat_loc;
  time_t time1;

  subtest = 1;

  System("rm -rf ../DIR_24/*");

  if ((fd = dup(0)) != 3) e(1);	/* dup stdin */
  close(fd);			/* free the fd again */
  errno= 0;
  dirp = opendir("/");		/* open "/" */
  if (dirp == ((DIR *) NULL)) e(2);	/* has to succseed */
  if (errno != 0) e(3); 	/* success implies errno didn't change */
  if ((fd = dup(0)) <= 2) e(4);	/* dup stdin */
  if (fd > 3) {			/* if opendir() uses fd 3 */
	flags = fcntl(3, F_GETFD);	/* get fd fags of 3 */
	if (!(flags & FD_CLOEXEC)) e(5);	/* it should be closed on */
  }				/* exec..() calls */
  close(fd);			/* free the fd again */
  ret = closedir(dirp);		/* close, we don't need it */
  if (ret == -1) e(6);		/* closedir () unsucces full */
  if (ret != 0) e(7);		/* should be 0 or -1 */
  if ((fd = dup(0)) != 3) e(8);	/* see if next fd is same */
  close(fd);			/* free the fd again */

  System("rm -rf foo; mkdir foo");
  Chdir("foo");
  System("touch f1 f2 f3 f4 f5");	/* make f1 .. f5 */
  System("rm f[24]");		/* creat `holes' in entrys */
  Chdir("..");

  if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(9);	/* open foo */
  chk_dir(dirp);		/* test if foo's ok */
  for (j = 0; j < 10; j++) {
	errno = j * 47 % 7;	/* there should */
	if (readdir(dirp) != DIRENT0) e(10);	/* be nomore dir */
	if (errno != j * 47 % 7) e(11);	/* entrys */
  }
  rewinddir(dirp);		/* rewind foo */
  chk_dir(dirp);		/* test foosok */
  for (j = 0; j < 10; j++) {
	errno = j * 23 % 7;	/* there should */
	if (readdir(dirp) != DIRENT0) e(12);	/* be nomore dir */
	if (errno != j * 23 % 7) e(13);	/* entrys */
  }
  if ((fd4 = creat("foo/f4", 0666)) <= 2) e(14);	/* Open a file. */
  System("rm foo/f4");		/* Kill entry. */
  rewinddir(dirp);		/* Rewind foo. */
  if ((fd3 = open("foo/f3", O_WRONLY)) <= 2) e(15);	/* Open more files. */
  if ((fd5 = open("foo/f5", O_WRONLY)) <= 2) e(16);
  if (write(fd3, "Hello", 6) != 6) e(17);
  if (write(fd4, "Hello", 6) != 6) e(18);	/* write some data */
  if (close(fd5) != 0) e(19);
  chk_dir(dirp);
  for (j = 0; j < 10; j++) {
	errno = j * 101 % 7;	/* there should */
	if (readdir(dirp) != DIRENT0) e(20);	/* be nomore dir */
	if (errno != j * 101 % 7) e(21);	/* entrys */
  }
  if (close(fd4) != 0) e(22);	/* shouldn't matter */
  if (close(fd3) != 0) e(23);	/* when we do this */
  if (closedir(dirp) != 0) e(24);	/* close foo again */

  Chdir("foo");
  if ((dirp = opendir(".//")) == ((DIR *) NULL)) e(25);	/* open foo again */
  Chdir("..");
  chk_dir(dirp);		/* foosok? */
  for (j = 0; j < 10; j++) {
	errno = (j * 101) % 7;	/* there should */
	if (readdir(dirp) != DIRENT0) e(26);	/* be nomore dir */
	if (errno != (j * 101) % 7) e(27);	/* entrys */
  }

  if (closedir(dirp) != 0) e(28);	/* It should be closable */

  stat("foo", &st1);		/* get stat */
  time(&time1);
  while (time1 >= time((time_t *)0))
	;
  if ((dirp = opendir("foo")) == ((DIR *) NULL)) e(29);	/* open, */
  if (readdir(dirp) == DIRENT0) e(30);	/* read and */
  stat("foo", &st2);		/* get new stat */
  if (st1.st_atime > st2.st_atime) e(31);	/* st_atime check */

  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	rewinddir(dirp);	/* rewind childs dirp */
	if (readdir(dirp) == DIRENT0) e(32);	/* read should be ok */
	if (closedir(dirp) != 0) e(33);	/* close child'd foo */
	exit(0);		/* 0 stops here */
      default:
	if (wait(&stat_loc) == -1) e(34);	/* PARENT wait()'s */
	break;
  }
  if (closedir(dirp) != 0) e(35);	/* close parent's foo */
}
Пример #15
0
/*----------------------------------------------------------------------------
>  Function Name: RtStatus_t ChangeToLowLevelDir(int32_t HandleNumber,FindData_t *_finddata,int32_t StartingCluster)

   FunctionType:  Reentrant

   Inputs:        1) Handle Number
                  2) FindData_t Structure  
                  3) Starting Cluster

   Outputs:       Returns SUCCESS on success else an Error Code
                   
   Description:   Changes to low level directory if available within the given directory 
                  and updates the Handle
<
----------------------------------------------------------------------------*/
RtStatus_t ChangeToLowLevelDir(int32_t HandleNumber, FindData_t * _finddata,
                               int32_t StartingCluster)
{
    RtStatus_t RetValue = SUCCESS;
    int32_t RecordNumber;
    uint8_t Buffer[32];
    int32_t ClusterNumber = 0;
    uint8_t Buf[5];
    // int64_t lTemp;

    PutWord(Buf, 0x2e2e, 0);

    if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR)))
        return RetValue;

    if ((RetValue = Isdirectoryempty(HandleNumber)) == SUCCESS) {
        if ((ReadDirectoryRecord(HandleNumber, 0, Buffer)) <= 0)
            return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD;

        // sdk2.6 changed this from right shift to a left shift.   
        ClusterNumber =
            ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) |
             (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16));

        if ((RetValue = Fseek(HandleNumber, 0, SEEK_SET)) < 0)
            return RetValue;

        if ((RetValue = Chdir((uint8_t *) & Buf)) < 0)
            return RetValue;

        Handle[HandleNumber] = Handle[CWD_HANDLE];

        if ((RecordNumber = DelGetRecordNumber(HandleNumber, ClusterNumber)) < 0)
            return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD;

        if ((RetValue = FileRemove(RecordNumber, HandleNumber)) < 0)
            return RetValue;

        if (Handle[HandleNumber].StartingCluster ==
            MediaTable[Handle[HandleNumber].Device].RootdirCluster
            || Handle[HandleNumber].StartingCluster == StartingCluster)
            return ERROR_OS_FILESYSTEM_DIR_NOT_REMOVABLE;

        return SUCCESS;
    }

    if ((ReadDirectoryRecord(HandleNumber, (_finddata->startrecord - 1), Buffer)) <= 0)
        return ERROR_OS_FILESYSTEM_NO_MATCHING_RECORD;

    if ((RetValue = Fseek(HandleNumber, -DIRRECORDSIZE, SEEK_CUR)))
        return RetValue;

    // sdk2.6 changed this from a right shift to a left shift.
    ClusterNumber =
        ((FSGetWord(Buffer, DIR_FSTCLUSLOOFFSET)) | (FSGetWord(Buffer, DIR_FSTCLUSHIOFFSET) << 16));

    UpdateHandle(HandleNumber, ClusterNumber);

    Handle[CWD_HANDLE] = Handle[HandleNumber];

    return SUCCESS;
}
Пример #16
0
void test23c()
{				/* Check reaction to errors */
  subtest = 3;

  System("rm -rf ../DIR_23/*");

  if (getcwd(cwd, PATH_MAX) != cwd) e(1);	/* get cwd */

  /* Creat a working dir named "foo", remove any previous residues. */
  System("rm -rf foo; mkdir foo");

  /* Check some obviouse errors. */
  if (chdir("") != -1) e(2);
  if (errno != ENOENT) e(3);
  if (getcwd(buf, PATH_MAX) != buf) e(4);
  if (strcmp(buf, cwd) != 0) e(5);
  if (getcwd(buf, 0) != (char *) 0) e(6);
  if (errno != EINVAL) e(7);
  if (getcwd(buf, PATH_MAX) != buf) e(8);
  if (strcmp(buf, cwd) != 0) e(9);
  if (getcwd(buf, 0) != (char *) 0) e(10);
  if (errno != EINVAL) e(11);
  if (getcwd(buf, PATH_MAX) != buf) e(12);
  if (strcmp(buf, cwd) != 0) e(13);
  if (chdir(cwd) != 0) e(14);	/* getcwd might be buggy. */

  /* Change the mode of foo, and check the effect. */
  if (chdir("foo") != 0) e(15);	/* change to foo */
  if (mkdir("bar", 0777) != 0) e(16);	/* make a new dir bar */
  if (getcwd(cwd2, PATH_MAX) != cwd2) e(17);	/* get the new cwd */
  if (getcwd(buf, 3) != (char *) 0) e(18);	/* size is too small */
  if (errno != ERANGE) e(19);
  if (getcwd(buf, PATH_MAX) != buf) e(20);
  if (strcmp(buf, cwd2) != 0) e(21);
  Chdir(cwd2);			/* getcwd() might cd / */
  System("chmod 377 .");	/* make foo unreadable */
  if (getcwd(buf, PATH_MAX) != buf) e(22);	/* dir not readable */
  if (getcwd(buf, PATH_MAX) != buf) e(23);
  if (strcmp(buf, cwd2) != 0) e(24);
  if (chdir("bar") != 0) e(25);	/* at .../foo/bar */
  if (!superuser) {
	if (getcwd(buf, PATH_MAX) != (char *) 0) e(26);
	if (errno != EACCES) e(27);
  }
  if (superuser) {
	if (getcwd(buf, PATH_MAX) != buf) e(28);
  }
  if (chdir(cwd2) != 0) e(29);
  if (getcwd(buf, PATH_MAX) != buf) e(30);
  if (strcmp(buf, cwd2) != 0) e(31);
  System("chmod 677 .");	/* make foo inaccessable */
  if (!superuser) {
	if (getcwd(buf, PATH_MAX) != (char *) 0) e(32);	/* try to get cwd */
	if (errno != EACCES) e(33);	/* but no access */
	if (chdir("..") != -1) e(34);	/* try to get back */
	if (errno != EACCES) e(35);	/* again no access */
	if (chdir(cwd) != 0) e(36);	/* get back to cwd */
	/* `Chdir()' might do path optimizing, it shouldn't. */
	if (chdir("foo/..") != -1) e(37);	/* no op */
	if (chdir("foo") != -1) e(38);	/* try to cd to foo */
	if (errno != EACCES) e(39);	/* no have access */
	if (getcwd(buf, PATH_MAX) != buf) e(40);
	if (strcmp(buf, cwd) != 0) e(41);
  }
  if (superuser) {
	if (getcwd(buf, PATH_MAX) != buf) e(42);
	if (strcmp(buf, cwd2) != 0) e(43);
	if (chdir("..") != 0) e(44);	/* get back to cwd */
	if (chdir("foo") != 0) e(45);	/* get back to foo */
	if (chdir(cwd) != 0) e(46);	/* get back to cwd */
  }
  if (getcwd(buf, PATH_MAX) != buf) e(47);	/* check we are */
  if (strcmp(buf, cwd) != 0) e(48);	/* back at cwd. */
  Chdir(cwd);			/* just in case... */

  if (chdir("/etc/passwd") != -1) e(49);	/* try to change to a file */
  if (errno != ENOTDIR) e(50);
  if (getcwd(buf, PATH_MAX) != buf) e(51);
  if (strcmp(buf, cwd) != 0) e(52);
  if (chdir("/notexist") != -1) e(53);
  if (errno != ENOENT) e(54);
  if (getcwd(buf, PATH_MAX) != buf) e(55);
  if (strcmp(buf, cwd) != 0) e(56);
  System("chmod 777 foo");
  if (chdir("foo") != 0) e(57);

  /* XXX - this comment was botched by 'pretty'. */
  /* * Since `foo' is the cwd, it should not be removeable but * if it
   * were, this code would be found here; *
   * 
   *  System ("cd .. ; rm -rf foo");	remove foo *  if (chdir (".")
   * != -1) e();		try go to. *  if (errno != ENOENT) e();
   * hould not be an entry *  if (chdir ("..") != -1) e();	try
   * to get back *  if (errno != ENOENT) e();		should not be
   * an entry *  if (getcwd (buf, PATH_MAX) != (char *)0) e(); don't
   * know where we are *
   * 
   * What should errno be now ? The cwd might be gone if te superuser *
   * removed the cwd. (Might even have linked it first.) But this *
   * testing should be done by the test program for `rmdir()'. */
  if (chdir(cwd) != 0) e(58);
}
Пример #17
0
static void build_pgxc_ctl_home(char *home)
{
	char *env_pgxc_ctl_home = getenv(PGXC_CTL_HOME);
	char *env_home = getenv(HOME);		/* We assume this is always available */

	if (home)
	{
		if (home[0] == '/')
		{
			/* Absolute path */
			strncpy(pgxc_ctl_home, home, MAXPATH);
			goto set_bash;
		}
		else
		{
			/* Relative path */
			trim_trailing_slash(home);
			snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, home);
			goto set_bash;
		}
	}
	if ((env_pgxc_ctl_home = getenv(PGXC_CTL_HOME)) == NULL)
	{
		snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, pgxc_ctl_home_def);
		goto set_bash;
	}
	if (env_pgxc_ctl_home[0] == '/') /* Absoute path */
	{
		strncpy(pgxc_ctl_home, env_pgxc_ctl_home, MAXPATH);
		goto set_bash;
	}
	trim_trailing_slash(env_pgxc_ctl_home);
	if (env_pgxc_ctl_home[0] == '\0' || env_pgxc_ctl_home[0] == ' ' || env_pgxc_ctl_home[0] == '\t')
	{
		/* Null environment */
		snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, pgxc_ctl_home_def);
		goto set_bash;
	}
	snprintf(pgxc_ctl_home, MAXPATH, "%s/%s", env_home, home);
	goto set_bash;

set_bash:
	snprintf(pgxc_ctl_bash_path, MAXPATH, "%s/%s", pgxc_ctl_home, PGXC_CTL_BASH);
	/*
	 * Create home dir if necessary and change current directory to it.
	 */
	{
		struct stat buf;
		char	cmd[MAXLINE+1];
		
		if (stat(pgxc_ctl_home, &buf) ==0)
		{
			if (S_ISDIR(buf.st_mode))
			{
				Chdir(pgxc_ctl_home, TRUE);
				return;
			}
			else
			{
				fprintf(stderr, "%s is not directory.  Check your configurfation\n", pgxc_ctl_home);
				exit(1);
			}
		}
		snprintf(cmd, MAXLINE, "mkdir -p %s", pgxc_ctl_home);
		system(cmd);
		if (stat(pgxc_ctl_home, &buf) ==0)
		{
			if (S_ISDIR(buf.st_mode))
			{
				Chdir(pgxc_ctl_home, TRUE);
				return;
			}
			else
			{
				fprintf(stderr, "Creating %s directory failed. Check your configuration\n", pgxc_ctl_home);
				exit(1);
			}
		}
		fprintf(stderr, "Creating directory %s failed. %s\n", pgxc_ctl_home, strerror(errno));
		exit(1);
	}
	return;
}
Пример #18
0
TVerdict CTestSyscalls::doTestStepL()
	{
	int err;
	if(TestStepName() == KCreat)
   		{
   		INFO_PRINTF1(_L("Creat():"));
   		err = Creat();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kopen1)
		{
		INFO_PRINTF1(_L("open1():"));
		err = open1();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	   	
	else if(TestStepName() == Kopen2)
		{
		INFO_PRINTF1(_L("open2():"));
		err = open2();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen3)
		{
		INFO_PRINTF1(_L("open3():"));
		err = open3();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen4)
		{
		INFO_PRINTF1(_L("open4():"));
		err = open4();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen5)
		{
		INFO_PRINTF1(_L("open5():"));
		err = open5();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen6)
		{
		INFO_PRINTF1(_L("open6():"));
		err = open6();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenTruncate1)
		{
		INFO_PRINTF1(_L("OpenTruncate1:"));
		err = OpenTruncate1();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenTruncate2)
		{
		INFO_PRINTF1(_L("OpenTruncate2:"));
		err = OpenTruncate2();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen7)
   		{
   		INFO_PRINTF1(_L("open7():"));
   		err = open7();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenInAppendMode)
   		{
   		INFO_PRINTF1(_L("OpenInAppendMode():"));
   		err = OpenInAppendMode();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kwrite1)
		{
   		INFO_PRINTF1(_L("write1():"));
		err = write1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kwrite2)
   		{
   		INFO_PRINTF1(_L("write2():"));
   		err = write2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kwrite3)
   		{
   		INFO_PRINTF1(_L("write3():"));
   		err = write3();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kwrite5)
		{
   		INFO_PRINTF1(_L("write5():"));
   		err = write5();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread1)
   		{
   		INFO_PRINTF1(_L("read1():"));
   		err = read1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread2)
   		{
		INFO_PRINTF1(_L("read2():"));
   		err = read2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread3)
   		{
		INFO_PRINTF1(_L("read3():"));
   		err = read3();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread4)
		{
		INFO_PRINTF1(_L("read4():"));
		err = read4();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == KOpendir)
   		{
   	   	INFO_PRINTF1(_L("Opendir():"));
   	   	err = Opendir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClosedir)
   		{
   	   	INFO_PRINTF1(_L("Closedir():"));
   	   	err = Closedir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KReaddir)
   		{
   	   	INFO_PRINTF1(_L("Readdir():"));
   	   	err = Readdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KLseek)
   		{
   	   	INFO_PRINTF1(_L("Lseek():"));
   	   	err = Lseek();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KLseek1)
   		{
   	   	INFO_PRINTF1(_L("Lseek1():"));
   	   	err = Lseek1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KAccess)
   		{
   	   	INFO_PRINTF1(_L("Access():"));
   	   	err = Access();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KAccess1)
   		{
   	   	INFO_PRINTF1(_L("Access1():"));
   	   	err = Access1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KDup)
   		{
   	   	INFO_PRINTF1(_L("Dup():"));
   	   	err = Dup();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KDup2)
   		{
   	   	INFO_PRINTF1(_L("Dup2():"));
   	   	err = Dup2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename)
   		{
   	   	INFO_PRINTF1(_L("Rename():"));
   	   	err = Rename();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename1)
   		{
   	   	INFO_PRINTF1(_L("Rename1():"));
   	   	err = Rename1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod)
   		{
   	   	INFO_PRINTF1(_L("Chmod():"));
   	   	err = Chmod();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod1)
   		{
   	   	INFO_PRINTF1(_L("Chmod1():"));
   	   	err = Chmod1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KChmod_dir)
   		{
   	   	INFO_PRINTF1(_L("Chmod_dir():"));
   	   	err = Chmod_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFChmod)
   		{
   	   	INFO_PRINTF1(_L("FChmod():"));
   	   	err = FChmod();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFChmod_dir)
   		{
   	   	INFO_PRINTF1(_L("FChmod_dir():"));
   	   	err = FChmod_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KExit)
   		{
   	   	INFO_PRINTF1(_L("Exit():"));
   	   	err = Exit();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClose)
   		{
   	   	INFO_PRINTF1(_L("Close():"));
   	   	err = Close();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMkdir)
   		{
   	   	INFO_PRINTF1(_L("Mkdir():"));
   	   	err = Mkdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMk_dir)
   		{
   	   	INFO_PRINTF1(_L("Mk_dir():"));
   	   	err = Mk_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRmdir)
   		{
   	   	INFO_PRINTF1(_L("Rmdir():"));
   	   	err = Rmdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRm_dir)
   		{
   	   	INFO_PRINTF1(_L("Rm_dir():"));
   	   	err = Rm_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KRmdir1)
   		{
   	   	INFO_PRINTF1(_L("Rmdir1():"));
   	   	err = Rmdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRmdir_Chdir)
   		{
   	   	INFO_PRINTF1(_L("Rmdir_Chdir():"));
   	   	err = Rmdir_Chdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFsync)
   		{
   	   	INFO_PRINTF1(_L("Fsync():"));
   	   	err = Fsync();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KUtimes)
   		{
   	   	INFO_PRINTF1(_L("Utimes():"));
   	   	err = Utimes();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	else if(TestStepName() == KUtime)
   		{
   	   	INFO_PRINTF1(_L("Utime():"));
   	   	err = Utime();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChdir)
   		{
   	   	INFO_PRINTF1(_L("Chdir():"));
   	   	err = Chdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFcntl)
   		{
   	   	INFO_PRINTF1(_L("Fcntl():"));
   	   	err = Fcntl();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KIoctl)
   		{
   	   	INFO_PRINTF1(_L("Ioctl():"));
   	   	err = Ioctl();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFstat)
   		{
   	   	INFO_PRINTF1(_L("Fstat():"));
   	   	err = Fstat();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat)
   		{
   	   	INFO_PRINTF1(_L("Stat():"));
   	   	err = Stat();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat1)
   		{
   	   	INFO_PRINTF1(_L("Stat1():"));
   	   	err = Stat1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat2)
   		{
   	   	INFO_PRINTF1(_L("Stat2():"));
   	   	err = Stat2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KStat3)
   		{
   	   	INFO_PRINTF1(_L("Stat3():"));
   	   	err = Stat3();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KGetpid)
   		{
   	   	INFO_PRINTF1(_L("Getpid():"));
   	   	err = Getpid();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClock)
   		{
   	   	INFO_PRINTF1(_L("Clock():"));
   	   	err = Clock();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTime)
   		{
   	   	INFO_PRINTF1(_L("Time():"));
   	   	err = Time();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KWaitPid)
   		{
   	   	INFO_PRINTF1(_L("WaitPid():"));
   	   	err = WaitPid();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KReadV)
   		{
   	   	INFO_PRINTF1(_L("ReadV():"));
   	   	err = ReadV();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KWriteV)
   		{
   	   	INFO_PRINTF1(_L("WriteV():"));
   	   	err = WriteV();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KSleep)
   		{
   	   	INFO_PRINTF1(_L("Sleep():"));
   	   	err = Sleep();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KSeekDir)
   		{
   	   	INFO_PRINTF1(_L("SeekDir():"));
   	   	err = SeekDir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRewindDir)
   		{
   	   	INFO_PRINTF1(_L("RewindDir():"));
   	   	err = RewindDir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTelldir)
   		{
   	   	INFO_PRINTF1(_L("Telldir():"));
   	   	err = Telldir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTestClock)
   		{
   	   	INFO_PRINTF1(_L("TestClock():"));
   	   	err = TestClock();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KCreat2)
   		{
   		INFO_PRINTF1(_L("Creat2():"));
   		err = Creat2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == Kopen8)
   		{
   		INFO_PRINTF1(_L("open8():"));
   		err = open8();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == KTestStat)
   		{
   		INFO_PRINTF1(_L("KTestStat():"));
   		err = TestStat();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KLseekttytest1)
   		{
   		INFO_PRINTF1(_L("Lseekttytest1():"));
   		err = Lseekttytest1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KLseekttytest2)
   		{
   		INFO_PRINTF1(_L("Lseekttytest2():"));
   		err = Lseekttytest2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KWaitPidtest)
   		{
   		INFO_PRINTF1(_L("WaitPidtest():"));
   		err = WaitPidtest();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KWaittest)
   		{
   		INFO_PRINTF1(_L("Waittest():"));
   		err = Waittest();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpen_FileDes_Test)
   		{
   		INFO_PRINTF1(_L("Open_FileDes_Test():"));
   		err = Open_FileDes_Test();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopenuid)
   		{
   		INFO_PRINTF1(_L("openuid():"));
   		err = openuid();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KMkdir1)
   		{
   	   	INFO_PRINTF1(_L("Mkdir1():"));
   	   	err = Mkdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMkdir2)
   		{
   	   	INFO_PRINTF1(_L("Mkdir2():"));
   	   	err = Mkdir2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRename2)
   		{
   	   	INFO_PRINTF1(_L("Rename2():"));
   	   	err = Rename2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == Ktestfsync)
   		{
   		INFO_PRINTF1(_L("testfsync():"));
   		err = testfsync();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ktestrename)
   		{
   		INFO_PRINTF1(_L("testrename():"));
   		err = testrename();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ktestopenvalidate)
   		{
   		INFO_PRINTF1(_L("testopenvalidate():"));
   		err = testopenvalidate();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ksync_safe)
   		{
   		INFO_PRINTF1(_L("sync_safe():"));
   		err = sync_safe();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	else if(TestStepName() == KFstat1)
   		{
   	   	INFO_PRINTF1(_L("Fstat1():"));
   	   	err = Fstat1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KUtimes1)
   		{
   	   	INFO_PRINTF1(_L("Utimes1():"));
   	   	err = Utimes1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KMkdir_test1)
   		{
   	   	INFO_PRINTF1(_L("Mkdir_test1():"));
   	   	err = Mkdir_test1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod_test)
   		{
   	   	INFO_PRINTF1(_L("Chmod_test():"));
   	   	err = Chmod_test();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KChdir1)
   		{
   	   	INFO_PRINTF1(_L("Chdir1():"));
   	   	err = Chdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}   
   	else if(TestStepName() == KRmdir2)
   		{
   	   	INFO_PRINTF1(_L("Rmdir2():"));
   	   	err = Rmdir2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename_test)
   		{
   	   	INFO_PRINTF1(_L("Rename_test():"));
   	   	err = Rename_test();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename3)
   		{
   	   	INFO_PRINTF1(_L("Rename3():"));
   	   	err = Rename3();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KCreat1)
   		{
   		INFO_PRINTF1(_L("Creat1():"));
   		err = Creat1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == KReadV1)
   		{
   	   	INFO_PRINTF1(_L("ReadV1():"));
   	   	err = ReadV1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
 	else if(TestStepName() == KUtimes2)
    		{
    	   	INFO_PRINTF1(_L("Utimes2():"));
    	   	err = Utimes2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
 		}
 	else if(TestStepName() == KStat_test)
    		{
    	   	INFO_PRINTF1(_L("Stat_test():"));
    	   	err = Stat_test();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KMkdir_test2)
    		{
    	   	INFO_PRINTF1(_L("Mkdir_test2():"));
    	   	err = Mkdir_test2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KChmod2)
    		{
    	   	INFO_PRINTF1(_L("Chmod2():"));
    	   	err = Chmod2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KChdir2)
    		{
    	   	INFO_PRINTF1(_L("Chdir2():"));
    	   	err = Chdir2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	} 
    	else if(TestStepName() == KRename4)
    		{
    	   	INFO_PRINTF1(_L("Rename4():"));
    	   	err = Rename4();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
 	else if(TestStepName() == KRename5)
    		{
    	   	INFO_PRINTF1(_L("Rename5():"));
    	   	err = Rename5();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}  
 	else if(TestStepName() == KRmdir3)
    		{
    	   	INFO_PRINTF1(_L("Rmdir3():"));
    	   	err = Rmdir3();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}  
    	else if(TestStepName() == Kread5)
 		{
 		INFO_PRINTF1(_L("read5():"));
 		err = read5();
    		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    		} 	   	 
	return TestStepResult(); 
	}
Пример #19
0
void test24b()
{
/* See what happens with too many dir's open.  Check if file size seems ok, 
 * and independency.
 */

  int i, j;			/* i = highest open dir count */
  DIR *dirp[OVERFLOW_DIR_NR], *dp;
  struct dirent *dep, *dep1, *dep2;
  char *name;	/* buffer for file name, and count */
  int dot = 0, dotdot = 0;
  int max_name_length;

  subtest = 2;

  System("rm -rf ../DIR_24/*");

  max_name_length = name_max(".");
  name = malloc(max_name_length + 2);
  memset(name, '\0', max_name_length + 2);

  for (i = 0; i < OVERFLOW_DIR_NR; i++) {
	dirp[i] = opendir("/");
	if (dirp[i] == ((DIR *) NULL)) {
		if (errno != EMFILE) e(1);
		break;
	}
  }
  if (i <= 4) e(2);		/* sounds resanable */
  if (i >= OVERFLOW_DIR_NR) e(3);	/* might be to small */
  for (j = 0; j < i; j++) {
	if (closedir(dirp[(j + 5) % i]) != 0) e(4);	/* neat! */
  }

  /* Now check if number of bytes in d_name can go up till NAME_MAX */
  System("rm -rf foo; mkdir foo");
  Chdir("foo");
  name[0] = 0;
  for (i = 0; i <= max_name_length; i++) {
	if (strcat(name, "X") != name) e(5);
	close(creat(name, 0666));	/* fails once on */
  }				/* XX..XX, 1 too long */
  Chdir("..");
  /* Now change i-th X to Y in name buffer record file of length i. */
  if ((dp = opendir("foo")) == ((DIR *) NULL)) e(6);
  while ((dep = readdir(dp)) != DIRENT0) {
	if (strcmp("..", dep->d_name) == 0)
		dotdot++;
	else if (strcmp(".", dep->d_name) == 0)
		dot++;
	else
		name[strlen(dep->d_name)] += 1;	/* 'X' + 1 == 'Y' */
  }
  if (closedir(dp) != 0) e(7);
  for (i = 1; i <= max_name_length; i++) {	/* Check if every length */
	if (name[i] != 'Y') e(8);	/* has been seen once. */
  }

  /* Check upper and lower bound. */
  if (name[0] != 'X') e(9);
  if (name[max_name_length + 1] != '\0') e(10);

  /* Now check if two simultaniouse open dirs do the same */
  if ((dirp[1] = opendir("foo")) == ((DIR *) NULL)) e(11);
  if ((dirp[2] = opendir("foo")) == ((DIR *) NULL)) e(12);
  if ((dep1 = readdir(dirp[1])) == DIRENT0) e(13);
  if ((dep2 = readdir(dirp[2])) == DIRENT0) e(14);
  if (dep1->d_name == dep2->d_name) e(15);	/* 1 & 2 Should be */
  strcpy(name, dep2->d_name);	/* differand buffers */
  if (strcmp(dep1->d_name, name) != 0) e(16);	/* But hold the same */
  if ((dep1 = readdir(dirp[1])) == DIRENT0) e(17);
  if ((dep1 = readdir(dirp[1])) == DIRENT0) e(18);	/* lose some entries */
  if ((dep1 = readdir(dirp[1])) == DIRENT0) e(19);	/* Using dirp 1 has */
  if (dep1->d_name == dep2->d_name) e(20);	/* no effect on 2 */
  if (strcmp(dep2->d_name, name) != 0) e(21);
  rewinddir(dirp[1]);		/* Rewinding dirp 1 */
  if ((dep2 = readdir(dirp[2])) == DIRENT0) e(22);	/* can't effect 2 */
  if (strcmp(dep2->d_name, name) == 0) e(23);	/* Must be next */
  if (closedir(dirp[1]) != 0) e(24);	/* Closing dirp 1 */
  if ((dep2 = readdir(dirp[2])) == DIRENT0) e(25);	/* can't effect 2 */
  if (strcmp(dep2->d_name, name) == 0) e(26);	/* Must be next */
  if (closedir(dirp[2]) != 0) e(27);
  free(name);
}