-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathramdisk.c
52 lines (45 loc) · 1.56 KB
/
ramdisk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*=====================================================================================*/
// A request handling which behaves as a ramdisk
//
// This part is not used by the project, but can be in case
// I need to compare how is Linux behaving
char *data = NULL;
static void ramdisk_transfer(sector_t sector,
unsigned long nsect, char *buffer, int write) {
unsigned long offset = sector * 512;
unsigned long nbytes = nsect * 512;
if ((offset + nbytes) > nb_sectors * 512) {
printk (KERN_NOTICE "SaWa: Beyond-end write (%ld %ld)\n", offset, nbytes);
return;
}
printk(KERN_INFO "SaWa: Request for %lu sectors starting at sector #%lu (write=%d)\n", nsect, sector, write);
if (write) {
dump_mem(buffer, 32);
memcpy(data + offset, buffer, nbytes);
}
else
memcpy(buffer, data + offset, nbytes);
}
static void ramdisk_request(struct request_queue *q) {
struct request *req;
req = blk_fetch_request(q);
while (req != NULL) {
// blk_fs_request() was removed in 2.6.36 - many thanks to
// Christian Paro for the heads up and fix...
//if (!blk_fs_request(req)) {
if (req == NULL || (req->cmd_type != REQ_TYPE_FS)) {
printk (KERN_NOTICE "Skip non-CMD request\n");
__blk_end_request_all(req, -EIO);
continue;
}
ramdisk_transfer(blk_rq_pos(req), blk_rq_cur_sectors(req),
req->buffer, rq_data_dir(req));
if ( ! __blk_end_request_cur(req, 0) ) {
req = blk_fetch_request(q);
}
else {
// printk(KERN_INFO "Same request?\n");
}
// printk(KERN_INFO "Request ended. New request = %px\n", req);
}
}