inode.c 33 KB

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