From owner-freebsd-questions Wed Dec 6 18:47:31 2000 From owner-freebsd-questions@FreeBSD.ORG Wed Dec 6 18:47:26 2000 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from digger1.defence.gov.au (digger1.defence.gov.au [203.5.217.4]) by hub.freebsd.org (Postfix) with ESMTP id 519EB37B401 for ; Wed, 6 Dec 2000 18:47:21 -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 eB72lbQ14769 for ; Thu, 7 Dec 2000 13:17:38 +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 for ; Thu, 7 Dec 2000 11:58:09 +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 LAA23064 for ; Thu, 7 Dec 2000 11:53:42 +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 WZWR8D1W; Thu, 7 Dec 2000 11:53:42 +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 LAA10723 for ; Thu, 7 Dec 2000 11:53:42 +1030 (CST) Sender: thyerm@dsto.defence.gov.au Message-ID: <3A2EE6B8.69624B48@dsto.defence.gov.au> Date: Thu, 07 Dec 2000 11:54:08 +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: freebsd-questions@freebsd.org Subject: write(2) returns error saying read only filesystem when trying to write to a partition Content-Type: multipart/mixed; boundary="------------12E4E8D0908F652BEE36EF01" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------12E4E8D0908F652BEE36EF01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 --------------12E4E8D0908F652BEE36EF01 Content-Type: text/plain; charset=us-ascii; name="scrub.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="scrub.c" #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"); } --------------12E4E8D0908F652BEE36EF01-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message