14 #include <linux/module.h>
15 #include <linux/slab.h>
17 #include <linux/time.h>
18 #include <asm/uaccess.h>
41 return !
strncmp(rs->
s_v1.s_magic, reiserfs_3_5_magic_string,
42 strlen(reiserfs_3_5_magic_string));
47 return !
strncmp(rs->
s_v1.s_magic, reiserfs_3_6_magic_string,
48 strlen(reiserfs_3_6_magic_string));
53 return !
strncmp(rs->
s_v1.s_magic, reiserfs_jr_magic_string,
54 strlen(reiserfs_jr_magic_string));
96 reiserfs_sync_fs(s, 1);
116 static void cancel_old_flush(
struct super_block *s)
149 static int reiserfs_unfreeze(
struct super_block *s)
164 static int remove_save_link_only(
struct super_block *s,
184 static int reiserfs_quota_on_mount(
struct super_block *,
int);
188 static int finish_unfinished(
struct super_block *s)
195 struct buffer_head *bh;
209 max_cpu_key.on_disk_key.k_dir_id = ~0
U;
210 max_cpu_key.on_disk_key.k_objectid = ~0
U;
211 set_cpu_key_k_offset(&max_cpu_key, ~0
U);
212 max_cpu_key.key_length = 3;
214 memset(&last_inode_key, 0,
sizeof(last_inode_key));
226 quota_enabled[
i] = 1;
227 if (REISERFS_SB(s)->s_qf_names[i]) {
230 if (sb_has_quota_active(s, i)) {
231 quota_enabled[
i] = 0;
234 ret = reiserfs_quota_on_mount(s, i);
237 "cannot turn on journaled "
238 "quota: error %d", ret);
244 REISERFS_SB(s)->s_is_unlinked_ok = 1;
249 "search_by_key returned %d", retval);
257 "wrong position found");
267 save_link_key = ih->
ih_key;
268 if (is_indirect_le_ih(ih))
276 obj_key.on_disk_key.k_objectid =
278 obj_key.on_disk_key.k_offset = 0;
279 obj_key.on_disk_key.k_type = 0;
289 retval = remove_save_link_only(s, &save_link_key, 1);
293 if (!truncate && inode->
i_nlink) {
296 "file %K is not unlinked",
298 retval = remove_save_link_only(s, &save_link_key, 0);
311 "impossible truncate on a "
312 "directory %k. Please report",
314 retval = remove_save_link_only(s, &save_link_key, 0);
321 REISERFS_I(inode)->i_flags |=
337 sizeof(last_inode_key))){
343 "in finish_unfinished "
344 "detected, just remove "
346 retval = remove_save_link_only(s,
355 REISERFS_SB(s)->s_is_unlinked_ok = 0;
360 if (sb_dqopt(s)->
files[i] && quota_enabled[i])
369 reiserfs_info(s,
"There were %d uncompleted unlinks/truncates. "
370 "Completed\n", done);
379 struct inode *inode,
int truncate)
392 "saved link already exists for truncated inode %lx",
396 "saved link already exists for unlinked inode %lx",
405 set_cpu_key_k_offset(&key, 1 + inode->
i_sb->s_blocksize);
416 "Adding a truncate savelink for "
417 "a directory %k! Please report",
419 set_cpu_key_k_offset(&key, 1);
433 "search_by_key (%K) returned %d", &key,
448 "insert_item returned %d", retval);
451 REISERFS_I(inode)->i_flags |=
476 1 + inode->
i_sb->s_blocksize);
492 REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
494 REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
499 static void reiserfs_kill_sb(
struct super_block *s)
501 if (REISERFS_SB(s)) {
512 dput(REISERFS_SB(s)->xattr_root);
513 REISERFS_SB(s)->xattr_root =
NULL;
514 dput(REISERFS_SB(s)->priv_root);
515 REISERFS_SB(s)->priv_root =
NULL;
521 static void reiserfs_put_super(
struct super_block *s)
536 REISERFS_SB(s)->s_mount_state);
552 if (REISERFS_SB(s)->reserved_blocks != 0) {
554 REISERFS_SB(s)->reserved_blocks);
565 static struct kmem_cache *reiserfs_inode_cachep;
567 static struct inode *reiserfs_alloc_inode(
struct super_block *
sb)
585 static void reiserfs_destroy_inode(
struct inode *inode)
590 static void init_once(
void *
foo)
598 static int init_inodecache(
void)
606 if (reiserfs_inode_cachep ==
NULL)
611 static void destroy_inodecache(
void)
622 static void reiserfs_dirty_inode(
struct inode *inode,
int flags)
631 "writing inode %lu on readonly FS",
644 reiserfs_update_sd(&
th, inode);
651 static int reiserfs_show_options(
struct seq_file *seq,
struct dentry *root)
655 long opts = REISERFS_SB(s)->s_mount_opt;
691 if (REISERFS_SB(s)->s_jdev)
692 seq_printf(seq,
",jdev=%s", REISERFS_SB(s)->s_jdev);
698 if (REISERFS_SB(s)->s_qf_names[
USRQUOTA])
699 seq_printf(seq,
",usrjquota=%s", REISERFS_SB(s)->s_qf_names[USRQUOTA]);
702 if (REISERFS_SB(s)->s_qf_names[
GRPQUOTA])
703 seq_printf(seq,
",grpjquota=%s", REISERFS_SB(s)->s_qf_names[GRPQUOTA]);
706 if (REISERFS_SB(s)->s_jquota_fmt) {
709 else if (REISERFS_SB(s)->s_jquota_fmt ==
QFMT_VFS_V0)
716 seq_puts(seq,
",block-allocator=noborder");
718 seq_puts(seq,
",block-allocator=no_unhashed_relocation");
720 seq_puts(seq,
",block-allocator=hashed_relocation");
722 seq_puts(seq,
",block-allocator=test4");
735 .alloc_inode = reiserfs_alloc_inode,
736 .destroy_inode = reiserfs_destroy_inode,
738 .dirty_inode = reiserfs_dirty_inode,
740 .put_super = reiserfs_put_super,
741 .sync_fs = reiserfs_sync_fs,
742 .freeze_fs = reiserfs_freeze,
743 .unfreeze_fs = reiserfs_unfreeze,
744 .statfs = reiserfs_statfs,
745 .remount_fs = reiserfs_remount,
746 .show_options = reiserfs_show_options,
748 .quota_read = reiserfs_quota_read,
749 .quota_write = reiserfs_quota_write,
754 #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
756 static int reiserfs_write_dquot(
struct dquot *);
757 static int reiserfs_acquire_dquot(
struct dquot *);
758 static int reiserfs_release_dquot(
struct dquot *);
759 static int reiserfs_mark_dquot_dirty(
struct dquot *);
760 static int reiserfs_write_info(
struct super_block *,
int);
761 static int reiserfs_quota_on(
struct super_block *,
int,
int,
struct path *);
765 .acquire_dquot = reiserfs_acquire_dquot,
766 .release_dquot = reiserfs_release_dquot,
767 .mark_dirty = reiserfs_mark_dquot_dirty,
768 .write_info = reiserfs_write_info,
773 static const struct quotactl_ops reiserfs_qctl_operations = {
803 #define REISERFS_OPT_ALLOWEMPTY 31
860 #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
874 char **opt_arg,
unsigned long *bit_flags)
895 if (!
strncmp(p,
"alloc=", 6)) {
913 "%s not supported.\n",
920 "%s not supported.\n",
930 "unknown mount option \"%s\"", p);
939 "the option \"%s\" does not "
940 "require an argument\n",
949 "the option \"%s\" requires an "
956 "head of option \"%s\" is only correct\n",
969 "empty argument for \"%s\"\n",
992 "bad value \"%s\" for option \"%s\"\n", p,
1003 unsigned long *blocks,
1005 unsigned int *commit_max_age,
1021 #ifdef CONFIG_REISERFS_FS_XATTR
1028 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
1035 {.option_name =
"nolog"},
1037 {
"block-allocator",.arg_required =
'a',.values = balloc},
1038 {
"data",.arg_required =
'd',.values = logging_mode},
1039 {
"barrier",.arg_required =
'b',.values = barrier_mode},
1040 {
"resize",.arg_required =
'r',.values =
NULL},
1041 {
"jdev",.arg_required =
'j',.values =
NULL},
1042 {
"nolargeio",.arg_required =
'w',.values =
NULL},
1043 {
"commit",.arg_required =
'c',.values =
NULL},
1047 {
"errors",.arg_required =
'e',.values = error_actions},
1048 {
"usrjquota",.arg_required =
1050 {
"grpjquota",.arg_required =
1052 {
"jqfmt",.arg_required =
'f',.values =
NULL},
1053 {.option_name =
NULL}
1057 if (!options || !*options)
1062 for (pos = options;
pos;) {
1063 c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
1074 if (!
strcmp(arg,
"auto")) {
1077 s->
s_bdev->bd_inode->i_size >> s->
1095 if (*p !=
'\0' || val >= (
unsigned int)-1) {
1097 "bad value %s for -ocommit\n",
1101 *commit_max_age = (
unsigned int)val;
1106 "is no longer supported");
1111 if (arg && *arg && jdev_name) {
1114 "journal device was "
1115 "already specified to "
1116 "be %s", *jdev_name);
1123 if (c ==
'u' || c ==
'g') {
1124 int qtype = c ==
'u' ? USRQUOTA :
GRPQUOTA;
1126 if (sb_any_quota_loaded(s) &&
1127 (!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) {
1129 "cannot change journaled "
1130 "quota options when quota "
1135 if (REISERFS_SB(s)->s_qf_names[qtype]
1136 &&
strcmp(REISERFS_SB(s)->s_qf_names[qtype],
1140 "already specified.",
1146 "quotafile must be "
1147 "on filesystem root.");
1152 if (!qf_names[qtype]) {
1154 "not enough memory "
1159 strcpy(qf_names[qtype], arg);
1160 if (qtype == USRQUOTA)
1165 if (qf_names[qtype] !=
1166 REISERFS_SB(s)->s_qf_names[qtype])
1167 kfree(qf_names[qtype]);
1168 qf_names[qtype] =
NULL;
1169 if (qtype == USRQUOTA)
1176 if (!
strcmp(arg,
"vfsold"))
1178 else if (!
strcmp(arg,
"vfsv0"))
1182 "unknown quota format "
1186 if (sb_any_quota_loaded(s) &&
1187 *qfmt != REISERFS_SB(s)->s_jquota_fmt) {
1189 "cannot change journaled "
1190 "quota options when quota "
1196 if (c ==
'u' || c ==
'g' || c ==
'f') {
1198 "quota options not supported.");
1205 if (!REISERFS_SB(s)->s_jquota_fmt && !*qfmt
1206 && (qf_names[USRQUOTA] || qf_names[GRPQUOTA])) {
1208 "journaled quota format not specified.");
1212 sb_has_quota_loaded(s, USRQUOTA)) ||
1214 sb_has_quota_loaded(s, GRPQUOTA))) {
1216 "be present when quota is turned on.");
1224 static void switch_data_mode(
struct super_block *s,
unsigned long mode)
1229 REISERFS_SB(s)->s_mount_opt |= (1 <<
mode);
1232 static void handle_data_mode(
struct super_block *s,
unsigned long mount_options)
1252 static void handle_barrier_mode(
struct super_block *s,
unsigned long bits)
1256 int all_barrier = flush |
none;
1258 if (bits & all_barrier) {
1259 REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
1261 REISERFS_SB(s)->s_mount_opt |= flush;
1262 printk(
"reiserfs: enabling write barrier flush mode\n");
1263 }
else if (bits & none) {
1264 REISERFS_SB(s)->s_mount_opt |=
none;
1265 printk(
"reiserfs: write barriers turned off\n");
1277 "attributes on 3.5.x disk format");
1283 "attributes until flag is set in "
1291 static void handle_quota_files(
struct super_block *s,
char **qf_names,
1297 if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
1298 kfree(REISERFS_SB(s)->s_qf_names[i]);
1299 REISERFS_SB(s)->s_qf_names[
i] = qf_names[
i];
1302 REISERFS_SB(s)->s_jquota_fmt = *
qfmt;
1306 static int reiserfs_remount(
struct super_block *s,
int *mount_flags,
char *arg)
1310 unsigned long blocks;
1311 unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
1312 unsigned long safe_mask = 0;
1313 unsigned int commit_max_age = (
unsigned int)-1;
1318 unsigned int qfmt = 0;
1326 memcpy(qf_names, REISERFS_SB(s)->s_qf_names,
sizeof(qf_names));
1331 if (!reiserfs_parse_options
1332 (s, arg, &mount_options, &blocks,
NULL, &commit_max_age,
1336 if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
1343 handle_quota_files(s, qf_names, &qfmt);
1368 REISERFS_SB(s)->s_mount_opt =
1370 s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
1372 if (commit_max_age != 0 && commit_max_age != (
unsigned int)-1) {
1375 }
else if (commit_max_age == 0) {
1399 err = dquot_suspend(s, -1);
1420 if (!(s->
s_flags & MS_RDONLY)) {
1430 handle_data_mode(s, mount_options);
1431 handle_barrier_mode(s, mount_options);
1455 if (!(*mount_flags & MS_RDONLY)) {
1463 finish_unfinished(s);
1481 struct buffer_head *bh;
1488 "bread failed (dev %s, block %lu, size %lu)",
1495 if (!is_any_reiserfs_magic_string(rs)) {
1509 "bread failed (dev %s, block %lu, size %lu)",
1518 "filesystem on (dev %s, block %Lu, size %lu)",
1519 reiserfs_bdevname(s),
1520 (
unsigned long long)bh->b_blocknr,
1529 "--rebuild-tree run detected. Please run\n"
1530 "reiserfsck --rebuild-tree and wait for a "
1531 "completion. If that fails\n"
1532 "get newer reiserfsprogs package");
1544 " with non-standard journal\n");
1547 " with non-standard journal\n");
1550 "format \"%u\" of reiserfs with "
1558 "found reiserfs format \"%s\" with standard journal\n",
1561 s->
s_op = &reiserfs_sops;
1564 s->
s_qcop = &reiserfs_qctl_operations;
1565 s->
dq_op = &reiserfs_quota_operations;
1576 static int reread_meta_blocks(
struct super_block *s)
1599 struct inode *
inode;
1605 inode = s->
s_root->d_inode;
1608 u32 teahash, r5hash, yurahash;
1625 "is using the default hash\n");
1631 if (((teahash == r5hash)
1634 == r5hash)) || ((teahash == yurahash)
1641 || ((r5hash == yurahash)
1646 "automatically detect hash function. "
1647 "Please mount with -o "
1648 "hash={tea,rupasov,r5}");
1663 "Unrecognised hash function");
1684 code = find_hash_out(s);
1692 "Error, %s hash detected, "
1693 "unable to force rupasov hash",
1698 "Error, %s hash detected, "
1699 "unable to force tea hash",
1704 "Error, %s hash detected, "
1705 "unable to force r5 hash",
1734 switch (what_hash(s)) {
1763 #define SWARN(silent, s, id, ...) \
1765 reiserfs_warning(s, id, __VA_ARGS__)
1767 static int reiserfs_fill_super(
struct super_block *s,
void *
data,
int silent)
1769 struct inode *root_inode;
1772 unsigned long blocks;
1773 unsigned int commit_max_age = 0;
1781 unsigned int qfmt = 0;
1807 if (reiserfs_parse_options
1808 (s, (
char *)data, &(sbi->
s_mount_opt), &blocks, &jdev_name,
1809 &commit_max_age, qf_names, &qfmt) == 0) {
1810 goto error_unlocked;
1812 if (jdev_name && jdev_name[0]) {
1815 SWARN(silent, s,
"",
"Cannot allocate memory for "
1816 "journal device name");
1821 handle_quota_files(s, qf_names, &qfmt);
1825 SWARN(silent, s,
"jmacd-7",
"resize option for remount only");
1826 goto error_unlocked;
1834 SWARN(silent, s,
"sh-2021",
"can not find reiserfs on %s",
1835 reiserfs_bdevname(s));
1836 goto error_unlocked;
1844 && i_size_read(s->
s_bdev->bd_inode) <
1846 SWARN(silent, s,
"",
"Filesystem cannot be "
1847 "mounted because it is bigger than the device");
1848 SWARN(silent, s,
"",
"You may need to run fsck "
1849 "or increase size of your LVM partition");
1850 SWARN(silent, s,
"",
"Or may be you forgot to "
1851 "reboot after fdisk when it told you to");
1852 goto error_unlocked;
1859 SWARN(silent, s,
"jmacd-8",
"unable to read bitmap");
1860 goto error_unlocked;
1864 #ifdef CONFIG_REISERFS_CHECK
1865 SWARN(silent, s,
"",
"CONFIG_REISERFS_CHECK is set ON");
1866 SWARN(silent, s,
"",
"- it is slow mode for debugging.");
1883 printk(
"reiserfs: using flush barriers\n");
1887 if (
journal_init(s, jdev_name, old_format, commit_max_age)) {
1888 SWARN(silent, s,
"sh-2022",
1889 "unable to initialize journal space");
1890 goto error_unlocked;
1897 if (reread_meta_blocks(s)) {
1898 SWARN(silent, s,
"jmacd-9",
1899 "unable to reread meta blocks after journal init");
1900 goto error_unlocked;
1904 goto error_unlocked;
1907 SWARN(silent, s,
"clm-7000",
1908 "Detected readonly device, marking FS readonly");
1917 SWARN(silent, s,
"jmacd-10",
"get root inode failed");
1918 goto error_unlocked;
1950 else if (old_format)
1972 if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
1975 "claims to use %u bitmap blocks in "
1976 "its super block, but requires %u. "
1978 reiserfs_bmap_count(s));
1990 "converting 3.5 filesystem to the 3.6 format");
1996 reiserfs_3_6_magic_string,
1998 (reiserfs_3_6_magic_string));
2004 }
else if (!silent) {
2027 finish_unfinished(s);
2102 static int reiserfs_write_dquot(
struct dquot *
dquot)
2126 static int reiserfs_acquire_dquot(
struct dquot *dquot)
2150 static int reiserfs_release_dquot(
struct dquot *dquot)
2177 static int reiserfs_mark_dquot_dirty(
struct dquot *dquot)
2180 if (REISERFS_SB(dquot->
dq_sb)->s_qf_names[USRQUOTA] ||
2181 REISERFS_SB(dquot->
dq_sb)->s_qf_names[GRPQUOTA]) {
2183 return reiserfs_write_dquot(dquot);
2212 static int reiserfs_quota_on_mount(
struct super_block *sb,
int type)
2215 REISERFS_SB(sb)->s_jquota_fmt, type);
2225 struct inode *
inode;
2230 if (!(REISERFS_SB(sb)->s_mount_opt & (1 << opt))) {
2236 if (path->
dentry->d_sb != sb) {
2240 inode = path->
dentry->d_inode;
2246 "Unpacking tail of quota file failed"
2247 " (%d). Cannot turn on quotas.", err);
2251 mark_inode_dirty(inode);
2254 if (REISERFS_SB(sb)->s_qf_names[type]) {
2258 "Quota file not on filesystem root. "
2259 "Journalled quota will not work.");
2266 if (reiserfs_file_data_log(inode)) {
2287 size_t len, loff_t off)
2289 struct inode *inode = sb_dqopt(sb)->files[
type];
2291 int err = 0, offset = off & (sb->
s_blocksize - 1), tocopy;
2293 struct buffer_head tmp_bh, *bh;
2294 loff_t i_size = i_size_read(inode);
2298 if (off + len > i_size)
2301 while (toread > 0) {
2312 if (!buffer_mapped(&tmp_bh))
2315 bh = sb_bread(sb, tmp_bh.b_blocknr);
2318 memcpy(data, bh->b_data + offset, tocopy);
2332 const char *data,
size_t len, loff_t off)
2334 struct inode *inode = sb_dqopt(sb)->files[
type];
2336 int err = 0, offset = off & (sb->
s_blocksize - 1), tocopy;
2337 int journal_quota = REISERFS_SB(sb)->s_qf_names[
type] !=
NULL;
2338 size_t towrite = len;
2339 struct buffer_head tmp_bh, *bh;
2343 " cancelled because transaction is not started.\n",
2344 (
unsigned long long)off, (
unsigned long long)len);
2347 while (towrite > 0) {
2357 bh = sb_bread(sb, tmp_bh.b_blocknr);
2359 bh = sb_getblk(sb, tmp_bh.b_blocknr);
2365 memcpy(bh->b_data + offset, data, tocopy);
2367 set_buffer_uptodate(bh);
2384 if (inode->
i_size < off + len - towrite)
2385 i_size_write(inode, off + len - towrite);
2388 mark_inode_dirty(inode);
2389 return len - towrite;
2395 int flags,
const char *dev_name,
2398 return mount_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super);
2401 static int __init init_reiserfs_fs(
void)
2405 if ((ret = init_inodecache())) {
2418 destroy_inodecache();
2423 static void __exit exit_reiserfs_fs(
void)
2427 destroy_inodecache();
2433 .mount = get_super_block,
2434 .kill_sb = reiserfs_kill_sb,