Commit 2f8e2dc8 authored by Peter Osterlund's avatar Peter Osterlund Committed by Linus Torvalds

[PATCH] CDRW packet writing support

This patch implements CDRW packet writing as a kernel block device.  Usage
instructions are in the packet-writing.txt file.

A hint: If you don't want to wait for a complete disc format, you can
format just a part of the disc.  For example:

        cdrwtool -d /dev/hdc -m 10240

This will format 10240 blocks, ie 20MB.
Signed-off-by: default avatarPeter Osterlund <petero2@telia.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent a7cbd7da
...@@ -22,6 +22,8 @@ mcdx ...@@ -22,6 +22,8 @@ mcdx
- info on improved Mitsumi CD-ROM driver. - info on improved Mitsumi CD-ROM driver.
optcd optcd
- info on the Optics Storage 8000 AT CD-ROM driver - info on the Optics Storage 8000 AT CD-ROM driver
packet-writing.txt
- Info on the CDRW packet writing module
sbpcd sbpcd
- info on the SoundBlaster/Panasonic CD-ROM interface driver. - info on the SoundBlaster/Panasonic CD-ROM interface driver.
sjcd sjcd
......
Getting started quick
---------------------
- Select packet support in the block device section and UDF support in
the file system section.
- Compile and install kernel and modules, reboot.
- You need the udftools package (pktsetup, mkudffs, cdrwtool).
Download from http://sourceforge.net/projects/linux-udf/
- Grab a new CD-RW disc and format it (assuming CD-RW is hdc, substitute
as appropriate):
# cdrwtool -d /dev/hdc -q
- Setup your writer
# pktsetup dev_name /dev/hdc
- Now you can mount /dev/pktcdvd/dev_name and copy files to it. Enjoy!
# mount /dev/pktcdvd/dev_name /cdrom -t udf -o rw,noatime
Packet writing for DVD-RW media
-------------------------------
DVD-RW discs can be written to much like CD-RW discs if they are in
the so called "restricted overwrite" mode. To put a disc in restricted
overwrite mode, run:
# dvd+rw-format /dev/hdc
You can then use the disc the same way you would use a CD-RW disc:
# pktsetup dev_name /dev/hdc
# mount /dev/pktcdvd/dev_name /cdrom -t udf -o rw,noatime
Packet writing for DVD+RW media
-------------------------------
According to the DVD+RW specification, a drive supporting DVD+RW discs
shall implement "true random writes with 2KB granularity", which means
that it should be possible to put any filesystem with a block size >=
2KB on such a disc. For example, it should be possible to do:
# mkudffs /dev/hdc
# mount /dev/hdc /cdrom -t udf -o rw,noatime
However, some drives don't follow the specification and expect the
host to perform aligned writes at 32KB boundaries. Other drives do
follow the specification, but suffer bad performance problems if the
writes are not 32KB aligned.
Both problems can be solved by using the pktcdvd driver, which always
generates aligned writes.
# pktsetup dev_name /dev/hdc
# mkudffs /dev/pktcdvd/dev_name
# mount /dev/pktcdvd/dev_name /cdrom -t udf -o rw,noatime
Notes
-----
- CD-RW media can usually not be overwritten more than about 1000
times, so to avoid unnecessary wear on the media, you should always
use the noatime mount option.
- Defect management (ie automatic remapping of bad sectors) has not
been implemented yet, so you are likely to get at least some
filesystem corruption if the disc wears out.
- Since the pktcdvd driver makes the disc appear as a regular block
device with a 2KB block size, you can put any filesystem you like on
the disc. For example, run:
# /sbin/mke2fs /dev/pktcdvd/dev_name
to create an ext2 filesystem on the disc.
Links
-----
See http://fy.chalmers.se/~appro/linux/DVD+RW/ for more information
about DVD writing.
...@@ -356,6 +356,39 @@ config LBD ...@@ -356,6 +356,39 @@ config LBD
your machine, or if you want to have a raid or loopback device your machine, or if you want to have a raid or loopback device
bigger than 2TB. Otherwise say N. bigger than 2TB. Otherwise say N.
config CDROM_PKTCDVD
tristate "Packet writing on CD/DVD media"
help
If you have a CDROM drive that supports packet writing, say Y to
include preliminary support. It should work with any MMC/Mt Fuji
compliant ATAPI or SCSI drive, which is just about any newer CD
writer.
Currently only writing to CD-RW, DVD-RW and DVD+RW discs is possible.
DVD-RW disks must be in restricted overwrite mode.
To compile this driver as a module, choose M here: the
module will be called pktcdvd.
config CDROM_PKTCDVD_BUFFERS
int "Free buffers for data gathering"
depends on CDROM_PKTCDVD
default "8"
help
This controls the maximum number of active concurrent packets. More
concurrent packets can increase write performance, but also require
more memory. Each concurrent packet will require approximately 64Kb
of non-swappable kernel memory, memory which will be allocated at
pktsetup time.
config CDROM_PKTCDVD_WCACHE
bool "Enable write caching"
depends on CDROM_PKTCDVD
help
If enabled, write caching will be set for the CD-R/W device. For now
this option is dangerous unless the CD-RW media is known good, as we
don't do deferred write error handling yet.
source "drivers/s390/block/Kconfig" source "drivers/s390/block/Kconfig"
endmenu endmenu
...@@ -35,6 +35,7 @@ obj-$(CONFIG_BLK_DEV_XD) += xd.o ...@@ -35,6 +35,7 @@ obj-$(CONFIG_BLK_DEV_XD) += xd.o
obj-$(CONFIG_BLK_CPQ_DA) += cpqarray.o obj-$(CONFIG_BLK_CPQ_DA) += cpqarray.o
obj-$(CONFIG_BLK_CPQ_CISS_DA) += cciss.o obj-$(CONFIG_BLK_CPQ_CISS_DA) += cciss.o
obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o obj-$(CONFIG_BLK_DEV_DAC960) += DAC960.o
obj-$(CONFIG_CDROM_PKTCDVD) += pktcdvd.o
obj-$(CONFIG_BLK_DEV_UMEM) += umem.o obj-$(CONFIG_BLK_DEV_UMEM) += umem.o
obj-$(CONFIG_BLK_DEV_NBD) += nbd.o obj-$(CONFIG_BLK_DEV_NBD) += nbd.o
......
This diff is collapsed.
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
obj-$(CONFIG_BLK_DEV_IDECD) += cdrom.o obj-$(CONFIG_BLK_DEV_IDECD) += cdrom.o
obj-$(CONFIG_BLK_DEV_SR) += cdrom.o obj-$(CONFIG_BLK_DEV_SR) += cdrom.o
obj-$(CONFIG_PARIDE_PCD) += cdrom.o obj-$(CONFIG_PARIDE_PCD) += cdrom.o
obj-$(CONFIG_CDROM_PKTCDVD) += cdrom.o
obj-$(CONFIG_AZTCD) += aztcd.o obj-$(CONFIG_AZTCD) += aztcd.o
obj-$(CONFIG_CDU31A) += cdu31a.o cdrom.o obj-$(CONFIG_CDU31A) += cdu31a.o cdrom.o
......
...@@ -2001,7 +2001,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block) ...@@ -2001,7 +2001,7 @@ ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, sector_t block)
} }
CDROM_CONFIG_FLAGS(drive)->seeking = 0; CDROM_CONFIG_FLAGS(drive)->seeking = 0;
} }
if (IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) { if ((rq_data_dir(rq) == READ) && IDE_LARGE_SEEK(info->last_block, block, IDECD_SEEK_THRESHOLD) && drive->dsc_overlap) {
action = cdrom_start_seek(drive, block); action = cdrom_start_seek(drive, block);
} else { } else {
if (rq_data_dir(rq) == READ) if (rq_data_dir(rq) == READ)
...@@ -2962,8 +2962,10 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive) ...@@ -2962,8 +2962,10 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
CDROM_CONFIG_FLAGS(drive)->no_eject = 0; CDROM_CONFIG_FLAGS(drive)->no_eject = 0;
if (cap.cd_r_write) if (cap.cd_r_write)
CDROM_CONFIG_FLAGS(drive)->cd_r = 1; CDROM_CONFIG_FLAGS(drive)->cd_r = 1;
if (cap.cd_rw_write) if (cap.cd_rw_write) {
CDROM_CONFIG_FLAGS(drive)->cd_rw = 1; CDROM_CONFIG_FLAGS(drive)->cd_rw = 1;
CDROM_CONFIG_FLAGS(drive)->ram = 1;
}
if (cap.test_write) if (cap.test_write)
CDROM_CONFIG_FLAGS(drive)->test_write = 1; CDROM_CONFIG_FLAGS(drive)->test_write = 1;
if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom) if (cap.dvd_ram_read || cap.dvd_r_read || cap.dvd_rom)
......
...@@ -876,10 +876,10 @@ static void get_capabilities(struct scsi_cd *cd) ...@@ -876,10 +876,10 @@ static void get_capabilities(struct scsi_cd *cd)
cd->cdi.mask |= CDC_CLOSE_TRAY; */ cd->cdi.mask |= CDC_CLOSE_TRAY; */
/* /*
* if DVD-RAM of MRW-W, we are randomly writeable * if DVD-RAM, MRW-W or CD-RW, we are randomly writable
*/ */
if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) != if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) !=
(CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) { (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) {
cd->device->writeable = 1; cd->device->writeable = 1;
} }
......
...@@ -115,6 +115,7 @@ ...@@ -115,6 +115,7 @@
#include <linux/random.h> #include <linux/random.h>
#include <linux/filter.h> #include <linux/filter.h>
#include <linux/msdos_fs.h> #include <linux/msdos_fs.h>
#include <linux/pktcdvd.h>
#include <linux/hiddev.h> #include <linux/hiddev.h>
......
...@@ -499,6 +499,7 @@ struct cdrom_generic_command ...@@ -499,6 +499,7 @@ struct cdrom_generic_command
#define GPMODE_VENDOR_PAGE 0x00 #define GPMODE_VENDOR_PAGE 0x00
#define GPMODE_R_W_ERROR_PAGE 0x01 #define GPMODE_R_W_ERROR_PAGE 0x01
#define GPMODE_WRITE_PARMS_PAGE 0x05 #define GPMODE_WRITE_PARMS_PAGE 0x05
#define GPMODE_WCACHING_PAGE 0x08
#define GPMODE_AUDIO_CTL_PAGE 0x0e #define GPMODE_AUDIO_CTL_PAGE 0x0e
#define GPMODE_POWER_PAGE 0x1a #define GPMODE_POWER_PAGE 0x1a
#define GPMODE_FAULT_FAIL_PAGE 0x1c #define GPMODE_FAULT_FAIL_PAGE 0x1c
......
...@@ -382,6 +382,8 @@ COMPATIBLE_IOCTL(CDROMREADALL) ...@@ -382,6 +382,8 @@ COMPATIBLE_IOCTL(CDROMREADALL)
COMPATIBLE_IOCTL(DVD_READ_STRUCT) COMPATIBLE_IOCTL(DVD_READ_STRUCT)
COMPATIBLE_IOCTL(DVD_WRITE_STRUCT) COMPATIBLE_IOCTL(DVD_WRITE_STRUCT)
COMPATIBLE_IOCTL(DVD_AUTH) COMPATIBLE_IOCTL(DVD_AUTH)
/* pktcdvd */
COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
/* Big L */ /* Big L */
ULONG_IOCTL(LOOP_SET_FD) ULONG_IOCTL(LOOP_SET_FD)
ULONG_IOCTL(LOOP_CHANGE_FD) ULONG_IOCTL(LOOP_CHANGE_FD)
......
/*
* Copyright (C) 2000 Jens Axboe <axboe@suse.de>
* Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com>
*
* May be copied or modified under the terms of the GNU General Public
* License. See linux/COPYING for more information.
*
* Packet writing layer for ATAPI and SCSI CD-R, CD-RW, DVD-R, and
* DVD-RW devices.
*
*/
#ifndef __PKTCDVD_H
#define __PKTCDVD_H
#include <linux/types.h>
/*
* 1 for normal debug messages, 2 is very verbose. 0 to turn it off.
*/
#define PACKET_DEBUG 1
#define MAX_WRITERS 8
#define PKT_RB_POOL_SIZE 512
/*
* How long we should hold a non-full packet before starting data gathering.
*/
#define PACKET_WAIT_TIME (HZ * 5 / 1000)
/*
* use drive write caching -- we need deferred error handling to be
* able to sucessfully recover with this option (drive will return good
* status as soon as the cdb is validated).
*/
#if defined(CONFIG_CDROM_PKTCDVD_WCACHE)
#define USE_WCACHING 1
#else
#define USE_WCACHING 0
#endif
/*
* No user-servicable parts beyond this point ->
*/
/*
* device types
*/
#define PACKET_CDR 1
#define PACKET_CDRW 2
#define PACKET_DVDR 3
#define PACKET_DVDRW 4
/*
* flags
*/
#define PACKET_WRITABLE 1 /* pd is writable */
#define PACKET_NWA_VALID 2 /* next writable address valid */
#define PACKET_LRA_VALID 3 /* last recorded address valid */
#define PACKET_MERGE_SEGS 4 /* perform segment merging to keep */
/* underlying cdrom device happy */
/*
* Disc status -- from READ_DISC_INFO
*/
#define PACKET_DISC_EMPTY 0
#define PACKET_DISC_INCOMPLETE 1
#define PACKET_DISC_COMPLETE 2
#define PACKET_DISC_OTHER 3
/*
* write type, and corresponding data block type
*/
#define PACKET_MODE1 1
#define PACKET_MODE2 2
#define PACKET_BLOCK_MODE1 8
#define PACKET_BLOCK_MODE2 10
/*
* Last session/border status
*/
#define PACKET_SESSION_EMPTY 0
#define PACKET_SESSION_INCOMPLETE 1
#define PACKET_SESSION_RESERVED 2
#define PACKET_SESSION_COMPLETE 3
#define PACKET_MCN "4a656e734178626f65323030300000"
#undef PACKET_USE_LS
#define PKT_CTRL_CMD_SETUP 0
#define PKT_CTRL_CMD_TEARDOWN 1
#define PKT_CTRL_CMD_STATUS 2
struct pkt_ctrl_command {
__u32 command; /* in: Setup, teardown, status */
__u32 dev_index; /* in/out: Device index */
__u32 dev; /* in/out: Device nr for cdrw device */
__u32 pkt_dev; /* in/out: Device nr for packet device */
__u32 num_devices; /* out: Largest device index + 1 */
__u32 padding; /* Not used */
};
/*
* packet ioctls
*/
#define PACKET_IOCTL_MAGIC ('X')
#define PACKET_CTRL_CMD _IOWR(PACKET_IOCTL_MAGIC, 1, struct pkt_ctrl_command)
#ifdef __KERNEL__
#include <linux/blkdev.h>
#include <linux/completion.h>
#include <linux/cdrom.h>
struct packet_settings
{
__u8 size; /* packet size in (512 byte) sectors */
__u8 fp; /* fixed packets */
__u8 link_loss; /* the rest is specified
* as per Mt Fuji */
__u8 write_type;
__u8 track_mode;
__u8 block_mode;
};
/*
* Very crude stats for now
*/
struct packet_stats
{
unsigned long pkt_started;
unsigned long pkt_ended;
unsigned long secs_w;
unsigned long secs_rg;
unsigned long secs_r;
};
struct packet_cdrw
{
struct list_head pkt_free_list;
struct list_head pkt_active_list;
spinlock_t active_list_lock; /* Serialize access to pkt_active_list */
struct task_struct *thread;
atomic_t pending_bios;
};
/*
* Switch to high speed reading after reading this many kilobytes
* with no interspersed writes.
*/
#define HI_SPEED_SWITCH 512
struct packet_iosched
{
atomic_t attention; /* Set to non-zero when queue processing is needed */
int writing; /* Non-zero when writing, zero when reading */
spinlock_t lock; /* Protecting read/write queue manipulations */
struct bio *read_queue;
struct bio *read_queue_tail;
struct bio *write_queue;
struct bio *write_queue_tail;
int high_prio_read; /* An important read request has been queued */
int successive_reads;
};
/*
* 32 buffers of 2048 bytes
*/
#define PACKET_MAX_SIZE 32
#define PAGES_PER_PACKET (PACKET_MAX_SIZE * CD_FRAMESIZE / PAGE_SIZE)
#define PACKET_MAX_SECTORS (PACKET_MAX_SIZE * CD_FRAMESIZE >> 9)
enum packet_data_state {
PACKET_IDLE_STATE, /* Not used at the moment */
PACKET_WAITING_STATE, /* Waiting for more bios to arrive, so */
/* we don't have to do as much */
/* data gathering */
PACKET_READ_WAIT_STATE, /* Waiting for reads to fill in holes */
PACKET_WRITE_WAIT_STATE, /* Waiting for the write to complete */
PACKET_RECOVERY_STATE, /* Recover after read/write errors */
PACKET_FINISHED_STATE, /* After write has finished */
PACKET_NUM_STATES /* Number of possible states */
};
/*
* Information needed for writing a single packet
*/
struct pktcdvd_device;
struct packet_data
{
struct list_head list;
spinlock_t lock; /* Lock protecting state transitions and */
/* orig_bios list */
struct bio *orig_bios; /* Original bios passed to pkt_make_request */
struct bio *orig_bios_tail;/* that will be handled by this packet */
int write_size; /* Total size of all bios in the orig_bios */
/* list, measured in number of frames */
struct bio *w_bio; /* The bio we will send to the real CD */
/* device once we have all data for the */
/* packet we are going to write */
sector_t sector; /* First sector in this packet */
int frames; /* Number of frames in this packet */
enum packet_data_state state; /* Current state */
atomic_t run_sm; /* Incremented whenever the state */
/* machine needs to be run */
long sleep_time; /* Set this to non-zero to make the state */
/* machine run after this many jiffies. */
atomic_t io_wait; /* Number of pending IO operations */
atomic_t io_errors; /* Number of read/write errors during IO */
struct bio *r_bios[PACKET_MAX_SIZE]; /* bios to use during data gathering */
struct page *pages[PAGES_PER_PACKET];
int cache_valid; /* If non-zero, the data for the zone defined */
/* by the sector variable is completely cached */
/* in the pages[] vector. */
int id; /* ID number for debugging */
struct pktcdvd_device *pd;
};
struct pkt_rb_node {
struct rb_node rb_node;
struct bio *bio;
};
struct packet_stacked_data
{
struct bio *bio; /* Original read request bio */
struct pktcdvd_device *pd;
};
#define PSD_POOL_SIZE 64
struct pktcdvd_device
{
struct block_device *bdev; /* dev attached */
dev_t pkt_dev; /* our dev */
char name[20];
struct packet_settings settings;
struct packet_stats stats;
int refcnt; /* Open count */
int write_speed; /* current write speed, kB/s */
int read_speed; /* current read speed, kB/s */
unsigned long offset; /* start offset */
__u8 mode_offset; /* 0 / 8 */
__u8 type;
unsigned long flags;
__u16 mmc3_profile;
__u32 nwa; /* next writable address */
__u32 lra; /* last recorded address */
struct packet_cdrw cdrw;
wait_queue_head_t wqueue;
spinlock_t lock; /* Serialize access to bio_queue */
struct rb_root bio_queue; /* Work queue of bios we need to handle */
int bio_queue_size; /* Number of nodes in bio_queue */
sector_t current_sector; /* Keep track of where the elevator is */
atomic_t scan_queue; /* Set to non-zero when pkt_handle_queue */
/* needs to be run. */
mempool_t *rb_pool; /* mempool for pkt_rb_node allocations */
struct packet_iosched iosched;
struct gendisk *disk;
};
#endif /* __KERNEL__ */
#endif /* __PKTCDVD_H */
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