@@ -306,8 +306,9 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
306306{
307307 struct sahara_pkt read_req ;
308308 uint64_t remain ;
309- size_t offset ;
309+ size_t offset , buf_offset ;
310310 size_t chunk ;
311+ size_t written ;
311312 ssize_t n ;
312313 void * buf ;
313314 int fd ;
@@ -318,7 +319,7 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
318319
319320 char path [PATH_MAX ];
320321 snprintf (path , sizeof (path ), "%s/%s" , ramdump_path , region .filename );
321-
322+
322323 fd = open (path , O_WRONLY | O_CREAT | O_BINARY , 0644 );
323324 if (fd < 0 ) {
324325 warn ("failed to open \"%s\"" , region .filename );
@@ -339,14 +340,23 @@ static ssize_t sahara_debug64_one(struct qdl_device *qdl,
339340
340341 offset = 0 ;
341342 while (offset < remain ) {
343+ buf_offset = 0 ;
342344 n = qdl_read (qdl , buf , DEBUG_BLOCK_SIZE , 30000 );
343345 if (n < 0 ) {
344346 warn ("failed to read ramdump chunk" );
345347 goto out ;
346348 }
347349
348- write (fd , buf , n );
349- offset += n ;
350+ while (buf_offset < n ) {
351+ written = write (fd , buf + buf_offset , n - buf_offset );
352+ if (written <= 0 ) {
353+ warn ("failed to write ramdump chunk to \"%s\"" , region .filename );
354+ goto out ;
355+ }
356+ buf_offset += written ;
357+ }
358+
359+ offset += buf_offset ;
350360 }
351361
352362 qdl_read (qdl , buf , DEBUG_BLOCK_SIZE , 10 );
0 commit comments