inode.c 32 KB

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