30 #include <linux/slab.h>
31 #include <linux/module.h>
32 #include <linux/ctype.h>
45 #define UBIFS_KMALLOC_OK (128*1024)
51 static struct shrinker ubifs_shrinker_info = {
92 ubifs_warn(
"inode %lu uses '%s' compression, but it was not compiled in",
124 ino_key_init(c, &key, inode->
i_ino);
126 err = ubifs_tnc_lookup(c, &key, ino);
154 err = validate_inode(c, inode);
247 ubifs_err(
"inode %lu validation failed, error %d", inode->
i_ino, err);
254 ubifs_err(
"failed to read inode %lu, error %d", inode->
i_ino, err);
259 static struct inode *ubifs_alloc_inode(
struct super_block *
sb)
267 memset((
void *)ui +
sizeof(
struct inode), 0,
268 sizeof(
struct ubifs_inode) -
sizeof(
struct inode));
281 static void ubifs_destroy_inode(
struct inode *inode)
319 dbg_gen(
"inode %lu, mode %#x, nlink %u",
324 ubifs_err(
"can't write inode %lu, error %d",
336 static void ubifs_evict_inode(
struct inode *inode)
368 ubifs_err(
"can't delete inode %lu, error %d",
376 c->
bi.nospace = c->
bi.nospace_rp = 0;
383 static void ubifs_dirty_inode(
struct inode *inode,
int flags)
397 unsigned long long free;
401 dbg_gen(
"free space %lld bytes (%lld blocks)",
421 static int ubifs_show_options(
struct seq_file *
s,
struct dentry *root)
466 err = ubifs_wbuf_sync(&c->
jheads[i].wbuf);
494 static int init_constants_early(
struct ubifs_info *c)
496 if (c->
vi.corrupted) {
497 ubifs_warn(
"UBI volume is corrupted - read-only mode");
507 ubifs_msg(
"static UBI volume - read-only mode");
521 ubifs_err(
"too small LEBs (%d bytes), min. is %d bytes",
527 ubifs_err(
"too few LEBs (%d), min. is %d",
544 ubifs_err(
"bad write buffer size %d for %d min. I/O unit",
635 static int bud_wbuf_callback(
struct ubifs_info *c,
int lnum,
int free,
int pad)
649 static int init_constants_sb(
struct ubifs_info *c)
658 tmp = ubifs_idx_node_sz(c, 1);
662 tmp = ubifs_idx_node_sz(c, c->
fanout);
670 ubifs_err(
"too small LEB size %d, at least %d needed",
685 ubifs_err(
"too small log %d LEBs, required min. %d LEBs",
739 static void init_constants_master(
struct ubifs_info *c)
805 INIT_LIST_HEAD(&c->
jheads[i].buds_list);
810 c->
jheads[
i].wbuf.sync_callback = &bud_wbuf_callback;
847 static void free_orphans(
struct ubifs_info *c)
862 ubifs_err(
"orphan list not empty at unmount");
906 static int check_volume_empty(
struct ubifs_info *c)
911 for (lnum = 0; lnum < c->
leb_cnt; lnum++) {
973 static int parse_standard_option(
const char *
option)
976 if (!
strcmp(option,
"sync"))
999 while ((p =
strsep(&options,
","))) {
1040 if (!
strcmp(name,
"none"))
1042 else if (!
strcmp(name,
"lzo"))
1044 else if (!
strcmp(name,
"zlib"))
1047 ubifs_err(
"unknown compressor \"%s\"", name);
1061 flag = parse_standard_option(p);
1063 ubifs_err(
"unrecognized mount option \"%s\" or missing value",
1083 static void destroy_journal(
struct ubifs_info *c)
1093 while (!list_empty(&c->
old_buds)) {
1126 ubifs_warn(
"cannot allocate %d bytes of memory for bulk-read, disabling it",
1141 static int check_free_space(
struct ubifs_info *c)
1145 ubifs_err(
"insufficient free space to mount in R/W mode");
1167 err = init_constants_early(c);
1175 err = check_volume_empty(c);
1184 ubifs_err(
"can't format empty UBI volume: read-only %s",
1185 c->
ro_media ?
"UBI volume" :
"mount");
1191 ubifs_err(
"cannot mount read-write - read-only media");
1237 ubifs_err(
"'compressor \"%s\" is not compiled in",
1243 err = init_constants_sb(c);
1255 err = alloc_wbufs(c);
1263 if (IS_ERR(c->
bgt)) {
1264 err = PTR_ERR(c->
bgt);
1266 ubifs_err(
"cannot spawn \"%s\", error %d",
1277 init_constants_master(c);
1329 err = check_free_space(c);
1351 err = take_gc_lnum(c);
1378 err = take_gc_lnum(c);
1383 spin_lock(&ubifs_infos_lock);
1385 spin_unlock(&ubifs_infos_lock);
1413 ubifs_msg(
"mounted UBI device %d, volume %d, name \"%s\"%s",
1414 c->
vi.ubi_num, c->
vi.vol_id, c->
vi.name,
1418 ubifs_msg(
"LEB size: %d bytes (%d KiB), min./max. I/O unit sizes: %d bytes/%d bytes",
1421 ubifs_msg(
"FS size: %lld bytes (%lld MiB, %d LEBs), journal size %lld bytes (%lld MiB, %d LEBs)",
1424 ubifs_msg(
"reserved for root: %llu bytes (%llu KiB)",
1426 ubifs_msg(
"media format: w%d/r%d (latest is w%d/r%d), UUID %pUB%s",
1429 c->
big_lpt ?
", big LPT model" :
", small LPT model");
1432 dbg_gen(
"data journal heads: %d",
1434 dbg_gen(
"log LEBs: %d (%d - %d)",
1436 dbg_gen(
"LPT area LEBs: %d (%d - %d)",
1438 dbg_gen(
"orphan area LEBs: %d (%d - %d)",
1440 dbg_gen(
"main area LEBs: %d (%d - %d)",
1443 dbg_gen(
"total index bytes: %lld (%lld KiB, %lld MiB)",
1444 c->
bi.old_idx_sz, c->
bi.old_idx_sz >> 10,
1445 c->
bi.old_idx_sz >> 20);
1451 dbg_gen(
"node sizes: data %zu, inode %zu, dentry %zu",
1453 dbg_gen(
"node sizes: trun %zu, sb %zu, master %zu",
1455 dbg_gen(
"node sizes: ref %zu, cmt. start %zu, orph %zu",
1457 dbg_gen(
"max. node sizes: data %zu, inode %zu dentry %zu, idx %d",
1464 dbg_gen(
"max. dark space: %lld (%lld KiB, %lld MiB)",
1465 x, x >> 10, x >> 20);
1466 dbg_gen(
"maximum bud bytes: %lld (%lld KiB, %lld MiB)",
1469 dbg_gen(
"BG commit bud bytes: %lld (%lld KiB, %lld MiB)",
1472 dbg_gen(
"current bud bytes %lld (%lld KiB, %lld MiB)",
1480 spin_lock(&ubifs_infos_lock);
1482 spin_unlock(&ubifs_infos_lock);
1517 static void ubifs_umount(
struct ubifs_info *c)
1519 dbg_gen(
"un-mounting UBI device %d, volume %d", c->
vi.ubi_num,
1523 spin_lock(&ubifs_infos_lock);
1525 spin_unlock(&ubifs_infos_lock);
1554 static int ubifs_remount_rw(
struct ubifs_info *c)
1559 ubifs_err(
"the file-system is not R/W-compatible");
1560 ubifs_msg(
"on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
1571 err = check_free_space(c);
1591 ubifs_msg(
"completing deferred recovery");
1635 if (IS_ERR(c->
bgt)) {
1636 err = PTR_ERR(c->
bgt);
1638 ubifs_err(
"cannot spawn \"%s\", error %d",
1667 dbg_gen(
"re-mounted read-write");
1672 ubifs_msg(
"deferred recovery completed");
1722 static void ubifs_remount_ro(
struct ubifs_info *c)
1738 ubifs_wbuf_sync(&c->
jheads[i].wbuf);
1761 static void ubifs_put_super(
struct super_block *sb)
1766 ubifs_msg(
"un-mount UBI device %d, volume %d", c->
vi.ubi_num,
1806 ubifs_wbuf_sync(&c->
jheads[i].wbuf);
1823 ubifs_err(
"failed to write master node, error %d",
1838 static int ubifs_remount_fs(
struct super_block *sb,
int *flags,
char *
data)
1845 err = ubifs_parse_options(c, data, 1);
1847 ubifs_err(
"invalid or unknown remount parameter");
1853 ubifs_msg(
"cannot re-mount R/W due to prior errors");
1857 ubifs_msg(
"cannot re-mount R/W - UBI volume is R/O");
1860 err = ubifs_remount_rw(c);
1863 }
else if (!c->
ro_mount && (*flags & MS_RDONLY)) {
1865 ubifs_msg(
"cannot re-mount R/O due to prior errors");
1868 ubifs_remount_ro(c);
1884 .alloc_inode = ubifs_alloc_inode,
1885 .destroy_inode = ubifs_destroy_inode,
1886 .put_super = ubifs_put_super,
1887 .write_inode = ubifs_write_inode,
1888 .evict_inode = ubifs_evict_inode,
1889 .statfs = ubifs_statfs,
1890 .dirty_inode = ubifs_dirty_inode,
1891 .remount_fs = ubifs_remount_fs,
1892 .show_options = ubifs_show_options,
1893 .sync_fs = ubifs_sync_fs,
1927 if (name[0] !=
'u' || name[1] !=
'b' || name[2] !=
'i')
1931 if ((name[3] ==
':' || name[3] ==
'!') && name[4] !=
'\0')
1940 if (*endptr ==
'\0')
1944 if (*endptr ==
'_' &&
isdigit(endptr[1])) {
1946 if (*endptr !=
'\0')
1952 if ((*endptr ==
':' || *endptr ==
'!') && endptr[1] !=
'\0')
1983 INIT_LIST_HEAD(&c->
idx_gc);
2005 static int ubifs_fill_super(
struct super_block *sb,
void *data,
int silent)
2014 if (IS_ERR(c->
ubi)) {
2015 err = PTR_ERR(c->
ubi);
2027 c->
bdi.name =
"ubifs",
2033 c->
vi.ubi_num, c->
vi.vol_id);
2037 err = ubifs_parse_options(c, data, 0);
2052 err = mount_ubifs(c);
2061 err = PTR_ERR(root);
2084 static int sb_test(
struct super_block *sb,
void *data)
2089 return c->
vi.cdev == c1->
vi.cdev;
2092 static int sb_set(
struct super_block *sb,
void *data)
2098 static struct dentry *ubifs_mount(
struct file_system_type *fs_type,
int flags,
2099 const char *name,
void *data)
2106 dbg_gen(
"name %s, flags %#x", name, flags);
2115 ubifs_err(
"cannot open \"%s\", error %d",
2116 name, (
int)PTR_ERR(ubi));
2117 return ERR_CAST(ubi);
2120 c = alloc_ubifs_info(ubi);
2126 dbg_gen(
"opened ubi%d_%d", c->
vi.ubi_num, c->
vi.vol_id);
2128 sb =
sget(fs_type, sb_test, sb_set, flags, c);
2139 dbg_gen(
"this ubi volume is already mounted");
2140 if (!!(flags & MS_RDONLY) != c1->
ro_mount) {
2145 err = ubifs_fill_super(sb, data, flags &
MS_SILENT ? 1 : 0);
2161 return ERR_PTR(err);
2164 static void kill_ubifs_super(
struct super_block *s)
2174 .mount = ubifs_mount,
2175 .kill_sb = kill_ubifs_super,
2181 static void inode_slab_ctor(
void *obj)
2187 static int __init ubifs_init(
void)
2243 ubifs_err(
"VFS page cache size is %u bytes, but UBIFS requires at least 4096 bytes",
2252 if (!ubifs_inode_slab)
2267 ubifs_err(
"cannot register file system, error %d", err);
2284 static void __exit ubifs_exit(
void)