Lines Matching +full:ubi +full:- +full:volume +full:-

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2006-2008 Nokia Corporation.
35 return -EINVAL; in ubifs_default_version_set()
60 * validate_inode - validate inode.
61 * @c: UBIFS file-system description object
67 * a non-zero error code if not.
74 if (inode->i_size > c->max_inode_sz) { in validate_inode()
76 (long long)inode->i_size); in validate_inode()
80 if (ui->compr_type >= UBIFS_COMPR_TYPES_CNT) { in validate_inode()
81 ubifs_err(c, "unknown compression type %d", ui->compr_type); in validate_inode()
85 if (ui->xattr_names + ui->xattr_cnt > XATTR_LIST_MAX) in validate_inode()
88 if (ui->data_len < 0 || ui->data_len > UBIFS_MAX_INO_DATA) in validate_inode()
91 if (ui->xattr && !S_ISREG(inode->i_mode)) in validate_inode()
94 if (!ubifs_compr_present(c, ui->compr_type)) { in validate_inode()
96 inode->i_ino, ubifs_compr_name(c, ui->compr_type)); in validate_inode()
108 struct ubifs_info *c = sb->s_fs_info; in ubifs_iget()
116 return ERR_PTR(-ENOMEM); in ubifs_iget()
117 if (!(inode->i_state & I_NEW)) in ubifs_iget()
123 err = -ENOMEM; in ubifs_iget()
127 ino_key_init(c, &key, inode->i_ino); in ubifs_iget()
133 inode->i_flags |= S_NOCMTIME; in ubifs_iget()
136 inode->i_flags |= S_NOATIME; in ubifs_iget()
138 set_nlink(inode, le32_to_cpu(ino->nlink)); in ubifs_iget()
139 i_uid_write(inode, le32_to_cpu(ino->uid)); in ubifs_iget()
140 i_gid_write(inode, le32_to_cpu(ino->gid)); in ubifs_iget()
141 inode_set_atime(inode, (int64_t)le64_to_cpu(ino->atime_sec), in ubifs_iget()
142 le32_to_cpu(ino->atime_nsec)); in ubifs_iget()
143 inode_set_mtime(inode, (int64_t)le64_to_cpu(ino->mtime_sec), in ubifs_iget()
144 le32_to_cpu(ino->mtime_nsec)); in ubifs_iget()
145 inode_set_ctime(inode, (int64_t)le64_to_cpu(ino->ctime_sec), in ubifs_iget()
146 le32_to_cpu(ino->ctime_nsec)); in ubifs_iget()
147 inode->i_mode = le32_to_cpu(ino->mode); in ubifs_iget()
148 inode->i_size = le64_to_cpu(ino->size); in ubifs_iget()
150 ui->data_len = le32_to_cpu(ino->data_len); in ubifs_iget()
151 ui->flags = le32_to_cpu(ino->flags); in ubifs_iget()
152 ui->compr_type = le16_to_cpu(ino->compr_type); in ubifs_iget()
153 ui->creat_sqnum = le64_to_cpu(ino->creat_sqnum); in ubifs_iget()
154 ui->xattr_cnt = le32_to_cpu(ino->xattr_cnt); in ubifs_iget()
155 ui->xattr_size = le32_to_cpu(ino->xattr_size); in ubifs_iget()
156 ui->xattr_names = le32_to_cpu(ino->xattr_names); in ubifs_iget()
157 ui->synced_i_size = ui->ui_size = inode->i_size; in ubifs_iget()
159 ui->xattr = (ui->flags & UBIFS_XATTR_FL) ? 1 : 0; in ubifs_iget()
165 switch (inode->i_mode & S_IFMT) { in ubifs_iget()
167 inode->i_mapping->a_ops = &ubifs_file_address_operations; in ubifs_iget()
168 inode->i_op = &ubifs_file_inode_operations; in ubifs_iget()
169 inode->i_fop = &ubifs_file_operations; in ubifs_iget()
170 if (ui->xattr) { in ubifs_iget()
171 ui->data = kmalloc(ui->data_len + 1, GFP_NOFS); in ubifs_iget()
172 if (!ui->data) { in ubifs_iget()
173 err = -ENOMEM; in ubifs_iget()
176 memcpy(ui->data, ino->data, ui->data_len); in ubifs_iget()
177 ((char *)ui->data)[ui->data_len] = '\0'; in ubifs_iget()
178 } else if (ui->data_len != 0) { in ubifs_iget()
184 inode->i_op = &ubifs_dir_inode_operations; in ubifs_iget()
185 inode->i_fop = &ubifs_dir_operations; in ubifs_iget()
186 if (ui->data_len != 0) { in ubifs_iget()
192 inode->i_op = &ubifs_symlink_inode_operations; in ubifs_iget()
193 if (ui->data_len <= 0 || ui->data_len > UBIFS_MAX_INO_DATA) { in ubifs_iget()
197 ui->data = kmalloc(ui->data_len + 1, GFP_NOFS); in ubifs_iget()
198 if (!ui->data) { in ubifs_iget()
199 err = -ENOMEM; in ubifs_iget()
202 memcpy(ui->data, ino->data, ui->data_len); in ubifs_iget()
203 ((char *)ui->data)[ui->data_len] = '\0'; in ubifs_iget()
211 ui->data = kmalloc(sizeof(union ubifs_dev_desc), GFP_NOFS); in ubifs_iget()
212 if (!ui->data) { in ubifs_iget()
213 err = -ENOMEM; in ubifs_iget()
217 dev = (union ubifs_dev_desc *)ino->data; in ubifs_iget()
218 if (ui->data_len == sizeof(dev->new)) in ubifs_iget()
219 rdev = new_decode_dev(le32_to_cpu(dev->new)); in ubifs_iget()
220 else if (ui->data_len == sizeof(dev->huge)) in ubifs_iget()
221 rdev = huge_decode_dev(le64_to_cpu(dev->huge)); in ubifs_iget()
226 memcpy(ui->data, ino->data, ui->data_len); in ubifs_iget()
227 inode->i_op = &ubifs_file_inode_operations; in ubifs_iget()
228 init_special_inode(inode, inode->i_mode, rdev); in ubifs_iget()
233 inode->i_op = &ubifs_file_inode_operations; in ubifs_iget()
234 init_special_inode(inode, inode->i_mode, 0); in ubifs_iget()
235 if (ui->data_len != 0) { in ubifs_iget()
251 ubifs_err(c, "inode %lu validation failed, error %d", inode->i_ino, err); in ubifs_iget()
254 err = -EINVAL; in ubifs_iget()
258 ubifs_err(c, "failed to read inode %lu, error %d", inode->i_ino, err); in ubifs_iget()
272 sizeof(struct ubifs_inode) - sizeof(struct inode)); in ubifs_alloc_inode()
273 mutex_init(&ui->ui_mutex); in ubifs_alloc_inode()
274 init_rwsem(&ui->xattr_sem); in ubifs_alloc_inode()
275 spin_lock_init(&ui->ui_lock); in ubifs_alloc_inode()
276 return &ui->vfs_inode; in ubifs_alloc_inode()
283 kfree(ui->data); in ubifs_free_inode()
290 * Note, Linux write-back code calls this without 'i_mutex'.
295 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_write_inode()
298 ubifs_assert(c, !ui->xattr); in ubifs_write_inode()
302 mutex_lock(&ui->ui_mutex); in ubifs_write_inode()
304 * Due to races between write-back forced by budgeting in ubifs_write_inode()
305 * (see 'sync_some_inodes()') and background write-back, the inode may in ubifs_write_inode()
310 if (!ui->dirty) { in ubifs_write_inode()
311 mutex_unlock(&ui->ui_mutex); in ubifs_write_inode()
320 inode->i_ino, (int)inode->i_mode, inode->i_nlink); in ubifs_write_inode()
321 if (inode->i_nlink) { in ubifs_write_inode()
325 inode->i_ino, err); in ubifs_write_inode()
327 err = dbg_check_inode_size(c, inode, ui->ui_size); in ubifs_write_inode()
330 ui->dirty = 0; in ubifs_write_inode()
331 mutex_unlock(&ui->ui_mutex); in ubifs_write_inode()
349 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_evict_inode()
352 if (ui->xattr) in ubifs_evict_inode()
360 dbg_gen("inode %lu, mode %#x", inode->i_ino, (int)inode->i_mode); in ubifs_evict_inode()
361 ubifs_assert(c, !atomic_read(&inode->i_count)); in ubifs_evict_inode()
363 truncate_inode_pages_final(&inode->i_data); in ubifs_evict_inode()
365 if (inode->i_nlink) in ubifs_evict_inode()
371 ui->ui_size = inode->i_size = 0; in ubifs_evict_inode()
379 inode->i_ino, err); in ubifs_evict_inode()
382 if (ui->dirty) in ubifs_evict_inode()
385 /* We've deleted something - clean the "no space" flags */ in ubifs_evict_inode()
386 c->bi.nospace = c->bi.nospace_rp = 0; in ubifs_evict_inode()
396 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_dirty_inode()
399 ubifs_assert(c, mutex_is_locked(&ui->ui_mutex)); in ubifs_dirty_inode()
400 if (!ui->dirty) { in ubifs_dirty_inode()
401 ui->dirty = 1; in ubifs_dirty_inode()
402 dbg_gen("inode %lu", inode->i_ino); in ubifs_dirty_inode()
408 struct ubifs_info *c = dentry->d_sb->s_fs_info; in ubifs_statfs()
410 __le32 *uuid = (__le32 *)c->uuid; in ubifs_statfs()
416 buf->f_type = UBIFS_SUPER_MAGIC; in ubifs_statfs()
417 buf->f_bsize = UBIFS_BLOCK_SIZE; in ubifs_statfs()
418 buf->f_blocks = c->block_cnt; in ubifs_statfs()
419 buf->f_bfree = free >> UBIFS_BLOCK_SHIFT; in ubifs_statfs()
420 if (free > c->report_rp_size) in ubifs_statfs()
421 buf->f_bavail = (free - c->report_rp_size) >> UBIFS_BLOCK_SHIFT; in ubifs_statfs()
423 buf->f_bavail = 0; in ubifs_statfs()
424 buf->f_files = 0; in ubifs_statfs()
425 buf->f_ffree = 0; in ubifs_statfs()
426 buf->f_namelen = UBIFS_MAX_NLEN; in ubifs_statfs()
427 buf->f_fsid.val[0] = le32_to_cpu(uuid[0]) ^ le32_to_cpu(uuid[2]); in ubifs_statfs()
428 buf->f_fsid.val[1] = le32_to_cpu(uuid[1]) ^ le32_to_cpu(uuid[3]); in ubifs_statfs()
429 ubifs_assert(c, buf->f_bfree <= c->block_cnt); in ubifs_statfs()
435 struct ubifs_info *c = root->d_sb->s_fs_info; in ubifs_show_options()
437 if (c->mount_opts.unmount_mode == 2) in ubifs_show_options()
439 else if (c->mount_opts.unmount_mode == 1) in ubifs_show_options()
442 if (c->mount_opts.bulk_read == 2) in ubifs_show_options()
444 else if (c->mount_opts.bulk_read == 1) in ubifs_show_options()
447 if (c->mount_opts.chk_data_crc == 2) in ubifs_show_options()
449 else if (c->mount_opts.chk_data_crc == 1) in ubifs_show_options()
452 if (c->mount_opts.override_compr) { in ubifs_show_options()
454 ubifs_compr_name(c, c->mount_opts.compr_type)); in ubifs_show_options()
458 seq_printf(s, ",ubi=%d,vol=%d", c->vi.ubi_num, c->vi.vol_id); in ubifs_show_options()
466 struct ubifs_info *c = sb->s_fs_info; in ubifs_sync_fs()
471 * '->sync_fs()' call, with non-zero @wait. in ubifs_sync_fs()
480 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_sync_fs()
481 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_sync_fs()
488 * synchronizing write-buffers would be enough. But committing makes in ubifs_sync_fs()
497 return ubi_sync(c->vi.ubi_num); in ubifs_sync_fs()
501 * init_constants_early - initialize UBIFS constants.
502 * @c: UBIFS file-system description object
505 * be read. It also checks that the UBI volume satisfies basic UBIFS
511 if (c->vi.corrupted) { in init_constants_early()
512 ubifs_warn(c, "UBI volume is corrupted - read-only mode"); in init_constants_early()
513 c->ro_media = 1; in init_constants_early()
516 if (c->di.ro_mode) { in init_constants_early()
517 ubifs_msg(c, "read-only UBI device"); in init_constants_early()
518 c->ro_media = 1; in init_constants_early()
521 if (c->vi.vol_type == UBI_STATIC_VOLUME) { in init_constants_early()
522 ubifs_msg(c, "static UBI volume - read-only mode"); in init_constants_early()
523 c->ro_media = 1; in init_constants_early()
526 c->leb_cnt = c->vi.size; in init_constants_early()
527 c->leb_size = c->vi.usable_leb_size; in init_constants_early()
528 c->leb_start = c->di.leb_start; in init_constants_early()
529 c->half_leb_size = c->leb_size / 2; in init_constants_early()
530 c->min_io_size = c->di.min_io_size; in init_constants_early()
531 c->min_io_shift = fls(c->min_io_size) - 1; in init_constants_early()
532 c->max_write_size = c->di.max_write_size; in init_constants_early()
533 c->max_write_shift = fls(c->max_write_size) - 1; in init_constants_early()
535 if (c->leb_size < UBIFS_MIN_LEB_SZ) { in init_constants_early()
537 c->leb_size, UBIFS_MIN_LEB_SZ); in init_constants_early()
538 return -EINVAL; in init_constants_early()
541 if (c->leb_cnt < UBIFS_MIN_LEB_CNT) { in init_constants_early()
543 c->leb_cnt, UBIFS_MIN_LEB_CNT); in init_constants_early()
544 return -EINVAL; in init_constants_early()
547 if (!is_power_of_2(c->min_io_size)) { in init_constants_early()
548 ubifs_errc(c, "bad min. I/O size %d", c->min_io_size); in init_constants_early()
549 return -EINVAL; in init_constants_early()
556 if (c->max_write_size < c->min_io_size || in init_constants_early()
557 c->max_write_size % c->min_io_size || in init_constants_early()
558 !is_power_of_2(c->max_write_size)) { in init_constants_early()
560 c->max_write_size, c->min_io_size); in init_constants_early()
561 return -EINVAL; in init_constants_early()
565 * UBIFS aligns all node to 8-byte boundary, so to make function in in init_constants_early()
569 if (c->min_io_size < 8) { in init_constants_early()
570 c->min_io_size = 8; in init_constants_early()
571 c->min_io_shift = 3; in init_constants_early()
572 if (c->max_write_size < c->min_io_size) { in init_constants_early()
573 c->max_write_size = c->min_io_size; in init_constants_early()
574 c->max_write_shift = c->min_io_shift; in init_constants_early()
578 c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size); in init_constants_early()
579 c->mst_node_alsz = ALIGN(UBIFS_MST_NODE_SZ, c->min_io_size); in init_constants_early()
585 c->ranges[UBIFS_PAD_NODE].len = UBIFS_PAD_NODE_SZ; in init_constants_early()
586 c->ranges[UBIFS_SB_NODE].len = UBIFS_SB_NODE_SZ; in init_constants_early()
587 c->ranges[UBIFS_MST_NODE].len = UBIFS_MST_NODE_SZ; in init_constants_early()
588 c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ; in init_constants_early()
589 c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ; in init_constants_early()
590 c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ; in init_constants_early()
591 c->ranges[UBIFS_AUTH_NODE].min_len = UBIFS_AUTH_NODE_SZ; in init_constants_early()
592 c->ranges[UBIFS_AUTH_NODE].max_len = UBIFS_AUTH_NODE_SZ + in init_constants_early()
594 c->ranges[UBIFS_SIG_NODE].min_len = UBIFS_SIG_NODE_SZ; in init_constants_early()
595 c->ranges[UBIFS_SIG_NODE].max_len = c->leb_size - UBIFS_SB_NODE_SZ; in init_constants_early()
597 c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ; in init_constants_early()
598 c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ; in init_constants_early()
599 c->ranges[UBIFS_ORPH_NODE].min_len = in init_constants_early()
601 c->ranges[UBIFS_ORPH_NODE].max_len = c->leb_size; in init_constants_early()
602 c->ranges[UBIFS_DENT_NODE].min_len = UBIFS_DENT_NODE_SZ; in init_constants_early()
603 c->ranges[UBIFS_DENT_NODE].max_len = UBIFS_MAX_DENT_NODE_SZ; in init_constants_early()
604 c->ranges[UBIFS_XENT_NODE].min_len = UBIFS_XENT_NODE_SZ; in init_constants_early()
605 c->ranges[UBIFS_XENT_NODE].max_len = UBIFS_MAX_XENT_NODE_SZ; in init_constants_early()
606 c->ranges[UBIFS_DATA_NODE].min_len = UBIFS_DATA_NODE_SZ; in init_constants_early()
607 c->ranges[UBIFS_DATA_NODE].max_len = UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
612 c->ranges[UBIFS_IDX_NODE].min_len = UBIFS_IDX_NODE_SZ + UBIFS_BRANCH_SZ; in init_constants_early()
617 c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX; in init_constants_early()
623 c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size); in init_constants_early()
624 c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size); in init_constants_early()
631 c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
633 /* Buffer size for bulk-reads */ in init_constants_early()
634 c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
635 if (c->max_bu_buf_len > c->leb_size) in init_constants_early()
636 c->max_bu_buf_len = c->leb_size; in init_constants_early()
639 c->min_log_bytes = c->leb_size; in init_constants_early()
645 * bud_wbuf_callback - bud LEB write-buffer synchronization call-back.
646 * @c: UBIFS file-system description object
647 * @lnum: LEB the write-buffer was synchronized to
652 * write-buffer is synchronized. We need this to correctly maintain space
665 * init_constants_sb - initialize UBIFS constants.
666 * @c: UBIFS file-system description object
678 c->main_bytes = (long long)c->main_lebs * c->leb_size; in init_constants_sb()
679 c->max_znode_sz = sizeof(struct ubifs_znode) + in init_constants_sb()
680 c->fanout * sizeof(struct ubifs_zbranch); in init_constants_sb()
683 c->ranges[UBIFS_IDX_NODE].min_len = tmp; in init_constants_sb()
684 c->min_idx_node_sz = ALIGN(tmp, 8); in init_constants_sb()
686 tmp = ubifs_idx_node_sz(c, c->fanout); in init_constants_sb()
687 c->ranges[UBIFS_IDX_NODE].max_len = tmp; in init_constants_sb()
688 c->max_idx_node_sz = ALIGN(tmp, 8); in init_constants_sb()
691 tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt; in init_constants_sb()
692 tmp = ALIGN(tmp, c->min_io_size); in init_constants_sb()
693 if (tmp > c->leb_size) { in init_constants_sb()
695 c->leb_size, tmp); in init_constants_sb()
696 return -EINVAL; in init_constants_sb()
703 tmp64 = c->max_bud_bytes + c->leb_size - 1; in init_constants_sb()
704 c->max_bud_cnt = div_u64(tmp64, c->leb_size); in init_constants_sb()
705 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1); in init_constants_sb()
706 tmp /= c->leb_size; in init_constants_sb()
708 if (c->log_lebs < tmp) { in init_constants_sb()
710 c->log_lebs, tmp); in init_constants_sb()
711 return -EINVAL; in init_constants_sb()
715 * When budgeting we assume worst-case scenarios when the pages are not in init_constants_sb()
719 * it is not included into 'c->bi.inode_budget'. in init_constants_sb()
721 c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE; in init_constants_sb()
722 c->bi.inode_budget = UBIFS_INO_NODE_SZ; in init_constants_sb()
723 c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ; in init_constants_sb()
727 * 'c->max_bud_bytes', UBIFS just blocks all writers and starts commit. in init_constants_sb()
732 c->bg_bud_bytes = (c->max_bud_bytes * 13) >> 4; in init_constants_sb()
740 tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1; in init_constants_sb()
741 if (c->bg_bud_bytes < tmp64) in init_constants_sb()
742 c->bg_bud_bytes = tmp64; in init_constants_sb()
743 if (c->max_bud_bytes < tmp64 + c->leb_size) in init_constants_sb()
744 c->max_bud_bytes = tmp64 + c->leb_size; in init_constants_sb()
751 c->idx_leb_size = c->leb_size - c->max_idx_node_sz; in init_constants_sb()
756 * init_constants_master - initialize UBIFS constants.
757 * @c: UBIFS file-system description object
767 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in init_constants_master()
768 c->report_rp_size = ubifs_reported_space(c, c->rp_size); in init_constants_master()
779 tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt; in init_constants_master()
780 tmp64 *= (long long)c->leb_size - c->leb_overhead; in init_constants_master()
782 c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT; in init_constants_master()
786 * take_gc_lnum - reserve GC LEB.
787 * @c: UBIFS file-system description object
791 * space to zero, because lprops may contain out-of-date information if the
792 * file-system was un-mounted before it has been committed. This function
800 if (c->gc_lnum == -1) { in take_gc_lnum()
802 return -EINVAL; in take_gc_lnum()
806 err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0, in take_gc_lnum()
812 * alloc_wbufs - allocate write-buffers.
813 * @c: UBIFS file-system description object
815 * This helper function allocates and initializes UBIFS write-buffers. Returns
816 * zero in case of success and %-ENOMEM in case of failure.
822 c->jheads = kcalloc(c->jhead_cnt, sizeof(struct ubifs_jhead), in alloc_wbufs()
824 if (!c->jheads) in alloc_wbufs()
825 return -ENOMEM; in alloc_wbufs()
828 for (i = 0; i < c->jhead_cnt; i++) { in alloc_wbufs()
829 INIT_LIST_HEAD(&c->jheads[i].buds_list); in alloc_wbufs()
830 err = ubifs_wbuf_init(c, &c->jheads[i].wbuf); in alloc_wbufs()
834 c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback; in alloc_wbufs()
835 c->jheads[i].wbuf.jhead = i; in alloc_wbufs()
836 c->jheads[i].grouped = 1; in alloc_wbufs()
837 c->jheads[i].log_hash = ubifs_hash_get_desc(c); in alloc_wbufs()
838 if (IS_ERR(c->jheads[i].log_hash)) { in alloc_wbufs()
839 err = PTR_ERR(c->jheads[i].log_hash); in alloc_wbufs()
848 c->jheads[GCHD].wbuf.no_timer = 1; in alloc_wbufs()
849 c->jheads[GCHD].grouped = 0; in alloc_wbufs()
854 kfree(c->jheads[i].wbuf.buf); in alloc_wbufs()
855 kfree(c->jheads[i].wbuf.inodes); in alloc_wbufs()
858 while (i--) { in alloc_wbufs()
859 kfree(c->jheads[i].wbuf.buf); in alloc_wbufs()
860 kfree(c->jheads[i].wbuf.inodes); in alloc_wbufs()
861 kfree(c->jheads[i].log_hash); in alloc_wbufs()
863 kfree(c->jheads); in alloc_wbufs()
864 c->jheads = NULL; in alloc_wbufs()
870 * free_wbufs - free write-buffers.
871 * @c: UBIFS file-system description object
877 if (c->jheads) { in free_wbufs()
878 for (i = 0; i < c->jhead_cnt; i++) { in free_wbufs()
879 kfree(c->jheads[i].wbuf.buf); in free_wbufs()
880 kfree(c->jheads[i].wbuf.inodes); in free_wbufs()
881 kfree(c->jheads[i].log_hash); in free_wbufs()
883 kfree(c->jheads); in free_wbufs()
884 c->jheads = NULL; in free_wbufs()
889 * free_orphans - free orphans.
890 * @c: UBIFS file-system description object
896 while (c->orph_dnext) { in free_orphans()
897 orph = c->orph_dnext; in free_orphans()
898 c->orph_dnext = orph->dnext; in free_orphans()
899 list_del(&orph->list); in free_orphans()
903 while (!list_empty(&c->orph_list)) { in free_orphans()
904 orph = list_entry(c->orph_list.next, struct ubifs_orphan, list); in free_orphans()
905 list_del(&orph->list); in free_orphans()
910 vfree(c->orph_buf); in free_orphans()
911 c->orph_buf = NULL; in free_orphans()
915 * free_buds - free per-bud objects.
916 * @c: UBIFS file-system description object
922 rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb) { in free_buds()
923 kfree(bud->log_hash); in free_buds()
929 * check_volume_empty - check if the UBI volume is empty.
930 * @c: UBIFS file-system description object
932 * This function checks if the UBIFS volume is empty by looking if its LEBs are
933 * mapped or not. The result of checking is stored in the @c->empty variable.
941 c->empty = 1; in check_volume_empty()
942 for (lnum = 0; lnum < c->leb_cnt; lnum++) { in check_volume_empty()
947 c->empty = 0; in check_volume_empty()
960 * Opt_fast_unmount: do not run a journal commit before un-mounting
961 * Opt_norm_unmount: run a journal commit before un-mounting
962 * Opt_bulk_read: enable bulk-reads
963 * Opt_no_bulk_read: disable bulk-reads
996 { "read-only", ASSACT_RO },
1012 fsparam_string ("ubi", Opt_ignore),
1028 * ubifs_parse_param - parse a parameter.
1037 struct ubifs_fs_context *ctx = fc->fs_private; in ubifs_parse_param()
1039 bool is_remount = (fc->purpose & FS_CONTEXT_FOR_RECONFIGURE); in ubifs_parse_param()
1049 * We accept them in order to be backward-compatible. But this in ubifs_parse_param()
1053 ctx->mount_opts.unmount_mode = 2; in ubifs_parse_param()
1056 ctx->mount_opts.unmount_mode = 1; in ubifs_parse_param()
1059 ctx->mount_opts.bulk_read = 2; in ubifs_parse_param()
1060 ctx->bulk_read = 1; in ubifs_parse_param()
1063 ctx->mount_opts.bulk_read = 1; in ubifs_parse_param()
1064 ctx->bulk_read = 0; in ubifs_parse_param()
1067 ctx->mount_opts.chk_data_crc = 2; in ubifs_parse_param()
1068 ctx->no_chk_data_crc = 0; in ubifs_parse_param()
1071 ctx->mount_opts.chk_data_crc = 1; in ubifs_parse_param()
1072 ctx->no_chk_data_crc = 1; in ubifs_parse_param()
1075 ctx->mount_opts.compr_type = result.uint_32; in ubifs_parse_param()
1076 ctx->mount_opts.override_compr = 1; in ubifs_parse_param()
1077 ctx->default_compr = ctx->mount_opts.compr_type; in ubifs_parse_param()
1080 ctx->assert_action = result.uint_32; in ubifs_parse_param()
1084 kfree(ctx->auth_key_name); in ubifs_parse_param()
1085 ctx->auth_key_name = param->string; in ubifs_parse_param()
1086 param->string = NULL; in ubifs_parse_param()
1091 kfree(ctx->auth_hash_name); in ubifs_parse_param()
1092 ctx->auth_hash_name = param->string; in ubifs_parse_param()
1093 param->string = NULL; in ubifs_parse_param()
1104 * ubifs_release_options - release mount parameters which have been dumped.
1105 * @c: UBIFS file-system description object
1109 kfree(c->auth_key_name); in ubifs_release_options()
1110 c->auth_key_name = NULL; in ubifs_release_options()
1111 kfree(c->auth_hash_name); in ubifs_release_options()
1112 c->auth_hash_name = NULL; in ubifs_release_options()
1116 * destroy_journal - destroy journal data structures.
1117 * @c: UBIFS file-system description object
1124 while (!list_empty(&c->unclean_leb_list)) { in destroy_journal()
1127 ucleb = list_entry(c->unclean_leb_list.next, in destroy_journal()
1129 list_del(&ucleb->list); in destroy_journal()
1132 while (!list_empty(&c->old_buds)) { in destroy_journal()
1135 bud = list_entry(c->old_buds.next, struct ubifs_bud, list); in destroy_journal()
1136 list_del(&bud->list); in destroy_journal()
1137 kfree(bud->log_hash); in destroy_journal()
1147 * bu_init - initialize bulk-read information.
1148 * @c: UBIFS file-system description object
1152 ubifs_assert(c, c->bulk_read == 1); in bu_init()
1154 if (c->bu.buf) in bu_init()
1158 c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN); in bu_init()
1159 if (!c->bu.buf) { in bu_init()
1160 if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) { in bu_init()
1161 c->max_bu_buf_len = UBIFS_KMALLOC_OK; in bu_init()
1165 /* Just disable bulk-read */ in bu_init()
1166 ubifs_warn(c, "cannot allocate %d bytes of memory for bulk-read, disabling it", in bu_init()
1167 c->max_bu_buf_len); in bu_init()
1168 c->mount_opts.bulk_read = 1; in bu_init()
1169 c->bulk_read = 0; in bu_init()
1175 * check_free_space - check if there is enough free space to mount.
1176 * @c: UBIFS file-system description object
1183 ubifs_assert(c, c->dark_wm > 0); in check_free_space()
1184 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { in check_free_space()
1186 ubifs_dump_budg(c, &c->bi); in check_free_space()
1188 return -ENOSPC; in check_free_space()
1194 * mount_ubifs - mount UBIFS file-system.
1195 * @c: UBIFS file-system description object
1206 c->ro_mount = !!sb_rdonly(c->vfs_sb); in mount_ubifs()
1208 c->probing = !!(c->vfs_sb->s_flags & SB_SILENT); in mount_ubifs()
1226 if (c->empty && (c->ro_mount || c->ro_media)) { in mount_ubifs()
1228 * This UBI volume is empty, and read-only, or the file system in mount_ubifs()
1229 * is mounted read-only - we cannot format it. in mount_ubifs()
1231 ubifs_err(c, "can't format empty UBI volume: read-only %s", in mount_ubifs()
1232 c->ro_media ? "UBI volume" : "mount"); in mount_ubifs()
1233 err = -EROFS; in mount_ubifs()
1237 if (c->ro_media && !c->ro_mount) { in mount_ubifs()
1238 ubifs_err(c, "cannot mount read-write - read-only media"); in mount_ubifs()
1239 err = -EROFS; in mount_ubifs()
1244 * The requirement for the buffer is that it should fit indexing B-tree in mount_ubifs()
1248 err = -ENOMEM; in mount_ubifs()
1249 c->bottom_up_buf = kmalloc_array(BOTTOM_UP_HEIGHT, sizeof(int), in mount_ubifs()
1251 if (!c->bottom_up_buf) in mount_ubifs()
1254 c->sbuf = vmalloc(c->leb_size); in mount_ubifs()
1255 if (!c->sbuf) in mount_ubifs()
1258 if (!c->ro_mount) { in mount_ubifs()
1259 c->ileb_buf = vmalloc(c->leb_size); in mount_ubifs()
1260 if (!c->ileb_buf) in mount_ubifs()
1264 if (c->bulk_read == 1) in mount_ubifs()
1267 if (!c->ro_mount) { in mount_ubifs()
1268 c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \ in mount_ubifs()
1271 if (!c->write_reserve_buf) in mount_ubifs()
1275 c->mounting = 1; in mount_ubifs()
1277 if (c->auth_key_name) { in mount_ubifs()
1285 err = -EINVAL; in mount_ubifs()
1294 c->probing = 0; in mount_ubifs()
1300 if (!ubifs_compr_present(c, c->default_compr)) { in mount_ubifs()
1302 ubifs_compr_name(c, c->default_compr)); in mount_ubifs()
1303 err = -ENOTSUPP; in mount_ubifs()
1311 sz = ALIGN(c->max_idx_node_sz, c->min_io_size) * 2; in mount_ubifs()
1312 c->cbuf = kmalloc(sz, GFP_NOFS); in mount_ubifs()
1313 if (!c->cbuf) { in mount_ubifs()
1314 err = -ENOMEM; in mount_ubifs()
1322 sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id); in mount_ubifs()
1323 if (!c->ro_mount) { in mount_ubifs()
1325 c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name); in mount_ubifs()
1326 if (IS_ERR(c->bgt)) { in mount_ubifs()
1327 err = PTR_ERR(c->bgt); in mount_ubifs()
1328 c->bgt = NULL; in mount_ubifs()
1330 c->bgt_name, err); in mount_ubifs()
1341 if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) { in mount_ubifs()
1343 c->need_recovery = 1; in mount_ubifs()
1346 if (c->need_recovery && !c->ro_mount) { in mount_ubifs()
1347 err = ubifs_recover_inl_heads(c, c->sbuf); in mount_ubifs()
1352 err = ubifs_lpt_init(c, 1, !c->ro_mount); in mount_ubifs()
1356 if (!c->ro_mount && c->space_fixup) { in mount_ubifs()
1362 if (!c->ro_mount && !c->need_recovery) { in mount_ubifs()
1367 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); in mount_ubifs()
1379 if (ubifs_authenticated(c) && ubifs_hmac_zero(c, c->sup_node->hmac)) { in mount_ubifs()
1380 err = ubifs_hmac_wkm(c, c->sup_node->hmac_wkm); in mount_ubifs()
1383 c->superblock_need_write = 1; in mount_ubifs()
1386 if (!c->ro_mount && c->superblock_need_write) { in mount_ubifs()
1387 err = ubifs_write_sb_node(c, c->sup_node); in mount_ubifs()
1390 c->superblock_need_write = 0; in mount_ubifs()
1393 err = dbg_check_idx_size(c, c->bi.old_idx_sz); in mount_ubifs()
1402 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in mount_ubifs()
1404 err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount); in mount_ubifs()
1408 if (!c->ro_mount) { in mount_ubifs()
1416 lnum = c->lhead_lnum + 1; in mount_ubifs()
1417 if (lnum >= UBIFS_LOG_LNUM + c->log_lebs) in mount_ubifs()
1419 if (lnum == c->ltail_lnum) { in mount_ubifs()
1425 if (c->need_recovery) { in mount_ubifs()
1448 * reboot, and it should be un-mapped. in mount_ubifs()
1450 err = ubifs_leb_unmap(c, c->gc_lnum); in mount_ubifs()
1458 } else if (c->need_recovery) { in mount_ubifs()
1464 * Even if we mount read-only, we have to set space in GC LEB in mount_ubifs()
1467 * re-mounting from R/O to R/W changes amount of free space. in mount_ubifs()
1475 list_add_tail(&c->infos_list, &ubifs_infos); in mount_ubifs()
1478 if (c->need_recovery) { in mount_ubifs()
1479 if (c->ro_mount) in mount_ubifs()
1482 c->need_recovery = 0; in mount_ubifs()
1489 ubifs_assert(c, c->lst.taken_empty_lebs > 0); in mount_ubifs()
1492 ubifs_assert(c, c->lst.taken_empty_lebs > 0); in mount_ubifs()
1500 c->mounting = 0; in mount_ubifs()
1502 ubifs_msg(c, "UBIFS: mounted UBI device %d, volume %d, name \"%s\"%s", in mount_ubifs()
1503 c->vi.ubi_num, c->vi.vol_id, c->vi.name, in mount_ubifs()
1504 c->ro_mount ? ", R/O mode" : ""); in mount_ubifs()
1505 x = (long long)c->main_lebs * c->leb_size; in mount_ubifs()
1506 y = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes; in mount_ubifs()
1508 c->leb_size, c->leb_size >> 10, c->min_io_size, in mount_ubifs()
1509 c->max_write_size); in mount_ubifs()
1511 x, x >> 20, c->main_lebs, c->max_leb_cnt, in mount_ubifs()
1512 y, y >> 20, c->log_lebs + c->max_bud_cnt); in mount_ubifs()
1514 c->report_rp_size, c->report_rp_size >> 10); in mount_ubifs()
1516 c->fmt_version, c->ro_compat_version, in mount_ubifs()
1517 UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION, c->uuid, in mount_ubifs()
1518 c->big_lpt ? ", big LPT model" : ", small LPT model"); in mount_ubifs()
1520 dbg_gen("default compressor: %s", ubifs_compr_name(c, c->default_compr)); in mount_ubifs()
1522 c->jhead_cnt - NONDATA_JHEADS_CNT); in mount_ubifs()
1523 dbg_gen("log LEBs: %d (%d - %d)", in mount_ubifs()
1524 c->log_lebs, UBIFS_LOG_LNUM, c->log_last); in mount_ubifs()
1525 dbg_gen("LPT area LEBs: %d (%d - %d)", in mount_ubifs()
1526 c->lpt_lebs, c->lpt_first, c->lpt_last); in mount_ubifs()
1527 dbg_gen("orphan area LEBs: %d (%d - %d)", in mount_ubifs()
1528 c->orph_lebs, c->orph_first, c->orph_last); in mount_ubifs()
1529 dbg_gen("main area LEBs: %d (%d - %d)", in mount_ubifs()
1530 c->main_lebs, c->main_first, c->leb_cnt - 1); in mount_ubifs()
1531 dbg_gen("index LEBs: %d", c->lst.idx_lebs); in mount_ubifs()
1533 c->bi.old_idx_sz, c->bi.old_idx_sz >> 10, in mount_ubifs()
1534 c->bi.old_idx_sz >> 20); in mount_ubifs()
1535 dbg_gen("key hash type: %d", c->key_hash_type); in mount_ubifs()
1536 dbg_gen("tree fanout: %d", c->fanout); in mount_ubifs()
1537 dbg_gen("reserved GC LEB: %d", c->gc_lnum); in mount_ubifs()
1538 dbg_gen("max. znode size %d", c->max_znode_sz); in mount_ubifs()
1539 dbg_gen("max. index node size %d", c->max_idx_node_sz); in mount_ubifs()
1548 UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout)); in mount_ubifs()
1549 dbg_gen("dead watermark: %d", c->dead_wm); in mount_ubifs()
1550 dbg_gen("dark watermark: %d", c->dark_wm); in mount_ubifs()
1551 dbg_gen("LEB overhead: %d", c->leb_overhead); in mount_ubifs()
1552 x = (long long)c->main_lebs * c->dark_wm; in mount_ubifs()
1556 c->max_bud_bytes, c->max_bud_bytes >> 10, in mount_ubifs()
1557 c->max_bud_bytes >> 20); in mount_ubifs()
1559 c->bg_bud_bytes, c->bg_bud_bytes >> 10, in mount_ubifs()
1560 c->bg_bud_bytes >> 20); in mount_ubifs()
1562 c->bud_bytes, c->bud_bytes >> 10, c->bud_bytes >> 20); in mount_ubifs()
1563 dbg_gen("max. seq. number: %llu", c->max_sqnum); in mount_ubifs()
1564 dbg_gen("commit number: %llu", c->cmt_no); in mount_ubifs()
1566 dbg_gen("max orphans: %d", c->max_orphans); in mount_ubifs()
1572 list_del(&c->infos_list); in mount_ubifs()
1581 kfree(c->mst_node); in mount_ubifs()
1582 kfree(c->rcvrd_mst_node); in mount_ubifs()
1583 if (c->bgt) in mount_ubifs()
1584 kthread_stop(c->bgt); in mount_ubifs()
1588 kfree(c->cbuf); in mount_ubifs()
1592 kfree(c->write_reserve_buf); in mount_ubifs()
1593 kfree(c->bu.buf); in mount_ubifs()
1594 vfree(c->ileb_buf); in mount_ubifs()
1595 vfree(c->sbuf); in mount_ubifs()
1596 kfree(c->bottom_up_buf); in mount_ubifs()
1597 kfree(c->sup_node); in mount_ubifs()
1605 * ubifs_umount - un-mount UBIFS file-system.
1606 * @c: UBIFS file-system description object
1608 * Note, this function is called to free allocated resourced when un-mounting,
1615 dbg_gen("un-mounting UBI device %d, volume %d", c->vi.ubi_num, in ubifs_umount()
1616 c->vi.vol_id); in ubifs_umount()
1620 list_del(&c->infos_list); in ubifs_umount()
1623 if (c->bgt) in ubifs_umount()
1624 kthread_stop(c->bgt); in ubifs_umount()
1633 kfree(c->cbuf); in ubifs_umount()
1634 kfree(c->rcvrd_mst_node); in ubifs_umount()
1635 kfree(c->mst_node); in ubifs_umount()
1636 kfree(c->write_reserve_buf); in ubifs_umount()
1637 kfree(c->bu.buf); in ubifs_umount()
1638 vfree(c->ileb_buf); in ubifs_umount()
1639 vfree(c->sbuf); in ubifs_umount()
1640 kfree(c->bottom_up_buf); in ubifs_umount()
1641 kfree(c->sup_node); in ubifs_umount()
1647 * ubifs_remount_rw - re-mount in read-write mode.
1648 * @c: UBIFS file-system description object
1650 * UBIFS avoids allocating many unnecessary resources when mounted in read-only
1651 * mode. This function allocates the needed resources and re-mounts UBIFS in
1652 * read-write mode.
1658 if (c->rw_incompat) { in ubifs_remount_rw()
1659 ubifs_err(c, "the file-system is not R/W-compatible"); in ubifs_remount_rw()
1660 …ubifs_msg(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d… in ubifs_remount_rw()
1661 c->fmt_version, c->ro_compat_version, in ubifs_remount_rw()
1663 return -EROFS; in ubifs_remount_rw()
1666 mutex_lock(&c->umount_mutex); in ubifs_remount_rw()
1668 c->remounting_rw = 1; in ubifs_remount_rw()
1669 c->ro_mount = 0; in ubifs_remount_rw()
1671 if (c->space_fixup) { in ubifs_remount_rw()
1681 if (c->need_recovery) { in ubifs_remount_rw()
1691 err = ubifs_clean_lebs(c, c->sbuf); in ubifs_remount_rw()
1694 err = ubifs_recover_inl_heads(c, c->sbuf); in ubifs_remount_rw()
1699 ubifs_assert(c, c->tot_orphans == 0); in ubifs_remount_rw()
1705 if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) { in ubifs_remount_rw()
1706 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_remount_rw()
1712 if (c->superblock_need_write) { in ubifs_remount_rw()
1713 struct ubifs_sb_node *sup = c->sup_node; in ubifs_remount_rw()
1719 c->superblock_need_write = 0; in ubifs_remount_rw()
1722 c->ileb_buf = vmalloc(c->leb_size); in ubifs_remount_rw()
1723 if (!c->ileb_buf) { in ubifs_remount_rw()
1724 err = -ENOMEM; in ubifs_remount_rw()
1728 c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \ in ubifs_remount_rw()
1730 if (!c->write_reserve_buf) { in ubifs_remount_rw()
1731 err = -ENOMEM; in ubifs_remount_rw()
1740 c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name); in ubifs_remount_rw()
1741 if (IS_ERR(c->bgt)) { in ubifs_remount_rw()
1742 err = PTR_ERR(c->bgt); in ubifs_remount_rw()
1743 c->bgt = NULL; in ubifs_remount_rw()
1745 c->bgt_name, err); in ubifs_remount_rw()
1749 c->orph_buf = vmalloc(c->leb_size); in ubifs_remount_rw()
1750 if (!c->orph_buf) { in ubifs_remount_rw()
1751 err = -ENOMEM; in ubifs_remount_rw()
1756 lnum = c->lhead_lnum + 1; in ubifs_remount_rw()
1757 if (lnum >= UBIFS_LOG_LNUM + c->log_lebs) in ubifs_remount_rw()
1759 if (lnum == c->ltail_lnum) { in ubifs_remount_rw()
1765 if (c->need_recovery) { in ubifs_remount_rw()
1776 err = ubifs_leb_unmap(c, c->gc_lnum); in ubifs_remount_rw()
1781 dbg_gen("re-mounted read-write"); in ubifs_remount_rw()
1782 c->remounting_rw = 0; in ubifs_remount_rw()
1784 if (c->need_recovery) { in ubifs_remount_rw()
1785 c->need_recovery = 0; in ubifs_remount_rw()
1791 * file-system in a state where the TNC and lprops has been in ubifs_remount_rw()
1793 * commit) were deferred. So the file-system was in in ubifs_remount_rw()
1794 * "non-committed" state. Now the file-system is in committed in ubifs_remount_rw()
1801 mutex_unlock(&c->umount_mutex); in ubifs_remount_rw()
1805 c->ro_mount = 1; in ubifs_remount_rw()
1806 vfree(c->orph_buf); in ubifs_remount_rw()
1807 c->orph_buf = NULL; in ubifs_remount_rw()
1808 if (c->bgt) { in ubifs_remount_rw()
1809 kthread_stop(c->bgt); in ubifs_remount_rw()
1810 c->bgt = NULL; in ubifs_remount_rw()
1812 kfree(c->write_reserve_buf); in ubifs_remount_rw()
1813 c->write_reserve_buf = NULL; in ubifs_remount_rw()
1814 vfree(c->ileb_buf); in ubifs_remount_rw()
1815 c->ileb_buf = NULL; in ubifs_remount_rw()
1817 c->remounting_rw = 0; in ubifs_remount_rw()
1818 mutex_unlock(&c->umount_mutex); in ubifs_remount_rw()
1823 * ubifs_remount_ro - re-mount in read-only mode.
1824 * @c: UBIFS file-system description object
1833 ubifs_assert(c, !c->need_recovery); in ubifs_remount_ro()
1834 ubifs_assert(c, !c->ro_mount); in ubifs_remount_ro()
1836 mutex_lock(&c->umount_mutex); in ubifs_remount_ro()
1837 if (c->bgt) { in ubifs_remount_ro()
1838 kthread_stop(c->bgt); in ubifs_remount_ro()
1839 c->bgt = NULL; in ubifs_remount_ro()
1844 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_remount_ro()
1845 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_remount_ro()
1850 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_remount_ro()
1851 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in ubifs_remount_ro()
1852 c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); in ubifs_remount_ro()
1857 vfree(c->orph_buf); in ubifs_remount_ro()
1858 c->orph_buf = NULL; in ubifs_remount_ro()
1859 kfree(c->write_reserve_buf); in ubifs_remount_ro()
1860 c->write_reserve_buf = NULL; in ubifs_remount_ro()
1861 vfree(c->ileb_buf); in ubifs_remount_ro()
1862 c->ileb_buf = NULL; in ubifs_remount_ro()
1864 c->ro_mount = 1; in ubifs_remount_ro()
1868 mutex_unlock(&c->umount_mutex); in ubifs_remount_ro()
1874 struct ubifs_info *c = sb->s_fs_info; in ubifs_put_super()
1876 ubifs_msg(c, "un-mount UBI device %d", c->vi.ubi_num); in ubifs_put_super()
1883 if (!c->ro_error) { in ubifs_put_super()
1884 ubifs_assert(c, c->bi.idx_growth == 0); in ubifs_put_super()
1885 ubifs_assert(c, c->bi.dd_growth == 0); in ubifs_put_super()
1886 ubifs_assert(c, c->bi.data_growth == 0); in ubifs_put_super()
1890 * The 'c->umount_lock' prevents races between UBIFS memory shrinker in ubifs_put_super()
1891 * and file system un-mount. Namely, it prevents the shrinker from in ubifs_put_super()
1892 * picking this superblock for shrinking - it will be just skipped if in ubifs_put_super()
1895 mutex_lock(&c->umount_mutex); in ubifs_put_super()
1896 if (!c->ro_mount) { in ubifs_put_super()
1899 * not interfere with un-mounting and freeing resources. in ubifs_put_super()
1901 if (c->bgt) { in ubifs_put_super()
1902 kthread_stop(c->bgt); in ubifs_put_super()
1903 c->bgt = NULL; in ubifs_put_super()
1907 * On fatal errors c->ro_error is set to 1, in which case we do in ubifs_put_super()
1910 if (!c->ro_error) { in ubifs_put_super()
1913 /* Synchronize write-buffers */ in ubifs_put_super()
1914 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_put_super()
1915 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_put_super()
1922 * orphans were killed - indicate this in the master in ubifs_put_super()
1925 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_put_super()
1926 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in ubifs_put_super()
1927 c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); in ubifs_put_super()
1938 for (i = 0; i < c->jhead_cnt; i++) in ubifs_put_super()
1939 /* Make sure write-buffer timers are canceled */ in ubifs_put_super()
1940 hrtimer_cancel(&c->jheads[i].wbuf.timer); in ubifs_put_super()
1945 ubi_close_volume(c->ubi); in ubifs_put_super()
1946 mutex_unlock(&c->umount_mutex); in ubifs_put_super()
1951 struct ubifs_fs_context *ctx = fc->fs_private; in ubifs_reconfigure()
1952 struct super_block *sb = fc->root->d_sb; in ubifs_reconfigure()
1954 struct ubifs_info *c = sb->s_fs_info; in ubifs_reconfigure()
1957 dbg_gen("old flags %#lx, new flags %#x", sb->s_flags, fc->sb_flags); in ubifs_reconfigure()
1963 c->mount_opts = ctx->mount_opts; in ubifs_reconfigure()
1964 c->bulk_read = ctx->bulk_read; in ubifs_reconfigure()
1965 c->no_chk_data_crc = ctx->no_chk_data_crc; in ubifs_reconfigure()
1966 c->default_compr = ctx->default_compr; in ubifs_reconfigure()
1967 c->assert_action = ctx->assert_action; in ubifs_reconfigure()
1969 if (c->ro_mount && !(fc->sb_flags & SB_RDONLY)) { in ubifs_reconfigure()
1970 if (c->ro_error) { in ubifs_reconfigure()
1971 ubifs_msg(c, "cannot re-mount R/W due to prior errors"); in ubifs_reconfigure()
1972 return -EROFS; in ubifs_reconfigure()
1974 if (c->ro_media) { in ubifs_reconfigure()
1975 ubifs_msg(c, "cannot re-mount R/W - UBI volume is R/O"); in ubifs_reconfigure()
1976 return -EROFS; in ubifs_reconfigure()
1981 } else if (!c->ro_mount && (fc->sb_flags & SB_RDONLY)) { in ubifs_reconfigure()
1982 if (c->ro_error) { in ubifs_reconfigure()
1983 ubifs_msg(c, "cannot re-mount R/O due to prior errors"); in ubifs_reconfigure()
1984 return -EROFS; in ubifs_reconfigure()
1989 if (c->bulk_read == 1) in ubifs_reconfigure()
1992 dbg_gen("disable bulk-read"); in ubifs_reconfigure()
1993 mutex_lock(&c->bu_mutex); in ubifs_reconfigure()
1994 kfree(c->bu.buf); in ubifs_reconfigure()
1995 c->bu.buf = NULL; in ubifs_reconfigure()
1996 mutex_unlock(&c->bu_mutex); in ubifs_reconfigure()
1999 if (!c->need_recovery) in ubifs_reconfigure()
2000 ubifs_assert(c, c->lst.taken_empty_lebs > 0); in ubifs_reconfigure()
2019 * open_ubi - parse UBI device name string and open the UBI device.
2021 * @mode: UBI volume open mode
2023 * The primary method of mounting UBIFS is by specifying the UBI volume
2027 * o ubiX_Y - mount UBI device number X, volume Y;
2028 * o ubiY - mount UBI device number 0, volume Y;
2029 * o ubiX:NAME - mount UBI device X, volume with name NAME;
2030 * o ubi:NAME - mount UBI device 0, volume with name NAME.
2034 * returns UBI volume description object in case of success and a negative
2039 struct ubi_volume_desc *ubi; in open_ubi() local
2040 const char *name = fc->source; in open_ubi()
2045 ubi = ubi_open_volume_path(name, mode); in open_ubi()
2046 if (!IS_ERR(ubi)) in open_ubi()
2047 return ubi; in open_ubi()
2053 /* ubi:NAME method */ in open_ubi()
2082 static struct ubifs_info *alloc_ubifs_info(struct ubi_volume_desc *ubi) in alloc_ubifs_info() argument
2088 spin_lock_init(&c->cnt_lock); in alloc_ubifs_info()
2089 spin_lock_init(&c->cs_lock); in alloc_ubifs_info()
2090 spin_lock_init(&c->buds_lock); in alloc_ubifs_info()
2091 spin_lock_init(&c->space_lock); in alloc_ubifs_info()
2092 spin_lock_init(&c->orphan_lock); in alloc_ubifs_info()
2093 init_rwsem(&c->commit_sem); in alloc_ubifs_info()
2094 mutex_init(&c->lp_mutex); in alloc_ubifs_info()
2095 mutex_init(&c->tnc_mutex); in alloc_ubifs_info()
2096 mutex_init(&c->log_mutex); in alloc_ubifs_info()
2097 mutex_init(&c->umount_mutex); in alloc_ubifs_info()
2098 mutex_init(&c->bu_mutex); in alloc_ubifs_info()
2099 mutex_init(&c->write_reserve_mutex); in alloc_ubifs_info()
2100 init_waitqueue_head(&c->cmt_wq); in alloc_ubifs_info()
2101 init_waitqueue_head(&c->reserve_space_wq); in alloc_ubifs_info()
2102 atomic_set(&c->need_wait_space, 0); in alloc_ubifs_info()
2103 c->buds = RB_ROOT; in alloc_ubifs_info()
2104 c->old_idx = RB_ROOT; in alloc_ubifs_info()
2105 c->size_tree = RB_ROOT; in alloc_ubifs_info()
2106 c->orph_tree = RB_ROOT; in alloc_ubifs_info()
2107 INIT_LIST_HEAD(&c->infos_list); in alloc_ubifs_info()
2108 INIT_LIST_HEAD(&c->idx_gc); in alloc_ubifs_info()
2109 INIT_LIST_HEAD(&c->replay_list); in alloc_ubifs_info()
2110 INIT_LIST_HEAD(&c->replay_buds); in alloc_ubifs_info()
2111 INIT_LIST_HEAD(&c->uncat_list); in alloc_ubifs_info()
2112 INIT_LIST_HEAD(&c->empty_list); in alloc_ubifs_info()
2113 INIT_LIST_HEAD(&c->freeable_list); in alloc_ubifs_info()
2114 INIT_LIST_HEAD(&c->frdi_idx_list); in alloc_ubifs_info()
2115 INIT_LIST_HEAD(&c->unclean_leb_list); in alloc_ubifs_info()
2116 INIT_LIST_HEAD(&c->old_buds); in alloc_ubifs_info()
2117 INIT_LIST_HEAD(&c->orph_list); in alloc_ubifs_info()
2118 INIT_LIST_HEAD(&c->orph_new); in alloc_ubifs_info()
2119 c->no_chk_data_crc = 1; in alloc_ubifs_info()
2120 c->assert_action = ASSACT_RO; in alloc_ubifs_info()
2122 c->highest_inum = UBIFS_FIRST_INO; in alloc_ubifs_info()
2123 c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM; in alloc_ubifs_info()
2125 ubi_get_volume_info(ubi, &c->vi); in alloc_ubifs_info()
2126 ubi_get_device_info(c->vi.ubi_num, &c->di); in alloc_ubifs_info()
2133 struct ubifs_info *c = sb->s_fs_info; in ubifs_fill_super()
2134 struct ubifs_fs_context *ctx = fc->fs_private; in ubifs_fill_super()
2138 c->vfs_sb = sb; in ubifs_fill_super()
2139 /* Re-open the UBI device in read-write mode */ in ubifs_fill_super()
2140 c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE); in ubifs_fill_super()
2141 if (IS_ERR(c->ubi)) { in ubifs_fill_super()
2142 err = PTR_ERR(c->ubi); in ubifs_fill_super()
2147 c->mount_opts = ctx->mount_opts; in ubifs_fill_super()
2148 c->auth_key_name = ctx->auth_key_name; in ubifs_fill_super()
2149 c->auth_hash_name = ctx->auth_hash_name; in ubifs_fill_super()
2150 c->no_chk_data_crc = ctx->no_chk_data_crc; in ubifs_fill_super()
2151 c->bulk_read = ctx->bulk_read; in ubifs_fill_super()
2152 c->default_compr = ctx->default_compr; in ubifs_fill_super()
2153 c->assert_action = ctx->assert_action; in ubifs_fill_super()
2156 ctx->auth_key_name = NULL; in ubifs_fill_super()
2157 ctx->auth_hash_name = NULL; in ubifs_fill_super()
2160 * UBIFS provides 'backing_dev_info' in order to disable read-ahead. For in ubifs_fill_super()
2163 * but the read-ahead I/O as well i.e. completely pointless. in ubifs_fill_super()
2165 * Read-ahead will be disabled because @sb->s_bdi->ra_pages is 0. Also in ubifs_fill_super()
2166 * @sb->s_bdi->capabilities are initialized to 0 so there won't be any in ubifs_fill_super()
2169 err = super_setup_bdi_name(sb, "ubifs_%d_%d", c->vi.ubi_num, in ubifs_fill_super()
2170 c->vi.vol_id); in ubifs_fill_super()
2173 sb->s_bdi->ra_pages = 0; in ubifs_fill_super()
2174 sb->s_bdi->io_pages = 0; in ubifs_fill_super()
2176 sb->s_fs_info = c; in ubifs_fill_super()
2177 sb->s_magic = UBIFS_SUPER_MAGIC; in ubifs_fill_super()
2178 sb->s_blocksize = UBIFS_BLOCK_SIZE; in ubifs_fill_super()
2179 sb->s_blocksize_bits = UBIFS_BLOCK_SHIFT; in ubifs_fill_super()
2180 sb->s_maxbytes = c->max_inode_sz = key_max_inode_size(c); in ubifs_fill_super()
2181 if (c->max_inode_sz > MAX_LFS_FILESIZE) in ubifs_fill_super()
2182 sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE; in ubifs_fill_super()
2183 sb->s_op = &ubifs_super_operations; in ubifs_fill_super()
2184 sb->s_xattr = ubifs_xattr_handlers; in ubifs_fill_super()
2187 mutex_lock(&c->umount_mutex); in ubifs_fill_super()
2202 sb->s_root = d_make_root(root); in ubifs_fill_super()
2203 if (!sb->s_root) { in ubifs_fill_super()
2204 err = -ENOMEM; in ubifs_fill_super()
2208 super_set_uuid(sb, c->uuid, sizeof(c->uuid)); in ubifs_fill_super()
2210 c->vi.ubi_num, c->vi.vol_id); in ubifs_fill_super()
2212 mutex_unlock(&c->umount_mutex); in ubifs_fill_super()
2218 mutex_unlock(&c->umount_mutex); in ubifs_fill_super()
2221 ubi_close_volume(c->ubi); in ubifs_fill_super()
2228 struct ubifs_info *c1 = fc->s_fs_info; in sb_test()
2229 struct ubifs_info *c = sb->s_fs_info; in sb_test()
2231 return c->vi.cdev == c1->vi.cdev; in sb_test()
2236 struct ubi_volume_desc *ubi; in ubifs_get_tree() local
2241 if (!fc->source || !*fc->source) in ubifs_get_tree()
2244 dbg_gen("name %s, flags %#x", fc->source, fc->sb_flags); in ubifs_get_tree()
2247 * Get UBI device number and volume ID. Mount it read-only so far in ubifs_get_tree()
2248 * because this might be a new mount point, and UBI allows only one in ubifs_get_tree()
2249 * read-write user at a time. in ubifs_get_tree()
2251 ubi = open_ubi(fc, UBI_READONLY); in ubifs_get_tree()
2252 if (IS_ERR(ubi)) { in ubifs_get_tree()
2253 err = PTR_ERR(ubi); in ubifs_get_tree()
2254 if (!(fc->sb_flags & SB_SILENT)) in ubifs_get_tree()
2256 current->pid, fc->source, err); in ubifs_get_tree()
2260 c = alloc_ubifs_info(ubi); in ubifs_get_tree()
2262 err = -ENOMEM; in ubifs_get_tree()
2265 fc->s_fs_info = c; in ubifs_get_tree()
2267 dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); in ubifs_get_tree()
2276 if (sb->s_root) { in ubifs_get_tree()
2277 struct ubifs_info *c1 = sb->s_fs_info; in ubifs_get_tree()
2280 dbg_gen("this ubi volume is already mounted"); in ubifs_get_tree()
2281 if (!!(fc->sb_flags & SB_RDONLY) != c1->ro_mount) { in ubifs_get_tree()
2282 err = -EBUSY; in ubifs_get_tree()
2290 sb->s_flags |= SB_ACTIVE; in ubifs_get_tree()
2294 sb->s_flags |= SB_NOATIME; in ubifs_get_tree()
2297 /* 'fill_super()' opens ubi again so we must close it here */ in ubifs_get_tree()
2298 ubi_close_volume(ubi); in ubifs_get_tree()
2300 fc->root = dget(sb->s_root); in ubifs_get_tree()
2306 ubi_close_volume(ubi); in ubifs_get_tree()
2312 struct ubifs_info *c = s->s_fs_info; in kill_ubifs_super()
2319 struct ubifs_fs_context *ctx = fc->fs_private; in ubifs_free_fc()
2322 kfree(ctx->auth_key_name); in ubifs_free_fc()
2323 kfree(ctx->auth_hash_name); in ubifs_free_fc()
2341 return -ENOMEM; in ubifs_init_fs_context()
2343 if (fc->purpose != FS_CONTEXT_FOR_RECONFIGURE) { in ubifs_init_fs_context()
2345 ctx->no_chk_data_crc = 1; in ubifs_init_fs_context()
2346 ctx->assert_action = ASSACT_RO; in ubifs_init_fs_context()
2348 struct ubifs_info *c = fc->root->d_sb->s_fs_info; in ubifs_init_fs_context()
2354 ctx->mount_opts = c->mount_opts; in ubifs_init_fs_context()
2355 ctx->bulk_read = c->bulk_read; in ubifs_init_fs_context()
2356 ctx->no_chk_data_crc = c->no_chk_data_crc; in ubifs_init_fs_context()
2357 ctx->default_compr = c->default_compr; in ubifs_init_fs_context()
2358 ctx->assert_action = c->assert_action; in ubifs_init_fs_context()
2361 fc->ops = &ubifs_context_ops; in ubifs_init_fs_context()
2362 fc->fs_private = ctx; in ubifs_init_fs_context()
2382 inode_init_once(&ui->vfs_inode); in inode_slab_ctor()
2387 int err = -ENOMEM; in ubifs_init()
2391 /* Make sure node sizes are 8-byte aligned */ in ubifs_init()
2429 * We use 2 bit wide bit-fields to store compression type, which should in ubifs_init()
2430 * be amended if more compressors are added. The bit-fields are: in ubifs_init()
2437 * We require that PAGE_SIZE is greater-than-or-equal-to in ubifs_init()
2442 current->pid, (unsigned int)PAGE_SIZE); in ubifs_init()
2443 return -EINVAL; in ubifs_init()
2451 return -ENOMEM; in ubifs_init()
2453 ubifs_shrinker_info = shrinker_alloc(0, "ubifs-slab"); in ubifs_init()
2457 ubifs_shrinker_info->count_objects = ubifs_shrink_count; in ubifs_init()
2458 ubifs_shrinker_info->scan_objects = ubifs_shrink_scan; in ubifs_init()
2475 current->pid, err); in ubifs_init()
2517 MODULE_DESCRIPTION("UBIFS - UBI File System");