I was going through the linear.txt file of device mapper.It goes like this:-
Source:- lxr - linux/documentation/device-mapper/linear.txt
[[
34#!/usr/bin/perl -w
35# Split a device into 4M chunks and then join them together in reverse order.
36
37my $name = "reverse";
38my $extent_size = 4 * 1024 * 2;
39my $dev = $ARGV[0];
40my $table = "";
41my $count = 0;
42
43if (!defined($dev)) {
44 die("Please specify a device.\n");
45}
46
47my $dev_size = `blockdev --getsize $dev`;
48my $extents = int($dev_size / $extent_size) -
49 (($dev_size % $extent_size) ? 1 : 0);
50
51while ($extents > 0) {
52 my $this_start = $count * $extent_size;
53 $extents--;
54 $count++;
55 my $this_offset = $extents * $extent_size;
56
57 $table .= "$this_start $extent_size linear $dev $this_offset\n";
58}
59
60`echo \"$table\" | dmsetup create $name`;
61]]
Can someone please tell me why is the extent_size has such a value 4*1024*2 ?
And what value is being assinged to $extents in line 48 and 49.
print
this is a perl script, you can just add a line
49a print "dev=$dev_size, ext=$extent_size, extents=$extents\n";
to print the values you are interested in. lines 48/49 do the same as the equivalent code in C or java, only replace 'my' by 'int' and omit the '$'-s. there are not that many comments in this script, but the comment may answer some of your questions.
device mapper
I would like to clear my question
1> I m not able to figure out why the value 4*1024*2 is being assinged to $extent_size i.e. if the chunk size is 4M,
then why extent_size has this value??
2> And why there is such an assingment to $extents in line 48/49 .I mean what value is going inside $extents and how
the eveluation of the left hand side value.
I think i have made myself clear
find out
to be able to really understand the code and to find the solution next time, you have to find out yourself; i can only give you hints. here i assume everyone on this forum wants to be able to solve a simple programming task and to read and/or debug some code. you can for example print the partial results of line 48/49, what are the values of $dev_size / $extent_size, int($dev_size / $extent_size), $dev_size % $extent_size, ($dev_size % $extent_size) ? 1 : 0 for varying values of the variables?
if you assume for a moment that the numeric value of the extent size matches the comment, what unit is extent size in? what is the factor? what does the manual page for 'blockdev' say about the option --getsize ?
device mapper
shouldn't my $extent_size = 4 * 1024 * 2;
be 4 * 1024 ^2 because if we have to make chunks of 4M.
sorry if i am wrong . Plz reply
thankyou