comparison simtool/restorebin.c @ 80:54cebab70c19

fc-simtool restore-file: add support for cyclic files
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 05:31:53 +0000
parents a6ca422323b9
children bd19dc7591ec
comparison
equal deleted inserted replaced
79:b0982c0cf54d 80:54cebab70c19
43 for (recno = 1; recno <= curfile_record_count; recno++) { 43 for (recno = 1; recno <= curfile_record_count; recno++) {
44 rc = update_rec_op(recno, 0x04, dp, curfile_record_len); 44 rc = update_rec_op(recno, 0x04, dp, curfile_record_len);
45 if (rc < 0) 45 if (rc < 0)
46 return(rc); 46 return(rc);
47 dp += curfile_record_len; 47 dp += curfile_record_len;
48 }
49 return(0);
50 }
51
52 static
53 restore_cyclic(data)
54 u_char *data;
55 {
56 unsigned count;
57 u_char *dp;
58 int rc;
59
60 dp = data + curfile_total_size;
61 for (count = 0; count < curfile_record_count; count++) {
62 dp -= curfile_record_len;
63 rc = update_rec_op(0, 0x03, dp, curfile_record_len);
64 if (rc < 0)
65 return(rc);
48 } 66 }
49 return(0); 67 return(0);
50 } 68 }
51 69
52 cmd_restore_file(argc, argv) 70 cmd_restore_file(argc, argv)
110 case 0x01: 128 case 0x01:
111 /* record-based */ 129 /* record-based */
112 rc = restore_records(databuf); 130 rc = restore_records(databuf);
113 break; 131 break;
114 case 0x03: 132 case 0x03:
115 fprintf(stderr, "error: cyclic files are not supported\n"); 133 /* cyclic */
116 rc = -1; 134 rc = restore_cyclic(databuf);
135 break;
117 } 136 }
118 free(databuf); 137 free(databuf);
119 return(rc); 138 return(rc);
120 } 139 }