~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to include/ocfs2/ocfs2.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-basic-offset: 8; -*-
 
2
 * vim: noexpandtab sw=8 ts=8 sts=0:
 
3
 *
 
4
 * ocfs2.h
 
5
 *
 
6
 * Filesystem object routines for the OCFS2 userspace library.
 
7
 *
 
8
 * Copyright (C) 2004 Oracle.  All rights reserved.
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or
 
11
 * modify it under the terms of the GNU General Public
 
12
 * License, version 2,  as published by the Free Software Foundation.
 
13
 * 
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
 * General Public License for more details.
 
18
 * 
 
19
 * You should have received a copy of the GNU General Public
 
20
 * License along with this program; if not, write to the
 
21
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
22
 * Boston, MA 021110-1307, USA.
 
23
 *
 
24
 * Authors: Joel Becker
 
25
 */
 
26
 
 
27
#ifndef _FILESYS_H
 
28
#define _FILESYS_H
 
29
 
 
30
#ifndef _XOPEN_SOURCE
 
31
# define _XOPEN_SOURCE 600
 
32
#endif
 
33
#ifndef _LARGEFILE64_SOURCE
 
34
# define _LARGEFILE64_SOURCE
 
35
#endif
 
36
 
 
37
#include <stdio.h>
 
38
#include <stdint.h>
 
39
#include <sys/stat.h>
 
40
#include <time.h>
 
41
#include <string.h>
 
42
#include <stddef.h>
 
43
 
 
44
#include <limits.h>
 
45
 
 
46
#include <linux/types.h>
 
47
 
 
48
#include <et/com_err.h>
 
49
 
 
50
#include <ocfs2-kernel/kernel-list.h>
 
51
#include <ocfs2-kernel/sparse_endian_types.h>
 
52
#include <ocfs2-kernel/ocfs2_fs.h>
 
53
#include <o2dlm/o2dlm.h>
 
54
#include <o2cb/o2cb.h>
 
55
#include <ocfs2/ocfs2_err.h>
 
56
#include <ocfs2/jbd2.h>
 
57
#include <ocfs2-kernel/ocfs2_lockid.h>
 
58
 
 
59
#define OCFS2_LIB_FEATURE_INCOMPAT_SUPP         (OCFS2_FEATURE_INCOMPAT_SUPP | \
 
60
                                                 OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV | \
 
61
                                                 OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG | \
 
62
                                                 OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT   | \
 
63
                                                 OCFS2_FEATURE_INCOMPAT_INLINE_DATA   | \
 
64
                                                 OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG)
 
65
 
 
66
#define OCFS2_LIB_FEATURE_RO_COMPAT_SUPP        OCFS2_FEATURE_RO_COMPAT_SUPP
 
67
 
 
68
#define OCFS2_LIB_FEATURE_COMPAT_SUPP           OCFS2_FEATURE_COMPAT_SUPP
 
69
 
 
70
#define OCFS2_LIB_ABORTED_TUNEFS_SUPP           OCFS2_TUNEFS_INPROG_REMOVE_SLOT
 
71
 
 
72
 
 
73
/* define OCFS2_SB for ocfs2-tools */
 
74
#define OCFS2_SB(sb)    (sb)
 
75
 
 
76
/* Flags for the ocfs2_filesys structure */
 
77
#define OCFS2_FLAG_RO                   0x00
 
78
#define OCFS2_FLAG_RW                   0x01
 
79
#define OCFS2_FLAG_CHANGED              0x02
 
80
#define OCFS2_FLAG_DIRTY                0x04
 
81
#define OCFS2_FLAG_SWAP_BYTES           0x08
 
82
#define OCFS2_FLAG_BUFFERED             0x10
 
83
#define OCFS2_FLAG_NO_REV_CHECK         0x20    /* Do not check the OCFS
 
84
                                                   vol_header structure
 
85
                                                   for revision info */
 
86
#define OCFS2_FLAG_HEARTBEAT_DEV_OK     0x40
 
87
#define OCFS2_FLAG_STRICT_COMPAT_CHECK  0x80
 
88
#define OCFS2_FLAG_IMAGE_FILE         0x0100
 
89
 
 
90
/* Return flags for the directory iterator functions */
 
91
#define OCFS2_DIRENT_CHANGED    0x01
 
92
#define OCFS2_DIRENT_ABORT      0x02
 
93
#define OCFS2_DIRENT_ERROR      0x04
 
94
 
 
95
/* Directory iterator flags */
 
96
#define OCFS2_DIRENT_FLAG_INCLUDE_EMPTY         0x01
 
97
#define OCFS2_DIRENT_FLAG_INCLUDE_REMOVED       0x02
 
98
#define OCFS2_DIRENT_FLAG_EXCLUDE_DOTS          0x04
 
99
#define OCFS2_DIRENT_FLAG_INCLUDE_TRAILER       0x08
 
100
 
 
101
/* Return flags for the chain iterator functions */
 
102
#define OCFS2_CHAIN_CHANGED     0x01
 
103
#define OCFS2_CHAIN_ABORT       0x02
 
104
#define OCFS2_CHAIN_ERROR       0x04
 
105
 
 
106
/* Directory constants */
 
107
#define OCFS2_DIRENT_DOT_FILE           1
 
108
#define OCFS2_DIRENT_DOT_DOT_FILE       2
 
109
#define OCFS2_DIRENT_OTHER_FILE         3
 
110
#define OCFS2_DIRENT_DELETED_FILE       4
 
111
 
 
112
/* Directory scan flags */
 
113
#define OCFS2_DIR_SCAN_FLAG_EXCLUDE_DOTS        0x01
 
114
 
 
115
/* Check if mounted flags */
 
116
#define OCFS2_MF_MOUNTED                1
 
117
#define OCFS2_MF_ISROOT                 2
 
118
#define OCFS2_MF_READONLY               4
 
119
#define OCFS2_MF_SWAP                   8
 
120
#define OCFS2_MF_BUSY                   16
 
121
#define OCFS2_MF_MOUNTED_CLUSTER        32
 
122
 
 
123
/* check_heartbeats progress states */
 
124
#define OCFS2_CHB_START         1
 
125
#define OCFS2_CHB_WAITING       2
 
126
#define OCFS2_CHB_COMPLETE      3
 
127
 
 
128
typedef void (*ocfs2_chb_notify)(int state, char *progress, void *data);
 
129
 
 
130
typedef struct _ocfs2_filesys ocfs2_filesys;
 
131
typedef struct _ocfs2_cached_inode ocfs2_cached_inode;
 
132
typedef struct _io_channel io_channel;
 
133
typedef struct _ocfs2_inode_scan ocfs2_inode_scan;
 
134
typedef struct _ocfs2_dir_scan ocfs2_dir_scan;
 
135
typedef struct _ocfs2_bitmap ocfs2_bitmap;
 
136
typedef struct _ocfs2_devices ocfs2_devices;
 
137
 
 
138
struct _ocfs2_filesys {
 
139
        char *fs_devname;
 
140
        uint32_t fs_flags;
 
141
        io_channel *fs_io;
 
142
        struct ocfs2_dinode *fs_super;
 
143
        struct ocfs2_dinode *fs_orig_super;
 
144
        unsigned int fs_blocksize;
 
145
        unsigned int fs_clustersize;
 
146
        uint32_t fs_clusters;
 
147
        uint64_t fs_blocks;
 
148
        uint32_t fs_umask;
 
149
        uint64_t fs_root_blkno;
 
150
        uint64_t fs_sysdir_blkno;
 
151
        uint64_t fs_first_cg_blkno;
 
152
        char uuid_str[OCFS2_VOL_UUID_LEN * 2 + 1];
 
153
 
 
154
        /* Allocators */
 
155
        ocfs2_cached_inode *fs_cluster_alloc;
 
156
        ocfs2_cached_inode **fs_inode_allocs;
 
157
        ocfs2_cached_inode *fs_system_inode_alloc;
 
158
        ocfs2_cached_inode **fs_eb_allocs;
 
159
        ocfs2_cached_inode *fs_system_eb_alloc;
 
160
 
 
161
        struct o2dlm_ctxt *fs_dlm_ctxt;
 
162
        struct ocfs2_image_state *ost;
 
163
 
 
164
        /* Reserved for the use of the calling application. */
 
165
        void *fs_private;
 
166
};
 
167
 
 
168
struct _ocfs2_cached_inode {
 
169
        struct _ocfs2_filesys *ci_fs;
 
170
        uint64_t ci_blkno;
 
171
        struct ocfs2_dinode *ci_inode;
 
172
        ocfs2_bitmap *ci_chains;
 
173
};
 
174
 
 
175
struct ocfs2_slot_data {
 
176
        int             sd_valid;
 
177
        unsigned int    sd_node_num;
 
178
};
 
179
 
 
180
struct ocfs2_slot_map_data {
 
181
        int                     md_num_slots;
 
182
        struct ocfs2_slot_data  *md_slots;
 
183
};
 
184
 
 
185
struct _ocfs2_devices {
 
186
        struct list_head list;
 
187
        char dev_name[PATH_MAX];
 
188
        uint8_t label[64];
 
189
        uint8_t uuid[16];
 
190
        int mount_flags;
 
191
        int fs_type;                    /* 0=unknown, 1=ocfs, 2=ocfs2 */
 
192
        int hb_dev;
 
193
        uint32_t maj_num;               /* major number of the device */
 
194
        uint32_t min_num;               /* minor number of the device */
 
195
        errcode_t errcode;              /* error encountered reading device */
 
196
        void *private;
 
197
        struct ocfs2_slot_map_data *map; /* Mounted nodes, must be freed */
 
198
};
 
199
 
 
200
typedef struct _ocfs2_fs_options ocfs2_fs_options;
 
201
 
 
202
struct _ocfs2_fs_options {
 
203
        uint32_t opt_compat;
 
204
        uint32_t opt_incompat;
 
205
        uint32_t opt_ro_compat;
 
206
};
 
207
 
 
208
errcode_t ocfs2_malloc(unsigned long size, void *ptr);
 
209
errcode_t ocfs2_malloc0(unsigned long size, void *ptr);
 
210
errcode_t ocfs2_free(void *ptr);
 
211
errcode_t ocfs2_realloc(unsigned long size, void *ptr);
 
212
errcode_t ocfs2_realloc0(unsigned long size, void *ptr,
 
213
                         unsigned long old_size);
 
214
errcode_t ocfs2_malloc_blocks(io_channel *channel, int num_blocks,
 
215
                              void *ptr);
 
216
errcode_t ocfs2_malloc_block(io_channel *channel, void *ptr);
 
217
 
 
218
errcode_t io_open(const char *name, int flags, io_channel **channel);
 
219
errcode_t io_close(io_channel *channel);
 
220
int io_get_error(io_channel *channel);
 
221
errcode_t io_set_blksize(io_channel *channel, int blksize);
 
222
int io_get_blksize(io_channel *channel);
 
223
int io_get_fd(io_channel *channel);
 
224
 
 
225
/* use ocfs2_read_blocks if your application might handle o2image file */
 
226
errcode_t io_read_block(io_channel *channel, int64_t blkno, int count,
 
227
                        char *data);
 
228
errcode_t io_write_block(io_channel *channel, int64_t blkno, int count,
 
229
                         const char *data);
 
230
errcode_t io_init_cache(io_channel *channel, size_t nr_blocks);
 
231
errcode_t io_init_cache_size(io_channel *channel, size_t bytes);
 
232
void io_destroy_cache(io_channel *channel);
 
233
 
 
234
errcode_t ocfs2_read_super(ocfs2_filesys *fs, uint64_t superblock, char *sb);
 
235
/* Writes the main superblock at OCFS2_SUPER_BLOCK_BLKNO */
 
236
errcode_t ocfs2_write_primary_super(ocfs2_filesys *fs);
 
237
/* Writes the primary and backups if enabled */
 
238
errcode_t ocfs2_write_super(ocfs2_filesys *fs);
 
239
 
 
240
/*
 
241
 * ocfs2_read_blocks is a wraper around io_read_block. If device is an image-
 
242
 * file it translates disk offset to image offset
 
243
 */
 
244
errcode_t ocfs2_read_blocks(ocfs2_filesys *fs, int64_t blkno, int count,
 
245
                            char *data);
 
246
int ocfs2_mount_local(ocfs2_filesys *fs);
 
247
errcode_t ocfs2_open(const char *name, int flags,
 
248
                     unsigned int superblock, unsigned int blksize,
 
249
                     ocfs2_filesys **ret_fs);
 
250
errcode_t ocfs2_flush(ocfs2_filesys *fs);
 
251
errcode_t ocfs2_close(ocfs2_filesys *fs);
 
252
void ocfs2_freefs(ocfs2_filesys *fs);
 
253
 
 
254
void ocfs2_swap_inode_from_cpu(struct ocfs2_dinode *di, size_t blocksize);
 
255
void ocfs2_swap_inode_to_cpu(struct ocfs2_dinode *di, size_t blocksize);
 
256
errcode_t ocfs2_read_inode(ocfs2_filesys *fs, uint64_t blkno,
 
257
                           char *inode_buf);
 
258
errcode_t ocfs2_write_inode(ocfs2_filesys *fs, uint64_t blkno,
 
259
                            char *inode_buf);
 
260
errcode_t ocfs2_check_directory(ocfs2_filesys *fs, uint64_t dir);
 
261
 
 
262
errcode_t ocfs2_read_cached_inode(ocfs2_filesys *fs, uint64_t blkno,
 
263
                                  ocfs2_cached_inode **ret_ci);
 
264
errcode_t ocfs2_write_cached_inode(ocfs2_filesys *fs,
 
265
                                   ocfs2_cached_inode *cinode);
 
266
errcode_t ocfs2_free_cached_inode(ocfs2_filesys *fs,
 
267
                                  ocfs2_cached_inode *cinode);
 
268
 
 
269
void ocfs2_swap_extent_list_from_cpu(struct ocfs2_extent_list *el);
 
270
void ocfs2_swap_extent_list_to_cpu(struct ocfs2_extent_list *el);
 
271
errcode_t ocfs2_extent_map_get_blocks(ocfs2_cached_inode *cinode,
 
272
                                      uint64_t v_blkno, int count,
 
273
                                      uint64_t *p_blkno,
 
274
                                      uint64_t *ret_count,
 
275
                                      uint16_t *extent_flags);
 
276
errcode_t ocfs2_get_clusters(ocfs2_cached_inode *cinode,
 
277
                             uint32_t v_cluster,
 
278
                             uint32_t *p_cluster,
 
279
                             uint32_t *num_clusters,
 
280
                             uint16_t *extent_flags);
 
281
int ocfs2_find_leaf(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
282
                    uint32_t cpos, char **leaf_buf);
 
283
int ocfs2_search_extent_list(struct ocfs2_extent_list *el, uint32_t v_cluster);
 
284
void ocfs2_swap_journal_superblock(journal_superblock_t *jsb);
 
285
errcode_t ocfs2_init_journal_superblock(ocfs2_filesys *fs, char *buf,
 
286
                                        int buflen, uint32_t jrnl_size);
 
287
errcode_t ocfs2_read_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
 
288
                                        char *jsb_buf);
 
289
errcode_t ocfs2_write_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
 
290
                                         char *jsb_buf);
 
291
errcode_t ocfs2_make_journal(ocfs2_filesys *fs, uint64_t blkno,
 
292
                             uint32_t clusters, ocfs2_fs_options *features);
 
293
errcode_t ocfs2_journal_clear_features(journal_superblock_t *jsb,
 
294
                                       ocfs2_fs_options *features);
 
295
errcode_t ocfs2_journal_set_features(journal_superblock_t *jsb,
 
296
                                     ocfs2_fs_options *features);
 
297
extern size_t ocfs2_journal_tag_bytes(journal_superblock_t *jsb);
 
298
extern uint64_t ocfs2_journal_tag_block(journal_block_tag_t *tag,
 
299
                                        size_t tag_bytes);
 
300
 
 
301
void ocfs2_swap_extent_block_to_cpu(struct ocfs2_extent_block *eb);
 
302
void ocfs2_swap_extent_block_from_cpu(struct ocfs2_extent_block *eb);
 
303
errcode_t ocfs2_read_extent_block(ocfs2_filesys *fs, uint64_t blkno,
 
304
                                  char *eb_buf);
 
305
errcode_t ocfs2_read_extent_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
 
306
                                          char *eb_buf);
 
307
errcode_t ocfs2_write_extent_block(ocfs2_filesys *fs, uint64_t blkno,
 
308
                                   char *eb_buf);
 
309
errcode_t ocfs2_swap_dir_entries_from_cpu(void *buf, uint64_t bytes);
 
310
errcode_t ocfs2_swap_dir_entries_to_cpu(void *buf, uint64_t bytes);
 
311
void ocfs2_swap_dir_trailer(struct ocfs2_dir_block_trailer *trailer);
 
312
errcode_t ocfs2_read_dir_block(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
313
                               uint64_t block, void *buf);
 
314
errcode_t ocfs2_write_dir_block(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
315
                                uint64_t block, void *buf);
 
316
unsigned int ocfs2_dir_trailer_blk_off(ocfs2_filesys *fs);
 
317
struct ocfs2_dir_block_trailer *ocfs2_dir_trailer_from_block(ocfs2_filesys *fs,
 
318
                                                             void *data);
 
319
int ocfs2_supports_dir_trailer(ocfs2_filesys *fs);
 
320
int ocfs2_dir_has_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di);
 
321
int ocfs2_skip_dir_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
322
                           struct ocfs2_dir_entry *de, unsigned long offset);
 
323
void ocfs2_init_dir_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
324
                            uint64_t blkno, void *buf);
 
325
 
 
326
errcode_t ocfs2_dir_iterate2(ocfs2_filesys *fs,
 
327
                             uint64_t dir,
 
328
                             int flags,
 
329
                             char *block_buf,
 
330
                             int (*func)(uint64_t       dir,
 
331
                                         int            entry,
 
332
                                         struct ocfs2_dir_entry *dirent,
 
333
                                         int    offset,
 
334
                                         int    blocksize,
 
335
                                         char   *buf,
 
336
                                         void   *priv_data),
 
337
                             void *priv_data);
 
338
extern errcode_t ocfs2_dir_iterate(ocfs2_filesys *fs, 
 
339
                                   uint64_t dir,
 
340
                                   int flags,
 
341
                                   char *block_buf,
 
342
                                   int (*func)(struct ocfs2_dir_entry *dirent,
 
343
                                               int      offset,
 
344
                                               int      blocksize,
 
345
                                               char     *buf,
 
346
                                               void     *priv_data),
 
347
                                   void *priv_data);
 
348
 
 
349
errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir,
 
350
                       const char *name, int namelen, char *buf,
 
351
                       uint64_t *inode);
 
352
 
 
353
errcode_t ocfs2_lookup_system_inode(ocfs2_filesys *fs, int type,
 
354
                                    int slot_num, uint64_t *blkno);
 
355
 
 
356
errcode_t ocfs2_link(ocfs2_filesys *fs, uint64_t dir, const char *name,
 
357
                     uint64_t ino, int flags);
 
358
 
 
359
errcode_t ocfs2_unlink(ocfs2_filesys *fs, uint64_t dir,
 
360
                       const char *name, uint64_t ino, int flags);
 
361
 
 
362
errcode_t ocfs2_open_inode_scan(ocfs2_filesys *fs,
 
363
                                ocfs2_inode_scan **ret_scan);
 
364
void ocfs2_close_inode_scan(ocfs2_inode_scan *scan);
 
365
errcode_t ocfs2_get_next_inode(ocfs2_inode_scan *scan,
 
366
                               uint64_t *blkno, char *inode);
 
367
 
 
368
errcode_t ocfs2_open_dir_scan(ocfs2_filesys *fs, uint64_t dir, int flags,
 
369
                              ocfs2_dir_scan **ret_scan);
 
370
void ocfs2_close_dir_scan(ocfs2_dir_scan *scan);
 
371
errcode_t ocfs2_get_next_dir_entry(ocfs2_dir_scan *scan,
 
372
                                   struct ocfs2_dir_entry *dirent);
 
373
 
 
374
errcode_t ocfs2_cluster_bitmap_new(ocfs2_filesys *fs,
 
375
                                   const char *description,
 
376
                                   ocfs2_bitmap **ret_bitmap);
 
377
errcode_t ocfs2_block_bitmap_new(ocfs2_filesys *fs,
 
378
                                 const char *description,
 
379
                                 ocfs2_bitmap **ret_bitmap);
 
380
void ocfs2_bitmap_free(ocfs2_bitmap *bitmap);
 
381
errcode_t ocfs2_bitmap_set(ocfs2_bitmap *bitmap, uint64_t bitno,
 
382
                           int *oldval);
 
383
errcode_t ocfs2_bitmap_clear(ocfs2_bitmap *bitmap, uint64_t bitno,
 
384
                             int *oldval);
 
385
errcode_t ocfs2_bitmap_test(ocfs2_bitmap *bitmap, uint64_t bitno,
 
386
                            int *val);
 
387
errcode_t ocfs2_bitmap_find_next_set(ocfs2_bitmap *bitmap,
 
388
                                     uint64_t start, uint64_t *found);
 
389
errcode_t ocfs2_bitmap_find_next_clear(ocfs2_bitmap *bitmap,
 
390
                                       uint64_t start, uint64_t *found);
 
391
errcode_t ocfs2_bitmap_read(ocfs2_bitmap *bitmap);
 
392
errcode_t ocfs2_bitmap_write(ocfs2_bitmap *bitmap);
 
393
uint64_t ocfs2_bitmap_get_set_bits(ocfs2_bitmap *bitmap);
 
394
errcode_t ocfs2_bitmap_alloc_range(ocfs2_bitmap *bitmap, uint64_t min,
 
395
                                   uint64_t len, uint64_t *first_bit,
 
396
                                   uint64_t *bits_found);
 
397
errcode_t ocfs2_bitmap_clear_range(ocfs2_bitmap *bitmap, uint64_t len, 
 
398
                                   uint64_t first_bit);
 
399
 
 
400
errcode_t ocfs2_get_device_size(const char *file, int blocksize,
 
401
                                uint64_t *retblocks);
 
402
 
 
403
errcode_t ocfs2_get_device_sectsize(const char *file, int *sectsize);
 
404
 
 
405
errcode_t ocfs2_check_if_mounted(const char *file, int *mount_flags);
 
406
errcode_t ocfs2_check_mount_point(const char *device, int *mount_flags,
 
407
                                  char *mtpt, int mtlen);
 
408
 
 
409
errcode_t ocfs2_read_whole_file(ocfs2_filesys *fs, uint64_t blkno,
 
410
                                char **buf, int *len);
 
411
 
 
412
void ocfs2_swap_disk_heartbeat_block(struct o2hb_disk_heartbeat_block *hb);
 
413
errcode_t ocfs2_check_heartbeat(char *device, int *mount_flags,
 
414
                                struct list_head *nodes_list);
 
415
 
 
416
errcode_t ocfs2_check_heartbeats(struct list_head *dev_list, int ignore_local);
 
417
 
 
418
errcode_t ocfs2_get_ocfs1_label(char *device, uint8_t *label, uint16_t label_len,
 
419
                                uint8_t *uuid, uint16_t uuid_len);
 
420
 
 
421
void ocfs2_swap_group_desc(struct ocfs2_group_desc *gd);
 
422
errcode_t ocfs2_read_group_desc(ocfs2_filesys *fs, uint64_t blkno,
 
423
                                char *gd_buf);
 
424
 
 
425
errcode_t ocfs2_write_group_desc(ocfs2_filesys *fs, uint64_t blkno,
 
426
                                 char *gd_buf);
 
427
 
 
428
errcode_t ocfs2_chain_iterate(ocfs2_filesys *fs,
 
429
                              uint64_t blkno,
 
430
                              int (*func)(ocfs2_filesys *fs,
 
431
                                          uint64_t gd_blkno,
 
432
                                          int chain_num,
 
433
                                          void *priv_data),
 
434
                              void *priv_data);
 
435
 
 
436
errcode_t ocfs2_load_chain_allocator(ocfs2_filesys *fs,
 
437
                                     ocfs2_cached_inode *cinode);
 
438
errcode_t ocfs2_write_chain_allocator(ocfs2_filesys *fs,
 
439
                                      ocfs2_cached_inode *cinode);
 
440
errcode_t ocfs2_chain_alloc(ocfs2_filesys *fs,
 
441
                            ocfs2_cached_inode *cinode,
 
442
                            uint64_t *gd_blkno,
 
443
                            uint64_t *bitno);
 
444
errcode_t ocfs2_chain_free(ocfs2_filesys *fs,
 
445
                           ocfs2_cached_inode *cinode,
 
446
                           uint64_t bitno);
 
447
errcode_t ocfs2_chain_alloc_range(ocfs2_filesys *fs,
 
448
                                  ocfs2_cached_inode *cinode,
 
449
                                  uint64_t min,
 
450
                                  uint64_t requested,
 
451
                                  uint64_t *start_bit,
 
452
                                  uint64_t *bits_found);
 
453
errcode_t ocfs2_chain_free_range(ocfs2_filesys *fs,
 
454
                                 ocfs2_cached_inode *cinode,
 
455
                                 uint64_t len,
 
456
                                 uint64_t start_bit);
 
457
errcode_t ocfs2_chain_test(ocfs2_filesys *fs,
 
458
                           ocfs2_cached_inode *cinode,
 
459
                           uint64_t bitno,
 
460
                           int *oldval);
 
461
errcode_t ocfs2_chain_force_val(ocfs2_filesys *fs,
 
462
                                ocfs2_cached_inode *cinode,
 
463
                                uint64_t blkno, 
 
464
                                int newval,
 
465
                                int *oldval);
 
466
errcode_t ocfs2_chain_add_group(ocfs2_filesys *fs,
 
467
                                ocfs2_cached_inode *cinode);
 
468
 
 
469
errcode_t ocfs2_init_dir(ocfs2_filesys *fs,
 
470
                         uint64_t dir,
 
471
                         uint64_t parent_dir);
 
472
 
 
473
errcode_t ocfs2_expand_dir(ocfs2_filesys *fs,
 
474
                           uint64_t dir);
 
475
 
 
476
errcode_t ocfs2_test_inode_allocated(ocfs2_filesys *fs, uint64_t blkno,
 
477
                                     int *is_allocated);
 
478
void ocfs2_init_group_desc(ocfs2_filesys *fs,
 
479
                           struct ocfs2_group_desc *gd,
 
480
                           uint64_t blkno, uint32_t generation,
 
481
                           uint64_t parent_inode, uint16_t bits,
 
482
                           uint16_t chain);
 
483
 
 
484
errcode_t ocfs2_new_dir_block(ocfs2_filesys *fs, uint64_t dir_ino,
 
485
                              uint64_t parent_ino, char **block);
 
486
 
 
487
errcode_t ocfs2_insert_extent(ocfs2_filesys *fs, uint64_t ino, uint32_t cpos,
 
488
                              uint64_t c_blkno, uint32_t clusters,
 
489
                              uint16_t flag);
 
490
errcode_t ocfs2_cached_inode_insert_extent(ocfs2_cached_inode *ci,
 
491
                                           uint32_t cpos, uint64_t c_blkno,
 
492
                                           uint32_t clusters, uint16_t flag);
 
493
 
 
494
void ocfs2_dinode_new_extent_list(ocfs2_filesys *fs, struct ocfs2_dinode *di);
 
495
void ocfs2_set_inode_data_inline(ocfs2_filesys *fs, struct ocfs2_dinode *di);
 
496
errcode_t ocfs2_convert_inline_data_to_extents(ocfs2_cached_inode *ci);
 
497
errcode_t ocfs2_new_inode(ocfs2_filesys *fs, uint64_t *ino, int mode);
 
498
errcode_t ocfs2_new_system_inode(ocfs2_filesys *fs, uint64_t *ino, int mode, int flags);
 
499
errcode_t ocfs2_delete_inode(ocfs2_filesys *fs, uint64_t ino);
 
500
errcode_t ocfs2_new_extent_block(ocfs2_filesys *fs, uint64_t *blkno);
 
501
errcode_t ocfs2_delete_extent_block(ocfs2_filesys *fs, uint64_t blkno);
 
502
/*
 
503
 * Allocate the blocks and insert them to the file.
 
504
 * only i_clusters of dinode will be updated accordingly, i_size not changed.
 
505
 */
 
506
errcode_t ocfs2_extend_allocation(ocfs2_filesys *fs, uint64_t ino,
 
507
                                  uint32_t new_clusters);
 
508
/* Extend the file to the new size. No clusters will be allocated. */
 
509
errcode_t ocfs2_extend_file(ocfs2_filesys *fs, uint64_t ino, uint64_t new_size);
 
510
 
 
511
int ocfs2_mark_extent_written(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 
512
                              uint32_t cpos, uint32_t len, uint64_t p_blkno);
 
513
/* Reserve spaces at "offset" with a "len" in the files. */
 
514
errcode_t ocfs2_allocate_unwritten_extents(ocfs2_filesys *fs, uint64_t ino,
 
515
                                           uint64_t offset, uint64_t len);
 
516
 
 
517
errcode_t ocfs2_truncate(ocfs2_filesys *fs, uint64_t ino, uint64_t new_i_size);
 
518
errcode_t ocfs2_zero_tail_and_truncate(ocfs2_filesys *fs,
 
519
                                       ocfs2_cached_inode *ci,
 
520
                                       uint64_t new_size,
 
521
                                       uint32_t *new_clusters);
 
522
errcode_t ocfs2_new_clusters(ocfs2_filesys *fs,
 
523
                             uint32_t min,
 
524
                             uint32_t requested,
 
525
                             uint64_t *start_blkno,
 
526
                             uint32_t *clusters_found);
 
527
errcode_t ocfs2_test_cluster_allocated(ocfs2_filesys *fs, uint32_t cpos,
 
528
                                       int *is_allocated);
 
529
errcode_t ocfs2_new_specific_cluster(ocfs2_filesys *fs, uint32_t cpos);
 
530
errcode_t ocfs2_free_clusters(ocfs2_filesys *fs,
 
531
                              uint32_t len,
 
532
                              uint64_t start_blkno);
 
533
errcode_t ocfs2_test_clusters(ocfs2_filesys *fs,
 
534
                              uint32_t len,
 
535
                              uint64_t start_blkno,
 
536
                              int test,
 
537
                              int *matches);
 
538
 
 
539
errcode_t ocfs2_lookup(ocfs2_filesys *fs, uint64_t dir, const char *name,
 
540
                       int namelen, char *buf, uint64_t *inode);
 
541
 
 
542
errcode_t ocfs2_namei(ocfs2_filesys *fs, uint64_t root, uint64_t cwd,
 
543
                      const char *name, uint64_t *inode);
 
544
 
 
545
errcode_t ocfs2_namei_follow(ocfs2_filesys *fs, uint64_t root, uint64_t cwd,
 
546
                             const char *name, uint64_t *inode);
 
547
 
 
548
errcode_t ocfs2_follow_link(ocfs2_filesys *fs, uint64_t root, uint64_t cwd,
 
549
                            uint64_t inode, uint64_t *res_inode);
 
550
 
 
551
errcode_t ocfs2_file_read(ocfs2_cached_inode *ci, void *buf, uint32_t count,
 
552
                          uint64_t offset, uint32_t *got);
 
553
 
 
554
errcode_t ocfs2_file_write(ocfs2_cached_inode *ci, void *buf, uint32_t count,
 
555
                           uint64_t offset, uint32_t *wrote);
 
556
 
 
557
errcode_t ocfs2_fill_cluster_desc(ocfs2_filesys *fs,
 
558
                                  struct o2cb_cluster_desc *desc);
 
559
errcode_t ocfs2_set_cluster_desc(ocfs2_filesys *fs,
 
560
                                 struct o2cb_cluster_desc *desc);
 
561
errcode_t ocfs2_fill_heartbeat_desc(ocfs2_filesys *fs,
 
562
                                    struct o2cb_region_desc *desc);
 
563
 
 
564
errcode_t ocfs2_lock_down_cluster(ocfs2_filesys *fs);
 
565
 
 
566
errcode_t ocfs2_release_cluster(ocfs2_filesys *fs);
 
567
 
 
568
errcode_t ocfs2_initialize_dlm(ocfs2_filesys *fs, const char *service);
 
569
 
 
570
errcode_t ocfs2_shutdown_dlm(ocfs2_filesys *fs, const char *service);
 
571
 
 
572
errcode_t ocfs2_super_lock(ocfs2_filesys *fs);
 
573
 
 
574
errcode_t ocfs2_super_unlock(ocfs2_filesys *fs);
 
575
 
 
576
errcode_t ocfs2_meta_lock(ocfs2_filesys *fs, ocfs2_cached_inode *inode,
 
577
                          enum o2dlm_lock_level level, int flags);
 
578
 
 
579
errcode_t ocfs2_meta_unlock(ocfs2_filesys *fs, ocfs2_cached_inode *ci);
 
580
 
 
581
/* Low level */
 
582
void ocfs2_swap_slot_map(struct ocfs2_slot_map *sm, int num_slots);
 
583
void ocfs2_swap_slot_map_extended(struct ocfs2_slot_map_extended *se,
 
584
                                  int num_slots);
 
585
errcode_t ocfs2_read_slot_map(ocfs2_filesys *fs,
 
586
                              int num_slots,
 
587
                              struct ocfs2_slot_map **map_ret);
 
588
errcode_t ocfs2_read_slot_map_extended(ocfs2_filesys *fs,
 
589
                                       int num_slots,
 
590
                                       struct ocfs2_slot_map_extended **map_ret);
 
591
errcode_t ocfs2_write_slot_map(ocfs2_filesys *fs,
 
592
                               int num_slots,
 
593
                               struct ocfs2_slot_map *sm);
 
594
errcode_t ocfs2_write_slot_map_extended(ocfs2_filesys *fs,
 
595
                                        int num_slots,
 
596
                                        struct ocfs2_slot_map_extended *se);
 
597
 
 
598
/* High level functions for metadata ecc */
 
599
void ocfs2_compute_meta_ecc(ocfs2_filesys *fs, void *data,
 
600
                            struct ocfs2_block_check *bc);
 
601
errcode_t ocfs2_validate_meta_ecc(ocfs2_filesys *fs, void *data,
 
602
                                  struct ocfs2_block_check *bc);
 
603
/* Low level checksum compute functions.  Use the high-level ones. */
 
604
extern void ocfs2_block_check_compute(void *data, size_t blocksize,
 
605
                                      struct ocfs2_block_check *bc);
 
606
extern errcode_t ocfs2_block_check_validate(void *data, size_t blocksize,
 
607
                                            struct ocfs2_block_check *bc);
 
608
 
 
609
/* High level */
 
610
errcode_t ocfs2_format_slot_map(ocfs2_filesys *fs);
 
611
errcode_t ocfs2_load_slot_map(ocfs2_filesys *fs,
 
612
                              struct ocfs2_slot_map_data **data_ret);
 
613
errcode_t ocfs2_store_slot_map(ocfs2_filesys *fs,
 
614
                               struct ocfs2_slot_map_data *md);
 
615
 
 
616
enum ocfs2_lock_type ocfs2_get_lock_type(char c);
 
617
 
 
618
char *ocfs2_get_lock_type_string(enum ocfs2_lock_type type);
 
619
 
 
620
errcode_t ocfs2_encode_lockres(enum ocfs2_lock_type type, uint64_t blkno,
 
621
                               uint32_t generation, uint64_t parent,
 
622
                               char *lockres);
 
623
 
 
624
errcode_t ocfs2_decode_lockres(char *lockres, enum ocfs2_lock_type *type,
 
625
                               uint64_t *blkno, uint32_t *generation,
 
626
                               uint64_t *parent);
 
627
 
 
628
errcode_t ocfs2_printable_lockres(char *lockres, char *name, int len);
 
629
 
 
630
/* write the superblock at the specific block. */
 
631
errcode_t ocfs2_write_backup_super(ocfs2_filesys *fs, uint64_t blkno);
 
632
 
 
633
/* Get the blkno according to the file system info.
 
634
 * The unused ones, depending on the volume size, are zeroed.
 
635
 * Return the length of the block array.
 
636
 */
 
637
int ocfs2_get_backup_super_offsets(ocfs2_filesys *fs,
 
638
                                   uint64_t *blocks, size_t len);
 
639
 
 
640
/* This function will get the superblock pointed to by fs and copy it to
 
641
 * the blocks. But first it will ensure all the appropriate clusters are free.
 
642
 * If not, it will error out with ENOSPC. If free, it will set bits for all
 
643
 * the clusters, zero the clusters and write the backup sb.
 
644
 * In case of updating, it will override the backup blocks with the newest
 
645
 * superblock information.
 
646
 */
 
647
errcode_t ocfs2_set_backup_super_list(ocfs2_filesys *fs,
 
648
                                      uint64_t *blocks, size_t len);
 
649
/* Conversely, this clears all the allocator bits associated with the
 
650
 * specified backup superblocks */
 
651
errcode_t ocfs2_clear_backup_super_list(ocfs2_filesys *fs,
 
652
                                        uint64_t *blocks, size_t len);
 
653
 
 
654
/* Refresh the backup superblock information */
 
655
errcode_t ocfs2_refresh_backup_supers(ocfs2_filesys *fs);
 
656
/* Refresh a specific list of backup superblocks */
 
657
errcode_t ocfs2_refresh_backup_super_list(ocfs2_filesys *fs,
 
658
                                          uint64_t *blocks, size_t len);
 
659
 
 
660
errcode_t ocfs2_read_backup_super(ocfs2_filesys *fs, int backup, char *sbbuf);
 
661
 
 
662
/* get the virtual offset of the last allocated cluster. */
 
663
errcode_t ocfs2_get_last_cluster_offset(ocfs2_filesys *fs,
 
664
                                        struct ocfs2_dinode *di,
 
665
                                        uint32_t *v_cluster);
 
666
 
 
667
/* Filesystem features */
 
668
enum ocfs2_feature_levels {
 
669
        OCFS2_FEATURE_LEVEL_DEFAULT = 0,
 
670
        OCFS2_FEATURE_LEVEL_MAX_COMPAT,
 
671
        OCFS2_FEATURE_LEVEL_MAX_FEATURES,
 
672
};
 
673
 
 
674
errcode_t ocfs2_snprint_feature_flags(char *str, size_t size,
 
675
                                      ocfs2_fs_options *flags);
 
676
errcode_t ocfs2_snprint_tunefs_flags(char *str, size_t size, uint16_t flags);
 
677
errcode_t ocfs2_parse_feature(const char *opts,
 
678
                              ocfs2_fs_options *feature_flags,
 
679
                              ocfs2_fs_options *reverse_flags);
 
680
 
 
681
errcode_t ocfs2_parse_feature_level(const char *typestr,
 
682
                                    enum ocfs2_feature_levels *level);
 
683
 
 
684
errcode_t ocfs2_merge_feature_flags_with_level(ocfs2_fs_options *dest,
 
685
                                               int level,
 
686
                                               ocfs2_fs_options *feature_set,
 
687
                                               ocfs2_fs_options *reverse_set);
 
688
 
 
689
/*
 
690
 * Get a callback with each feature in feature_set in order.  This will
 
691
 * calculate the dependencies of each feature in feature_set, then call func
 
692
 * once per feature, with only that feature passed to func.
 
693
 */
 
694
void ocfs2_feature_foreach(ocfs2_fs_options *feature_set,
 
695
                           int (*func)(ocfs2_fs_options *feature,
 
696
                                       void *user_data),
 
697
                           void *user_data);
 
698
/* The reverse function.  It will call the features in reverse order. */
 
699
void ocfs2_feature_reverse_foreach(ocfs2_fs_options *reverse_set,
 
700
                                   int (*func)(ocfs2_fs_options *feature,
 
701
                                               void *user_data),
 
702
                                   void *user_data);
 
703
 
 
704
 
 
705
/* These are deprecated names - don't use them */
 
706
int ocfs2_get_backup_super_offset(ocfs2_filesys *fs,
 
707
                                  uint64_t *blocks, size_t len);
 
708
errcode_t ocfs2_refresh_backup_super(ocfs2_filesys *fs,
 
709
                                     uint64_t *blocks, size_t len);
 
710
errcode_t ocfs2_set_backup_super(ocfs2_filesys *fs,
 
711
                                 uint64_t *blocks, size_t len);
 
712
 
 
713
 
 
714
 
 
715
/* 
 
716
 * ${foo}_to_${bar} is a floor function.  blocks_to_clusters will
 
717
 * returns the cluster that contains a block, not the number of clusters
 
718
 * that hold a given number of blocks.
 
719
 *
 
720
 * ${foo}_in_${bar} is a ceiling function.  clusters_in_blocks will give
 
721
 * the number of clusters needed to hold a given number of blocks.
 
722
 *
 
723
 * These functions return UINTxx_MAX when they overflow, but UINTxx_MAX
 
724
 * cannot be used to check overflow.  UINTxx_MAX is a valid value in much
 
725
 * of ocfs2.  The caller is responsible for preventing overflow before
 
726
 * using these functions.
 
727
 */
 
728
 
 
729
static inline uint64_t ocfs2_clusters_to_blocks(ocfs2_filesys *fs,
 
730
                                                uint32_t clusters)
 
731
{
 
732
        int c_to_b_bits =
 
733
                OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits -
 
734
                OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
735
 
 
736
        return (uint64_t)clusters << c_to_b_bits;
 
737
}
 
738
 
 
739
static inline uint32_t ocfs2_blocks_to_clusters(ocfs2_filesys *fs,
 
740
                                                uint64_t blocks)
 
741
{
 
742
        int b_to_c_bits =
 
743
                OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits -
 
744
                OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
745
        uint64_t ret = blocks >> b_to_c_bits;
 
746
 
 
747
        if (ret > UINT32_MAX)
 
748
                ret = UINT32_MAX;
 
749
 
 
750
        return (uint32_t)ret;
 
751
}
 
752
 
 
753
static inline uint64_t ocfs2_clusters_to_bytes(ocfs2_filesys *fs,
 
754
                                               uint32_t clusters)
 
755
{
 
756
        uint64_t ret = clusters;
 
757
 
 
758
        ret = ret << OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
 
759
        if (ret < clusters)
 
760
                ret = UINT64_MAX;
 
761
 
 
762
        return ret;
 
763
}
 
764
 
 
765
static inline uint32_t ocfs2_bytes_to_clusters(ocfs2_filesys *fs,
 
766
                                               uint64_t bytes)
 
767
{
 
768
        uint64_t ret =
 
769
                bytes >> OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
 
770
 
 
771
        if (ret > UINT32_MAX)
 
772
                ret = UINT32_MAX;
 
773
 
 
774
        return (uint32_t)ret;
 
775
}
 
776
 
 
777
static inline uint64_t ocfs2_blocks_to_bytes(ocfs2_filesys *fs,
 
778
                                             uint64_t blocks)
 
779
{
 
780
        uint64_t ret =
 
781
                blocks << OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
782
 
 
783
        if (ret < blocks)
 
784
                ret = UINT64_MAX;
 
785
 
 
786
        return ret;
 
787
}
 
788
 
 
789
static inline uint64_t ocfs2_bytes_to_blocks(ocfs2_filesys *fs,
 
790
                                             uint64_t bytes)
 
791
{
 
792
        return bytes >> OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
793
}
 
794
 
 
795
static inline uint32_t ocfs2_clusters_in_blocks(ocfs2_filesys *fs, 
 
796
                                                uint64_t blocks)
 
797
{
 
798
        int c_to_b_bits = OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits -
 
799
                          OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
800
        uint64_t ret = blocks + ((1 << c_to_b_bits) - 1); 
 
801
 
 
802
        if (ret < blocks) /* deal with wrapping */
 
803
                ret = UINT64_MAX;
 
804
 
 
805
        ret = ret >> c_to_b_bits;
 
806
        if (ret > UINT32_MAX)
 
807
                ret = UINT32_MAX;
 
808
 
 
809
        return (uint32_t)ret;
 
810
}
 
811
 
 
812
static inline uint32_t ocfs2_clusters_in_bytes(ocfs2_filesys *fs,
 
813
                                               uint64_t bytes)
 
814
{
 
815
        uint64_t ret = bytes + fs->fs_clustersize - 1;
 
816
 
 
817
        if (ret < bytes) /* deal with wrapping */
 
818
                ret = UINT64_MAX;
 
819
 
 
820
        ret = ret >> OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
 
821
        if (ret > UINT32_MAX)
 
822
                ret = UINT32_MAX;
 
823
 
 
824
        return (uint32_t)ret;
 
825
}
 
826
 
 
827
static inline uint64_t ocfs2_blocks_in_bytes(ocfs2_filesys *fs,
 
828
                                             uint64_t bytes)
 
829
{
 
830
        uint64_t ret = bytes + fs->fs_blocksize - 1;
 
831
 
 
832
        if (ret < bytes) /* deal with wrapping */
 
833
                return UINT64_MAX;
 
834
 
 
835
        return ret >> OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
 
836
}
 
837
 
 
838
 
 
839
/* given a cluster offset, calculate which block group it belongs to
 
840
 * and return that block offset. */
 
841
static inline uint64_t ocfs2_which_cluster_group(ocfs2_filesys *fs,
 
842
                                                 uint16_t cpg,
 
843
                                                 uint32_t cluster)
 
844
{
 
845
        struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
 
846
        uint32_t group_no;
 
847
 
 
848
        group_no = cluster / cpg;
 
849
        if (!group_no)
 
850
                return sb->s_first_cluster_group;
 
851
        return ocfs2_clusters_to_blocks(fs, group_no * cpg);
 
852
}
 
853
 
 
854
static inline int ocfs2_block_out_of_range(ocfs2_filesys *fs, uint64_t block)
 
855
{
 
856
        return (block < OCFS2_SUPER_BLOCK_BLKNO) || (block > fs->fs_blocks);
 
857
}
 
858
 
 
859
struct ocfs2_cluster_group_sizes {
 
860
        uint16_t        cgs_cpg;
 
861
        uint16_t        cgs_tail_group_bits;
 
862
        uint32_t        cgs_cluster_groups;
 
863
};
 
864
static inline void ocfs2_calc_cluster_groups(uint64_t clusters, 
 
865
                                             uint64_t blocksize,
 
866
                                     struct ocfs2_cluster_group_sizes *cgs)
 
867
{
 
868
        uint16_t max_bits = 8 * ocfs2_group_bitmap_size(blocksize);
 
869
 
 
870
        cgs->cgs_cpg = max_bits;
 
871
        if (max_bits > clusters)
 
872
                cgs->cgs_cpg = clusters;
 
873
 
 
874
        cgs->cgs_cluster_groups = (clusters + cgs->cgs_cpg - 1) / 
 
875
                                  cgs->cgs_cpg;
 
876
 
 
877
        cgs->cgs_tail_group_bits = clusters % cgs->cgs_cpg;
 
878
        if (cgs->cgs_tail_group_bits == 0)
 
879
                cgs->cgs_tail_group_bits = cgs->cgs_cpg;
 
880
}
 
881
 
 
882
/*
 
883
 * This is only valid for leaf nodes, which are the only ones that can
 
884
 * have empty extents anyway.
 
885
 */
 
886
static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec)
 
887
{
 
888
        return !rec->e_leaf_clusters;
 
889
}
 
890
 
 
891
/*
 
892
 * Helper function to look at the # of clusters in an extent record.
 
893
 */
 
894
static inline uint32_t ocfs2_rec_clusters(uint16_t tree_depth,
 
895
                                          struct ocfs2_extent_rec *rec)
 
896
{
 
897
        /*
 
898
         * Cluster count in extent records is slightly different
 
899
         * between interior nodes and leaf nodes. This is to support
 
900
         * unwritten extents which need a flags field in leaf node
 
901
         * records, thus shrinking the available space for a clusters
 
902
         * field.
 
903
         */
 
904
        if (tree_depth)
 
905
                return rec->e_int_clusters;
 
906
        else
 
907
                return rec->e_leaf_clusters;
 
908
}
 
909
 
 
910
static inline void ocfs2_set_rec_clusters(uint16_t tree_depth,
 
911
                                          struct ocfs2_extent_rec *rec,
 
912
                                          uint32_t clusters)
 
913
{
 
914
        if (tree_depth)
 
915
                rec->e_int_clusters = clusters;
 
916
        else
 
917
                rec->e_leaf_clusters = clusters;
 
918
}
 
919
 
 
920
static inline int ocfs2_sparse_alloc(struct ocfs2_super_block *osb)
 
921
{
 
922
        if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC)
 
923
                return 1;
 
924
        return 0;
 
925
}
 
926
 
 
927
static inline int ocfs2_userspace_stack(struct ocfs2_super_block *osb)
 
928
{
 
929
        if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK)
 
930
                return 1;
 
931
        return 0;
 
932
}
 
933
 
 
934
static inline int ocfs2_writes_unwritten_extents(struct ocfs2_super_block *osb)
 
935
{
 
936
        /*
 
937
         * Support for sparse files is a pre-requisite
 
938
         */
 
939
        if (!ocfs2_sparse_alloc(osb))
 
940
                return 0;
 
941
 
 
942
        if (osb->s_feature_ro_compat & OCFS2_FEATURE_RO_COMPAT_UNWRITTEN)
 
943
                return 1;
 
944
        return 0;
 
945
}
 
946
 
 
947
static inline int ocfs2_uses_extended_slot_map(struct ocfs2_super_block *osb)
 
948
{
 
949
        if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP)
 
950
                return 1;
 
951
        return 0;
 
952
}
 
953
 
 
954
static inline int ocfs2_support_inline_data(struct ocfs2_super_block *osb)
 
955
{
 
956
        if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_INLINE_DATA)
 
957
                return 1;
 
958
        return 0;
 
959
}
 
960
 
 
961
static inline int ocfs2_meta_ecc(struct ocfs2_super_block *osb)
 
962
{
 
963
        if (OCFS2_HAS_INCOMPAT_FEATURE(osb,
 
964
                                       OCFS2_FEATURE_INCOMPAT_META_ECC))
 
965
                return 1;
 
966
        return 0;
 
967
}
 
968
 
 
969
static inline int ocfs2_support_xattr(struct ocfs2_super_block *osb)
 
970
{
 
971
        if (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR)
 
972
                return 1;
 
973
        return 0;
 
974
}
 
975
 
 
976
/*
 
977
 * shamelessly lifted from the kernel
 
978
 *
 
979
 * min()/max() macros that also do
 
980
 * strict type-checking.. See the
 
981
 * "unnecessary" pointer comparison.
 
982
 */
 
983
#define ocfs2_min(x,y) ({ \
 
984
        const typeof(x) _x = (x);       \
 
985
        const typeof(y) _y = (y);       \
 
986
        (void) (&_x == &_y);            \
 
987
        _x < _y ? _x : _y; })
 
988
                                                                                
 
989
#define ocfs2_max(x,y) ({ \
 
990
        const typeof(x) _x = (x);       \
 
991
        const typeof(y) _y = (y);       \
 
992
        (void) (&_x == &_y);            \
 
993
        _x > _y ? _x : _y; })
 
994
 
 
995
/* lifted from the kernel. include/linux/kernel.h */
 
996
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
997
 
 
998
/*
 
999
 * DEPRECATED: Extent/block iterate functions.
 
1000
 *
 
1001
 * Do not use these for reading/writing regular files - they don't properly
 
1002
 * handle holes or inline data.
 
1003
 */
 
1004
 
 
1005
/* Return flags for the extent iterator functions */
 
1006
#define OCFS2_EXTENT_CHANGED    0x01
 
1007
#define OCFS2_EXTENT_ABORT      0x02
 
1008
#define OCFS2_EXTENT_ERROR      0x04
 
1009
 
 
1010
/*
 
1011
 * Extent iterate flags
 
1012
 *
 
1013
 * OCFS2_EXTENT_FLAG_APPEND indicates that the iterator function should
 
1014
 * be called on extents past the leaf next_free_rec.  This is used by
 
1015
 * ocfs2_expand_dir() to add a new extent to a directory (via
 
1016
 * OCFS2_BLOCK_FLAG_APPEND and the block iteration functions).
 
1017
 *
 
1018
 * OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE indicates that the iterator
 
1019
 * function for tree_depth > 0 records (ocfs2_extent_blocks, iow)
 
1020
 * should be called after all of the extents contained in the
 
1021
 * extent_block are processed.  This is useful if you are going to be
 
1022
 * deallocating extents.
 
1023
 *
 
1024
 * OCFS2_EXTENT_FLAG_DATA_ONLY indicates that the iterator function
 
1025
 * should be called for data extents (depth == 0) only.
 
1026
 */
 
1027
#define OCFS2_EXTENT_FLAG_APPEND                0x01
 
1028
#define OCFS2_EXTENT_FLAG_DEPTH_TRAVERSE        0x02
 
1029
#define OCFS2_EXTENT_FLAG_DATA_ONLY             0x04
 
1030
 
 
1031
 
 
1032
/* Return flags for the block iterator functions */
 
1033
#define OCFS2_BLOCK_CHANGED     0x01
 
1034
#define OCFS2_BLOCK_ABORT       0x02
 
1035
#define OCFS2_BLOCK_ERROR       0x04
 
1036
 
 
1037
/*
 
1038
 * Block iterate flags
 
1039
 *
 
1040
 * In OCFS2, block iteration runs through the blocks contained in an
 
1041
 * inode's data extents.  As such, "DATA_ONLY" and "DEPTH_TRAVERSE"
 
1042
 * can't really apply.
 
1043
 *
 
1044
 * OCFS2_BLOCK_FLAG_APPEND is as OCFS2_EXTENT_FLAG_APPEND, except on a
 
1045
 * blocksize basis.  This may mean that the underlying extent already
 
1046
 * contains the space for a new block, and i_size is updated
 
1047
 * accordingly.
 
1048
 */
 
1049
#define OCFS2_BLOCK_FLAG_APPEND         0x01
 
1050
 
 
1051
errcode_t ocfs2_extent_iterate(ocfs2_filesys *fs,
 
1052
                               uint64_t blkno,
 
1053
                               int flags,
 
1054
                               char *block_buf,
 
1055
                               int (*func)(ocfs2_filesys *fs,
 
1056
                                           struct ocfs2_extent_rec *rec,
 
1057
                                           int tree_depth,
 
1058
                                           uint32_t ccount,
 
1059
                                           uint64_t ref_blkno,
 
1060
                                           int ref_recno,
 
1061
                                           void *priv_data),
 
1062
                               void *priv_data);
 
1063
errcode_t ocfs2_extent_iterate_inode(ocfs2_filesys *fs,
 
1064
                                     struct ocfs2_dinode *inode,
 
1065
                                     int flags,
 
1066
                                     char *block_buf,
 
1067
                                     int (*func)(ocfs2_filesys *fs,
 
1068
                                                 struct ocfs2_extent_rec *rec,
 
1069
                                                 int tree_depth,
 
1070
                                                 uint32_t ccount,
 
1071
                                                 uint64_t ref_blkno,
 
1072
                                                 int ref_recno,
 
1073
                                                 void *priv_data),
 
1074
                                                 void *priv_data);
 
1075
errcode_t ocfs2_block_iterate(ocfs2_filesys *fs,
 
1076
                              uint64_t blkno,
 
1077
                              int flags,
 
1078
                              int (*func)(ocfs2_filesys *fs,
 
1079
                                          uint64_t blkno,
 
1080
                                          uint64_t bcount,
 
1081
                                          uint16_t ext_flags,
 
1082
                                          void *priv_data),
 
1083
                              void *priv_data);
 
1084
errcode_t ocfs2_block_iterate_inode(ocfs2_filesys *fs,
 
1085
                                    struct ocfs2_dinode *inode,
 
1086
                                    int flags,
 
1087
                                    int (*func)(ocfs2_filesys *fs,
 
1088
                                                uint64_t blkno,
 
1089
                                                uint64_t bcount,
 
1090
                                                uint16_t ext_flags,
 
1091
                                                void *priv_data),
 
1092
                                    void *priv_data);
 
1093
 
 
1094
uint32_t ocfs2_xattr_uuid_hash(unsigned char *uuid);
 
1095
uint32_t ocfs2_xattr_name_hash(uint32_t uuid_hash, const char *name,
 
1096
                               int name_len);
 
1097
int ocfs2_xattr_find_leaf(ocfs2_filesys *fs, struct ocfs2_xattr_block *xb,
 
1098
                          uint32_t cpos, char **leaf_buf);
 
1099
uint16_t ocfs2_xattr_buckets_per_cluster(ocfs2_filesys *fs);
 
1100
uint16_t ocfs2_blocks_per_xattr_bucket(ocfs2_filesys *fs);
 
1101
void ocfs2_swap_xattrs_to_cpu(struct ocfs2_xattr_header *xh);
 
1102
void ocfs2_swap_xattrs_from_cpu(struct ocfs2_xattr_header *xh);
 
1103
void ocfs2_swap_xattr_block_to_cpu(struct ocfs2_xattr_block *xb);
 
1104
void ocfs2_swap_xattr_block_from_cpu(struct ocfs2_xattr_block *xb);
 
1105
errcode_t ocfs2_read_xattr_block(ocfs2_filesys *fs,
 
1106
                                 uint64_t blkno,
 
1107
                                 char *xb_buf);
 
1108
errcode_t ocfs2_write_xattr_block(ocfs2_filesys *fs,
 
1109
                                  uint64_t blkno,
 
1110
                                  char *xb_buf);
 
1111
errcode_t ocfs2_xattr_get_rec(ocfs2_filesys *fs,
 
1112
                              struct ocfs2_xattr_block *xb,
 
1113
                              uint32_t name_hash,
 
1114
                              uint64_t *p_blkno,
 
1115
                              uint32_t *e_cpos,
 
1116
                              uint32_t *num_clusters);
 
1117
uint16_t ocfs2_xattr_value_real_size(uint16_t name_len, uint16_t value_len);
 
1118
uint16_t ocfs2_xattr_min_offset(struct ocfs2_xattr_header *xh, uint16_t size);
 
1119
uint16_t ocfs2_xattr_name_value_len(struct ocfs2_xattr_header *xh);
 
1120
errcode_t ocfs2_read_xattr_bucket(ocfs2_filesys *fs,
 
1121
                                  uint64_t blkno,
 
1122
                                  char *bucket_buf);
 
1123
errcode_t ocfs2_write_xattr_bucket(ocfs2_filesys *fs,
 
1124
                                   uint64_t blkno,
 
1125
                                   char *bucket_buf);
 
1126
errcode_t ocfs2_xattr_value_truncate(ocfs2_filesys *fs,
 
1127
                                     struct ocfs2_xattr_value_root *xv);
 
1128
errcode_t ocfs2_xattr_tree_truncate(ocfs2_filesys *fs,
 
1129
                                    struct ocfs2_xattr_tree_root *xt);
 
1130
errcode_t ocfs2_extent_iterate_xattr(ocfs2_filesys *fs,
 
1131
                                     struct ocfs2_extent_list *el,
 
1132
                                     uint64_t last_eb_blk,
 
1133
                                     int flags,
 
1134
                                     int (*func)(ocfs2_filesys *fs,
 
1135
                                                struct ocfs2_extent_rec *rec,
 
1136
                                                int tree_depth,
 
1137
                                                uint32_t ccount,
 
1138
                                                uint64_t ref_blkno,
 
1139
                                                int ref_recno,
 
1140
                                                void *priv_data),
 
1141
                                     void *priv_data,
 
1142
                                     int *changed);
 
1143
errcode_t ocfs2_delete_xattr_block(ocfs2_filesys *fs, uint64_t blkno);
 
1144
 
 
1145
#endif  /* _FILESYS_H */