2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)dvd_reader.c 1.3 04/03/04 joerg */
15 * Copyright (C) 2001, 2002 Billy Biggs <vektor@dumbterm.net>,
16 * Håkan Hjort <d95hjort@dtek.chalmers.se>,
17 * Olaf Beck <olaf_sc@yahoo.com>
18 * (I only did the cut down no other contribs)
19 * Jörg Schilling <schilling@fokus.gmd.de>
20 * (making the code portable)
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or (at
24 * your option) any later version.
26 * This program is distributed in the hope that it will be useful, but
27 * WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * General Public License for more details.
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 * NOTE: This is a cut down version of libdvdread for genisoimage, due
38 * to portability issues with the current libdvdread according to
39 * the maintainer of genisoimage.
40 * This cut down version only reads from a harddisk file structure
41 * and it only implements the functions necessary inorder to make
42 * genisoimage produce valid DVD-Video images.
43 * DON'T USE THIS LIBRARY IN ANY OTHER PROGRAM GET THE REAL
48 #include "genisoimage.h"
52 #include "dvd_reader.h"
55 /* Basic information. */
58 /* Calculated at open-time, size in blocks. */
63 void DVDCloseFile(dvd_file_t *dvd_file);
64 static dvd_file_t *DVDOpenFilePath(dvd_reader_t *dvd, char *filename);
65 static dvd_file_t *DVDOpenVOBPath(dvd_reader_t *dvd, int title, int menu);
66 dvd_file_t *DVDOpenFile(dvd_reader_t *dvd, int titlenum,
67 dvd_read_domain_t domain);
68 static dvd_reader_t *DVDOpenPath(const char *path_root);
69 dvd_reader_t *DVDOpen(const char *path);
70 void DVDClose(dvd_reader_t *dvd);
71 ssize_t DVDFileSize(dvd_file_t *dvd_file);
78 DVDCloseFile(dvd_file_t *dvd_file)
86 * Stat a IFO or BUP file from a DVD directory tree.
89 DVDOpenFilePath(dvd_reader_t *dvd, char *filename)
92 char full_path[PATH_MAX + 1];
96 /* Get the full path of the file. */
98 snprintf(full_path, sizeof (full_path),
99 "%s/%s", dvd->path_root, filename);
102 dvd_file = (dvd_file_t *) e_malloc(sizeof (dvd_file_t));
106 dvd_file->filesize = 0;
108 if (stat(full_path, &fileinfo) < 0) {
112 dvd_file->filesize = fileinfo.st_size / DVD_VIDEO_LB_LEN;
119 * Stat a VOB file from a DVD directory tree.
122 DVDOpenVOBPath(dvd_reader_t *dvd, int title, int menu)
125 char filename[PATH_MAX + 1];
126 struct stat fileinfo;
127 dvd_file_t *dvd_file;
130 dvd_file = (dvd_file_t *) e_malloc(sizeof (dvd_file_t));
134 dvd_file->filesize = 0;
138 snprintf(filename, sizeof (filename),
139 "%s/VIDEO_TS/VIDEO_TS.VOB", dvd->path_root);
141 snprintf(filename, sizeof (filename),
142 "%s/VIDEO_TS/VTS_%02i_0.VOB", dvd->path_root, title);
144 if (stat(filename, &fileinfo) < 0) {
148 dvd_file->filesize = fileinfo.st_size / DVD_VIDEO_LB_LEN;
150 for (i = 0; i < 9; ++i) {
152 snprintf(filename, sizeof (filename),
153 "%s/VIDEO_TS/VTS_%02i_%i.VOB", dvd->path_root, title, i + 1);
154 if (stat(filename, &fileinfo) < 0) {
158 dvd_file->filesize += fileinfo.st_size / DVD_VIDEO_LB_LEN;
166 * Stat a DVD file from a DVD directory tree
169 DVDOpenFile(dvd_reader_t *dvd, int titlenum, dvd_read_domain_t domain)
171 char filename[MAX_UDF_FILE_NAME_LEN];
175 case DVD_READ_INFO_FILE:
177 snprintf(filename, sizeof (filename),
178 "/VIDEO_TS/VIDEO_TS.IFO");
180 snprintf(filename, sizeof (filename),
181 "/VIDEO_TS/VTS_%02i_0.IFO", titlenum);
185 case DVD_READ_INFO_BACKUP_FILE:
187 snprintf(filename, sizeof (filename),
188 "/VIDEO_TS/VIDEO_TS.BUP");
190 snprintf(filename, sizeof (filename),
191 "/VIDEO_TS/VTS_%02i_0.BUP", titlenum);
195 case DVD_READ_MENU_VOBS:
196 return (DVDOpenVOBPath(dvd, titlenum, 1));
198 case DVD_READ_TITLE_VOBS:
201 return (DVDOpenVOBPath(dvd, titlenum, 0));
205 errmsgno(EX_BAD, "Invalid domain for file open.\n");
207 fprintf(stderr, "Invalid domain for file open.\n");
211 return (DVDOpenFilePath(dvd, filename));
217 * Stat a DVD directory structure
219 static dvd_reader_t *
220 DVDOpenPath(const char *path_root)
224 dvd = (dvd_reader_t *) e_malloc(sizeof (dvd_reader_t));
227 dvd->path_root = strdup(path_root);
234 * Stat a DVD structure - this one only works with directory structures
237 DVDOpen(const char *path)
239 struct stat fileinfo;
245 ret = stat(path, &fileinfo);
247 /* If we can't stat the file, give up */
249 errmsg("Can't stat %s\n", path);
251 fprintf(stderr, "Can't stat %s\n", path);
258 if (S_ISDIR(fileinfo.st_mode)) {
259 return (DVDOpenPath(path));
262 /* If it's none of the above, screw it. */
264 errmsgno(EX_BAD, "Could not open %s\n", path);
266 fprintf(stderr, "Could not open %s\n", path);
272 * Free a DVD structure - this one will only close a directory tree
275 DVDClose(dvd_reader_t *dvd)
278 if (dvd->path_root) free(dvd->path_root);
287 * Return the size of a DVD file
290 DVDFileSize(dvd_file_t *dvd_file)
292 return (dvd_file->filesize);
295 #endif /* DVD_VIDEO */