inode.c 33 KB

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