Using Scatterlist

This is a discussion on Using Scatterlist within the C Programming forums, part of the General Programming Boards category; Hello, I am trying to implement some encryption in the kernel space. I need to use crypto api, which requires ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    7

    Using Scatterlist

    Hello,

    I am trying to implement some encryption in the kernel space. I need to use crypto api, which requires the use of scatterlist. I need to simple encrypt a string of characters and the store the encrypted string. I think I have most of my code right, but I seem to have a problem when extracting the string back from the scatterlist. Lets say I do the following:

    Code:
            char p[4] = "abc"; 
            char *t;
    	dst.page = virt_to_page(p);
    	dst.offset = offset_in_page(p);
    	dst.length = 3;
    
    	t = kmap (dst.page + dst.offset);
    	*(t+3) = '\0';
     	printk("%s\n",t);
    I am expecting my code to print "abc" but it doesn't. It prints some junk. How can I get a pointer to my string back once I put it into the scatterlist?

    Thank you for any suggestions you might have.

    -George

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    As far as I can tell, kmap() returns a page-address, which means an address with the low 12 bits set to zero. So you would need to calculate the offset-within-page to to the new virtual address.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    7
    Thanks, I think I managed to figure it out. I think skatterlist only acts as a pointer, it doesn't store any data, and I thought it would store it. All should be sorted out.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21