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

This page was automatically generated by LXR 0.3.1.  •  OpenWrt