iso9660: ~Check signature
[meinos.git] / apps / iso9660 / volume_descriptor.c
blob8cb963084dde633acbb415438484f076e3b8196d
1 /*
2 iso9660 - An iso9660 CDI driver with Rockridge support
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <stdint.h>
20 #include <string.h>
22 #include "cdi/fs.h"
24 #include "iso9660_cdi.h"
26 #include "iso9660def.h"
27 #include "volume_descriptor.h"
29 /**
30 * Checks signature of volume descriptor
31 * @param sig Signature
32 * @return If signature is right
34 static int iso9660_voldesc_checksig(uint8_t sig[6]) {
35 char right[6] = {'C','D','0','0','1',1};
36 return memcmp(right,sig,6)==0;
39 /**
40 * Loads a volume descriptor
41 * @param fs Filesystem
42 * @param type Type of volume descriptor
43 * @param buf Buffer for volume descriptor
44 * @return 0=success; -1=failure
46 int iso9660_voldesc_load(struct cdi_fs_filesystem *fs,iso9660_voldesc_type_t type,void *buf) {
47 debug("iso9660_voldesc_load(0x%x,%d,0x%x)\n",fs,type,buf);
48 struct iso9660_voldesc header;
49 size_t i;
51 for (i=ISO9660_FIRST_SECTOR;header.type!=type && header.type!=ISO9660_VOLDESC_TERM;i++) {
52 if (iso9660_sector_read(fs,i*ISO9660_DEFAULT_SECTOR_SIZE,sizeof(header),&header)!=sizeof(header)) return -1;
53 if (!iso9660_voldesc_checksig(header.signature)) return -1;
55 i--;
57 if (header.type==type) {
58 iso9660_sector_read(fs,i*ISO9660_DEFAULT_SECTOR_SIZE,sizeof(struct iso9660_voldesc_prim),buf);
59 return 0;
61 else {
62 debug("Volume Descriptor: Wrong type: %d\n",header.type);
63 return -1;