inode.c 32 KB

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