From dds@istlab.dmst.aueb.gr  Thu Oct 10 05:47:50 2002
Return-Path: <dds@istlab.dmst.aueb.gr>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1B62237B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Oct 2002 05:47:50 -0700 (PDT)
Received: from istlab.dmst.aueb.gr (istlab.dmst.aueb.gr [195.251.253.207])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 1F8B543E8A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Oct 2002 05:47:49 -0700 (PDT)
	(envelope-from dds@istlab.dmst.aueb.gr)
Received: from istlab.dmst.aueb.gr (localhost [127.0.0.1])
	by istlab.dmst.aueb.gr (8.12.3/8.11.6) with ESMTP id g9ACljxt030893
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Oct 2002 15:47:45 +0300 (EEST)
	(envelope-from dds@istlab.dmst.aueb.gr)
Received: (from dds@localhost)
	by istlab.dmst.aueb.gr (8.12.3/8.12.3/Submit) id g9ACliFJ030892;
	Thu, 10 Oct 2002 15:47:44 +0300 (EEST)
	(envelope-from dds)
Message-Id: <200210101247.g9ACliFJ030892@istlab.dmst.aueb.gr>
Date: Thu, 10 Oct 2002 15:47:44 +0300 (EEST)
From: "Diomidis D. Spinellis" <dds@istlab.dmst.aueb.gr>
Reply-To: "Diomidis D. Spinellis" <dds@istlab.dmst.aueb.gr>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Undocumented behavior: write(2) over a disk label returns EROFS
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         43891
>Category:       docs
>Synopsis:       Undocumented behavior: write(2) over a disk label returns EROFS
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    schweikh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 10 05:50:02 PDT 2002
>Closed-Date:    Sun Oct 13 10:43:22 PDT 2002
>Last-Modified:  Sun Oct 13 10:43:22 PDT 2002
>Originator:     Diomidis D. Spinellis
>Release:        FreeBSD 4.6.2-RELEASE-p2 i386
>Organization:
AUEB
>Environment:
System: FreeBSD istlab.dmst.aueb.gr 4.6.2-RELEASE-p2 FreeBSD 4.6.2-RELEASE-p2 #5: Wed Sep 18 12:07:12 EEST 2002 root@istlab.dmst.aueb.gr:/usr/obj/usr/src/sys/ISTLAB i386
>Description:
Writing over a disk label results in write(2) returning EROFS.
The EROFS return value is not documented in the write(2) man page.
The disklabel(8) man page claims that the driver does silently ignore
writing over disk labels.
>How-To-Repeat:
strace dd if=/dev/zero of=/dev/ad0
If you feel nervous abour running the above command (I certainly would,
it can trash the entire disk) search for EROFS in
src/sys/kern/subr_diskslice.c
>Fix:
I propose fixing the documentation to conform to the code;
silently ignoring requests is bad behaviour.  Apply the following
fix:
*** disklabel.8	2002/10/10 11:52:48	1.1
--- disklabel.8	2002/10/10 11:58:07
***************
*** 311,317 ****
  .Ss Enabling and disabling writing to the disk label area
  .Pp
  By default, it is not possible to write to the disk label area at the beginning
! of a disk.  The disk driver silently ignores any attempt to do so.  If you need
  to write to this area (for example, to obliterate the label), use the form
  .Pp
  .Nm
--- 311,320 ----
  .Ss Enabling and disabling writing to the disk label area
  .Pp
  By default, it is not possible to write to the disk label area at the beginning
! of a disk.  The disk driver arranges for
! .Xr write 2
! and similar system calls
! to return EROFS on any attempt to do so.  If you need
  to write to this area (for example, to obliterate the label), use the form
  .Pp
  .Nm
*** write.2	2002/10/10 11:52:48	1.1
--- write.2	2002/10/10 12:08:09
***************
*** 171,176 ****
--- 171,183 ----
  .It Bq Er EAGAIN
  The file was marked for non-blocking I/O,
  and no data could be written immediately.
+ .It Bq Er EROFS
+ An attempt was made to write over a disk label area at the beginning
+ of a disk.
+ Use
+ .Xr disklabel 8
+ .Fl W
+ to enable writing on the disk label area.
  .El
  .Pp
  In addition,

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-doc->schweikh 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Thu Oct 10 10:22:50 PDT 2002 
Responsible-Changed-Why:  
I'll take care of my fellow IOCCC winner's problem report :-) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43891 
State-Changed-From-To: open->patched 
State-Changed-By: schweikh 
State-Changed-When: Thu Oct 10 12:16:25 PDT 2002 
State-Changed-Why:  
Committed to -current with a slight modification, s/disk/slice/. 
MFC in 3 days. Thanks Diomidis! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43891 
State-Changed-From-To: patched->closed 
State-Changed-By: schweikh 
State-Changed-When: Sun Oct 13 10:42:27 PDT 2002 
State-Changed-Why:  
MFC committed to RELENG_4. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43891 
>Unformatted:
