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

📄 mount_main.c

📁 這是一個實時嵌入式作業系統 實作了MCS51 ARM等MCU
💻 C
📖 第 1 页 / 共 2 页
字号:
      g_nerrors++;    }  else if (errno != expectederror)    {      printf("fail_rmdir: ERROR rmdir(%s) failed with errno=%d (expected %d)\n",             path, errno, expectederror);      g_nerrors++;    }}/**************************************************************************** * Name: succeed_rmdir ****************************************************************************/static void succeed_rmdir(const char *path){  int ret;  printf("succeed_rmdir: Try rmdir(%s)\n", path);  ret = rmdir(path);  if (ret != 0)    {      printf("succeed_rmdir: ERROR rmdir(%s) failed with errno=%d\n",             path, errno);      g_nerrors++;    }}/**************************************************************************** * Name: fail_unlink ****************************************************************************/static void fail_unlink(const char *path, int expectederror){  int ret;  /* Try unlink() against a file or directory.  It should fail with expectederror */  printf("fail_unlink: Try unlink(%s)\n", path);  ret = unlink(path);  if (ret == 0)    {      printf("fail_unlink: ERROR unlink(%s) succeeded\n", path);      g_nerrors++;    }  else if (errno != expectederror)    {      printf("fail_unlink: ERROR unlink(%s) failed with errno=%d (expected %d)\n",             path, errno, expectederror);      g_nerrors++;    }}/**************************************************************************** * Name: succeed_unlink ****************************************************************************/static void succeed_unlink(const char *path){  int ret;  /* Try unlink() against the test file.  It should succeed. */  printf("succeed_unlink: Try unlink(%s)\n", path);  ret = unlink(path);  if (ret != 0)    {      printf("succeed_unlink: ERROR unlink(%s) failed with errno=%d\n",             path, errno);      g_nerrors++;    }}/**************************************************************************** * Name: fail_rename ****************************************************************************/static void fail_rename(const char *oldpath, const char *newpath, int expectederror){  int ret;  /* Try rename() against a file or directory.  It should fail with expectederror */  printf("fail_rename: Try rename(%s->%s)\n", oldpath, newpath);  ret = rename(oldpath, newpath);  if (ret == 0)    {      printf("fail_rename: ERROR rename(%s->%s) succeeded\n",             oldpath, newpath);      g_nerrors++;    }  else if (errno != expectederror)    {      printf("fail_rename: ERROR rename(%s->%s) failed with errno=%d (expected %d)\n",             oldpath, newpath, errno, expectederror);      g_nerrors++;    }}/**************************************************************************** * Name: succeed_rename ****************************************************************************/static void succeed_rename(const char *oldpath, const char *newpath){  int ret;  printf("succeed_rename: Try rename(%s->%s)\n", oldpath, newpath);  ret = rename(oldpath, newpath);  if (ret != 0)    {      printf("succeed_rename: ERROR rename(%s->%s) failed with errno=%d\n",             oldpath, newpath, errno);      g_nerrors++;    }}/**************************************************************************** * Name: fail_stat ****************************************************************************/#ifdef TEST_USE_STATstatic void fail_stat(const char *path, int expectederror){  struct stat buf;  int ret;  /* Try stat() against a file or directory.  It should fail with expectederror */  printf("fail_stat: Try stat(%s)\n", path);  ret = stat(path, &buf);  if (ret == 0)    {      printf("fail_stat: ERROR stat(%s) succeeded\n", path);      show_stat(path, &buf);      g_nerrors++;    }  else if (errno != expectederror)    {      printf("fail_stat: ERROR stat(%s) failed with errno=%d (expected %d)\n",             path, errno, expectederror);      g_nerrors++;    }}#else# define fail_stat(p,e);#endif/**************************************************************************** * Name: succeed_stat ****************************************************************************/#ifdef TEST_USE_STATstatic void succeed_stat(const char *path){  struct stat buf;  int ret;  printf("succeed_stat: Try stat(%s)\n", path);  ret = stat(path, &buf);  if (ret != 0)    {      printf("succeed_stat: ERROR stat(%s) failed with errno=%d\n",             path, errno);      g_nerrors++;    }  else    {      printf("succeed_stat: stat(%s) succeeded\n", path);      show_stat(path, &buf);    }}#else#define succeed_stat(p)#endif/**************************************************************************** * Public Functions ****************************************************************************//**************************************************************************** * Name: user_initialize ****************************************************************************/void user_initialize(void){}/**************************************************************************** * Name: user_start ****************************************************************************/int user_start(int argc, char *argv[]){  int  ret;#ifndef CONFIG_EXAMPLES_MOUNT_DEVNAME  /* Create a RAM disk for the test */  ret = create_ramdisk();  if (ret < 0)    {      printf("user_start: ERROR failed to create RAM disk\n");      return 1;    }#endif  /* Mount the test file system (see arch/sim/src/up_deviceimage.c */  printf("user_start: mounting %s filesystem at target=%s with source=%s\n",         g_filesystemtype, g_target, g_source);  ret = mount(g_source, g_target, g_filesystemtype, 0, NULL);  printf("user_start: mount() returned %d\n", ret);  if (ret == 0)    {      show_statfs(g_mntdir);      show_statfs(g_target);#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME      /* Read a test file that is already on the test file system image */      show_directories("", 0);      succeed_stat(g_testfile1);      show_statfs(g_testfile1);      read_test_file(g_testfile1);#else      /* Create the test directory that would have been on the canned filesystem */      succeed_mkdir(g_testdir1);      show_directories("", 0);      succeed_stat(g_testdir1);      show_statfs(g_testdir1);#endif      /* Write a test file into a pre-existing directory on the test file system */      fail_stat(g_testfile2, ENOENT);      write_test_file(g_testfile2);      show_directories("", 0);      succeed_stat(g_testfile2);      show_statfs(g_testfile2);      /* Read the file that we just wrote */      read_test_file(g_testfile2);      /* Try rmdir() against a file on the directory.  It should fail with ENOTDIR */#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME      fail_rmdir(g_testfile1, ENOTDIR);#endif      /* Try rmdir() against the test directory.  It should fail with ENOTEMPTY */      fail_rmdir(g_testdir1, ENOTEMPTY);      /* Try unlink() against the test directory.  It should fail with EISDIR */      fail_unlink(g_testdir1, EISDIR);      /* Try unlink() against the test file1.  It should succeed. */#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME      succeed_unlink(g_testfile1);      fail_stat(g_testfile1, ENOENT);      show_directories("", 0);#endif      /* Attempt to open testfile1 should fail with ENOENT */#ifdef CONFIG_EXAMPLES_MOUNT_DEVNAME      fail_read_open(g_testfile1, ENOENT);#endif      /* Try rmdir() against the test directory.  It should still fail with ENOTEMPTY */      fail_rmdir(g_testdir1, ENOTEMPTY);      /* Try mkdir() against the test file2.  It should fail with EEXIST. */      fail_mkdir(g_testfile2, EEXIST);      /* Try unlink() against the test file2.  It should succeed. */      succeed_unlink(g_testfile2);      show_directories("", 0);      fail_stat(g_testfile2, ENOENT);      /* Try mkdir() against the test dir1.  It should fail with EEXIST. */      fail_mkdir(g_testdir1, EEXIST);      /* Try rmdir() against the test directory.  mkdir should now succeed. */      succeed_rmdir(g_testdir1);      show_directories("", 0);      fail_stat(g_testdir1, ENOENT);      /* Try mkdir() against the test dir2.  It should succeed */      succeed_mkdir(g_testdir2);      show_directories("", 0);      succeed_stat(g_testdir2);      show_statfs(g_testdir2);      /* Try mkdir() against the test dir2.  It should fail with EXIST */      fail_mkdir(g_testdir2, EEXIST);      /* Write a test file into a new directory on the test file system */      fail_stat(g_testfile3, ENOENT);      write_test_file(g_testfile3);      show_directories("", 0);      succeed_stat(g_testfile3);      show_statfs(g_testfile3);      /* Read the file that we just wrote */      read_test_file(g_testfile3);      /* Use mkdir() to create test dir3.  It should succeed */      fail_stat(g_testdir3, ENOENT);      succeed_mkdir(g_testdir3);      show_directories("", 0);      succeed_stat(g_testdir3);      show_statfs(g_testdir3);      /* Try rename() on the root directory. Should fail with EXDEV*/      fail_rename(g_target, g_testdir4, EXDEV);      /* Try rename() to an existing directory.  Should fail with EEXIST */      fail_rename(g_testdir2, g_testdir3, EEXIST);      /* Try rename() to a non-existing directory.  Should succeed */      fail_stat(g_testdir4, ENOENT);      succeed_rename(g_testdir3, g_testdir4);      show_directories("", 0);      fail_stat(g_testdir3, ENOENT);      succeed_stat(g_testdir4);      show_statfs(g_testdir4);      /* Try rename() of file.  Should work. */      fail_stat(g_testfile4, ENOENT);      succeed_rename(g_testfile3, g_testfile4);      show_directories("", 0);      fail_stat(g_testfile3, ENOENT);      succeed_stat(g_testfile4);      show_statfs(g_testfile4);      /* Make sure that we can still read the renamed file */      read_test_file(g_testfile4);      /* Unmount the file system */      printf("user_start: Try unmount(%s)\n", g_target);      ret = umount(g_target);      if (ret != 0)        {          printf("user_start: ERROR umount() failed, errno %d\n", errno);          g_nerrors++;        }      printf("user_start: %d errors reported\n", g_nerrors);    }  fflush(stdout);  return 0;}

⌨️ 快捷键说明

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