Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 08 Dec 2000 08:43:36 +1030
From:      Matthew Thyer <Matthew.Thyer@dsto.defence.gov.au>
To:        "John W. De Boskey" <jwd@bsdwins.com>
Cc:        freebsd-current@freebsd.org
Subject:   Re: write(2) returns error saying read only filesystem when trying  to write to a partition
Message-ID:  <3A300B90.F20A6120@dsto.defence.gov.au>
References:  <3A2EE6B8.69624B48@dsto.defence.gov.au> <20001207012231.A4194@bsdwins.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/types.h>
> > #include <sys/stat.h>
> > #include <fcntl.h>
> >
> > #include <sys/uio.h>
> > #include <unistd.h>
> >
> > #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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A300B90.F20A6120>