source: mainline/uspace/lib/block/block.h@ 75751db6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 75751db6 was 3abf70c7, checked in by Jiri Svoboda <jiri@…>, 11 years ago

libblock is not the best place to define SCSI structures.

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[fc840d9]1/*
2 * Copyright (c) 2008 Jakub Jermar
[15f3c3f]3 * Copyright (c) 2008 Martin Decky
4 * Copyright (c) 2011 Martin Sucha
[fc840d9]5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
[b7adc22]31/** @addtogroup libblock
[fc840d9]32 * @{
[b7adc22]33 */
[fc840d9]34/**
35 * @file
36 */
37
38#ifndef LIBBLOCK_LIBBLOCK_H_
[1e4cada]39#define LIBBLOCK_LIBBLOCK_H_
[fc840d9]40
41#include <stdint.h>
[79ae36dd]42#include <async.h>
[1e4cada]43#include <fibril_synch.h>
[d9c8c81]44#include <adt/hash_table.h>
45#include <adt/list.h>
[b7adc22]46#include <loc.h>
[fc840d9]47
[1d8cdb1]48/*
49 * Flags that can be used with block_get().
50 */
51
[b7adc22]52/**
[1d8cdb1]53 * This macro is a symbolic value for situations where no special flags are
54 * needed.
55 */
56#define BLOCK_FLAGS_NONE 0
57
58/**
59 * When the client of block_get() intends to overwrite the current contents of
60 * the block, this flag is used to avoid the unnecessary read.
61 */
62#define BLOCK_FLAGS_NOREAD 1
63
[fc840d9]64typedef struct block {
[4e1b57d]65 /** Mutex protecting the reference count. */
66 fibril_mutex_t lock;
[5cf723b]67 /** Number of references to the block_t structure. */
68 unsigned refcnt;
69 /** If true, the block needs to be written back to the block device. */
[fc840d9]70 bool dirty;
[cd688d9]71 /** If true, the blcok does not contain valid data. */
72 bool toxic;
[5cf723b]73 /** Readers / Writer lock protecting the contents of the block. */
[4e1b57d]74 fibril_rwlock_t contents_lock;
[15f3c3f]75 /** Service ID of service providing the block device. */
76 service_id_t service_id;
[f092718]77 /** Logical block address */
[a6ba0c9]78 aoff64_t lba;
[f092718]79 /** Physical block address */
80 aoff64_t pba;
[5cf723b]81 /** Size of the block. */
82 size_t size;
[3d35386]83 /** Number of write failures. */
84 int write_failures;
[5cf723b]85 /** Link for placing the block into the free block list. */
86 link_t free_link;
87 /** Link for placing the block into the block hash table. */
[062d900]88 ht_link_t hash_link;
[5cf723b]89 /** Buffer with the block data. */
90 void *data;
[fc840d9]91} block_t;
92
[1fbe064b]93/** Caching mode */
94enum cache_mode {
95 /** Write-Through */
96 CACHE_MODE_WT,
97 /** Write-Back */
98 CACHE_MODE_WB
99};
100
[15f3c3f]101extern int block_init(exch_mgmt_t, service_id_t, size_t);
102extern void block_fini(service_id_t);
[6284978]103
[15f3c3f]104extern int block_bb_read(service_id_t, aoff64_t);
105extern void *block_bb_get(service_id_t);
[fc840d9]106
[15f3c3f]107extern int block_cache_init(service_id_t, size_t, unsigned, enum cache_mode);
108extern int block_cache_fini(service_id_t);
[f1ba5d6]109
[15f3c3f]110extern int block_get(block_t **, service_id_t, aoff64_t, int);
[c91f2d1b]111extern int block_put(block_t *);
[fc840d9]112
[4802dd7]113extern int block_seqread(service_id_t, void *, size_t *, size_t *, aoff64_t *,
114 void *, size_t);
[fc840d9]115
[15f3c3f]116extern int block_get_bsize(service_id_t, size_t *);
117extern int block_get_nblocks(service_id_t, aoff64_t *);
[3abf70c7]118extern int block_read_toc(service_id_t, uint8_t, void *, size_t);
[15f3c3f]119extern int block_read_direct(service_id_t, aoff64_t, size_t, void *);
120extern int block_read_bytes_direct(service_id_t, aoff64_t, size_t, void *);
121extern int block_write_direct(service_id_t, aoff64_t, size_t, const void *);
[00b1d20e]122
[fc840d9]123#endif
124
125/** @}
126 */
Note: See TracBrowser for help on using the repository browser.