libblock.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008 Jakub Jermar
00003  * Copyright (c) 2008 Martin Decky 
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * - Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * - The name of the author may not be used to endorse or promote products
00016  *   derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00019  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00020  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00021  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00023  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00024  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00025  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00027  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00037 #ifndef LIBBLOCK_LIBBLOCK_H_
00038 #define LIBBLOCK_LIBBLOCK_H_
00039 
00040 #include <stdint.h>
00041 #include "../../srv/vfs/vfs.h"
00042 #include <fibril_synch.h>
00043 #include <adt/hash_table.h>
00044 #include <adt/list.h>
00045 
00046 /*
00047  * Flags that can be used with block_get().
00048  */
00049 
00054 #define BLOCK_FLAGS_NONE        0
00055 
00060 #define BLOCK_FLAGS_NOREAD      1
00061 
00062 typedef struct block {
00064         fibril_mutex_t lock;
00066         unsigned refcnt;
00068         bool dirty;
00070         bool toxic;
00072         fibril_rwlock_t contents_lock;
00074         devmap_handle_t devmap_handle;
00076         aoff64_t lba;
00078         aoff64_t pba;
00080         size_t size;
00082         link_t free_link;
00084         link_t hash_link;
00086         void *data;
00087 } block_t;
00088 
00090 enum cache_mode {
00092         CACHE_MODE_WT,
00094         CACHE_MODE_WB
00095 };
00096 
00097 extern int block_init(devmap_handle_t, size_t);
00098 extern void block_fini(devmap_handle_t);
00099 
00100 extern int block_bb_read(devmap_handle_t, aoff64_t);
00101 extern void *block_bb_get(devmap_handle_t);
00102 
00103 extern int block_cache_init(devmap_handle_t, size_t, unsigned, enum cache_mode);
00104 extern int block_cache_fini(devmap_handle_t);
00105 
00106 extern int block_get(block_t **, devmap_handle_t, aoff64_t, int);
00107 extern int block_put(block_t *);
00108 
00109 extern int block_seqread(devmap_handle_t, size_t *, size_t *, aoff64_t *, void *,
00110     size_t);
00111 
00112 extern int block_get_bsize(devmap_handle_t, size_t *);
00113 extern int block_get_nblocks(devmap_handle_t, aoff64_t *);
00114 extern int block_read_direct(devmap_handle_t, aoff64_t, size_t, void *);
00115 extern int block_write_direct(devmap_handle_t, aoff64_t, size_t, const void *);
00116 
00117 #endif
00118 

Generated on Thu Jun 2 07:45:45 2011 for HelenOS/USB by  doxygen 1.4.7