Пример #1
0
/* read file */
int 
read(int fd, void *buffer, unsigned size)
{
	int read_size = 0;
	struct file *current_file;
	char *read_buffer = (char *)buffer;
    
	lock_acquire(&file_lock);

	if(fd == 0)              /* stdin */
	{
		read_buffer[read_size]=input_getc();
		while(read_buffer[read_size] != '\n' && read_size < size)
		{
			read_size++;
			read_buffer[read_size]=input_getc();
		}
		read_buffer[read_size]='\0';
	}
	else
	{
		current_file = process_get_file(fd);
		if(current_file != NULL)
		{
			read_size = file_read(current_file,buffer,size);
		}
	}
	lock_release(&file_lock);
	return read_size;
}
Пример #2
0
static int
byte(void)
{
    int             c;

    assert(input);
    for (;;)
    {
        c = input_getc(input);
        switch (c)
        {
        case INPUT_EOF:
            bol = 1;
            break;

        case '\n':
            ++line_number;
            bol = 1;
            first = 1;
            colon_special = 1;
            break;

        case ' ':
        case '\t':
        case '\f':
#if __STDC__ >= 1
        case '\v':
#endif
            bol = 0;
            break;

        case '\\':
            c = input_getc(input);
            if (c == '\n')
            {
                ++line_number;
                continue;
            }
            if (c != INPUT_EOF)
                input_ungetc(input, c);
            c = '\\';
            /* fall through... */

        default:
            bol = 0;
            first = 0;
            break;
        }
        return c;
    }
}
Пример #3
0
static int sys_read(int fd, void* buffer, unsigned size)
{
  struct thread *curr=thread_current();
  struct opened_file_elem *opened_elem;
  int real_size;
  struct list_elem *e;
  int i;
  int check_valid=0;

  if(fd==0)
  {
    i=0;
    while(size>0 &&  input_getc()!="\xa")
    {
      *(char*)(buffer + i) = input_getc();
      size+=-1;
      i++;
    }
    *(char*) (buffer + i) = "\x00";
    return i;
  }
  else if(fd<=1)
  {
    return -1;
  }
  else
  {
    for( e = list_begin(&curr->openfile_list) ; e != list_end(&curr->openfile_list) ;
        e = list_next(e) )
    {
      opened_elem=list_entry(e,struct opened_file_elem,elem_f);
      if(opened_elem->fd==fd)
      {
        check_valid=1;
//        printf("file read start \n");
//        printf("%d %d\n", opened_elem->fd,fd);
//          printf(" %p \n",&opened_elem->opened_file);
        real_size = file_read(opened_elem->opened_file,buffer,size);
//        printf("%d ========\n",real_size);
//        printf("file read finish\n");
//        printf("%s\n",buffer);
        return real_size;
      }
    }
  }
  if(check_valid==0)
    return -1;
}
Пример #4
0
int
read(int fd, void *buffer, unsigned size)
{
    struct thread *t = thread_current();
    if (fd == 0) {
        unsigned i;
        uint8_t *buf = buffer;

        lock_acquire(&filesys_lock);
        for (i = 0; i < size; i++) {
            buf[i] = input_getc();
        }
        lock_release(&filesys_lock);
        return size;
    } else {
        uint8_t *buf = buffer;

        struct file_handle *fh = thread_get_fh(&t->files, fd);

        if (fh == NULL) {
            exit(-1);
        }

        lock_acquire(&filesys_lock);
        off_t read = file_read(fh->file, buf, size);
        lock_release(&filesys_lock);
 
        return read;
    }
}
int syscall_read(int fd, void *buffer, unsigned size){
	/* Reads size bytes from the file open as fd into buffer.
	 *
	 * Returns the number of bytes actually read (0 at end of file),
	 * or -1 if the file could not be read (due to a condition
	 * other than end of file).
	 * 
	 * FD 0 reads from the keyboard using input_getc(). (ref:man29-31)
	 */
	int ret = -1;
	unsigned i;
    if(!is_valid_ptr(buffer))
	    syscall_exit(-1);
	if(fd == 0){
		// STDIN 0
		for(i = 0; i < size; i++){
			uint8_t buf = input_getc();
			memset((buffer + i * sizeof(uint8_t)), buf, sizeof(uint8_t));
		}
		ret = i;
	}else{
		// 0. Find fd.
		struct fd_list *found = Search_FD(&(thread_current()->FDs), fd);
		if(!found)
			return -1;
		lock_acquire(&(found->file->inode->lock));
		ret = file_read(found->file, buffer, size);
		lock_release(&(found->file->inode->lock));
	}
	return ret;
}
Пример #6
0
/*
 * System Call: int read (int fd, void *buffer, unsigned size)
 * Reads size bytes from the file open as fd into buffer. Returns
 * the number of bytes actually read (0 at end of file), or -1 if
 * the file could not be read (due to a condition other than end of file).
 * Fd 0 reads from the keyboard using input_getc().
 */
int read_handler(int fd, void *buffer, unsigned size) {
	if (buffer_access_ok(buffer, size, true)) {
		/*
		 * TODO:
		 * buffer needs to be pinned during I/O
		 */
//		frame_pin_buffer(buffer,size);
		if (fd == STDIN_FILENO){
			unsigned i;
			char* local_buffer = (char *) buffer;
			for (i = 0; i < size; i++) {
				local_buffer[i] = input_getc();
			}
//			frame_unpin_buffer(buffer,size);
			return size;
		}
		lock_acquire (&fic_m);
		struct file* f = findfd(fd);
		if (f != NULL) {
			int ret =  file_read (f, buffer, size);
			lock_release (&fic_m);
//			frame_unpin_buffer(buffer,size);
			return ret;
		}
		lock_release (&fic_m);
	}
//	frame_unpin_buffer(buffer,size);
	return -1;
}
Пример #7
0
/* Reads up to size bytes from the file open with descriptor fd into buffer,
   and returns the actual number of bytes read (may be less than size if EOF
   is reached), or -1 if no file is open as fd, or the read fails for any
   other reason.  Calling read with fd = 0 will read input from standard input,
   blocking until size bytes have been read */
static int
sys_read (int fd, void *buffer, unsigned size)
{
  check_ptr (buffer);
  
  unsigned read;
  struct file_fd *ffd;
  char *char_buffer = buffer;

  switch (fd) {
  case 0:
    for (read = 0; read < size; read++) {
      char_buffer[read] = input_getc ();
    }
    return read;
  case 1:
    return -1;
  case 2:
    return -1;
  default:
    ffd = get_file_fd (fd);
    if (ffd == NULL)
      return -1;
    lock_acquire (&fs_lock);
    read = file_read (ffd->file, buffer, size);
    lock_release (&fs_lock);
    return read;
  }
}
Пример #8
0
int syscall_read(void)
{
	int fd = (int) next_arg();
	void *buf = next_arg();
	int size = (int) next_arg();
	
   //Don't perform operation if size is zero
   if(size == 0)
     return 0;
	  
   //Read from stdin
   if(fd==0)
   {
     int i;
     char * char_buffer = buf;
     for(i=0; i < size; i++)
     {
       char_buffer[i] = input_getc();
     }
     return size;
   }
   //Perform operation onbly if the given fd is in the calling threads
   //open fd list 
   else if(thread_has_fd(fd))
   {
        return file_read(file_get_file(fd),buf,size);
   }
   return -1;
}
Пример #9
0
int sys_read(int fd, void* buffer, unsigned size)
{
  if(fd == STDOUT_FILENO)
    return 0;
  else if(fd == STDIN_FILENO)
  {
    unsigned i = 0;
    char* buf = (char*) buffer;
    for(; i < size; ++i)
      buf[i] = input_getc();
    return 0;
  }
  else if(fd < FDTABLESIZE && fd > 1)
  {
    struct thread *cur = thread_current ();
    struct file* fi = cur->fd_table[fd];
    if(fi)
    {
      int ret;
      lock_acquire(&filesys_lock);
      ret = file_read(fi, buffer, size);
      lock_release(&filesys_lock);
      return ret;
    }
  }
  return 0;
}
Пример #10
0
/* Reads a file into specified buffer and returns number of chars read or -1. */
static int syscall_read(int fd, void *buf, unsigned size)
{
  int ret_val;
  struct fd_elem **fdt = thread_current()->open_files;

  /* Verify user supplied buffer is valid. */
  validate_buffer(buf, size);

  if(fd == STDIN_FILENO) { /* Read from stdin. */
    char *c = buf;
    while((void *) c < buf + size)
      *c++ = input_getc();
    ret_val = size;

  } else if(fd >= 2 && fd < 128 && fdt[fd] != NULL) {
    /* If fd is valid, read from file. */
    lock_acquire(&fs_lock);
    ret_val = file_read(fdt[fd]->file, buf, size);
    lock_release(&fs_lock);

  } else /* fd not valid. */
    ret_val = -1;

  return ret_val;
}
Пример #11
0
static int read_handler (int fd, void *buffer, unsigned size) {
  // Verifies that the buffer is a user virtual address as well as verifies it is mapped to kernel virtual memory
  if (!is_user_vaddr(buffer + size) || pagedir_get_page(thread_current()->pagedir, buffer) == NULL) {
    exit_handler(-1);
  }

  int num_bytes_read = 0;
  if (fd == STDIN_FILENO) {
    // Special case reading from STDIN
    char * buffy = (char *) buffer;
    while (num_bytes_read < (int) size) {
      char chary = input_getc();
      buffy[num_bytes_read] = chary;
      num_bytes_read++;
    }
  } else if (fd == STDOUT_FILENO) {
    // Can not read from STDOUT, so gracefully exit program
    exit_handler(-1);
  } else {
    // Should be dealing with a normal file, if so use given functions
    struct file_struct * file_reading = get_file(fd);
    if (file_reading != NULL && file_reading->sys_file != NULL) {
      num_bytes_read = file_read(file_reading->sys_file, buffer, size);
    } else {
      // Was not able to read from file so return -1 
      num_bytes_read = -1;
    }
  }
  
  return num_bytes_read;
}
Пример #12
0
/* Read file to buffer */
int 
read(int fd,void* buffer,unsigned size)
{
	struct thread* t = thread_current();
	struct file* f = t->file_desc_table[fd];
	unsigned char c;
	int ret_size = 0;
	if( fd == 0 ) /*Standard input*/
	{
		if(!stdio_lock_init)
		{
			stdio_lock_init = true;
			lock_init(&stdio_lock);
		}
		lock_acquire(&stdio_lock);
		while( ret_size < size )
		{
			c = input_getc();
			memcpy(buffer+ret_size,&c,sizeof(unsigned char));
			ret_size++;
		}
		lock_release(&stdio_lock);
	}
	else
	{
		ret_size = file_read(f,buffer,size);
	}
	return (int)ret_size;
}
Пример #13
0
static int 
my_read(int fd, void *buffer, unsigned size)
{
	lock_acquire(&filesys_lock);
	if(!address_valid(buffer)){
		lock_release(&filesys_lock);
		my_exit(-1);
	}
	if(fd == STDIN_FILENO){
		unsigned i = 0;
		uint8_t* local_buffer = (uint8_t *)buffer;
		for(;i< size; i++)
			local_buffer[i] = input_getc();
		lock_release(&filesys_lock);
		return size;
	}
	
	struct file * fp = get_file_by_fd(fd);
	
	if(!fp){
		lock_release(&filesys_lock);
		return -1;
	}
	
	int byte = file_read(fp, buffer, size);
	lock_release(&filesys_lock);
	return byte;

}
Пример #14
0
int read (int fd, void *buffer, unsigned size)
{
  unsigned i = 0;

  if (fd == STDOUT_FILENO)
    return -1;

  if (fd == STDIN_FILENO)
  {
    uint8_t *local_buffer = (uint8_t*) buffer;

    for (i = 0; i < size; i++)
    {
      local_buffer[i] = input_getc();
    }
  return size;
  }

  lock_acquire (&filesys_lock);

  struct file *f = process_get_file (fd);
  if (!f)
  {
    lock_release (&filesys_lock);
    return -1;
  }

  int bytes = file_read (f, buffer, size);

  lock_release (&filesys_lock);

  return bytes;
}
Пример #15
0
/* Read system call. */
static int
sys_read (int handle, void *udst_, unsigned size) 
{
  uint8_t *udst = udst_;
  struct file_descriptor *fd;
  int bytes_read = 0;

  /* Look up file descriptor. */
  if (handle != STDIN_FILENO)
    fd = lookup_file_fd (handle);

  while (size > 0) 
    {
      /* How much to read into this page? */
      size_t page_left = PGSIZE - pg_ofs (udst);
      size_t read_amt = size < page_left ? size : page_left;
      off_t retval;

      /* Check that touching this page is okay. */
      if (!page_lock (udst, true)) 
        thread_exit ();

      /* Read from file into page. */
      if (handle != STDIN_FILENO) 
        {
          retval = file_read (fd->file, udst, read_amt);
          if (retval < 0)
            {
              if (bytes_read == 0)
                bytes_read = -1; 
              break;
            }
          bytes_read += retval; 
        }
      else 
        {
          size_t i;
          
          for (i = 0; i < read_amt; i++) 
            udst[i] = input_getc ();
          bytes_read = read_amt;
        }

      /* Release page. */
      page_unlock (udst);

      /* If it was a short read we're done. */
      if (retval != (off_t) read_amt)
        break;

      /* Advance. */
      udst += retval;
      size -= retval;
    }
   
  return bytes_read;
}
Пример #16
0
/* Yuqi's change:
 * getline() function: gets a line from input. */
void getline(char* in)
{
	char cmd[255];
	int i = 0;
	while ((cmd[i] = input_getc()) != '\r') {
	    printf("%c", cmd[i]);
	    i++;
	}
	
	cmd[i+1] = '\0';
	strlcpy(in, cmd, strlen(cmd));
	printf("\n");
}
Пример #17
0
static int syscall_read(int fd, char* content, unsigned content_size){
	if(fd == STDIN_FILENO){//standard input stream
		unsigned i=0;
		for(;i<content_size;i++){
			content[i] = input_getc(); // Read command line by using input_getc();
		}
		return (int)i;
	}else{
		struct file* f = file_find(fd);
		if(f != NULL) return file_read(f, content, content_size);
		else return -1;
	}
}
Пример #18
0
/* Reads 'size' bytes from file open as fd into buffer. Returns number of
   bytes actually read - 0 at end of file, or -1 if file could not be read.
   fd = 0 reads from the keyboard. */
static int
sys_read(int fd, void *buffer, unsigned size, struct intr_frame *f) 
{
  /* Cannot read from stdout. */
  if (fd == STDOUT_FILENO)
    sys_exit(ERROR);
  int bytes;
  void *buf_iter = pg_round_down(buffer);

  check_fd(fd);
  check_buffer(buffer, size);

  lock_acquire(&secure_file);

  for (; buf_iter <= buffer + size; buf_iter += PGSIZE) {
    struct spt_entry *entry = get_spt_entry(&thread_current()->supp_pt, buf_iter);
    if (entry == NULL && should_stack_grow(buf_iter, f->esp)) {
      grow_stack(buf_iter);
    } 
  }

  /* fd = 0 corresponds to reading from stdin. */
  if (fd == STDIN_FILENO) 
  {
    unsigned i;
    uint8_t keys[size];
    /* Make an array of keys pressed. */
    for (i = 0; i < size; i++) 
    {
      keys[i] = input_getc();
    }
    /* Put these keys pressed into the buffer. */
    memcpy(buffer, (const void *) keys, size);
    /* Must have successfully read all bytes we were told to. */
    bytes = size;
  } else {

    struct file *f = get_file(fd);
    if (!f) 
    {
      lock_release(&secure_file);
      return ERROR;
    }
    bytes = file_read(f, buffer, size);
  }

  lock_release(&secure_file);
  return bytes;
}
Пример #19
0
int SYS_READ_handler(int32_t* esp)
{
  
  int fd = *(esp + 1);
  char* buffer = (char*)*(esp + 2);
  int len = *(esp + 3);


  if(verify_fix_length(esp[2], esp[3]) == false){
	sys_exit(-1);
  }

  DEBUG_SYSCALL(" # SYS_READ fd: %i ", fd);

  // Default to error...
  int retVal = -1;
  if(fd == STDIN_FILENO){
    int writtenCharacters = 0;
    while(writtenCharacters < len){
      uint8_t c = input_getc ();

      // Replace all \r with \n because output
      // will be weird looking otherwise
      if(c == '\r'){
        c = '\n';
      }

      *(buffer + writtenCharacters) = c;

      // Print typed character on screen
      putbuf(&c, 1);
      writtenCharacters++;
    }
    // We read data, set return value to bytes read.
    retVal = writtenCharacters;
  }
  else if(fd > 1){

	// A file descriptor has been used.
	struct file* file = flist_get_process_file(fd);
	if(file != NULL){
		retVal = file_read(file, buffer, len);
	}  
	
  }
  return retVal;
}
Пример #20
0
/*! Read from file */
int read(uint32_t fd, void *buffer, unsigned size) {
    uint8_t* addr_e;
    struct supp_table* st;
    
    /* Check the validity of given pointer */
    if ((!checkva(buffer)) || (!checkva(buffer + size))){
        exit(-1);
    }
    
    for (addr_e = (uint8_t*) pg_round_down(buffer); 
         addr_e < (uint8_t*) buffer + size; addr_e += PGSIZE){
        st = find_supp_table(addr_e);
        if (st && !st->writable)
            exit(-1);
    }
    
    int read_size = 0;
    if (fd == STDIN_FILENO) {
        /* If std-in, then read using input_getc() */
        unsigned i;
        for (i = 0; i < size; i++){
            *((uint8_t*) buffer) = input_getc();
            ++ read_size;
            ++ buffer;
        }
    } else {
        /* Otherwise, first find the file of this fd. */
        struct f_info* f = findfile(fd);
        
        /* We should read a dir like a file. */
        if (f->isdir)
            exit(-1);
        
        struct file* fin = f->f;
        off_t pos = f->pos;
        
        /* Read from the file at f->pos */
        //lock_acquire(&filesys_lock);
        read_size = (int) file_read_at(fin, buffer, (off_t) size, pos);
        f->pos += (off_t) read_size;
        //lock_release(&filesys_lock);
        
    }
    return read_size;

}
Пример #21
0
static void sys_read(struct intr_frame *f_)
{
  unsigned int *esp = f_->esp;
  int fd = *(esp + 1);
  char *buffer = *(esp + 2);
  unsigned int size = *(esp + 3);
  struct file *f;
  
  if (fd == STDIN_FILENO) f_->eax = input_getc();
  else if (fd < 3) f_->eax = -1;
  else
  {
    f = file_search_in_fd(fd);
    if (f == NULL) f_->eax = -1;
    else f_->eax = file_read(f, buffer, size);
  }
}
Пример #22
0
static int
syscall_read (int fd, char *buffer, unsigned size)
{
	struct file *f;	

	// if the FD is 0, read STDIN
	if (fd == 0) {
		unsigned i;
		for (i = 0; i < size; i++)
			buffer[i] = (char)input_getc();
		return (int)i;
	}

	f = process_file_find (fd);
	if (f == NULL)
		return -1;
	return file_read(f, buffer, size);
}
Пример #23
0
/* Syscall handler for when a syscall read is invoked. */
static int read (int fd, void *buffer, unsigned length) {
  int size = -1;
  if (fd == STDIN_FILENO) {
    uint8_t *buffer_copy = (uint8_t *) buffer;
    unsigned i;
    for (i = 0; i < length; i++)
      buffer_copy[i] = input_getc();
    size = length;
  } else if (fd == STDOUT_FILENO) {
    size = -1;
  } else {
    struct file_wrapper *curr = fd_to_file_wrapper(fd);
    if (!curr)
      exit(-1);
    lock_acquire(&file_lock);
    size = file_read(curr->file, buffer, length);
    lock_release(&file_lock);
  }
  return size;
}
Пример #24
0
int sys_read(int fd, void *buffer, unsigned size) {
  // memory validation : [buffer+0, buffer+size) should be all valid
  check_user((const uint8_t*) buffer);
  check_user((const uint8_t*) buffer + size - 1);

  lock_acquire (&filesys_lock);
  int ret;

  if(fd == 0) { // stdin
    unsigned i;
    for(i = 0; i < size; ++i) {
      if(! put_user(buffer + i, input_getc()) ) {
        lock_release (&filesys_lock);
        sys_exit(-1); // segfault
      }
    }
    ret = size;
  }
  else {
    // read from file
    struct file_desc* file_d = find_file_desc(thread_current(), fd, FD_FILE);

    if(file_d && file_d->file) {

#ifdef VM
      preload_and_pin_pages(buffer, size);
#endif

      ret = file_read(file_d->file, buffer, size);

#ifdef VM
      unpin_preloaded_pages(buffer, size);
#endif
    }
    else // no such file or can't open
      ret = -1;
  }

  lock_release (&filesys_lock);
  return ret;
}
Пример #25
0
int read (int fd, void* buffer, unsigned size)
{
    //Read from stdin
    if (fd == STDIN_FILENO) {
        unsigned i;
        uint8_t* buf = (uint8_t*)buffer;
        for (i = 0; i < size; ++i)
            buf[i] = input_getc();
        return size;
    }

    //Fail if file is not open
    struct file_info* f = get_file(fd);
    if (!f) return -1;

    //Do filesys call
    lock_acquire(&file_lock);
    int ret = file_read(f->file, buffer, size);
    lock_release(&file_lock);
    return ret;
}
Пример #26
0
static int syscall_read (int fd, void *buffer, unsigned size)
{
  pin_buffer (buffer, size, true);
  int retval = -1;

  if (fd == STDIN_FILENO) {
    unsigned int i = 0;
    for (; i < size; i++)
      *((char *) buffer + size) = input_getc();
    retval = 0;
  } else {    
    struct file_with_lock fwl = fwl_from_fd (fm, fd);
    if (fwl.fp && fwl.mode == FM_MODE_FD) {
      lock_acquire (fwl.lock);
      retval = file_read (fwl.fp, buffer, size);
      lock_release (fwl.lock);
    }
  }

  pin_buffer (buffer, size, false);
  return retval;
}
Пример #27
0
/*
 * System Call: int read (int fd, void *buffer, unsigned size)
 * Reads size bytes from the file open as fd into buffer. Returns
 * the number of bytes actually read (0 at end of file), or -1 if
 * the file could not be read (due to a condition other than end of file).
 * Fd 0 reads from the keyboard using input_getc().
 */
int read_handler(int fd, void *buffer, unsigned size) {
	//printf("read...\n");
	if (buffer_access_ok(buffer, size)) {
		if (fd == STDIN_FILENO){
			unsigned i;
			char* local_buffer = (char *) buffer;
			for (i = 0; i < size; i++) {
				local_buffer[i] = input_getc();
			}
			return size;
		}
		lock_acquire (&fic_m);
		struct file* f = findfd(fd);
		if (f != NULL) {
			int ret =  file_read (f, buffer, size);
			lock_release (&fic_m);
			return ret;
		}
		lock_release (&fic_m);
	}
	return -1;
}
Пример #28
0
int sys_read(int fd, char* buffer, unsigned length)
{
    if (fd == STDOUT_FILENO)
        return -1; // Vi kan inte läsa från skärmen

    unsigned i = 0;
    char key;
    for (i = 0; i != length; i++)
    {
        if (fd == STDIN_FILENO) // Tangentbord
        {
            key = (char)input_getc();

            if (key == '\r') // enter
            {
                key = '\n'; // lägg till ny rad-tecken
                buffer[i] = key;
                break;
            }
            else
                buffer[i] = key;

            putbuf(&buffer[i], 1);
        }
        else
        {
            //Read from file
            struct file* read_from = map_find(get_filemap(), fd);

            if(read_from != NULL && length > 0)
                return file_read(read_from, buffer, length);
            else
                return -1;
        }
    }

    return length; // Så här många tecken läste jag
}
Пример #29
0
/* Reads a line of input from the user into LINE, which has room
   for SIZE bytes.  Handles backspace and Ctrl+U in the ways
   expected by Unix users.  On return, LINE will always be
   null-terminated and will not end in a new-line character. */
static void
read_line (char line[], size_t size) 
{
  char *pos = line;
  for (;;)
    {
      char c;
      c = input_getc ();

      switch (c) 
        {
        case '\r':
          *pos = '\0';
          printf ("\n");
          return;

        case '\b':
          backspace (&pos, line);
          break;

        case ('U' - 'A') + 1:       /* Ctrl+U. */
          while (backspace (&pos, line))
            continue;
          break;

        default:
          /* Add character to line. */
          if (pos < line + size - 1) 
            {
              printf ("%c",c);
              *pos++ = c;
            }
          break;
        }
    }
}
Пример #30
0
int 
read (int fd, void *buffer, unsigned size)
{
  if (not_valid(buffer) || not_valid(buffer+size) || fd == STDOUT_FILENO)
    exit (-1);
  lock_acquire(&file_lock);
  int count = 0, result = 0;
  if (fd == STDIN_FILENO)
    {
      while (count < size)
        {
          *((uint8_t *) (buffer + count)) = input_getc ();
          count++;
        }
      result = size;
    }
  else 
    {
      struct file *file = get_file(fd);
      result = file ? file_read(file, buffer, size) : -1;
    }
  lock_release(&file_lock);
  return result;
}