File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed
Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -716,6 +716,71 @@ static int _dfs_lfs_close(struct dfs_file* file)
716716
717717static int _dfs_lfs_ioctl (struct dfs_file * file , int cmd , void * args )
718718{
719+ switch (cmd )
720+ {
721+ case RT_FIOFTRUNCATE :
722+ {
723+ #ifdef LFS_READONLY
724+ return - EROFS ;
725+ #else
726+ dfs_lfs_fd_t * dfs_lfs_fd ;
727+ off_t length ;
728+ int result ;
729+ lfs_soff_t pos ;
730+
731+ RT_ASSERT (file != RT_NULL );
732+ RT_ASSERT (file -> data != RT_NULL );
733+
734+ if (file -> vnode -> type == FT_DIRECTORY )
735+ {
736+ return - EISDIR ;
737+ }
738+
739+ if (args == RT_NULL )
740+ {
741+ return - EINVAL ;
742+ }
743+
744+ if ((file -> flags & 3 ) == O_RDONLY )
745+ {
746+ return - EBADF ;
747+ }
748+
749+ length = * (off_t * )args ;
750+ if (length < 0 )
751+ {
752+ return - EINVAL ;
753+ }
754+
755+ dfs_lfs_fd = (dfs_lfs_fd_t * )file -> data ;
756+
757+ result = lfs_file_truncate (dfs_lfs_fd -> lfs , & dfs_lfs_fd -> u .file , (lfs_off_t )length );
758+ if (result < 0 )
759+ {
760+ return _lfs_result_to_dfs (result );
761+ }
762+
763+ pos = lfs_file_tell (dfs_lfs_fd -> lfs , & dfs_lfs_fd -> u .file );
764+ if (pos < 0 )
765+ {
766+ return _lfs_result_to_dfs ((int )pos );
767+ }
768+ file -> pos = (rt_off_t )pos ;
769+
770+ pos = lfs_file_size (dfs_lfs_fd -> lfs , & dfs_lfs_fd -> u .file );
771+ if (pos < 0 )
772+ {
773+ return _lfs_result_to_dfs ((int )pos );
774+ }
775+ file -> vnode -> size = (rt_off_t )pos ;
776+ return RT_EOK ;
777+ #endif
778+ }
779+
780+ default :
781+ break ;
782+ }
783+
719784 return - ENOSYS ;
720785}
721786
You can’t perform that action at this time.
0 commit comments