Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / fs / isofs / susp.c
blob78005b48a1f01b6118bc73a8f64479b4c3ed582d
1 /*
2 * This file contains support for System Use Sharing Protocol (SUSP) extension
3 * to ISO 9660.
4 */
6 #include "inc.h"
7 #include <sys/stat.h>
9 #ifdef ISO9660_OPTION_ROCKRIDGE
11 int parse_susp(struct rrii_dir_record *dir, char *buffer)
13 /* Parse fundamental SUSP entries */
14 char susp_signature[2];
15 u8_t susp_length;
16 u8_t susp_version;
17 u32_t ca_block_nr;
18 u32_t ca_offset;
19 u32_t ca_length;
20 struct buf *ca_bp;
21 int r;
23 susp_signature[0] = buffer[0];
24 susp_signature[1] = buffer[1];
25 susp_length = *((u8_t*)buffer + 2);
26 susp_version = *((u8_t*)buffer + 3);
28 if ((susp_signature[0] == 'C') && (susp_signature[1] == 'E') &&
29 (susp_length >= 28) && (susp_version >= 1)) {
31 * Continuation area, perform a recursion.
33 * FIXME: Currently we're parsing only first logical block of a
34 * continuation area, and infinite recursion is not checked.
37 ca_block_nr = *((u32_t*)(buffer + 4));
38 ca_offset = *((u32_t*)(buffer + 12));
39 ca_length = *((u32_t*)(buffer + 20));
41 /* Truncate continuation area to fit one logical block. */
42 if (ca_offset >= v_pri.logical_block_size_l) {
43 return EINVAL;
45 if (ca_offset + ca_length > v_pri.logical_block_size_l) {
46 ca_length = v_pri.logical_block_size_l - ca_offset;
49 r = lmfs_get_block(&ca_bp, fs_dev, ca_block_nr, NORMAL);
50 if (r != OK)
51 return r;
53 parse_susp_buffer(dir, b_data(ca_bp) + ca_offset, ca_length);
54 lmfs_put_block(ca_bp);
56 return OK;
58 else if ((susp_signature[0] == 'P') && (susp_signature[1] == 'D')) {
59 /* Padding, skip. */
60 return OK;
62 else if ((susp_signature[0] == 'S') && (susp_signature[1] == 'P')) {
63 /* Ignored, skip. */
64 return OK;
66 else if ((susp_signature[0] == 'S') && (susp_signature[1] == 'T')) {
67 /* Terminator entry, stop processing. */
68 return(ECANCELED);
70 else if ((susp_signature[0] == 'E') && (susp_signature[1] == 'R')) {
71 /* Ignored, skip. */
72 return OK;
74 else if ((susp_signature[0] == 'E') && (susp_signature[1] == 'S')) {
75 /* Ignored, skip. */
76 return OK;
79 /* Not a SUSP fundamental entry. */
80 return EINVAL;
83 void parse_susp_buffer(struct rrii_dir_record *dir, char *buffer, u32_t size)
86 * Parse a SUSP system use entry for the ISO 9660.
87 * This is the main entry point for parsing SUSP data : SUSP entries are
88 * routed from here to the relevant handling functions.
90 char susp_signature[2];
91 u8_t susp_length;
93 int parser_return;
95 while (TRUE) {
96 /* A SUSP entry can't be smaller than 4 bytes. */
97 if (size < 4)
98 return;
100 susp_signature[0] = buffer[0];
101 susp_signature[1] = buffer[1];
102 susp_length = *((u8_t*)buffer + 2);
104 /* Check if SUSP entry is present. */
105 if (((susp_signature[0] == 0) && (susp_signature[1] == 0)) ||
106 (susp_length > size) || (susp_length < 4))
107 return;
109 /* Check for SUSP fundamental entry. */
110 parser_return = parse_susp(dir, buffer);
111 if (parser_return == ECANCELED)
112 return;
113 else if (parser_return == OK)
114 goto next_entry;
116 /* Check for Rock Ridge entry. */
117 if (opt.norock == FALSE) {
118 parser_return = parse_susp_rock_ridge(dir, buffer);
119 if (parser_return == ECANCELED)
120 return;
121 else if (parser_return == OK)
122 goto next_entry;
125 /* Parse next SUSP entry. */
126 next_entry:
127 buffer += susp_length;
128 size -= susp_length;
132 #endif