initial commit
[pfinal.git] / Routix / include / fs / blockcache.h
blob57b6c9c844a512fb60d479b4397337e2e547bd12
1 /* block.h */
3 #ifndef __BLOCK_CACHE
4 #define __BLOCK_CACHE
6 #include <routix/device.h>
7 #include <routix/task.h>
8 #include <routix/system.h>
9 #include <sys/list.h>
11 // Cache
12 typedef enum block_state { READ_LOCKED, WRITE_LOCKED, SYNCRONIZING, UNLOCKED, DIRTY } block_state;
14 typedef struct block_cache_t {
15 device_t device;
16 word sector;
17 byte *buffer;
19 // Estado del bloque
20 block_state state;
21 unsigned int lock_count; /// \var cantidad de locks sobre el bloque
23 // Info para el driver
24 operation_t operation;
25 int ret;
27 LIST_NEW(task_struct_t) pending_process_list; // lista de procesos en espera por este bloque
28 LIST_DATA(block_cache_t) free; // puede pertenecer a una lista de bloques libres
29 LIST_DATA(block_cache_t) cached; // puede pertenecer a una lista contenida en un hash
30 LIST_DATA(block_cache_t) driver_request_list; // puede pertenecer a una lista de requests a un driver
32 } block_cache_t;
34 #define BLOCK_CACHE_DEVICE(bf) ((bf)->device)
35 #define BLOCK_CACHE_SECTOR(bf) ((bf)->sector)
36 #define BLOCK_CACHE_BUFFER(bf) ((bf)->buffer)
37 #define BLOCK_CACHE_STATE(bf) ((bf)->state)
38 #define BLOCK_CACHE_LOCKCOUNT(bf) ((bf)->lock_count)
39 #define BLOCK_CACHE_OPERATION(bf) ((bf)->operation)
40 #define BLOCK_CACHE_RETURN(bf) ((bf)->ret)
41 #define BLOCK_CACHE_PENDING_PROCESS_LIST(bf) ((bf)->pending_process_list)
43 #define DRIVER_REQUEST_DEVICE(bf) ((bf)->device)
44 #define DRIVER_REQUEST_SECTOR(bf) ((bf)->sector)
45 #define DRIVER_REQUEST_BUFFER(bf) ((bf)->buffer)
46 #define DRIVER_REQUEST_STATE(bf) ((bf)->state)
47 #define DRIVER_REQUEST_OPERATION(bf) ((bf)->operation)
48 #define DRIVER_REQUEST_RETURN(bf) ((bf)->ret)
50 // Definiciones
51 #define BLOCK_SIZE 512
54 // Funciones
55 void start_block_cache(int totalmemory);
57 block_cache_t *getrequest(device_t device);
58 inline void sendrequest(block_cache_t *block);
59 inline void endrequest(block_cache_t *block);
60 int cache_read(device_t device, word sector, unsigned int start, char *dstbuffer, unsigned int len);
62 // Funciones locales de debug
63 void show_cached_list(void);
66 #define CACHE_READ(device,sector,buffer) ( cache_read(device,sector,0,buffer,BLOCK_SIZE) )
69 #endif