Commit ab941afd authored by Christoph Hellwig's avatar Christoph Hellwig

[PATCH] split initrd from ramdisk driver

They don't have any code in common, so the initrd support can
go into a separate file and not require ramdisk support.

Lots of ifdefs gone and smaller kernel images for initrd users.
parent 536ab54b
......@@ -331,7 +331,6 @@ config BLK_DEV_RAM_SIZE
config BLK_DEV_INITRD
bool "Initial RAM disk (initrd) support"
depends on BLK_DEV_RAM=y
help
The initial RAM disk is a RAM disk that is loaded by the boot loader
(loadlin or lilo) and that is mounted as root before the normal boot
......
......@@ -20,6 +20,7 @@ obj-$(CONFIG_ATARI_ACSI) += acsi.o
obj-$(CONFIG_ATARI_SLM) += acsi_slm.o
obj-$(CONFIG_AMIGA_Z2RAM) += z2ram.o
obj-$(CONFIG_BLK_DEV_RAM) += rd.o
obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
obj-$(CONFIG_BLK_DEV_LOOP) += loop.o
obj-$(CONFIG_BLK_DEV_PS2) += ps2esdi.o
obj-$(CONFIG_BLK_DEV_XD) += xd.o
......
#include <linux/blkdev.h>
#include <linux/genhd.h>
#include <linux/initrd.h>
#include <linux/init.h>
#include <linux/major.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <asm/uaccess.h>
unsigned long initrd_start, initrd_end;
int initrd_below_start_ok;
static int initrd_users;
static spinlock_t initrd_users_lock = SPIN_LOCK_UNLOCKED;
static struct gendisk *initrd_disk;
static ssize_t initrd_read(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
int left = initrd_end - initrd_start - *ppos;
if (count > left)
count = left;
if (count == 0)
return 0;
if (copy_to_user(buf, (char *)initrd_start + *ppos, count))
return -EFAULT;
*ppos += count;
return count;
}
static int initrd_release(struct inode *inode,struct file *file)
{
blkdev_put(inode->i_bdev, BDEV_FILE);
spin_lock(&initrd_users_lock);
if (!--initrd_users) {
spin_unlock(&initrd_users_lock);
del_gendisk(initrd_disk);
free_initrd_mem(initrd_start, initrd_end);
initrd_start = 0;
} else
spin_unlock(&initrd_users_lock);
return 0;
}
static struct file_operations initrd_fops = {
.read = initrd_read,
.release = initrd_release,
};
static int initrd_open(struct inode *inode, struct file *filp)
{
if (!initrd_start)
return -ENODEV;
spin_lock(&initrd_users_lock);
initrd_users++;
spin_unlock(&initrd_users_lock);
filp->f_op = &initrd_fops;
return 0;
}
static struct block_device_operations initrd_bdops = {
.owner = THIS_MODULE,
.open = initrd_open,
};
static int __init initrd_init(void)
{
initrd_disk = alloc_disk(1);
if (!initrd_disk)
return -ENOMEM;
initrd_disk->major = RAMDISK_MAJOR;
initrd_disk->first_minor = INITRD_MINOR;
initrd_disk->fops = &initrd_bdops;
sprintf(initrd_disk->disk_name, "initrd");
sprintf(initrd_disk->devfs_name, "rd/initrd");
set_capacity(initrd_disk, (initrd_end-initrd_start+511) >> 9);
add_disk(initrd_disk);
return 0;
}
static void __exit initrd_exit(void)
{
put_disk(initrd_disk);
}
module_init(initrd_init);
module_exit(initrd_exit);
......@@ -56,20 +56,12 @@
#include <linux/bio.h>
#include <linux/buffer_head.h> /* for invalidate_bdev() */
#include <linux/backing-dev.h>
#include <linux/initrd.h>
#include <linux/blkpg.h>
#include <asm/uaccess.h>
/* The RAM disk size is now a parameter */
#define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */
#ifdef CONFIG_BLK_DEV_INITRD
static int initrd_users;
static spinlock_t initrd_users_lock = SPIN_LOCK_UNLOCKED;
unsigned long initrd_start, initrd_end;
int initrd_below_start_ok;
#endif
/* Various static variables go here. Most are used only in the RAM disk code.
*/
......@@ -269,53 +261,6 @@ static int rd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
return error;
}
#ifdef CONFIG_BLK_DEV_INITRD
static struct block_device_operations rd_bd_op;
static struct gendisk *initrd_disk;
static ssize_t initrd_read(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
int left;
left = initrd_end - initrd_start - *ppos;
if (count > left) count = left;
if (count == 0) return 0;
if (copy_to_user(buf, (char *)initrd_start + *ppos, count))
return -EFAULT;
*ppos += count;
return count;
}
static int initrd_release(struct inode *inode,struct file *file)
{
extern void free_initrd_mem(unsigned long, unsigned long);
blkdev_put(inode->i_bdev, BDEV_FILE);
spin_lock(&initrd_users_lock);
if (!--initrd_users) {
spin_unlock(&initrd_users_lock);
del_gendisk(initrd_disk);
free_initrd_mem(initrd_start, initrd_end);
initrd_start = 0;
} else {
spin_unlock(&initrd_users_lock);
}
return 0;
}
static struct file_operations initrd_fops = {
.read = initrd_read,
.release = initrd_release,
};
#endif
static struct backing_dev_info rd_backing_dev_info = {
.ra_pages = 0, /* No readahead */
.memory_backed = 1, /* Does not contribute to dirty memory */
......@@ -325,18 +270,6 @@ static int rd_open(struct inode * inode, struct file * filp)
{
int unit = minor(inode->i_rdev);
#ifdef CONFIG_BLK_DEV_INITRD
if (unit == INITRD_MINOR) {
spin_lock(&initrd_users_lock);
initrd_users++;
spin_unlock(&initrd_users_lock);
if (!initrd_start)
return -ENODEV;
filp->f_op = &initrd_fops;
return 0;
}
#endif
/*
* Immunize device against invalidate_buffers() and prune_icache().
*/
......@@ -375,9 +308,7 @@ static void __exit rd_cleanup (void)
del_gendisk(rd_disks[i]);
put_disk(rd_disks[i]);
}
#ifdef CONFIG_BLK_DEV_INITRD
put_disk(initrd_disk);
#endif
devfs_remove("rd");
unregister_blkdev(RAMDISK_MAJOR, "ramdisk" );
}
......@@ -396,17 +327,6 @@ static int __init rd_init (void)
rd_blocksize = BLOCK_SIZE;
}
#ifdef CONFIG_BLK_DEV_INITRD
initrd_disk = alloc_disk(1);
if (!initrd_disk)
return -ENOMEM;
initrd_disk->major = RAMDISK_MAJOR;
initrd_disk->first_minor = INITRD_MINOR;
initrd_disk->fops = &rd_bd_op;
sprintf(initrd_disk->disk_name, "initrd");
sprintf(initrd_disk->devfs_name, "rd/initrd");
#endif
for (i = 0; i < NUM_RAMDISKS; i++) {
rd_disks[i] = alloc_disk(1);
if (!rd_disks[i])
......@@ -436,12 +356,6 @@ static int __init rd_init (void)
add_disk(rd_disks[i]);
}
#ifdef CONFIG_BLK_DEV_INITRD
/* We ought to separate initrd operations here */
set_capacity(initrd_disk, (initrd_end-initrd_start+511)>>9);
add_disk(initrd_disk);
#endif
/* rd_size is given in kB */
printk("RAMDISK driver initialized: "
"%d RAM disks of %dK size %d blocksize\n",
......@@ -451,9 +365,6 @@ static int __init rd_init (void)
out:
while (i--)
put_disk(rd_disks[i]);
#ifdef CONFIG_BLK_DEV_INITRD
put_disk(initrd_disk);
#endif
return err;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment