home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / linux / 6701 < prev    next >
Encoding:
Text File  |  1992-07-25  |  9.7 KB  |  354 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!darwin.sura.net!Sirius.dfn.de!chx400!bernina!almesber
  3. From: almesber@nessie.cs.id.ethz.ch (Werner Almesberger)
  4. Subject: Re: mrphmpmmmph shoelace and partitions
  5. Message-ID: <1992Jul25.210010.4405@bernina.ethz.ch>
  6. Sender: news@bernina.ethz.ch (USENET News System)
  7. Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
  8. References: <1992Jul24.021543.24526@sol.UVic.CA> <1992Jul24.143547.23391@crd.ge.com>
  9. Date: Sat, 25 Jul 1992 21:00:10 GMT
  10. Lines: 342
  11.  
  12. In article <1992Jul24.143547.23391@crd.ge.com> davidsen@crd.ge.com (bill davidsen) writes:
  13. >In article <1992Jul24.021543.24526@sol.UVic.CA>, pmacdona@sanjuan (Peter MacDonald) writes:
  14. >
  15. >| One solution is to implement quotas, but I think Linus may
  16. >| have said nay to that already.  Another would be to
  17. >| allow mounting of files as file systems?  Comments? Catcalls?
  18.  
  19. I've had this sitting around for a long time. A patch I've originally
  20. made for 0.96c-pl1 and that seems to work unmodified for 0.96c-pl2 is
  21. at the end of this posting.
  22.  
  23. Usage example:
  24.  
  25.   # a floppy with a Minix FS (e.g. the rootimage) is in drive A:
  26.   dd if=/dev/fd0 of=/file bs=256k
  27.   mount /file /mnt
  28.  
  29. A few remarks:
  30.   - files that reside on an MS-DOS FS can only be mounted if that FS
  31.     supports bmap. Hard disk and 3.5" floppy file systems usually
  32.     don't.
  33.   - newer umounts may refuse to unmount a mounted file. Hacking umount
  34.     to accept files is left as an exercise to the reader ;-)
  35.   - recursion (mounting a file from an FS that is a mounted file,
  36.     etc.) is possible.
  37.  
  38. >   Well, I like the basic idea, because it solves a bunch of problems.
  39. > But it needs a bit of support before it really works; namely support in
  40. > fsck and mkfs to support it.
  41.  
  42. Last time I've checked (early June, 0.96a-pl2), fsck and mkfs were able
  43. to operate on files.
  44.  
  45. Enjoy,
  46. - Werner
  47.  
  48. ---------------------------------- cut here -----------------------------------
  49.  
  50. diff -cr +new-files linux.orig/fs/Makefile linux/fs/Makefile
  51. *** linux.orig/fs/Makefile    Fri Jul 17 08:56:13 1992
  52. --- linux/fs/Makefile    Fri Jul 17 09:55:19 1992
  53. ***************
  54. *** 18,24 ****
  55.   
  56.   OBJS=    open.o read_write.o inode.o file_table.o buffer.o super.o \
  57.       block_dev.o stat.o exec.o pipe.o namei.o fcntl.o ioctl.o \
  58. !     select.o fifo.o
  59.   
  60.   all: fs.o subdirs
  61.   
  62. --- 18,24 ----
  63.   
  64.   OBJS=    open.o read_write.o inode.o file_table.o buffer.o super.o \
  65.       block_dev.o stat.o exec.o pipe.o namei.o fcntl.o ioctl.o \
  66. !     select.o fifo.o loop.o
  67.   
  68.   all: fs.o subdirs
  69.   
  70. diff -cr +new-files linux.orig/fs/buffer.c linux/fs/buffer.c
  71. *** linux.orig/fs/buffer.c    Fri Jul 17 08:56:13 1992
  72. --- linux/fs/buffer.c    Fri Jul 17 09:35:30 1992
  73. ***************
  74. *** 23,28 ****
  75. --- 23,29 ----
  76.   #include <linux/config.h>
  77.   #include <linux/sched.h>
  78.   #include <linux/kernel.h>
  79. + #include <linux/loop.h>
  80.   #include <asm/system.h>
  81.   #include <asm/io.h>
  82.   
  83. ***************
  84. *** 261,266 ****
  85. --- 262,269 ----
  86.       struct buffer_head * bh, * tmp;
  87.       int buffers;
  88.   
  89. +     while (MAJOR(dev) == LOOP_MAJOR)
  90. +         if (loop_trans(&dev,&block)) break;
  91.   repeat:
  92.       if (bh = get_hash_table(dev,block))
  93.           return bh;
  94. diff -cr +new-files linux.orig/fs/loop.c linux/fs/loop.c
  95. *** linux.orig/fs/loop.c
  96. --- linux/fs/loop.c    Fri Jul 17 09:35:31 1992
  97. ***************
  98. *** 0 ****
  99. --- 1,73 ----
  100. + /* Loop devices. They're used to mount files as FS'. */
  101. + /* Written 1992 by Werner Almesberger */
  102. + #include <asm/segment.h>
  103. + #include <linux/kernel.h>
  104. + #include <linux/fs.h>
  105. + #include <linux/loop.h>
  106. + #include <errno.h>
  107. + static int first_use = 1;
  108. + static struct inode *loops[MAX_LOOPS];
  109. + int loop_getdev(struct inode *inode)
  110. + {
  111. +     int count;
  112. +     if (first_use) {
  113. +         for (count = 0; count < MAX_LOOPS; count++) loops[count] = NULL;
  114. +         first_use = 0;
  115. +     }
  116. +     if (inode->i_op == NULL || inode->i_op->bmap == NULL) return -EINVAL;
  117. +     for (count = 0; count < MAX_LOOPS; count++)
  118. +         if (loops[count] == inode) return -EBUSY;
  119. +     for (count = 0; count < MAX_LOOPS; count++)
  120. +         if (loops[count] == NULL) {
  121. +             loops[count] = inode;
  122. +             return (LOOP_MAJOR << 8) | count;
  123. +         }
  124. +     return -ENODEV;
  125. + }
  126. + int loop_finddev(struct inode *inode)
  127. + {
  128. +     int count;
  129. +     for (count = 0; count < MAX_LOOPS; count++)
  130. +         if (loops[count] == inode) return (LOOP_MAJOR << 8) | count;
  131. +     return -ENODEV;
  132. + }
  133. + void loop_dropdev(int dev)
  134. + {
  135. +     int loop;
  136. +     if (MAJOR(dev) != LOOP_MAJOR) panic("loop_dropdev: bad major number");
  137. +     loop = MINOR(dev);
  138. +     if (loop < 0 || loop >= MAX_LOOPS || loops[loop] == NULL)
  139. +         panic("loop_dropdev: bad minor number");
  140. +     iput(loops[loop]);
  141. +     loops[loop] = NULL;
  142. + }
  143. + int loop_trans(int *dev,int *block)
  144. + {
  145. +     int loop,this;
  146. +     if (MAJOR(*dev) != LOOP_MAJOR) panic("loop_trans: bad major number");
  147. +     loop = MINOR(*dev);
  148. +     if (loop < 0 || loop >= MAX_LOOPS || loops[loop] == NULL)
  149. +         panic("loop_trans: bad minor number");
  150. +     if (*block < 0 || *block >= ((loops[loop]->i_size+BLOCK_SIZE-1) >>
  151. +         BLOCK_SIZE_BITS)) return -1;
  152. + /* makes a lot of noise when failing, but it's better than a panic. */
  153. +     if (!(this = bmap(loops[loop],*block))) return -1;
  154. +     *block = this;
  155. +     *dev = loops[loop]->i_dev;
  156. +     return 0;
  157. + }
  158. diff -cr +new-files linux.orig/fs/super.c linux/fs/super.c
  159. *** linux.orig/fs/super.c    Fri Jul 17 08:56:14 1992
  160. --- linux/fs/super.c    Fri Jul 17 10:05:33 1992
  161. ***************
  162. *** 13,18 ****
  163. --- 13,19 ----
  164.   #include <linux/ext_fs.h>
  165.   #include <linux/msdos_fs.h>
  166.   #include <linux/kernel.h>
  167. + #include <linux/loop.h>
  168.   #include <linux/stat.h>
  169.   #include <asm/system.h>
  170.   #include <asm/segment.h>
  171. ***************
  172. *** 158,167 ****
  173.           return -EPERM;
  174.       if (!(inode = namei(dev_name)))
  175.           return -ENOENT;
  176. !     dev = inode->i_rdev;
  177. !     if (!S_ISBLK(inode->i_mode)) {
  178. !         iput(inode);
  179. !         return -ENOTBLK;
  180.       }
  181.       iput(inode);
  182.       if (dev==ROOT_DEV)
  183. --- 159,176 ----
  184.           return -EPERM;
  185.       if (!(inode = namei(dev_name)))
  186.           return -ENOENT;
  187. !     if (S_ISBLK(inode->i_mode)) dev = inode->i_rdev;
  188. !     else {
  189. !         if (S_ISREG(inode->i_mode)) {
  190. !             if ((dev = loop_finddev(inode)) < 0) {
  191. !                 iput(inode);
  192. !                 return dev;
  193. !             }
  194. !         }
  195. !         else {
  196. !             iput(inode);
  197. !             return -ENOTBLK;
  198. !         }
  199.       }
  200.       iput(inode);
  201.       if (dev==ROOT_DEV)
  202. ***************
  203. *** 185,190 ****
  204. --- 194,200 ----
  205.           sb->s_op->write_super (sb);
  206.           put_super(dev);
  207.           sync_dev(dev);
  208. +     if (MAJOR(dev) == LOOP_MAJOR) loop_dropdev(dev);
  209.       return 0;
  210.   }
  211.   
  212. ***************
  213. *** 248,254 ****
  214.       unsigned long new_flags, void *data)
  215.   {
  216.       struct inode * inode;
  217. !     int dev;
  218.       int retval = 0;
  219.       char tmp[100],*t;
  220.       int i;
  221. --- 258,264 ----
  222.       unsigned long new_flags, void *data)
  223.   {
  224.       struct inode * inode;
  225. !     int dev = 0; /* to make GCC happy ... */
  226.       int retval = 0;
  227.       char tmp[100],*t;
  228.       int i;
  229. ***************
  230. *** 259,269 ****
  231.           return -EPERM;
  232.       if (!(inode = namei(dev_name)))
  233.           return -ENOENT;
  234. !     dev = inode->i_rdev;
  235. !     if (!S_ISBLK(inode->i_mode))
  236. !         retval = -EPERM;
  237. !     else if (IS_NODEV(inode))
  238. !         retval = -EACCES;
  239.       iput(inode);
  240.       if (retval)
  241.           return retval;
  242. --- 269,282 ----
  243.           return -EPERM;
  244.       if (!(inode = namei(dev_name)))
  245.           return -ENOENT;
  246. !     if (S_ISBLK(inode->i_mode)) {
  247. !         if (IS_NODEV(inode)) retval = -EACCES;
  248. !         else dev = inode->i_rdev;
  249. !     }
  250. !     else {
  251. !         if (!S_ISREG(inode->i_mode)) retval = -EPERM;
  252. !         else if ((dev = loop_getdev(inode)) < 0) retval = dev;
  253. !       }
  254.       iput(inode);
  255.       if (retval)
  256.           return retval;
  257. ***************
  258. *** 285,291 ****
  259.           t = tmp;
  260.       } else
  261.           t = "minix";
  262. !     retval = do_mount(dev,dir_name,t,flags,(void *) page);
  263.       free_page(page);
  264.       return retval;
  265.   }
  266. --- 298,305 ----
  267.           t = tmp;
  268.       } else
  269.           t = "minix";
  270. !     if ((retval = do_mount(dev,dir_name,t,flags,(void *) page)) < 0 &&
  271. !         MAJOR(dev) == LOOP_MAJOR) loop_dropdev(dev);
  272.       free_page(page);
  273.       return retval;
  274.   }
  275. diff -cr +new-files linux.orig/include/linux/loop.h linux/include/linux/loop.h
  276. *** linux.orig/include/linux/loop.h
  277. --- linux/include/linux/loop.h    Fri Jul 17 09:35:32 1992
  278. ***************
  279. *** 0 ****
  280. --- 1,12 ----
  281. + #ifndef _LOOP_H
  282. + #define _LOOP_H
  283. + #define LOOP_MAJOR 10    /* loop device major number */
  284. + #define MAX_LOOPS   8   /* max. number of loop devices */
  285. + int loop_getdev(struct inode *inode); /* create loop device */
  286. + int loop_finddev(struct inode *inode); /* find loop device */
  287. + void loop_dropdev(int dev); /* remove loop device */
  288. + int loop_trans(int *dev,int *block); /* translate to real params */
  289. + #endif
  290. diff -cr +new-files linux.orig/kernel/blk_drv/blk.h linux/kernel/blk_drv/blk.h
  291. *** linux.orig/kernel/blk_drv/blk.h    Fri Jul 17 08:56:46 1992
  292. --- linux/kernel/blk_drv/blk.h    Fri Jul 17 09:35:32 1992
  293. ***************
  294. *** 1,7 ****
  295.   #ifndef _BLK_H
  296.   #define _BLK_H
  297.   
  298. ! #define NR_BLK_DEV    10
  299.   /*
  300.    * NR_REQUEST is the number of entries in the request-queue.
  301.    * NOTE that writes may use only the low 2/3 of these: reads
  302. --- 1,7 ----
  303.   #ifndef _BLK_H
  304.   #define _BLK_H
  305.   
  306. ! #define NR_BLK_DEV    11
  307.   /*
  308.    * NR_REQUEST is the number of entries in the request-queue.
  309.    * NOTE that writes may use only the low 2/3 of these: reads
  310. diff -cr +new-files linux.orig/kernel/blk_drv/ll_rw_blk.c linux/kernel/blk_drv/ll_rw_blk.c
  311. *** linux.orig/kernel/blk_drv/ll_rw_blk.c    Fri Jul 17 08:56:45 1992
  312. --- linux/kernel/blk_drv/ll_rw_blk.c    Fri Jul 17 09:35:32 1992
  313. ***************
  314. *** 42,48 ****
  315.       { NULL, NULL },        /* dev lp */
  316.       { NULL, NULL },        /* dev pipes */
  317.       { NULL, NULL },        /* dev sd */
  318. !     { NULL, NULL }        /* dev st */
  319.   };
  320.   
  321.   /*
  322. --- 42,49 ----
  323.       { NULL, NULL },        /* dev lp */
  324.       { NULL, NULL },        /* dev pipes */
  325.       { NULL, NULL },        /* dev sd */
  326. !     { NULL, NULL },        /* dev st */
  327. !     { NULL, NULL }        /* dev loop */
  328.   };
  329.   
  330.   /*
  331. -- 
  332.    _________________________________________________________________________
  333.   / Werner Almesberger, ETH Zuerich, CH      almesber@nessie.cs.id.ethz.ch /
  334.  / IFW A44  Tel. +41 1 254 7213                 almesberger@rzvax.ethz.ch /
  335. /_BITNET:_ALMESBER@CZHETH5A__HEPNET/CHADNET:_[20579::]57414::ALMESBERGER_/
  336.