Changeset a35b458 in mainline for uspace/srv/fs/udf/udf_osta.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/udf/udf_osta.c
r3061bc1 ra35b458 59 59 if ((ch == 0x0000) || (ch == 0x002F)) 60 60 return false; 61 61 62 62 return true; 63 63 } … … 85 85 /* Use udf_compressed to store current byte being read. */ 86 86 uint8_t comp_id = udf_compressed[0]; 87 87 88 88 /* First check for valid compID. */ 89 89 if ((comp_id != 8) && (comp_id != 16)) 90 90 return 0; 91 91 92 92 size_t unicode_idx = 0; 93 93 size_t byte_idx = 1; 94 94 95 95 /* Loop through all the bytes. */ 96 96 while ((byte_idx < number_of_bytes) && (unicode_idx < unicode_max_len)) { … … 103 103 } else 104 104 unicode[unicode_idx] = 0; 105 105 106 106 if (byte_idx < number_of_bytes) { 107 107 /* Then the next byte to the low bits. */ 108 108 unicode[unicode_idx] |= udf_compressed[byte_idx++]; 109 109 } 110 110 111 111 unicode_idx++; 112 112 } 113 113 114 114 return unicode_idx; 115 115 } … … 136 136 size_t new_idx = 0; 137 137 size_t new_ext_idx = 0; 138 138 139 139 for (size_t idx = 0; idx < udf_len; idx++) { 140 140 uint16_t current = udf_name[idx]; 141 141 142 142 if ((!legal_check(current)) || (!ascii_check(current))) { 143 143 needs_crc = true; 144 144 145 145 /* 146 146 * Replace Illegal and non-displayable chars with … … 148 148 */ 149 149 current = ILLEGAL_CHAR_MARK; 150 150 151 151 /* 152 152 * Skip any other illegal or non-displayable … … 158 158 idx++; 159 159 } 160 160 161 161 /* Record position of extension, if one is found. */ 162 162 if ((current == PERIOD) && ((udf_len - idx - 1) <= EXT_SIZE)) { … … 170 170 } 171 171 } 172 172 173 173 if (new_idx < MAXLEN) 174 174 new_name[new_idx++] = current; … … 176 176 needs_crc = true; 177 177 } 178 178 179 179 if (needs_crc) { 180 180 uint16_t ext[EXT_SIZE]; 181 181 size_t local_ext_idx = 0; 182 182 183 183 if (has_ext) { 184 184 size_t max_filename_len; 185 185 186 186 /* Translate extension, and store it in ext. */ 187 187 for (size_t idx = 0; (idx < EXT_SIZE) && 188 188 (ext_idx + idx + 1 < udf_len); idx++) { 189 189 uint16_t current = udf_name[ext_idx + idx + 1]; 190 190 191 191 if ((!legal_check(current)) || (!ascii_check(current))) { 192 192 needs_crc = true; 193 193 194 194 /* 195 195 * Replace Illegal and non-displayable … … 197 197 */ 198 198 current = ILLEGAL_CHAR_MARK; 199 199 200 200 /* 201 201 * Skip any other illegal or … … 207 207 idx++; 208 208 } 209 209 210 210 ext[local_ext_idx++] = current; 211 211 } 212 212 213 213 /* 214 214 * Truncate filename to leave room for extension and … … 224 224 new_idx = MAXLEN - 5; 225 225 } 226 226 227 227 /* Add mark for CRC. */ 228 228 new_name[new_idx++] = CRC_MARK; 229 229 230 230 /* Calculate CRC from original filename. */ 231 231 uint16_t value_crc = udf_unicode_cksum(udf_name, udf_len); 232 232 233 233 /* Convert 16-bits of CRC to hex characters. */ 234 234 const char hex_char[] = "0123456789ABCDEF"; 235 235 236 236 new_name[new_idx++] = hex_char[(value_crc & 0xf000) >> 12]; 237 237 new_name[new_idx++] = hex_char[(value_crc & 0x0f00) >> 8]; 238 238 new_name[new_idx++] = hex_char[(value_crc & 0x00f0) >> 4]; 239 239 new_name[new_idx++] = hex_char[(value_crc & 0x000f)]; 240 240 241 241 /* Place a translated extension at end, if found. */ 242 242 if (has_ext) { 243 243 new_name[new_idx++] = PERIOD; 244 244 245 245 for (size_t idx = 0; idx < local_ext_idx; idx++) 246 246 new_name[new_idx++] = ext[idx]; 247 247 } 248 248 } 249 249 250 250 return new_idx; 251 251 } … … 265 265 const char *osta_id = "OSTA Compressed Unicode"; 266 266 size_t ucode_chars, nice_uchars; 267 267 268 268 uint16_t *raw_name = malloc(MAX_BUF * sizeof(uint16_t)); 269 269 uint16_t *unix_name = malloc(MAX_BUF * sizeof(uint16_t)); 270 270 271 271 // FIXME: Check for malloc returning NULL 272 272 273 273 bool is_osta_typ0 = (chsp->type == 0) && 274 274 (str_cmp((char *) chsp->info, osta_id) == 0); 275 275 276 276 if (is_osta_typ0) { 277 277 *raw_name = 0; 278 278 *unix_name = 0; 279 279 280 280 ucode_chars = 281 281 udf_uncompress_unicode(len, (uint8_t *) id, raw_name, MAX_BUF); … … 283 283 nice_uchars = 284 284 udf_translate_name(unix_name, raw_name, ucode_chars); 285 285 286 286 /* Output UTF-8 */ 287 287 unix_name[nice_uchars] = 0; … … 292 292 str_size((char *) (id + 1))); 293 293 } 294 294 295 295 free(raw_name); 296 296 free(unix_name);
Note:
See TracChangeset
for help on using the changeset viewer.