From owner-freebsd-current Thu Dec 7 14:18:56 2000 From owner-freebsd-current@FreeBSD.ORG Thu Dec 7 14:18:50 2000 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from digger1.defence.gov.au (digger1.defence.gov.au [203.5.217.4]) by hub.freebsd.org (Postfix) with ESMTP id E3E5E37B400 for ; Thu, 7 Dec 2000 14:18:47 -0800 (PST) Received: from dsto-ms2.dsto.defence.gov.au (dsto-ms2.dsto.defence.gov.au [131.185.2.150]) by digger1.defence.gov.au (8.10.1/8.10.1) with ESMTP id eB7MJ9Q24277 for ; Fri, 8 Dec 2000 08:49:09 +1030 (CST) Received: from muttley.dsto.defence.gov.au (unverified) by dsto-ms2.dsto.defence.gov.au (Content Technologies SMTPRS 4.1.5) with ESMTP id ; Fri, 8 Dec 2000 08:48:06 +1030 Received: from salex001.dsto.defence.gov.au (salex001.dsto.defence.gov.au [131.185.2.9]) by muttley.dsto.defence.gov.au (8.9.3/8.9.3/8.9.3.LMD.990513) with ESMTP id IAA16807; Fri, 8 Dec 2000 08:43:08 +1030 (CST) Received: from fang.dsto.defence.gov.au ([131.185.2.5]) by salex001.dsto.defence.gov.au with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id WZWR8PHQ; Fri, 8 Dec 2000 08:43:07 +1030 Received: from dsto.defence.gov.au (fuzz.dsto.defence.gov.au [131.185.75.229]) by fang.dsto.defence.gov.au (8.9.3/8.9.3/8.9.3.LMD.990513) with ESMTP id IAA20529; Fri, 8 Dec 2000 08:43:07 +1030 (CST) Sender: thyerm@dsto.defence.gov.au Message-ID: <3A300B90.F20A6120@dsto.defence.gov.au> Date: Fri, 08 Dec 2000 08:43:36 +1030 From: Matthew Thyer X-Mailer: Mozilla 4.76 [en] (X11; U; FreeBSD 5.0-CURRENT i386) X-Accept-Language: en MIME-Version: 1.0 To: "John W. De Boskey" Cc: freebsd-current@freebsd.org Subject: Re: write(2) returns error saying read only filesystem when trying to write to a partition References: <3A2EE6B8.69624B48@dsto.defence.gov.au> <20001207012231.A4194@bsdwins.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG CC: to -current as that's what I'm running. "John W. De Boskey" wrote: > > Hi, > > I can't answer your questions directly, but you might want > to checkout the sources to newfs (/usr/src/sbin/newfs/newfs.c or > http://www.FreeBSD.org/cgi/cvsweb.cgi/src/sbin/newfs/newfs.c?annotate=1.31 > line 417). > > I'll be glad to review your program if you would like. I'm not after a review, I'd like FreeBSD-CURRENT fixed. The program works on Compaq True64 UNIX v 4.0d It also works on Solaris 7 (only tested sparc). So it seems FreeBSD is broken here. > -john > jwd@FreeBSD.org > > ----- Matthew Thyer's Original Message ----- > > Attached is scrub.c used to scrub a hard disk. > > > > Examine the lines: > > > > /* if ( (fd = open("/dev/da12s1c",O_RDWR)) < 0 ) { */ > > if ( (fd = open("/mnt/foo",O_RDWR)) < 0 ) { > > > > > > If I newfs the 'a' partition of da12s1 (a is the same as 'c'), mount > > it as /mnt, touch the file foo and then run the program it works fine. > > > > If instead I open the c partition (as in the commented out line), > > the open succeeds, the lseek succeeds but the writes fail with an > > error saying read only filesystem. > > > > Why ?? > > > > I want to scrub the whole disk, not just write to a file. > > > > -- > > Matthew Thyer Phone: +61 8 8259 7249 > > Science Corporate Information Systems Fax: +61 8 8259 5537 > > Defence Science and Technology Organisation, Salisbury > > PO Box 1500 Salisbury South Australia 5108 > > > > #include > > #include > > #include > > > > #include > > #include > > > > #define BUFSIZE 8192 > > > > > > main() > > { > > /* program to write 1's and 0's to disk */ > > > > off_t result; > > long int i; > > long int nwrite; > > long int count; > > int passes; > > int fd; > > char buf0[BUFSIZE], buf1[BUFSIZE]; > > > > /* initialize write buffers */ > > > > for (i=0; i < BUFSIZE; i++) { > > buf0[i] = 0; > > buf1[i] = 1; > > } > > > > /* if ( (fd = open("/dev/da12s1c",O_RDWR)) < 0 ) { */ > > if ( (fd = open("/mnt/foo",O_RDWR)) < 0 ) { > > perror("open"); > > exit(1); > > } > > > > /* write alternating 1s and zeros to disk */ > > > > for (i = 1; i <= 5; i++) { > > > > /* rewind to start file partition */ > > if ((result = lseek(fd, 0L, SEEK_SET)) != 0) { > > perror("lseek"); > > exit(1); > > } > > count = 0L; > > do { > > > > if ( (nwrite = write(fd, buf0, BUFSIZE)) != BUFSIZE) { > > printf("wrote last %ld bytes to disk\n",nwrite); > > printf("Total bytes written were %ld bytes\n", > > BUFSIZE*count + nwrite); > > perror("write"); > > } > > else { > > ++count; > > if ( count % 1000 == 0) > > printf("overwrote %ld bytes w/ 0s\n", > > BUFSIZE*count); > > } > > > > } while ( nwrite == BUFSIZE && nwrite > 0 ); > > > > /* rewind to start file partition */ > > if ((result = lseek(fd, 0L, SEEK_SET)) != 0) { > > perror("lseek"); > > exit(1); > > } > > count = 0L; > > > > do { > > if ( (nwrite = write(fd, buf1, BUFSIZE)) != BUFSIZE) { > > printf("wrote last %ld bytes to disk\n",nwrite); > > printf("Total bytes written were %ld bytes\n", > > BUFSIZE*count + nwrite); > > perror("write"); > > } > > else { > > ++count; > > if ( count % 1000 == 0) > > printf("overwrote %ld bytes w/ 1s\n", > > BUFSIZE*count); > > } > > > > } while ( nwrite == BUFSIZE && nwrite > 0 ); > > > > printf("Pass %d complete\n",i); > > } > > printf("All passes complete\n"); > > } -- Matthew Thyer Phone: +61 8 8259 7249 Science Corporate Information Systems Fax: +61 8 8259 5537 Defence Science and Technology Organisation, Salisbury PO Box 1500 Salisbury South Australia 5108 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message