[tyndur-devel] [PATCH] Tool zum Speichern und Wiederherstellen von Partitionstabellen
Roman Muentener ·
Kleines Tool, aus Langeweile entstanden und zum fseek mit Devices zu testen. Signed-off-by: Roman Muentener <fmnssun at gmail.com> --- src/modules/c/partt/Makefile.all | 7 ++ src/modules/c/partt/main.c | 125 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/partt/Makefile.all create mode 100644 src/modules/c/partt/main.c diff --git a/src/modules/c/partt/Makefile.all b/src/modules/c/partt/Makefile.all new file mode 100644 index 0000000..0549688 --- /dev/null +++ b/src/modules/c/partt/Makefile.all @@ -0,0 +1,7 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/partt" +$LOST_TOOLS_LD -opartt -Ttext=0x40000000 *.o --start-group $2 --end-group + +mv partt $1/apps/ diff --git a/src/modules/c/partt/main.c b/src/modules/c/partt/main.c new file mode 100644 index 0000000..e2d6ecc --- /dev/null +++ b/src/modules/c/partt/main.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2010 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Roman Muentener. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +unsigned char partition_table[64]; + +int go_part(char* source, char* destination,char* action); + +int main(int argc, char* argv[]) +{ + if(argc < 4) + { + printf("partt source destination action\n"); + printf(" source -- Quelle (Device oder Datei)\n"); + printf(" destination -- Zielort (Device oder Datei)\n"); + printf(" action -- Aktion: load oder save\n"); + printf(" load: Liest Partitionstabelle von Datei [source] und schreibt nach Device [destination]\n"); + printf(" save: Liest Partitionstabelle von Device [source] und schreibt nach Datei [destination]\n"); + printf("\n\n"); + printf("Beispiel: Speichern: partt ata:/ata00 save.pt save\n"); + printf(" Laden: partt save.pt ata:/ata00 load\n"); + return 1; + } + return go_part(argv[1],argv[2],argv[3]); +} + +int go_part(char* source, char* destination,char* action) +{ + FILE* fsrc = fopen(source,"r"); + if(!fsrc) + { + printf("partt: Konnte Device/Datei nicht lesen! [source]\n"); + return 3; + } + + int read_offset = 0x0; + int write_offset = 0x0; + + if(strcmp(action,"save") == 0) + { + read_offset = 0x01BE; + write_offset = 0x0; + } + else if(strcmp(action,"load") == 0) + { + read_offset = 0x0; + write_offset = 0x01BE; + } + else + { + printf("partt: Unbekannte Aktion!\n"); + return 2; + } + + if(fseek(fsrc,read_offset,SEEK_SET) != 0) + { + printf("partt: Sprung an Position schlug fehl! [source]\n"); + return 4; + } + + if(fread(partition_table,1,64,fsrc) != 64) + { + printf("partt: Konnte Partitionstabelle nicht lesen! [source]\n"); + return 5; + } + + FILE* fdst = fopen(destination,"w"); + if(!fdst) + { + printf("partt: Konnte Device/Datei nicht lesen! [destination]\n"); + return 3; + } + + if(fseek(fdst,write_offset,SEEK_SET) != 0) + { + printf("partt: Sprung an Position schlug fehl! [destination]\n"); + return 6; + } + + if(fwrite(partition_table,1,64,fdst) != 64) + { + printf("partt: Konnte Partitionstabelle nicht speichern! [destination]\n"); + return 7; + } + + fclose(fdst); + fclose(fsrc); + + return 0; +} -- 1.6.0.4