• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/fstools/libfstools/volume.h

  1 /*
  2  * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
  3  *
  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
  7  *
  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.
 12  */
 13 
 14 #ifndef _VOLUME_H__
 15 #define _VOLUME_H__
 16 
 17 #include <asm/byteorder.h>
 18 
 19 struct volume;
 20 
 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);
 30 
 31 struct driver {
 32         struct list_head        list;
 33         char                    *name;
 34         volume_probe_t          probe;
 35         volume_init_t           init;
 36         volume_stop_t           stop;
 37         volume_find_t           find;
 38         volume_identify_t       identify;
 39         volume_read_t           read;
 40         volume_write_t          write;
 41         volume_erase_t          erase;
 42         volume_erase_all_t      erase_all;
 43 };
 44 
 45 enum {
 46         UNKNOWN_TYPE,
 47         NANDFLASH,
 48         NORFLASH,
 49         UBIVOLUME,
 50         BLOCKDEV,
 51 };
 52 
 53 struct volume {
 54         struct driver   *drv;
 55         char            *name;
 56         char            *blk;
 57 
 58         __u64           size;
 59         __u32           block_size;
 60         int             type;
 61 };
 62 
 63 extern struct volume* volume_find(char *name);
 64 extern void volume_register_driver(struct driver *drv);
 65 
 66 static inline int volume_init(struct volume *v)
 67 {
 68         if (v && v->drv->init)
 69                 return v->drv->init(v);
 70         return -1;
 71 }
 72 
 73 static inline int volume_identify(struct volume *v)
 74 {
 75         if (v && v->drv->identify)
 76                 return v->drv->identify(v);
 77         return -1;
 78 }
 79 
 80 static inline int volume_erase(struct volume *v, int offset, int len)
 81 {
 82         if (v && v->drv->erase)
 83                 return v->drv->erase(v, offset, len);
 84         return -1;
 85 }
 86 
 87 static inline int volume_erase_all(struct volume *v)
 88 {
 89         if (v && v->drv->erase_all)
 90                 return v->drv->erase_all(v);
 91         return -1;
 92 }
 93 
 94 static inline int volume_read(struct volume *v, void *buf, int offset, int length)
 95 {
 96         if (v && v->drv->read)
 97                 return v->drv->read(v, buf, offset, length);
 98         return -1;
 99 }
100 
101 static inline int volume_write(struct volume *v, void *buf, int offset, int length)
102 {
103         if (v && v->drv->write)
104                 return v->drv->write(v, buf, offset, length);
105         return -1;
106 }
107 
108 #define DRIVER(x)                                       \
109         static void __attribute__((constructor))        \
110         drv_register_##x(void) {                        \
111                 volume_register_driver(&x);             \
112         }
113 
114 #endif
115 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt