@@ -1292,19 +1292,27 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
12921292{
12931293 if (fio_is_remote (location ))
12941294 {
1295- fio_header hdr ;
12961295 size_t old_path_len = strlen (old_path ) + 1 ;
12971296 size_t new_path_len = strlen (new_path ) + 1 ;
1298- hdr .cop = FIO_RENAME ;
1299- hdr .handle = -1 ;
1300- hdr .size = old_path_len + new_path_len ;
1297+ fio_header hdr = {
1298+ .cop = FIO_RENAME ,
1299+ .handle = -1 ,
1300+ .size = old_path_len + new_path_len ,
1301+ .arg = 0 ,
1302+ };
13011303
13021304 IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
13031305 IO_CHECK (fio_write_all (fio_stdout , old_path , old_path_len ), old_path_len );
13041306 IO_CHECK (fio_write_all (fio_stdout , new_path , new_path_len ), new_path_len );
13051307
1306- //TODO: wait for confirmation.
1308+ IO_CHECK (fio_read_all (fio_stdin , & hdr , sizeof (hdr )), sizeof (hdr ));
1309+ Assert (hdr .cop == FIO_RENAME );
13071310
1311+ if (hdr .arg != 0 )
1312+ {
1313+ errno = hdr .arg ;
1314+ return -1 ;
1315+ }
13081316 return 0 ;
13091317 }
13101318 else
@@ -1313,6 +1321,22 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
13131321 }
13141322}
13151323
1324+ static void
1325+ fio_rename_impl (char const * old_path , const char * new_path , int out )
1326+ {
1327+ fio_header hdr = {
1328+ .cop = FIO_RENAME ,
1329+ .handle = -1 ,
1330+ .size = 0 ,
1331+ .arg = 0 ,
1332+ };
1333+
1334+ if (rename (old_path , new_path ) != 0 )
1335+ hdr .arg = errno ;
1336+
1337+ IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
1338+ }
1339+
13161340/* Sync file to disk */
13171341int
13181342fio_sync (fio_location location , const char * path )
@@ -3337,7 +3361,8 @@ fio_communicate(int in, int out)
33373361 IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
33383362 break ;
33393363 case FIO_RENAME : /* Rename file */
3340- SYS_CHECK (rename (buf , buf + strlen (buf ) + 1 ));
3364+ /* possible buffer overflow */
3365+ fio_rename_impl (buf , buf + strlen (buf ) + 1 , out );
33413366 break ;
33423367 case FIO_SYMLINK : /* Create symbolic link */
33433368 fio_symlink_impl (out , buf , hdr .arg > 0 ? true : false);
@@ -3363,7 +3388,7 @@ fio_communicate(int in, int out)
33633388 fio_list_dir_impl (out , buf );
33643389 break ;
33653390 case FIO_SEND_PAGES :
3366- // buf contain fio_send_request header and bitmap.
3391+ /* buf contain fio_send_request header and bitmap. */
33673392 fio_send_pages_impl (out , buf );
33683393 break ;
33693394 case FIO_SEND_FILE :
0 commit comments