2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 #include <asm/byteorder.h>
21 typedef int (*volume_probe_t
)(void);
22 typedef int (*volume_init_t
)(struct volume
*v
);
23 typedef void (*volume_stop_t
)(struct volume
*v
);
24 typedef struct volume
*(*volume_find_t
)(char *name
);
25 typedef int (*volume_identify_t
)(struct volume
*v
);
26 typedef int (*volume_read_t
)(struct volume
*v
, void *buf
, int offset
, int length
);
27 typedef int (*volume_write_t
)(struct volume
*v
, void *buf
, int offset
, int length
);
28 typedef int (*volume_erase_t
)(struct volume
*v
, int start
, int len
);
29 typedef int (*volume_erase_all_t
)(struct volume
*v
);
32 struct list_head list
;
38 volume_identify_t identify
;
42 volume_erase_all_t erase_all
;
62 extern struct volume
* volume_find(char *name
);
63 extern void volume_register_driver(struct driver
*drv
);
65 static inline int volume_init(struct volume
*v
)
67 if (v
&& v
->drv
->init
)
68 return v
->drv
->init(v
);
72 static inline int volume_identify(struct volume
*v
)
74 if (v
&& v
->drv
->identify
)
75 return v
->drv
->identify(v
);
79 static inline int volume_erase(struct volume
*v
, int offset
, int len
)
81 if (v
&& v
->drv
->erase
)
82 return v
->drv
->erase(v
, offset
, len
);
86 static inline int volume_erase_all(struct volume
*v
)
88 if (v
&& v
->drv
->erase_all
)
89 return v
->drv
->erase_all(v
);
93 static inline int volume_read(struct volume
*v
, void *buf
, int offset
, int length
)
95 if (v
&& v
->drv
->read
)
96 return v
->drv
->read(v
, buf
, offset
, length
);
100 static inline int volume_write(struct volume
*v
, void *buf
, int offset
, int length
)
102 if (v
&& v
->drv
->write
)
103 return v
->drv
->write(v
, buf
, offset
, length
);
108 static void __attribute__((constructor)) \
109 drv_register_##x(void) { \
110 volume_register_driver(&x); \