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);
358 cd.buffer[
cd.count] =
x;
422 while (
cd.offset != 0)
439 while (*
s != 0 && bytecount != 0)
444 while (bytecount != 0)
466 unsigned wordcount = bytecount / 2;
468 while (*
s != 0 && wordcount != 0)
473 while (wordcount != 0)
479 if (bytecount % 2 != 0)
518 unsigned identifier_size;
519 unsigned record_size;
526 identifier_size =
strlen(
d->joliet_name) * 2;
538 identifier_size =
strlen(
d->name_on_cd);
542 identifier_size =
strlen(
d->name_on_cd) + 2;
543 if (
d->extension_on_cd[0] != 0)
544 identifier_size += 1 +
strlen(
d->extension_on_cd);
551 record_size = 33 + identifier_size;
552 if ((identifier_size & 1) == 0)
602 if (
d->extension_on_cd[0] != 0)
611 if ((identifier_size & 1) == 0)
652 #if defined(_WIN32) && !defined(strcasecmp) 653 #define strcasecmp stricmp 663 && !
strcasecmp(
p->extension_on_cd,
d->extension_on_cd) )
665 p =
p->next_in_directory;
673 char *
t =
d->name_on_cd;
676 int filename_counter;
677 filename_counter = 1;
686 if ((
size_t)(
t-
d->name_on_cd) <
sizeof(
d->name_on_cd)-1)
704 t =
d->extension_on_cd;
707 if ((
size_t)(
t-
d->extension_on_cd) <
sizeof(
d->extension_on_cd)-1)
718 if (
d->extension[0] != 0)
729 filename_counter = 1;
736 if ((
d->name_on_cd[8] ==
'.') && (
strlen(
d->name_on_cd) < 13))
740 if (filename_counter>255)
743 d->name_on_cd[8] =
'~';
745 sprintf(&
d->name_on_cd[9],
"%d",filename_counter);
752 if (joliet_length > 64)
754 d->joliet_name =
malloc(joliet_length + 1);
755 if (
d->joliet_name ==
NULL)
779 d->next_in_memory =
root.next_in_memory;
780 root.next_in_memory =
d;
789 d->size =
d->joliet_size =
f->size;
790 d->next_in_directory =
parent->first_record;
808 d->next_in_memory =
root.next_in_memory;
809 root.next_in_memory =
d;
822 d->size =
d->joliet_size = stbuf->
st_size;
823 d->next_in_directory =
parent->first_record;
838 int n =
strcmp(
p->name_on_cd,
q->name_on_cd);
840 n =
strcmp(
p->extension_on_cd,
q->extension_on_cd);
852 int n =
p->level -
q->level;
888 char *old_end_source;
891 d->first_record =
NULL;
942 new_d->next_in_path_table =
root.next_in_path_table;
943 root.next_in_path_table = new_d;
944 new_d->level =
d->level + 1;
972 char *old_end_source;
976 d->first_record =
NULL;
1072 new_d->next_in_path_table =
root.next_in_path_table;
1073 root.next_in_path_table = new_d;
1074 new_d->level =
d->level + 1;
1139 new_d->next_in_path_table =
root.next_in_path_table;
1140 root.next_in_path_table = new_d;
1141 new_d->level =
d->level + 1;
1188 new_d =
calloc(1,
sizeof(*new_d));
1190 new_d->level =
d->level + 1;
1191 new_d->next_in_directory =
d->first_record;
1192 d->first_record = new_d;
1193 new_d->next_in_memory =
root.next_in_memory;
1194 root.next_in_memory = new_d;
1195 new_d->date_and_time =
d->date_and_time;
1199 new_d->next_in_path_table =
root.next_in_path_table;
1200 root.next_in_path_table = new_d;
1216 memset(cd_time_info, 0,
sizeof(*cd_time_info));
1220 cd_time_info->
day = sys_time.
wDay;
1242 d->first_record =
NULL;
1257 error_exit(
"Cannot open timestamp file '%s'\n",
file->source_name);
1260 if (!get_cd_file_time(
open_file, &
d->date_and_time))
1262 error_exit(
"Cannot stat timestamp file '%s'\n",
file->source_name);
1266 if (
stat(
file->target_name, &stbuf) == -1)
1268 error_exit(
"Cannot stat timestamp file '%s'\n",
file->source_name);
1277 printf(
"%d: file %s (from %s)\n",
1295 if (!get_cd_file_time(
open_file, &new_d->date_and_time))
1303 new_d->size = new_d->joliet_size =
file_size.QuadPart;
1304 new_d->orig_name =
file->source_name;
1307 if (
stat(
file->source_name, &stbuf) == -1)
1309 error_exit(
"Cannot find '%s' (target '%s')\n",
1314 new_d->size = new_d->joliet_size = stbuf.
st_size;
1315 new_d->orig_name =
file->source_name;
1324 printf(
"%d: directory %s\n",
d->level,
child->case_name);
1350 if (
d->joliet_name ==
NULL)
1357 if (
d->joliet_name ==
NULL)
1371 root.date_and_time.year,
1372 root.date_and_time.month,
1373 root.date_and_time.day,
1374 root.date_and_time.hour,
1375 root.date_and_time.minute,
1376 root.date_and_time.second);
1416 unsigned int name_length;
1418 DWORD number_of_sectors;
1419 char *old_end_source;
1425 char timestring[17];
1640 entry->sector_count = (
size + 511) / 512;
1669 root.path_table_index = 1;
1670 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1672 name_length =
strlen(
d->name_on_cd);
1678 if (name_length & 1)
1680 d->path_table_index = ++
index;
1698 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1700 name_length =
strlen(
d->name_on_cd);
1706 if (name_length & 1)
1723 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1725 name_length =
strlen(
d->joliet_name) * 2;
1747 for (
d =
root.next_in_path_table;
d !=
NULL;
d =
d->next_in_path_table)
1749 name_length =
strlen(
d->joliet_name) * 2;
1771 d->sector =
cd.sector;
1774 for (
q =
d->first_record;
q !=
NULL;
q =
q->next_in_directory)
1786 d->joliet_sector =
cd.sector;
1789 for (
q =
d->first_record;
q !=
NULL;
q =
q->next_in_directory)
1804 for (
q =
d->first_record;
q !=
NULL;
q =
q->next_in_directory)
1808 q->sector =
q->joliet_sector =
cd.sector;
1813 cd.sector += number_of_sectors;
1821 const char *file_source;
1831 file_source =
q->orig_name;
1834 printf(
"Writing contents of %s\n", file_source);
1837 error_exit(
"Cannot open '%s'\n", file_source);
1841 error_exit(
"Read error in file '%s'\n", file_source);
1858 "CDMAKE CD-ROM Premastering Utility\n" 1859 "Copyright (C) 1997 Philip J. Erdelsky\n" 1860 "Copyright (C) 2003-2016 ReactOS Team\n" 1862 "CDMAKE [-vN] [-p] [-s N] [-m] [-j] [-q] " 1864 "[-pN] [-eN] [-b bootimage]\n" 1865 " [-bootdata:N#<defaultBootEntry>#<bootEntry1>#...#<bootEntryN>]\n" 1866 " source volume image\n" 1868 "Mandatory options:\n" 1869 " source Specifications of base directory containing all files to be\n" 1870 " written to CD-ROM image. Can be a directory, or a path to a\n" 1871 " file list (in which case the path must start with a '@').\n" 1872 " volume Volume label.\n" 1873 " image Image file or device.\n" 1875 "General options:\n" 1876 " -vN Verbosity level. Valid values for 'N' are:\n" 1877 " 0: Quiet mode - display nothing but error messages.\n" 1878 " 1: Normal mode (default).\n" 1879 " 2: Verbose mode - display file information as files are\n" 1880 " scanned and written. Overrides the -p option.\n" 1881 " -p Show progress while writing.\n" 1882 " -s N Abort operation before beginning write if image will be larger\n" 1883 " than N megabytes (i.e. 1024*1024*N bytes).\n" 1884 " -q Only scan the source files; do not create an image.\n" 1887 "ISO 9660 and Joliet options:\n" 1888 " -m Accept punctuation marks other than underscores in names and\n" 1890 " -j Generate Joliet filename records.\n" 1895 "El-Torito boot options:\n" 1896 " -pN Boot platform ID in hex format (default: 00 for a BIOS system).\n" 1897 " -eN Boot media emulation. Valid values for 'N' are:\n" 1898 " 0 (or nothing): No emulation.\n" 1899 " 1: 1.2 MB diskette.\n" 1900 " 2: 1.44MB diskette.\n" 1901 " 3: 2.88MB diskette.\n" 1903 " -b bootimage Create a single-boot El-Torito image.\n" 1904 " -bootdata: Create a multi-boot El-Torito image. This option cannot be\n" 1905 " combined with the -b option.\n" 1907 " -bootdata:N#<defaultBootEntry>#<bootEntry2>#...#<bootEntryN>\n" 1908 " 'N': number of boot entries following.\n" 1909 " defaultBootEntry: The default boot entry, needed in all cases.\n" 1910 " Used by BIOSes which do not support additional boot entries.\n" 1911 " bootEntryX: Additional boot entries.\n" 1912 " - Do not use spaces.\n" 1913 " - Each multi-boot entry must be delimited with a hash symbol (#).\n" 1914 " - Each option for a boot entry must be delimited with a comma (,).\n" 1915 " - Each boot entry must specify the platform ID.\n";
1921 #if (defined(__GNUC__) || (_MSC_VER < 1900)) 1952 BYTE boot_emu_type,
WORD load_segment,
1979 cd.filespecs[0] = 0;
2054 if (size_limit < 1 || size_limit > 800)
2067 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2083 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2096 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2104 else if (
strncmp(
argv[
i],
"-bootdata:",
sizeof(
"-bootdata:") - 1) == 0)
2106 char *bootdata, *entry_ctx, *option_ctx;
2107 DWORD num_boot_entries = 0;
2112 BYTE platform_id, old_platform_id = 0;
2115 char bootimage[512];
2120 error_exit(
"Single-boot and multi-boot entries cannot be combined");
2122 t =
argv[
i] + (
sizeof(
"-bootdata:") - 1);
2124 if (bootdata ==
NULL)
2133 t =
strtok_s(bootdata,
"#", &entry_ctx);
2142 while (num_boot_entries--)
2148 bootimage[0] =
'\0';
2222 default_entry =
FALSE;
2249 old_boot_entry =
NULL;
2250 old_platform_id = platform_id;
2257 if (old_platform_id != platform_id)
2271 old_boot_entry =
NULL;
2272 old_platform_id = platform_id;
2282 if (old_boot_entry ==
NULL)
2295 else if (
i + 2 <
argc)
2309 if (
cd.filespecs[0] == 0)
2310 error_exit(
"Missing image file specifications");
2327 char *trimmedline, *targetname, *normdir, *srcname, *
eq;
2328 char lineread[1024];
2335 while (
fgets(lineread,
sizeof(lineread),
f))
2338 trimmedline =
strtok(lineread,
"\t\r\n;");
2343 targetname = trimmedline;
2344 normdir =
strdup(targetname);
2351 targetname =
strtok(lineread,
"=");
2361 error_exit(
"Target '%s' (file '%s') is invalid\n", targetname, srcname);
2364 error_exit(
"Cannot access file '%s' (target '%s')\n", srcname, targetname);
2396 printf(
"%s unused bytes at ends of files\n",
2399 printf(
"in %s directories\n",
2402 puts(
"-------------");
2403 printf(
"%s total bytes\n",
2405 puts(
"=============");
2417 error_exit(
"Cannot open image file '%s'",
cd.filespecs);
2434 error_exit(
"File write error in image file '%s'",
cd.filespecs);
2438 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 **
static unsigned int file_size
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
enum directory_record_type * PDIR_RECORD_TYPE
static void get_file_specifications(PDIR_RECORD d)
static struct cd_image cd
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
GLuint GLuint GLsizei 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 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)
#define DECLSPEC_NORETURN
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 *)
GLenum GLuint GLenum GLsizei const GLchar * buf
struct date_and_time * PDATE_AND_TIME
static void flush_buffer(void)
#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)
static DECLSPEC_NORETURN void error_exit(const char *fmt,...)
_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
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
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