AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
blkcache.h File Reference
#include <core/system.h>

Go to the source code of this file.

Typedefs

typedef ssize_t(*) blkcache_io(void *owner, uint64_t sector, size_t count, void *buf)

Functions

ssize_t blkcache_read (void *owner, uint64_t sector, size_t count, void *buf, uint64_t nsectors, blkcache_io read)
 Reads sectors of a disk through the cache.
ssize_t blkcache_write (void *owner, uint64_t sector, size_t count, void *buf, blkcache_io write)
 Writes sectors of a disk through the cache: they stay dirty in it until it is flushed.
int blkcache_flush (void)
 Writes every dirty block of the cache to its disk.

Typedef Documentation

◆ blkcache_io

typedef ssize_t(*) blkcache_io(void *owner, uint64_t sector, size_t count, void *buf)

Definition at line 10 of file blkcache.h.

Function Documentation

◆ blkcache_flush()

int blkcache_flush ( void )

Writes every dirty block of the cache to its disk.

Returns
0, or a negative errno if a write failed

Definition at line 309 of file blkcache.c.

References blkcache_flush(), blks, CACHE_BLOCKS, blk::dirty, dirty, flush_block(), full_dirty(), lookup(), blk::nr, blk::owner, RUN_MAX, and blk::write.

Referenced by blkcache_flush(), blkcache_write(), flush_old(), and kdev_sync().

◆ blkcache_read()

ssize_t blkcache_read ( void * owner,
uint64_t sector,
size_t count,
void * buf,
uint64_t nsectors,
blkcache_io read )

Reads sectors of a disk through the cache.

The sectors the cache doesn't have are read with read, and cached.

Parameters
ownerthe disk (the driver's, for its sectors)
sectorthe first sector, absolute on the disk
counthow many sectors
bufwhere to put them
nsectorsthe disk's size in sectors, or 0 if it isn't known
readhow the driver reads sectors
Returns
0, or a negative errno (-EIO past the disk's end)

Definition at line 367 of file blkcache.c.

References blk_data(), BLK_SECTORS, BLK_SIZE, blkcache_read(), block_new(), flush_old(), kfree(), kmalloc(), lookup(), memcpy(), MIN, blk::nr, overlap(), blk::owner, prefault(), RUN_MAX, sector_mask(), SECTOR_SIZE, touch(), blk::valid, and writes.

Referenced by ata_read(), and blkcache_read().

◆ blkcache_write()

ssize_t blkcache_write ( void * owner,
uint64_t sector,
size_t count,
void * buf,
blkcache_io write )

Writes sectors of a disk through the cache: they stay dirty in it until it is flushed.

If the cache has no room even after flushing, they go straight to the disk.

Parameters
ownerthe disk (the driver's, for its sectors)
sectorthe first sector, absolute on the disk
counthow many sectors
bufthe sectors' data
writehow the driver writes sectors
Returns
0, or a negative errno

Definition at line 484 of file blkcache.c.

References blk_data(), BLK_SECTORS, blkcache_flush(), blkcache_write(), block_new(), dirty, DIRTY_MAX, flush_old(), kfree(), kmalloc(), lookup(), make_dirty(), memcpy(), blk::nr, overlap(), blk::owner, prefault(), sector_mask(), SECTOR_SIZE, touch(), blk::valid, blk::write, and writes.

Referenced by ata_write(), and blkcache_write().