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