Lines Matching refs:inode
12 * This file implements VFS file and inode operations for regular files, device
26 * A thing to keep in mind: inode @i_mutex is locked in most VFS operations we
45 static int read_block(struct inode *inode, void *addr, unsigned int block,
48 struct ubifs_info *c = inode->i_sb->s_fs_info;
53 data_key_init(c, &key, inode->i_ino, block);
63 ubifs_inode(inode)->creat_sqnum);
70 if (IS_ENCRYPTED(inode)) {
71 err = ubifs_decrypt(inode, dn, &dlen, block);
93 ubifs_err(c, "bad data node (block %u, inode %lu)",
94 block, inode->i_ino);
105 struct inode *inode = page->mapping->host;
106 struct ubifs_info *c = inode->i_sb->s_fs_info;
107 loff_t i_size = i_size_read(inode);
110 inode->i_ino, page->index, i_size, page->flags);
119 /* Reading beyond inode */
136 /* Reading beyond inode */
140 ret = read_block(inode, addr, block, dn);
159 struct ubifs_info *c = inode->i_sb->s_fs_info;
166 ubifs_err(c, "cannot read page %lu of inode %lu, error %d",
167 page->index, inode->i_ino, err);
220 struct inode *inode = mapping->host;
221 struct ubifs_info *c = inode->i_sb->s_fs_info;
224 int err, appending = !!(pos + len > inode->i_size);
228 inode->i_ino, pos, len, inode->i_size);
239 /* We are appending data, budget for inode change */
288 struct ubifs_inode *ui = ubifs_inode(inode);
298 * The inode is dirty already, so we may free the
312 * @ui: UBIFS inode object the page belongs to
337 * The page is dirty and we are appending, so the inode
341 * should prevent write-back from flushing the inode
348 * The page is dirty, we are appending, the inode is clean, so
349 * we need to budget the inode change.
374 * The inode is clean but we will have to mark
396 * changing the inode; however, if the inode is already dirty, there is
421 struct inode *inode = mapping->host;
422 struct ubifs_info *c = inode->i_sb->s_fs_info;
423 struct ubifs_inode *ui = ubifs_inode(inode);
425 int err, appending = !!(pos + len > inode->i_size);
429 ubifs_assert(c, ubifs_inode(inode)->ui_size == inode->i_size);
505 * @ui: UBIFS inode object the page belongs to
531 struct inode *inode = mapping->host;
532 struct ubifs_inode *ui = ubifs_inode(inode);
533 struct ubifs_info *c = inode->i_sb->s_fs_info;
535 int appending = !!(end_pos > inode->i_size);
538 inode->i_ino, pos, page->index, len, copied, inode->i_size);
573 i_size_write(inode, end_pos);
577 * inode has dirty pages), this has been done in
580 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
604 struct inode *inode = page->mapping->host;
605 loff_t i_size = i_size_read(inode);
611 inode->i_ino, page->index, i_size, page->flags);
635 ubifs_inode(inode)->creat_sqnum);
644 if (IS_ENCRYPTED(inode)) {
645 err = ubifs_decrypt(inode, dn, &dlen, page_block);
698 ubifs_err(c, "bad data node (block %u, inode %lu)",
699 page_block, inode->i_ino);
716 struct inode *inode = mapping->host;
717 struct ubifs_inode *ui = ubifs_inode(inode);
772 isize = i_size_read(inode);
823 struct inode *inode = page->mapping->host;
824 struct ubifs_info *c = inode->i_sb->s_fs_info;
825 struct ubifs_inode *ui = ubifs_inode(inode);
873 data_key_init(c, &bu->key, inode->i_ino,
904 struct inode *inode = page->mapping->host;
905 struct ubifs_info *c = inode->i_sb->s_fs_info;
908 struct ubifs_inode *ui = ubifs_inode(inode);
922 data_key_init(c, &key, inode->i_ino, block);
923 err = ubifs_jnl_write_data(c, inode, &key, addr, blen);
934 ubifs_err(c, "cannot write page %lu of inode %lu, error %d",
935 page->index, inode->i_ino, err);
957 * inode, then the inode itself. For UBIFS this may cause a problem. Consider a
958 * situation when a we have an inode with size 0, then a megabyte of data is
959 * appended to the inode, then write-back starts and flushes some amount of the
962 * inode size would still be 0, but there would be many pages which are beyond
963 * the inode size, they would be indexed and consume flash space. Because the
965 * situation and correct the inode size. This means UBIFS would have to scan
966 * whole index and correct all inode sizes, which is long an unacceptable.
969 * within the last synchronized inode size, i.e. the size which has been
970 * written to the flash media last time. Otherwise, UBIFS forces inode
971 * write-back, thus making sure the on-flash inode contains current inode size,
975 * the page locked, and it locks @ui_mutex. However, write-back does take inode
976 * @i_mutex, which means other VFS operations may be run on this inode at the
978 * we have to call 'truncate_setsize()', which first changes @inode->i_size,
982 * This means that @inode->i_size is changed while @ui_mutex is unlocked.
989 * inode size. How do we do this if @inode->i_size may became smaller while we
991 * @ui->ui_isize "shadow" field which UBIFS uses instead of @inode->i_size
995 * situation when the inode is truncated while we are in the middle of
996 * 'do_writepage()', so we do write beyond inode size?
998 * on the page lock and it would not write the truncated inode node to the
1003 struct inode *inode = page->mapping->host;
1004 struct ubifs_info *c = inode->i_sb->s_fs_info;
1005 struct ubifs_inode *ui = ubifs_inode(inode);
1006 loff_t i_size = i_size_read(inode), synced_i_size;
1012 inode->i_ino, page->index, page->flags);
1028 err = inode->i_sb->s_op->write_inode(inode, NULL);
1032 * The inode has been written, but the write-buffer has
1034 * reboot we may end up with some pages beyond inode
1056 err = inode->i_sb->s_op->write_inode(inode, NULL);
1066 * there is no need to do space budget for dirty inode.
1075 * do_attr_changes - change inode attributes.
1076 * @inode: inode to change attributes for
1079 static void do_attr_changes(struct inode *inode, const struct iattr *attr)
1082 inode->i_uid = attr->ia_uid;
1084 inode->i_gid = attr->ia_gid;
1086 inode->i_atime = attr->ia_atime;
1088 inode->i_mtime = attr->ia_mtime;
1090 inode_set_ctime_to_ts(inode, attr->ia_ctime);
1094 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
1096 inode->i_mode = mode;
1101 * do_truncation - truncate an inode.
1103 * @inode: inode to truncate
1104 * @attr: inode attribute changes description
1106 * This function implements VFS '->setattr()' call when the inode is truncated
1110 static int do_truncation(struct ubifs_info *c, struct inode *inode,
1115 loff_t old_size = inode->i_size, new_size = attr->ia_size;
1117 struct ubifs_inode *ui = ubifs_inode(inode);
1119 dbg_gen("ino %lu, size %lld -> %lld", inode->i_ino, old_size, new_size);
1144 truncate_setsize(inode, new_size);
1150 page = find_lock_page(inode->i_mapping, index);
1188 ui->ui_size = inode->i_size;
1189 /* Truncation changes inode [mc]time */
1190 inode->i_mtime = inode_set_ctime_current(inode);
1192 do_attr_changes(inode, attr);
1193 err = ubifs_jnl_truncate(c, inode, old_size, new_size);
1207 * do_setattr - change inode attributes.
1209 * @inode: inode to change attributes for
1210 * @attr: inode attribute changes description
1216 static int do_setattr(struct ubifs_info *c, struct inode *inode,
1221 struct ubifs_inode *ui = ubifs_inode(inode);
1230 dbg_gen("size %lld -> %lld", inode->i_size, new_size);
1231 truncate_setsize(inode, new_size);
1236 /* Truncation changes inode [mc]time */
1237 inode->i_mtime = inode_set_ctime_current(inode);
1239 ui->ui_size = inode->i_size;
1242 do_attr_changes(inode, attr);
1250 __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
1252 mark_inode_dirty_sync(inode);
1257 if (IS_SYNC(inode))
1258 err = inode->i_sb->s_op->write_inode(inode, NULL);
1266 struct inode *inode = d_inode(dentry);
1267 struct ubifs_info *c = inode->i_sb->s_fs_info;
1270 inode->i_ino, inode->i_mode, attr->ia_valid);
1275 err = dbg_check_synced_i_size(c, inode);
1283 if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size < inode->i_size)
1285 err = do_truncation(c, inode, attr);
1287 err = do_setattr(c, inode, attr);
1295 struct inode *inode = folio->mapping->host;
1296 struct ubifs_info *c = inode->i_sb->s_fs_info;
1315 struct inode *inode = file->f_mapping->host;
1316 struct ubifs_info *c = inode->i_sb->s_fs_info;
1319 dbg_gen("syncing inode %lu", inode->i_ino);
1331 inode_lock(inode);
1333 /* Synchronize the inode unless this is a 'datasync()' call. */
1334 if (!datasync || (inode->i_state & I_DIRTY_DATASYNC)) {
1335 err = inode->i_sb->s_op->write_inode(inode, NULL);
1341 * Nodes related to this inode may still sit in a write-buffer. Flush
1344 err = ubifs_sync_wbufs_by_inode(c, inode);
1346 inode_unlock(inode);
1352 * @inode: the inode to do the check for
1355 * This helper function checks if the inode mtime/ctime should be updated or
1356 * not. If current values of the time-stamps are within the UBIFS inode time
1359 static inline int mctime_update_needed(const struct inode *inode,
1362 struct timespec64 ctime = inode_get_ctime(inode);
1364 if (!timespec64_equal(&inode->i_mtime, now) ||
1371 * ubifs_update_time - update time of inode.
1372 * @inode: inode to update
1374 * This function updates time of the inode.
1376 int ubifs_update_time(struct inode *inode, int flags)
1378 struct ubifs_inode *ui = ubifs_inode(inode);
1379 struct ubifs_info *c = inode->i_sb->s_fs_info;
1385 generic_update_time(inode, flags);
1394 inode_update_timestamps(inode, flags);
1396 __mark_inode_dirty(inode, I_DIRTY_SYNC);
1404 * update_mctime - update mtime and ctime of an inode.
1405 * @inode: inode to update
1407 * This function updates mtime and ctime of the inode if it is not equivalent to
1411 static int update_mctime(struct inode *inode)
1413 struct timespec64 now = current_time(inode);
1414 struct ubifs_inode *ui = ubifs_inode(inode);
1415 struct ubifs_info *c = inode->i_sb->s_fs_info;
1417 if (mctime_update_needed(inode, &now)) {
1427 inode->i_mtime = inode_set_ctime_current(inode);
1429 mark_inode_dirty_sync(inode);
1464 struct inode *inode = folio->mapping->host;
1465 struct ubifs_info *c = inode->i_sb->s_fs_info;
1496 struct inode *inode = file_inode(vmf->vma->vm_file);
1497 struct ubifs_info *c = inode->i_sb->s_fs_info;
1498 struct timespec64 now = current_time(inode);
1502 dbg_gen("ino %lu, pg %lu, i_size %lld", inode->i_ino, page->index,
1503 i_size_read(inode));
1527 update_time = mctime_update_needed(inode, &now);
1530 * We have to change inode time stamp which requires extra
1538 ubifs_warn(c, "out of space for mmapped file (inode number %lu)",
1539 inode->i_ino);
1544 if (unlikely(page->mapping != inode->i_mapping ||
1545 page_offset(page) > i_size_read(inode))) {
1562 struct ubifs_inode *ui = ubifs_inode(inode);
1565 inode->i_mtime = inode_set_ctime_current(inode);
1567 mark_inode_dirty_sync(inode);
1604 struct inode *inode,
1607 struct ubifs_inode *ui = ubifs_inode(inode);
1609 if (!IS_ENCRYPTED(inode))
1615 return fscrypt_get_symlink(inode, ui->data, ui->data_len, done);