inode.c 32 KB

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