Ejemplo n.º 1
0
int main(int argc, char **argv)
{
  //char *pathname = "special_file";
  int err;
  int num = 1000;
  char *dir = ".";
  char *dirname = "block_dir";
  char *dirname_char = "char_dir";
  char *dirname_pipe = "pipe_dir";
  char *dirname_regular_file = "file_dir";
  char *entries_dir_path;  

  if(argv[1])
    num = atoi(argv[1]);
  
  printf("%d\n",num);
  if ( ulimit_unlimited() == -1 ) {
    fprintf(stderr, "%s:ulimit failed going with default value, Setting %d to 1000\n",
	    strerror(errno),num);
    num = 1000;
  }
  /* Creating 1000 block special files and calculating the time needed for it */
  entries_dir_path = getcwd(entries_dir_path,255);
  mkdir (dirname,0755);
  strcat(entries_dir_path,dirname);
  create_block_special_file(dirname,num);
  rmdir(dirname);

  /* Creating 1000 cgaracter special files and calculating the time needed for it */
  entries_dir_path = getcwd(entries_dir_path,255);
  mkdir (dirname_char,0755); 
  strcat(entries_dir_path,dirname_char);
  create_character_special_file(dirname_char,num);
  rmdir(dirname_char);

  /*Creating 1000 directories and calculating the time needed for it */
  create_directory(dir,num);

  /* Creating 1000 files and calculating the time needed for it */
  entries_dir_path = getcwd(entries_dir_path,255);
  mkdir (dirname_pipe,0755); 
  strcat(entries_dir_path,dirname_pipe);
  create_pipe(dirname_pipe,num);
  rmdir(dirname_pipe);

  /* Creating 1000 regular files and calculating the time needed for it */
  entries_dir_path = getcwd(entries_dir_path,255);
  mkdir (dirname_regular_file,0755); 
  strcat(entries_dir_path,dirname_regular_file);
  create_regular_file(dirname_regular_file,num);
  rmdir(dirname_regular_file);
  
  return 0;
}
Ejemplo n.º 2
0
Archivo: open.c Proyecto: AoLaD/rtems
static int do_open(
  rtems_libio_t *iop,
  const char *path,
  int oflag,
  mode_t mode
)
{
  int rv = 0;
  int fd = rtems_libio_iop_to_descriptor( iop );
  int rwflag = oflag + 1;
  bool read_access = (rwflag & _FREAD) == _FREAD;
  bool write_access = (rwflag & _FWRITE) == _FWRITE;
  bool make = (oflag & O_CREAT) == O_CREAT;
  bool exclusive = (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL);
  bool truncate = (oflag & O_TRUNC) == O_TRUNC;
  int eval_flags = RTEMS_FS_FOLLOW_LINK
    | (read_access ? RTEMS_FS_PERMS_READ : 0)
    | (write_access ? RTEMS_FS_PERMS_WRITE : 0)
    | (make ? RTEMS_FS_MAKE : 0)
    | (exclusive ?  RTEMS_FS_EXCLUSIVE : 0);
  rtems_filesystem_eval_path_context_t ctx;

  rtems_filesystem_eval_path_start( &ctx, path, eval_flags );

  if ( rtems_filesystem_eval_path_has_token( &ctx ) ) {
    create_regular_file( &ctx, mode );
  }

  if ( write_access ) {
    const rtems_filesystem_location_info_t *currentloc =
      rtems_filesystem_eval_path_get_currentloc( &ctx );
    mode_t type = rtems_filesystem_location_type( currentloc );

    if ( S_ISDIR( type ) ) {
      rtems_filesystem_eval_path_error( &ctx, EISDIR );
    }
  }

  iop->flags |= rtems_libio_fcntl_flags( oflag );
  rtems_filesystem_eval_path_extract_currentloc( &ctx, &iop->pathinfo );
  rtems_filesystem_eval_path_cleanup( &ctx );

  rv = (*iop->pathinfo.handlers->open_h)( iop, path, oflag, mode );

  if ( rv == 0 ) {
    if ( truncate ) {
      rv = ftruncate( fd, 0 );
      if ( rv != 0 ) {
        (*iop->pathinfo.handlers->close_h)( iop );
      }
    }

    if ( rv == 0 ) {
      rv = fd;
    } else {
      rv = -1;
    }
  }

  if ( rv < 0 ) {
    rtems_libio_free( iop );
  }

  return rv;
}
Ejemplo n.º 3
0
int command_create(args_t * args)
{
	assert(args != NULL);

	uint32_t block = 0;
	uint32_t size = 0;
	uint32_t pad = 0xff;

	if (parse_size(args->block, &block) < 0)
		return -1;
	if (parse_size(args->size, &size) < 0)
		return -1;
	if (args->pad != NULL)
		if (parse_size(args->pad, &pad) < 0)
			return -1;

	struct stat st;
	if (stat(args->target, &st) < 0) {
		if (errno == ENOENT) {
			create_regular_file(args->target, size, (uint8_t)pad);
		} else {
			ERRNO(errno);
			return -1;
		}
	} else {
		if (st.st_size != size) {
			create_regular_file(args->target, size, (uint8_t)pad);
		} else {
			if (args->force != f_FORCE && st.st_size != size) {
				UNEXPECTED("--size '%d' differs from actual "
					   "size '%lld', use --force to "
					   "override", size, (long long)st.st_size);
				return -1;
			}
		}
	}

	/* ========================= */

	int create(args_t * args, off_t poffset)
	{
		if (args->verbose == f_VERBOSE)
			printf("%llx: create partition table\n", (long long)poffset);

		const char * target = args->target;
		int debug = args->debug;

		RAII(FILE*, file, fopen_generic(target, "r+", debug), fclose);
		if (file == NULL)
			return -1;
		RAII(ffs_t*, ffs, __ffs_fcreate(file, poffset, block,
		     size / block), __ffs_fclose);
		if (ffs == NULL)
			return -1;

		return 0;
	}

	/* ========================= */

	return command(args, create);
}