@@ -1292,19 +1292,27 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
1292
1292
{
1293
1293
if (fio_is_remote (location ))
1294
1294
{
1295
- fio_header hdr ;
1296
1295
size_t old_path_len = strlen (old_path ) + 1 ;
1297
1296
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
+ };
1301
1303
1302
1304
IO_CHECK (fio_write_all (fio_stdout , & hdr , sizeof (hdr )), sizeof (hdr ));
1303
1305
IO_CHECK (fio_write_all (fio_stdout , old_path , old_path_len ), old_path_len );
1304
1306
IO_CHECK (fio_write_all (fio_stdout , new_path , new_path_len ), new_path_len );
1305
1307
1306
- //TODO: wait for confirmation.
1308
+ IO_CHECK (fio_read_all (fio_stdin , & hdr , sizeof (hdr )), sizeof (hdr ));
1309
+ Assert (hdr .cop == FIO_RENAME );
1307
1310
1311
+ if (hdr .arg != 0 )
1312
+ {
1313
+ errno = hdr .arg ;
1314
+ return -1 ;
1315
+ }
1308
1316
return 0 ;
1309
1317
}
1310
1318
else
@@ -1313,6 +1321,22 @@ fio_rename(fio_location location, const char* old_path, const char* new_path)
1313
1321
}
1314
1322
}
1315
1323
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
+
1316
1340
/* Sync file to disk */
1317
1341
int
1318
1342
fio_sync (fio_location location , const char * path )
@@ -3337,7 +3361,8 @@ fio_communicate(int in, int out)
3337
3361
IO_CHECK (fio_write_all (out , & hdr , sizeof (hdr )), sizeof (hdr ));
3338
3362
break ;
3339
3363
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 );
3341
3366
break ;
3342
3367
case FIO_SYMLINK : /* Create symbolic link */
3343
3368
fio_symlink_impl (out , buf , hdr .arg > 0 ? true : false);
@@ -3363,7 +3388,7 @@ fio_communicate(int in, int out)
3363
3388
fio_list_dir_impl (out , buf );
3364
3389
break ;
3365
3390
case FIO_SEND_PAGES :
3366
- // buf contain fio_send_request header and bitmap.
3391
+ /* buf contain fio_send_request header and bitmap. */
3367
3392
fio_send_pages_impl (out , buf );
3368
3393
break ;
3369
3394
case FIO_SEND_FILE :
0 commit comments