From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1FaBoq-0004eR-Fr for mharc-grub-devel@gnu.org; Sun, 30 Apr 2006 09:18:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FaBoo-0004do-87 for grub-devel@gnu.org; Sun, 30 Apr 2006 09:18:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FaBon-0004dR-37 for grub-devel@gnu.org; Sun, 30 Apr 2006 09:18:33 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FaBom-0004dO-TV for grub-devel@gnu.org; Sun, 30 Apr 2006 09:18:32 -0400 Received: from [212.85.152.101] (helo=kotoba.storever.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FaBsN-0003xh-Ft for grub-devel@gnu.org; Sun, 30 Apr 2006 09:22:15 -0400 Received: from kotoba.oasis.nexedi.com (kotoba.oasis.nexedi.com [212.85.152.101]) by kotoba.storever.com (Postfix) with ESMTP id AD9013C8C7188 for ; Sun, 30 Apr 2006 16:39:35 +0200 (CEST) Received: from [??1] (localhost [127.0.0.1]) by kotoba.storever.com (Postfix) with ESMTP id CBB323C8C7187 for ; Sun, 30 Apr 2006 16:39:34 +0200 (CEST) From: "Yoshinori K. Okuji" Organization: enbug.org To: grub-devel@gnu.org Date: Sun, 30 Apr 2006 15:18:27 +0200 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_kkLVE7v7WxFdTK+" Message-Id: <200604301518.29064.okuji@enbug.org> X-Bogosity: No, tests=bogofilter, spamicity=0.485669, version=0.17.2 Subject: blklist.c X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Apr 2006 13:18:34 -0000 --Boundary-00=_kkLVE7v7WxFdTK+ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_kkLVE7v7WxFdTK+ Content-Type: text/x-csrc; charset="us-ascii"; name="blklist.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="blklist.c" /* blklist.c - display block lists of files */ /* * Copyright (C) 2006 Yoshinori Okuji * * 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 #include #include #include #include #include #ifdef __linux__ # include # 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; } --Boundary-00=_kkLVE7v7WxFdTK+--