1 /* @(#)movesect.c	1.6 09/07/05 Copyright 2001, 2004-2009 J. Schilling */
2 #include <schily/mconfig.h>
3 #ifndef lint
4 static	UConst char sccsid[] =
5 	"@(#)movesect.c	1.6 09/07/05 Copyright 2001, 2004-2009 J. Schilling";
6 #endif
7 /*
8  *	Copyright (c) 2001, 2004-2009 J. Schilling
9  */
10 /*
11  * The contents of this file are subject to the terms of the
12  * Common Development and Distribution License, Version 1.0 only
13  * (the "License").  You may not use this file except in compliance
14  * with the License.
15  *
16  * See the file CDDL.Schily.txt in this distribution for details.
17  * A copy of the CDDL is also available via the Internet at
18  * http://www.opensource.org/licenses/cddl1.txt
19  *
20  * When distributing Covered Code, include this CDDL HEADER in each
21  * file and include the License file CDDL.Schily.txt from this distribution.
22  */
23 
24 #include <schily/mconfig.h>
25 #include <schily/standard.h>
26 #include <schily/utypes.h>
27 #include <schily/schily.h>
28 
29 #include "cdrecord.h"
30 #include "movesect.h"
31 
32 EXPORT	void	scatter_secs	__PR((track_t *trackp, char *bp, int nsecs));
33 
34 /*
35  * Scatter input sector size records over buffer to make them
36  * output sector size.
37  *
38  * If input sector size is less than output sector size,
39  *
40  *	| sector_0 || sector_1 || ... || sector_n ||
41  *
42  * will be convterted into:
43  *
44  *	| sector_0 |grass|| sector_1 |grass|| ... || sector_n |grass||
45  *
46  *	Sector_n must me moved n * grass_size forward,
47  *	Sector_1 must me moved 1 * grass_size forward
48  *
49  *
50  * If output sector size is less than input sector size,
51  *
52  *	| sector_0 |grass|| sector_1 |grass|| ... || sector_n |grass||
53  *
54  * will be convterted into:
55  *
56  *	| sector_0 || sector_1 || ... || sector_n ||
57  *
58  *	Sector_1 must me moved 1 * grass_size backward,
59  *	Sector_n must me moved n * grass_size backward,
60  *
61  *	Sector_0 must never be moved.
62  */
63 EXPORT void
scatter_secs(trackp,bp,nsecs)64 scatter_secs(trackp, bp, nsecs)
65 	track_t	*trackp;
66 	char	*bp;
67 	int	nsecs;
68 {
69 	char	*from;
70 	char	*to;
71 	int	isecsize = trackp->isecsize;
72 	int	secsize = trackp->secsize;
73 	int	i;
74 
75 	if (secsize == isecsize)
76 		return;
77 
78 	nsecs -= 1;	/* we do not move sector # 0 */
79 
80 	if (secsize < isecsize) {
81 		from = bp + isecsize;
82 		to   = bp + secsize;
83 
84 		for (i = nsecs; i > 0; i--) {
85 			movebytes(from, to, secsize);
86 			from += isecsize;
87 			to   += secsize;
88 		}
89 	} else {
90 		from = bp + (nsecs * isecsize);
91 		to   = bp + (nsecs * secsize);
92 
93 		for (i = nsecs; i > 0; i--) {
94 			movebytes(from, to, isecsize);
95 			from -= isecsize;
96 			to   -= secsize;
97 		}
98 	}
99 }
100