17static unsigned char buff[32768];
60 printf(
"Syntax: %s image_file [list of commands]\n\n",
name);
62 printf(
"Commands: [Note: both '/' and '-' are accepted as command prefixes.]\n");
67 printf(
" -format <sectors> [<custom header label>]\n"
68 " Formats the disk image.\n");
69 printf(
" -boot <sector file>\n"
70 " Writes a new boot sector.\n");
71 printf(
" -add <src path> <dst path>\n"
72 " Copies an external file or directory into the image.\n");
73 printf(
" -extract <src path> <dst path>\n"
74 " Copies a file or directory from the image into an external file\n"
76 printf(
" -move <src path> <new path>\n"
77 " Moves/renames a file or directory.\n");
78 printf(
" -copy <src path> <new path>\n"
79 " Copies a file or directory.\n");
80 printf(
" -mkdir <src path> <new path>\n"
81 " Creates a directory.\n");
82 printf(
" -rmdir <src path> <new path>\n"
83 " Creates a directory.\n");
84 printf(
" -list [<pattern>]\n"
85 " Lists files a directory (defaults to root).\n");
88#define PRINT_HELP_AND_QUIT() \
91 print_help(oargv[0]); \
98 return (parg[0] ==
'/') || (parg[0] ==
'-');
100 return (parg[0] ==
'-');
104#define NEED_PARAMS(_min_, _max_) \
106 if (nargs < _min_) { fprintf(stderr, "Error: Too few args for command %s.\n" , argv[-1]); PRINT_HELP_AND_QUIT(); } \
107 if (nargs > _max_) { fprintf(stderr, "Error: Too many args for command %s.\n", argv[-1]); PRINT_HELP_AND_QUIT(); } \
125#define NEED_MOUNT() \
126 do { ret = need_mount(); if(ret) \
128 fprintf(stderr, "Error: Could not mount disk (%d).\n", ret); \
132int main(
int oargc,
char* oargv[])
135 int argc = oargc - 1;
136 char**
argv = oargv + 1;
141 fprintf(
stderr,
"Error: First parameter must be a filename.\n");
147 fprintf(
stderr,
"Error: First parameter must be a filename, found '%s' instead.\n",
argv[0]);
169 fprintf(
stderr,
"Error: Expected a command, found '%s' instead.\n", parg);
181 if (
strcmp(parg,
"format") == 0)
217#define FAT_VOL_LABEL_LEN 11
219 char*
label = vol_label + 2;
232 if ((ch < 0x20) || !
isprint(ch))
257 fprintf(
stderr,
"Error: Header label is limited to 11 printable uppercase ASCII symbols.");
264 fprintf(
stderr,
"Error: Unable to read existing boot sector from image.");
280 fprintf(
stderr,
"Error: Unable to write new boot sector to image.");
286 memcpy(vol_label,
"0:", 2);
296 else if (
strcmp(parg,
"boot") == 0)
308 fprintf(
stderr,
"Error: Unable to open external file '%s' for reading.",
argv[0]);
327 fprintf(
stderr,
"Error: Unable to read existing boot sector from image.");
334 printf(
"TODO: Writing boot sectors for FAT32 images not yet supported.");
340#define FAT16_HEADER_START 3
341#define FAT16_HEADER_END 62
348 fprintf(
stderr,
"Error: Unable to write new boot sector to image.");
353 else if (
strcmp(parg,
"add") == 0)
370 fprintf(
stderr,
"Error: Unable to open external file '%s' for reading.",
argv[0]);
385 if (
f_write(&fv,
buff, rdlen, &wrlen) || wrlen < rdlen)
387 fprintf(
stderr,
"Error: Unable to write '%d' bytes to disk.", wrlen);
396 else if (
strcmp(parg,
"extract") == 0)
420 fprintf(
stderr,
"Error: Unable to open external file '%s' for writing.",
argv[1]);
426 while ((
f_read(&fe,
buff,
sizeof(
buff), &rdlen) == 0) && (rdlen > 0))
430 fprintf(
stderr,
"Error: Unable to write '%d' bytes to file.", rdlen);
439 else if (
strcmp(parg,
"move") == 0)
454 else if (
strcmp(parg,
"copy") == 0)
481 while ((
f_read(&fe,
buff,
sizeof(
buff), &rdlen) == 0) && (rdlen > 0))
483 if (
f_write(&fv,
buff, rdlen, &wrlen) || wrlen < rdlen)
485 fprintf(
stderr,
"Error: Unable to write '%d' bytes to disk.", wrlen);
494 else if (
strcmp(parg,
"mkdir") == 0)
508 else if (
strcmp(parg,
"delete") == 0)
517 fprintf(
stderr,
"Error: Unable to delete file or directory.");
522 else if (
strcmp(parg,
"list") == 0)
545 printf(
"Listing directory contents of: %s\n",
root);
547 info.lfname = lfname;
548 info.lfsize =
sizeof(lfname)-1;
int strcmp(const char *String1, const char *String2)
ACPI_SIZE strlen(const char *String)
static BOOLEAN disk_read(ULONG DeviceId, u64 physical, void *dest, u32 count)
VOID disk_cleanup(BYTE pdrv)
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
DSTATUS disk_openimage(BYTE pdrv, const char *imageFileName)
_In_ PLARGE_INTEGER _In_ BOOLEAN _Out_ PFAT_TIME_STAMP FatTime
#define FAT16_HEADER_START
int is_command(const char *parg)
static FATFS g_Filesystem
#define NEED_PARAMS(_min_, _max_)
static unsigned char buff[32768]
#define FAT_VOL_LABEL_LEN
#define PRINT_HELP_AND_QUIT()
FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt)
FRESULT f_unlink(const TCHAR *path)
FRESULT f_mkdir(const TCHAR *path)
FRESULT f_mkfs(const TCHAR *path, BYTE sfd, UINT au)
FRESULT f_rename(const TCHAR *path_old, const TCHAR *path_new)
FRESULT f_setlabel(const TCHAR *label)
FRESULT f_readdir(DIR *dp, FILINFO *fno)
FRESULT f_opendir(DIR *dp, const TCHAR *path)
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br)
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw)
FRESULT f_open(FIL *fp, const TCHAR *path, BYTE mode)
GLdouble GLdouble GLdouble r
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
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_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)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_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)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define memcpy(s1, s2, n)
static NTSTATUS disk_write(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
static const WCHAR label[]
static const WCHAR invalid[]
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)