home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / bsd / 9229 < prev    next >
Encoding:
Text File  |  1992-11-23  |  9.2 KB  |  319 lines

  1. Path: sparky!uunet!charon.amdahl.com!amdahl!paulp
  2. From: paulp@uts.amdahl.com (Paul Popelka)
  3. Newsgroups: comp.unix.bsd
  4. Subject: [386bsd] patches for pcfs to support hard disk filesystems
  5. Message-ID: <6a0K03lubdIH00@amdahl.uts.amdahl.com>
  6. Date: 23 Nov 92 17:35:09 GMT
  7. Organization: Amdahl Corporation, Sunnyvale CA
  8. Lines: 309
  9.  
  10.  
  11. Hi,
  12.  
  13. Here are some patches to make pcfs work with dos filesystems
  14. on hard disks.  Don't use an unpatched pcfs on hard disks.
  15.  
  16. To mount a hard disk dos filesystem:
  17. - use disklabel to define a 386bsd partition that covers the
  18.   area occupied by the dos filesystem.  Set this partition's
  19.   type to MSDOS with disklabel.  When you use disklabel in
  20.   this way it will write a 386bsd bootblock on the
  21.   first block of the disk.  This wipes out the dos partition
  22.   table.  I don't know of a way to prevent
  23.   it from doing this.  So, I just used dd to save a copy of
  24.   the dos bootblock, and restored it after disklabel was done.
  25. - Then, mount the filesystem.  Example:
  26.     mount -t pcfs /dev/sd0b /mnt
  27.  
  28. Don't put a dos filesystem in partition "a" of your hard disk.
  29. This will corrupt that dos filesystem.  This is because the kernel
  30. thinks partition "a" covers the disk label and attempts to write
  31. in the area where the label is thought to be are disallowed.
  32. Unfortunately the first block of the fat in a hard disk dos
  33. filesystem lives in this spot where the label might be.
  34.  
  35. There is a problem with moving directories in pcfs.  It does
  36. NOT corrupt your filesystem.  Here's a description of how to
  37. see the problem.
  38.  
  39.     Assume there are 3 directories on the filesystem.  One
  40.     called abc and under it is one called def.  Under def
  41.     is one called 123.
  42.  
  43.     mount -t pcfs /dev/fd0a /mnt
  44.     cd /mnt
  45.     mv abc/def def
  46.     cd def/123
  47.     pwd
  48.         /mnt/def/123
  49.     cd /mnt
  50.     mv def abc
  51.     cd abc/def
  52.     pwd
  53.  
  54.     At this pointed the diagnostic "pwd: No such file or directory"
  55.     will appear.  At this point we are(?) in directory /mnt/abc/def.
  56.  
  57.     cd ..
  58.     pwd
  59.         /mnt
  60.  
  61.     So, the cd .. moved us up 2 levels to def's old parent.
  62.  
  63. Once the vnode cache is flushed of the related vnodes this
  64. works ok.  I'm looking at this problem.
  65.  
  66. Paul
  67.  
  68. --------------------------cut here-----------------------------------
  69. *** 0.0/pcfs_fat.c    Sun Nov 22 20:14:33 1992
  70. --- pcfs_fat.c    Fri Nov 20 20:06:05 1992
  71. ***************
  72. *** 204,211 ****
  73.               if (bn != bp0_bn) {
  74.                   if (bp0)
  75.                       brelse(bp0);
  76. !                 if (error = bread(pmp->pm_devvp, bn,
  77. !                     pmp->pm_BytesPerSec, NOCRED, &bp0)) {
  78.                       brelse(bp0);
  79.                       return error;
  80.                   }
  81. --- 204,212 ----
  82.               if (bn != bp0_bn) {
  83.                   if (bp0)
  84.                       brelse(bp0);
  85. !                 error = bread(pmp->pm_devvp, bn,
  86. !                     pmp->pm_BytesPerSec, NOCRED, &bp0);
  87. !                 if (error) {
  88.                       brelse(bp0);
  89.                       return error;
  90.                   }
  91. ***************
  92. *** 571,577 ****
  93.                   whichbyte));
  94.           }
  95.           if (function & FAT_SET) {
  96. !             *(u_short *)(bp0->b_un.b_addr+whichbyte) = newcontents;
  97.               updateotherfats(pmp, bp0, 0, whichblk);
  98.               if (pmp->pm_waitonfat)
  99.                   bwrite(bp0);    /* write out blk from the 1st fat */
  100. --- 572,578 ----
  101.                   whichbyte));
  102.           }
  103.           if (function & FAT_SET) {
  104. !             *((u_short *)(bp0->b_un.b_addr+whichbyte)) = newcontents;
  105.               updateotherfats(pmp, bp0, 0, whichblk);
  106.               if (pmp->pm_waitonfat)
  107.                   bwrite(bp0);    /* write out blk from the 1st fat */
  108. *** 0.0/pcfs_lookup.c    Sun Nov 22 20:14:24 1992
  109. --- pcfs_lookup.c    Sat Nov 21 20:49:24 1992
  110. ***************
  111. *** 488,494 ****
  112.    */
  113.       if (ndp->ni_pcfs.pcfs_cluster == PCFSROOT) {
  114.           bn = pmp->pm_rootdirblk +
  115. !             (ndp->ni_pcfs.pcfs_offset / pmp->pm_depclust);
  116.           theoff = ndp->ni_pcfs.pcfs_offset % pmp->pm_depclust;
  117.       } else {
  118.           bn = cntobn(pmp, ndp->ni_pcfs.pcfs_cluster);
  119. --- 488,495 ----
  120.    */
  121.       if (ndp->ni_pcfs.pcfs_cluster == PCFSROOT) {
  122.           bn = pmp->pm_rootdirblk +
  123. !             ((ndp->ni_pcfs.pcfs_offset / pmp->pm_depclust) *
  124. !             pmp->pm_SectPerClust);
  125.           theoff = ndp->ni_pcfs.pcfs_offset % pmp->pm_depclust;
  126.       } else {
  127.           bn = cntobn(pmp, ndp->ni_pcfs.pcfs_cluster);
  128. ***************
  129. *** 534,540 ****
  130.       struct buf *bp;
  131.   
  132.       if (dirclust == PCFSROOT) {
  133. !         bn = pmp->pm_rootdirblk + (diroffset / pmp->pm_depclust);
  134.           offset = diroffset % pmp->pm_depclust;
  135.       } else {
  136.           bn = cntobn(pmp, dirclust);
  137. --- 535,542 ----
  138.       struct buf *bp;
  139.   
  140.       if (dirclust == PCFSROOT) {
  141. !         bn = pmp->pm_rootdirblk + ((diroffset / pmp->pm_depclust) *
  142. !             pmp->pm_SectPerClust);
  143.           offset = diroffset % pmp->pm_depclust;
  144.       } else {
  145.           bn = cntobn(pmp, dirclust);
  146. ***************
  147. *** 753,759 ****
  148.   
  149.       if (dep->de_dirclust == PCFSROOT) {
  150.           bn = pmp->pm_rootdirblk +
  151. !             (dep->de_diroffset / pmp->pm_depclust);
  152.           theoff = dep->de_diroffset % pmp->pm_depclust;
  153.       } else {
  154.           bn = cntobn(pmp, dep->de_dirclust);
  155. --- 755,762 ----
  156.   
  157.       if (dep->de_dirclust == PCFSROOT) {
  158.           bn = pmp->pm_rootdirblk +
  159. !             ((dep->de_diroffset / pmp->pm_depclust) *
  160. !             pmp->pm_SectPerClust);
  161.           theoff = dep->de_diroffset % pmp->pm_depclust;
  162.       } else {
  163.           bn = cntobn(pmp, dep->de_dirclust);
  164. *** 0.0/pcfs_vnops.c    Wed Nov 18 21:46:28 1992
  165. --- pcfs_vnops.c    Sat Nov 21 20:18:45 1992
  166. ***************
  167. *** 991,996 ****
  168. --- 991,997 ----
  169.    *  tdep is unlocked and unreferenced
  170.    */
  171.       } else {
  172. +         unsigned long dirsize;
  173.   /*
  174.    *  If the source and destination are in different
  175.    *  directories, then mark the entry in the source
  176. ***************
  177. *** 1000,1009 ****
  178.    *  the filesystem.  And, if we moved a directory,
  179.    *  then update its .. entry to point to the new
  180.    *  parent directory.
  181.    */
  182.           DELOCK(fdep);
  183.           bcopy(toname, fdep->de_Name, 11);    /* update denode */
  184. !         if (error = createde(fdep, tndp, (struct denode **)0)) {
  185.               /* should put back filename */
  186.               DEUNLOCK(fdep);
  187.               goto bad;
  188. --- 1001,1021 ----
  189.    *  the filesystem.  And, if we moved a directory,
  190.    *  then update its .. entry to point to the new
  191.    *  parent directory.
  192. +  *  If we moved a directory will also insure that
  193. +  *  the directory entry on disk has a filesize of
  194. +  *  zero.
  195.    */
  196.           DELOCK(fdep);
  197.           bcopy(toname, fdep->de_Name, 11);    /* update denode */
  198. !         if (fdep->de_Attributes & ATTR_DIRECTORY) {
  199. !             dirsize = fdep->de_FileSize;
  200. !             fdep->de_FileSize = 0;
  201. !         }
  202. !         error = createde(fdep, tndp, (struct denode **)0);
  203. !         if (fdep->de_Attributes & ATTR_DIRECTORY) {
  204. !             fdep->de_FileSize = dirsize;
  205. !         }
  206. !         if (error) {
  207.               /* should put back filename */
  208.               DEUNLOCK(fdep);
  209.               goto bad;
  210. ***************
  211. *** 1294,1299 ****
  212. --- 1306,1312 ----
  213.   {
  214.       int error = 0;
  215.       int diff;
  216. +     char pushout;
  217.       long n;
  218.       long on;
  219.       long lost;
  220. ***************
  221. *** 1380,1389 ****
  222.   /*
  223.    *  code to convert from dos directory entries to ufs directory entries
  224.    */
  225. !         dentp = (struct direntry *)bp->b_un.b_addr + on;
  226.           prev = 0;
  227.           crnt = (struct dirent *)dirbuf;
  228. !         while ((char *)dentp < bp->b_un.b_addr + n) {
  229.   /*printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
  230.       dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);*/
  231.   /*
  232. --- 1393,1403 ----
  233.   /*
  234.    *  code to convert from dos directory entries to ufs directory entries
  235.    */
  236. !         pushout = 0;
  237. !         dentp = (struct direntry *)(bp->b_un.b_addr + on);
  238.           prev = 0;
  239.           crnt = (struct dirent *)dirbuf;
  240. !         while ((char *)dentp < bp->b_un.b_addr + on + n) {
  241.   /*printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
  242.       dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);*/
  243.   /*
  244. ***************
  245. *** 1392,1401 ****
  246.    *  space onto the end of the previous entry or,
  247.    *  manufacture an empty entry if there is no previous
  248.    *  entry.
  249. -  *  If the entry is empty then set a flag saying finish
  250. -  *  out the block but signal an end of file since empty
  251. -  *  slots mean there are no further entries of interest
  252. -  *  in the directory.
  253.    */
  254.               if (dentp->deName[0] == SLOT_EMPTY  ||
  255.                   dentp->deName[0] == SLOT_DELETED  ||
  256. --- 1406,1411 ----
  257. ***************
  258. *** 1432,1437 ****
  259. --- 1442,1448 ----
  260.                   prev = crnt;
  261.               }
  262.               crnt = (struct dirent *)((char *)crnt + sizeof(struct direntry));
  263. +             pushout = 1;
  264.   
  265.   /*
  266.    *  If our intermediate buffer is full then copy
  267. ***************
  268. *** 1443,1449 ****
  269.    *  the buffer before brelse()'ing it.
  270.    */
  271.               if ((unsigned char *)crnt >= &dirbuf[sizeof dirbuf]) {
  272. !                 error = uiomove(dirbuf, n, uio);
  273.                   if (error)
  274.                       break;
  275.                   prev = 0;
  276. --- 1454,1461 ----
  277.    *  the buffer before brelse()'ing it.
  278.    */
  279.               if ((unsigned char *)crnt >= &dirbuf[sizeof dirbuf]) {
  280. !                 pushout = 0;
  281. !                 error = uiomove(dirbuf, sizeof(dirbuf), uio);
  282.                   if (error)
  283.                       break;
  284.                   prev = 0;
  285. ***************
  286. *** 1451,1456 ****
  287. --- 1463,1473 ----
  288.               }
  289.               dentp++;
  290.           }
  291. +         if (pushout) {
  292. +             pushout = 0;
  293. +             error = uiomove(dirbuf, (char *)crnt - (char *)dirbuf,
  294. +                 uio);
  295. +         }
  296.   
  297.   /*
  298.    *  If we have read everything from this block or
  299. ***************
  300. *** 1572,1580 ****
  301.    *  holes, so we shouldn't ever see this.
  302.    */
  303.       if (bp->b_blkno == bp->b_lblkno) {
  304. !         if (error = pcbmap(dep,
  305. !             bp->b_lblkno << (pmp->pm_cnshift - pmp->pm_bnshift),
  306. !             &bp->b_blkno, 0))
  307.               return error;
  308.           if ((long)bp->b_blkno == -1)
  309.               clrbuf(bp);
  310. --- 1589,1595 ----
  311.    *  holes, so we shouldn't ever see this.
  312.    */
  313.       if (bp->b_blkno == bp->b_lblkno) {
  314. !         if (error = pcbmap(dep, bp->b_lblkno, &bp->b_blkno, 0))
  315.               return error;
  316.           if ((long)bp->b_blkno == -1)
  317.               clrbuf(bp);
  318. --------------------------you've got the complete patch---------------------
  319.