inode.c 33 KB

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