Ejemplo n.º 1
0
int
nfsMount(char *uidhost, char *path, char *mntpoint)
{
    int   devl = strlen(uidhost) + strlen(path) + 2;
    char *dev;
    int   rval = -1;

    if ((dev = malloc(devl)) == NULL) {
        fprintf(stderr,"nfsMount: out of memory\n");
        return -1;
    }
    sprintf(dev, "%s:%s", uidhost, path);
    printf("Mount %s on %s\n", dev, mntpoint);
    if (rtems_mkdir(mntpoint, S_IRWXU | S_IRWXG | S_IRWXO))
        printf("Warning -- unable to make directory \"%s\"\n", mntpoint);
    if (mount(dev, mntpoint, RTEMS_FILESYSTEM_TYPE_NFS,
                             RTEMS_FILESYSTEM_READ_WRITE, NULL)) {
        perror("mount failed");
    }
    else {
        rval = 0;
    }
    free(dev);
    return rval;
}
Ejemplo n.º 2
0
static void test_mkdir(const char *path, mode_t omode, int expected_rv)
{
  struct stat st;
  int rv = 0;
  mode_t current_umask = umask(0);
  mode_t dirmode = S_IFDIR | (omode & ~current_umask);

  umask(current_umask);

  rv = rtems_mkdir(path, omode);
  rtems_test_assert(rv == expected_rv);

  if (rv == 0) {
    rv = stat(path, &st);
    rtems_test_assert(rv == 0 && st.st_mode == dirmode);
  }
}
Ejemplo n.º 3
0
int
rtems_create_root_fs (void)
{
  const char *lines[1];
  size_t      i;

  /*
   * Create the directories.
   */

  for (i = 0;
       i < (sizeof (default_directories) / sizeof (rtems_rootfs_dir_table));
       i++)
    if (rtems_mkdir (default_directories[i].name,
                            default_directories[i].mode))
      return -1;

  /*
   * The TCP/IP stack likes this one. If DNS does not work
   * use the host file.
   */

  lines[0] = "hosts,bind\n";

  if (rtems_rootfs_file_append ("/etc/host.conf", MKFILE_MODE, 1, lines))
    return -1;

  /*
   * Create a `/etc/hosts' file.
   */

  if (rtems_rootfs_append_host_rec (htonl (0x7f000001), "localhost", "localdomain"))
    return -1;

  return 0;
}
Ejemplo n.º 4
0
/*=========================================================================*\
| Function:                                                                 |
\*-------------------------------------------------------------------------*/
int rtems_fsmount
(
/*-------------------------------------------------------------------------*\
  | Purpose:                                                                  |
  |  This function will create the mount points listed and mount the file     |
  |   systems listed in the calling parameters                                |
  +---------------------------------------------------------------------------+
  | Input Parameters:                                                         |
  \*-------------------------------------------------------------------------*/
  const rtems_fstab_entry *fstab_ptr,
  size_t fstab_count,
  size_t *fail_idx
 )
/*-------------------------------------------------------------------------*\
  | Return Value:                                                             |
  |    0, if success, -1 and errno if failed                                  |
  \*=========================================================================*/
{
  int rc = 0;
  int tmp_rc;
  size_t fstab_idx = 0;
  bool terminate = false;

  /*
   * scan through all fstab entries;
   */
  while (!terminate &&
         (fstab_idx < fstab_count)) {
    tmp_rc = 0;
    /*
     * create mount point
     */
    if (tmp_rc == 0) {
      tmp_rc = rtems_mkdir(fstab_ptr->target, S_IRWXU | S_IRWXG | S_IRWXO);
      if (tmp_rc != 0) {
        if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNTPNT_CRTERR)) {
          fprintf(stdout,"fsmount: creation of mount point \"%s\" failed: %s\n",
                  fstab_ptr->target,
                  strerror(errno));
        }
        if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNTPNT_CRTERR)) {
          terminate = true;
          rc = tmp_rc;
        }
      }
    }
    /*
     * mount device to given mount point
     */
    if (tmp_rc == 0) {
      tmp_rc = mount(fstab_ptr->source,
                     fstab_ptr->target,
                     fstab_ptr->type,
                     fstab_ptr->options,
                     NULL);
      if (tmp_rc != 0) {
        if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_FAILED)) {
          fprintf(stdout,"fsmount: mounting of \"%s\" to"
                  " \"%s\" failed: %s\n",
                  fstab_ptr->source,
                  fstab_ptr->target,
                  strerror(errno));
        }
        if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_FAILED)) {
          terminate = true;
          rc = tmp_rc;
        }
      }
      else {
        if (0 != (fstab_ptr->report_reasons & FSMOUNT_MNT_OK)) {
          fprintf(stdout,"fsmount: mounting of \"%s\" to"
                  " \"%s\" succeeded\n",
                  fstab_ptr->source,
                  fstab_ptr->target);
        }
        if (0 != (fstab_ptr->abort_reasons & FSMOUNT_MNT_OK)) {
          terminate = true;
        }
      }
    }
    /*
     * proceed to next entry
     */
    if (!terminate) {
      fstab_ptr++;
      fstab_idx++;
    }
  }
  if (fail_idx != NULL) {
    *fail_idx = fstab_idx;
  }
  return rc;
}
Ejemplo n.º 5
0
int
rtems_rootfs_file_append (const char *file,
                          mode_t     omode,
                          const int  line_cnt,
                          const char **lines)
{
  struct stat sb;
  int         fd;
  int         i;

  /*
   * See is a file exists. If it does not, create the
   * file and the path to the file.
   */

  fd = -1;

  if (stat(file, &sb))
  {
    if (errno == ENOENT)
    {
      /*
       * Get the path to the file if one exists and create the
       * path. If it exists nothing happens.
       */

      size_t i = strlen (file);

      while (i)
      {
        if (file[i] == '/')
        {
          char path[128];

          if (i >= sizeof path)
          {
            printf ("root fs, path too long `%s'\n", file);
            return -1;
          }

          strncpy (path, file, i);
          path[i] = '\0';

          if (rtems_mkdir (path, MKDIR_MODE))
            return -1;
          break;
        }
        i--;
      }

      if ((fd = open (file, O_CREAT | O_APPEND | O_WRONLY, omode)) < 0)
      {
        printf ("root fs, cannot create file `%s' : %s\n",
                file, strerror (errno));
        return -1;
      }
    }
  }

  if (fd < 0)
  {
    if ((fd = open (file, O_APPEND | O_WRONLY)) < 0)
    {
      printf ("root fs, cannot open file `%s' : %s\n",
              file, strerror (errno));
      return -1;
    }
  }

  for (i = 0; i < line_cnt; i++)
  {
    size_t len = strlen (lines[i]);

    if (len)
    {
      if (write (fd, lines[i], strlen (lines[i])) < 0)
      {
        close (fd);
        printf ("root fs, cannot write to `%s' : %s\n",
                file, strerror (errno));
        return -1;
      }
    }
  }

  return close (fd);
}