On 11/8/06, Rafael J. Wysocki <[EMAIL PROTECTED]> wrote:
> Hi,
>
> On Wednesday, 8 November 2006 18:58, Luca wrote:
> > I've been working on a small program to find the first valid block of a
> > swapfile. If I understand it correctly we need the first contiguos cluster
> > of blocks (not counting the header) which is at least PAGE_SIZE big and
> > the starting block must be page aligned.
> > The block number must then be converted in an offset from the start of
> > the device and the number must be expressed in multiple of PAGE_SIZE.
> >
> > This is what I've come up with ;)
>
> It doesn't look bad, but you shouldn't skip the header, actually.  The header
> is what we need. ;-)

Oh, right.. you print the offset of page_no == 0. Hum, I think I don't
understand the layout of a swapfile then; reading swapfile.c I see
that even the header should be a PAGE_SIZE continuous block, but I
have test cases where the header is not contiguous on disk (ext2,
1024b per block, with artificial fragmentation) - which is why I
thought that first-page-after-header was needed.

> > #include <stdio.h>
> > #include <string.h>
> > #include <fcntl.h>
> > #include <unistd.h>
> > #include <sys/ioctl.h>
> > #include <sys/types.h>
> > #include <sys/stat.h>
> > #include <linux/fs.h>
> > #include <errno.h>
> >
> > #define SWAP_SIG "SWAPSPACE2"
> >
> > int main(int argc, char **argv) {
> >       int block, last_block, first_block;
>
> Don't use int here, please.  loff_t will do, or long long int verbatim.

The ioctl expects a 32bit integer, giving us a limit of 4TB.

> >       if (size < page_size) {
> >               fprintf(stderr, "Invalid swapfile\n");
>
> I'd say a bit more in the message (why it's invalid, in our opinion).

Well, it's "invalid" as in "mkswap won't create a swapfile with no
usable pages and kernel won't use it either".

Thanks for the review ;)

Luca

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Suspend-devel mailing list
Suspend-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/suspend-devel

Reply via email to