home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / programm / 5671 < prev    next >
Encoding:
Internet Message Format  |  1992-12-13  |  3.5 KB

  1. Xref: sparky comp.unix.programmer:5671 comp.unix.wizards:5208
  2. Path: sparky!uunet!spool.mu.edu!uwm.edu!psuvax1!rutgers!banana!vpbuild!adsi!markp
  3. From: markp@adsi.homecare.com (Mark Parr)
  4. Newsgroups: comp.unix.programmer,comp.unix.wizards
  5. Subject: Tape management program
  6. Message-ID: <1992Dec8.175936.5802@adsi.homecare.com>
  7. Date: 8 Dec 92 17:59:36 GMT
  8. Sender: markp@adsi.homecare.com (Mark Parr)
  9. Organization: Application Data Systems, Inc.
  10. Lines: 82
  11.  
  12. I'm working on a C program as a front end to tape management program that
  13. I'm writing.  The layout of our tape format is:
  14.  
  15.     [tape header][file1 header][file1][.....][filen header][filen]
  16.  
  17.  
  18. Headers are written to tape using the following syntax:
  19.  
  20.     sprintf(command, "dd of=%s 2> /dev/null", tape_device);
  21.     fp = popen(command, "w");
  22.     fwrite(fp, &header, (sizeof(header)), 1, fp);
  23.     pclose(fp);
  24.  
  25. where header is either the tape header structure or the file header
  26. structure.
  27.  
  28.  
  29. Adding files to the tape is done as follows:
  30.  
  31.     sprintf(command, "ls %s | cpio -oc > %s 2> /dev/null", file, tape_device);
  32.     system(command);
  33.  
  34. where file is the file to add.
  35.  
  36.  
  37. Extracting files first accomplished by verifying the correct tape then moving
  38. through the various files using:
  39.  
  40.     sprintf(command, "dd if=%s 2> /dev/null", tape_device);
  41.     fp = fopen(command, "r");
  42.     fread(&fileheader, sizeof(fileheader), 1, fp);
  43.     pclose(fp);
  44.  
  45. until fileheader.filename equals the file that is being extracted.  At this
  46. time, the file is extracted using:
  47.  
  48.     sprintf(command, "cpio -icd < %s 2> /dev/null", tape_device);
  49.     system(command);
  50.  
  51.  
  52. Care has been taken to make sure that tape_device is the correct device in 
  53. regards to rewind before/after use.
  54.  
  55.  
  56. Everything works fine *except* for the command to actually extract the file.
  57. I am able to add files and headers and move up to the file to extract.
  58. However, the extract does not want to work for me.  The call seems to come 
  59. back clean, but the file is not extract.  In fact, the tape remains in the
  60. same position.  When I return to the shell, the tape has not be rewound at this
  61. point.  I can then actually type the cpio command for the extract and it 
  62. will work.  
  63.  
  64. To try and track things down, I changed the extract system call to a
  65.  
  66.      system("sh");
  67.  
  68. and typed the command by hand at the shell prompt.  That didn't work.  (Note:
  69. the other cpio and dd commands work in this shell.) 
  70.  
  71. Something else weird:  This program is being developed on a NCR 750 Tower.  We
  72. are running a public doman Korn Shell on this system.  Now, if while in the 
  73. above shell, I enter the ksh and type the cpio command by hand, it works.  
  74. Also, if I run the command as "system" call in another program (this is
  75. done by running the program that does not work to position the tape at the
  76. correct location and then running this new program) it will extract the file.
  77.  
  78. The problem appears to be some kind of problem between my program and our
  79. "/bin/sh" -- but what has got me puzzled.  In the early stages of development,
  80. the program extract part worked fine.
  81.  
  82. I hope that there's someone out there that can give me some ideas on 
  83. where to start in trying to solve this problem.  Any ideas would be
  84. appreciated.
  85.  
  86. Thanks,
  87. Mark
  88.  
  89. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  90.  | |-------------|  Application Data Systems     |  Phone: (601) 393-2046  | |
  91.  | |  Mark Parr  |  1930-B 1st Commercial Dr. N  |    Fax: (601) 393-6605  | |
  92.  | |-------------|  Southaven, MS 38671          |    markp@adsi.vp.com    | |
  93. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  94.