Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
Two examples
The md driver
RAIDs
Full-disk encryption (software)
LVM
Secure deletion (TrueErase)
The md driver
File systems
mounted on top of
device mapper
virtual device
Virtual device can
Abstract multiple
devices
Perform encryption
Other things
Application
s
File System
DM
User/Kernel
Linear
Delay
Flakey
Zero
http://lxr.linux.no/#linux+v3.2/Documentation/devi
ce-mapper
Logical start
sector
#!/bin/bash
mount /dev/mapper/identity /mnt
Unloading a device
mapper
#!/bin/bash
umount /mnt
dmsetup remove identity
Unloading a device
mapper
#!/bin/bash
umount /mnt
dmsetup remove identity
Unloading a device
mapper
#!/bin/bash
umount /mnt
dmsetup remove identity
dm-linear.c
Documentation
http://lxr.linux.no/#linux+v3.2/Docum
entation/device-mapper/linear.txt
Code
http://lxr.linux.no/#linux+v3.2/drivers
/md/dm-linear.c
dm-linear.c
static struct target_type linear_target = {
.name = "linear",
.version = {1, 1, 0},
.module = THIS_MODULE,
.ctr = linear_ctr,
.dtr = linear_dtr,
.map = linear_map,
.status = linear_status,
.ioctl = linear_ioctl,
.merge = linear_merge,
.iterate_devices = linear_iterate_devices,
};
linear_map
static int linear_map(struct dm_target *ti, struct bio *bio,
union map_info *map_context)
{
struct linear_c *lc = (struct linear_c *) ti->private;
bio->bi_bdev = lc->dev->bdev;
bio->bi_sector = lc->start + (bio->bi_sector - ti->begin);
return DM_MAPIO_REMAPPED;
}
Memory Technology
Device
http://www.linux-mtd.infradead.org/
NAND Flash
Characteristics
NAND Flash
Characteristics
NAND Flash
Characteristics
Accessed by ioctls
NAND Flash
Characteristics
Data Path
Apps
Virtual file system (VFS)
File system
Ext3
Multi-device drivers
FTL
Disk
driver
Disk
driver
MTD
driver
JFFS2
MTD
driver
OS
Flash
data
data
Logical
Address
0
Physical
Address
0
OS
Flash
data
data
rando
m
Logical
Address
0
Physical
Address
0
FTL Example
INFTL
http://lxr.linux.no/linux+*/drivers/mt
d/inftlmount.c
http://lxr.linux.no/linux+*/drivers/mt
d/inftlcore.c
INFTL
INFTL Chaining
INFTL Chaining
inftlcore.c
static struct mtd_blktrans_ops inftl_tr = {
.name
= "inftl",
.major
= INFTL_MAJOR,
.part_bits
= INFTL_PARTN_BITS,
.blksize
= 512,
.getgeo
= inftl_getgeo,
.readsect
= inftl_readblock,
.writesect
= inftl_writeblock,
.add_mtd
= inftl_add_mtd,
.remove_dev
= inftl_remove_dev,
.owner
= THIS_MODULE,
};
inftl_writeblock
static int inftl_writeblock(struct mtd_blktrans_dev *mbd, unsigned long
block,
char *buffer)
{
struct INFTLrecord *inftl = (void *)mbd;
unsigned int writeEUN;
unsigned long blockofs = (block * SECTORSIZE) & (inftl->EraseSize 1);
size_t retlen;
struct inftl_oob oob;
char *p, *pend;
inftl_writeblock
/* Is block all zero? */
pend = buffer + SECTORSIZE;
for (p = buffer; p < pend && !*p; p++);
if (p < pend) {
writeEUN = INFTL_findwriteunit(inftl, block);
if (writeEUN == BLOCK_NIL) {
printk(KERN_WARNING "inftl_writeblock():cannot find"
"block to write to\n");
/*
* If we _still_ haven't got a block to use, we're screwed.
*/
return 1;
}
memset(&oob, 0xff, sizeof(struct inftl_oob));
oob.b.Status = oob.b.Status1 = SECTOR_USED;
inftl_write(inftl->mbd.mtd, (writeEUN * inftl->EraseSize) +
blockofs, SECTORSIZE, &retlen, (char *)buffer,
(char *)&oob);
inftl_writeblock
memset(&oob, 0xff, sizeof(struct inftl_oob));
oob.b.Status = oob.b.Status1 = SECTOR_USED;
inftl_write(inftl->mbd.mtd, (writeEUN * inftl->EraseSize) +
blockofs, SECTORSIZE, &retlen, (char *)buffer,
(char *)&oob);
} else {
INFTL_deleteblock(inftl, block);
}
return 0;
}