* blklist.c
@ 2006-04-30 13:18 Yoshinori K. Okuji
2006-04-30 15:49 ` blklist.c Marco Gerards
0 siblings, 1 reply; 4+ messages in thread
From: Yoshinori K. Okuji @ 2006-04-30 13:18 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 371 bytes --]
Here is a simple utility to display a block list based on the knowledge of
Linux's but not of GRUB's. I wrote this to aid the debugging of a filesystem.
The output format is similar to GRUB's block list, but not completely
identical (because GRUB always treats sectors instead of filesystem blocks).
If you think this is useful, I can put this code into GRUB.
Okuji
[-- Attachment #2: blklist.c --]
[-- Type: text/x-csrc, Size: 2968 bytes --]
/* blklist.c - display block lists of files */
/*
* Copyright (C) 2006 Yoshinori Okuji <okuji@enbug.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#ifdef __linux__
# include <sys/ioctl.h>
# define FIBMAP _IO(0x00,1)
# define FIGETBSZ _IO(0x00,2)
#else /* ! __linux__ */
# error "This code is specific to Linux at the moment."
#endif /* ! __linux__ */
struct block
{
int start;
int len;
struct block *next;
};
static void
show_blklist (const char *filename)
{
int fd;
int blocksize;
struct stat st;
int i;
struct block head = { 0, 0, 0 };
struct block *current = &head;
fd = open (filename, O_RDONLY);
if (fd < 0)
{
printf ("cannot open %s\n", filename);
goto fail;
}
if (ioctl (fd, FIGETBSZ, &blocksize) < 0)
{
printf ("cannot get the block size of %s\n", filename);
goto fail;
}
if (fstat (fd, &st) < 0)
{
printf ("cannot get the size of %s\n", filename);
goto fail;
}
for (i = 0; i < (st.st_size + blocksize - 1) / blocksize; i++)
{
int block = i;
if (ioctl (fd, FIBMAP, &block) < 0)
{
printf ("cannot get the block %d of %s\n", i, filename);
goto fail;
}
if (current->start + current->len == block)
current->len++;
else
{
struct block *b;
b = malloc (sizeof (*b));
if (! b)
{
printf ("cannot allocate memory\n");
goto fail;
}
b->start = block;
b->len = 1;
b->next = 0;
current->next = b;
current = b;
}
}
printf ("%s: ", filename);
for (current = head.next; current; current = current->next)
{
printf ("%d+%d", current->start, current->len);
if (current->next)
printf (",");
}
printf (" (block size = %d)\n", blocksize);
fail:
for (current = head.next; current; current = head.next)
{
head.next = current->next;
free (current);
}
if (fd >= 0)
close (fd);
}
int
main (int argc, char *argv[])
{
if (argc < 2)
{
printf ("Display the list of blocks for given files\n");
printf ("Usage: blklist FILE...\n");
return 1;
}
while (*++argv)
show_blklist (*argv);
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: blklist.c
2006-04-30 13:18 blklist.c Yoshinori K. Okuji
@ 2006-04-30 15:49 ` Marco Gerards
2006-04-30 16:31 ` blklist.c Yoshinori K. Okuji
0 siblings, 1 reply; 4+ messages in thread
From: Marco Gerards @ 2006-04-30 15:49 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> Here is a simple utility to display a block list based on the knowledge of
> Linux's but not of GRUB's. I wrote this to aid the debugging of a filesystem.
> The output format is similar to GRUB's block list, but not completely
> identical (because GRUB always treats sectors instead of filesystem blocks).
> If you think this is useful, I can put this code into GRUB.
Perhaps we can turn it into a test program for automated testing?
--
Marco
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: blklist.c
2006-04-30 15:49 ` blklist.c Marco Gerards
@ 2006-04-30 16:31 ` Yoshinori K. Okuji
2006-04-30 16:36 ` blklist.c Marco Gerards
0 siblings, 1 reply; 4+ messages in thread
From: Yoshinori K. Okuji @ 2006-04-30 16:31 UTC (permalink / raw)
To: The development of GRUB 2
On Sunday 30 April 2006 17:49, Marco Gerards wrote:
> "Yoshinori K. Okuji" <okuji@enbug.org> writes:
> > Here is a simple utility to display a block list based on the knowledge
> > of Linux's but not of GRUB's. I wrote this to aid the debugging of a
> > filesystem. The output format is similar to GRUB's block list, but not
> > completely identical (because GRUB always treats sectors instead of
> > filesystem blocks). If you think this is useful, I can put this code into
> > GRUB.
>
> Perhaps we can turn it into a test program for automated testing?
I'd appreciate if you can do it. It would be significantly useful to have
regression tests, in particular for filesystems.
Okuji
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: blklist.c
2006-04-30 16:31 ` blklist.c Yoshinori K. Okuji
@ 2006-04-30 16:36 ` Marco Gerards
0 siblings, 0 replies; 4+ messages in thread
From: Marco Gerards @ 2006-04-30 16:36 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Sunday 30 April 2006 17:49, Marco Gerards wrote:
>> "Yoshinori K. Okuji" <okuji@enbug.org> writes:
>> > Here is a simple utility to display a block list based on the knowledge
>> > of Linux's but not of GRUB's. I wrote this to aid the debugging of a
>> > filesystem. The output format is similar to GRUB's block list, but not
>> > completely identical (because GRUB always treats sectors instead of
>> > filesystem blocks). If you think this is useful, I can put this code into
>> > GRUB.
>>
>> Perhaps we can turn it into a test program for automated testing?
>
> I'd appreciate if you can do it. It would be significantly useful to have
> regression tests, in particular for filesystems.
I completely agree. Perhaps I even created a task for this already?
But I can not make any promise for the short term. My todo list is
huge already.
--
Marco
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-04-30 16:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-30 13:18 blklist.c Yoshinori K. Okuji
2006-04-30 15:49 ` blklist.c Marco Gerards
2006-04-30 16:31 ` blklist.c Yoshinori K. Okuji
2006-04-30 16:36 ` blklist.c Marco Gerards
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.