leowrite.c 17.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
/**************************************************************************
 *                                                                        *
 *               Copyright (C) 1995, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 *************************************************************************/

#include <sys/u64gio.h>
#include <sys/types.h>
#include <time.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ultrahost.h>
#include <unistd.h>
#include "hostio.h"

extern	char	*rindex(const char *, int);

/*
 * Prototypes
 */
static 	void	usage(void);
static 	int	endProc(int);
static	int	getHostName(u8 *);
static	void	getCurTime(LEODiskTime *);
static	void 	printID(LEODiskID *id);
static	int 	mainProc(void);

char	*command_name;
ctrlblk	data;
char	*filename;
char	sendMeInfo = 0;
unsigned int	write_ipl3 = TRUE;	/* write ipl3 and other stuffs to the disk */
/* by default */
unsigned int	write_all = TRUE; 	/* write all of the file */
int		startbyte = 0, endbyte = 0;
static	int	argFileIsSpecified = FALSE;
char	argFileName[256];
char	idFileName[256];
char	idFileBuf[32];

void usage(void)
{
  fprintf(stderr, "\nleowrite ver.%s\n\n", VERSION);
  fprintf(stderr, "Usage: %s [-sfvih] [-L LBA] [-t Type] [-w [start]-[end]]"
	  " [-a address] [-I idfile] [-A argfile] file\n",
	  command_name);
  fprintf(stderr, "    -L: Specify a start LBA to start to write with[0-4291]. default is 0 \n");
  fprintf(stderr, "    -t: Specify a type of the disk [0-6]. default is \"don't change\"\n");
  fprintf(stderr, "    -s: Do not write the first 4K byte, which might include ipl3 etc.\n");
  fprintf(stderr, "    -w: Specify a range of the file.\n");
  fprintf(stderr, "    -a: Specify the address where IPL4 put the first file into.\n");
  fprintf(stderr, "    -f: Force to format the disk.\n");
  fprintf(stderr, "    -i: Get information on the disk.\n");
  fprintf(stderr, "    -v: Print version number.\n");
  fprintf(stderr, "    -I: Use idfile as ID.\n");
  fprintf(stderr, "    -A: Specify an argument file.\n");
  fprintf(stderr, "    -h: show this help.\n");
  fprintf(stderr, "\n");
  fprintf(stderr, "    If both -s and -w options are specified, the second one is ignored.\n\n");
  exit(1);
  
}

int fileToArgs(FILE *fp, int *argc, char **argv)
{
  int		c;
  char		tmpBuf[50], *tmpBufp;
  char 		*argPtr;

  /*
   * The first argument is the command itself
   */
  *argc = 1;
  *argv++ = command_name;
  
  c=getc(fp);

  while( (c != EOF) && (c != '\n') )
  {
    if(c != ' ')
    {
      tmpBufp = tmpBuf;
      (*argc)++;

      do
      {
	*tmpBufp++ = c;
	c = getc(fp);

      } while ((c != EOF) && (c != ' ') && (c != '\n'));

      if (NULL == 
	  (argPtr = (char *)malloc( (tmpBufp - tmpBuf) + 1 )) )
      {
	fprintf(stderr, "host: malloc: %s\n", sys_errlist[errno]);
	return(1);
      }
      bcopy((void *)tmpBuf, (void *)argPtr, tmpBufp - tmpBuf);
      argPtr[tmpBufp - tmpBuf] = 0;

      *argv++ = argPtr;
    }
    else
    {
      /*
       * Skip spaces
       */
      for( c=getc(fp); c == ' '; )
	c = getc(fp);
    }
  } /* while( (c != EOF) && (c != '\n') ) */

  *argv = 0;

  if (c == EOF)
    return EOF;
  else
    return 0;
  
} /* fileToArgs() */

void datainit(void)
{
  data.cmdFlags = 0;
  data.offset = 0;
  data.type = TYPE_DONT_CHANGE;		/* default */
  data.address = 0;
  
  argFileIsSpecified = FALSE;  
  sendMeInfo = 0;
  write_ipl3 = TRUE;
  write_all =TRUE;
  endbyte = 0;
}

void parseArgs(int argc, char **argv)
{
  char		*p;
  
  while(--argc > 0)
  {
    if (**(++argv) == '-')
    {
      p = *argv;
      while (*++p)
      {
	switch (*p)
	{
	case 'A':
	  argFileIsSpecified = TRUE;

	  strcpy(argFileName, *++argv);
	  argc--;
	  
	  return;

	case 'h':
	  usage();
	  break;

	case 'f':
	  data.cmdFlags |= DO_FORMAT;
	  break;

	case 'i':
	  data.cmdFlags |= SEND_ME_INFO;
	  sendMeInfo = 1;
	  return;

	case 'v':
	  fprintf(stderr, "\nleowrite ver.%s\n\n", VERSION);
	  exit (0);
	  return;
	  
	case 'L':
	  data.offset = strtol(*++argv, (char **)NULL, 0);
	  argc--;
	  break;

	case 't':
	{
	  s32	type;
	  
	  type = strtol(*++argv, (char **)NULL, 0);
	  argc--;

	  if ((type < 0) || (type > 6))
	  {
	    fprintf(stderr, "specified type is illegal\n");
	    exit(1);
	  }

	  data.type = type;
	}
	  break;
	  
	case 'I':
	  data.cmdFlags |= SPECD_ID_FILE;

	  strcpy(idFileName, *++argv);
	  argc--;
	  
	  break;

	case 'w':
	  if (write_ipl3 == TRUE) 	/* if -s option is already specified, ignore */
	  {
	    startbyte = strtol(*++argv, (char **)NULL, 0);
	    if(rindex(*argv, '-') != NULL)
	      endbyte = strtol(rindex(*argv, '-')+1, (char **)NULL, 0);
	    write_all = FALSE;
	  }
	  else
	    argv++;
	  argc--;
	  break;
	  
	case 's':
	  if (write_all == TRUE) 	/* if -w option is already specified, ignore */
	    write_ipl3 = FALSE;
	  break;
	  
	case 'a':
	  data.address = (void *)strtoul(*++argv, (char **)NULL, 0);
	  argc--;
	  break;
	  
	default:
	  usage();

	} /* switch */

      } /* while */

    }
    else
      break;
      
  } /* while */
    
  if (argc == 1)
    filename = *argv;
  else
    usage();

  return;

}

pid_t		pid;
int		fd, status;
int		fildes;

int
main(int argc, char **argv)
{
  char		r4300prog[100];		       /* Too much! */
  FILE		*argFp;
  char 		*argV[50], **argVp;
  int		argC;
  int		dummy;
  
  datainit();
  
  if ((command_name = rindex(argv[0], '/')) != NULL)
    command_name++;
  else
    command_name = argv[0];
    
  parseArgs(argc, argv);

  /*
   * Open the interface to the emulation board.
   */
  if ((fd = uhOpenGame("/dev/u64_data")) == -1) {
    fprintf(stderr, "host: openGame(/dev/u64_data): %s\n", sys_errlist[errno]);
    return(1);
  }

  /*
   * Generate a child process, in which "leowrrom" is gloaded.
   */
  if ((pid = fork()) == -1) {
    fprintf(stderr, "host: fork: %s\n", sys_errlist[errno]);
    endProc( CLOSE_GAME );
    return(1);
  } else if (pid == 0) {
    if(getenv("ROOT") != NULL)
    {
      strcpy(r4300prog, getenv("ROOT"));
      strcat(r4300prog, "/usr/lib/PR/leowrrom");
    }
    else
      strcpy(r4300prog, "/usr/lib/PR/leowrrom");

    (void)execl("/usr/sbin/gload", "/usr/sbin/gload", r4300prog, 0);
    fprintf(stderr, "host: execl(\"gload\") failed\n");
    return(1);
  }

  if(argFileIsSpecified)
  {
    /* open file */
    if ( (argFp = fopen(argFileName, "r")) == NULL )
    {
      fprintf(stderr, "host: open arg file: %s\n", sys_errlist[errno]);
      endProc( CLOSE_GAME|KILL_CHILD );
      return(1);
    }

    while( fileToArgs(argFp, &argC, argV) != EOF )
    {
      int	mainProcResult;
      
      /*
       * If the line contains no arguments or begins with #,
       * skip the line. (the line starts with # is considered
       * to be a comment line.)
       */
      if ( (argC == 1) || (*(argV[1]) == '#') )
	continue;
      
      datainit();
      parseArgs(argC, argV);
      mainProcResult = mainProc();
      
      /*
       * Release memory
       */
      argVp = argV;
      while (*argVp != '\0')
	free((void *)*argVp++);

      /*
       * Check the result of mainProc
       */
      if(mainProcResult)
      {
	/*
	 * We don't have to do error check for fclose;
	 * it's error, anyway.
	 */
	fclose(argFp);
	return (1);
      }

    } /* while */
    
    if ( fclose(argFp) == EOF )
    {
      endProc(CLOSE_GAME | KILL_CHILD);
      return (1);
    }

  }
  else
  {
    if(mainProc())
      return (1);
  }

  /*
   * Wait 4300 to get ready
   */
  if (uhReadGame(fd, &dummy, 4) == -1) {
    fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
    endProc(CLOSE_GAME | KILL_CHILD);
    return(1);
  }
  
  /*
   * Tell 4300 that leowrite is finished.
   */
  data.cmdFlags = END_COMMAND;

  if (uhWriteGame(fd, &data, sizeof(ctrlblk)) == -1) {
    fprintf(stderr, "uhWriteGame %s\n", sys_errlist[errno]);
    endProc(CLOSE_GAME | KILL_CHILD);
    return(1);
  }

  /*
   * Receive "ack"
   */
  if (uhReadGame(fd, &data, sizeof(ctrlblk)) == -1) {
    fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
    endProc(CLOSE_GAME | KILL_CHILD);
    return(1);
  }
  
  endProc( CLOSE_GAME|KILL_CHILD );
  return (0);

} /* main */


int mainProc(void)
{
  int		dummy;
  int		transbyte;
  char		filebuf[BUFSIZE];
  unsigned long long int
                written = 0;

  if ( data.cmdFlags & SPECD_ID_FILE )
  {
    int	fd, i;
    
    if ( (fd = open(idFileName, O_RDONLY)) == -1 )
    {
      fprintf(stderr, "host: open id file: %s\n", sys_errlist[errno]);
      return(1);
    }
    
    if (read(fd, (void *)&data.diskID, sizeof(LEODiskID)) < 32 )
    {
      fprintf(stderr, "host: read id file: %s\n", sys_errlist[errno]);
      return(1);
    }
    
    for (i = 0; i < 32; i++)
      printf("%x", ((u8 *)&data.diskID)[i]);
    
    printf("\n");
    
  }
  
  
  if (sendMeInfo == 0)
  {
    if (getHostName((u8 *)&data.diskID.serialNumber.lineNumber) == 1)
      return (1);
    
    getCurTime(&data.diskID.serialNumber.time);
    
    if ((data.offset < 0) || (data.offset >= NUM_LBAS))
    {
      fprintf(stderr, "Specified LBA is illegal; LBA is [0 - %d]\n", NUM_LBAS - 1);
      return(1);
    }
  }  

  if (sendMeInfo == 1)
  {
    /*
     * Wait 4300 to get ready
     */
    if (uhReadGame(fd, &dummy, 4) == -1) {
      fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
      endProc(CLOSE_GAME | KILL_CHILD);
      return(1);
    }
    
    /*
     * First, we send the filesize and offset.
     */
    if (uhWriteGame(fd, &data, sizeof(ctrlblk)) == -1) {
      fprintf(stderr, "uhWriteGame %s\n", sys_errlist[errno]);
      endProc(CLOSE_GAME | KILL_CHILD);
      return(1);
    }

    if (uhReadGame(fd, &data, sizeof(ctrlblk)) == -1) {
      fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
      endProc(CLOSE_GAME | KILL_CHILD);
      return(1);
    }
    
    if(data.cmdFlags & SYS_UNFORMATTED)
    {
      printf("This disk is unformatted\n");
      return ( endProc(CLOSE_GAME | KILL_CHILD) );
    }
    
    printf("\n");
    printf("disk type = %d\n", data.type);
    printf("load address = 0x%08x\n", data.address);
    printf("IPL size = %d\n", data.offset);

    if(data.cmdFlags & ID_UNFORMATTED)
    {
      printf("ID area is unformatted\n");
      return ( endProc(CLOSE_GAME | KILL_CHILD) );
    }

    printID(&data.diskID);

    return 0;
    
  }
  
  /*
   * Open the specified file.
   */
  if ((fildes = open(filename, O_RDONLY)) == -1)
  {
    fprintf(stderr, "open %s\n", sys_errlist[errno]);
    endProc( CLOSE_GAME | KILL_CHILD );
    return(1);
  }
  
  /*
   * Seek to the end of the file to get the file size.
   * What is the best way to do this?
   */
  if ((data.filesize = lseek(fildes, 0, SEEK_END)) == -1)
  {
    perror("lseek");
    endProc(END_ALL);
    return(1);
  }
  
  /*
   * Check to see "startbyte" and "endbyte" are legal when -w option
   * is specified.
   */
  if ( write_all == FALSE )
  {
    if ( endbyte == 0 )
      endbyte = data.filesize - 1; 	/* We set "byte offset" in endbyte!! */
    
    printf("startbyte = %d, endbyte = %d\n", startbyte, endbyte);

    if ( (startbyte < 0) || (startbyte >= data.filesize) )
    {
      fprintf(stderr, "leowrite: illegal startbyte(%d) is specified\n", startbyte);
      endProc(END_ALL);
      return(1);
    }
    if ( (endbyte < 0) || (endbyte >= data.filesize) )
    {
      fprintf(stderr, "leowrite: illegal endbyte(%d) is specified\n", endbyte);
      endProc(END_ALL);
      return(1);
    }
    if ( startbyte > endbyte )
    {
      fprintf(stderr, "leowrite: start-end relation is illegal\n");
      fprintf(stderr, "  startbyte(%d) should not be larger than endbyte(%d).\n",
	      startbyte, endbyte);
      endProc(END_ALL);
      return(1);
    }
    data.filesize = endbyte - startbyte + 1;

  } /* if (-w option is specified) */

  /*
   * If -s option is specified, skip the first 4K byte, that prevent us from
   * writing the redundant part of rom image.
   * If not specified, set the cursor of the file descriptor to the very first
   * of the file unless -w option is not specified.
   */
  if ( write_ipl3 == FALSE )
  {
    if ( lseek(fildes, 4096, SEEK_SET) == -1 )
    {
      perror("lseek");
      endProc(END_ALL);
      return(1);
    }
    data.filesize -= 4096;
    if ( data.filesize <= 0 )
    {
      fprintf(stderr, "leowrite: filesize error\n");
      fprintf(stderr, "  When you specify -s option, the file you want to write should be a\n");
      fprintf(stderr, "  romimage, the size of which will be larger than 4K bytes\n");
      endProc(END_ALL);
      return(1);
    }
    
  }
  else
  {
    if ( lseek(fildes, startbyte, SEEK_SET) == -1 )
    {
      perror("lseek");
      endProc(END_ALL);
      return(1);
    }
  } /* if (-s option is specified) */
  
  printf("Write %s (%d bytes)\n", filename, data.filesize);
  
  /*
   * Wait 4300 to get ready
   */
  if (uhReadGame(fd, &dummy, 4) == -1) {
    fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
    endProc(END_ALL);
    return(1);
  }

  /*
   * First, we send the filesize and offset.
   */
  if (uhWriteGame(fd, &data, sizeof(ctrlblk)) == -1) {
    fprintf(stderr, "uhWriteGame %s\n", sys_errlist[errno]);
    endProc(END_ALL);
    return(1);
  }

  while(1)
  {
    /*
     * 4300 tells host how many bytes to be transferred
     */
    if (uhReadGame(fd, &transbyte, sizeof(transbyte)) == -1) {
      fprintf(stderr, "uhReadGame %s\n", sys_errlist[errno]);
      endProc(END_ALL);
      return(1);
    }

    printf("Wrote %3llu %%\n",
	   Min(written, (unsigned int)data.filesize) * 100
	   / (unsigned int)data.filesize);
    written += transbyte;

    /* "transbyte = -1" means the write is finished */
    if (transbyte == -1)
      break;
      
    /*
     * Read from the input file
     */
    if (read(fildes, filebuf, transbyte) == -1)
    {
      perror("read");
      endProc(END_ALL);
      return(1);
    }
      
    /*
     * Send it to 4300
     */
    if (uhWriteGame(fd, filebuf, transbyte) == -1) {
      fprintf(stderr, "uhWriteGame %s\n", sys_errlist[errno]);
      endProc(END_ALL);
      return(1);
    }

  } /* while */

  printf("\n");
  
  return( endProc(CLOSE_FILE) );

}

void printID(LEODiskID *id)
{
  int	i;
  LEODiskTime	*time = &(id->serialNumber.time);
  
  printf("ID area: game name is %c%c%c%c\n", id->gameName[0],
	 id->gameName[1], id->gameName[2], id->gameName[3]);
  printf("         game version is %02x\n", id->gameVersion);
  printf("         disk number is %02x\n", id->diskNumber);
  printf("         disk usage is %04x\n", id->diskUsage);
  printf("         line number is %08llx (", *(long long *)&id->serialNumber.lineNumber);
  for (i = 0; i < 8; i++)
    printf("%c", ((u8 *)&id->serialNumber.lineNumber)[i]);
  printf(")\n");
  printf("         time is %x%x/%x/%x %02x:%02x:%02x\n",
	 time->yearhi, time->yearlo, time->month, time->day,
	 time->hour, time->minute, time->second);

  return;
  
} /* printID() */

/*
 * Terminate various stuffs used in our program. If you specify,
 *	CLOSE_FILE;  close the file descriptor for the file you specified.
 *    	CLOSE_GAME;  close the interface between host indy and target 4300.
 *      KILL_CHILD;  kill the child process for gloading 4300 program.
 *      END_ALL;     do all the things above.
 */
int endProc(int type)
{
  if (type & CLOSE_FILE)
    if (close(fildes) == -1)
    {
      fprintf(stderr, "close %s\n", sys_errlist[errno]);
      return(1);
    }
    
  if (type & CLOSE_GAME)
    if (uhCloseGame(fd) != 0) {
      fprintf(stderr, "host: closeGame: %s\n", sys_errlist[errno]);
      return(1);
    }
  
  if (type & KILL_CHILD)
  {
    if (kill(pid, SIGTERM) == -1) {
      fprintf(stderr, "host: kill(SIGTERM): %s\n", sys_errlist[errno]);
      return(1);
    }
    if (waitpid(pid, &status, WUNTRACED) == -1) {
      fprintf(stderr, "host: waitpid: %s\n", sys_errlist[errno]);
      return(1);
    }
  }
  
  return(0);
  
}

int	getHostName(char *name)
{
  int 	fd, len;
  char	tmpFileName[80], *s, command[90];
  
  if ( (s = getenv("TMPDIR")) != NULL )
    strcpy((void *)tmpFileName, (void *)s);
  else
    strcpy((void *)tmpFileName, (void *)"/tmp");

  strcat((void *)tmpFileName, "/__hostfile");

  strcpy((void *)command, "hostname > ");
  strcat((void *)command, (void *)tmpFileName);

  system(command);

  if ((fd = open(tmpFileName, O_RDONLY)) == -1)
  {
    fprintf(stderr, "Unable to open temporary file\n");
    return (1);
  }
  
  if ((len = lseek(fd, -1, SEEK_END)) == -1)
  {
    fprintf(stderr, "tmp file seek fail\n");
    return (1);
  }
  
  if ( lseek(fd, Max(len - MAX_HOSTNAME_LEN, 0), SEEK_SET) == -1 )
  {
    fprintf(stderr, "tmp file seek fail\n");
    return (1);
  }

  if ( read(fd, name, Min(len, MAX_HOSTNAME_LEN)) == -1 )
  {
    fprintf(stderr, "tmp file read fail\n");
    return (1);
  }

  if ( close(fd) == -1 )
  {
    fprintf(stderr, "tmp file close fail\n");
    return (1);
  }

  strcpy((void *)command, "rm ");
  strcat((void *)command, (void *)tmpFileName);
  
  system(command);
  
  return 0;
  
}

#define	ONE_BYTE(x, i)	( ((x)[i] - '0')*16 + ((x)[i+1] - '0') )

void	getCurTime(LEODiskTime *diskTime)
{
  char	tmp[30];
  time_t	t;
  
  t = time((time_t *)NULL);

  strftime(tmp, MAX_TIME_LEN * 3 , "%Y%m%d%H%M%S", 
	   localtime(&t));
  
  diskTime->yearhi = ONE_BYTE(tmp, 0);
  diskTime->yearlo = ONE_BYTE(tmp, 2);
  diskTime->month  = ONE_BYTE(tmp, 4);
  diskTime->day    = ONE_BYTE(tmp, 6);
  diskTime->hour   = ONE_BYTE(tmp, 8);
  diskTime->minute = ONE_BYTE(tmp, 10);
  diskTime->second = ONE_BYTE(tmp, 12);
  
  return;
}