50 # define WIN32_LEAN_AND_MEAN 58 # if defined(__FreeBSD__) || defined(__APPLE__) 62 # endif // __FreeBSD__ 76 typedef unsigned char BYTE;
77 typedef unsigned short WORD;
84 #define MAX_NAME_LENGTH 64 85 #define MAX_CDNAME_LENGTH 8 86 #define MAX_EXTENSION_LENGTH 10 87 #define MAX_CDEXTENSION_LENGTH 3 88 #define SECTOR_SIZE 2048 89 #define BUFFER_SIZE (8 * SECTOR_SIZE) 92 #define DIRECTORY_FLAG 2 261 if (
i % 4 == 2)
s[--
i] =
',';
263 }
while ((
x/=10) != 0);
266 while (
i > 0)
s[--
i] =
' ';
296 free(
root.next_in_memory->joliet_name);
356 cd.buffer[
cd.count] =
x;
420 while (
cd.offset != 0)
437 while (*
s != 0 && bytecount != 0)
442 while (bytecount != 0)
464 unsigned wordcount = bytecount / 2;
466 while (*
s != 0 && wordcount != 0)
471 while (wordcount != 0)
477 if (bytecount % 2 != 0)
516 unsigned identifier_size;
517 unsigned record_size;
524 identifier_size =
strlen(
d->joliet_name) * 2;
536 identifier_size =
strlen(
d->name_on_cd);
540 identifier_size =
strlen(
d->name_on_cd) + 2;
541 if (
d->extension_on_cd[0] != 0)
542 identifier_size += 1 +
strlen(
d->extension_on_cd);
549 record_size = 33 + identifier_size;
550 if ((identifier_size & 1) == 0)
600 if (
d->extension_on_cd[0] != 0)
609 if ((identifier_size & 1) == 0)
650 #if defined(_WIN32) && !defined(strcasecmp) 651 #define strcasecmp stricmp 661 && !
strcasecmp(
p->extension_on_cd,
d->extension_on_cd) )
663 p =
p->next_in_directory;
671 char *
t =
d->name_on_cd;
674 int filename_counter;
675 filename_counter = 1;
684 if ((
size_t)(
t-
d->name_on_cd) <
sizeof(
d->name_on_cd)-1)
702 t =
d->extension_on_cd;
705 if ((
size_t)(
t-
d->extension_on_cd) <
sizeof(
d->extension_on_cd)-1)
716 if (
d->extension[0] != 0)
727 filename_counter = 1;
734 if ((
d->name_on_cd[8] ==
'.') && (
strlen(
d->name_on_cd) < 13))
738 if (filename_counter>255)
741 d->name_on_cd[8] =
'~';
743 sprintf(&
d->name_on_cd[9],
"%d",filename_counter);
750 if (joliet_length > 64)
752 d->joliet_name =
malloc(joliet_length + 1);
753 if (
d->joliet_name ==
NULL)
777 d->next_in_memory =
root.next_in_memory;
778 root.next_in_memory =
d;
787 d->size =
d->joliet_size =
f->size;
788 d->next_in_directory =
parent->first_record;
806 d->next_in_memory =
root.next_in_memory;
807 root.next_in_memory =
d;
820 d->size =
d->joliet_size = stbuf->
st_size;
821 d->next_in_directory =
parent->first_record;
836 int n =
strcmp(
p->name_on_cd,
q->name_on_cd);
838 n =
strcmp(
p->extension_on_cd,
q->extension_on_cd);
850 int n =
p->level -
q->level;
886 char *old_end_source;
889 d->first_record =
NULL;
940 new_d->next_in_path_table =
root.next_in_path_table;
941 root.next_in_path_table = new_d;
942 new_d->level =
d->level + 1;
970 char *old_end_source;
974 d->first_record =
NULL;
1070 new_d->next_in_path_table =
root.next_in_path_table;
1071 root.next_in_path_table = new_d;
1072 new_d->level =
d->level + 1;
1137 new_d->next_in_path_table =
root.next_in_path_table;
1138 root.next_in_path_table = new_d;
1139 new_d->level =
d->level + 1;
1186 new_d =
calloc(1,
sizeof(*new_d));
1188 new_d->level =
d->level + 1;
1189 new_d->next_in_directory =
d->first_record;
1190 d->first_record = new_d;
1191 new_d->next_in_memory =
root.next_in_memory;
1192 root.next_in_memory = new_d;
1193 new_d->date_and_time =
d->date_and_time;
1197 new_d->next_in_path_table =
root.next_in_path_table;
1198 root.next_in_path_table = new_d;
1214 memset(cd_time_info, 0,
sizeof(*cd_time_info));
1218 cd_time_info->
day = sys_time.
wDay;
1240 d->first_record =
NULL;
1255 error_exit(
"Cannot open timestamp file '%s'\n",
file->source_name);
1258 if (!get_cd_file_time(
open_file, &
d->date_and_time))
1260 error_exit(
"Cannot stat timestamp file '%s'\n",
file->source_name);
1264 if (
stat(
file->target_name, &stbuf) == -1)
1266 error_exit(
"Cannot stat timestamp file '%s'\n",
file->source_name);
1275 printf(
"%d: file %s (from %s)\n",
1293 if (!get_cd_file_time(
open_file, &new_d->date_and_time))
1301 new_d->size = new_d->joliet_size =
file_size.QuadPart;
1302 new_d->orig_name =
file->source_name;
1305 if (
stat(
file->source_name, &stbuf) == -1)
1307 error_exit(
"Cannot find '%s' (target '%s')\n",
1312 new_d->size = new_d->joliet_size = stbuf.
st_size;
1313 new_d->orig_name =
file->source_name;
1322 printf(
"%d: directory %s\n",
d->level,
child->case_name);
1348 if (
d->joliet_name ==
NULL)
1355 if (
d->joliet_name ==
NULL)
1369 root.date_and_time.year,
1370 root.date_and_time.month,
1371 root.date_and_time.day,
1372 root.date_and_time.hour,
1373 root.date_and_time.minute,
1374 root.date_and_time.second);
1414 unsigned int name_length;
1416 DWORD number_of_sectors;
1417 char *old_end_source;
1423 char timestring[17];
1638 entry->sector_count = (
size + 511) / 512;
1667 root.path_table_index = 1;
1668 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1670 name_length =
strlen(
d->name_on_cd);
1676 if (name_length & 1)
1678 d->path_table_index = ++
index;
1696 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1698 name_length =
strlen(
d->name_on_cd);
1704 if (name_length & 1)
1721 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1723 name_length =
strlen(
d->joliet_name) * 2;
1745 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1747 name_length =
strlen(
d->joliet_name) * 2;
1769 d->sector =
cd.sector;
1772 for (
q =
d->first_record;
q !=
NULL;
q =
q->next_in_directory)
1784 d->joliet_sector =
cd.sector;
1787 for (
q =
d->first_record;
q !=
NULL;
q =
q->next_in_directory)
1802 for (
q =
d->first_record;
q !=
NULL;
q =
q->next_in_directory)
1806 q->sector =
q->joliet_sector =
cd.sector;
1811 cd.sector += number_of_sectors;
1819 const char *file_source;
1829 file_source =
q->orig_name;
1832 printf(
"Writing contents of %s\n", file_source);
1835 error_exit(
"Cannot open '%s'\n", file_source);
1839 error_exit(
"Read error in file '%s'\n", file_source);
1856 "CDMAKE CD-ROM Premastering Utility\n" 1857 "Copyright (C) 1997 Philip J. Erdelsky\n" 1858 "Copyright (C) 2003-2016 ReactOS Team\n" 1860 "CDMAKE [-vN] [-p] [-s N] [-m] [-j] [-q] " 1862 "[-pN] [-eN] [-b bootimage]\n" 1863 " [-bootdata:N#<defaultBootEntry>#<bootEntry1>#...#<bootEntryN>]\n" 1864 " source volume image\n" 1866 "Mandatory options:\n" 1867 " source Specifications of base directory containing all files to be\n" 1868 " written to CD-ROM image. Can be a directory, or a path to a\n" 1869 " file list (in which case the path must start with a '@').\n" 1870 " volume Volume label.\n" 1871 " image Image file or device.\n" 1873 "General options:\n" 1874 " -vN Verbosity level. Valid values for 'N' are:\n" 1875 " 0: Quiet mode - display nothing but error messages.\n" 1876 " 1: Normal mode (default).\n" 1877 " 2: Verbose mode - display file information as files are\n" 1878 " scanned and written. Overrides the -p option.\n" 1879 " -p Show progress while writing.\n" 1880 " -s N Abort operation before beginning write if image will be larger\n" 1881 " than N megabytes (i.e. 1024*1024*N bytes).\n" 1882 " -q Only scan the source files; do not create an image.\n" 1885 "ISO 9660 and Joliet options:\n" 1886 " -m Accept punctuation marks other than underscores in names and\n" 1888 " -j Generate Joliet filename records.\n" 1893 "El-Torito boot options:\n" 1894 " -pN Boot platform ID in hex format (default: 00 for a BIOS system).\n" 1895 " -eN Boot media emulation. Valid values for 'N' are:\n" 1896 " 0 (or nothing): No emulation.\n" 1897 " 1: 1.2 MB diskette.\n" 1898 " 2: 1.44MB diskette.\n" 1899 " 3: 2.88MB diskette.\n" 1901 " -b bootimage Create a single-boot El-Torito image.\n" 1902 " -bootdata: Create a multi-boot El-Torito image. This option cannot be\n" 1903 " combined with the -b option.\n" 1905 " -bootdata:N#<defaultBootEntry>#<bootEntry2>#...#<bootEntryN>\n" 1906 " 'N': number of boot entries following.\n" 1907 " defaultBootEntry: The default boot entry, needed in all cases.\n" 1908 " Used by BIOSes which do not support additional boot entries.\n" 1909 " bootEntryX: Additional boot entries.\n" 1910 " - Do not use spaces.\n" 1911 " - Each multi-boot entry must be delimited with a hash symbol (#).\n" 1912 " - Each option for a boot entry must be delimited with a comma (,).\n" 1913 " - Each boot entry must specify the platform ID.\n";
1919 #if (defined(__GNUC__) || (_MSC_VER < 1900)) 1939 while (**ctx && !
strchr(delim, **ctx))
1950 BYTE boot_emu_type,
WORD load_segment,
1977 cd.filespecs[0] = 0;
2052 if (size_limit < 1 || size_limit > 800)
2065 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2081 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2094 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2102 else if (
strncmp(
argv[
i],
"-bootdata:",
sizeof(
"-bootdata:") - 1) == 0)
2104 char *bootdata, *entry_ctx, *option_ctx;
2105 DWORD num_boot_entries = 0;
2110 BYTE platform_id, old_platform_id = 0;
2113 char bootimage[512];
2118 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2120 t =
argv[
i] + (
sizeof(
"-bootdata:") - 1);
2122 if (bootdata ==
NULL)
2131 t =
strtok_s(bootdata,
"#", &entry_ctx);
2140 while (num_boot_entries--)
2146 bootimage[0] =
'\0';
2220 default_entry =
FALSE;
2247 old_boot_entry =
NULL;
2248 old_platform_id = platform_id;
2255 if (old_platform_id != platform_id)
2269 old_boot_entry =
NULL;
2270 old_platform_id = platform_id;
2280 if (old_boot_entry ==
NULL)
2293 else if (
i + 2 <
argc)
2307 if (
cd.filespecs[0] == 0)
2308 error_exit(
"Missing image file specifications");
2325 char *trimmedline, *targetname, *normdir, *srcname, *
eq;
2326 char lineread[1024];
2333 while (
fgets(lineread,
sizeof(lineread),
f))
2336 trimmedline =
strtok(lineread,
"\t\r\n;");
2341 targetname = trimmedline;
2342 normdir =
strdup(targetname);
2349 targetname =
strtok(lineread,
"=");
2359 error_exit(
"Target '%s' (file '%s') is invalid\n", targetname, srcname);
2362 error_exit(
"Cannot access file '%s' (target '%s')\n", srcname, targetname);
2394 printf(
"%s unused bytes at ends of files\n",
2397 printf(
"in %s directories\n",
2400 puts(
"-------------");
2401 printf(
"%s total bytes\n",
2403 puts(
"=============");
2415 error_exit(
"Cannot open image file '%s'",
cd.filespecs);
2432 error_exit(
"File write error in image file '%s'",
cd.filespecs);
2436 puts(
"CD-ROM image made successfully");
DWORD little_endian_path_table_sector
static void convert_date_and_time(PDATE_AND_TIME dt, time_t *time)
struct _boot_validation_header BOOT_VALIDATION_HEADER
DWORD number_of_directories
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
DATE_AND_TIME date_and_time
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
struct boot_header BOOT_HEADER
struct directory_record * first_record
static void write_byte(BYTE x)
char * strcat(char *DstString, const char *SrcString)
static void write_string(char *s)
static void write_both_endian_dword(DWORD x)
ACPI_SIZE strlen(const char *String)
char * strpbrk(const char *String, const char *Delimiters)
struct _boot_validation_header * PBOOT_VALIDATION_HEADER
enum directory_record_type DIR_RECORD_TYPE
GLenum GLuint GLenum GLsizei const GLchar * buf
enum directory_record_type * PDIR_RECORD_TYPE
static void get_file_specifications(PDIR_RECORD d)
static struct cd_image cd
GLuint GLuint GLsizei count
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
#define MAX_CDEXTENSION_LENGTH
char extension_on_cd[MAX_CDEXTENSION_LENGTH+1]
DWORD unused_bytes_at_ends_of_files
#define INVALID_HANDLE_VALUE
struct boot_entry * next_entry
static void error_exit(const char *fmt,...)
static BOOL cdname_exists(PDIR_RECORD d)
GLint GLint GLint GLint GLint x
char name_on_cd[MAX_CDNAME_LENGTH+1]
void dir_hash_destroy(struct target_dir_hash *dh)
static char DIRECTORY_TIMESTAMP[]
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
const char * strerror(int err)
#define eq(received, expected, label, type)
char * strtok_s(char *str, const char *delim, char **ctx)
struct boot_header * PBOOT_HEADER
PDIR_RECORD sort_linked_list(PDIR_RECORD, unsigned, int(*)(PDIR_RECORD, PDIR_RECORD))
static void write_word_block(unsigned count, WORD value)
struct date_and_time DATE_AND_TIME
#define sprintf(buf, format,...)
DIR *__cdecl opendir(const char *)
struct date_and_time * PDATE_AND_TIME
static void flush_buffer(void)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define DIR_SEPARATOR_CHAR
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
static void write_little_endian_word(WORD x)
static void write_little_endian_dword(DWORD x)
static PDIR_RECORD new_empty_dirrecord(PDIR_RECORD d, BOOL directory)
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
struct boot_entry * PBOOT_ENTRY
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
static void parse_filename_into_dirrecord(const char *filename, PDIR_RECORD d, BOOL dir)
struct directory_record * next_in_path_table
static void release_memory(void)
struct boot_entry BOOT_ENTRY
static int check_for_punctuation(int c, const char *name)
static void write_big_endian_dword(DWORD x)
_Check_return_opt_ _CRTIMP int __cdecl _findclose(_In_ intptr_t _FindHandle)
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
_Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char *_Filename, _In_ int _AccessMode)
_CRTIMP int __cdecl _findnext(intptr_t _FindHandle, struct _finddata_t *_FindData)
struct directory_record DIR_RECORD
DWORD big_endian_path_table_sector
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
BOOL accept_punctuation_marks
static int compare_directory_order(PDIR_RECORD p, PDIR_RECORD q)
PDIR_RECORD new_directory_record(struct dirent *entry, struct stat *stbuf, PDIR_RECORD parent)
DWORD joliet_big_endian_path_table_sector
GLdouble GLdouble GLdouble GLdouble q
struct directory_record * next_in_memory
static void init_boot_entry(PBOOT_ENTRY boot_entry, BYTE boot_emu_type, WORD load_segment, char *bootimage)
static void write_big_endian_word(WORD x)
struct target_dir_hash specified_files
#define FILE_ATTRIBUTE_NORMAL
DWORD joliet_path_table_size
static void write_block(unsigned count, BYTE value)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
int __cdecl closedir(DIR *)
int puts(const char *string)
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
struct target_dir_entry * dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char *targetnorm)
static void append_string_to_source(char *s)
struct dirent *__cdecl readdir(DIR *)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
static unsigned __int64 next
struct directory_record * next_in_directory
struct directory_record * PDIR_RECORD
static void write_bytecounted_string_as_big_endian_unicode(unsigned bytecount, char *s, char padding)
static void write_both_endian_word(WORD x)
static BOOL write_from_file(FILE *file, DWORD size)
GLuint GLint GLboolean GLint GLenum access
#define MAX_CDNAME_LENGTH
_CRTIMP intptr_t __cdecl _findfirst(const char *_Filename, struct _finddata_t *_FindData)
static void write_directory_record(PDIR_RECORD d, DIR_RECORD_TYPE DirType, BOOL joliet)
static void fill_sector(void)
struct target_file * dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target)
void normalize_dirname(char *filename)
PBOOT_HEADER boot_header_list
static char * edit_with_commas(DWORD x, BOOL pad)
char * strtok(char *String, const char *Delimiters)
char * strchr(const char *String, int ch)
struct directory_record * parent
int main(int argc, char **argv)
char * strcpy(char *DstString, const char *SrcString)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
int strcmp(const char *String1, const char *String2)
static void scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir)
#define DIR_SEPARATOR_STRING
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
BOOT_ENTRY default_boot_entry
#define CreateFileA(a, b, c, d, e, f, g)
DWORD boot_catalog_sector
static void get_time_string(char *str)
DWORD joliet_little_endian_path_table_sector
static void make_directory_records(PDIR_RECORD d)
BOOT_VALIDATION_HEADER boot_validation_header
static int compare_path_table_order(PDIR_RECORD p, PDIR_RECORD q)
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
char extension[MAX_EXTENSION_LENGTH+1]
static void write_bytecounted_string(unsigned bytecount, char *s, char padding)
HANDLE open_file(char *filename, BOOL bWrite)
#define MAX_EXTENSION_LENGTH
static void write_string_as_big_endian_unicode(char *s)
DWORD bytes_in_directories