exfat_super.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* Some of the source code in this file came from "linux/fs/fat/fat.h". */
  2. /*
  3. * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef _EXFAT_LINUX_H
  20. #define _EXFAT_LINUX_H
  21. #include <linux/buffer_head.h>
  22. #include <linux/string.h>
  23. #include <linux/nls.h>
  24. #include <linux/fs.h>
  25. #include <linux/mutex.h>
  26. #include <linux/swap.h>
  27. #include "exfat_config.h"
  28. #include "exfat_global.h"
  29. #include "exfat_data.h"
  30. #include "exfat_oal.h"
  31. #include "exfat_blkdev.h"
  32. #include "exfat_cache.h"
  33. #include "exfat_part.h"
  34. #include "exfat_nls.h"
  35. #include "exfat_api.h"
  36. #include "exfat.h"
  37. #define EXFAT_ERRORS_CONT 1
  38. #define EXFAT_ERRORS_PANIC 2
  39. #define EXFAT_ERRORS_RO 3
  40. #define EXFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
  41. struct exfat_mount_options {
  42. #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)
  43. uid_t fs_uid;
  44. gid_t fs_gid;
  45. #else
  46. kuid_t fs_uid;
  47. kgid_t fs_gid;
  48. #endif
  49. unsigned short fs_fmask;
  50. unsigned short fs_dmask;
  51. unsigned short allow_utime;
  52. unsigned short codepage;
  53. char *iocharset;
  54. unsigned char casesensitive;
  55. unsigned char tz_utc;
  56. unsigned char errors;
  57. #if EXFAT_CONFIG_DISCARD
  58. unsigned char discard;
  59. #endif
  60. };
  61. #define EXFAT_HASH_BITS 8
  62. #define EXFAT_HASH_SIZE (1UL << EXFAT_HASH_BITS)
  63. struct exfat_sb_info {
  64. FS_INFO_T fs_info;
  65. BD_INFO_T bd_info;
  66. struct exfat_mount_options options;
  67. int use_vmalloc;
  68. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,00)
  69. int s_dirt;
  70. struct mutex s_lock;
  71. #endif
  72. struct nls_table *nls_disk;
  73. struct nls_table *nls_io;
  74. struct inode *fat_inode;
  75. spinlock_t inode_hash_lock;
  76. struct hlist_head inode_hashtable[EXFAT_HASH_SIZE];
  77. #if EXFAT_CONFIG_KERNEL_DEBUG
  78. long debug_flags;
  79. #endif
  80. };
  81. struct exfat_inode_info {
  82. FILE_ID_T fid;
  83. char *target;
  84. loff_t mmu_private;
  85. loff_t i_pos;
  86. struct hlist_node i_hash_fat;
  87. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,00)
  88. struct rw_semaphore truncate_lock;
  89. #endif
  90. struct inode vfs_inode;
  91. };
  92. #define EXFAT_SB(sb) ((struct exfat_sb_info *)((sb)->s_fs_info))
  93. static inline struct exfat_inode_info *EXFAT_I(struct inode *inode) {
  94. return container_of(inode, struct exfat_inode_info, vfs_inode);
  95. }
  96. static inline int exfat_mode_can_hold_ro(struct inode *inode)
  97. {
  98. struct exfat_sb_info *sbi = EXFAT_SB(inode->i_sb);
  99. if (S_ISDIR(inode->i_mode))
  100. return 0;
  101. if ((~sbi->options.fs_fmask) & S_IWUGO)
  102. return 1;
  103. return 0;
  104. }
  105. static inline mode_t exfat_make_mode(struct exfat_sb_info *sbi,
  106. u32 attr, mode_t mode)
  107. {
  108. if ((attr & ATTR_READONLY) && !(attr & ATTR_SUBDIR))
  109. mode &= ~S_IWUGO;
  110. if (attr & ATTR_SUBDIR)
  111. return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
  112. else if (attr & ATTR_SYMLINK)
  113. return (mode & ~sbi->options.fs_dmask) | S_IFLNK;
  114. else
  115. return (mode & ~sbi->options.fs_fmask) | S_IFREG;
  116. }
  117. static inline u32 exfat_make_attr(struct inode *inode)
  118. {
  119. if (exfat_mode_can_hold_ro(inode) && !(inode->i_mode & S_IWUGO))
  120. return ((EXFAT_I(inode)->fid.attr) | ATTR_READONLY);
  121. else
  122. return (EXFAT_I(inode)->fid.attr);
  123. }
  124. static inline void exfat_save_attr(struct inode *inode, u32 attr)
  125. {
  126. if (exfat_mode_can_hold_ro(inode))
  127. EXFAT_I(inode)->fid.attr = attr & ATTR_RWMASK;
  128. else
  129. EXFAT_I(inode)->fid.attr = attr & (ATTR_RWMASK | ATTR_READONLY);
  130. }
  131. /* exfat_xattr.c */
  132. extern int exfat_setxattr(struct dentry *dentry, const char *name,
  133. const void *value, size_t size, int flags);
  134. extern ssize_t exfat_getxattr(struct dentry *dentry, const char *name,
  135. void *value, size_t size);
  136. extern ssize_t exfat_listxattr(struct dentry *dentry, char *list, size_t size);
  137. extern int exfat_removexattr(struct dentry *dentry, const char *name);
  138. #endif