inode.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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 "ecryptfs_kernel.h"
  34. static struct dentry *lock_parent(struct dentry *dentry)
  35. {
  36. struct dentry *dir;
  37. dir = dget(dentry->d_parent);
  38. mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
  39. return dir;
  40. }
  41. static void unlock_parent(struct dentry *dentry)
  42. {
  43. mutex_unlock(&(dentry->d_parent->d_inode->i_mutex));
  44. dput(dentry->d_parent);
  45. }
  46. static void unlock_dir(struct dentry *dir)
  47. {
  48. mutex_unlock(&dir->d_inode->i_mutex);
  49. dput(dir);
  50. }
  51. /**
  52. * ecryptfs_create_underlying_file
  53. * @lower_dir_inode: inode of the parent in the lower fs of the new file
  54. * @lower_dentry: New file's dentry in the lower fs
  55. * @ecryptfs_dentry: New file's dentry in ecryptfs
  56. * @mode: The mode of the new file
  57. * @nd: nameidata of ecryptfs' parent's dentry & vfsmount
  58. *
  59. * Creates the file in the lower file system.
  60. *
  61. * Returns zero on success; non-zero on error condition
  62. */
  63. static int
  64. ecryptfs_create_underlying_file(struct inode *lower_dir_inode,
  65. struct dentry *dentry, int mode,
  66. struct nameidata *nd)
  67. {
  68. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  69. struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
  70. struct dentry *dentry_save;
  71. struct vfsmount *vfsmount_save;
  72. int rc;
  73. dentry_save = nd->dentry;
  74. vfsmount_save = nd->mnt;
  75. nd->dentry = lower_dentry;
  76. nd->mnt = lower_mnt;
  77. rc = vfs_create(lower_dir_inode, lower_dentry, mode, nd);
  78. nd->dentry = dentry_save;
  79. nd->mnt = vfsmount_save;
  80. return rc;
  81. }
  82. /**
  83. * ecryptfs_do_create
  84. * @directory_inode: inode of the new file's dentry's parent in ecryptfs
  85. * @ecryptfs_dentry: New file's dentry in ecryptfs
  86. * @mode: The mode of the new file
  87. * @nd: nameidata of ecryptfs' parent's dentry & vfsmount
  88. *
  89. * Creates the underlying file and the eCryptfs inode which will link to
  90. * it. It will also update the eCryptfs directory inode to mimic the
  91. * stat of the lower directory inode.
  92. *
  93. * Returns zero on success; non-zero on error condition
  94. */
  95. static int
  96. ecryptfs_do_create(struct inode *directory_inode,
  97. struct dentry *ecryptfs_dentry, int mode,
  98. struct nameidata *nd)
  99. {
  100. int rc;
  101. struct dentry *lower_dentry;
  102. struct dentry *lower_dir_dentry;
  103. lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
  104. lower_dir_dentry = lock_parent(lower_dentry);
  105. if (unlikely(IS_ERR(lower_dir_dentry))) {
  106. ecryptfs_printk(KERN_ERR, "Error locking directory of "
  107. "dentry\n");
  108. rc = PTR_ERR(lower_dir_dentry);
  109. goto out;
  110. }
  111. rc = ecryptfs_create_underlying_file(lower_dir_dentry->d_inode,
  112. ecryptfs_dentry, mode, nd);
  113. if (rc) {
  114. struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode;
  115. struct ecryptfs_inode_info *inode_info =
  116. ecryptfs_inode_to_private(ecryptfs_inode);
  117. printk(KERN_WARNING "%s: Error creating underlying file; "
  118. "rc = [%d]; checking for existing\n", __FUNCTION__, rc);
  119. if (inode_info) {
  120. mutex_lock(&inode_info->lower_file_mutex);
  121. if (!inode_info->lower_file) {
  122. mutex_unlock(&inode_info->lower_file_mutex);
  123. printk(KERN_ERR "%s: Failure to set underlying "
  124. "file; rc = [%d]\n", __FUNCTION__, rc);
  125. goto out_lock;
  126. }
  127. mutex_unlock(&inode_info->lower_file_mutex);
  128. }
  129. }
  130. rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry,
  131. directory_inode->i_sb, 0);
  132. if (rc) {
  133. ecryptfs_printk(KERN_ERR, "Failure in ecryptfs_interpose\n");
  134. goto out_lock;
  135. }
  136. fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
  137. fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
  138. out_lock:
  139. unlock_dir(lower_dir_dentry);
  140. out:
  141. return rc;
  142. }
  143. /**
  144. * grow_file
  145. * @ecryptfs_dentry: the eCryptfs dentry
  146. *
  147. * This is the code which will grow the file to its correct size.
  148. */
  149. static int grow_file(struct dentry *ecryptfs_dentry)
  150. {
  151. struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode;
  152. struct file fake_file;
  153. struct ecryptfs_file_info tmp_file_info;
  154. char zero_virt[] = { 0x00 };
  155. int rc = 0;
  156. memset(&fake_file, 0, sizeof(fake_file));
  157. fake_file.f_path.dentry = ecryptfs_dentry;
  158. memset(&tmp_file_info, 0, sizeof(tmp_file_info));
  159. ecryptfs_set_file_private(&fake_file, &tmp_file_info);
  160. ecryptfs_set_file_lower(
  161. &fake_file,
  162. ecryptfs_inode_to_private(ecryptfs_inode)->lower_file);
  163. rc = ecryptfs_write(&fake_file, zero_virt, 0, 1);
  164. i_size_write(ecryptfs_inode, 0);
  165. rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
  166. ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat.flags |=
  167. ECRYPTFS_NEW_FILE;
  168. return rc;
  169. }
  170. /**
  171. * ecryptfs_initialize_file
  172. *
  173. * Cause the file to be changed from a basic empty file to an ecryptfs
  174. * file with a header and first data page.
  175. *
  176. * Returns zero on success
  177. */
  178. static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
  179. {
  180. struct ecryptfs_crypt_stat *crypt_stat =
  181. &ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->crypt_stat;
  182. int rc = 0;
  183. if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
  184. ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
  185. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  186. goto out;
  187. }
  188. crypt_stat->flags |= ECRYPTFS_NEW_FILE;
  189. ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
  190. rc = ecryptfs_new_file_context(ecryptfs_dentry);
  191. if (rc) {
  192. ecryptfs_printk(KERN_ERR, "Error creating new file "
  193. "context; rc = [%d]\n", rc);
  194. goto out;
  195. }
  196. rc = ecryptfs_write_metadata(ecryptfs_dentry);
  197. if (rc) {
  198. printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc);
  199. goto out;
  200. }
  201. rc = grow_file(ecryptfs_dentry);
  202. if (rc)
  203. printk(KERN_ERR "Error growing file; rc = [%d]\n", rc);
  204. out:
  205. return rc;
  206. }
  207. /**
  208. * ecryptfs_create
  209. * @dir: The inode of the directory in which to create the file.
  210. * @dentry: The eCryptfs dentry
  211. * @mode: The mode of the new file.
  212. * @nd: nameidata
  213. *
  214. * Creates a new file.
  215. *
  216. * Returns zero on success; non-zero on error condition
  217. */
  218. static int
  219. ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
  220. int mode, struct nameidata *nd)
  221. {
  222. int rc;
  223. /* ecryptfs_do_create() calls ecryptfs_interpose(), which opens
  224. * the crypt_stat->lower_file (persistent file) */
  225. rc = ecryptfs_do_create(directory_inode, ecryptfs_dentry, mode, nd);
  226. if (unlikely(rc)) {
  227. ecryptfs_printk(KERN_WARNING, "Failed to create file in"
  228. "lower filesystem\n");
  229. goto out;
  230. }
  231. /* At this point, a file exists on "disk"; we need to make sure
  232. * that this on disk file is prepared to be an ecryptfs file */
  233. rc = ecryptfs_initialize_file(ecryptfs_dentry);
  234. out:
  235. return rc;
  236. }
  237. /**
  238. * ecryptfs_lookup
  239. * @dir: inode
  240. * @dentry: The dentry
  241. * @nd: nameidata, may be NULL
  242. *
  243. * Find a file on disk. If the file does not exist, then we'll add it to the
  244. * dentry cache and continue on to read it from the disk.
  245. */
  246. static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
  247. struct nameidata *nd)
  248. {
  249. int rc = 0;
  250. struct dentry *lower_dir_dentry;
  251. struct dentry *lower_dentry;
  252. struct vfsmount *lower_mnt;
  253. char *encoded_name;
  254. int encoded_namelen;
  255. struct ecryptfs_crypt_stat *crypt_stat = NULL;
  256. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  257. char *page_virt = NULL;
  258. struct inode *lower_inode;
  259. u64 file_size;
  260. lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent);
  261. dentry->d_op = &ecryptfs_dops;
  262. if ((dentry->d_name.len == 1 && !strcmp(dentry->d_name.name, "."))
  263. || (dentry->d_name.len == 2
  264. && !strcmp(dentry->d_name.name, ".."))) {
  265. d_drop(dentry);
  266. goto out;
  267. }
  268. encoded_namelen = ecryptfs_encode_filename(crypt_stat,
  269. dentry->d_name.name,
  270. dentry->d_name.len,
  271. &encoded_name);
  272. if (encoded_namelen < 0) {
  273. rc = encoded_namelen;
  274. d_drop(dentry);
  275. goto out;
  276. }
  277. ecryptfs_printk(KERN_DEBUG, "encoded_name = [%s]; encoded_namelen "
  278. "= [%d]\n", encoded_name, encoded_namelen);
  279. lower_dentry = lookup_one_len(encoded_name, lower_dir_dentry,
  280. encoded_namelen - 1);
  281. kfree(encoded_name);
  282. if (IS_ERR(lower_dentry)) {
  283. ecryptfs_printk(KERN_ERR, "ERR from lower_dentry\n");
  284. rc = PTR_ERR(lower_dentry);
  285. d_drop(dentry);
  286. goto out;
  287. }
  288. lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
  289. ecryptfs_printk(KERN_DEBUG, "lower_dentry = [%p]; lower_dentry->"
  290. "d_name.name = [%s]\n", lower_dentry,
  291. lower_dentry->d_name.name);
  292. lower_inode = lower_dentry->d_inode;
  293. fsstack_copy_attr_atime(dir, lower_dir_dentry->d_inode);
  294. BUG_ON(!atomic_read(&lower_dentry->d_count));
  295. ecryptfs_set_dentry_private(dentry,
  296. kmem_cache_alloc(ecryptfs_dentry_info_cache,
  297. GFP_KERNEL));
  298. if (!ecryptfs_dentry_to_private(dentry)) {
  299. rc = -ENOMEM;
  300. ecryptfs_printk(KERN_ERR, "Out of memory whilst attempting "
  301. "to allocate ecryptfs_dentry_info struct\n");
  302. goto out_dput;
  303. }
  304. ecryptfs_set_dentry_lower(dentry, lower_dentry);
  305. ecryptfs_set_dentry_lower_mnt(dentry, lower_mnt);
  306. if (!lower_dentry->d_inode) {
  307. /* We want to add because we couldn't find in lower */
  308. d_add(dentry, NULL);
  309. goto out;
  310. }
  311. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 1);
  312. if (rc) {
  313. ecryptfs_printk(KERN_ERR, "Error interposing\n");
  314. goto out_dput;
  315. }
  316. if (S_ISDIR(lower_inode->i_mode)) {
  317. ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n");
  318. goto out;
  319. }
  320. if (S_ISLNK(lower_inode->i_mode)) {
  321. ecryptfs_printk(KERN_DEBUG, "Is a symlink; returning\n");
  322. goto out;
  323. }
  324. if (special_file(lower_inode->i_mode)) {
  325. ecryptfs_printk(KERN_DEBUG, "Is a special file; returning\n");
  326. goto out;
  327. }
  328. if (!nd) {
  329. ecryptfs_printk(KERN_DEBUG, "We have a NULL nd, just leave"
  330. "as we *think* we are about to unlink\n");
  331. goto out;
  332. }
  333. /* Released in this function */
  334. page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2,
  335. GFP_USER);
  336. if (!page_virt) {
  337. rc = -ENOMEM;
  338. ecryptfs_printk(KERN_ERR,
  339. "Cannot ecryptfs_kmalloc a page\n");
  340. goto out_dput;
  341. }
  342. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  343. if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
  344. ecryptfs_set_default_sizes(crypt_stat);
  345. rc = ecryptfs_read_and_validate_header_region(page_virt,
  346. dentry->d_inode);
  347. if (rc) {
  348. rc = ecryptfs_read_and_validate_xattr_region(page_virt, dentry);
  349. if (rc) {
  350. printk(KERN_DEBUG "Valid metadata not found in header "
  351. "region or xattr region; treating file as "
  352. "unencrypted\n");
  353. rc = 0;
  354. kmem_cache_free(ecryptfs_header_cache_2, page_virt);
  355. goto out;
  356. }
  357. crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR;
  358. }
  359. mount_crypt_stat = &ecryptfs_superblock_to_private(
  360. dentry->d_sb)->mount_crypt_stat;
  361. if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) {
  362. if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR)
  363. file_size = ((crypt_stat->extent_size
  364. * crypt_stat->num_header_extents_at_front)
  365. + i_size_read(lower_dentry->d_inode));
  366. else
  367. file_size = i_size_read(lower_dentry->d_inode);
  368. } else {
  369. memcpy(&file_size, page_virt, sizeof(file_size));
  370. file_size = be64_to_cpu(file_size);
  371. }
  372. i_size_write(dentry->d_inode, (loff_t)file_size);
  373. kmem_cache_free(ecryptfs_header_cache_2, page_virt);
  374. goto out;
  375. out_dput:
  376. dput(lower_dentry);
  377. d_drop(dentry);
  378. out:
  379. return ERR_PTR(rc);
  380. }
  381. static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
  382. struct dentry *new_dentry)
  383. {
  384. struct dentry *lower_old_dentry;
  385. struct dentry *lower_new_dentry;
  386. struct dentry *lower_dir_dentry;
  387. u64 file_size_save;
  388. int rc;
  389. file_size_save = i_size_read(old_dentry->d_inode);
  390. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  391. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  392. dget(lower_old_dentry);
  393. dget(lower_new_dentry);
  394. lower_dir_dentry = lock_parent(lower_new_dentry);
  395. rc = vfs_link(lower_old_dentry, lower_dir_dentry->d_inode,
  396. lower_new_dentry);
  397. if (rc || !lower_new_dentry->d_inode)
  398. goto out_lock;
  399. rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
  400. if (rc)
  401. goto out_lock;
  402. fsstack_copy_attr_times(dir, lower_new_dentry->d_inode);
  403. fsstack_copy_inode_size(dir, lower_new_dentry->d_inode);
  404. old_dentry->d_inode->i_nlink =
  405. ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink;
  406. i_size_write(new_dentry->d_inode, file_size_save);
  407. out_lock:
  408. unlock_dir(lower_dir_dentry);
  409. dput(lower_new_dentry);
  410. dput(lower_old_dentry);
  411. d_drop(lower_old_dentry);
  412. d_drop(new_dentry);
  413. d_drop(old_dentry);
  414. return rc;
  415. }
  416. static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
  417. {
  418. int rc = 0;
  419. struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
  420. struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
  421. lock_parent(lower_dentry);
  422. rc = vfs_unlink(lower_dir_inode, lower_dentry);
  423. if (rc) {
  424. printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
  425. goto out_unlock;
  426. }
  427. fsstack_copy_attr_times(dir, lower_dir_inode);
  428. dentry->d_inode->i_nlink =
  429. ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink;
  430. dentry->d_inode->i_ctime = dir->i_ctime;
  431. out_unlock:
  432. unlock_parent(lower_dentry);
  433. return rc;
  434. }
  435. static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
  436. const char *symname)
  437. {
  438. int rc;
  439. struct dentry *lower_dentry;
  440. struct dentry *lower_dir_dentry;
  441. umode_t mode;
  442. char *encoded_symname;
  443. int encoded_symlen;
  444. struct ecryptfs_crypt_stat *crypt_stat = NULL;
  445. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  446. dget(lower_dentry);
  447. lower_dir_dentry = lock_parent(lower_dentry);
  448. mode = S_IALLUGO;
  449. encoded_symlen = ecryptfs_encode_filename(crypt_stat, symname,
  450. strlen(symname),
  451. &encoded_symname);
  452. if (encoded_symlen < 0) {
  453. rc = encoded_symlen;
  454. goto out_lock;
  455. }
  456. rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
  457. encoded_symname, mode);
  458. kfree(encoded_symname);
  459. if (rc || !lower_dentry->d_inode)
  460. goto out_lock;
  461. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
  462. if (rc)
  463. goto out_lock;
  464. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  465. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  466. out_lock:
  467. unlock_dir(lower_dir_dentry);
  468. dput(lower_dentry);
  469. if (!dentry->d_inode)
  470. d_drop(dentry);
  471. return rc;
  472. }
  473. static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
  474. {
  475. int rc;
  476. struct dentry *lower_dentry;
  477. struct dentry *lower_dir_dentry;
  478. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  479. lower_dir_dentry = lock_parent(lower_dentry);
  480. rc = vfs_mkdir(lower_dir_dentry->d_inode, lower_dentry, mode);
  481. if (rc || !lower_dentry->d_inode)
  482. goto out;
  483. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
  484. if (rc)
  485. goto out;
  486. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  487. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  488. dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
  489. out:
  490. unlock_dir(lower_dir_dentry);
  491. if (!dentry->d_inode)
  492. d_drop(dentry);
  493. return rc;
  494. }
  495. static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
  496. {
  497. struct dentry *lower_dentry;
  498. struct dentry *lower_dir_dentry;
  499. int rc;
  500. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  501. dget(dentry);
  502. lower_dir_dentry = lock_parent(lower_dentry);
  503. dget(lower_dentry);
  504. rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry);
  505. dput(lower_dentry);
  506. if (!rc)
  507. d_delete(lower_dentry);
  508. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  509. dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
  510. unlock_dir(lower_dir_dentry);
  511. if (!rc)
  512. d_drop(dentry);
  513. dput(dentry);
  514. return rc;
  515. }
  516. static int
  517. ecryptfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
  518. {
  519. int rc;
  520. struct dentry *lower_dentry;
  521. struct dentry *lower_dir_dentry;
  522. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  523. lower_dir_dentry = lock_parent(lower_dentry);
  524. rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
  525. if (rc || !lower_dentry->d_inode)
  526. goto out;
  527. rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
  528. if (rc)
  529. goto out;
  530. fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
  531. fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
  532. out:
  533. unlock_dir(lower_dir_dentry);
  534. if (!dentry->d_inode)
  535. d_drop(dentry);
  536. return rc;
  537. }
  538. static int
  539. ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  540. struct inode *new_dir, struct dentry *new_dentry)
  541. {
  542. int rc;
  543. struct dentry *lower_old_dentry;
  544. struct dentry *lower_new_dentry;
  545. struct dentry *lower_old_dir_dentry;
  546. struct dentry *lower_new_dir_dentry;
  547. lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
  548. lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry);
  549. dget(lower_old_dentry);
  550. dget(lower_new_dentry);
  551. lower_old_dir_dentry = dget_parent(lower_old_dentry);
  552. lower_new_dir_dentry = dget_parent(lower_new_dentry);
  553. lock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  554. rc = vfs_rename(lower_old_dir_dentry->d_inode, lower_old_dentry,
  555. lower_new_dir_dentry->d_inode, lower_new_dentry);
  556. if (rc)
  557. goto out_lock;
  558. fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL);
  559. if (new_dir != old_dir)
  560. fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL);
  561. out_lock:
  562. unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
  563. dput(lower_new_dentry->d_parent);
  564. dput(lower_old_dentry->d_parent);
  565. dput(lower_new_dentry);
  566. dput(lower_old_dentry);
  567. return rc;
  568. }
  569. static int
  570. ecryptfs_readlink(struct dentry *dentry, char __user * buf, int bufsiz)
  571. {
  572. int rc;
  573. struct dentry *lower_dentry;
  574. char *decoded_name;
  575. char *lower_buf;
  576. mm_segment_t old_fs;
  577. struct ecryptfs_crypt_stat *crypt_stat;
  578. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  579. if (!lower_dentry->d_inode->i_op ||
  580. !lower_dentry->d_inode->i_op->readlink) {
  581. rc = -EINVAL;
  582. goto out;
  583. }
  584. /* Released in this function */
  585. lower_buf = kmalloc(bufsiz, GFP_KERNEL);
  586. if (lower_buf == NULL) {
  587. ecryptfs_printk(KERN_ERR, "Out of memory\n");
  588. rc = -ENOMEM;
  589. goto out;
  590. }
  591. old_fs = get_fs();
  592. set_fs(get_ds());
  593. ecryptfs_printk(KERN_DEBUG, "Calling readlink w/ "
  594. "lower_dentry->d_name.name = [%s]\n",
  595. lower_dentry->d_name.name);
  596. rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
  597. (char __user *)lower_buf,
  598. bufsiz);
  599. set_fs(old_fs);
  600. if (rc >= 0) {
  601. crypt_stat = NULL;
  602. rc = ecryptfs_decode_filename(crypt_stat, lower_buf, rc,
  603. &decoded_name);
  604. if (rc == -ENOMEM)
  605. goto out_free_lower_buf;
  606. if (rc > 0) {
  607. ecryptfs_printk(KERN_DEBUG, "Copying [%d] bytes "
  608. "to userspace: [%*s]\n", rc,
  609. decoded_name);
  610. if (copy_to_user(buf, decoded_name, rc))
  611. rc = -EFAULT;
  612. }
  613. kfree(decoded_name);
  614. fsstack_copy_attr_atime(dentry->d_inode,
  615. lower_dentry->d_inode);
  616. }
  617. out_free_lower_buf:
  618. kfree(lower_buf);
  619. out:
  620. return rc;
  621. }
  622. static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
  623. {
  624. char *buf;
  625. int len = PAGE_SIZE, rc;
  626. mm_segment_t old_fs;
  627. /* Released in ecryptfs_put_link(); only release here on error */
  628. buf = kmalloc(len, GFP_KERNEL);
  629. if (!buf) {
  630. rc = -ENOMEM;
  631. goto out;
  632. }
  633. old_fs = get_fs();
  634. set_fs(get_ds());
  635. ecryptfs_printk(KERN_DEBUG, "Calling readlink w/ "
  636. "dentry->d_name.name = [%s]\n", dentry->d_name.name);
  637. rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
  638. buf[rc] = '\0';
  639. set_fs(old_fs);
  640. if (rc < 0)
  641. goto out_free;
  642. rc = 0;
  643. nd_set_link(nd, buf);
  644. goto out;
  645. out_free:
  646. kfree(buf);
  647. out:
  648. return ERR_PTR(rc);
  649. }
  650. static void
  651. ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
  652. {
  653. /* Free the char* */
  654. kfree(nd_get_link(nd));
  655. }
  656. /**
  657. * upper_size_to_lower_size
  658. * @crypt_stat: Crypt_stat associated with file
  659. * @upper_size: Size of the upper file
  660. *
  661. * Calculate the requried size of the lower file based on the
  662. * specified size of the upper file. This calculation is based on the
  663. * number of headers in the underlying file and the extent size.
  664. *
  665. * Returns Calculated size of the lower file.
  666. */
  667. static loff_t
  668. upper_size_to_lower_size(struct ecryptfs_crypt_stat *crypt_stat,
  669. loff_t upper_size)
  670. {
  671. loff_t lower_size;
  672. lower_size = (crypt_stat->extent_size
  673. * crypt_stat->num_header_extents_at_front);
  674. if (upper_size != 0) {
  675. loff_t num_extents;
  676. num_extents = upper_size >> crypt_stat->extent_shift;
  677. if (upper_size & ~crypt_stat->extent_mask)
  678. num_extents++;
  679. lower_size += (num_extents * crypt_stat->extent_size);
  680. }
  681. return lower_size;
  682. }
  683. /**
  684. * ecryptfs_truncate
  685. * @dentry: The ecryptfs layer dentry
  686. * @new_length: The length to expand the file to
  687. *
  688. * Function to handle truncations modifying the size of the file. Note
  689. * that the file sizes are interpolated. When expanding, we are simply
  690. * writing strings of 0's out. When truncating, we need to modify the
  691. * underlying file size according to the page index interpolations.
  692. *
  693. * Returns zero on success; non-zero otherwise
  694. */
  695. int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
  696. {
  697. int rc = 0;
  698. struct inode *inode = dentry->d_inode;
  699. struct dentry *lower_dentry;
  700. struct vfsmount *lower_mnt;
  701. struct file fake_ecryptfs_file, *lower_file = NULL;
  702. struct ecryptfs_crypt_stat *crypt_stat;
  703. loff_t i_size = i_size_read(inode);
  704. loff_t lower_size_before_truncate;
  705. loff_t lower_size_after_truncate;
  706. if (unlikely((new_length == i_size)))
  707. goto out;
  708. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  709. /* Set up a fake ecryptfs file, this is used to interface with
  710. * the file in the underlying filesystem so that the
  711. * truncation has an effect there as well. */
  712. memset(&fake_ecryptfs_file, 0, sizeof(fake_ecryptfs_file));
  713. fake_ecryptfs_file.f_path.dentry = dentry;
  714. /* Released at out_free: label */
  715. ecryptfs_set_file_private(&fake_ecryptfs_file,
  716. kmem_cache_alloc(ecryptfs_file_info_cache,
  717. GFP_KERNEL));
  718. if (unlikely(!ecryptfs_file_to_private(&fake_ecryptfs_file))) {
  719. rc = -ENOMEM;
  720. goto out;
  721. }
  722. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  723. /* This dget & mntget is released through fput at out_fput: */
  724. lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
  725. rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt,
  726. O_RDWR);
  727. if (rc) {
  728. ecryptfs_printk(KERN_ERR,
  729. "Error opening dentry; rc = [%i]\n", rc);
  730. goto out_free;
  731. }
  732. ecryptfs_set_file_lower(&fake_ecryptfs_file, lower_file);
  733. /* Switch on growing or shrinking file */
  734. if (new_length > i_size) {
  735. rc = ecryptfs_fill_zeros(&fake_ecryptfs_file, new_length);
  736. if (rc) {
  737. ecryptfs_printk(KERN_ERR,
  738. "Problem with fill_zeros\n");
  739. goto out_fput;
  740. }
  741. i_size_write(inode, new_length);
  742. rc = ecryptfs_write_inode_size_to_metadata(inode);
  743. if (rc) {
  744. printk(KERN_ERR "Problem with "
  745. "ecryptfs_write_inode_size_to_metadata; "
  746. "rc = [%d]\n", rc);
  747. goto out_fput;
  748. }
  749. } else { /* new_length < i_size_read(inode) */
  750. pgoff_t index = 0;
  751. int end_pos_in_page = -1;
  752. if (new_length != 0) {
  753. index = ((new_length - 1) >> PAGE_CACHE_SHIFT);
  754. end_pos_in_page = ((new_length - 1) & ~PAGE_CACHE_MASK);
  755. }
  756. if (end_pos_in_page != (PAGE_CACHE_SIZE - 1)) {
  757. rc = ecryptfs_write_zeros(&fake_ecryptfs_file,
  758. index,
  759. (end_pos_in_page + 1),
  760. ((PAGE_CACHE_SIZE - 1)
  761. - end_pos_in_page));
  762. if (rc) {
  763. printk(KERN_ERR "Error attempting to zero out "
  764. "the remainder of the end page on "
  765. "reducing truncate; rc = [%d]\n", rc);
  766. goto out_fput;
  767. }
  768. }
  769. vmtruncate(inode, new_length);
  770. rc = ecryptfs_write_inode_size_to_metadata(inode);
  771. if (rc) {
  772. printk(KERN_ERR "Problem with "
  773. "ecryptfs_write_inode_size_to_metadata; "
  774. "rc = [%d]\n", rc);
  775. goto out_fput;
  776. }
  777. /* We are reducing the size of the ecryptfs file, and need to
  778. * know if we need to reduce the size of the lower file. */
  779. lower_size_before_truncate =
  780. upper_size_to_lower_size(crypt_stat, i_size);
  781. lower_size_after_truncate =
  782. upper_size_to_lower_size(crypt_stat, new_length);
  783. if (lower_size_after_truncate < lower_size_before_truncate)
  784. vmtruncate(lower_dentry->d_inode,
  785. lower_size_after_truncate);
  786. }
  787. /* Update the access times */
  788. lower_dentry->d_inode->i_mtime = lower_dentry->d_inode->i_ctime
  789. = CURRENT_TIME;
  790. mark_inode_dirty_sync(inode);
  791. out_fput:
  792. rc = ecryptfs_close_lower_file(lower_file);
  793. if (rc)
  794. printk(KERN_ERR "Error closing lower_file\n");
  795. out_free:
  796. if (ecryptfs_file_to_private(&fake_ecryptfs_file))
  797. kmem_cache_free(ecryptfs_file_info_cache,
  798. ecryptfs_file_to_private(&fake_ecryptfs_file));
  799. out:
  800. return rc;
  801. }
  802. static int
  803. ecryptfs_permission(struct inode *inode, int mask, struct nameidata *nd)
  804. {
  805. int rc;
  806. if (nd) {
  807. struct vfsmount *vfsmnt_save = nd->mnt;
  808. struct dentry *dentry_save = nd->dentry;
  809. nd->mnt = ecryptfs_dentry_to_lower_mnt(nd->dentry);
  810. nd->dentry = ecryptfs_dentry_to_lower(nd->dentry);
  811. rc = permission(ecryptfs_inode_to_lower(inode), mask, nd);
  812. nd->mnt = vfsmnt_save;
  813. nd->dentry = dentry_save;
  814. } else
  815. rc = permission(ecryptfs_inode_to_lower(inode), mask, NULL);
  816. return rc;
  817. }
  818. /**
  819. * ecryptfs_setattr
  820. * @dentry: dentry handle to the inode to modify
  821. * @ia: Structure with flags of what to change and values
  822. *
  823. * Updates the metadata of an inode. If the update is to the size
  824. * i.e. truncation, then ecryptfs_truncate will handle the size modification
  825. * of both the ecryptfs inode and the lower inode.
  826. *
  827. * All other metadata changes will be passed right to the lower filesystem,
  828. * and we will just update our inode to look like the lower.
  829. */
  830. static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
  831. {
  832. int rc = 0;
  833. struct dentry *lower_dentry;
  834. struct inode *inode;
  835. struct inode *lower_inode;
  836. struct ecryptfs_crypt_stat *crypt_stat;
  837. crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
  838. if (!(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED))
  839. ecryptfs_init_crypt_stat(crypt_stat);
  840. inode = dentry->d_inode;
  841. lower_inode = ecryptfs_inode_to_lower(inode);
  842. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  843. mutex_lock(&crypt_stat->cs_mutex);
  844. if (S_ISDIR(dentry->d_inode->i_mode))
  845. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  846. else if (S_ISREG(dentry->d_inode->i_mode)
  847. && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
  848. || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) {
  849. struct vfsmount *lower_mnt;
  850. struct file *lower_file = NULL;
  851. struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
  852. int lower_flags;
  853. lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
  854. lower_flags = O_RDONLY;
  855. rc = ecryptfs_open_lower_file(&lower_file, lower_dentry,
  856. lower_mnt, lower_flags);
  857. if (rc) {
  858. printk(KERN_ERR
  859. "Error opening lower file; rc = [%d]\n", rc);
  860. mutex_unlock(&crypt_stat->cs_mutex);
  861. goto out;
  862. }
  863. mount_crypt_stat = &ecryptfs_superblock_to_private(
  864. dentry->d_sb)->mount_crypt_stat;
  865. rc = ecryptfs_read_metadata(dentry);
  866. if (rc) {
  867. if (!(mount_crypt_stat->flags
  868. & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
  869. rc = -EIO;
  870. printk(KERN_WARNING "Attempt to read file that "
  871. "is not in a valid eCryptfs format, "
  872. "and plaintext passthrough mode is not "
  873. "enabled; returning -EIO\n");
  874. mutex_unlock(&crypt_stat->cs_mutex);
  875. fput(lower_file);
  876. goto out;
  877. }
  878. rc = 0;
  879. crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
  880. mutex_unlock(&crypt_stat->cs_mutex);
  881. fput(lower_file);
  882. goto out;
  883. }
  884. fput(lower_file);
  885. }
  886. mutex_unlock(&crypt_stat->cs_mutex);
  887. if (ia->ia_valid & ATTR_SIZE) {
  888. ecryptfs_printk(KERN_DEBUG,
  889. "ia->ia_valid = [0x%x] ATTR_SIZE" " = [0x%x]\n",
  890. ia->ia_valid, ATTR_SIZE);
  891. rc = ecryptfs_truncate(dentry, ia->ia_size);
  892. /* ecryptfs_truncate handles resizing of the lower file */
  893. ia->ia_valid &= ~ATTR_SIZE;
  894. ecryptfs_printk(KERN_DEBUG, "ia->ia_valid = [%x]\n",
  895. ia->ia_valid);
  896. if (rc < 0)
  897. goto out;
  898. }
  899. rc = notify_change(lower_dentry, ia);
  900. out:
  901. fsstack_copy_attr_all(inode, lower_inode, NULL);
  902. return rc;
  903. }
  904. int
  905. ecryptfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  906. size_t size, int flags)
  907. {
  908. int rc = 0;
  909. struct dentry *lower_dentry;
  910. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  911. if (!lower_dentry->d_inode->i_op->setxattr) {
  912. rc = -ENOSYS;
  913. goto out;
  914. }
  915. mutex_lock(&lower_dentry->d_inode->i_mutex);
  916. rc = lower_dentry->d_inode->i_op->setxattr(lower_dentry, name, value,
  917. size, flags);
  918. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  919. out:
  920. return rc;
  921. }
  922. ssize_t
  923. ecryptfs_getxattr_lower(struct dentry *lower_dentry, const char *name,
  924. void *value, size_t size)
  925. {
  926. int rc = 0;
  927. if (!lower_dentry->d_inode->i_op->getxattr) {
  928. rc = -ENOSYS;
  929. goto out;
  930. }
  931. mutex_lock(&lower_dentry->d_inode->i_mutex);
  932. rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value,
  933. size);
  934. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  935. out:
  936. return rc;
  937. }
  938. ssize_t
  939. ecryptfs_getxattr(struct dentry *dentry, const char *name, void *value,
  940. size_t size)
  941. {
  942. int rc = 0;
  943. struct dentry *lower_dentry;
  944. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  945. if (!lower_dentry->d_inode->i_op->getxattr) {
  946. rc = -ENOSYS;
  947. goto out;
  948. }
  949. mutex_lock(&lower_dentry->d_inode->i_mutex);
  950. rc = lower_dentry->d_inode->i_op->getxattr(lower_dentry, name, value,
  951. size);
  952. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  953. out:
  954. return rc;
  955. }
  956. static ssize_t
  957. ecryptfs_listxattr(struct dentry *dentry, char *list, size_t size)
  958. {
  959. int rc = 0;
  960. struct dentry *lower_dentry;
  961. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  962. if (!lower_dentry->d_inode->i_op->listxattr) {
  963. rc = -ENOSYS;
  964. goto out;
  965. }
  966. mutex_lock(&lower_dentry->d_inode->i_mutex);
  967. rc = lower_dentry->d_inode->i_op->listxattr(lower_dentry, list, size);
  968. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  969. out:
  970. return rc;
  971. }
  972. static int ecryptfs_removexattr(struct dentry *dentry, const char *name)
  973. {
  974. int rc = 0;
  975. struct dentry *lower_dentry;
  976. lower_dentry = ecryptfs_dentry_to_lower(dentry);
  977. if (!lower_dentry->d_inode->i_op->removexattr) {
  978. rc = -ENOSYS;
  979. goto out;
  980. }
  981. mutex_lock(&lower_dentry->d_inode->i_mutex);
  982. rc = lower_dentry->d_inode->i_op->removexattr(lower_dentry, name);
  983. mutex_unlock(&lower_dentry->d_inode->i_mutex);
  984. out:
  985. return rc;
  986. }
  987. int ecryptfs_inode_test(struct inode *inode, void *candidate_lower_inode)
  988. {
  989. if ((ecryptfs_inode_to_lower(inode)
  990. == (struct inode *)candidate_lower_inode))
  991. return 1;
  992. else
  993. return 0;
  994. }
  995. int ecryptfs_inode_set(struct inode *inode, void *lower_inode)
  996. {
  997. ecryptfs_init_inode(inode, (struct inode *)lower_inode);
  998. return 0;
  999. }
  1000. const struct inode_operations ecryptfs_symlink_iops = {
  1001. .readlink = ecryptfs_readlink,
  1002. .follow_link = ecryptfs_follow_link,
  1003. .put_link = ecryptfs_put_link,
  1004. .permission = ecryptfs_permission,
  1005. .setattr = ecryptfs_setattr,
  1006. .setxattr = ecryptfs_setxattr,
  1007. .getxattr = ecryptfs_getxattr,
  1008. .listxattr = ecryptfs_listxattr,
  1009. .removexattr = ecryptfs_removexattr
  1010. };
  1011. const struct inode_operations ecryptfs_dir_iops = {
  1012. .create = ecryptfs_create,
  1013. .lookup = ecryptfs_lookup,
  1014. .link = ecryptfs_link,
  1015. .unlink = ecryptfs_unlink,
  1016. .symlink = ecryptfs_symlink,
  1017. .mkdir = ecryptfs_mkdir,
  1018. .rmdir = ecryptfs_rmdir,
  1019. .mknod = ecryptfs_mknod,
  1020. .rename = ecryptfs_rename,
  1021. .permission = ecryptfs_permission,
  1022. .setattr = ecryptfs_setattr,
  1023. .setxattr = ecryptfs_setxattr,
  1024. .getxattr = ecryptfs_getxattr,
  1025. .listxattr = ecryptfs_listxattr,
  1026. .removexattr = ecryptfs_removexattr
  1027. };
  1028. const struct inode_operations ecryptfs_main_iops = {
  1029. .permission = ecryptfs_permission,
  1030. .setattr = ecryptfs_setattr,
  1031. .setxattr = ecryptfs_setxattr,
  1032. .getxattr = ecryptfs_getxattr,
  1033. .listxattr = ecryptfs_listxattr,
  1034. .removexattr = ecryptfs_removexattr
  1035. };