int rtems_rfs_rtems_initialise (rtems_filesystem_mount_table_entry_t* mt_entry, const void* data) { rtems_rfs_rtems_private* rtems; rtems_rfs_file_system* fs; uint32_t flags = 0; uint32_t max_held_buffers = RTEMS_RFS_FS_MAX_HELD_BUFFERS; const char* options = data; int rc; /* * Parse the options the user specifiies. */ while (options) { printf ("options=%s\n", options); if (strncmp (options, "hold-bitmaps", sizeof ("hold-bitmaps") - 1) == 0) flags |= RTEMS_RFS_FS_BITMAPS_HOLD; else if (strncmp (options, "no-local-cache", sizeof ("no-local-cache") - 1) == 0) flags |= RTEMS_RFS_FS_NO_LOCAL_CACHE; else if (strncmp (options, "max-held-bufs", sizeof ("max-held-bufs") - 1) == 0) { max_held_buffers = strtoul (options + sizeof ("max-held-bufs"), 0, 0); } else return rtems_rfs_rtems_error ("initialise: invalid option", EINVAL); options = strchr (options, ','); if (options) { ++options; if (*options == '\0') options = NULL; } } rtems = malloc (sizeof (rtems_rfs_rtems_private)); if (!rtems) return rtems_rfs_rtems_error ("initialise: local data", ENOMEM); memset (rtems, 0, sizeof (rtems_rfs_rtems_private)); rc = rtems_rfs_mutex_create (&rtems->access); if (rc > 0) { free (rtems); return rtems_rfs_rtems_error ("initialise: cannot create mutex", rc); } rc = rtems_rfs_mutex_lock (&rtems->access); if (rc > 0) { rtems_rfs_mutex_destroy (&rtems->access); free (rtems); return rtems_rfs_rtems_error ("initialise: cannot lock access mutex", rc); } rc = rtems_rfs_fs_open (mt_entry->dev, rtems, flags, max_held_buffers, &fs); if (rc) { free (rtems); return rtems_rfs_rtems_error ("initialise: open", rc); } mt_entry->fs_info = fs; mt_entry->ops = &rtems_rfs_ops; mt_entry->mt_fs_root->location.node_access = (void*) RTEMS_RFS_ROOT_INO; mt_entry->mt_fs_root->location.handlers = &rtems_rfs_rtems_dir_handlers; rtems_rfs_rtems_unlock (fs); return 0; }
static int rtems_rfs_write_root_dir (const char* name) { rtems_rfs_file_system* fs; rtems_rfs_inode_handle inode; rtems_rfs_ino ino; int rc; /* * External API so returns -1. */ rc = rtems_rfs_fs_open (name, NULL, RTEMS_RFS_FS_FORCE_OPEN, &fs); if (rc < 0) { printf ("rtems-rfs: format: file system open failed: %d: %s\n", errno, strerror (errno)); return -1; } rc = rtems_rfs_inode_alloc (fs, RTEMS_RFS_ROOT_INO, &ino); if (rc > 0) { printf ("rtems-rfs: format: inode allocation failed: %d: %s\n", rc, strerror (rc)); rtems_rfs_fs_close (fs); return rc; } if (ino != RTEMS_RFS_ROOT_INO) { printf ("rtems-rfs: format: allocated inode not root ino: %" PRId32 "\n", ino); rtems_rfs_fs_close (fs); return rc; } rc = rtems_rfs_inode_open (fs, ino, &inode, true); if (rc > 0) { printf ("rtems-rfs: format: inode open failed: %d: %s\n", rc, strerror (rc)); rtems_rfs_group_bitmap_free (fs, true, ino); rtems_rfs_fs_close (fs); return rc; } rc = rtems_rfs_inode_initialise (&inode, 0, (RTEMS_RFS_S_IFDIR | RTEMS_RFS_S_IRWXU | RTEMS_RFS_S_IXGRP | RTEMS_RFS_S_IXOTH), 0, 0); if (rc > 0) printf ("rtems-rfs: format: inode initialise failed: %d: %s\n", rc, strerror (rc)); rc = rtems_rfs_dir_add_entry (fs, &inode, ".", 1, ino); if (rc > 0) printf ("rtems-rfs: format: directory add failed: %d: %s\n", rc, strerror (rc)); rc = rtems_rfs_inode_close (fs, &inode); if (rc > 0) printf ("rtems-rfs: format: inode close failed: %d: %s\n", rc, strerror (rc)); rc = rtems_rfs_fs_close (fs); if (rc < 0) printf ("rtems-rfs: format: file system close failed: %d: %s\n", errno, strerror (errno)); return rc; }