Beispiel #1
0
static void rd_write_section(struct msm_rd_state *rd,
                             enum rd_sect_type type, const void *buf, int sz)
{
    rd_write(rd, &type, 4);
    rd_write(rd, &sz, 4);
    rd_write(rd, buf, sz);
}
int handle_write_call(unsigned long ioctl_arg)
{

    struct read_write_args_t write_args;
    int fd;
    char* address;
    int num_bytes;

    if (0 != copy_from_user(&write_args, (struct read_write_args_t *)ioctl_arg,
                            sizeof(struct read_write_args_t)))
    {
        printk("Error copying creat args from user\n");
        return -1;
    }

    fd = write_args.fd;
    address = write_args.address;
    num_bytes = write_args.num_bytes;

#ifdef DEBUG
    printk("Received write call with args %i, %i, %i\n", fd, (int) address, num_bytes);
#endif

    //	UNCOMMENT TO PASS TO RAMDISK
    //
    write_args.ret_val = rd_write(fd, address, num_bytes);

    if (0 != copy_to_user((void*) ioctl_arg, (void*) &write_args, sizeof(struct read_write_args_t)))
    {
        printk("Error copyting write return value to user level\n");
        return -1;
    }

    return 1;
}
Beispiel #3
0
void rd_write_section(enum rd_sect_type type, const void *buf, int sz)
{
	if (fd == -1) {
		rd_start("unknown", "unknown");
		printf("opened rd, %d\n", fd);
	}

	if (type == RD_GPU_ID) {
		gpu_id = *(unsigned int *)buf;
	}

	rd_write(&type, sizeof(type));
	rd_write(&sz, 4);
	rd_write(buf, sz);
	if (wrap_safe())
		fsync(fd);
}
Beispiel #4
0
int make_seqfile()
{
  int retval, fd;
  retval = rd_creat("/seqfile");
  if (retval < 0) {
    fprintf (stderr, "rd_create: Error creating seqfile! status: %d\n", 
	     retval);
    exit(1);
  }

  retval = rd_open("/seqfile");
  if (retval < 0) {
    fprintf (stderr, "rd_open: Error opening seqfile! status: %d\n", 
	     retval);
    exit(1);
  }
  fd = retval;

#ifdef EXCESSIVE_WRITE_REQUEST  
  retval = rd_write(fd, sequential_data, 2*MAX_FILE_SIZE);
  if (retval > MAX_FILE_SIZE) {
    fprintf (stderr, "rd_write: Reportedly wrote too much data! status: %d\n", 
	     retval);
    exit(1);
  }
#else
  retval = rd_write(fd, sequential_data, MAX_FILE_SIZE);
  if (retval > MAX_FILE_SIZE) {
    fprintf (stderr, "rd_write: Reportedly wrote too much data! status: %d\n", 
	     retval);
    exit(1);
  }
#endif  

  if ((retval = rd_close(fd)) < 0) {
    fprintf (stderr, "rd_close: Error closing seqfile! status: %d\n", 
	     retval);
    exit(1);
  }
  
  return 0;
  
}
int main() {

	char a = 'a';
	rd_read(3, &a, 12);

	rd_close(10);

	rd_write(5, &a, 10);
	rd_seek(6, 14);
	rd_readdir(12, &a);
}
Beispiel #6
0
void rd_write_section(enum rd_sect_type type, const void *buf, int sz)
{
	uint32_t val = ~0;

	if (fd == -1) {
		const char *name = getenv("TESTNAME");
		if (!name)
			name = "unknown";
		rd_start(name, "");
		printf("opened rd, %d\n", fd);
	}

	if (type == RD_GPU_ID) {
		gpu_id = *(unsigned int *)buf;
	}

	rd_write(&val, 4);
	rd_write(&val, 4);

	rd_write(&type, 4);
	val = ALIGN(sz, 4);
	rd_write(&val, 4);
	rd_write(buf, sz);

	val = 0;
	rd_write(&val, ALIGN(sz, 4) - sz);

	if (wrap_safe())
		fsync(fd);
}
Beispiel #7
0
void inline rd_write_block(void *ram, void *mem)
{
        rd_write(ram, mem, 1);
}
Beispiel #8
0
static int ramdisk_ioctl(struct inode *inode, struct file *file, 
                         unsigned int cmd, unsigned long arg)
{
	char cur_path[100];
	char (*list)[14];
	char *pathname;
	int ret = ERROR;
	int size;
	int *fd;
	file_info_t *file_info;
	dirctory_entry_t *dirctory_entry;
	switch (cmd)
	{
		case IOCTL_PWD:
			strcpy(cur_path, rd_pwd());
			ret = copy_to_user((char *)arg, cur_path, sizeof(cur_path));
			return ret;
		case IOCTL_LS:
			list = (char *)vmalloc(sizeof(char) * 1024 * 14);
			memset((char *) list, 0, 1024 * 14);
			if ((ret = rd_ls(list)) != ERROR )
				ret = copy_to_user((char **)arg, list, 1024 * 14);
			vfree(list);
			return ret;
		case IOCTL_CREAT:
			size = sizeof(char) * (strlen((char *)arg) + 1);
            pathname = (char*)vmalloc(size);
            copy_from_user(pathname, (char *)arg, size);
            ret = rd_creat(pathname);
            vfree(pathname);
            return ret;
		case IOCTL_MKDIR:
		 	size = sizeof(char) * (strlen((char *)arg) + 1);
            pathname = (char*)vmalloc(size);
            copy_from_user(pathname, (char *)arg, size);
            ret = rd_mkdir(pathname);
            vfree(pathname);
			return ret;
		case IOCTL_UNLINK:
			size = sizeof(char) * (strlen((char *)arg) + 1);
            pathname = (char*)vmalloc(size);
            copy_from_user(pathname, (char *)arg, size);
			ret = rd_unlink(pathname);
            vfree(pathname);
            return ret;
        case IOCTL_OPEN:
			size = sizeof(char) * (strlen((char *)arg) + 1);
            pathname = (char*)vmalloc(size);
            copy_from_user(pathname, (char *)arg, size);
            ret = rd_open(pathname);
            vfree(pathname);
			return ret;
		case IOCTL_CLOSE:
			size = sizeof(int);
			fd = (int *)vmalloc(size);
            copy_from_user(fd, (int *)arg, size);
            ret = rd_close(*fd);
			return ret;
		case IOCTL_WRITE:
			size = sizeof(file_info_t);
			file_info = (file_info_t *)vmalloc(size);
            copy_from_user(file_info, (file_info_t *)arg, size);
            ret = rd_write(file_info->fdt_index, file_info->input, file_info->size);
            vfree(file_info);
			return ret;
		case IOCTL_READ:
			size = sizeof(file_info_t);
			file_info = (file_info_t *)vmalloc(size);
            copy_from_user(file_info, (file_info_t *)arg, size);
            ret = rd_read(file_info->fdt_index, file_info->input, file_info->size);
            copy_to_user((file_info_t *)arg, file_info, size);
            vfree(file_info);
			return ret;
		case IOCTL_READDIR:
			size = sizeof(file_info_t);
			file_info = (file_info_t *)vmalloc(size);
            copy_from_user(file_info, (file_info_t *)arg, size);
            ret = rd_readdir(file_info->fdt_index, file_info->input);
            dirctory_entry = (dirctory_entry_t *)file_info->input;
            copy_to_user((file_info_t *)arg, file_info, size);
            vfree(file_info);
			return ret;
		case IOCTL_LSEEK:
			size = sizeof(file_info_t);
			file_info = (file_info_t *)vmalloc(size);
            copy_from_user(file_info, (file_info_t *)arg, size);
            ret = rd_lseek(file_info->position, file_info->fdt_index);
            vfree(file_info);
		default:
			break;
	}

	return ret;
}
Beispiel #9
0
int main () {
    
  int retval, i;
  int fd;
  int index_node_number;

  /* Some arbitrary data for our files */
  memset (data1, '1', sizeof (data1));
  memset (data2, '2', sizeof (data2));
  memset (data3, '3', sizeof (data3));


#ifdef TEST1

  /* ****TEST 1: MAXIMUM file creation**** */

  /* Assumes the pre-existence of a root directory file "/"
     that is neither created nor deleted in this test sequence */

  /* Generate MAXIMUM regular files */
  for (i = 0; i < MAX_FILES + 1; i++) { // go beyond the limit
    sprintf (pathname, "/file%d", i);
    
    retval = rd_creat (pathname);
    
    if (retval < 0) {
      fprintf (stderr, "rd_create: File creation error! status: %d\n", 
	       retval);
      
      if (i != MAX_FILES)
	exit (1);
    }
    
    memset (pathname, 0, 80);
  }   

  /* Delete all the files created */
  for (i = 0; i < MAX_FILES; i++) { 
    sprintf (pathname, "/file%d", i);
    
    retval = rd_unlink (pathname);
    
    if (retval < 0) {
      fprintf (stderr, "rd_unlink: File deletion error! status: %d\n", 
	       retval);
      
      exit (1);
    }
    
    memset (pathname, 0, 80);
  }

#endif // TEST1
  
#ifdef TEST2

  /* ****TEST 2: LARGEST file size**** */

  
  /* Generate one LARGEST file */
  retval = rd_creat ("/bigfile");

  if (retval < 0) {
    fprintf (stderr, "rd_creat: File creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval =  rd_open ("/bigfile"); /* Open file to write to it */
  
  if (retval < 0) {
    fprintf (stderr, "rd_open: File open error! status: %d\n", 
	     retval);

    exit (1);
  }

  fd = retval;			/* Assign valid fd */

  /* Try writing to all direct data blocks */
  retval = rd_write (fd, data1, sizeof(data1));
  
  if (retval < 0) {
    fprintf (stderr, "rd_write: File write STAGE1 error! status: %d\n", 
	     retval);

    exit (1);
  }

#ifdef TEST_SINGLE_INDIRECT
  
  /* Try writing to all single-indirect data blocks */
  retval = rd_write (fd, data2, sizeof(data2));
  
  if (retval < 0) {
    fprintf (stderr, "rd_write: File write STAGE2 error! status: %d\n", 
	     retval);

    exit (1);
  }

#ifdef TEST_DOUBLE_INDIRECT

  /* Try writing to all double-indirect data blocks */
  retval = rd_write (fd, data3, sizeof(data3));
  
  if (retval < 0) {
    fprintf (stderr, "rd_write: File write STAGE3 error! status: %d\n", 
	     retval);

    exit (1);
  }

#endif // TEST_DOUBLE_INDIRECT

#endif // TEST_SINGLE_INDIRECT

#endif // TEST2

#ifdef TEST3

  /* ****TEST 3: Seek and Read file test**** */
  retval = rd_lseek (fd, 0);	/* Go back to the beginning of your file */

  if (retval < 0) {
    fprintf (stderr, "rd_lseek: File seek error! status: %d\n", 
	     retval);

    exit (1);
  }

  /* Try reading from all direct data blocks */
  retval = rd_read (fd, addr, sizeof(data1));
  
  if (retval < 0) {
    fprintf (stderr, "rd_read: File read STAGE1 error! status: %d\n", 
	     retval);

    exit (1);
  }
  /* Should be all 1s here... */
  printf ("Data at addr: %s\n", addr);

#ifdef TEST_SINGLE_INDIRECT

  /* Try reading from all single-indirect data blocks */
  retval = rd_read (fd, addr, sizeof(data2));
  
  if (retval < 0) {
    fprintf (stderr, "rd_read: File read STAGE2 error! status: %d\n", 
	     retval);

    exit (1);
  }
  /* Should be all 2s here... */
  printf ("Data at addr: %s\n", addr);

#ifdef TEST_DOUBLE_INDIRECT

  /* Try reading from all double-indirect data blocks */
  retval = rd_read (fd, addr, sizeof(data3));
  
  if (retval < 0) {
    fprintf (stderr, "rd_read: File read STAGE3 error! status: %d\n", 
	     retval);

    exit (1);
  }
  /* Should be all 3s here... */
  printf ("Data at addr: %s\n", addr);

#endif // TEST_DOUBLE_INDIRECT

#endif // TEST_SINGLE_INDIRECT

  /* Close the bigfile */
  retval = rd_close (fd);
  
  if (retval < 0) {
    fprintf (stderr, "rd_close: File close error! status: %d\n", 
	     retval);

    exit (1);
  }

  /* Remove the biggest file */

  retval = rd_unlink ("/bigfile");
	
  if (retval < 0) {
    fprintf (stderr, "rd_unlink: /bigfile file deletion error! status: %d\n", 
	     retval);
    
    exit (1);
  }

#endif // TEST3

#ifdef TEST4
  
  /* ****TEST 4: Make directory and read directory entries**** */
  retval = rd_mkdir ("/dir1");
    
  if (retval < 0) {
    fprintf (stderr, "rd_mkdir: Directory 1 creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval = rd_mkdir ("/dir1/dir2");
    
  if (retval < 0) {
    fprintf (stderr, "rd_mkdir: Directory 2 creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval = rd_mkdir ("/dir1/dir3");
    
  if (retval < 0) {
    fprintf (stderr, "rd_mkdir: Directory 3 creation error! status: %d\n", 
	     retval);

    exit (1);
  }

  retval =  rd_open ("/dir1"); /* Open directory file to read its entries */
  
  if (retval < 0) {
    fprintf (stderr, "rd_open: Directory open error! status: %d\n", 
	     retval);

    exit (1);
  }

  fd = retval;			/* Assign valid fd */

  memset (addr, 0, sizeof(addr)); /* Clear scratchpad memory */

  while ((retval = rd_readdir (fd, addr))) { /* 0 indicates end-of-file */

    if (retval < 0) {
      fprintf (stderr, "rd_readdir: Directory read error! status: %d\n", 
	       retval);
      
      exit (1);
    }

    index_node_number = atoi(&addr[14]);
    printf ("Contents at addr: [%s,%d]\n", addr, index_node_number);
  }

#endif // TEST4

#ifdef TEST5

  /* ****TEST 5: 2 process test**** */
  
  if((retval = fork())) {

    if(retval == -1) {
      fprintf(stderr, "Failed to fork\n");
      
      exit(1);
    }

    /* Generate 300 regular files */
    for (i = 0; i < 300; i++) { 
      sprintf (pathname, "/file_p_%d", i);
      
      retval = rd_creat (pathname);
      
      if (retval < 0) {
	fprintf (stderr, "(Parent) rd_create: File creation error! status: %d\n", 
		 retval);

	exit(1);
      }
    
      memset (pathname, 0, 80);
    }  
    
  }
  else {
    /* Generate 300 regular files */
    for (i = 0; i < 300; i++) { 
      sprintf (pathname, "/file_c_%d", i);
      
      retval = rd_creat (pathname);
      
      if (retval < 0) {
	fprintf (stderr, "(Child) rd_create: File creation error! status: %d\n", 
		 retval);

	exit(1);
      }
    
      memset (pathname, 0, 80);
    }
  }

#endif // TEST5


  fprintf(stdout, "Congratulations,  you have passed all tests!!\n");

  return 0;
}