87
87
static void DECL(assign_joliet_directory_addresses, (struct directory * node));
88
88
static int jroot_gen __PR((void));
91
91
* Function: convert_to_unicode
93
93
* Purpose: Perform a 1/2 assed unicode conversion on a text
98
98
static void FDECL3(convert_to_unicode, unsigned char *, buffer, int, size, char *, source )
127
127
* JS integrated from: Achim_Kaiser@t-online.de
129
129
* Let all valid unicode characters pass through (assuming ISO-8859-1).
130
* Others are set to '_' .
132
if( tmpbuf[j] != 0 &&
130
* Others are set to '_' .
132
if( tmpbuf[j] != 0 &&
133
133
(tmpbuf[j] <= 0x1f || (tmpbuf[j] >= 0x7F && tmpbuf[j] <= 0xA0)) )
135
135
buffer[i+1] = '_';
179
179
rtn = strlen(string) << 1;
182
182
* We do clamp the maximum length of a Joliet string to be the
183
183
* maximum path size. This helps to ensure that we don't completely
184
184
* bolix things up with very long paths. The Joliet specs say
212
212
* "expands" 8 bit character codes to 16 bits and does nothing
213
213
* special with the Unicode characters, therefore shouldn't mkisofs
214
214
* really be stating that it's using UCS-2 Level 1, not Level 3 for
215
* the Joliet directory tree.
215
* the Joliet directory tree.
217
217
strcpy(jvol_desc->escape_sequences, "%/@");
229
229
* Set this one up.
231
memcpy(jvol_desc->root_directory_record, &jroot_record,
231
memcpy(jvol_desc->root_directory_record, &jroot_record,
232
232
sizeof(struct iso_directory_record));
277
277
/* skip if hidden - but not for the rr_moved dir */
278
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
278
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
280
280
assign_joliet_directory_addresses(dpnt->subdir);
303
303
} /* build_jpathlist(... */
305
static int FDECL2(joliet_compare_paths, void const *, r, void const *, l)
305
static int FDECL2(joliet_compare_paths, void const *, r, void const *, l)
307
307
struct directory const *ll = *(struct directory * const *)l;
308
308
struct directory const *rr = *(struct directory * const *)r;
349
* First allocate memory for the tables and initialize the memory
349
* First allocate memory for the tables and initialize the memory
351
351
tablesize = jpath_blocks << 11;
352
352
jpath_table_m = (char *) e_malloc(tablesize);
364
* Now start filling in the path tables. Start with root directory
364
* Now start filling in the path tables. Start with root directory
366
366
jpath_table_index = 0;
367
jpathlist = (struct directory **) e_malloc(sizeof(struct directory *)
367
jpathlist = (struct directory **) e_malloc(sizeof(struct directory *)
368
368
* next_jpath_index);
369
369
memset(jpathlist, 0, sizeof(struct directory *) * next_jpath_index);
370
370
build_jpathlist(root);
376
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
376
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
377
377
(int (*)(const void *, const void *))joliet_compare_paths);
379
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
379
qsort(&jpathlist[1], next_jpath_index-1, sizeof(struct directory *),
380
380
joliet_compare_paths);
401
401
npnt = dpnt->de_name;
403
403
npnt1 = strrchr(npnt, PATH_SEPARATOR);
406
406
npnt = npnt1 + 1;
412
fprintf (stderr, _("Fatal goof - directory has amnesia\n"));
412
fprintf (stderr, _("Fatal goof - directory has amnesia\n"));
416
416
namelen = joliet_strlen(de->name);
418
418
if( dpnt == root )
426
426
jpath_table_m[jpath_table_index] = namelen;
428
428
jpath_table_index += 2;
430
set_731(jpath_table_l + jpath_table_index, dpnt->jextent);
431
set_732(jpath_table_m + jpath_table_index, dpnt->jextent);
430
set_731(jpath_table_l + jpath_table_index, dpnt->jextent);
431
set_732(jpath_table_m + jpath_table_index, dpnt->jextent);
432
432
jpath_table_index += 4;
434
434
if( dpnt->parent != reloc_dir )
436
set_721(jpath_table_l + jpath_table_index,
437
dpnt->parent->jpath_index);
438
set_722(jpath_table_m + jpath_table_index,
439
dpnt->parent->jpath_index);
436
set_721(jpath_table_l + jpath_table_index,
437
dpnt->parent->jpath_index);
438
set_722(jpath_table_m + jpath_table_index,
439
dpnt->parent->jpath_index);
443
set_721(jpath_table_l + jpath_table_index,
444
dpnt->self->parent_rec->filedir->jpath_index);
445
set_722(jpath_table_m + jpath_table_index,
446
dpnt->self->parent_rec->filedir->jpath_index);
443
set_721(jpath_table_l + jpath_table_index,
444
dpnt->self->parent_rec->filedir->jpath_index);
445
set_722(jpath_table_m + jpath_table_index,
446
dpnt->self->parent_rec->filedir->jpath_index);
449
449
jpath_table_index += 2;
452
452
* The root directory is still represented in non-unicode fashion.
462
convert_to_unicode((uint8_t *)jpath_table_l + jpath_table_index,
462
convert_to_unicode((uint8_t *)jpath_table_l + jpath_table_index,
463
463
namelen, de->name);
464
convert_to_unicode((uint8_t *)jpath_table_m + jpath_table_index,
464
convert_to_unicode((uint8_t *)jpath_table_m + jpath_table_index,
465
465
namelen, de->name);
466
466
jpath_table_index += namelen;
469
if(jpath_table_index & 1)
469
if(jpath_table_index & 1)
471
471
jpath_table_index++; /* For odd lengths we pad */
476
476
if(jpath_table_index != jpath_table_size)
493
493
unsigned int total_size;
495
495
struct directory * finddir;
497
497
total_size = (dpnt->jsize + (SECTOR_SIZE - 1)) & ~(SECTOR_SIZE - 1);
498
498
directory_buffer = (char *) e_malloc(total_size);
499
499
memset(directory_buffer, 0, total_size);
502
502
s_entry = dpnt->jcontents;
505
505
if(s_entry->de_flags & INHIBIT_JOLIET_ENTRY) {
506
506
s_entry = s_entry->jnext;
511
511
* If this entry was a directory that was relocated, we have a bit
512
512
* of trouble here. We need to dig out the real thing and put it
536
536
s_entry1 = s_entry;
540
* We do not allow directory entries to cross sector boundaries.
541
* Simply pad, and then start the next entry at the next sector
540
* We do not allow directory entries to cross sector boundaries.
541
* Simply pad, and then start the next entry at the next sector
543
543
new_reclen = s_entry1->jreclen;
544
544
if( (dir_index & (SECTOR_SIZE - 1)) + new_reclen >= SECTOR_SIZE )
546
dir_index = (dir_index + (SECTOR_SIZE - 1)) &
546
dir_index = (dir_index + (SECTOR_SIZE - 1)) &
547
547
~(SECTOR_SIZE - 1);
550
550
memcpy(&jrec, &s_entry1->isorec, sizeof(struct iso_directory_record) -
551
551
sizeof(s_entry1->isorec.name));
553
553
cvt_len = joliet_strlen(s_entry1->name);
556
556
* Fix the record length - this was the non-Joliet version we
559
559
jrec.name_len[0] = cvt_len;
560
560
jrec.length[0] = s_entry1->jreclen;
563
563
* If this is a directory, fix the correct size and extent
566
566
if( (jrec.flags[0] & 2) != 0 )
568
if(strcmp(s_entry1->name,".") == 0)
568
if(strcmp(s_entry1->name,".") == 0)
570
570
jrec.name_len[0] = 1;
571
571
set_733((char *) jrec.extent, dpnt->jextent);
572
572
set_733((char *) jrec.size, ROUND_UP(dpnt->jsize));
574
else if(strcmp(s_entry1->name,"..") == 0)
574
else if(strcmp(s_entry1->name,"..") == 0)
576
576
jrec.name_len[0] = 1;
577
577
if( dpnt->parent == reloc_dir )
610
610
set_733((char *) jrec.size, ROUND_UP(finddir->jsize));
614
memcpy(directory_buffer + dir_index, &jrec,
614
memcpy(directory_buffer + dir_index, &jrec,
615
615
sizeof(struct iso_directory_record) -
616
616
sizeof(s_entry1->isorec.name));
619
dir_index += sizeof(struct iso_directory_record) -
619
dir_index += sizeof(struct iso_directory_record) -
620
620
sizeof (s_entry1->isorec.name);
623
623
* Finally dump the Unicode version of the filename.
624
624
* Note - . and .. are the same as with non-Joliet discs.
626
if( (jrec.flags[0] & 2) != 0
626
if( (jrec.flags[0] & 2) != 0
627
627
&& strcmp(s_entry1->name, ".") == 0 )
629
629
directory_buffer[dir_index++] = 0;
631
else if( (jrec.flags[0] & 2) != 0
631
else if( (jrec.flags[0] & 2) != 0
632
632
&& strcmp(s_entry1->name, "..") == 0 )
634
634
directory_buffer[dir_index++] = 1;
649
649
s_entry = s_entry->jnext;
652
652
if(dpnt->jsize != dir_index)
654
654
fprintf (stderr, _("Unexpected joliet directory length %d %d %s\n"),
655
655
dpnt->jsize, dir_index, dpnt->de_name);
658
658
xfwrite(directory_buffer, 1, total_size, outfile);
659
659
last_extent_written += total_size >> 11;
660
660
free(directory_buffer);
691
691
if(s_entry->isorec.flags[0] == 2)
693
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
693
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
695
695
jpath_table_size += joliet_strlen(s_entry->name) + sizeof(struct iso_path_table) - 1;
696
if (jpath_table_size & 1)
696
if (jpath_table_size & 1)
698
698
jpath_table_size++;
703
703
if (this_dir == root && strlen(s_entry->name) == 1)
711
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
711
if (strcmp(s_entry->name,".") && strcmp(s_entry->name,".."))
713
713
s_entry->jreclen = sizeof(struct iso_directory_record)
714
714
- sizeof(s_entry->isorec.name)
715
+ joliet_strlen(s_entry->name)
715
+ joliet_strlen(s_entry->name)
737
737
this_dir->jcontents = this_dir->contents;
738
738
status = joliet_sort_directory(&this_dir->jcontents);
741
741
* Now go through the directory and figure out how large this one will be.
742
* Do not split a directory entry across a sector boundary
742
* Do not split a directory entry across a sector boundary
744
744
s_entry = this_dir->jcontents;
758
758
jreclen = s_entry->jreclen;
760
760
if ((this_dir->jsize & (SECTOR_SIZE - 1)) + jreclen >= SECTOR_SIZE)
762
this_dir->jsize = (this_dir->jsize + (SECTOR_SIZE - 1)) &
762
this_dir->jsize = (this_dir->jsize + (SECTOR_SIZE - 1)) &
763
763
~(SECTOR_SIZE - 1);
765
765
this_dir->jsize += jreclen;
771
771
* Similar to the iso9660 case, except here we perform a full sort based upon the
772
772
* regular name of the file, not the 8.3 version.
774
static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
774
static int FDECL2(joliet_compare_dirs, const void *, rr, const void *, ll)
776
776
char * rpnt, *lpnt;
777
777
struct directory_entry ** r, **l;
779
779
r = (struct directory_entry **) rr;
780
780
l = (struct directory_entry **) ll;
781
781
rpnt = (*r)->name;
800
800
if( strcmp(rpnt, "..") == 0 ) return -1;
801
801
if( strcmp(lpnt, "..") == 0 ) return 1;
803
while(*rpnt && *lpnt)
803
while(*rpnt && *lpnt)
805
805
if(*rpnt == ';' && *lpnt != ';') return -1;
806
806
if(*rpnt != ';' && *lpnt == ';') return 1;
808
808
if(*rpnt == ';' && *lpnt == ';') return 0;
811
811
* Extensions are not special here. Don't treat the dot as something that
812
812
* must be bumped to the start of the list.
854
* OK, now we know how many there are. Build a vector for sorting.
854
* OK, now we know how many there are. Build a vector for sorting.
856
sortlist = (struct directory_entry **)
856
sortlist = (struct directory_entry **)
857
857
e_malloc(sizeof(struct directory_entry *) * dcount);
868
868
s_entry = s_entry->next;
873
qsort(sortlist, dcount, sizeof(struct directory_entry *),
873
qsort(sortlist, dcount, sizeof(struct directory_entry *),
874
874
(int (*)(const void *, const void *))joliet_compare_dirs);
876
qsort(sortlist, dcount, sizeof(struct directory_entry *),
876
qsort(sortlist, dcount, sizeof(struct directory_entry *),
877
877
joliet_compare_dirs);
881
* Now reassemble the linked list in the proper sorted order
881
* Now reassemble the linked list in the proper sorted order
883
883
for(i=0; i<dcount-1; i++)
936
936
/* skip if hidden - but not for the rr_moved dir */
937
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
937
if(dpnt->subdir && (!(dpnt->dir_flags & INHIBIT_JOLIET_ENTRY) || dpnt == reloc_dir))
938
938
generate_joliet_directories(dpnt->subdir, outfile);
939
939
dpnt = dpnt->next;
947
947
static int FDECL1(jpathtab_write, FILE *, outfile)
950
* Next we write the path tables
950
* Next we write the path tables
952
952
xfwrite(jpath_table_l, 1, jpath_blocks << 11, outfile);
953
953
xfwrite(jpath_table_m, 1, jpath_blocks << 11, outfile);