summaryrefslogtreecommitdiffstats
path: root/ffs/libffs.h
blob: 9772cac3aa78bc6c8680ec338687900b4e06615a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 *   Copyright (c) International Business Machines Corp., 2012
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program;  if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef __LIBFFS_H__
#define __LIBFFS_H__

#include <stdbool.h>
#include <stdarg.h>

#include <clib/exception.h>

#include "ffs.h"

typedef struct ffs_entry ffs_entry_t;
typedef struct ffs_hdr ffs_hdr_t;
typedef enum type ffs_type_t;

#define FFS_EXCEPTION_DATA	1024

/* ============================================================ */

/*!
 * @brief ffs I/O interface
 */
struct ffs {
    ffs_hdr_t * hdr;

    char * path;
    off_t offset;

    FILE * file;
    uint32_t count;

    void * buf;			// FILE* buffer
    uint32_t buf_count;		// multiple of hdr->block_size

    bool dirty;
};

typedef struct ffs ffs_t;

struct ffs_exception {
    int rc;
    char data[FFS_EXCEPTION_DATA];
};

typedef struct ffs_exception ffs_exception_t;

#define FFS_PARTITION_NAME		"part"

#define FFS_INFO_ERROR			0
#define FFS_INFO_MAGIC			1
#define FFS_INFO_VERSION		2
#define FFS_INFO_ENTRY_SIZE		3
#define FFS_INFO_ENTRY_COUNT		4
#define FFS_INFO_BLOCK_SIZE		5
#define FFS_INFO_BLOCK_COUNT		6
#define FFS_INFO_BUFFER_COUNT		7
#define FFS_INFO_OFFSET			8

#define FFS_CHECK_PATH			-3
#define FFS_CHECK_HEADER_MAGIC		-4
#define FFS_CHECK_HEADER_CHECKSUM	-5
#define FFS_CHECK_ENTRY_CHECKSUM	-6

#ifdef __cplusplus
extern "C" {
#endif

extern int __ffs_fcheck(FILE *, off_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_check(const char *, off_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern ffs_t * __ffs_fcreate(FILE *, off_t, uint32_t, uint32_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern ffs_t * __ffs_create(const char *, off_t, uint32_t, uint32_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern ffs_t * __ffs_fopen(FILE *, off_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern ffs_t * __ffs_open(const char *, off_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_info(ffs_t *, int, uint32_t *)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_buffer(ffs_t *, size_t)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_close(ffs_t *)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_fclose(ffs_t *)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_fsync(ffs_t *)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_list_entries(ffs_t *, const char *, bool, FILE *)
/*! @cond */ __nonnull ((1)) /*! @endcond */ ;

extern int __ffs_iterate_entries(ffs_t *, int (*)(ffs_entry_t*))
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern int __ffs_entry_find(ffs_t *, const char *, ffs_entry_t *)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern int __ffs_entry_find_parent(ffs_t *, const char *, ffs_entry_t *)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern int __ffs_entry_name(ffs_t *, ffs_entry_t *, char *, size_t)
/*! @cond */ __nonnull ((1,2,3)) /*! @endcond */ ;

extern int __ffs_entry_add(ffs_t *, const char *, off_t,
			    size_t, ffs_type_t, uint32_t)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern int __ffs_entry_delete(ffs_t *, const char *)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern int __ffs_entry_user_get(ffs_t *, const char *, uint32_t, uint32_t *)
/*! @cond */ __nonnull ((1,2,4)) /*! @endcond */ ;

extern int __ffs_entry_user_put(ffs_t *, const char *, uint32_t, uint32_t)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern ssize_t __ffs_entry_hexdump(ffs_t *, const char *, FILE *)
/*! @cond */ __nonnull ((1,2,3)) /*! @endcond */ ;

extern ssize_t __ffs_entry_truncate(ffs_t *, const char *, size_t)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

extern ssize_t __ffs_entry_read(ffs_t *, const char *, void *, off_t, size_t)
/*! @cond */ __nonnull ((1,2,3)) /*! @endcond */ ;

extern ssize_t __ffs_entry_write(ffs_t *, const char *, const void *,
				 off_t, size_t)
/*! @cond */ __nonnull ((1,2,3)) /*! @endcond */ ;

extern ssize_t __ffs_entry_copy(ffs_t *, ffs_t *, const char *)
/*! @cond */ __nonnull ((1,2,3)) /*! @endcond */ ;

extern ssize_t __ffs_entry_compare(ffs_t *, ffs_t *, const char *)
/*! @cond */ __nonnull ((1,2,3)) /*! @endcond */ ;

extern int __ffs_entry_list(ffs_t *, ffs_entry_t ** list)
/*! @cond */ __nonnull ((1,2)) /*! @endcond */ ;

#ifdef __cplusplus
}
#endif

/* ============================================================ */

#endif /* __LIBFFS_H__ */
OpenPOWER on IntegriCloud