summaryrefslogtreecommitdiff
path: root/sys/kern/subr_disk.c
AgeCommit message (Collapse)Author
2011-07-26No need to byte-swap d_checksum just before setting it to zero.Kenneth R Westerback
ok matthew@
2011-07-06On several archs (e.g. hppa, sgi, macppc) readdoslabel() is called after an ↵Kenneth R Westerback
attempt to read a native label fails. Reset B_ERROR/b_error on buf to ensure any i/o failure on that first attempt is forgiven. A la the dkcsum() fix to recover from a disk error.
2011-07-06Eliminate redundant buf validation checks in xxstrategy() methods nowMatthew Dempsky
that they're implemented consistently in bounds_check_with_label(). Also, per krw's request, change bounds_check_with_label() to return 0 if the checks succeed, and change the drivers to test == -1 instead of <= 0. (Man page update to follow; intentionally omitting arch/vax/mba/hp.c from this commit because it doesn't even build currently and miod@ promises to kill it soon.) ok krw@
2011-07-05Add checks for sector-alignment and whole number of sectors toMatthew Dempsky
bounds_check_with_label() and generally cleanup the code while here. ok krw@ ("I like this a *lot*"); "i like it" tedu@
2011-06-30Refactor some common open/close/detach disk driver code intoMatthew Dempsky
subr_disk.c. For now just the MI disk drivers. ok deraadt@, krw@; jsing@ liked the approach too
2011-06-19Minor cleanup for disk_lock() and disk_unlock().Matthew Dempsky
ok deraadt@
2011-06-19Add disk_lock_nointr() as a way to acquire the disk lock without beingMatthew Dempsky
interrupted by signals. ok deraadt@
2011-06-19Kill the "lockname" argument to disk_construct().Matthew Dempsky
ok deraadt@
2011-06-03Get rid of the wlabel argument to bounds_check_with_label(). It'sMatthew Dempsky
never done anything in OpenBSD and just clutters disk drivers with silly flag handling. More cleanup to follow. ok deraadt@, millert@; no objections krw@
2011-06-01Add device_ref/device_unref calls to prevent a possible use-after-freeMatthew Dempsky
issue in disk_attach_callback. Assumes that the struct disk is part of the driver's softc, but this is always true in practice. Still other scary use-after-free races lying around here though... ok jsing@, deraadt@
2011-04-28spacesMarco Peereboom
2011-04-26Allow the root device to be identified via its disklabel UID.Joel Sing
ok deraadt@ marco@ krw@
2011-04-16Use 'CLR(<buf>->b_flags, B_READ | B_WRITE | B_DONE)' regardless ofKenneth R Westerback
what the previous IO was. Less chance of copy and paste errors. Suggested by miod@.
2011-04-15In days of yore one could arbitrarily whack buffer flags. Those daysKenneth R Westerback
are past. Use CLR() and SET() to modify necessary flags while leaving the flags used by the buffer cache in peace. Should make bufcache code much less confused about the state of the bufs used in reading/writing disklabels. Other such flag abuses no doubt await a visit. Errors in original diff found by miod@. ok beck@ deraadt@
2011-03-19Repair spoofing. We want to start at 'i', not 'j'.Kenneth R Westerback
Spotted by deraadt@.
2011-03-17Uncommitted bits. Spotted by deraadt@, who theorizes I have insuffientKenneth R Westerback
sushi level.
2011-03-14Don't confuse limiting spoofed partitions with limiting how manyKenneth R Westerback
EBRs to follow looking for the OpenBSD partition. Just stop spoofing if necessary.
2010-11-24Ensure that hw.disknames gets updated whenever a disklabel is set, sinceJoel Sing
the disklabel UID may have changed. ok krw@ deraadt@
2010-11-18Do not #include <sys/dkstat.h> if you don't need anything from it.Miod Vallat
ok krw@ deraadt@
2010-09-24Fixes before-boot umass hangs on units without media.Theo de Raadt
In disk_readlabel() if the ioctl fails don't forget to close the disk. Avoid sharing a static error buffer between a workq and mountroot since they can compete. Pass the dev_t to the workq inside one of the arguments without a malloc'd object. ok miod dlg krw
2010-09-23The only sensible argument for VOP_* calls that take a struct proc pointer isOwain Ainsworth
curproc. A bunch of callers were passing in 0 (not even NULL, 0) as this pointer, which was fine until the called vnode function tried to do something with it. Typically, this code was then copy/pasted to various parts of the tree. Accept the facts of life and switch all of these over to passing curproc for now until the argument can be removed. Discovered by stsp trying to create a softraid on top of a vnd, which crashed with a NULL deref in vndioctl. softraid bits tested by mikeb and jsing. raidframe bits tested by pea, matthieu and naddy. The rest tested by at least thib, jsing and myself. ok thib@, jsing@.
2010-09-23When a disk is attached create a workq task to read the disklabel,Joel Sing
providing the DKF_NOLABELREAD flag is not set. This provides the kernel with the actual disklabel which includes the disklabel UID. ok deraadt@ miod@ krw@
2010-09-08Introduce a disk_lookup() function which calls device_lookup(), beforeJoel Sing
verifying that the resulting device is present on the disklist. This avoids a race whereby the disk driver can be accessed as soon as the softc has been allocated, but before the disk has completed initialisation and has called disk_attach() (up until this point dk_label is still a null pointer). Cut cd(4), sd(4) and wd(4) across to disk_lookup(). All callers of disk_attach() need to be tested and cut over in due course. ok deraadt@ krw@
2010-09-08Store a struct device pointer within struct disk and populate this whenJoel Sing
disk_attach() is called by the device driver. We will be building on this shortly. ok deraadt@ krw@
2010-09-01Do not panic in parsedisk() for ``second class'' block devices (which we can'tMiod Vallat
root off), return NULL instead.
2010-08-30Add a device number to struct disk and populate it on disk attach. WhilstJoel Sing
here also expose disklist for future use. ok deraadt@ miod@
2010-08-18- fix compilation of kernel without FFS...don't ask ;-)Jasper Lievisse Adriaanse
ok jsing@
2010-06-27Factor out code used to read a disklabel. We'll be making use of this soon.Joel Sing
ok deraadt@
2010-05-03Provide a disk_map() function which attempts to map a disklabel UID to theJoel Sing
actual device. If successful, the real path is returned via mappath. Soon to be used by several other diffs. ok krw@
2010-04-28When setting a disklabel automatically generate a new UID if it does notJoel Sing
already have one. ok krw@
2010-04-25introducing a 64-bit type to the disklabel structure leads some architecturesTheo de Raadt
to pad-align the size of the structure; it grows, the disklabel ioctl's are break ABI. Change the uid to a character array. this also simplifies some other stuff ok jsing
2010-04-23Recycle unused disklabel fields in order to create a disklabel uniqueJoel Sing
identifier, allowing the disk to be identified without relying on the device name. ok deraadt@ krw@ beck@ marco@ todd@
2010-01-14fix typos in comments, no code changes;Ingo Schwarze
from Brad Tilley <brad at 16systems dot com>; ok oga@
2010-01-11Negative offset or negative size in a buf is invalid. Treat just like otherKenneth R Westerback
invalid offsets and sizes: reject the i/o. ok deraadt@ beck@
2009-08-13Replace the error strings that were being passed around with much simplerTheo de Raadt
errnos. Note that the error strings are being ignored, since we long ago decided to not spam the console, and there is no other nice way to use the errors (without changing the ioctls to pass it back) The errno is now useful, since we can pass b_error from failing IO up, and the drive can decide how to use that ok miod
2009-08-09Make dk_mmountroot use vnodes instead of d_open/d_close. This does uglyMarco Peereboom
things to softraid. ok jsing thib krw beck oga
2009-06-17Revert bufq's. this is inline with the major midlayer reverts thatThordur I. Bjornsson
have been going on. this appears to bring us back to stable state. lots of testing by oga and ariane and my self.
2009-06-14Don't mess with the bounds in the lp if *partoffp is non-NULL, since thisTheo de Raadt
indicates that writedisklabel is trying to find the location for writing the label. If the lp is messed with, an invalid checksum is written. done with miod and kettenis, lots of moaning and gnashing of teeth, etc
2009-06-05Clamp the ending bound to the size of the disk. This makes disklabel -ATheo de Raadt
still do the right thing if the MBR has a lie in it
2009-06-04Recycle four ancient fields in the disklabel structure, replacing them withTheo de Raadt
bounds information, ie. the zone of the disk that OpenBSD can use. Have each pre-disklabel parser (MBR, DPME, or per-arch MD disklabel parsers) figure out this area and pass it up to userland. Then, delete all the same disk parsing code from disklabel(8) since the kernel passes it up. Lots and lots of - signs in the disklabel(8) code. Tested on as many platforms as possible, the fallout will be repaired as time goes on. To test, use disklabel -d <drive> and validate that the bounds do not overlap any boot blocks. This same information is used by disklabel -A... OK for the concept from krw, miod, and drahn
2009-06-03add a flexible buffer queue (bufq) api, based on the never usedThordur I. Bjornsson
one by tedu@. It doesn't do anything smart yet, it just uses plain old disksort. we also keep the old method of queueing bufs since some miods have crazy MD drivers that need some love. ok beck@, art@ tested by many on many archs.
2009-06-03Add a callback specifically for softraid. If you touch this kittens willMarco Peereboom
be murdered and theo will visit with a 2x4. ok deraadt
2009-06-03remove the never used bufq_ code.Thordur I. Bjornsson
ok oga@ 'dance for me' blambert@
2009-05-15Validate the main MBR minimally; if it does not have the AA55 thingy we mustTheo de Raadt
not read garbage values as partitions... which we then put into the spoofed label... and which would lead disklabel -A to make surprising decisions. earlier versions which did too much validation tested by many
2009-05-13initialize d_npartitions to MAXPARTITIONS always; ok krwTheo de Raadt
2009-05-03Discovering an extended MBR partition and setting 'wander' to 1Kenneth R Westerback
should not stop the spoofing process. Setting 'wander' means when we are done with this MBR, read the next one. Problem noted and fix tested by Nick Guenther. ok weingart@ (I think), deraadt@
2009-03-28use a static and unique string as the disk lock name, so if we're waitingDavid Gwynne
on the disk lock we can find that code rather than wondering where "sd0" gets passed to tsleep. ok deraadt@
2009-02-09two more consistency checks for a disklabel, to prevent havoc laterOtto Moerbeek
on; prompted by Thorsten Glaser; ok miod@ krw@
2008-11-21Relax sanity check so any two-byte jmp followed by a NOP, or anyKenneth R Westerback
three-byte jmp will be acceptable as the preamble to a FAT boot sector for the purposes of spoofing an 'i' partition. Problem noted most recently by mbalmer@. Fixes mbalmer@, fkr@ and jmc@'s Nokia E71 phones. "seems silly" tedu@ "disgusting" deraadt@ "makes sense" fkr@ ok jmc@ "looks ok" weingart@
2008-08-25If partoffp is non-NULL then readdoslabel() is just looking for theKenneth R Westerback
correct address to write the passed label. Don't spoof partitions while looking for the address, as this could result in an invalid label being written out. "That looks right" deraadt@ "Looks good to me" miod@