xfs_iops.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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_dir.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_alloc.h"
  29. #include "xfs_dmapi.h"
  30. #include "xfs_quota.h"
  31. #include "xfs_mount.h"
  32. #include "xfs_bmap_btree.h"
  33. #include "xfs_alloc_btree.h"
  34. #include "xfs_ialloc_btree.h"
  35. #include "xfs_dir_sf.h"
  36. #include "xfs_dir2_sf.h"
  37. #include "xfs_attr_sf.h"
  38. #include "xfs_dinode.h"
  39. #include "xfs_inode.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_btree.h"
  42. #include "xfs_ialloc.h"
  43. #include "xfs_rtalloc.h"
  44. #include "xfs_error.h"
  45. #include "xfs_itable.h"
  46. #include "xfs_rw.h"
  47. #include "xfs_acl.h"
  48. #include "xfs_cap.h"
  49. #include "xfs_mac.h"
  50. #include "xfs_attr.h"
  51. #include "xfs_buf_item.h"
  52. #include "xfs_utils.h"
  53. #include <linux/xattr.h>
  54. #include <linux/namei.h>
  55. /*
  56. * Change the requested timestamp in the given inode.
  57. * We don't lock across timestamp updates, and we don't log them but
  58. * we do record the fact that there is dirty information in core.
  59. *
  60. * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
  61. * with XFS_ICHGTIME_ACC to be sure that access time
  62. * update will take. Calling first with XFS_ICHGTIME_ACC
  63. * and then XFS_ICHGTIME_MOD may fail to modify the access
  64. * timestamp if the filesystem is mounted noacctm.
  65. */
  66. void
  67. xfs_ichgtime(
  68. xfs_inode_t *ip,
  69. int flags)
  70. {
  71. struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip));
  72. timespec_t tv;
  73. /*
  74. * We're not supposed to change timestamps in readonly-mounted
  75. * filesystems. Throw it away if anyone asks us.
  76. */
  77. if (unlikely(IS_RDONLY(inode)))
  78. return;
  79. /*
  80. * Don't update access timestamps on reads if mounted "noatime".
  81. * Throw it away if anyone asks us.
  82. */
  83. if (unlikely(
  84. (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
  85. (flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
  86. XFS_ICHGTIME_ACC))
  87. return;
  88. nanotime(&tv);
  89. if (flags & XFS_ICHGTIME_MOD) {
  90. inode->i_mtime = tv;
  91. ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
  92. ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
  93. }
  94. if (flags & XFS_ICHGTIME_ACC) {
  95. inode->i_atime = tv;
  96. ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
  97. ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
  98. }
  99. if (flags & XFS_ICHGTIME_CHG) {
  100. inode->i_ctime = tv;
  101. ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
  102. ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
  103. }
  104. /*
  105. * We update the i_update_core field _after_ changing
  106. * the timestamps in order to coordinate properly with
  107. * xfs_iflush() so that we don't lose timestamp updates.
  108. * This keeps us from having to hold the inode lock
  109. * while doing this. We use the SYNCHRONIZE macro to
  110. * ensure that the compiler does not reorder the update
  111. * of i_update_core above the timestamp updates above.
  112. */
  113. SYNCHRONIZE();
  114. ip->i_update_core = 1;
  115. if (!(inode->i_state & I_LOCK))
  116. mark_inode_dirty_sync(inode);
  117. }
  118. /*
  119. * Variant on the above which avoids querying the system clock
  120. * in situations where we know the Linux inode timestamps have
  121. * just been updated (and so we can update our inode cheaply).
  122. * We also skip the readonly and noatime checks here, they are
  123. * also catered for already.
  124. */
  125. void
  126. xfs_ichgtime_fast(
  127. xfs_inode_t *ip,
  128. struct inode *inode,
  129. int flags)
  130. {
  131. timespec_t *tvp;
  132. /*
  133. * We're not supposed to change timestamps in readonly-mounted
  134. * filesystems. Throw it away if anyone asks us.
  135. */
  136. if (unlikely(IS_RDONLY(inode)))
  137. return;
  138. /*
  139. * Don't update access timestamps on reads if mounted "noatime".
  140. * Throw it away if anyone asks us.
  141. */
  142. if (unlikely(
  143. (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
  144. ((flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
  145. XFS_ICHGTIME_ACC)))
  146. return;
  147. if (flags & XFS_ICHGTIME_MOD) {
  148. tvp = &inode->i_mtime;
  149. ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
  150. ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
  151. }
  152. if (flags & XFS_ICHGTIME_ACC) {
  153. tvp = &inode->i_atime;
  154. ip->i_d.di_atime.t_sec = (__int32_t)tvp->tv_sec;
  155. ip->i_d.di_atime.t_nsec = (__int32_t)tvp->tv_nsec;
  156. }
  157. if (flags & XFS_ICHGTIME_CHG) {
  158. tvp = &inode->i_ctime;
  159. ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
  160. ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
  161. }
  162. /*
  163. * We update the i_update_core field _after_ changing
  164. * the timestamps in order to coordinate properly with
  165. * xfs_iflush() so that we don't lose timestamp updates.
  166. * This keeps us from having to hold the inode lock
  167. * while doing this. We use the SYNCHRONIZE macro to
  168. * ensure that the compiler does not reorder the update
  169. * of i_update_core above the timestamp updates above.
  170. */
  171. SYNCHRONIZE();
  172. ip->i_update_core = 1;
  173. if (!(inode->i_state & I_LOCK))
  174. mark_inode_dirty_sync(inode);
  175. }
  176. /*
  177. * Pull the link count and size up from the xfs inode to the linux inode
  178. */
  179. STATIC void
  180. validate_fields(
  181. struct inode *ip)
  182. {
  183. vnode_t *vp = LINVFS_GET_VP(ip);
  184. vattr_t va;
  185. int error;
  186. va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
  187. VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error);
  188. if (likely(!error)) {
  189. ip->i_nlink = va.va_nlink;
  190. ip->i_blocks = va.va_nblocks;
  191. /* we're under i_sem so i_size can't change under us */
  192. if (i_size_read(ip) != va.va_size)
  193. i_size_write(ip, va.va_size);
  194. }
  195. }
  196. /*
  197. * Determine whether a process has a valid fs_struct (kernel daemons
  198. * like knfsd don't have an fs_struct).
  199. *
  200. * XXX(hch): nfsd is broken, better fix it instead.
  201. */
  202. STATIC inline int
  203. has_fs_struct(struct task_struct *task)
  204. {
  205. return (task->fs != init_task.fs);
  206. }
  207. STATIC int
  208. linvfs_mknod(
  209. struct inode *dir,
  210. struct dentry *dentry,
  211. int mode,
  212. dev_t rdev)
  213. {
  214. struct inode *ip;
  215. vattr_t va;
  216. vnode_t *vp = NULL, *dvp = LINVFS_GET_VP(dir);
  217. xfs_acl_t *default_acl = NULL;
  218. attrexists_t test_default_acl = _ACL_DEFAULT_EXISTS;
  219. int error;
  220. /*
  221. * Irix uses Missed'em'V split, but doesn't want to see
  222. * the upper 5 bits of (14bit) major.
  223. */
  224. if (!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)
  225. return -EINVAL;
  226. if (test_default_acl && test_default_acl(dvp)) {
  227. if (!_ACL_ALLOC(default_acl))
  228. return -ENOMEM;
  229. if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
  230. _ACL_FREE(default_acl);
  231. default_acl = NULL;
  232. }
  233. }
  234. if (IS_POSIXACL(dir) && !default_acl && has_fs_struct(current))
  235. mode &= ~current->fs->umask;
  236. memset(&va, 0, sizeof(va));
  237. va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
  238. va.va_mode = mode;
  239. switch (mode & S_IFMT) {
  240. case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
  241. va.va_rdev = sysv_encode_dev(rdev);
  242. va.va_mask |= XFS_AT_RDEV;
  243. /*FALLTHROUGH*/
  244. case S_IFREG:
  245. VOP_CREATE(dvp, dentry, &va, &vp, NULL, error);
  246. break;
  247. case S_IFDIR:
  248. VOP_MKDIR(dvp, dentry, &va, &vp, NULL, error);
  249. break;
  250. default:
  251. error = EINVAL;
  252. break;
  253. }
  254. if (default_acl) {
  255. if (!error) {
  256. error = _ACL_INHERIT(vp, &va, default_acl);
  257. if (!error) {
  258. VMODIFY(vp);
  259. } else {
  260. struct dentry teardown = {};
  261. int err2;
  262. /* Oh, the horror.
  263. * If we can't add the ACL we must back out.
  264. * ENOSPC can hit here, among other things.
  265. */
  266. teardown.d_inode = ip = LINVFS_GET_IP(vp);
  267. teardown.d_name = dentry->d_name;
  268. vn_mark_bad(vp);
  269. if (S_ISDIR(mode))
  270. VOP_RMDIR(dvp, &teardown, NULL, err2);
  271. else
  272. VOP_REMOVE(dvp, &teardown, NULL, err2);
  273. VN_RELE(vp);
  274. }
  275. }
  276. _ACL_FREE(default_acl);
  277. }
  278. if (!error) {
  279. ASSERT(vp);
  280. ip = LINVFS_GET_IP(vp);
  281. if (S_ISCHR(mode) || S_ISBLK(mode))
  282. ip->i_rdev = rdev;
  283. else if (S_ISDIR(mode))
  284. validate_fields(ip);
  285. d_instantiate(dentry, ip);
  286. validate_fields(dir);
  287. }
  288. return -error;
  289. }
  290. STATIC int
  291. linvfs_create(
  292. struct inode *dir,
  293. struct dentry *dentry,
  294. int mode,
  295. struct nameidata *nd)
  296. {
  297. return linvfs_mknod(dir, dentry, mode, 0);
  298. }
  299. STATIC int
  300. linvfs_mkdir(
  301. struct inode *dir,
  302. struct dentry *dentry,
  303. int mode)
  304. {
  305. return linvfs_mknod(dir, dentry, mode|S_IFDIR, 0);
  306. }
  307. STATIC struct dentry *
  308. linvfs_lookup(
  309. struct inode *dir,
  310. struct dentry *dentry,
  311. struct nameidata *nd)
  312. {
  313. struct vnode *vp = LINVFS_GET_VP(dir), *cvp;
  314. int error;
  315. if (dentry->d_name.len >= MAXNAMELEN)
  316. return ERR_PTR(-ENAMETOOLONG);
  317. VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error);
  318. if (error) {
  319. if (unlikely(error != ENOENT))
  320. return ERR_PTR(-error);
  321. d_add(dentry, NULL);
  322. return NULL;
  323. }
  324. return d_splice_alias(LINVFS_GET_IP(cvp), dentry);
  325. }
  326. STATIC int
  327. linvfs_link(
  328. struct dentry *old_dentry,
  329. struct inode *dir,
  330. struct dentry *dentry)
  331. {
  332. struct inode *ip; /* inode of guy being linked to */
  333. vnode_t *tdvp; /* target directory for new name/link */
  334. vnode_t *vp; /* vp of name being linked */
  335. int error;
  336. ip = old_dentry->d_inode; /* inode being linked to */
  337. if (S_ISDIR(ip->i_mode))
  338. return -EPERM;
  339. tdvp = LINVFS_GET_VP(dir);
  340. vp = LINVFS_GET_VP(ip);
  341. VOP_LINK(tdvp, vp, dentry, NULL, error);
  342. if (!error) {
  343. VMODIFY(tdvp);
  344. VN_HOLD(vp);
  345. validate_fields(ip);
  346. d_instantiate(dentry, ip);
  347. }
  348. return -error;
  349. }
  350. STATIC int
  351. linvfs_unlink(
  352. struct inode *dir,
  353. struct dentry *dentry)
  354. {
  355. struct inode *inode;
  356. vnode_t *dvp; /* directory containing name to remove */
  357. int error;
  358. inode = dentry->d_inode;
  359. dvp = LINVFS_GET_VP(dir);
  360. VOP_REMOVE(dvp, dentry, NULL, error);
  361. if (!error) {
  362. validate_fields(dir); /* For size only */
  363. validate_fields(inode);
  364. }
  365. return -error;
  366. }
  367. STATIC int
  368. linvfs_symlink(
  369. struct inode *dir,
  370. struct dentry *dentry,
  371. const char *symname)
  372. {
  373. struct inode *ip;
  374. vattr_t va;
  375. vnode_t *dvp; /* directory containing name of symlink */
  376. vnode_t *cvp; /* used to lookup symlink to put in dentry */
  377. int error;
  378. dvp = LINVFS_GET_VP(dir);
  379. cvp = NULL;
  380. memset(&va, 0, sizeof(va));
  381. va.va_mode = S_IFLNK |
  382. (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
  383. va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
  384. error = 0;
  385. VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error);
  386. if (!error && cvp) {
  387. ip = LINVFS_GET_IP(cvp);
  388. d_instantiate(dentry, ip);
  389. validate_fields(dir);
  390. validate_fields(ip); /* size needs update */
  391. }
  392. return -error;
  393. }
  394. STATIC int
  395. linvfs_rmdir(
  396. struct inode *dir,
  397. struct dentry *dentry)
  398. {
  399. struct inode *inode = dentry->d_inode;
  400. vnode_t *dvp = LINVFS_GET_VP(dir);
  401. int error;
  402. VOP_RMDIR(dvp, dentry, NULL, error);
  403. if (!error) {
  404. validate_fields(inode);
  405. validate_fields(dir);
  406. }
  407. return -error;
  408. }
  409. STATIC int
  410. linvfs_rename(
  411. struct inode *odir,
  412. struct dentry *odentry,
  413. struct inode *ndir,
  414. struct dentry *ndentry)
  415. {
  416. struct inode *new_inode = ndentry->d_inode;
  417. vnode_t *fvp; /* from directory */
  418. vnode_t *tvp; /* target directory */
  419. int error;
  420. fvp = LINVFS_GET_VP(odir);
  421. tvp = LINVFS_GET_VP(ndir);
  422. VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error);
  423. if (error)
  424. return -error;
  425. if (new_inode)
  426. validate_fields(new_inode);
  427. validate_fields(odir);
  428. if (ndir != odir)
  429. validate_fields(ndir);
  430. return 0;
  431. }
  432. /*
  433. * careful here - this function can get called recursively, so
  434. * we need to be very careful about how much stack we use.
  435. * uio is kmalloced for this reason...
  436. */
  437. STATIC void *
  438. linvfs_follow_link(
  439. struct dentry *dentry,
  440. struct nameidata *nd)
  441. {
  442. vnode_t *vp;
  443. uio_t *uio;
  444. iovec_t iov;
  445. int error;
  446. char *link;
  447. ASSERT(dentry);
  448. ASSERT(nd);
  449. link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL);
  450. if (!link) {
  451. nd_set_link(nd, ERR_PTR(-ENOMEM));
  452. return NULL;
  453. }
  454. uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL);
  455. if (!uio) {
  456. kfree(link);
  457. nd_set_link(nd, ERR_PTR(-ENOMEM));
  458. return NULL;
  459. }
  460. vp = LINVFS_GET_VP(dentry->d_inode);
  461. iov.iov_base = link;
  462. iov.iov_len = MAXNAMELEN;
  463. uio->uio_iov = &iov;
  464. uio->uio_offset = 0;
  465. uio->uio_segflg = UIO_SYSSPACE;
  466. uio->uio_resid = MAXNAMELEN;
  467. uio->uio_iovcnt = 1;
  468. VOP_READLINK(vp, uio, 0, NULL, error);
  469. if (error) {
  470. kfree(link);
  471. link = ERR_PTR(-error);
  472. } else {
  473. link[MAXNAMELEN - uio->uio_resid] = '\0';
  474. }
  475. kfree(uio);
  476. nd_set_link(nd, link);
  477. return NULL;
  478. }
  479. STATIC void
  480. linvfs_put_link(
  481. struct dentry *dentry,
  482. struct nameidata *nd,
  483. void *p)
  484. {
  485. char *s = nd_get_link(nd);
  486. if (!IS_ERR(s))
  487. kfree(s);
  488. }
  489. #ifdef CONFIG_XFS_POSIX_ACL
  490. STATIC int
  491. linvfs_permission(
  492. struct inode *inode,
  493. int mode,
  494. struct nameidata *nd)
  495. {
  496. vnode_t *vp = LINVFS_GET_VP(inode);
  497. int error;
  498. mode <<= 6; /* convert from linux to vnode access bits */
  499. VOP_ACCESS(vp, mode, NULL, error);
  500. return -error;
  501. }
  502. #else
  503. #define linvfs_permission NULL
  504. #endif
  505. STATIC int
  506. linvfs_getattr(
  507. struct vfsmount *mnt,
  508. struct dentry *dentry,
  509. struct kstat *stat)
  510. {
  511. struct inode *inode = dentry->d_inode;
  512. vnode_t *vp = LINVFS_GET_VP(inode);
  513. int error = 0;
  514. if (unlikely(vp->v_flag & VMODIFIED))
  515. error = vn_revalidate(vp);
  516. if (!error)
  517. generic_fillattr(inode, stat);
  518. return 0;
  519. }
  520. STATIC int
  521. linvfs_setattr(
  522. struct dentry *dentry,
  523. struct iattr *attr)
  524. {
  525. struct inode *inode = dentry->d_inode;
  526. unsigned int ia_valid = attr->ia_valid;
  527. vnode_t *vp = LINVFS_GET_VP(inode);
  528. vattr_t vattr;
  529. int flags = 0;
  530. int error;
  531. memset(&vattr, 0, sizeof(vattr_t));
  532. if (ia_valid & ATTR_UID) {
  533. vattr.va_mask |= XFS_AT_UID;
  534. vattr.va_uid = attr->ia_uid;
  535. }
  536. if (ia_valid & ATTR_GID) {
  537. vattr.va_mask |= XFS_AT_GID;
  538. vattr.va_gid = attr->ia_gid;
  539. }
  540. if (ia_valid & ATTR_SIZE) {
  541. vattr.va_mask |= XFS_AT_SIZE;
  542. vattr.va_size = attr->ia_size;
  543. }
  544. if (ia_valid & ATTR_ATIME) {
  545. vattr.va_mask |= XFS_AT_ATIME;
  546. vattr.va_atime = attr->ia_atime;
  547. }
  548. if (ia_valid & ATTR_MTIME) {
  549. vattr.va_mask |= XFS_AT_MTIME;
  550. vattr.va_mtime = attr->ia_mtime;
  551. }
  552. if (ia_valid & ATTR_CTIME) {
  553. vattr.va_mask |= XFS_AT_CTIME;
  554. vattr.va_ctime = attr->ia_ctime;
  555. }
  556. if (ia_valid & ATTR_MODE) {
  557. vattr.va_mask |= XFS_AT_MODE;
  558. vattr.va_mode = attr->ia_mode;
  559. if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
  560. inode->i_mode &= ~S_ISGID;
  561. }
  562. if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
  563. flags |= ATTR_UTIME;
  564. #ifdef ATTR_NO_BLOCK
  565. if ((ia_valid & ATTR_NO_BLOCK))
  566. flags |= ATTR_NONBLOCK;
  567. #endif
  568. VOP_SETATTR(vp, &vattr, flags, NULL, error);
  569. if (error)
  570. return -error;
  571. vn_revalidate(vp);
  572. return error;
  573. }
  574. STATIC void
  575. linvfs_truncate(
  576. struct inode *inode)
  577. {
  578. block_truncate_page(inode->i_mapping, inode->i_size, linvfs_get_block);
  579. }
  580. STATIC int
  581. linvfs_setxattr(
  582. struct dentry *dentry,
  583. const char *name,
  584. const void *data,
  585. size_t size,
  586. int flags)
  587. {
  588. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  589. char *attr = (char *)name;
  590. attrnames_t *namesp;
  591. int xflags = 0;
  592. int error;
  593. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  594. if (!namesp)
  595. return -EOPNOTSUPP;
  596. attr += namesp->attr_namelen;
  597. error = namesp->attr_capable(vp, NULL);
  598. if (error)
  599. return error;
  600. /* Convert Linux syscall to XFS internal ATTR flags */
  601. if (flags & XATTR_CREATE)
  602. xflags |= ATTR_CREATE;
  603. if (flags & XATTR_REPLACE)
  604. xflags |= ATTR_REPLACE;
  605. xflags |= namesp->attr_flag;
  606. return namesp->attr_set(vp, attr, (void *)data, size, xflags);
  607. }
  608. STATIC ssize_t
  609. linvfs_getxattr(
  610. struct dentry *dentry,
  611. const char *name,
  612. void *data,
  613. size_t size)
  614. {
  615. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  616. char *attr = (char *)name;
  617. attrnames_t *namesp;
  618. int xflags = 0;
  619. ssize_t error;
  620. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  621. if (!namesp)
  622. return -EOPNOTSUPP;
  623. attr += namesp->attr_namelen;
  624. error = namesp->attr_capable(vp, NULL);
  625. if (error)
  626. return error;
  627. /* Convert Linux syscall to XFS internal ATTR flags */
  628. if (!size) {
  629. xflags |= ATTR_KERNOVAL;
  630. data = NULL;
  631. }
  632. xflags |= namesp->attr_flag;
  633. return namesp->attr_get(vp, attr, (void *)data, size, xflags);
  634. }
  635. STATIC ssize_t
  636. linvfs_listxattr(
  637. struct dentry *dentry,
  638. char *data,
  639. size_t size)
  640. {
  641. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  642. int error, xflags = ATTR_KERNAMELS;
  643. ssize_t result;
  644. if (!size)
  645. xflags |= ATTR_KERNOVAL;
  646. xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
  647. error = attr_generic_list(vp, data, size, xflags, &result);
  648. if (error < 0)
  649. return error;
  650. return result;
  651. }
  652. STATIC int
  653. linvfs_removexattr(
  654. struct dentry *dentry,
  655. const char *name)
  656. {
  657. vnode_t *vp = LINVFS_GET_VP(dentry->d_inode);
  658. char *attr = (char *)name;
  659. attrnames_t *namesp;
  660. int xflags = 0;
  661. int error;
  662. namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
  663. if (!namesp)
  664. return -EOPNOTSUPP;
  665. attr += namesp->attr_namelen;
  666. error = namesp->attr_capable(vp, NULL);
  667. if (error)
  668. return error;
  669. xflags |= namesp->attr_flag;
  670. return namesp->attr_remove(vp, attr, xflags);
  671. }
  672. struct inode_operations linvfs_file_inode_operations = {
  673. .permission = linvfs_permission,
  674. .truncate = linvfs_truncate,
  675. .getattr = linvfs_getattr,
  676. .setattr = linvfs_setattr,
  677. .setxattr = linvfs_setxattr,
  678. .getxattr = linvfs_getxattr,
  679. .listxattr = linvfs_listxattr,
  680. .removexattr = linvfs_removexattr,
  681. };
  682. struct inode_operations linvfs_dir_inode_operations = {
  683. .create = linvfs_create,
  684. .lookup = linvfs_lookup,
  685. .link = linvfs_link,
  686. .unlink = linvfs_unlink,
  687. .symlink = linvfs_symlink,
  688. .mkdir = linvfs_mkdir,
  689. .rmdir = linvfs_rmdir,
  690. .mknod = linvfs_mknod,
  691. .rename = linvfs_rename,
  692. .permission = linvfs_permission,
  693. .getattr = linvfs_getattr,
  694. .setattr = linvfs_setattr,
  695. .setxattr = linvfs_setxattr,
  696. .getxattr = linvfs_getxattr,
  697. .listxattr = linvfs_listxattr,
  698. .removexattr = linvfs_removexattr,
  699. };
  700. struct inode_operations linvfs_symlink_inode_operations = {
  701. .readlink = generic_readlink,
  702. .follow_link = linvfs_follow_link,
  703. .put_link = linvfs_put_link,
  704. .permission = linvfs_permission,
  705. .getattr = linvfs_getattr,
  706. .setattr = linvfs_setattr,
  707. .setxattr = linvfs_setxattr,
  708. .getxattr = linvfs_getxattr,
  709. .listxattr = linvfs_listxattr,
  710. .removexattr = linvfs_removexattr,
  711. };