Package: genisovh / 0.1-4

02-std-types-and-endianness.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
--- a/dvh.h
+++ b/dvh.h
@@ -1,7 +1,11 @@
-#ifndef _SYS_DVH_H
-#define _SYS_DVH_H
-
 /*
+ * Copyright: (C) 2002 by Florian Lohoff <flo@rfc822.org>
+ *            (C) 2004 by Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, Version 2, as published by the
+ * Free Software Foundation.
+ *
  * Format for volume header information
  *
  * The volume header is a block located at the beginning of all disk
@@ -33,6 +37,11 @@
  * and other tables is user defined when the device is formatted.
  */
 
+#ifndef _SYS_DVH_H
+#define _SYS_DVH_H
+
+#include <stdint.h>
+
 /*
  * device parameters are in the volume header to determine mapping
  * from logical block numbers to physical device addresses
@@ -40,38 +49,38 @@
  * Linux doesn't care ...
  */
 struct device_parameters {
-	unsigned char	dp_skew;	/* spiral addressing skew */
-	unsigned char	dp_gap1;	/* words of 0 before header */
-	unsigned char	dp_gap2;	/* words of 0 between hdr and data */
-	unsigned char	dp_spares_cyl;	/* This is for drives (such as SCSI
+	uint8_t dp_skew;	/* spiral addressing skew */
+	uint8_t dp_gap1;	/* words of 0 before header */
+	uint8_t dp_gap2;	/* words of 0 between hdr and data */
+	uint8_t dp_spares_cyl;	/* This is for drives (such as SCSI
 		that support zone oriented sparing, where the zone is larger
 		than one track.  It gets subracteded from the cylinder size
 		( dp_trks0 * dp_sec) when doing partition size calculations */
-	unsigned short	dp_cyls;	/* number of usable cylinders (i.e.,
+	uint16_t dp_cyls;	/* number of usable cylinders (i.e.,
 		doesn't include cylinders reserved by the drive for badblocks,
 		etc.). For drives with variable geometry, this number may be
 		decreased so that:
 		dp_cyls * ((dp_heads * dp_trks0) - dp_spares_cyl) <= actualcapacity
 		This happens on SCSI drives such as the Wren IV and Toshiba 156
 		Also see dp_cylshi below */
-	unsigned short	dp_shd0;	/* starting head vol 0 */
-	unsigned short	dp_trks0;	/* number of tracks / cylinder vol 0*/
-	unsigned char	dp_ctq_depth;	/* Depth of CTQ queue */
-	unsigned char	dp_cylshi;	/* high byte of 24 bits of cylinder count */
-	unsigned short	dp_unused;	/* not used */
-	unsigned short	dp_secs;	/* number of sectors/track */
-	unsigned short	dp_secbytes;	/* length of sector in bytes */
-	unsigned short	dp_interleave;	/* sector interleave */
-	int	dp_flags;		/* controller characteristics */
-	int	dp_datarate;		/* bytes/sec for kernel stats */
-	int	dp_nretries;		/* max num retries on data error */
-	int	dp_mspw;		/* ms per word to xfer, for iostat */
-	unsigned short dp_xgap1;	/* Gap 1 for xylogics controllers */
-	unsigned short dp_xsync;    /* sync delay for xylogics controllers */
-	unsigned short dp_xrdly;    /* read delay for xylogics controllers */
-	unsigned short dp_xgap2;    /* gap 2 for xylogics controllers */
-	unsigned short dp_xrgate;   /* read gate for xylogics controllers */
-	unsigned short dp_xwcont;   /* write continuation for xylogics */
+	uint16_t dp_shd0;	/* starting head vol 0 */
+	uint16_t dp_trks0;	/* number of tracks / cylinder vol 0*/
+	uint8_t dp_ctq_depth;	/* Depth of CTQ queue */
+	uint8_t dp_cylshi;	/* high byte of 24 bits of cylinder count */
+	uint16_t dp_unused;	/* not used */
+	uint16_t dp_secs;	/* number of sectors/track */
+	uint16_t dp_secbytes;	/* length of sector in bytes */
+	uint16_t dp_interleave;	/* sector interleave */
+	int32_t dp_flags;		/* controller characteristics */
+	int32_t dp_datarate;		/* bytes/sec for kernel stats */
+	int32_t dp_nretries;		/* max num retries on data error */
+	int32_t dp_mspw;		/* ms per word to xfer, for iostat */
+	uint16_t dp_xgap1;	/* Gap 1 for xylogics controllers */
+	uint16_t dp_xsync;    /* sync delay for xylogics controllers */
+	uint16_t dp_xrdly;    /* read delay for xylogics controllers */
+	uint16_t dp_xgap2;    /* gap 2 for xylogics controllers */
+	uint16_t dp_xrgate;   /* read gate for xylogics controllers */
+	uint16_t dp_xwcont;   /* write continuation for xylogics */
 };
 
 /*
@@ -93,9 +102,9 @@
 #define VDNAMESIZE	8
 
 struct volume_directory {
-	char	vd_name[VDNAMESIZE];	/* name */
-	int	vd_lbn;			/* logical block number */
-	int	vd_nbytes;		/* file length in bytes */
+	int8_t  vd_name[VDNAMESIZE];	/* name */
+	int32_t vd_lbn;			/* logical block number */
+	int32_t vd_nbytes;		/* file length in bytes */
 };
 
 /*
@@ -107,9 +116,9 @@
  * NOTE: pt_firstlbn SHOULD BE CYLINDER ALIGNED
  */
 struct partition_table {		/* one per logical partition */
-	int	pt_nblks;		/* # of logical blks in partition */
-	int	pt_firstlbn;		/* first lbn of partition */
-	int	pt_type;		/* use of partition */
+	int32_t pt_nblks;		/* # of logical blks in partition */
+	int32_t pt_firstlbn;		/* first lbn of partition */
+	int32_t pt_type;		/* use of partition */
 };
 
 #define	PTYPE_VOLHDR	0		/* partition is volume header */
@@ -148,15 +157,15 @@
 #define NOT_BOOTABLE    0x80;
 
 struct volume_header {
-	int vh_magic;				/* identifies volume header */
-	short vh_rootpt;			/* root partition number */
-	short vh_swappt;			/* swap partition number */
-	char vh_bootfile[BFNAMESIZE];		/* name of file to boot */
-	struct device_parameters vh_dp;		/* device parameters */
-	struct volume_directory vh_vd[NVDIR];	/* other vol hdr contents */
-	struct partition_table vh_pt[NPARTAB];	/* device partition layout */
-	int vh_csum;				/* volume header checksum */
-	int vh_fill;	/* fill out to 512 bytes */
+	int32_t vh_magic; /* identifies volume header */
+	int16_t vh_rootpt; /* root partition number */
+	int16_t vh_swappt; /* swap partition number */
+	int8_t vh_bootfile[BFNAMESIZE]; /* name of file to boot */
+	struct device_parameters vh_dp; /* device parameters */
+	struct volume_directory vh_vd[NVDIR]; /* other vol hdr contents */
+	struct partition_table vh_pt[NPARTAB]; /* device partition layout */
+	int32_t vh_csum; /* volume header checksum */
+	int32_t vh_fill; /* fill out to 512 bytes */
 };
 
 #endif /* _SYS_DVH_H */
--- a/main.c
+++ b/main.c
@@ -1,17 +1,25 @@
+/*
+ * Copyright: (C) 2002 by Florian Lohoff <flo@rfc822.org>
+ *            (C) 2004 by Thiemo Seufer <seufer@csv.ica.uni-stuttgart.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, Version 2, as published by the
+ * Free Software Foundation.
+ */
 
 #include <stdio.h>
-#include <sys/ioctl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <linux/fs.h>
-#include <linux/hdreg.h>
-#include <assert.h>
-#include <string.h>
-#include <errno.h>
 
 #include "dvh.h"
 
+#define MIN(a,b) (((a) < (b)) ? (a) : (b))
+
 #if 1
 #define SECTORS_PER_TRACK	32
 #define BYTES_PER_SECTOR	512
@@ -20,25 +28,22 @@
 #define BYTES_PER_SECTOR	2048
 #endif
 
-#define __u16	unsigned short
-#define __u32	unsigned int
-
 #define swab16(x) \
 ({ \
-	__u16 __x = (x); \
-	((__u16)( \
-		(((__u16)(__x) & (__u16)0x00ffU) << 8) | \
-		(((__u16)(__x) & (__u16)0xff00U) >> 8) )); \
+	uint16_t __x = (x); \
+	((uint16_t)( \
+		(((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
+		(((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
 })
 
 #define swab32(x) \
 ({ \
-	__u32 __x = (x); \
-	((__u32)( \
-		(((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \
-		(((__u32)(__x) & (__u32)0x0000ff00UL) <<  8) | \
-		(((__u32)(__x) & (__u32)0x00ff0000UL) >>  8) | \
-		(((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \
+	uint32_t __x = (x); \
+	((uint32_t)( \
+		(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
+		(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) <<  8) | \
+		(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >>  8) | \
+		(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
 })
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -47,123 +52,171 @@
 #define cpu_to_be32(x) swab32((x))
 #define cpu_to_be16(x) swab16((x))
 #else
-#define be32_to_cpu(x) ((__u32)(x))
-#define be16_to_cpu(x) ((__u16)(x))
-#define cpu_to_be32(x) ((__u32)(x))
-#define cpu_to_be16(x) ((__u16)(x))
+#define be32_to_cpu(x) ((uint32_t)(x))
+#define be16_to_cpu(x) ((uint16_t)(x))
+#define cpu_to_be32(x) ((uint32_t)(x))
+#define cpu_to_be16(x) ((uint16_t)(x))
 #endif
 
 
-__u32 vh_calc_checksum(struct volume_header *vh) {
-	__u32	oldchecksum,
-		newsum=0,
-		*buffer=(__u32 *) vh;
-	int	i;
+static void vh_calc_checksum(struct volume_header *vh)
+{
+	uint32_t newsum = 0;
+	uint32_t *buffer = (uint32_t *)vh;
+	unsigned int i;
 
-	oldchecksum=vh->vh_csum;
-	vh->vh_csum=0;
+	vh->vh_csum = 0;
 
-	for(i=0;i<sizeof(struct volume_header)/sizeof(__u32);i++) {
-		newsum=newsum-be32_to_cpu(buffer[i]);
-	}
+	for(i = 0; i < sizeof(struct volume_header)/sizeof(uint32_t); i++)
+		newsum -= be32_to_cpu(buffer[i]);
 
-	vh->vh_csum=oldchecksum;
-	return(newsum);
+	vh->vh_csum = cpu_to_be32(newsum);
 }
 
-void usage(void ) {
-	printf("Usage:\ngenisovh <isofile> <name:sblock,size> ... \n");
-	exit(1);
+static void swap_dp_out(struct device_parameters *dp)
+{
+	cpu_to_be16(dp->dp_cyls);
+	cpu_to_be16(dp->dp_shd0);
+	cpu_to_be16(dp->dp_trks0);
+	cpu_to_be16(dp->dp_unused);
+	cpu_to_be16(dp->dp_secs);
+	cpu_to_be16(dp->dp_secbytes);
+	cpu_to_be16(dp->dp_interleave);
+	cpu_to_be32(dp->dp_flags);
+	cpu_to_be32(dp->dp_datarate);
+	cpu_to_be32(dp->dp_nretries);
+	cpu_to_be32(dp->dp_mspw);
+	cpu_to_be32(dp->dp_xgap1);
+	cpu_to_be32(dp->dp_xsync);
+	cpu_to_be32(dp->dp_xrdly);
+	cpu_to_be32(dp->dp_xgap2);
+	cpu_to_be32(dp->dp_xrgate);
+	cpu_to_be32(dp->dp_xwcont);
 }
 
-int main(int argc, char **argv) {
-	int			fd,
-				i,
-				v,
-				block,
-				size;
-	char			*isoname,
-				*cline,
-				*pos;
-	struct stat		st;
-	struct volume_header	vh;
+static void swap_vd_out(struct volume_directory *vd)
+{
+	cpu_to_be32(vd->vd_lbn);
+	cpu_to_be32(vd->vd_nbytes);
+}
 
+static void swap_pt_out(struct partition_table *pt)
+{
+	cpu_to_be32(pt->pt_nblks);
+	cpu_to_be32(pt->pt_firstlbn);
+	cpu_to_be32(pt->pt_type);
+}
+
+static void swap_vh_out(struct volume_header *vh)
+{
+	cpu_to_be32(vh->vh_magic);
+	cpu_to_be16(vh->vh_rootpt);
+	cpu_to_be16(vh->vh_swappt);
+	swap_dp_out(&vh->vh_dp);
+	swap_vd_out(vh->vh_vd);
+	swap_pt_out(vh->vh_pt);
+	cpu_to_be32(vh->vh_csum);
+	cpu_to_be32(vh->vh_fill);
+}
+
+static void usage(void)
+{
+	printf("Usage:\ngenisovh <isofile> [<name:sblock,size> ...]\n");
+	exit(1);
+}
+
+int main(int argc, char **argv)
+{
+	int fd;
+	int i;
+	int v;
+	int block;
+	int size;
+	char *isoname;
+	char *pos;
+	struct stat st;
+	struct volume_header vh;
 
 	if (argc < 2)
 		usage();
 
-	isoname=argv[1];
+	isoname = argv[1];
 
-	if (!(fd=open(isoname, O_RDWR))) {
+	if (!(fd = open(isoname, O_RDWR))) {
 		printf("File not found %s\n", isoname);
-		exit(1);
+		return 1;
 	}
 
 	if (fstat(fd, &st)) {
 		printf("Failed to stat file %s\n", isoname);
 		close(fd);
-		exit(1);
+		return 1;
 	}
 	
-	memset(&vh, 0, sizeof(struct volume_header));
+	memset(&vh, 0, sizeof(vh));
 
-	vh.vh_magic = cpu_to_be32(VHMAGIC);
+	vh.vh_magic = VHMAGIC;
 
 	/* Values from an IRIX cd */
-	vh.vh_dp.dp_secbytes=cpu_to_be16(BYTES_PER_SECTOR);
-	vh.vh_dp.dp_secs=cpu_to_be16(SECTORS_PER_TRACK);
-	vh.vh_dp.dp_flags=cpu_to_be32(DP_RESEEK|DP_IGNOREERRORS|DP_TRKFWD);
-	vh.vh_dp.dp_trks0=cpu_to_be16(1);
+	vh.vh_dp.dp_secbytes = BYTES_PER_SECTOR;
+	vh.vh_dp.dp_secs = SECTORS_PER_TRACK;
+	vh.vh_dp.dp_flags = DP_RESEEK|DP_IGNOREERRORS|DP_TRKFWD;
+	vh.vh_dp.dp_trks0 = 1;
 
-	vh.vh_dp.dp_cyls=cpu_to_be16((st.st_size + BYTES_PER_SECTOR - 1) /
-		(SECTORS_PER_TRACK*BYTES_PER_SECTOR));
+	vh.vh_dp.dp_cyls = (st.st_size + BYTES_PER_SECTOR - 1)
+		/ (SECTORS_PER_TRACK * BYTES_PER_SECTOR);
 
-	for(i=2,v=0;i<argc;i++,v++) {
-
-		cline=argv[i];	
+	for(i = 2, v = 0; i < argc; i++, v++) {
+		char *cline = argv[i];
 
 		/* ip22:3838383,3333 */
-		if (!(pos=strchr(cline, ':'))) {
-			printf("Couldnt find : in parameter %s\n", cline);	
+		if (!(pos = strchr(cline, ':'))) {
+			printf("Couldn't find : in parameter %s\n", cline);
 			usage();
 		}
 
-		*pos=0x0;
-
 		/* copy name */
-		strncpy(vh.vh_vd[v].vd_name, cline, VDNAMESIZE);
+		strncpy(vh.vh_vd[v].vd_name, cline, MIN(VDNAMESIZE, pos - cline));
 
-		cline=pos+1;
+		cline = pos + 1;
 
-		if (!(pos=strchr(cline, ','))) {
-			printf("Could find , in parameter %s\n", cline);
+		if (!(pos = strchr(cline, ','))) {
+			printf("Couldn't find , in parameter %s\n", cline);
 			usage();
 		}
 
-		*pos=0x0;
-
-		block=atoi(cline);	
-		vh.vh_vd[v].vd_lbn=cpu_to_be32(block);
+		block = atoi(cline);
+		vh.vh_vd[v].vd_lbn = block;
 
-		cline=pos+1;
-
-		size=atoi(cline);	
-		vh.vh_vd[v].vd_nbytes=cpu_to_be32(size);
+		cline = pos + 1;
 
+		size = atoi(cline);
+		vh.vh_vd[v].vd_nbytes = size;
 	}
 
-	/* Create volume header partition on WHOLE cd iso */
-	vh.vh_pt[8].pt_nblks=cpu_to_be32((st.st_size + (BYTES_PER_SECTOR - 1)) /
-		BYTES_PER_SECTOR);
+	/* Create volume partition on whole cd iso */
+	vh.vh_pt[10].pt_nblks = (st.st_size + (BYTES_PER_SECTOR - 1))
+		/ BYTES_PER_SECTOR;
+	vh.vh_pt[10].pt_firstlbn = 0;
+	vh.vh_pt[10].pt_type = PTYPE_VOLUME;
+
+	/* Create volume header partition, also on WHOLE cd iso */
+	vh.vh_pt[8].pt_nblks = (st.st_size + (BYTES_PER_SECTOR - 1))
+		/ BYTES_PER_SECTOR;
+	vh.vh_pt[8].pt_firstlbn = 0;
+	vh.vh_pt[8].pt_type = PTYPE_VOLHDR;
+
+	swap_vh_out(&vh);
 
 	/* Create checksum */
-	vh.vh_csum=cpu_to_be32(vh_calc_checksum(&vh));
+	vh_calc_checksum(&vh);
 
-	if (write(fd, &vh, sizeof(struct volume_header)) != sizeof(struct volume_header)) {
+	if (write(fd, &vh, sizeof(vh)) != sizeof(vh)) {
 		printf("Failed to write volume header to iso image");
 		close(fd);
-		exit(1);
+		return 1;
 	}
 
 	close(fd);
+	return 0;
 }