133{
135 int argc = oargc - 1;
136 char**
argv = oargv + 1;
137
138
140 {
141 fprintf(
stderr,
"Error: First parameter must be a filename.\n");
143 }
144
146 {
147 fprintf(
stderr,
"Error: First parameter must be a filename, found '%s' instead.\n",
argv[0]);
149 }
150
152 {
156 }
157
160
162 {
164 int nargs = 0;
166
168 {
169 fprintf(
stderr,
"Error: Expected a command, found '%s' instead.\n", parg);
171 }
172
173 parg++;
176
177
179 nargs++;
180
181 if (
strcmp(parg,
"format") == 0)
182 {
183
185
187
188
190
192 {
196 }
197
199 {
203 }
204
206
209 {
212 }
213
214
215 if (nargs > 1)
216 {
217#define FAT_VOL_LABEL_LEN 11
219 char*
label = vol_label + 2;
220 char ch;
221
224
226 {
227
228
230 {
232 if ((ch < 0x20) || !
isprint(ch))
233 {
235 break;
236 }
237
239 }
240
242 {
243
245 {
247 }
248 }
249 }
250 else
251 {
253 }
254
256 {
257 fprintf(
stderr,
"Error: Header label is limited to 11 printable uppercase ASCII symbols.");
260 }
261
263 {
264 fprintf(
stderr,
"Error: Unable to read existing boot sector from image.");
267 }
268
270 {
272 }
273 else
274 {
276 }
277
279 {
280 fprintf(
stderr,
"Error: Unable to write new boot sector to image.");
283 }
284
285
286 memcpy(vol_label,
"0:", 2);
289 {
293 }
294 }
295 }
296 else if (
strcmp(parg,
"boot") == 0)
297 {
300
302
303
304
306 if (!fe)
307 {
308 fprintf(
stderr,
"Error: Unable to open external file '%s' for reading.",
argv[0]);
311 }
312
314 {
319 }
320
322
324
326 {
327 fprintf(
stderr,
"Error: Unable to read existing boot sector from image.");
330 }
331
333 {
334 printf(
"TODO: Writing boot sectors for FAT32 images not yet supported.");
337 }
338 else
339 {
340#define FAT16_HEADER_START 3
341#define FAT16_HEADER_END 62
342
344 }
345
347 {
348 fprintf(
stderr,
"Error: Unable to write new boot sector to image.");
351 }
352 }
353 else if (
strcmp(parg,
"add") == 0)
354 {
359
361
363
364
365
366
368 if (!fe)
369 {
370 fprintf(
stderr,
"Error: Unable to open external file '%s' for reading.",
argv[0]);
373 }
374
376 {
381 }
382
384 {
385 if (
f_write(&fv,
buff, rdlen, &wrlen) || wrlen < rdlen)
386 {
387 fprintf(
stderr,
"Error: Unable to write '%d' bytes to disk.", wrlen);
390 }
391 }
392
395 }
396 else if (
strcmp(parg,
"extract") == 0)
397 {
402
404
406
407
408
409
411 {
415 }
416
418 if (!fv)
419 {
420 fprintf(
stderr,
"Error: Unable to open external file '%s' for writing.",
argv[1]);
424 }
425
426 while ((
f_read(&fe,
buff,
sizeof(
buff), &rdlen) == 0) && (rdlen > 0))
427 {
429 {
430 fprintf(
stderr,
"Error: Unable to write '%d' bytes to file.", rdlen);
433 }
434 }
435
438 }
439 else if (
strcmp(parg,
"move") == 0)
440 {
442
444
445
446
448 {
452 }
453 }
454 else if (
strcmp(parg,
"copy") == 0)
455 {
460
462
464
465
466
468 {
472 }
474 {
479 }
480
481 while ((
f_read(&fe,
buff,
sizeof(
buff), &rdlen) == 0) && (rdlen > 0))
482 {
483 if (
f_write(&fv,
buff, rdlen, &wrlen) || wrlen < rdlen)
484 {
485 fprintf(
stderr,
"Error: Unable to write '%d' bytes to disk.", wrlen);
488 }
489 }
490
493 }
494 else if (
strcmp(parg,
"mkdir") == 0)
495 {
497
499
500
502 {
506 }
507 }
508 else if (
strcmp(parg,
"delete") == 0)
509 {
511
513
514
516 {
517 fprintf(
stderr,
"Error: Unable to delete file or directory.");
520 }
521 }
522 else if (
strcmp(parg,
"list") == 0)
523 {
527 char lfname[257];
528
530
531
532
533 if (nargs == 1)
534 {
536 }
537
539 {
543 }
544
545 printf(
"Listing directory contents of: %s\n",
root);
546
547 info.lfname = lfname;
548 info.lfsize =
sizeof(lfname)-1;
550 {
553 else
555 }
556 }
557 else
558 {
561 }
564 }
565
567
569
571
573}
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)
#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
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)
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 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[]