* this function is will cause the regular file referenced by fd * to be truncated to a size of precisely length bytes. * * @param fd the file descriptor. * @param length the length to be truncated. * * @return the status of truncated. */
| 734 | * @return the status of truncated. |
| 735 | */ |
| 736 | int dfs_file_ftruncate(struct dfs_file *fd, off_t length) |
| 737 | { |
| 738 | int result; |
| 739 | |
| 740 | /* fd is null or not a regular file system fd, or length is invalid */ |
| 741 | if (fd == NULL || fd->vnode->type != FT_REGULAR || length < 0) |
| 742 | return -EINVAL; |
| 743 | |
| 744 | if (fd->vnode->fops->ioctl == NULL) |
| 745 | return -ENOSYS; |
| 746 | |
| 747 | result = fd->vnode->fops->ioctl(fd, RT_FIOFTRUNCATE, (void*)&length); |
| 748 | |
| 749 | /* update current size */ |
| 750 | if (result == 0) |
| 751 | fd->vnode->size = length; |
| 752 | |
| 753 | return result; |
| 754 | } |
| 755 | |
| 756 | #ifdef RT_USING_SMART |
| 757 | int dfs_file_mmap2(struct dfs_file *fd, struct dfs_mmap2_args *mmap2) |