source: mainline/uspace/lib/block/libblock.h@ 5e3eea10

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5e3eea10 was e272949, checked in by Martin Sucha <sucha14@…>, 15 years ago

Refactor direct reading of superblock

  • 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 "../../srv/vfs/vfs.h"
43#include <fibril_synch.h>
44#include <adt/hash_table.h>
45#include <adt/list.h>
46
47/*
48 * Flags that can be used with block_get().
49 */
50
51/**
52 * This macro is a symbolic value for situations where no special flags are
53 * needed.
54 */
55#define BLOCK_FLAGS_NONE 0
56
57/**
58 * When the client of block_get() intends to overwrite the current contents of
59 * the block, this flag is used to avoid the unnecessary read.
60 */
61#define BLOCK_FLAGS_NOREAD 1
62
63typedef struct block {
64 /** Mutex protecting the reference count. */
65 fibril_mutex_t lock;
66 /** Number of references to the block_t structure. */
67 unsigned refcnt;
68 /** If true, the block needs to be written back to the block device. */
69 bool dirty;
70 /** If true, the blcok does not contain valid data. */
71 bool toxic;
72 /** Readers / Writer lock protecting the contents of the block. */
73 fibril_rwlock_t contents_lock;
74 /** Handle of the device where the block resides. */
75 devmap_handle_t devmap_handle;
76 /** Logical block address */
77 aoff64_t lba;
78 /** Physical block address */
79 aoff64_t pba;
80 /** Size of the block. */
81 size_t size;
82 /** Link for placing the block into the free block list. */
83 link_t free_link;
84 /** Link for placing the block into the block hash table. */
85 link_t hash_link;
86 /** Buffer with the block data. */
87 void *data;
88} block_t;
89
90/** Caching mode */
91enum cache_mode {
92 /** Write-Through */
93 CACHE_MODE_WT,
94 /** Write-Back */
95 CACHE_MODE_WB
96};
97
98extern int block_init(devmap_handle_t, size_t);
99extern void block_fini(devmap_handle_t);
100
101extern int block_bb_read(devmap_handle_t, aoff64_t);
102extern void *block_bb_get(devmap_handle_t);
103
104extern int block_cache_init(devmap_handle_t, size_t, unsigned, enum cache_mode);
105extern int block_cache_fini(devmap_handle_t);
106
107extern int block_get(block_t **, devmap_handle_t, aoff64_t, int);
108extern int block_put(block_t *);
109
110extern int block_seqread(devmap_handle_t, size_t *, size_t *, aoff64_t *, void *,
111 size_t);
112
113extern int block_get_bsize(devmap_handle_t, size_t *);
114extern int block_get_nblocks(devmap_handle_t, aoff64_t *);
115extern int block_read_direct(devmap_handle_t, aoff64_t, size_t, void *);
116extern int block_read_bytes_direct(devmap_handle_t, aoff64_t, size_t, void *);
117extern int block_write_direct(devmap_handle_t, aoff64_t, size_t, const void *);
118
119#endif
120
121/** @}
122 */
123
Note: See TracBrowser for help on using the repository browser.