mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-11-18 21:06:31 +00:00
dos33: add utility for manipulating raw sectors
This commit is contained in:
parent
ba46a0de4d
commit
feea160820
@ -1,6 +1,7 @@
|
||||
include ../Makefile.inc
|
||||
|
||||
all: dos33 mkdos33fs make_b \
|
||||
dos33_raw \
|
||||
dos33_text2ascii char2hex
|
||||
|
||||
|
||||
@ -10,12 +11,24 @@ char2hex: char2hex.o
|
||||
char2hex.o: char2hex.c
|
||||
$(CC) $(CFLAGS) -c char2hex.c
|
||||
|
||||
###
|
||||
|
||||
dos33: dos33.o
|
||||
$(CC) $(LFLAGS) -o dos33 dos33.o
|
||||
|
||||
dos33.o: dos33.c dos33.h
|
||||
$(CC) $(CFLAGS) -g -c dos33.c
|
||||
|
||||
###
|
||||
|
||||
dos33_raw: dos33_raw.o
|
||||
$(CC) $(LFLAGS) -o dos33_raw dos33_raw.o
|
||||
|
||||
dos33_raw.o: dos33_raw.c
|
||||
$(CC) $(CFLAGS) -g -c dos33_raw.c
|
||||
|
||||
###
|
||||
|
||||
dos33_text2ascii: dos33_text2ascii.o
|
||||
$(CC) $(LFLGAS) -o dos33_text2ascii dos33_text2ascii.o
|
||||
|
||||
@ -36,8 +49,8 @@ mkdos33fs.o: mkdos33fs.c dos33.h
|
||||
|
||||
|
||||
install:
|
||||
cp dos33 mkdos33fs make_b dos33_text2ascii char2hex $(INSTALL_LOC)
|
||||
cp dos33 dos33_raw mkdos33fs make_b dos33_text2ascii char2hex $(INSTALL_LOC)
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o dos33 mkdos33fs make_b dos33_text2ascii char2hex
|
||||
rm -f *~ *.o dos33 dos33_raw mkdos33fs make_b dos33_text2ascii char2hex
|
||||
cd tests && make clean
|
||||
|
75
dos33fs-utils/dos33_raw.c
Normal file
75
dos33fs-utils/dos33_raw.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* usage: dos33_raw track sector file */
|
||||
static void usage(char *exe_name) {
|
||||
printf("Usage:\n");
|
||||
printf("\t%s disk_image track sector file\n\n",exe_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
unsigned int track,sector;
|
||||
int disk_image_fd;
|
||||
int file_fd;
|
||||
unsigned char buffer[256];
|
||||
int result;
|
||||
|
||||
if (argc<4) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
track=atoi(argv[2]);
|
||||
sector=atoi(argv[3]);
|
||||
|
||||
if (track>34) {
|
||||
fprintf(stderr,"Warning! Unusual track number %d\n",track);
|
||||
}
|
||||
|
||||
if (track>15) {
|
||||
fprintf(stderr,"Warning! Unusual sector number %d\n",sector);
|
||||
}
|
||||
|
||||
disk_image_fd=open(argv[1],O_RDWR);
|
||||
if (disk_image_fd<0) {
|
||||
fprintf(stderr,"Error opening %s: %s\n",
|
||||
argv[1],strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
file_fd=open(argv[4],O_RDONLY);
|
||||
if (file_fd<0) {
|
||||
fprintf(stderr,"Error opening %s: %s\n",
|
||||
argv[4],strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
result=lseek(disk_image_fd,(sector*256)+(track*16*256),SEEK_SET);
|
||||
if (result<0) {
|
||||
fprintf(stderr,"Error seeking: %s\n",strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* write until out of space */
|
||||
while(1) {
|
||||
result=read(file_fd,buffer,256);
|
||||
if (result<0) break;
|
||||
result=write(disk_image_fd,buffer,result);
|
||||
if (result<0) {
|
||||
fprintf(stderr,"Error writing image: %s\n",
|
||||
strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(file_fd);
|
||||
close(disk_image_fd);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user