xfs_iops.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_bit.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_dir2.h"
  27. #include "xfs_alloc.h"
  28. #include "xfs_dmapi.h"
  29. #include "xfs_quota.h"
  30. #include "xfs_mount.h"
  31. #include "xfs_bmap_btree.h"
  32. #include "xfs_alloc_btree.h"
  33. #include "xfs_ialloc_btree.h"
  34. #include "xfs_dir2_sf.h"
  35. #include "xfs_attr_sf.h"
  36. #include "xfs_dinode.h"
  37. #include "xfs_inode.h"
  38. #include "xfs_bmap.h"
  39. #include "xfs_btree.h"
  40. #include "xfs_ialloc.h"
  41. #include "xfs_rtalloc.h"
  42. #include "xfs_error.h"
  43. #include "xfs_itable.h"
  44. #include "xfs_rw.h"
  45. #include "xfs_acl.h"
  46. #include "xfs_attr.h"
  47. #include "xfs_buf_item.h"
  48. #include "xfs_utils.h"
  49. #include "xfs_vnodeops.h"
  50. #include <linux/capability.h>
  51. #include <linux/xattr.h>
  52. #include <linux/namei.h>
  53. #include <linux/security.h>
  54. #include <linux/falloc.h>
  55. /*
  56. * Bring the atime in the XFS inode uptodate.
  57. * Used before logging the inode to disk or when the Linux inode goes away.
  58. */
  59. void
  60. xfs_synchronize_atime(
  61. xfs_inode_t *ip)
  62. {
  63. struct inode *inode = VFS_I(ip);
  64. if (inode) {
  65. ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
  66. ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
  67. }
  68. }
  69. /*
  70. * If the linux inode exists, mark it dirty.
  71. * Used when commiting a dirty inode into a transaction so that
  72. * the inode will get written back by the linux code
  73. */
  74. void
  75. xfs_mark_inode_dirty_sync(
  76. xfs_inode_t *ip)
  77. {
  78. struct inode *inode = VFS_I(ip);
  79. if (inode)
  80. mark_inode_dirty_sync(inode);
  81. }
  82. /*
  83. * Change the requested timestamp in the given inode.
  84. * We don't lock across timestamp updates, and we don't log them but
  85. * we do record the fact that there is dirty information in core.
  86. */
  87. void
  88. xfs_ichgtime(
  89. xfs_inode_t *ip,
  90. int flags)
  91. {
  92. struct inode *inode = VFS_I(ip);
  93. timespec_t tv;
  94. int sync_it = 0;
  95. tv = current_fs_time(inode->i_sb);
  96. if ((flags & XFS_ICHGTIME_MOD) &&
  97. !timespec_equal(&inode->i_mtime, &tv)) {
  98. inode->i_mtime = tv;
  99. ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
  100. ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
  101. sync_it = 1;
  102. }
  103. if ((flags & XFS_ICHGTIME_CHG) &&
  104. !timespec_equal(&inode->i_ctime, &tv)) {
  105. inode->i_ctime = tv;
  106. ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
  107. ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
  108. sync_it = 1;
  109. }
  110. /*
  111. * We update the i_update_core field _after_ changing
  112. * the timestamps in order to coordinate properly with
  113. * xfs_iflush() so that we don't lose timestamp updates.
  114. * This keeps us from having to hold the inode lock
  115. * while doing this. We use the SYNCHRONIZE macro to
  116. * ensure that the compiler does not reorder the update
  117. * of i_update_core above the timestamp updates above.
  118. */
  119. if (sync_it) {
  120. SYNCHRONIZE();
  121. ip->i_update_core = 1;
  122. mark_inode_dirty_sync(inode);
  123. }
  124. }
  125. /*
  126. * Hook in SELinux. This is not quite correct yet, what we really need
  127. * here (as we do for default ACLs) is a mechanism by which creation of
  128. * these attrs can be journalled at inode creation time (along with the
  129. * inode, of course, such that log replay can't cause these to be lost).
  130. */
  131. STATIC int
  132. xfs_init_security(
  133. struct inode *inode,
  134. struct inode *dir)
  135. {
  136. struct xfs_inode *ip = XFS_I(inode);
  137. size_t length;
  138. void *value;
  139. char *name;
  140. int error;
  141. error = security_inode_init_security(inode, dir, &name,
  142. &value, &length);
  143. if (error) {
  144. if (error == -EOPNOTSUPP)
  145. return 0;
  146. return -error;
  147. }
  148. error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
  149. if (!error)
  150. xfs_iflags_set(ip, XFS_IMODIFIED);
  151. kfree(name);
  152. kfree(value);
  153. return error;
  154. }
  155. static void
  156. xfs_dentry_to_name(
  157. struct xfs_name *namep,
  158. struct dentry *dentry)
  159. {
  160. namep->name = dentry->d_name.name;
  161. namep->len = dentry->d_name.len;
  162. }
  163. STATIC void
  164. xfs_cleanup_inode(
  165. struct inode *dir,
  166. struct inode *inode,
  167. struct dentry *dentry)
  168. {
  169. struct xfs_name teardown;
  170. /* Oh, the horror.
  171. * If we can't add the ACL or we fail in
  172. * xfs_init_security we must back out.
  173. * ENOSPC can hit here, among other things.
  174. */
  175. xfs_dentry_to_name(&teardown, dentry);
  176. xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
  177. iput(inode);
  178. }
  179. STATIC int
  180. xfs_vn_mknod(
  181. struct inode *dir,
  182. struct dentry *dentry,
  183. int mode,
  184. dev_t rdev)
  185. {
  186. struct inode *inode;
  187. struct xfs_inode *ip = NULL;
  188. xfs_acl_t *default_acl = NULL;
  189. struct xfs_name name;
  190. int (*test_default_acl)(struct inode *) = _ACL_DEFAULT_EXISTS;
  191. int error;
  192. /*
  193. * Irix uses Missed'em'V split, but doesn't want to see
  194. * the upper 5 bits of (14bit) major.
  195. */
  196. if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
  197. return -EINVAL;
  198. if (test_default_acl && test_default_acl(dir)) {
  199. if (!_ACL_ALLOC(default_acl)) {
  200. return -ENOMEM;
  201. }
  202. if (!_ACL_GET_DEFAULT(dir, default_acl)) {
  203. _ACL_FREE(default_acl);
  204. default_acl = NULL;
  205. }
  206. }
  207. xfs_dentry_to_name(&name, dentry);
  208. if (IS_POSIXACL(dir) && !default_acl)
  209. mode &= ~current->fs->umask;
  210. switch (mode & S_IFMT) {
  211. case S_IFCHR:
  212. case S_IFBLK:
  213. case S_IFIFO:
  214. case S_IFSOCK:
  215. rdev = sysv_encode_dev(rdev);
  216. case S_IFREG:
  217. error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip, NULL);
  218. break;
  219. case S_IFDIR:
  220. error = xfs_mkdir(XFS_I(dir), &name, mode, &ip, NULL);
  221. break;
  222. default:
  223. error = EINVAL;
  224. break;
  225. }
  226. if (unlikely(error))
  227. goto out_free_acl;
  228. inode = VFS_I(ip);
  229. error = xfs_init_security(inode, dir);
  230. if (unlikely(error))
  231. goto out_cleanup_inode;
  232. if (default_acl) {
  233. error = _ACL_INHERIT(inode, mode, default_acl);
  234. if (unlikely(error))
  235. goto out_cleanup_inode;
  236. xfs_iflags_set(ip, XFS_IMODIFIED);
  237. _ACL_FREE(default_acl);
  238. }
  239. d_instantiate(dentry, inode);
  240. return -error;
  241. out_cleanup_inode:
  242. xfs_cleanup_inode(dir, inode, dentry);
  243. out_free_acl:
  244. if (default_acl)
  245. _ACL_FREE(default_acl);
  246. return -error;
  247. }
  248. STATIC int
  249. xfs_vn_create(
  250. struct inode *dir,
  251. struct dentry *dentry,
  252. int mode,
  253. struct nameidata *nd)
  254. {
  255. return xfs_vn_mknod(dir, dentry, mode, 0);
  256. }
  257. STATIC int
  258. xfs_vn_mkdir(
  259. struct inode *dir,
  260. struct dentry *dentry,
  261. int mode)
  262. {
  263. return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
  264. }
  265. STATIC struct dentry *
  266. xfs_vn_lookup(
  267. struct inode *dir,
  268. struct dentry *dentry,
  269. struct nameidata *nd)
  270. {
  271. struct xfs_inode *cip;
  272. struct xfs_name name;
  273. int error;
  274. if (dentry->d_name.len >= MAXNAMELEN)
  275. return ERR_PTR(-ENAMETOOLONG);
  276. xfs_dentry_to_name(&name, dentry);
  277. error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
  278. if (unlikely(error)) {
  279. if (unlikely(error != ENOENT))
  280. return ERR_PTR(-error);
  281. d_add(dentry, NULL);
  282. return NULL;
  283. }
  284. return d_splice_alias(VFS_I(cip), dentry);
  285. }
  286. STATIC struct dentry *
  287. xfs_vn_ci_lookup(
  288. struct inode *dir,
  289. struct dentry *dentry,
  290. struct nameidata *nd)
  291. {
  292. struct xfs_inode *ip;
  293. struct xfs_name xname;
  294. struct xfs_name ci_name;
  295. struct qstr dname;
  296. int error;
  297. if (dentry->d_name.len >= MAXNAMELEN)
  298. return ERR_PTR(-ENAMETOOLONG);
  299. xfs_dentry_to_name(&xname, dentry);
  300. error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
  301. if (unlikely(error)) {
  302. if (unlikely(error != ENOENT))
  303. return ERR_PTR(-error);
  304. /*
  305. * call d_add(dentry, NULL) here when d_drop_negative_children
  306. * is called in xfs_vn_mknod (ie. allow negative dentries
  307. * with CI filesystems).
  308. */
  309. return NULL;
  310. }
  311. /* if exact match, just splice and exit */
  312. if (!ci_name.name)
  313. return d_splice_alias(VFS_I(ip), dentry);
  314. /* else case-insensitive match... */
  315. dname.name = ci_name.name;
  316. dname.len = ci_name.len;
  317. dentry = d_add_ci(dentry, VFS_I(ip), &dname);
  318. kmem_free(ci_name.name);
  319. return dentry;
  320. }
  321. STATIC int
  322. xfs_vn_link(
  323. struct dentry *old_dentry,
  324. struct inode *dir,
  325. struct dentry *dentry)
  326. {
  327. struct inode *inode; /* inode of guy being linked to */
  328. struct xfs_name name;
  329. int error;
  330. inode = old_dentry->d_inode;
  331. xfs_dentry_to_name(&name, dentry);
  332. igrab(inode);
  333. error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
  334. if (unlikely(error)) {
  335. iput(inode);
  336. return -error;
  337. }
  338. xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
  339. d_instantiate(dentry, inode);
  340. return 0;
  341. }
  342. STATIC int
  343. xfs_vn_unlink(
  344. struct inode *dir,
  345. struct dentry *dentry)
  346. {
  347. struct xfs_name name;
  348. int error;
  349. xfs_dentry_to_name(&name, dentry);
  350. error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
  351. if (error)
  352. return error;
  353. /*
  354. * With unlink, the VFS makes the dentry "negative": no inode,
  355. * but still hashed. This is incompatible with case-insensitive
  356. * mode, so invalidate (unhash) the dentry in CI-mode.
  357. */
  358. if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
  359. d_invalidate(dentry);
  360. return 0;
  361. }
  362. STATIC int
  363. xfs_vn_symlink(
  364. struct inode *dir,
  365. struct dentry *dentry,
  366. const char *symname)
  367. {
  368. struct inode *inode;
  369. struct xfs_inode *cip = NULL;
  370. struct xfs_name name;
  371. int error;
  372. mode_t mode;
  373. mode = S_IFLNK |
  374. (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
  375. xfs_dentry_to_name(&name, dentry);
  376. error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
  377. if (unlikely(error))
  378. goto out;
  379. inode = VFS_I(cip);
  380. error = xfs_init_security(inode, dir);
  381. if (unlikely(error))
  382. goto out_cleanup_inode;
  383. d_instantiate(dentry, inode);
  384. return 0;
  385. out_cleanup_inode:
  386. xfs_cleanup_inode(dir, inode, dentry);
  387. out:
  388. return -error;
  389. }
  390. STATIC int
  391. xfs_vn_rename(
  392. struct inode *odir,
  393. struct dentry *odentry,
  394. struct inode *ndir,
  395. struct dentry *ndentry)
  396. {
  397. struct inode *new_inode = ndentry->d_inode;
  398. struct xfs_name oname;
  399. struct xfs_name nname;
  400. xfs_dentry_to_name(&oname, odentry);
  401. xfs_dentry_to_name(&nname, ndentry);
  402. return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
  403. XFS_I(ndir), &nname, new_inode ?
  404. XFS_I(new_inode) : NULL);
  405. }
  406. /*
  407. * careful here - this function can get called recursively, so
  408. * we need to be very careful about how much stack we use.
  409. * uio is kmalloced for this reason...
  410. */
  411. STATIC void *
  412. xfs_vn_follow_link(
  413. struct dentry *dentry,
  414. struct nameidata *nd)
  415. {
  416. char *link;
  417. int error = -ENOMEM;
  418. link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
  419. if (!link)
  420. goto out_err;
  421. error = -xfs_readlink(XFS_I(dentry->d_inode), link);
  422. if (unlikely(error))
  423. goto out_kfree;
  424. nd_set_link(nd, link);
  425. return NULL;
  426. out_kfree:
  427. kfree(link);
  428. out_err:
  429. nd_set_link(nd, ERR_PTR(error));
  430. return NULL;
  431. }
  432. STATIC void
  433. xfs_vn_put_link(
  434. struct dentry *dentry,
  435. struct nameidata *nd,
  436. void *p)
  437. {
  438. char *s = nd_get_link(nd);
  439. if (!IS_ERR(s))
  440. kfree(s);
  441. }
  442. #ifdef CONFIG_XFS_POSIX_ACL
  443. STATIC int
  444. xfs_check_acl(
  445. struct inode *inode,
  446. int mask)
  447. {
  448. struct xfs_inode *ip = XFS_I(inode);
  449. int error;
  450. xfs_itrace_entry(ip);
  451. if (XFS_IFORK_Q(ip)) {
  452. error = xfs_acl_iaccess(ip, mask, NULL);
  453. if (error != -1)
  454. return -error;
  455. }
  456. return -EAGAIN;
  457. }
  458. STATIC int
  459. xfs_vn_permission(
  460. struct inode *inode,
  461. int mask)
  462. {
  463. return generic_permission(inode, mask, xfs_check_acl);
  464. }
  465. #else
  466. #define xfs_vn_permission NULL
  467. #endif
  468. STATIC int
  469. xfs_vn_getattr(
  470. struct vfsmount *mnt,
  471. struct dentry *dentry,
  472. struct kstat *stat)
  473. {
  474. struct inode *inode = dentry->d_inode;
  475. struct xfs_inode *ip = XFS_I(inode);
  476. struct xfs_mount *mp = ip->i_mount;
  477. xfs_itrace_entry(ip);
  478. if (XFS_FORCED_SHUTDOWN(mp))
  479. return XFS_ERROR(EIO);
  480. stat->size = XFS_ISIZE(ip);
  481. stat->dev = inode->i_sb->s_dev;
  482. stat->mode = ip->i_d.di_mode;
  483. stat->nlink = ip->i_d.di_nlink;
  484. stat->uid = ip->i_d.di_uid;
  485. stat->gid = ip->i_d.di_gid;
  486. stat->ino = ip->i_ino;
  487. #if XFS_BIG_INUMS
  488. stat->ino += mp->m_inoadd;
  489. #endif
  490. stat->atime = inode->i_atime;
  491. stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  492. stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  493. stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  494. stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  495. stat->blocks =
  496. XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
  497. switch (inode->i_mode & S_IFMT) {
  498. case S_IFBLK:
  499. case S_IFCHR:
  500. stat->blksize = BLKDEV_IOSIZE;
  501. stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  502. sysv_minor(ip->i_df.if_u2.if_rdev));
  503. break;
  504. default:
  505. if (XFS_IS_REALTIME_INODE(ip)) {
  506. /*
  507. * If the file blocks are being allocated from a
  508. * realtime volume, then return the inode's realtime
  509. * extent size or the realtime volume's extent size.
  510. */
  511. stat->blksize =
  512. xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
  513. } else
  514. stat->blksize = xfs_preferred_iosize(mp);
  515. stat->rdev = 0;
  516. break;
  517. }
  518. return 0;
  519. }
  520. STATIC int
  521. xfs_vn_setattr(
  522. struct dentry *dentry,
  523. struct iattr *iattr)
  524. {
  525. return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0, NULL);
  526. }
  527. /*
  528. * block_truncate_page can return an error, but we can't propagate it
  529. * at all here. Leave a complaint + stack trace in the syslog because
  530. * this could be bad. If it is bad, we need to propagate the error further.
  531. */
  532. STATIC void
  533. xfs_vn_truncate(
  534. struct inode *inode)
  535. {
  536. int error;
  537. error = block_truncate_page(inode->i_mapping, inode->i_size,
  538. xfs_get_blocks);
  539. WARN_ON(error);
  540. }
  541. STATIC long
  542. xfs_vn_fallocate(
  543. struct inode *inode,
  544. int mode,
  545. loff_t offset,
  546. loff_t len)
  547. {
  548. long error;
  549. loff_t new_size = 0;
  550. xfs_flock64_t bf;
  551. xfs_inode_t *ip = XFS_I(inode);
  552. /* preallocation on directories not yet supported */
  553. error = -ENODEV;
  554. if (S_ISDIR(inode->i_mode))
  555. goto out_error;
  556. bf.l_whence = 0;
  557. bf.l_start = offset;
  558. bf.l_len = len;
  559. xfs_ilock(ip, XFS_IOLOCK_EXCL);
  560. error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
  561. 0, NULL, XFS_ATTR_NOLOCK);
  562. if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
  563. offset + len > i_size_read(inode))
  564. new_size = offset + len;
  565. /* Change file size if needed */
  566. if (new_size) {
  567. struct iattr iattr;
  568. iattr.ia_valid = ATTR_SIZE;
  569. iattr.ia_size = new_size;
  570. error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK, NULL);
  571. }
  572. xfs_iunlock(ip, XFS_IOLOCK_EXCL);
  573. out_error:
  574. return error;
  575. }
  576. static const struct inode_operations xfs_inode_operations = {
  577. .permission = xfs_vn_permission,
  578. .truncate = xfs_vn_truncate,
  579. .getattr = xfs_vn_getattr,
  580. .setattr = xfs_vn_setattr,
  581. .setxattr = generic_setxattr,
  582. .getxattr = generic_getxattr,
  583. .removexattr = generic_removexattr,
  584. .listxattr = xfs_vn_listxattr,
  585. .fallocate = xfs_vn_fallocate,
  586. };
  587. static const struct inode_operations xfs_dir_inode_operations = {
  588. .create = xfs_vn_create,
  589. .lookup = xfs_vn_lookup,
  590. .link = xfs_vn_link,
  591. .unlink = xfs_vn_unlink,
  592. .symlink = xfs_vn_symlink,
  593. .mkdir = xfs_vn_mkdir,
  594. /*
  595. * Yes, XFS uses the same method for rmdir and unlink.
  596. *
  597. * There are some subtile differences deeper in the code,
  598. * but we use S_ISDIR to check for those.
  599. */
  600. .rmdir = xfs_vn_unlink,
  601. .mknod = xfs_vn_mknod,
  602. .rename = xfs_vn_rename,
  603. .permission = xfs_vn_permission,
  604. .getattr = xfs_vn_getattr,
  605. .setattr = xfs_vn_setattr,
  606. .setxattr = generic_setxattr,
  607. .getxattr = generic_getxattr,
  608. .removexattr = generic_removexattr,
  609. .listxattr = xfs_vn_listxattr,
  610. };
  611. static const struct inode_operations xfs_dir_ci_inode_operations = {
  612. .create = xfs_vn_create,
  613. .lookup = xfs_vn_ci_lookup,
  614. .link = xfs_vn_link,
  615. .unlink = xfs_vn_unlink,
  616. .symlink = xfs_vn_symlink,
  617. .mkdir = xfs_vn_mkdir,
  618. /*
  619. * Yes, XFS uses the same method for rmdir and unlink.
  620. *
  621. * There are some subtile differences deeper in the code,
  622. * but we use S_ISDIR to check for those.
  623. */
  624. .rmdir = xfs_vn_unlink,
  625. .mknod = xfs_vn_mknod,
  626. .rename = xfs_vn_rename,
  627. .permission = xfs_vn_permission,
  628. .getattr = xfs_vn_getattr,
  629. .setattr = xfs_vn_setattr,
  630. .setxattr = generic_setxattr,
  631. .getxattr = generic_getxattr,
  632. .removexattr = generic_removexattr,
  633. .listxattr = xfs_vn_listxattr,
  634. };
  635. static const struct inode_operations xfs_symlink_inode_operations = {
  636. .readlink = generic_readlink,
  637. .follow_link = xfs_vn_follow_link,
  638. .put_link = xfs_vn_put_link,
  639. .permission = xfs_vn_permission,
  640. .getattr = xfs_vn_getattr,
  641. .setattr = xfs_vn_setattr,
  642. .setxattr = generic_setxattr,
  643. .getxattr = generic_getxattr,
  644. .removexattr = generic_removexattr,
  645. .listxattr = xfs_vn_listxattr,
  646. };
  647. STATIC void
  648. xfs_diflags_to_iflags(
  649. struct inode *inode,
  650. struct xfs_inode *ip)
  651. {
  652. if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
  653. inode->i_flags |= S_IMMUTABLE;
  654. else
  655. inode->i_flags &= ~S_IMMUTABLE;
  656. if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
  657. inode->i_flags |= S_APPEND;
  658. else
  659. inode->i_flags &= ~S_APPEND;
  660. if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
  661. inode->i_flags |= S_SYNC;
  662. else
  663. inode->i_flags &= ~S_SYNC;
  664. if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
  665. inode->i_flags |= S_NOATIME;
  666. else
  667. inode->i_flags &= ~S_NOATIME;
  668. }
  669. /*
  670. * Initialize the Linux inode, set up the operation vectors and
  671. * unlock the inode.
  672. *
  673. * When reading existing inodes from disk this is called directly
  674. * from xfs_iget, when creating a new inode it is called from
  675. * xfs_ialloc after setting up the inode.
  676. */
  677. void
  678. xfs_setup_inode(
  679. struct xfs_inode *ip)
  680. {
  681. struct inode *inode = ip->i_vnode;
  682. inode->i_mode = ip->i_d.di_mode;
  683. inode->i_nlink = ip->i_d.di_nlink;
  684. inode->i_uid = ip->i_d.di_uid;
  685. inode->i_gid = ip->i_d.di_gid;
  686. switch (inode->i_mode & S_IFMT) {
  687. case S_IFBLK:
  688. case S_IFCHR:
  689. inode->i_rdev =
  690. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  691. sysv_minor(ip->i_df.if_u2.if_rdev));
  692. break;
  693. default:
  694. inode->i_rdev = 0;
  695. break;
  696. }
  697. inode->i_generation = ip->i_d.di_gen;
  698. i_size_write(inode, ip->i_d.di_size);
  699. inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
  700. inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
  701. inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  702. inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  703. inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  704. inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  705. xfs_diflags_to_iflags(inode, ip);
  706. xfs_iflags_clear(ip, XFS_IMODIFIED);
  707. switch (inode->i_mode & S_IFMT) {
  708. case S_IFREG:
  709. inode->i_op = &xfs_inode_operations;
  710. inode->i_fop = &xfs_file_operations;
  711. inode->i_mapping->a_ops = &xfs_address_space_operations;
  712. break;
  713. case S_IFDIR:
  714. if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
  715. inode->i_op = &xfs_dir_ci_inode_operations;
  716. else
  717. inode->i_op = &xfs_dir_inode_operations;
  718. inode->i_fop = &xfs_dir_file_operations;
  719. break;
  720. case S_IFLNK:
  721. inode->i_op = &xfs_symlink_inode_operations;
  722. if (!(ip->i_df.if_flags & XFS_IFINLINE))
  723. inode->i_mapping->a_ops = &xfs_address_space_operations;
  724. break;
  725. default:
  726. inode->i_op = &xfs_inode_operations;
  727. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  728. break;
  729. }
  730. xfs_iflags_clear(ip, XFS_INEW);
  731. barrier();
  732. unlock_new_inode(inode);
  733. }