Пример #1
0
int
cfs_open (const char *name, int flags)
{
  eint8 mode;
  int fd;
  if (sdcard_efs.myCard.sectorCount == 0) return -1;
  fd = find_free_fd();
  if (fd < 0) return -1;
  if (flags == CFS_READ) {
    mode = MODE_READ;
  } else {
    mode = MODE_APPEND;
  }
  if (file_fopen(&file_descriptors[fd], &sdcard_efs.myFs,
		 (char*)name, mode) < 0) {
    return -1;
  }
  return fd;
}
Пример #2
0
/*
*	open_file()
*		Function:	Checks if a file is valid and opens it
*		Inputs:		fname, charstring of the dentry to search for
*		Effect:		Initializes the file_array[8] depending on the file to be opened
*		Returns:	fd, the index of the newly created file descriptor (success)
*					-1, if we could not find a empty file decriptor in file_array[8]
*/
uint32_t open_file(const uint8_t *fname)
{
	int check_file=read_dentry_by_name(fname, &dentry);

	//checks for valid file
	if (dentry.fname == NULL || check_file == -1)
		{
			return -1;
		}
	
	uint32_t fd = find_free_fd( current_pcb ); 
	if(fd==-1)
		return -1;
	if(dentry.ftype==FILE_TYPE_RTC) //user level access to rtc
	{
		((current_pcb->file_array)[fd]).file_ops = &rtc_ops;
		current_pcb->file_array[fd].inode_ptr=0;
		current_pcb->file_array[fd].file_position=0;
		current_pcb->file_array[fd].flags=FILE_IN_USE;
	}
	else if(dentry.ftype==FILE_TYPE_DIR) //file type is directory
	{
		((current_pcb->file_array)[fd]).file_ops = &file_ops;
		current_pcb->file_array[fd].inode_ptr=0;
		current_pcb->file_array[fd].file_position=0;
		current_pcb->file_array[fd].flags=FILE_IN_USE;
	}
	else if(dentry.ftype==FILE_TYPE_REG) //file type is regular
	{
		((current_pcb->file_array)[fd]).file_ops = &file_ops;
		current_pcb->file_array[fd].inode_ptr=(int32_t*)&inodes_array[dentry.inode];
		current_pcb->file_array[fd].file_position=0;
		current_pcb->file_array[fd].flags=FILE_IN_USE;
	}

	return fd;
}