source: mainline/uspace/lib/block/libblock.h@ 4d94002d

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4d94002d was 15f3c3f, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Rename devmap to loc, devfs to locfs.

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2008 Martin Decky
4 * Copyright (c) 2011 Martin Sucha
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
31/** @addtogroup libblock
32 * @{
33 */
34/**
35 * @file
36 */
37
38#ifndef LIBBLOCK_LIBBLOCK_H_
39#define LIBBLOCK_LIBBLOCK_H_
40
41#include <stdint.h>
42#include <async.h>
43#include "../../srv/vfs/vfs.h"
44#include <fibril_synch.h>
45#include <adt/hash_table.h>
46#include <adt/list.h>
47
48/*
49 * Flags that can be used with block_get().
50 */
51
52/**
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
64typedef struct block {
65 /** Mutex protecting the reference count. */
66 fibril_mutex_t lock;
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. */
70 bool dirty;
71 /** If true, the blcok does not contain valid data. */
72 bool toxic;
73 /** Readers / Writer lock protecting the contents of the block. */
74 fibril_rwlock_t contents_lock;
75 /** Service ID of service providing the block device. */
76 service_id_t service_id;
77 /** Logical block address */
78 aoff64_t lba;
79 /** Physical block address */
80 aoff64_t pba;
81 /** Size of the block. */
82 size_t size;
83 /** Link for placing the block into the free block list. */
84 link_t free_link;
85 /** Link for placing the block into the block hash table. */
86 link_t hash_link;
87 /** Buffer with the block data. */
88 void *data;
89} block_t;
90
91/** Caching mode */
92enum cache_mode {
93 /** Write-Through */
94 CACHE_MODE_WT,
95 /** Write-Back */
96 CACHE_MODE_WB
97};
98
99extern int block_init(exch_mgmt_t, service_id_t, size_t);
100extern void block_fini(service_id_t);
101
102extern int block_bb_read(service_id_t, aoff64_t);
103extern void *block_bb_get(service_id_t);
104
105extern int block_cache_init(service_id_t, size_t, unsigned, enum cache_mode);
106extern int block_cache_fini(service_id_t);
107
108extern int block_get(block_t **, service_id_t, aoff64_t, int);
109extern int block_put(block_t *);
110
111extern int block_seqread(service_id_t, size_t *, size_t *, aoff64_t *, void *,
112 size_t);
113
114extern int block_get_bsize(service_id_t, size_t *);
115extern int block_get_nblocks(service_id_t, aoff64_t *);
116extern int block_read_direct(service_id_t, aoff64_t, size_t, void *);
117extern int block_read_bytes_direct(service_id_t, aoff64_t, size_t, void *);
118extern int block_write_direct(service_id_t, aoff64_t, size_t, const void *);
119
120#endif
121
122/** @}
123 */
124
Note: See TracBrowser for help on using the repository browser.