fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
at master 100 lines 2.5 kB view raw
1/***************************************************************************** 2 * pce * 3 *****************************************************************************/ 4 5/***************************************************************************** 6 * File name: src/utils/psi/delete.c * 7 * Created: 2013-06-09 by Hampa Hug <hampa@hampa.ch> * 8 * Copyright: (C) 2013 Hampa Hug <hampa@hampa.ch> * 9 *****************************************************************************/ 10 11/***************************************************************************** 12 * This program is free software. You can redistribute it and / or modify it * 13 * under the terms of the GNU General Public License version 2 as published * 14 * by the Free Software Foundation. * 15 * * 16 * This program is distributed in the hope that it will be useful, but * 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 * Public License for more details. * 20 *****************************************************************************/ 21 22 23#include "main.h" 24#include "delete.h" 25 26#include <stdlib.h> 27#include <stdio.h> 28#include <string.h> 29 30#include <drivers/psi/psi.h> 31 32 33static 34int psi_delete_sectors_cb (psi_img_t *img, psi_trk_t *trk, 35 unsigned c, unsigned h, void *opaque) 36{ 37 unsigned i, j, a; 38 psi_sct_t *sct, *new, *tmp; 39 40 j = 0; 41 42 for (i = 0; i < trk->sct_cnt; i++) { 43 a = 0; 44 45 sct = trk->sct[i]; 46 new = NULL; 47 48 trk->sct[j] = NULL; 49 50 while (sct != NULL) { 51 tmp = sct; 52 sct = tmp->next; 53 tmp->next = NULL; 54 55 if (psi_sel_match (c, h, tmp->s, i, a)) { 56 psi_sct_del (tmp); 57 par_cnt += 1; 58 } 59 else { 60 if (new == NULL) { 61 trk->sct[j] = tmp; 62 } 63 else { 64 new->next = tmp; 65 } 66 67 new = tmp; 68 } 69 70 a += 1; 71 } 72 73 if (trk->sct[j] != NULL) { 74 j += 1; 75 } 76 } 77 78 trk->sct_cnt = j; 79 80 return (0); 81} 82 83int psi_delete_sectors (psi_img_t *img) 84{ 85 int r; 86 87 par_cnt = 0; 88 89 r = psi_for_all_tracks (img, psi_delete_sectors_cb, NULL); 90 91 if (par_verbose) { 92 fprintf (stderr, "%s: delete %lu sectors\n", arg0, par_cnt); 93 } 94 95 if (r) { 96 fprintf (stderr, "%s: deleting failed\n", arg0); 97 } 98 99 return (r); 100}