ReactOS 0.4.16-dev-319-g6cf4263
stream.c
Go to the documentation of this file.
1/* @(#)stream.c 1.17 15/12/08 Copyright 2002-2015 J. Schilling */
2#include <schily/mconfig.h>
3#ifndef lint
4static UConst char sccsid[] =
5 "@(#)stream.c 1.17 15/12/08 Copyright 2002-2015 J. Schilling";
6#endif
7/*
8 * ISO-9660 stream (pipe) file module for mkisofs
9 *
10 * Copyright (c) 2002-2015 J. Schilling
11 * Implemented after an idea from M.H. Voase
12 */
13/*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along with
24 * this program; see the file COPYING. If not, write to the Free Software
25 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27
28#include "mkisofs.h"
29#include "iso9660.h"
30#include <schily/schily.h>
31
32LOCAL int size_str_file __PR((UInt32_t starting_extent));
33LOCAL int size_str_dir __PR((UInt32_t starting_extent));
34LOCAL int size_str_path __PR((UInt32_t starting_extent));
35
37
41
42extern int stream_media_size;
43extern char *stream_filename;
44extern time_t begun;
45
46LOCAL unsigned int avail_extent;
47LOCAL unsigned int stream_extent;
48LOCAL unsigned int stream_size;
49LOCAL unsigned int stream_pad;
54
55/*
56 * Compute the size of the file
57 */
58LOCAL int
59size_str_file(starting_extent)
60 UInt32_t starting_extent;
61{
62 int n;
63extern int dopad;
64
65 stream_extent = last_extent; /* Start of stream file content */
66
68 n = last_extent; /* Room for FS blocks before file */
69 n += 1; /* Room for the directory block */
70 stream_pad = 0;
71 if (n < 50) {
72 stream_pad = 50 - n;
73 n = 50; /* Make net. size easy to compute */
74 }
75 if (dopad)
76 n += 150; /* Room for final padding */
77
78 if (n >= avail_extent) {
80 _("-stream-media-size %d but must be at least %d\n"),
81 avail_extent, n+2);
82 }
83 avail_extent -= n;
84
86
87 return (0);
88}
89
90/*
91 * The size of the directory record - one sector
92 */
93LOCAL int
94size_str_dir(starting_extent)
95 UInt32_t starting_extent;
96{
97 root->extent = last_extent;
98 last_extent += 1;
99 return (0);
100}
101
102/*
103 * The size of the path tables - two sectors
104 */
105LOCAL int
106size_str_path(starting_extent)
107 UInt32_t starting_extent;
108{
109 path_table[0] = starting_extent;
110 path_table[1] = 0;
111 path_table[2] = path_table[0] + 1;
112 path_table[3] = 0;
113 last_extent += 2 * 1;
114 return (0);
115}
116
117/*
118 * Generate the path table data
119 */
120LOCAL int
122{
123 /*
124 * Basically add the root directory entry
125 */
126 l_path = (char *)e_malloc(SECTOR_SIZE);
127 m_path = (char *)e_malloc(SECTOR_SIZE);
130 l_path[0] = 1;
131 m_path[0] = 1;
132 set_731(l_path + 2, root->extent);
133 set_732(m_path + 2, root->extent);
134 set_721(l_path + 6, 1);
135 set_722(m_path + 6, 1);
136 l_path[8] = '\0'; l_path[9] = '\0';
137 m_path[8] = '\0'; m_path[9] = '\0';
138 return (0);
139}
140
141/*
142 * Write the file content
143 */
144LOCAL int
146 FILE *outfile;
147{
148 unsigned int idx = 0;
149 unsigned int iso_blocks;
150 int count;
151 char *buf;
152
154 stream_size = 0;
155 while ((idx + SECTOR_SIZE) < (avail_extent * SECTOR_SIZE)) {
158 if (count <= 0) {
159 stream_finished = 1;
160 break;
161 }
162 idx += count;
163 xfwrite(buf, count, 1, outfile, 0, FALSE);
164 }
165
167 iso_blocks = ISO_BLOCKS(idx);
169 if (SECTOR_SIZE * iso_blocks - idx)
170 xfwrite(buf, SECTOR_SIZE * iso_blocks - idx, 1, outfile, 0, FALSE);
171 /*
172 * If we didn't fill the available area, pad to directory block
173 */
174 for (count = 0; count < (avail_extent - iso_blocks); count++)
176
177 for (count = 0; count < stream_pad; count++)
179
181 free(buf);
182 return (0);
183}
184
185/*
186 * Generate and write the directory record data
187 */
188LOCAL int
190 FILE *outfile;
191{
192 int reclen;
193 char *buf;
194
196 memset(&s_dir, 0, sizeof (struct iso_directory_record));
197 s_dir.length[0] = 34; /* BAD: Hardcoded - Will fix, MHV */
198 s_dir.ext_attr_length[0] = 0;
199 set_733((char *)s_dir.extent, root->extent);
200 set_733((char *)s_dir.size, SECTOR_SIZE);
201 iso9660_date(s_dir.date, begun);
202 s_dir.flags[0] = ISO_DIRECTORY;
203 s_dir.file_unit_size[0] = 0;
204 s_dir.interleave[0] = 0;
205 set_723((char *)s_dir.volume_sequence_number, volume_sequence_number);
206 s_dir.name_len[0] = 1;
207 s_dir.name[0] = 0; /* "." */
208 xfwrite(&s_dir, offsetof(struct iso_directory_record, name[0]) + 1, 1, outfile, 0, FALSE);
209 s_dir.name[0] = 1; /* ".." */
210 xfwrite(&s_dir, offsetof(struct iso_directory_record, name[0]) + 1, 1, outfile, 0, FALSE);
211 memset(&s_dir, 0, sizeof (struct iso_directory_record));
212 reclen = offsetof(struct iso_directory_record, name[0]) +
214 if (reclen & 1)
215 reclen++;
216 s_dir.length[0] = reclen;
217 s_dir.ext_attr_length[0] = 0;
218 set_733((char *)s_dir.extent, stream_extent);
219 set_733((char *)s_dir.size, stream_size);
220 iso9660_date(s_dir.date, begun);
221 s_dir.flags[0] = 0;
222 s_dir.file_unit_size[0] = 0;
223 set_723((char *)s_dir.volume_sequence_number, volume_sequence_number);
224 s_dir.name_len[0] = strlen(stream_filename);
225 memcpy(s_dir.name, stream_filename, s_dir.name_len[0]);
226 xfwrite(&s_dir, reclen, 1, outfile, 0, FALSE);
227
228 /*
229 * This calc is: 2 single char directory entries (34) + an additional entry
230 * with filename length stream_filename + round up for even lenght count
231 */
232 xfwrite(buf, SECTOR_SIZE - ((2 * 34) + reclen), 1, outfile, 0, FALSE);
233 free(buf);
235 return (0);
236}
237
238/*
239 * Generate the path table data
240 */
241LOCAL int
243 FILE *outfile;
244{
248 free(l_path);
249 free(m_path);
252 return (0);
253}
254
256struct output_fragment strdir_desc = { NULL, size_str_dir, NULL, write_str_dir, "Stream File Directory" };
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define SECTOR_SIZE
Definition: fs.h:22
#define UConst
Definition: ccomdefs.h:72
EXPORT void comerrno(int err, char *msg, va_alist)
Definition: comerr.c:137
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
unsigned int idx
Definition: utils.c:41
__kernel_time_t time_t
Definition: linux.h:252
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define _(X)
Definition: i386-dis.c:35
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
#define stdin
Definition: stdio.h:98
#define ISO_DIRECTORY
Definition: iso9660.h:265
EXPORT void set_723(void *vp, UInt32_t i)
Definition: isonum.c:76
EXPORT void set_731(void *vp, UInt32_t i)
Definition: isonum.c:91
EXPORT void set_722(void *vp, UInt32_t i)
Definition: isonum.c:61
EXPORT void set_721(void *vp, UInt32_t i)
Definition: isonum.c:46
EXPORT void set_732(void *vp, UInt32_t i)
Definition: isonum.c:108
EXPORT void set_733(void *vp, UInt32_t i)
Definition: isonum.c:125
#define LOCAL(type)
Definition: jmorecfg.h:289
EXPORT int iso9660_date(char *result, time_t crtime)
Definition: mkisofs.c:1868
int volume_sequence_number
Definition: mkisofs.c:173
char * path_table_m
Definition: mkisofs.c:1632
char * path_table_l
Definition: mkisofs.c:1631
EXPORT void * e_malloc(size_t size)
Definition: mkisofs.c:3921
unsigned int path_table[4]
Definition: mkisofs.c:79
int dopad
Definition: mkisofs.c:154
UInt32_t last_extent
Definition: mkisofs.c:76
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
UInt32_t last_extent_written
Definition: write.c:303
#define ISO_BLOCKS(X)
Definition: mkisofs.h:743
#define __PR(a)
Definition: prototyp.h:106
#define offsetof(TYPE, MEMBER)
#define memset(x, y, z)
Definition: compat.h:39
struct output_fragment strfile_desc
Definition: stream.c:255
LOCAL int write_str_path(FILE *outfile)
Definition: stream.c:242
LOCAL int stream_finished
Definition: stream.c:53
LOCAL char * m_path
Definition: stream.c:51
struct output_fragment strdir_desc
Definition: stream.c:256
LOCAL unsigned int stream_pad
Definition: stream.c:49
static UConst char sccsid[]
Definition: stream.c:4
LOCAL char * l_path
Definition: stream.c:50
char * stream_filename
Definition: mkisofs.c:261
LOCAL int size_str_path(UInt32_t starting_extent)
Definition: stream.c:106
int stream_media_size
Definition: mkisofs.c:260
struct output_fragment strpath_desc
Definition: stream.c:257
LOCAL struct iso_directory_record s_dir
Definition: stream.c:52
LOCAL int write_str_file(FILE *outfile)
Definition: stream.c:145
LOCAL int gen_str_path()
Definition: stream.c:121
LOCAL int write_str_dir(FILE *outfile)
Definition: stream.c:189
LOCAL int size_str_dir(UInt32_t starting_extent)
Definition: stream.c:94
LOCAL unsigned int stream_extent
Definition: stream.c:47
LOCAL unsigned int stream_size
Definition: stream.c:48
LOCAL unsigned int avail_extent
Definition: stream.c:46
LOCAL int size_str_file(UInt32_t starting_extent)
Definition: stream.c:59
time_t begun
Definition: write.c:305
EXPORT void xfwrite(void *buffer, int size, int count, FILE *file, int submode, BOOL islast)
Definition: write.c:168
#define EX_BAD
Definition: standard.h:62
Definition: name.c:39
static FILE * outfile
Definition: wrjpgcom.c:81