pub fn write(&mut self,
                 buffer: &[u8],
                 device: u32,
                 sector: u32)
                 -> Result<usize, fs::DiskError> {
        //until!(!self.busy, process::Channel::UseDisk); // sleep until it's no longer busy
        self.busy.set(true); // "lock" it
        // should probably create some kind of sleep lock instead, and populate it with this
        // possibly playing with fire due to aliasing rules, modifying mutable state that we "own"
        let _ = self.wait();
        unsafe {
            Self::ide_cmd(device, sector);
            io::outb(0x1f7, IDE_CMD_WRITE);
        }

        // write an entire sector
        if buffer.len() >= SECTOR_SIZE {
            unsafe {
                let as_u32: &[u32] = slice_cast::cast(&buffer[0..SECTOR_SIZE]);
                io::outsl(0x1f0, as_u32);
            }
        } else {
            // or write the first N bytes of the sector and keep the latter half of the sector
            // untouched
            let mut tmp_buf = [0; SECTOR_SIZE];
            self.read(&mut tmp_buf, device, sector)?;
            for (tmp, src) in tmp_buf.iter_mut().zip(buffer.iter()) {
                *tmp = *src;
            }
            assert_eq!(tmp_buf.len(), SECTOR_SIZE);
            let as_u32: &[u32] = unsafe { slice_cast::cast(&tmp_buf[0..SECTOR_SIZE]) };
            unsafe {
                io::outsl(0x1f0, as_u32);
            }
        }
        self.wait()?;

        // notify caller how much we wrote (should just be the buffer size if <= SECTOR_SIZE)
        let n = ::core::cmp::min(SECTOR_SIZE, buffer.len());

        Ok(n)
    }
// we pass a buffer that's larger than 512:
// truncate after 512?  can't really do anything else
// shorter: read the last block, overwrite the first N bytes, writeback
we pass a buffer that's larger than 512:
truncate after 512.  can't really do anything else
shorter: read the last block, overwrite the first N bytes, writeback
we pass a buffer that ' s larger than 512 : truncate after 512 . can ' t really do anything else shorter : read the last block overwrite the first N bytes writeback
pub fn write(&mut self,
                 buffer: &[u8],
                 device: u32,
                 sector: u32)
                 -> Result<usize, fs::DiskError> {
        //until!(!self.busy, process::Channel::UseDisk); // sleep until it's no longer busy
        self.busy.set(true); // "lock" it
        // should probably create some kind of sleep lock instead, and populate it with this
        // possibly playing with fire due to aliasing rules, modifying mutable state that we "own"
        let _ = self.wait();
        unsafe {
            Self::ide_cmd(device, sector);
            io::outb(0x1f7, IDE_CMD_WRITE);
        }
        // write an entire sector
        if buffer.len() >= SECTOR_SIZE {
            unsafe {
                let as_u32: &[u32] = slice_cast::cast(&buffer[0..SECTOR_SIZE]);
                io::outsl(0x1f0, as_u32);
            }
        } else {
            // or write the first N bytes of the sector and keep the latter half of the sector
            // untouched
            let mut tmp_buf = [0; SECTOR_SIZE];
            self.read(&mut tmp_buf, device, sector)?;
            for (tmp, src) in tmp_buf.iter_mut().zip(buffer.iter()) {
                *tmp = *src;
            }
            assert_eq!(tmp_buf.len(), SECTOR_SIZE);
            let as_u32: &[u32] = unsafe { slice_cast::cast(&tmp_buf[0..SECTOR_SIZE]) };
            unsafe {
                io::outsl(0x1f0, as_u32);
            }
        }
        self.wait()?;
        // notify caller how much we wrote (should just be the buffer size if <= SECTOR_SIZE)
        let n = ::core::cmp::min(SECTOR_SIZE, buffer.len());
        Ok(n)
    }
pub fn write ( & mut self , buffer : & [ u8 ] , device : u32 , sector : u32 ) -> Result < usize , fs :: DiskError > { //until!(!self.busy, process::Channel::UseDisk); // sleep until it's no longer busy self . busy . set ( true ) ; // "lock" it // should probably create some kind of sleep lock instead, and populate it with this // possibly playing with fire due to aliasing rules, modifying mutable state that we "own" let _ = self . wait ( ) ; unsafe { Self :: ide_cmd ( device , sector ) ; io :: outb ( 0x1f7 , IDE_CMD_WRITE ) ; } // write an entire sector if buffer . len ( ) >= SECTOR_SIZE { unsafe { let as_u32 : & [ u32 ] = slice_cast :: cast ( & buffer [ 0 .. SECTOR_SIZE ] ) ; io :: outsl ( 0x1f0 , as_u32 ) ; } } else { // or write the first N bytes of the sector and keep the latter half of the sector // untouched let mut tmp_buf = [ 0 ; SECTOR_SIZE ] ; self . read ( & mut tmp_buf , device , sector ) ? ; for ( tmp , src ) in tmp_buf . iter_mut ( ) . zip ( buffer . iter ( ) ) { * tmp = * src ; } assert_eq ! ( tmp_buf len ( ) SECTOR_SIZE ) ; let as_u32 : & [ u32 ] = unsafe { slice_cast :: cast ( & tmp_buf [ 0 .. SECTOR_SIZE ] ) } ; unsafe { io :: outsl ( 0x1f0 , as_u32 ) ; } } self . wait ( ) ? ; // notify caller how much we wrote (should just be the buffer size if <= SECTOR_SIZE) let n = :: core :: cmp :: min ( SECTOR_SIZE , buffer . len ( ) ) ; Ok ( n ) }
we pass a buffer that's larger than 512:
truncate after 512?
we pass a buffer that ' s larger than 512 : truncate after 512?
&mut self
buffer
&[u8]
device
u32
sector
u32
&mut self
buffer
&[u8]
device
u32
sector
u32