inode.c 32 KB

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