inode.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. /**
  2. * eCryptfs: Linux filesystem encryption layer
  3. *
  4. * Copyright (C) 1997-2004 Erez Zadok
  5. * Copyright (C) 2001-2004 Stony Brook University
  6. * Copyright (C) 2004-2007 International Business Machines Corp.
  7. * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
  8. * Michael C. Thompsion <mcthomps@us.ibm.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  23. * 02111-1307, USA.
  24. */
  25. #include <linux/file.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/dcache.h>
  29. #include <linux/namei.h>
  30. #include <linux/mount.h>
  31. #include <linux/crypto.h>
  32. #include <linux/fs_stack.h>
  33. #include <linux/slab.h>
  34. #include <linux/xattr.h>
  35. #include <asm/unaligned.h>
  36. #include "ecryptfs_kernel.h"
  37. static struct dentry *lock_parent(struct dentry *dentry)
  38. {
  39. struct dentry *dir;
  40. dir = dget_parent(dentry);
  41. mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
  42. return dir;
  43. }
  44. static void unlock_dir(struct dentry *dir)
  45. {
  46. mutex_unlock(&dir->d_inode->i_mutex);
  47. dput(dir);
  48. }
  49. static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
  50. {
  51. if (ecryptfs_inode_to_lower(inode) == (struct inode *)lower_inode)
  52. return 1;
  53. return 0;
  54. }
  55. static int ecryptfs_inode_set(struct inode *inode, void *opaque)
  56. {
  57. struct inode *lower_inode = opaque;
  58. ecryptfs_set_inode_lower(inode, lower_inode);
  59. fsstack_copy_attr_all(inode, lower_inode);
  60. /* i_size will be overwritten for encrypted regular files */
  61. fsstack_copy_inode_size(inode, lower_inode);
  62. inode->i_ino = lower_inode->i_ino;
  63. inode->i_version++;
  64. inode->i_mapping->a_ops = &ecryptfs_aops;
  65. inode->i_mapping->backing_dev_info = inode->i_sb->s_bdi;
  66. if (S_ISLNK(inode->i_mode))
  67. inode->i_op = &ecryptfs_symlink_iops;
  68. else if (S_ISDIR(inode->i_mode))
  69. inode->i_op = &ecryptfs_dir_iops;
  70. else
  71. inode->i_op = &ecryptfs_main_iops;
  72. if (S_ISDIR(inode->i_mode))
  73. inode->i_fop = &ecryptfs_dir_fops;
  74. else if (special_file(inode->i_mode))
  75. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  76. else
  77. inode->i_fop = &ecryptfs_main_fops;
  78. return 0;
  79. }
  80. static struct inode *__ecryptfs_get_inode(struct inode *lower_inode,
  81. struct super_block *sb)
  82. {
  83. struct inode *inode;
  84. if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb))
  85. return ERR_PTR(-EXDEV);
  86. if (!igrab(lower_inode))
  87. return ERR_PTR(-ESTALE);
  88. inode = iget5_locked(sb, (unsigned long)lower_inode,
  89. ecryptfs_inode_test, ecryptfs_inode_set,
  90. lower_inode);
  91. if (!inode) {
  92. iput(lower_inode);
  93. return ERR_PTR(-EACCES);
  94. }
  95. if (!(inode->i_state & I_NEW))
  96. iput(lower_inode);
  97. return inode;
  98. }
  99. struct inode *ecryptfs_get_inode(struct inode *lower_inode,
  100. struct super_block *sb)
  101. {
  102. struct inode *inode = __ecryptfs_get_inode(lower_inode, sb);
  103. if (!IS_ERR(inode) && (inode->i_state & I_NEW))
  104. unlock_new_inode(inode);
  105. return inode;
  106. }
  107. /**
  108. * ecryptfs_interpose
  109. * @lower_dentry: Existing dentry in the lower filesystem
  110. * @dentry: ecryptfs' dentry
  111. * @sb: ecryptfs's super_block
  112. *
  113. * Interposes upper and lower dentries.
  114. *
  115. * Returns zero on success; non-zero otherwise
  116. */
  117. static int ecryptfs_interpose(struct dentry *lower_dentry,
  118. struct dentry *dentry, struct super_block *sb)
  119. {
  120. struct inode *inode = ecryptfs_get_inode(lower_dentry->d_inode, sb);
  121. if (IS_ERR(inode))
  122. return PTR_ERR(inode);
  123. d_instantiate(dentry, inode);
  124. return 0;
  125. }
  126. static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry,
  127. struct inode *inode)
  128. {
  129. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  130. struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
  131. struct dentry *lower_dir_dentry;
  132. int rc;
  133. dget(lower_dentry);
  134. lower_dir_dentry = lock_parent(lower_dentry);
  135. rc = vfs_unlink(lower_dir_inode, lower_dentry, NULL);
  136. if (rc) {
  137. printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
  138. goto out_unlock;
  139. }
  140. fsstack_copy_attr_times(dir, lower_dir_inode);
  141. set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink);
  142. inode->i_ctime = dir->i_ctime;
  143. d_drop(dentry);
  144. out_unlock:
  145. unlock_dir(lower_dir_dentry);
  146. dput(lower_dentry);
  147. return rc;
  148. }
  149. /**
  150. * ecryptfs_do_create
  151. * @directory_inode: inode of the new file's dentry's parent in ecryptfs
  152. * @ecryptfs_dentry: New file's dentry in ecryptfs
  153. * @mode: The mode of the new file
  154. * @nd: nameidata of ecryptfs' parent's dentry & vfsmount
  155. *
  156. * Creates the underlying file and the eCryptfs inode which will link to
  157. * it. It will also update the eCryptfs directory inode to mimic the
  158. * stat of the lower directory inode.
  159. *
  160. * Returns the new eCryptfs inode on success; an ERR_PTR on error condition
  161. */
  162. static struct inode *
  163. ecryptfs_do_create(struct inode *directory_inode,
  164. struct dentry *ecryptfs_dentry, umode_t mode)
  165. {
  166. int rc;
  167. struct dentry *lower_dentry;
  168. struct dentry *lower_dir_dentry;
  169. struct inode *inode;
  170. lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
  171. lower_dir_dentry = lock_parent(lower_dentry);
  172. if (IS_ERR(lower_dir_dentry)) {
  173. ecryptfs_printk(KERN_ERR, "Error locking directory of "
  174. "dentry\n");
  175. inode = ERR_CAST(lower_dir_dentry);
  176. goto out;
  177. }
  178. rc = vfs_create(lower_dir_dentry->d_inode, lower_dentry, mode, true);
  179. if (rc) {
  180. printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
  181. "rc = [%d]\n", __func__, rc);
  182. inode = ERR_PTR(rc);
  183. goto out_lock;
  184. }
  185. inode = __ecryptfs_get_inode(lower_dentry->d_inode,
  186. directory_inode->i_sb);
  187. if (IS_ERR(inode)) {
  188. vfs_unlink(lower_dir_dentry->d_inode, lower_dentry, NULL);
  189. goto out_lock;
  190. }
  191. fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
  192. fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
  193. out_lock:
  194. unlock_dir(lower_dir_dentry);
  195. out:
  196. return inode;
  197. }
  198. /**
  199. * ecryptfs_initialize_file
  200. *
  201. * Cause the file to be changed from a basic empty file to an ecryptfs
  202. * file with a header and first data page.
  203. *
  204. * Returns zero on success
  205. */
  206. int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
  207. struct inode *ecryptfs_inode)
  208. {
  209. struct ecryptfs_crypt_stat *crypt_stat =
  210. &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
  211. int rc = 0;
  212. if (S_ISDIR(ecryptfs_inode->i_mode)) {
  213. ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
  214. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  215. goto out;
  216. }
  217. ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
  218. rc = ecryptfs_new_file_context(ecryptfs_inode);
  219. if (rc) {
  220. ecryptfs_printk(KERN_ERR, "Error creating new file "
  221. "context; rc = [%d]\n", rc);
  222. goto out;
  223. }
  224. rc = ecryptfs_get_lower_file(ecryptfs_dentry, ecryptfs_inode);
  225. if (rc) {
  226. printk(KERN_ERR "%s: Error attempting to initialize "
  227. "the lower file for the dentry with name "
  228. "[%s]; rc = [%d]\n", __func__,
  229. ecryptfs_dentry->d_name.name, rc);
  230. goto out;
  231. }
  232. rc = ecryptfs_write_metadata(ecryptfs_dentry, ecryptfs_inode);
  233. if (rc)
  234. printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc);
  235. ecryptfs_put_lower_file(ecryptfs_inode);
  236. out:
  237. return rc;
  238. }
  239. /**
  240. * ecryptfs_create
  241. * @dir: The inode of the directory in which to create the file.
  242. * @dentry: The eCryptfs dentry
  243. * @mode: The mode of the new file.
  244. *
  245. * Creates a new file.
  246. *
  247. * Returns zero on success; non-zero on error condition
  248. */
  249. static int
  250. ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
  251. umode_t mode, bool excl)
  252. {
  253. struct inode *ecryptfs_inode;
  254. int rc;
  255. ecryptfs_inode = ecryptfs_do_create(directory_inode, ecryptfs_dentry,
  256. mode);
  257. if (unlikely(IS_ERR(ecryptfs_inode))) {
  258. ecryptfs_printk(KERN_WARNING, "Failed to create file in"
  259. "lower filesystem\n");
  260. rc = PTR_ERR(ecryptfs_inode);
  261. goto out;
  262. }
  263. /* At this point, a file exists on "disk"; we need to make sure
  264. * that this on disk file is prepared to be an ecryptfs file */
  265. rc = ecryptfs_initialize_file(ecryptfs_dentry, ecryptfs_inode);
  266. if (rc) {
  267. ecryptfs_do_unlink(directory_inode, ecryptfs_dentry,
  268. ecryptfs_inode);
  269. make_bad_inode(ecryptfs_inode);
  270. unlock_new_inode(ecryptfs_inode);
  271. iput(ecryptfs_inode);
  272. goto out;
  273. }
  274. unlock_new_inode(ecryptfs_inode);
  275. d_instantiate(ecryptfs_dentry, ecryptfs_inode);
  276. out:
  277. return rc;
  278. }
  279. static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
  280. {
  281. struct ecryptfs_crypt_stat *crypt_stat;
  282. int rc;
  283. rc = ecryptfs_get_lower_file(dentry, inode);
  284. if (rc) {
  285. printk(KERN_ERR "%s: Error attempting to initialize "
  286. "the lower file for the dentry with name "
  287. "[%s]; rc = [%d]\n", __func__,
  288. dentry->d_name.name, rc);
  289. return rc;
  290. }
  291. crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
  292. /* TODO: lock for crypt_stat comparison */
  293. if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
  294. ecryptfs_set_default_sizes(crypt_stat);
  295. rc = ecryptfs_read_and_validate_header_region(inode);
  296. ecryptfs_put_lower_file(inode);
  297. if (rc) {
  298. rc = ecryptfs_read_and_validate_xattr_region(dentry, inode);
  299. if (!rc)
  300. crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
  301. }
  302. /* Must return 0 to allow non-eCryptfs files to be looked up, too */
  303. return 0;
  304. }
  305. /**
  306. * ecryptfs_lookup_interpose - Dentry interposition for a lookup
  307. */
  308. static int ecryptfs_lookup_interpose(struct dentry *dentry,
  309. struct dentry *lower_dentry,
  310. struct inode *dir_inode)
  311. {
  312. struct inode *inode, *lower_inode = lower_dentry->d_inode;
  313. struct ecryptfs_dentry_info *dentry_info;
  314. struct vfsmount *lower_mnt;
  315. int rc = 0;
  316. dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
  317. if (!dentry_info) {
  318. printk(KERN_ERR "%s: Out of memory whilst attempting "
  319. "to allocate ecryptfs_dentry_info struct\n",
  320. __func__);
  321. dput(lower_dentry);
  322. return -ENOMEM;
  323. }
  324. lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
  325. fsstack_copy_attr_atime(dir_inode, lower_dentry->d_parent->d_inode);
  326. BUG_ON(!d_count(lower_dentry));
  327. ecryptfs_set_dentry_private(dentry, dentry_info);
  328. dentry_info->lower_path.mnt = lower_mnt;
  329. dentry_info->lower_path.dentry = lower_dentry;
  330. if (!lower_dentry->d_inode) {
  331. /* We want to add because we couldn't find in lower */
  332. d_add(dentry, NULL);
  333. return 0;
  334. }
  335. inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb);
  336. if (IS_ERR(inode)) {
  337. printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
  338. __func__, PTR_ERR(inode));
  339. return PTR_ERR(inode);
  340. }
  341. if (S_ISREG(inode->i_mode)) {
  342. rc = ecryptfs_i_size_read(dentry, inode);
  343. if (rc) {
  344. make_bad_inode(inode);
  345. return rc;
  346. }
  347. }
  348. if (inode->i_state & I_NEW)
  349. unlock_new_inode(inode);
  350. d_add(dentry, inode);
  351. return rc;
  352. }
  353. /**
  354. * ecryptfs_lookup
  355. * @ecryptfs_dir_inode: The eCryptfs directory inode
  356. * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
  357. * @ecryptfs_nd: nameidata; may be NULL
  358. *
  359. * Find a file on disk. If the file does not exist, then we'll add it to the
  360. * dentry cache and continue on to read it from the disk.
  361. */
  362. static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
  363. struct dentry *ecryptfs_dentry,
  364. unsigned int flags)
  365. {
  366. char *encrypted_and_encoded_name = NULL;
  367. size_t encrypted_and_encoded_name_size;
  368. struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  369. struct dentry *lower_dir_dentry, *lower_dentry;
  370. int rc = 0;
  371. lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
  372. mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
  373. lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name,
  374. lower_dir_dentry,
  375. ecryptfs_dentry->d_name.len);
  376. mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
  377. if (IS_ERR(lower_dentry)) {
  378. rc = PTR_ERR(lower_dentry);
  379. ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
  380. "[%d] on lower_dentry = [%s]\n", __func__, rc,
  381. ecryptfs_dentry->d_name.name);
  382. goto out;
  383. }
  384. if (lower_dentry->d_inode)
  385. goto interpose;
  386. mount_crypt_stat = &ecryptfs_superblock_to_private(
  387. ecryptfs_dentry->d_sb)->mount_crypt_stat;
  388. if (!(mount_crypt_stat
  389. && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)))
  390. goto interpose;
  391. dput(lower_dentry);
  392. rc = ecryptfs_encrypt_and_encode_filename(
  393. &encrypted_and_encoded_name, &encrypted_and_encoded_name_size,
  394. NULL, mount_crypt_stat, ecryptfs_dentry->d_name.name,
  395. ecryptfs_dentry->d_name.len);
  396. if (rc) {
  397. printk(KERN_ERR "%s: Error attempting to encrypt and encode "
  398. "filename; rc = [%d]\n", __func__, rc);
  399. goto out;
  400. }
  401. mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
  402. lower_dentry = lookup_one_len(encrypted_and_encoded_name,
  403. lower_dir_dentry,
  404. encrypted_and_encoded_name_size);
  405. mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
  406. if (IS_ERR(lower_dentry)) {
  407. rc = PTR_ERR(lower_dentry);
  408. ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
  409. "[%d] on lower_dentry = [%s]\n", __func__, rc,
  410. encrypted_and_encoded_name);
  411. goto out;
  412. }
  413. interpose:
  414. rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
  415. ecryptfs_dir_inode);
  416. out:
  417. kfree(encrypted_and_encoded_name);
  418. return ERR_PTR(rc);
  419. }
  420. static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
  421. struct dentry *new_dentry)
  422. {
  423. struct dentry *lower_old_dentry;
  424. struct dentry *lower_new_dentry;
  425. struct dentry *lower_dir_dentry;
  426. u64 file_size_save;
  427. int rc;
  428. file_size_save = i_size_read(old_dentry->d_inode);
  429. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  430. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  431. dget(lower_old_dentry);
  432. dget(lower_new_dentry);
  433. lower_dir_dentry = lock_parent(lower_new_dentry);
  434. rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
  435. lower_new_dentry, NULL);
  436. if (rc || !lower_new_dentry->d_inode)
  437. goto out_lock;
  438. rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb);
  439. if (rc)
  440. goto out_lock;
  441. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  442. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  443. set_nlink(old_dentry->d_inode,
  444. ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink);
  445. i_size_write(new_dentry->d_inode, file_size_save);
  446. out_lock:
  447. unlock_dir(lower_dir_dentry);
  448. dput(lower_new_dentry);
  449. dput(lower_old_dentry);
  450. return rc;
  451. }
  452. static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
  453. {
  454. return ecryptfs_do_unlink(dir, dentry, dentry->d_inode);
  455. }
  456. static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
  457. const char *symname)
  458. {
  459. int rc;
  460. struct dentry *lower_dentry;
  461. struct dentry *lower_dir_dentry;
  462. char *encoded_symname;
  463. size_t encoded_symlen;
  464. struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
  465. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  466. dget(lower_dentry);
  467. lower_dir_dentry = lock_parent(lower_dentry);
  468. mount_crypt_stat = &ecryptfs_superblock_to_private(
  469. dir->i_sb)->mount_crypt_stat;
  470. rc = ecryptfs_encrypt_and_encode_filename(&encoded_symname,
  471. &encoded_symlen,
  472. NULL,
  473. mount_crypt_stat, symname,
  474. strlen(symname));
  475. if (rc)
  476. goto out_lock;
  477. rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
  478. encoded_symname);
  479. kfree(encoded_symname);
  480. if (rc || !lower_dentry->d_inode)
  481. goto out_lock;
  482. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  483. if (rc)
  484. goto out_lock;
  485. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  486. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  487. out_lock:
  488. unlock_dir(lower_dir_dentry);
  489. dput(lower_dentry);
  490. if (!dentry->d_inode)
  491. d_drop(dentry);
  492. return rc;
  493. }
  494. static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  495. {
  496. int rc;
  497. struct dentry *lower_dentry;
  498. struct dentry *lower_dir_dentry;
  499. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  500. lower_dir_dentry = lock_parent(lower_dentry);
  501. rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
  502. if (rc || !lower_dentry->d_inode)
  503. goto out;
  504. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  505. if (rc)
  506. goto out;
  507. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  508. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  509. set_nlink(dir, lower_dir_dentry->d_inode->i_nlink);
  510. out:
  511. unlock_dir(lower_dir_dentry);
  512. if (!dentry->d_inode)
  513. d_drop(dentry);
  514. return rc;
  515. }
  516. static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
  517. {
  518. struct dentry *lower_dentry;
  519. struct dentry *lower_dir_dentry;
  520. int rc;
  521. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  522. dget(dentry);
  523. lower_dir_dentry = lock_parent(lower_dentry);
  524. dget(lower_dentry);
  525. rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
  526. dput(lower_dentry);
  527. if (!rc && dentry->d_inode)
  528. clear_nlink(dentry->d_inode);
  529. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  530. set_nlink(dir, lower_dir_dentry->d_inode->i_nlink);
  531. unlock_dir(lower_dir_dentry);
  532. if (!rc)
  533. d_drop(dentry);
  534. dput(dentry);
  535. return rc;
  536. }
  537. static int
  538. ecryptfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
  539. {
  540. int rc;
  541. struct dentry *lower_dentry;
  542. struct dentry *lower_dir_dentry;
  543. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  544. lower_dir_dentry = lock_parent(lower_dentry);
  545. rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
  546. if (rc || !lower_dentry->d_inode)
  547. goto out;
  548. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
  549. if (rc)
  550. goto out;
  551. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  552. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  553. out:
  554. unlock_dir(lower_dir_dentry);
  555. if (!dentry->d_inode)
  556. d_drop(dentry);
  557. return rc;
  558. }
  559. static int
  560. ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  561. struct inode *new_dir, struct dentry *new_dentry)
  562. {
  563. int rc;
  564. struct dentry *lower_old_dentry;
  565. struct dentry *lower_new_dentry;
  566. struct dentry *lower_old_dir_dentry;
  567. struct dentry *lower_new_dir_dentry;
  568. struct dentry *trap = NULL;
  569. struct inode *target_inode;
  570. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  571. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  572. dget(lower_old_dentry);
  573. dget(lower_new_dentry);
  574. lower_old_dir_dentry = dget_parent(lower_old_dentry);
  575. lower_new_dir_dentry = dget_parent(lower_new_dentry);
  576. target_inode = new_dentry->d_inode;
  577. trap = lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  578. /* source should not be ancestor of target */
  579. if (trap == lower_old_dentry) {
  580. rc = -EINVAL;
  581. goto out_lock;
  582. }
  583. /* target should not be ancestor of source */
  584. if (trap == lower_new_dentry) {
  585. rc = -ENOTEMPTY;
  586. goto out_lock;
  587. }
  588. rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
  589. lower_new_dir_dentry->d_inode, lower_new_dentry,
  590. NULL);
  591. if (rc)
  592. goto out_lock;
  593. if (target_inode)
  594. fsstack_copy_attr_all(target_inode,
  595. ecryptfs_inode_to_lower(target_inode));
  596. fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode);
  597. if (new_dir != old_dir)
  598. fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode);
  599. out_lock:
  600. unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  601. dput(lower_new_dir_dentry);
  602. dput(lower_old_dir_dentry);
  603. dput(lower_new_dentry);
  604. dput(lower_old_dentry);
  605. return rc;
  606. }
  607. static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
  608. size_t *bufsiz)
  609. {
  610. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  611. char *lower_buf;
  612. mm_segment_t old_fs;
  613. int rc;
  614. lower_buf = kmalloc(PATH_MAX, GFP_KERNEL);
  615. if (!lower_buf) {
  616. rc = -ENOMEM;
  617. goto out;
  618. }
  619. old_fs = get_fs();
  620. set_fs(get_ds());
  621. rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
  622. (char __user *)lower_buf,
  623. PATH_MAX);
  624. set_fs(old_fs);
  625. if (rc < 0)
  626. goto out;
  627. rc = ecryptfs_decode_and_decrypt_filename(buf, bufsiz, dentry->d_sb,
  628. lower_buf, rc);
  629. out:
  630. kfree(lower_buf);
  631. return rc;
  632. }
  633. static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  634. {
  635. char *buf;
  636. size_t len = PATH_MAX;
  637. int rc;
  638. rc = ecryptfs_readlink_lower(dentry, &buf, &len);
  639. if (rc)
  640. goto out;
  641. fsstack_copy_attr_atime(dentry->d_inode,
  642. ecryptfs_dentry_to_lower(dentry)->d_inode);
  643. buf[len] = '\0';
  644. out:
  645. nd_set_link(nd, buf);
  646. return NULL;
  647. }
  648. /**
  649. * upper_size_to_lower_size
  650. * @crypt_stat: Crypt_stat associated with file
  651. * @upper_size: Size of the upper file
  652. *
  653. * Calculate the required size of the lower file based on the
  654. * specified size of the upper file. This calculation is based on the
  655. * number of headers in the underlying file and the extent size.
  656. *
  657. * Returns Calculated size of the lower file.
  658. */
  659. static loff_t
  660. upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
  661. loff_t upper_size)
  662. {
  663. loff_t lower_size;
  664. lower_size = ecryptfs_lower_header_size(crypt_stat);
  665. if (upper_size != 0) {
  666. loff_t num_extents;
  667. num_extents = upper_size >> crypt_stat->extent_shift;
  668. if (upper_size & ~crypt_stat->extent_mask)
  669. num_extents++;
  670. lower_size += (num_extents * crypt_stat->extent_size);
  671. }
  672. return lower_size;
  673. }
  674. /**
  675. * truncate_upper
  676. * @dentry: The ecryptfs layer dentry
  677. * @ia: Address of the ecryptfs inode's attributes
  678. * @lower_ia: Address of the lower inode's attributes
  679. *
  680. * Function to handle truncations modifying the size of the file. Note
  681. * that the file sizes are interpolated. When expanding, we are simply
  682. * writing strings of 0's out. When truncating, we truncate the upper
  683. * inode and update the lower_ia according to the page index
  684. * interpolations. If ATTR_SIZE is set in lower_ia->ia_valid upon return,
  685. * the caller must use lower_ia in a call to notify_change() to perform
  686. * the truncation of the lower inode.
  687. *
  688. * Returns zero on success; non-zero otherwise
  689. */
  690. static int truncate_upper(struct dentry *dentry, struct iattr *ia,
  691. struct iattr *lower_ia)
  692. {
  693. int rc = 0;
  694. struct inode *inode = dentry->d_inode;
  695. struct ecryptfs_crypt_stat *crypt_stat;
  696. loff_t i_size = i_size_read(inode);
  697. loff_t lower_size_before_truncate;
  698. loff_t lower_size_after_truncate;
  699. if (unlikely((ia->ia_size == i_size))) {
  700. lower_ia->ia_valid &= ~ATTR_SIZE;
  701. return 0;
  702. }
  703. rc = ecryptfs_get_lower_file(dentry, inode);
  704. if (rc)
  705. return rc;
  706. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  707. /* Switch on growing or shrinking file */
  708. if (ia->ia_size > i_size) {
  709. char zero[] = { 0x00 };
  710. lower_ia->ia_valid &= ~ATTR_SIZE;
  711. /* Write a single 0 at the last position of the file;
  712. * this triggers code that will fill in 0's throughout
  713. * the intermediate portion of the previous end of the
  714. * file and the new and of the file */
  715. rc = ecryptfs_write(inode, zero,
  716. (ia->ia_size - 1), 1);
  717. } else { /* ia->ia_size < i_size_read(inode) */
  718. /* We're chopping off all the pages down to the page
  719. * in which ia->ia_size is located. Fill in the end of
  720. * that page from (ia->ia_size & ~PAGE_CACHE_MASK) to
  721. * PAGE_CACHE_SIZE with zeros. */
  722. size_t num_zeros = (PAGE_CACHE_SIZE
  723. - (ia->ia_size & ~PAGE_CACHE_MASK));
  724. if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
  725. truncate_setsize(inode, ia->ia_size);
  726. lower_ia->ia_size = ia->ia_size;
  727. lower_ia->ia_valid |= ATTR_SIZE;
  728. goto out;
  729. }
  730. if (num_zeros) {
  731. char *zeros_virt;
  732. zeros_virt = kzalloc(num_zeros, GFP_KERNEL);
  733. if (!zeros_virt) {
  734. rc = -ENOMEM;
  735. goto out;
  736. }
  737. rc = ecryptfs_write(inode, zeros_virt,
  738. ia->ia_size, num_zeros);
  739. kfree(zeros_virt);
  740. if (rc) {
  741. printk(KERN_ERR "Error attempting to zero out "
  742. "the remainder of the end page on "
  743. "reducing truncate; rc = [%d]\n", rc);
  744. goto out;
  745. }
  746. }
  747. truncate_setsize(inode, ia->ia_size);
  748. rc = ecryptfs_write_inode_size_to_metadata(inode);
  749. if (rc) {
  750. printk(KERN_ERR "Problem with "
  751. "ecryptfs_write_inode_size_to_metadata; "
  752. "rc = [%d]\n", rc);
  753. goto out;
  754. }
  755. /* We are reducing the size of the ecryptfs file, and need to
  756. * know if we need to reduce the size of the lower file. */
  757. lower_size_before_truncate =
  758. upper_size_to_lower_size(crypt_stat, i_size);
  759. lower_size_after_truncate =
  760. upper_size_to_lower_size(crypt_stat, ia->ia_size);
  761. if (lower_size_after_truncate < lower_size_before_truncate) {
  762. lower_ia->ia_size = lower_size_after_truncate;
  763. lower_ia->ia_valid |= ATTR_SIZE;
  764. } else
  765. lower_ia->ia_valid &= ~ATTR_SIZE;
  766. }
  767. out:
  768. ecryptfs_put_lower_file(inode);
  769. return rc;
  770. }
  771. static int ecryptfs_inode_newsize_ok(struct inode *inode, loff_t offset)
  772. {
  773. struct ecryptfs_crypt_stat *crypt_stat;
  774. loff_t lower_oldsize, lower_newsize;
  775. crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
  776. lower_oldsize = upper_size_to_lower_size(crypt_stat,
  777. i_size_read(inode));
  778. lower_newsize = upper_size_to_lower_size(crypt_stat, offset);
  779. if (lower_newsize > lower_oldsize) {
  780. /*
  781. * The eCryptfs inode and the new *lower* size are mixed here
  782. * because we may not have the lower i_mutex held and/or it may
  783. * not be appropriate to call inode_newsize_ok() with inodes
  784. * from other filesystems.
  785. */
  786. return inode_newsize_ok(inode, lower_newsize);
  787. }
  788. return 0;
  789. }
  790. /**
  791. * ecryptfs_truncate
  792. * @dentry: The ecryptfs layer dentry
  793. * @new_length: The length to expand the file to
  794. *
  795. * Simple function that handles the truncation of an eCryptfs inode and
  796. * its corresponding lower inode.
  797. *
  798. * Returns zero on success; non-zero otherwise
  799. */
  800. int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
  801. {
  802. struct iattr ia = { .ia_valid = ATTR_SIZE, .ia_size = new_length };
  803. struct iattr lower_ia = { .ia_valid = 0 };
  804. int rc;
  805. rc = ecryptfs_inode_newsize_ok(dentry->d_inode, new_length);
  806. if (rc)
  807. return rc;
  808. rc = truncate_upper(dentry, &ia, &lower_ia);
  809. if (!rc && lower_ia.ia_valid & ATTR_SIZE) {
  810. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  811. mutex_lock(&lower_dentry->d_inode->i_mutex);
  812. rc = notify_change(lower_dentry, &lower_ia, NULL);
  813. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  814. }
  815. return rc;
  816. }
  817. static int
  818. ecryptfs_permission(struct inode *inode, int mask)
  819. {
  820. return inode_permission(ecryptfs_inode_to_lower(inode), mask);
  821. }
  822. /**
  823. * ecryptfs_setattr
  824. * @dentry: dentry handle to the inode to modify
  825. * @ia: Structure with flags of what to change and values
  826. *
  827. * Updates the metadata of an inode. If the update is to the size
  828. * i.e. truncation, then ecryptfs_truncate will handle the size modification
  829. * of both the ecryptfs inode and the lower inode.
  830. *
  831. * All other metadata changes will be passed right to the lower filesystem,
  832. * and we will just update our inode to look like the lower.
  833. */
  834. static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
  835. {
  836. int rc = 0;
  837. struct dentry *lower_dentry;
  838. struct iattr lower_ia;
  839. struct inode *inode;
  840. struct inode *lower_inode;
  841. struct ecryptfs_crypt_stat *crypt_stat;
  842. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  843. if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
  844. ecryptfs_init_crypt_stat(crypt_stat);
  845. inode = dentry->d_inode;
  846. lower_inode = ecryptfs_inode_to_lower(inode);
  847. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  848. mutex_lock(&crypt_stat->cs_mutex);
  849. if (S_ISDIR(dentry->d_inode->i_mode))
  850. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  851. else if (S_ISREG(dentry->d_inode->i_mode)
  852. && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
  853. || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) {
  854. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  855. mount_crypt_stat = &ecryptfs_superblock_to_private(
  856. dentry->d_sb)->mount_crypt_stat;
  857. rc = ecryptfs_get_lower_file(dentry, inode);
  858. if (rc) {
  859. mutex_unlock(&crypt_stat->cs_mutex);
  860. goto out;
  861. }
  862. rc = ecryptfs_read_metadata(dentry);
  863. ecryptfs_put_lower_file(inode);
  864. if (rc) {
  865. if (!(mount_crypt_stat->flags
  866. & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
  867. rc = -EIO;
  868. printk(KERN_WARNING "Either the lower file "
  869. "is not in a valid eCryptfs format, "
  870. "or the key could not be retrieved. "
  871. "Plaintext passthrough mode is not "
  872. "enabled; returning -EIO\n");
  873. mutex_unlock(&crypt_stat->cs_mutex);
  874. goto out;
  875. }
  876. rc = 0;
  877. crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
  878. | ECRYPTFS_ENCRYPTED);
  879. }
  880. }
  881. mutex_unlock(&crypt_stat->cs_mutex);
  882. rc = inode_change_ok(inode, ia);
  883. if (rc)
  884. goto out;
  885. if (ia->ia_valid & ATTR_SIZE) {
  886. rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size);
  887. if (rc)
  888. goto out;
  889. }
  890. memcpy(&lower_ia, ia, sizeof(lower_ia));
  891. if (ia->ia_valid & ATTR_FILE)
  892. lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file);
  893. if (ia->ia_valid & ATTR_SIZE) {
  894. rc = truncate_upper(dentry, ia, &lower_ia);
  895. if (rc < 0)
  896. goto out;
  897. }
  898. /*
  899. * mode change is for clearing setuid/setgid bits. Allow lower fs
  900. * to interpret this in its own way.
  901. */
  902. if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
  903. lower_ia.ia_valid &= ~ATTR_MODE;
  904. mutex_lock(&lower_dentry->d_inode->i_mutex);
  905. rc = notify_change(lower_dentry, &lower_ia, NULL);
  906. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  907. out:
  908. fsstack_copy_attr_all(inode, lower_inode);
  909. return rc;
  910. }
  911. static int ecryptfs_getattr_link(struct vfsmount *mnt, struct dentry *dentry,
  912. struct kstat *stat)
  913. {
  914. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  915. int rc = 0;
  916. mount_crypt_stat = &ecryptfs_superblock_to_private(
  917. dentry->d_sb)->mount_crypt_stat;
  918. generic_fillattr(dentry->d_inode, stat);
  919. if (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES) {
  920. char *target;
  921. size_t targetsiz;
  922. rc = ecryptfs_readlink_lower(dentry, &target, &targetsiz);
  923. if (!rc) {
  924. kfree(target);
  925. stat->size = targetsiz;
  926. }
  927. }
  928. return rc;
  929. }
  930. static int ecryptfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  931. struct kstat *stat)
  932. {
  933. struct kstat lower_stat;
  934. int rc;
  935. rc = vfs_getattr(ecryptfs_dentry_to_lower_path(dentry), &lower_stat);
  936. if (!rc) {
  937. fsstack_copy_attr_all(dentry->d_inode,
  938. ecryptfs_inode_to_lower(dentry->d_inode));
  939. generic_fillattr(dentry->d_inode, stat);
  940. stat->blocks = lower_stat.blocks;
  941. }
  942. return rc;
  943. }
  944. int
  945. ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  946. size_t size, int flags)
  947. {
  948. int rc = 0;
  949. struct dentry *lower_dentry;
  950. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  951. if (!lower_dentry->d_inode->i_op->setxattr) {
  952. rc = -EOPNOTSUPP;
  953. goto out;
  954. }
  955. rc = vfs_setxattr(lower_dentry, name, value, size, flags);
  956. if (!rc)
  957. fsstack_copy_attr_all(dentry->d_inode, lower_dentry->d_inode);
  958. out:
  959. return rc;
  960. }
  961. ssize_t
  962. ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
  963. void *value, size_t size)
  964. {
  965. int rc = 0;
  966. if (!lower_dentry->d_inode->i_op->getxattr) {
  967. rc = -EOPNOTSUPP;
  968. goto out;
  969. }
  970. mutex_lock(&lower_dentry->d_inode->i_mutex);
  971. rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value,
  972. size);
  973. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  974. out:
  975. return rc;
  976. }
  977. static ssize_t
  978. ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
  979. size_t size)
  980. {
  981. return ecryptfs_getxattr_lower(ecryptfs_dentry_to_lower(dentry), name,
  982. value, size);
  983. }
  984. static ssize_t
  985. ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
  986. {
  987. int rc = 0;
  988. struct dentry *lower_dentry;
  989. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  990. if (!lower_dentry->d_inode->i_op->listxattr) {
  991. rc = -EOPNOTSUPP;
  992. goto out;
  993. }
  994. mutex_lock(&lower_dentry->d_inode->i_mutex);
  995. rc = lower_dentry->d_inode->i_op->listxattr(lower_dentry, list, size);
  996. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  997. out:
  998. return rc;
  999. }
  1000. static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
  1001. {
  1002. int rc = 0;
  1003. struct dentry *lower_dentry;
  1004. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  1005. if (!lower_dentry->d_inode->i_op->removexattr) {
  1006. rc = -EOPNOTSUPP;
  1007. goto out;
  1008. }
  1009. mutex_lock(&lower_dentry->d_inode->i_mutex);
  1010. rc = lower_dentry->d_inode->i_op->removexattr(lower_dentry, name);
  1011. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  1012. out:
  1013. return rc;
  1014. }
  1015. const struct inode_operations ecryptfs_symlink_iops = {
  1016. .readlink = generic_readlink,
  1017. .follow_link = ecryptfs_follow_link,
  1018. .put_link = kfree_put_link,
  1019. .permission = ecryptfs_permission,
  1020. .setattr = ecryptfs_setattr,
  1021. .getattr = ecryptfs_getattr_link,
  1022. .setxattr = ecryptfs_setxattr,
  1023. .getxattr = ecryptfs_getxattr,
  1024. .listxattr = ecryptfs_listxattr,
  1025. .removexattr = ecryptfs_removexattr
  1026. };
  1027. const struct inode_operations ecryptfs_dir_iops = {
  1028. .create = ecryptfs_create,
  1029. .lookup = ecryptfs_lookup,
  1030. .link = ecryptfs_link,
  1031. .unlink = ecryptfs_unlink,
  1032. .symlink = ecryptfs_symlink,
  1033. .mkdir = ecryptfs_mkdir,
  1034. .rmdir = ecryptfs_rmdir,
  1035. .mknod = ecryptfs_mknod,
  1036. .rename = ecryptfs_rename,
  1037. .permission = ecryptfs_permission,
  1038. .setattr = ecryptfs_setattr,
  1039. .setxattr = ecryptfs_setxattr,
  1040. .getxattr = ecryptfs_getxattr,
  1041. .listxattr = ecryptfs_listxattr,
  1042. .removexattr = ecryptfs_removexattr
  1043. };
  1044. const struct inode_operations ecryptfs_main_iops = {
  1045. .permission = ecryptfs_permission,
  1046. .setattr = ecryptfs_setattr,
  1047. .getattr = ecryptfs_getattr,
  1048. .setxattr = ecryptfs_setxattr,
  1049. .getxattr = ecryptfs_getxattr,
  1050. .listxattr = ecryptfs_listxattr,
  1051. .removexattr = ecryptfs_removexattr
  1052. };