From owner-freebsd-fs Sun Aug 12 4:33:11 2001 Delivered-To: freebsd-fs@freebsd.org Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by hub.freebsd.org (Postfix) with SMTP id 506F537B403 for ; Sun, 12 Aug 2001 04:33:04 -0700 (PDT) (envelope-from iedowse@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 12 Aug 2001 12:33:03 +0100 (BST) To: Igor Shmukler Cc: freebsd-fs@freebsd.org Subject: Re: another FFS question In-Reply-To: Your message of "Fri, 10 Aug 2001 18:31:22 EDT." <00bb01c121ec$307d48c0$7b02a8c0@tp600e> Date: Sun, 12 Aug 2001 12:32:56 +0100 From: Ian Dowse Message-ID: <200108121233.aa95748@salmon.maths.tcd.ie> Sender: owner-freebsd-fs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org In message <00bb01c121ec$307d48c0$7b02a8c0@tp600e>, Igor Shmukler writes: >However dump of showed that 17th (starting count from 1st partition = >sector) and following two sectors >are 0x00 filled. You obviously didn't compile this with compiler warnings turned on (gcc -Wall) or you would have spotted the bugs yourself: fs.c: In function `main': fs.c:20: warning: assignment makes pointer from integer without a cast fs.c:24: warning: implicit declaration of function `pread' fs.c:29: warning: control reaches end of non-void function `man open' will tell you that open() returns an int, not a FILE *. `man pread' will tell you that `#include ' is required to get the correct prototype for pread(). This is the omission that actually stops the program from working as intended, because the `offset' argument to pread() is a 64-bit type, but without a prototype the compiler assumes an int (usually 32-bit). The functions open(), pread() and malloc() are documented to return values that indicate whether or not the operation was successful. If you ignore these errors, the program just carries on blindly, so any results may be meaningless - what happens if you accidentally mistype the device path pased to open() for example? There are useful functions such as perror() available to help print meaningful error messages, e.g.: fd = open(path, O_RDONLY); if (fd < 0) { perror(path); exit(1); } sbbuf = malloc(SBSIZE); if (sbbuf == NULL) { perror("malloc"); exit(1); } nread = pread(fd, sbbuf, SBSIZE, SBOFF); if (nread != SBSIZE) { if (nread < 0) perror("pread"); else fprintf(stderr, "SBSIZE at SBOFF: short read\n"); exit(1); } See also `man err' for some handy but less portable error printing functions. Ian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-fs" in the body of the message