wok view libdvdread/stuff/DVDFileStat.patch @ rev 12156
squidcalmav: typo
author | Eric Joseph-Alexandre <erjo@slitaz.org> |
---|---|
date | Sat Mar 17 12:23:37 2012 +0100 (2012-03-17) |
parents | |
children |
line source
1 diff -pruN libdvdread-4.1.3/src/dvd_reader.c libdvdread-4.1.3.new/src/dvd_reader.c
2 --- libdvdread-4.1.3/src/dvd_reader.c 2008-09-06 23:55:51.000000000 +0200
3 +++ libdvdread-4.1.3.new/src/dvd_reader.c 2009-02-28 01:36:20.000000000 +0100
4 @@ -889,6 +889,187 @@ void DVDCloseFile( dvd_file_t *dvd_file
5 }
6 }
8 +static int DVDFileStatVOBUDF(dvd_reader_t *dvd, int title,
9 + int menu, dvd_stat_t *statbuf)
10 +{
11 + char filename[ MAX_UDF_FILE_NAME_LEN ];
12 + uint32_t size;
13 + off_t tot_size;
14 + off_t parts_size[9];
15 + int nr_parts = 0;
16 + int n;
17 +
18 + if( title == 0 ) {
19 + sprintf( filename, "/VIDEO_TS/VIDEO_TS.VOB" );
20 + } else {
21 + sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
22 + }
23 + if(!UDFFindFile( dvd, filename, &size )) {
24 + return -1;
25 + }
26 + tot_size = size;
27 + nr_parts = 1;
28 + parts_size[0] = size;
29 +
30 + if( !menu ) {
31 + int cur;
32 +
33 + for( cur = 2; cur < 10; cur++ ) {
34 + sprintf( filename, "/VIDEO_TS/VTS_%02d_%d.VOB", title, cur );
35 + if( !UDFFindFile( dvd, filename, &size ) ) {
36 + break;
37 + }
38 + parts_size[nr_parts] = size;
39 + tot_size += size;
40 + nr_parts++;
41 + }
42 + }
43 +
44 + statbuf->size = tot_size;
45 + statbuf->nr_parts = nr_parts;
46 + for(n = 0; n < nr_parts; n++) {
47 + statbuf->parts_size[n] = parts_size[n];
48 + }
49 + return 0;
50 +}
51 +
52 +
53 +static int DVDFileStatVOBPath( dvd_reader_t *dvd, int title,
54 + int menu, dvd_stat_t *statbuf )
55 +{
56 + char filename[ MAX_UDF_FILE_NAME_LEN ];
57 + char full_path[ PATH_MAX + 1 ];
58 + struct stat fileinfo;
59 + off_t tot_size;
60 + off_t parts_size[9];
61 + int nr_parts = 0;
62 + int n;
63 +
64 +
65 +
66 + if( title == 0 ) {
67 + sprintf( filename, "VIDEO_TS.VOB" );
68 + } else {
69 + sprintf( filename, "VTS_%02d_%d.VOB", title, menu ? 0 : 1 );
70 + }
71 + if( !findDVDFile( dvd, filename, full_path ) ) {
72 + return -1;
73 + }
74 +
75 + if( stat( full_path, &fileinfo ) < 0 ) {
76 + fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
77 + return -1;
78 + }
79 +
80 +
81 + tot_size = fileinfo.st_size;
82 + nr_parts = 1;
83 + parts_size[0] = fileinfo.st_size;
84 +
85 + if( !menu ) {
86 + int cur;
87 +
88 + for( cur = 2; cur < 10; cur++ ) {
89 +
90 + sprintf( filename, "VTS_%02d_%d.VOB", title, cur );
91 + if( !findDVDFile( dvd, filename, full_path ) ) {
92 + break;
93 + }
94 +
95 + if( stat( full_path, &fileinfo ) < 0 ) {
96 + fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
97 + break;
98 + }
99 +
100 + parts_size[nr_parts] = fileinfo.st_size;
101 + tot_size += parts_size[nr_parts];
102 + nr_parts++;
103 + }
104 + }
105 +
106 + statbuf->size = tot_size;
107 + statbuf->nr_parts = nr_parts;
108 + for(n = 0; n < nr_parts; n++) {
109 + statbuf->parts_size[n] = parts_size[n];
110 + }
111 + return 0;
112 +}
113 +
114 +
115 +int DVDFileStat(dvd_reader_t *dvd, int titlenum,
116 + dvd_read_domain_t domain, dvd_stat_t *statbuf)
117 +{
118 + char filename[ MAX_UDF_FILE_NAME_LEN ];
119 + char full_path[ PATH_MAX + 1 ];
120 + struct stat fileinfo;
121 + uint32_t size;
122 +
123 + /* Check arguments. */
124 + if( dvd == NULL || titlenum < 0 ) {
125 + errno = EINVAL;
126 + return -1;
127 + }
128 +
129 + switch( domain ) {
130 + case DVD_READ_INFO_FILE:
131 + if( titlenum == 0 ) {
132 + sprintf( filename, "/VIDEO_TS/VIDEO_TS.IFO" );
133 + } else {
134 + sprintf( filename, "/VIDEO_TS/VTS_%02i_0.IFO", titlenum );
135 + }
136 + break;
137 + case DVD_READ_INFO_BACKUP_FILE:
138 + if( titlenum == 0 ) {
139 + sprintf( filename, "/VIDEO_TS/VIDEO_TS.BUP" );
140 + } else {
141 + sprintf( filename, "/VIDEO_TS/VTS_%02i_0.BUP", titlenum );
142 + }
143 + break;
144 + case DVD_READ_MENU_VOBS:
145 + if( dvd->isImageFile ) {
146 + return DVDFileStatVOBUDF( dvd, titlenum, 1, statbuf );
147 + } else {
148 + return DVDFileStatVOBPath( dvd, titlenum, 1, statbuf );
149 + }
150 + break;
151 + case DVD_READ_TITLE_VOBS:
152 + if( titlenum == 0 ) {
153 + return -1;
154 + }
155 + if( dvd->isImageFile ) {
156 + return DVDFileStatVOBUDF( dvd, titlenum, 0, statbuf );
157 + } else {
158 + return DVDFileStatVOBPath( dvd, titlenum, 0, statbuf );
159 + }
160 + break;
161 + default:
162 + fprintf( stderr, "libdvdread: Invalid domain for file stat.\n" );
163 + errno = EINVAL;
164 + return -1;
165 + }
166 +
167 + if( dvd->isImageFile ) {
168 + if( UDFFindFile( dvd, filename, &size ) ) {
169 + statbuf->size = size;
170 + statbuf->nr_parts = 1;
171 + statbuf->parts_size[0] = size;
172 + return 0;
173 + }
174 + } else {
175 + if( findDVDFile( dvd, filename, full_path ) ) {
176 + if( stat( full_path, &fileinfo ) < 0 ) {
177 + fprintf( stderr, "libdvdread: Can't stat() %s.\n", filename );
178 + } else {
179 + statbuf->size = fileinfo.st_size;
180 + statbuf->nr_parts = 1;
181 + statbuf->parts_size[0] = statbuf->size;
182 + return 0;
183 + }
184 + }
185 + }
186 + return -1;
187 +}
188 +
189 /* Internal, but used from dvd_udf.c */
190 int UDFReadBlocksRaw( dvd_reader_t *device, uint32_t lb_number,
191 size_t block_count, unsigned char *data,
192 diff -pruN libdvdread-4.1.3/src/dvd_reader.h libdvdread-4.1.3.new/src/dvd_reader.h
193 --- libdvdread-4.1.3/src/dvd_reader.h 2008-09-06 23:55:51.000000000 +0200
194 +++ libdvdread-4.1.3.new/src/dvd_reader.h 2009-02-28 01:36:49.000000000 +0100
195 @@ -115,6 +115,42 @@ typedef enum {
196 } dvd_read_domain_t;
198 /**
199 + *
200 + */
201 +typedef struct {
202 + off_t size; /**< Total size of file in bytes */
203 + int nr_parts; /**< Number of file parts */
204 + off_t parts_size[9]; /**< Size of each part in bytes */
205 +} dvd_stat_t;
206 +
207 +/**
208 + * Stats a file on the DVD given the title number and domain.
209 + * The information about the file is stored in a dvd_stat_t
210 + * which contains information about the size of the file and
211 + * the number of parts in case of a multipart file and the respective
212 + * sizes of the parts.
213 + * A multipart file is for instance VTS_02_1.VOB, VTS_02_2.VOB, VTS_02_3.VOB
214 + * The size of VTS_02_1.VOB will be stored in stat->parts_size[0],
215 + * VTS_02_2.VOB in stat->parts_size[1], ...
216 + * The total size (sum of all parts) is stored in stat->size and
217 + * stat->nr_parts will hold the number of parts.
218 + * Only DVD_READ_TITLE_VOBS (VTS_??_[1-9].VOB) can be multipart files.
219 + *
220 + * This function is only of use if you want to get the size of each file
221 + * in the filesystem. These sizes are not needed to use any other
222 + * functions in libdvdread.
223 + *
224 + * @param dvd A dvd read handle.
225 + * @param titlenum Which Video Title Set should be used, VIDEO_TS is 0.
226 + * @param domain Which domain.
227 + * @param stat Pointer to where the result is stored.
228 + * @return If successful 0, otherwise -1.
229 + *
230 + * int DVDFileStat(dvd, titlenum, domain, stat);
231 + */
232 +int DVDFileStat(dvd_reader_t *, int, dvd_read_domain_t, dvd_stat_t *);
233 +
234 +/**
235 * Opens a file on the DVD given the title number and domain.
236 *
237 * If the title number is 0, the video manager information is opened