yaffsfs.c: Fix NULL dereference in yaffs_unmount2_reldev()
[yaffs2.git] / rtems / rtems_yaffs.h
1 /*
2  * YAFFS port to RTEMS
3  *
4  * Copyright (C) 2010 Sebastien Bourdeauducq
5  * Copyright (C) 2011 Stephan Hoffmann <sho@reLinux.de>
6  * Copyright (C) 2011 embedded brains GmbH <rtems@embedded-brains.de>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  * 
12  * As a special exception, including this header in a file does not by
13  * itself cause the resulting executable application to be covered by the
14  * GNU General Public License.
15  * This exception does not however invalidate any other reasons why the
16  * executable file might be covered by the GNU Public License. In particular,
17  * the other YAFFS files are not covered by this exception, and using them
18  * in a proprietary application requires a paid license from Aleph One.
19  */
20
21 #ifndef __RTEMS_YAFFS_H
22 #define __RTEMS_YAFFS_H
23
24 #include <rtems.h>
25 #include <rtems/fs.h>
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cplusplus */
30
31 /* Must be inside the extern "C" */
32 #include "yportenv.h"
33 #include "yaffs_guts.h"
34
35 /**
36  * @defgroup rtems_yaffs YAFFS Support for RTEMS
37  *
38  *
39  * @{
40  */
41
42 #define RTEMS_FILESYSTEM_TYPE_YAFFS "yaffs"
43
44 typedef void (*rtems_yaffs_os_handler)(
45   struct yaffs_dev *dev,
46   void *os_context
47 );
48
49 /**
50  * @brief Per YAFFS file system instance context.
51  */
52 typedef struct {
53   rtems_yaffs_os_handler lock;
54   rtems_yaffs_os_handler unlock;
55   rtems_yaffs_os_handler unmount;
56
57   /**
58    * @brief The device containing the file system instance.
59    *
60    * This will be used for the st_dev field in stat().
61    */
62   dev_t dev;
63 } rtems_yaffs_os_context;
64
65 /**
66  * @brief Default per YAFFS file system instance context.
67  */
68 typedef struct {
69   rtems_yaffs_os_context os_context;
70   rtems_id semaphore_id;
71 } rtems_yaffs_default_os_context;
72
73 /**
74  * @brief Data for YAFFS mount handler.
75  *
76  * @see rtems_yaffs_mount_handler()
77  */
78 typedef struct {
79   /**
80    * @brief YAFFS device of the file system instance.
81    *
82    * The @a param field has to be completely set up.  The
83    * @a driver_context can point to arbitrary driver specific
84    * information.  The @a os_context must point to an initialized
85    * structure that begins with a rtems_yaffs_os_context structure.
86    */
87   struct yaffs_dev *dev;
88 } rtems_yaffs_mount_data;
89
90 /**
91  * @brief YAFFS mount handler.
92  *
93  * The @a data pointer must point to a completely initialized
94  * rtems_yaffs_mount_data structure.  The ownership of the YAFFS device
95  * structure changes.  This structure is now owned by the file system layer.
96  *
97  * @retval 0 Successful operation.
98  * @retval -1 An error occurred.  The @c errno indicates the error.
99  */
100 int rtems_yaffs_mount_handler(
101   rtems_filesystem_mount_table_entry_t *mt_entry,
102   const void *data
103 );
104
105 /**
106  * @brief Initializes the default per file system context @a os_context.
107  *
108  * A binary semaphore with priority inheritance will be used to ensure mutual
109  * exclusion.
110  *
111  * The umount handler will release all resources of the default context.
112  *
113  * @retval 0 Successful operation.
114  * @retval -1 An error occurred.  The @c errno indicates the error.
115  */
116 int rtems_yaffs_initialize_default_os_context(
117   rtems_yaffs_default_os_context *os_context
118 );
119
120 /** @} */
121
122 #ifdef __cplusplus
123 }
124 #endif /* __cplusplus */
125
126 #endif /* __RTEMS_YAFFS_H */