inode.c 32 KB

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