Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *  linux/fs/hfs/hfs_fs.h
0003  *
0004  * Copyright (C) 1995-1997  Paul H. Hargrove
0005  * (C) 2003 Ardis Technologies <roman@ardistech.com>
0006  * This file may be distributed under the terms of the GNU General Public License.
0007  */
0008 
0009 #ifndef _LINUX_HFS_FS_H
0010 #define _LINUX_HFS_FS_H
0011 
0012 #ifdef pr_fmt
0013 #undef pr_fmt
0014 #endif
0015 
0016 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0017 
0018 #include <linux/slab.h>
0019 #include <linux/types.h>
0020 #include <linux/mutex.h>
0021 #include <linux/buffer_head.h>
0022 #include <linux/fs.h>
0023 #include <linux/workqueue.h>
0024 
0025 #include <asm/byteorder.h>
0026 #include <linux/uaccess.h>
0027 
0028 #include "hfs.h"
0029 
0030 #define DBG_BNODE_REFS  0x00000001
0031 #define DBG_BNODE_MOD   0x00000002
0032 #define DBG_CAT_MOD 0x00000004
0033 #define DBG_INODE   0x00000008
0034 #define DBG_SUPER   0x00000010
0035 #define DBG_EXTENT  0x00000020
0036 #define DBG_BITMAP  0x00000040
0037 
0038 //#define DBG_MASK  (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD|DBG_CAT_MOD|DBG_BITMAP)
0039 //#define DBG_MASK  (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
0040 //#define DBG_MASK  (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
0041 #define DBG_MASK    (0)
0042 
0043 #define hfs_dbg(flg, fmt, ...)                  \
0044 do {                                \
0045     if (DBG_##flg & DBG_MASK)               \
0046         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__);  \
0047 } while (0)
0048 
0049 #define hfs_dbg_cont(flg, fmt, ...)             \
0050 do {                                \
0051     if (DBG_##flg & DBG_MASK)               \
0052         pr_cont(fmt, ##__VA_ARGS__);            \
0053 } while (0)
0054 
0055 
0056 /*
0057  * struct hfs_inode_info
0058  *
0059  * The HFS-specific part of a Linux (struct inode)
0060  */
0061 struct hfs_inode_info {
0062     atomic_t opencnt;
0063 
0064     unsigned int flags;
0065 
0066     /* to deal with localtime ugliness */
0067     int tz_secondswest;
0068 
0069     struct hfs_cat_key cat_key;
0070 
0071     struct list_head open_dir_list;
0072     spinlock_t open_dir_lock;
0073     struct inode *rsrc_inode;
0074 
0075     struct mutex extents_lock;
0076 
0077     u16 alloc_blocks, clump_blocks;
0078     sector_t fs_blocks;
0079     /* Allocation extents from catlog record or volume header */
0080     hfs_extent_rec first_extents;
0081     u16 first_blocks;
0082     hfs_extent_rec cached_extents;
0083     u16 cached_start, cached_blocks;
0084 
0085     loff_t phys_size;
0086     struct inode vfs_inode;
0087 };
0088 
0089 #define HFS_FLG_RSRC        0x0001
0090 #define HFS_FLG_EXT_DIRTY   0x0002
0091 #define HFS_FLG_EXT_NEW     0x0004
0092 
0093 #define HFS_IS_RSRC(inode)  (HFS_I(inode)->flags & HFS_FLG_RSRC)
0094 
0095 /*
0096  * struct hfs_sb_info
0097  *
0098  * The HFS-specific part of a Linux (struct super_block)
0099  */
0100 struct hfs_sb_info {
0101     struct buffer_head *mdb_bh;     /* The hfs_buffer
0102                            holding the real
0103                            superblock (aka VIB
0104                            or MDB) */
0105     struct hfs_mdb *mdb;
0106     struct buffer_head *alt_mdb_bh;     /* The hfs_buffer holding
0107                            the alternate superblock */
0108     struct hfs_mdb *alt_mdb;
0109     __be32 *bitmap;             /* The page holding the
0110                            allocation bitmap */
0111     struct hfs_btree *ext_tree;         /* Information about
0112                            the extents b-tree */
0113     struct hfs_btree *cat_tree;         /* Information about
0114                            the catalog b-tree */
0115     u32 file_count;             /* The number of
0116                            regular files in
0117                            the filesystem */
0118     u32 folder_count;           /* The number of
0119                            directories in the
0120                            filesystem */
0121     u32 next_id;                /* The next available
0122                            file id number */
0123     u32 clumpablks;             /* The number of allocation
0124                            blocks to try to add when
0125                            extending a file */
0126     u32 fs_start;               /* The first 512-byte
0127                            block represented
0128                            in the bitmap */
0129     u32 part_start;
0130     u16 root_files;             /* The number of
0131                            regular
0132                            (non-directory)
0133                            files in the root
0134                            directory */
0135     u16 root_dirs;              /* The number of
0136                            directories in the
0137                            root directory */
0138     u16 fs_ablocks;             /* The number of
0139                            allocation blocks
0140                            in the filesystem */
0141     u16 free_ablocks;           /* the number of unused
0142                            allocation blocks
0143                            in the filesystem */
0144     u32 alloc_blksz;            /* The size of an
0145                            "allocation block" */
0146     int s_quiet;                /* Silent failure when
0147                            changing owner or mode? */
0148     __be32 s_type;              /* Type for new files */
0149     __be32 s_creator;           /* Creator for new files */
0150     umode_t s_file_umask;           /* The umask applied to the
0151                            permissions on all files */
0152     umode_t s_dir_umask;            /* The umask applied to the
0153                            permissions on all dirs */
0154     kuid_t s_uid;               /* The uid of all files */
0155     kgid_t s_gid;               /* The gid of all files */
0156 
0157     int session, part;
0158     struct nls_table *nls_io, *nls_disk;
0159     struct mutex bitmap_lock;
0160     unsigned long flags;
0161     u16 blockoffset;
0162     int fs_div;
0163     struct super_block *sb;
0164     int work_queued;        /* non-zero delayed work is queued */
0165     struct delayed_work mdb_work;   /* MDB flush delayed work */
0166     spinlock_t work_lock;       /* protects mdb_work and work_queued */
0167 };
0168 
0169 #define HFS_FLG_BITMAP_DIRTY    0
0170 #define HFS_FLG_MDB_DIRTY   1
0171 #define HFS_FLG_ALT_MDB_DIRTY   2
0172 
0173 /* bitmap.c */
0174 extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
0175 extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
0176 
0177 /* catalog.c */
0178 extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
0179 struct hfs_find_data;
0180 extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
0181 extern int hfs_cat_create(u32, struct inode *, const struct qstr *, struct inode *);
0182 extern int hfs_cat_delete(u32, struct inode *, const struct qstr *);
0183 extern int hfs_cat_move(u32, struct inode *, const struct qstr *,
0184             struct inode *, const struct qstr *);
0185 extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, const struct qstr *);
0186 
0187 /* dir.c */
0188 extern const struct file_operations hfs_dir_operations;
0189 extern const struct inode_operations hfs_dir_inode_operations;
0190 
0191 /* extent.c */
0192 extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
0193 extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
0194 extern int hfs_ext_write_extent(struct inode *);
0195 extern int hfs_extend_file(struct inode *);
0196 extern void hfs_file_truncate(struct inode *);
0197 
0198 extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
0199 
0200 /* inode.c */
0201 extern const struct address_space_operations hfs_aops;
0202 extern const struct address_space_operations hfs_btree_aops;
0203 
0204 int hfs_write_begin(struct file *file, struct address_space *mapping,
0205         loff_t pos, unsigned len, struct page **pagep, void **fsdata);
0206 extern struct inode *hfs_new_inode(struct inode *, const struct qstr *, umode_t);
0207 extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
0208 extern int hfs_write_inode(struct inode *, struct writeback_control *);
0209 extern int hfs_inode_setattr(struct user_namespace *, struct dentry *,
0210                  struct iattr *);
0211 extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
0212             __be32 log_size, __be32 phys_size, u32 clump_size);
0213 extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
0214 extern void hfs_evict_inode(struct inode *);
0215 extern void hfs_delete_inode(struct inode *);
0216 
0217 /* attr.c */
0218 extern const struct xattr_handler *hfs_xattr_handlers[];
0219 
0220 /* mdb.c */
0221 extern int hfs_mdb_get(struct super_block *);
0222 extern void hfs_mdb_commit(struct super_block *);
0223 extern void hfs_mdb_close(struct super_block *);
0224 extern void hfs_mdb_put(struct super_block *);
0225 
0226 /* part_tbl.c */
0227 extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
0228 
0229 /* string.c */
0230 extern const struct dentry_operations hfs_dentry_operations;
0231 
0232 extern int hfs_hash_dentry(const struct dentry *, struct qstr *);
0233 extern int hfs_strcmp(const unsigned char *, unsigned int,
0234               const unsigned char *, unsigned int);
0235 extern int hfs_compare_dentry(const struct dentry *dentry,
0236         unsigned int len, const char *str, const struct qstr *name);
0237 
0238 /* trans.c */
0239 extern void hfs_asc2mac(struct super_block *, struct hfs_name *, const struct qstr *);
0240 extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
0241 
0242 /* super.c */
0243 extern void hfs_mark_mdb_dirty(struct super_block *sb);
0244 
0245 /*
0246  * There are two time systems.  Both are based on seconds since
0247  * a particular time/date.
0248  *  Unix:   signed little-endian since 00:00 GMT, Jan. 1, 1970
0249  *  mac:    unsigned big-endian since 00:00 GMT, Jan. 1, 1904
0250  *
0251  * HFS implementations are highly inconsistent, this one matches the
0252  * traditional behavior of 64-bit Linux, giving the most useful
0253  * time range between 1970 and 2106, by treating any on-disk timestamp
0254  * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
0255  */
0256 #define HFS_UTC_OFFSET 2082844800U
0257 
0258 static inline time64_t __hfs_m_to_utime(__be32 mt)
0259 {
0260     time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
0261 
0262     return ut + sys_tz.tz_minuteswest * 60;
0263 }
0264 
0265 static inline __be32 __hfs_u_to_mtime(time64_t ut)
0266 {
0267     ut -= sys_tz.tz_minuteswest * 60;
0268 
0269     return cpu_to_be32(lower_32_bits(ut) + HFS_UTC_OFFSET);
0270 }
0271 #define HFS_I(inode)    (container_of(inode, struct hfs_inode_info, vfs_inode))
0272 #define HFS_SB(sb)  ((struct hfs_sb_info *)(sb)->s_fs_info)
0273 
0274 #define hfs_m_to_utime(time)   (struct timespec64){ .tv_sec = __hfs_m_to_utime(time) }
0275 #define hfs_u_to_mtime(time)   __hfs_u_to_mtime((time).tv_sec)
0276 #define hfs_mtime()     __hfs_u_to_mtime(ktime_get_real_seconds())
0277 
0278 static inline const char *hfs_mdb_name(struct super_block *sb)
0279 {
0280     return sb->s_id;
0281 }
0282 
0283 static inline void hfs_bitmap_dirty(struct super_block *sb)
0284 {
0285     set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
0286     hfs_mark_mdb_dirty(sb);
0287 }
0288 
0289 #define sb_bread512(sb, sec, data) ({           \
0290     struct buffer_head *__bh;           \
0291     sector_t __block;               \
0292     loff_t __start;                 \
0293     int __offset;                   \
0294                             \
0295     __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
0296     __block = __start >> (sb)->s_blocksize_bits;    \
0297     __offset = __start & ((sb)->s_blocksize - 1);   \
0298     __bh = sb_bread((sb), __block);         \
0299     if (likely(__bh != NULL))           \
0300         data = (void *)(__bh->b_data + __offset);\
0301     else                        \
0302         data = NULL;                \
0303     __bh;                       \
0304 })
0305 
0306 #endif