linux/fs/hfs/hfs_fs.h
<<
>>
Prefs
   1/*
   2 *  linux/fs/hfs/hfs_fs.h
   3 *
   4 * Copyright (C) 1995-1997  Paul H. Hargrove
   5 * (C) 2003 Ardis Technologies <roman@ardistech.com>
   6 * This file may be distributed under the terms of the GNU General Public License.
   7 */
   8
   9#ifndef _LINUX_HFS_FS_H
  10#define _LINUX_HFS_FS_H
  11
  12#include <linux/slab.h>
  13#include <linux/types.h>
  14#include <linux/buffer_head.h>
  15#include <linux/fs.h>
  16
  17#include <asm/byteorder.h>
  18#include <asm/uaccess.h>
  19
  20#include "hfs.h"
  21
  22#define DBG_BNODE_REFS  0x00000001
  23#define DBG_BNODE_MOD   0x00000002
  24#define DBG_CAT_MOD     0x00000004
  25#define DBG_INODE       0x00000008
  26#define DBG_SUPER       0x00000010
  27#define DBG_EXTENT      0x00000020
  28#define DBG_BITMAP      0x00000040
  29
  30//#define DBG_MASK      (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD|DBG_CAT_MOD|DBG_BITMAP)
  31//#define DBG_MASK      (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
  32//#define DBG_MASK      (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
  33#define DBG_MASK        (0)
  34
  35#define dprint(flg, fmt, args...) \
  36        if (flg & DBG_MASK) printk(fmt , ## args)
  37
  38/*
  39 * struct hfs_inode_info
  40 *
  41 * The HFS-specific part of a Linux (struct inode)
  42 */
  43struct hfs_inode_info {
  44        atomic_t opencnt;
  45
  46        unsigned int flags;
  47
  48        /* to deal with localtime ugliness */
  49        int tz_secondswest;
  50
  51        struct hfs_cat_key cat_key;
  52
  53        struct list_head open_dir_list;
  54        struct inode *rsrc_inode;
  55
  56        struct semaphore extents_lock;
  57
  58        u16 alloc_blocks, clump_blocks;
  59        sector_t fs_blocks;
  60        /* Allocation extents from catlog record or volume header */
  61        hfs_extent_rec first_extents;
  62        u16 first_blocks;
  63        hfs_extent_rec cached_extents;
  64        u16 cached_start, cached_blocks;
  65
  66        loff_t phys_size;
  67        struct inode vfs_inode;
  68};
  69
  70#define HFS_FLG_RSRC            0x0001
  71#define HFS_FLG_EXT_DIRTY       0x0002
  72#define HFS_FLG_EXT_NEW         0x0004
  73
  74#define HFS_IS_RSRC(inode)      (HFS_I(inode)->flags & HFS_FLG_RSRC)
  75
  76/*
  77 * struct hfs_sb_info
  78 *
  79 * The HFS-specific part of a Linux (struct super_block)
  80 */
  81struct hfs_sb_info {
  82        struct buffer_head *mdb_bh;             /* The hfs_buffer
  83                                                   holding the real
  84                                                   superblock (aka VIB
  85                                                   or MDB) */
  86        struct hfs_mdb *mdb;
  87        struct buffer_head *alt_mdb_bh;         /* The hfs_buffer holding
  88                                                   the alternate superblock */
  89        struct hfs_mdb *alt_mdb;
  90        __be32 *bitmap;                         /* The page holding the
  91                                                   allocation bitmap */
  92        struct hfs_btree *ext_tree;                     /* Information about
  93                                                   the extents b-tree */
  94        struct hfs_btree *cat_tree;                     /* Information about
  95                                                   the catalog b-tree */
  96        u32 file_count;                         /* The number of
  97                                                   regular files in
  98                                                   the filesystem */
  99        u32 folder_count;                       /* The number of
 100                                                   directories in the
 101                                                   filesystem */
 102        u32 next_id;                            /* The next available
 103                                                   file id number */
 104        u32 clumpablks;                         /* The number of allocation
 105                                                   blocks to try to add when
 106                                                   extending a file */
 107        u32 fs_start;                           /* The first 512-byte
 108                                                   block represented
 109                                                   in the bitmap */
 110        u32 part_start;
 111        u16 root_files;                         /* The number of
 112                                                   regular
 113                                                   (non-directory)
 114                                                   files in the root
 115                                                   directory */
 116        u16 root_dirs;                          /* The number of
 117                                                   directories in the
 118                                                   root directory */
 119        u16 fs_ablocks;                         /* The number of
 120                                                   allocation blocks
 121                                                   in the filesystem */
 122        u16 free_ablocks;                       /* the number of unused
 123                                                   allocation blocks
 124                                                   in the filesystem */
 125        u32 alloc_blksz;                        /* The size of an
 126                                                   "allocation block" */
 127        int s_quiet;                            /* Silent failure when
 128                                                   changing owner or mode? */
 129        __be32 s_type;                          /* Type for new files */
 130        __be32 s_creator;                       /* Creator for new files */
 131        umode_t s_file_umask;                   /* The umask applied to the
 132                                                   permissions on all files */
 133        umode_t s_dir_umask;                    /* The umask applied to the
 134                                                   permissions on all dirs */
 135        uid_t s_uid;                            /* The uid of all files */
 136        gid_t s_gid;                            /* The gid of all files */
 137
 138        int session, part;
 139
 140        struct nls_table *nls_io, *nls_disk;
 141
 142        struct semaphore bitmap_lock;
 143
 144        unsigned long flags;
 145
 146        u16 blockoffset;
 147
 148        int fs_div;
 149
 150        struct hlist_head rsrc_inodes;
 151};
 152
 153#define HFS_FLG_BITMAP_DIRTY    0
 154#define HFS_FLG_MDB_DIRTY       1
 155#define HFS_FLG_ALT_MDB_DIRTY   2
 156
 157/* bitmap.c */
 158extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
 159extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
 160
 161/* catalog.c */
 162extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
 163struct hfs_find_data;
 164extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
 165extern int hfs_cat_create(u32, struct inode *, struct qstr *, struct inode *);
 166extern int hfs_cat_delete(u32, struct inode *, struct qstr *);
 167extern int hfs_cat_move(u32, struct inode *, struct qstr *,
 168                        struct inode *, struct qstr *);
 169extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, struct qstr *);
 170
 171/* dir.c */
 172extern const struct file_operations hfs_dir_operations;
 173extern const struct inode_operations hfs_dir_inode_operations;
 174
 175/* extent.c */
 176extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
 177extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
 178extern void hfs_ext_write_extent(struct inode *);
 179extern int hfs_extend_file(struct inode *);
 180extern void hfs_file_truncate(struct inode *);
 181
 182extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
 183
 184/* inode.c */
 185extern const struct address_space_operations hfs_aops;
 186extern const struct address_space_operations hfs_btree_aops;
 187
 188extern struct inode *hfs_new_inode(struct inode *, struct qstr *, int);
 189extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
 190extern int hfs_write_inode(struct inode *, int);
 191extern int hfs_inode_setattr(struct dentry *, struct iattr *);
 192extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
 193                        __be32 log_size, __be32 phys_size, u32 clump_size);
 194extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
 195extern void hfs_clear_inode(struct inode *);
 196extern void hfs_delete_inode(struct inode *);
 197
 198/* attr.c */
 199extern int hfs_setxattr(struct dentry *dentry, const char *name,
 200                        const void *value, size_t size, int flags);
 201extern ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
 202                            void *value, size_t size);
 203extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
 204
 205/* mdb.c */
 206extern int hfs_mdb_get(struct super_block *);
 207extern void hfs_mdb_commit(struct super_block *);
 208extern void hfs_mdb_close(struct super_block *);
 209extern void hfs_mdb_put(struct super_block *);
 210
 211/* part_tbl.c */
 212extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
 213
 214/* string.c */
 215extern struct dentry_operations hfs_dentry_operations;
 216
 217extern int hfs_hash_dentry(struct dentry *, struct qstr *);
 218extern int hfs_strcmp(const unsigned char *, unsigned int,
 219                      const unsigned char *, unsigned int);
 220extern int hfs_compare_dentry(struct dentry *, struct qstr *, struct qstr *);
 221
 222/* trans.c */
 223extern void hfs_asc2mac(struct super_block *, struct hfs_name *, struct qstr *);
 224extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
 225
 226extern struct timezone sys_tz;
 227
 228/*
 229 * There are two time systems.  Both are based on seconds since
 230 * a particular time/date.
 231 *      Unix:   unsigned lil-endian since 00:00 GMT, Jan. 1, 1970
 232 *      mac:    unsigned big-endian since 00:00 GMT, Jan. 1, 1904
 233 *
 234 */
 235#define __hfs_u_to_mtime(sec)   cpu_to_be32(sec + 2082844800U - sys_tz.tz_minuteswest * 60)
 236#define __hfs_m_to_utime(sec)   (be32_to_cpu(sec) - 2082844800U  + sys_tz.tz_minuteswest * 60)
 237
 238#define HFS_I(inode)    (list_entry(inode, struct hfs_inode_info, vfs_inode))
 239#define HFS_SB(sb)      ((struct hfs_sb_info *)(sb)->s_fs_info)
 240
 241#define hfs_m_to_utime(time)    (struct timespec){ .tv_sec = __hfs_m_to_utime(time) }
 242#define hfs_u_to_mtime(time)    __hfs_u_to_mtime((time).tv_sec)
 243#define hfs_mtime()             __hfs_u_to_mtime(get_seconds())
 244
 245static inline const char *hfs_mdb_name(struct super_block *sb)
 246{
 247        return sb->s_id;
 248}
 249
 250static inline void hfs_bitmap_dirty(struct super_block *sb)
 251{
 252        set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
 253        sb->s_dirt = 1;
 254}
 255
 256static inline void hfs_buffer_sync(struct buffer_head *bh)
 257{
 258        while (buffer_locked(bh)) {
 259                wait_on_buffer(bh);
 260        }
 261        if (buffer_dirty(bh)) {
 262                ll_rw_block(WRITE, 1, &bh);
 263                wait_on_buffer(bh);
 264        }
 265}
 266
 267#define sb_bread512(sb, sec, data) ({                   \
 268        struct buffer_head *__bh;                       \
 269        sector_t __block;                               \
 270        loff_t __start;                                 \
 271        int __offset;                                   \
 272                                                        \
 273        __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
 274        __block = __start >> (sb)->s_blocksize_bits;    \
 275        __offset = __start & ((sb)->s_blocksize - 1);   \
 276        __bh = sb_bread((sb), __block);                 \
 277        if (likely(__bh != NULL))                       \
 278                data = (void *)(__bh->b_data + __offset);\
 279        else                                            \
 280                data = NULL;                            \
 281        __bh;                                           \
 282})
 283
 284#endif
 285