@@ -1212,19 +1212,27 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
12121212{
12131213 if (fio_is_remote (location ))
12141214 {
1215- fio_header hdr ;
12161215 size_t old_path_len = strlen (old_path ) + 1 ;
12171216 size_t new_path_len = strlen (new_path ) + 1 ;
1218- hdr .cop = FIO_RENAME ;
1219- hdr .handle = -1 ;
1220- hdr .size = old_path_len + new_path_len ;
1217+ fio_header hdr = {
1218+ .cop = FIO_RENAME ,
1219+ .handle = -1 ,
1220+ .size = old_path_len + new_path_len ,
1221+ .arg = 0 ,
1222+ };
12211223
12221224 IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
12231225 IO_CHECK (fio_write_all (fio_stdout , old_path , old_path_len ), old_path_len );
12241226 IO_CHECK (fio_write_all (fio_stdout , new_path , new_path_len ), new_path_len );
12251227
1226- //TODO: wait for confirmation.
1228+ IO_CHECK (fio_read_all (fio_stdin , & hdr , sizeof (hdr )), sizeof (hdr ));
1229+ Assert (hdr .cop == FIO_RENAME );
12271230
1231+ if (hdr .arg != 0 )
1232+ {
1233+ errno = hdr .arg ;
1234+ return -1 ;
1235+ }
12281236 return 0 ;
12291237 }
12301238 else
@@ -1233,6 +1241,22 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
12331241 }
12341242}
12351243
1244+ static void
1245+ fio_rename_impl (char const * old_path , const char * new_path , int out )
1246+ {
1247+ fio_header hdr = {
1248+ .cop = FIO_RENAME ,
1249+ .handle = -1 ,
1250+ .size = 0 ,
1251+ .arg = 0 ,
1252+ };
1253+
1254+ if (rename (old_path , new_path ) != 0 )
1255+ hdr .arg = errno ;
1256+
1257+ IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
1258+ }
1259+
12361260/* Sync file to disk */
12371261int
12381262fio_sync (fio_location location , const char * path )
@@ -3787,7 +3811,8 @@ fio_communicate(int in, int out)
37873811 IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
37883812 break ;
37893813 case FIO_RENAME : /* Rename file */
3790- SYS_CHECK (rename (buf , buf + strlen (buf ) + 1 ));
3814+ /* possible buffer overflow */
3815+ fio_rename_impl (buf , buf + strlen (buf ) + 1 , out );
37913816 break ;
37923817 case FIO_SYMLINK : /* Create symbolic link */
37933818 fio_symlink_impl (out , buf , hdr .arg > 0 ? true : false);
@@ -3813,7 +3838,7 @@ fio_communicate(int in, int out)
38133838 fio_list_dir_impl (out , buf );
38143839 break ;
38153840 case FIO_SEND_PAGES :
3816- // buf contain fio_send_request header and bitmap.
3841+ /* buf contain fio_send_request header and bitmap. */
38173842 fio_send_pages_impl (out , buf );
38183843 break ;
38193844 case FIO_SEND_FILE :
0 commit comments