* this function will read specified length data from a file descriptor to a * buffer. * * @param fd the file descriptor. * @param buf the buffer to save the read data. * @param len the length of data buffer to be read. * * @return the actual read data bytes or 0 on end of file or failed. */
| 423 | * @return the actual read data bytes or 0 on end of file or failed. |
| 424 | */ |
| 425 | ssize_t dfs_file_read(struct dfs_file *fd, void *buf, size_t len) |
| 426 | { |
| 427 | int result = 0; |
| 428 | |
| 429 | if (fd == NULL) |
| 430 | { |
| 431 | return -EINVAL; |
| 432 | } |
| 433 | |
| 434 | if (fd->vnode->fops->read == NULL) |
| 435 | { |
| 436 | return -ENOSYS; |
| 437 | } |
| 438 | |
| 439 | if ((result = fd->vnode->fops->read(fd, buf, len)) < 0) |
| 440 | { |
| 441 | fd->flags |= DFS_F_EOF; |
| 442 | } |
| 443 | |
| 444 | return result; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * this function will fetch directory entries from a directory descriptor. |