CD exfat support for Tomato. https://github.com/dorimanx/exfat-nofuse.
[tomato.git] / release / src-rt / linux / linux-2.6 / fs / exfat / exfat_super.h
blobc9201dd79250a1e9bb358ace5cc6cb3488a538b7
1 /* Some of the source code in this file came from "linux/fs/fat/fat.h". */
3 /*
4 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef _EXFAT_LINUX_H
22 #define _EXFAT_LINUX_H
24 #include <linux/buffer_head.h>
25 #include <linux/string.h>
26 #include <linux/nls.h>
27 #include <linux/fs.h>
28 #include <linux/mutex.h>
29 #include <linux/swap.h>
31 #include "exfat_config.h"
32 #include "exfat_global.h"
33 #include "exfat_data.h"
34 #include "exfat_oal.h"
36 #include "exfat_blkdev.h"
37 #include "exfat_cache.h"
38 #include "exfat_part.h"
39 #include "exfat_nls.h"
40 #include "exfat_api.h"
41 #include "exfat.h"
43 #define EXFAT_ERRORS_CONT 1 /* ignore error and continue */
44 #define EXFAT_ERRORS_PANIC 2 /* panic on error */
45 #define EXFAT_ERRORS_RO 3 /* remount r/o on error */
47 /* ioctl command */
48 #define EXFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
50 struct exfat_mount_options {
51 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
52 kuid_t fs_uid;
53 kgid_t fs_gid;
54 #else
55 uid_t fs_uid;
56 gid_t fs_gid;
57 #endif
58 unsigned short fs_fmask;
59 unsigned short fs_dmask;
60 unsigned short allow_utime; /* permission for setting the [am]time */
61 unsigned short codepage; /* codepage for shortname conversions */
62 char *iocharset; /* charset for filename input/display */
63 unsigned char casesensitive;
64 unsigned char errors; /* on error: continue, panic, remount-ro */
65 #if EXFAT_CONFIG_DISCARD
66 unsigned char discard; /* flag on if -o dicard specified and device support discard() */
67 #endif /* EXFAT_CONFIG_DISCARD */
70 #define EXFAT_HASH_BITS 8
71 #define EXFAT_HASH_SIZE (1UL << EXFAT_HASH_BITS)
74 * EXFAT file system in-core superblock data
76 struct exfat_sb_info {
77 FS_INFO_T fs_info;
78 BD_INFO_T bd_info;
80 struct exfat_mount_options options;
82 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,00)
83 int s_dirt;
84 struct mutex s_lock;
85 #endif
86 struct nls_table *nls_disk; /* Codepage used on disk */
87 struct nls_table *nls_io; /* Charset used for input and display */
89 struct inode *fat_inode;
91 spinlock_t inode_hash_lock;
92 struct hlist_head inode_hashtable[EXFAT_HASH_SIZE];
93 #if EXFAT_CONFIG_KERNEL_DEBUG
94 long debug_flags;
95 #endif /* EXFAT_CONFIG_KERNEL_DEBUG */
99 * EXFAT file system inode data in memory
101 struct exfat_inode_info {
102 FILE_ID_T fid;
103 char *target;
104 /* NOTE: mmu_private is 64bits, so must hold ->i_mutex to access */
105 loff_t mmu_private; /* physically allocated size */
106 loff_t i_pos; /* on-disk position of directory entry or 0 */
107 struct hlist_node i_hash_fat; /* hash by i_location */
108 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,00)
109 struct rw_semaphore truncate_lock;
110 #endif
111 struct inode vfs_inode;
112 struct rw_semaphore i_alloc_sem; /* protect bmap against truncate */
115 #define EXFAT_SB(sb) ((struct exfat_sb_info *)((sb)->s_fs_info))
117 static inline struct exfat_inode_info *EXFAT_I(struct inode *inode) {
118 return container_of(inode, struct exfat_inode_info, vfs_inode);
122 * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to
123 * save ATTR_RO instead of ->i_mode.
125 * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only
126 * bit, it's just used as flag for app.
128 static inline int exfat_mode_can_hold_ro(struct inode *inode)
130 struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
132 if (S_ISDIR(inode->i_mode))
133 return 0;
135 if ((~sbi->options.fs_fmask) & S_IWUGO)
136 return 1;
137 return 0;
140 /* Convert attribute bits and a mask to the UNIX mode. */
141 static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi,
142 u32 attr, mode_t mode)
144 if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR))
145 mode &= ~S_IWUGO;
147 if (attr & ATTR_SUBDIR)
148 return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
149 else if (attr & ATTR_SYMLINK)
150 return (mode & ~sbi->options.fs_dmask) | S_IFLNK;
151 else
152 return (mode & ~sbi->options.fs_fmask) | S_IFREG;
155 /* Return the FAT attribute byte for this inode */
156 static inline u32 exfat_make_attr(struct inode *inode)
158 if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO))
159 return ((EXFAT_I(inode)->fid.attr) | ATTR_READONLY);
160 else
161 return (EXFAT_I(inode)->fid.attr);
164 static inline void exfat_save_attr(struct inode *inode, u32 attr)
166 if (exfat_mode_can_hold_ro(inode))
167 EXFAT_I(inode)->fid.attr = attr & ATTR_RWMASK;
168 else
169 EXFAT_I(inode)->fid.attr = attr & (ATTR_RWMASK | ATTR_READONLY);
172 #endif /* _EXFAT_LINUX_H */