6 #include <routix/device.h>
7 #include <routix/task.h>
8 #include <routix/system.h>
12 typedef enum block_state
{ READ_LOCKED
, WRITE_LOCKED
, SYNCRONIZING
, UNLOCKED
, DIRTY
} block_state
;
14 typedef struct block_cache_t
{
21 unsigned int lock_count
; /// \var cantidad de locks sobre el bloque
23 // Info para el driver
24 operation_t operation
;
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
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)
51 #define BLOCK_SIZE 512
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) )