inode.c 32 KB

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