inode.c 32 KB

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