@@ -1212,19 +1212,27 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
1212
1212
{
1213
1213
if (fio_is_remote (location ))
1214
1214
{
1215
- fio_header hdr ;
1216
1215
size_t old_path_len = strlen (old_path ) + 1 ;
1217
1216
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
+ };
1221
1223
1222
1224
IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
1223
1225
IO_CHECK (fio_write_all (fio_stdout , old_path , old_path_len ), old_path_len );
1224
1226
IO_CHECK (fio_write_all (fio_stdout , new_path , new_path_len ), new_path_len );
1225
1227
1226
- //TODO: wait for confirmation.
1228
+ IO_CHECK (fio_read_all (fio_stdin , & hdr , sizeof (hdr )), sizeof (hdr ));
1229
+ Assert (hdr .cop == FIO_RENAME );
1227
1230
1231
+ if (hdr .arg != 0 )
1232
+ {
1233
+ errno = hdr .arg ;
1234
+ return -1 ;
1235
+ }
1228
1236
return 0 ;
1229
1237
}
1230
1238
else
@@ -1233,6 +1241,22 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
1233
1241
}
1234
1242
}
1235
1243
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
+
1236
1260
/* Sync file to disk */
1237
1261
int
1238
1262
fio_sync (fio_location location , const char * path )
@@ -3787,7 +3811,8 @@ fio_communicate(int in, int out)
3787
3811
IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
3788
3812
break ;
3789
3813
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 );
3791
3816
break ;
3792
3817
case FIO_SYMLINK : /* Create symbolic link */
3793
3818
fio_symlink_impl (out , buf , hdr .arg > 0 ? true : false);
@@ -3813,7 +3838,7 @@ fio_communicate(int in, int out)
3813
3838
fio_list_dir_impl (out , buf );
3814
3839
break ;
3815
3840
case FIO_SEND_PAGES :
3816
- // buf contain fio_send_request header and bitmap.
3841
+ /* buf contain fio_send_request header and bitmap. */
3817
3842
fio_send_pages_impl (out , buf );
3818
3843
break ;
3819
3844
case FIO_SEND_FILE :
0 commit comments