inode.c 32 KB

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