1 /*
2  * gm_rfs.c -- gpart ReiserFS guessing module
3  *
4  * gpart (c) 1999-2001 Michail Brzitwa <mb@ichabod.han.de>
5  * Guess PC-type hard disk partitions.
6  *
7  * gpart is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published
9  * by the Free Software Foundation; either version 2, or (at your
10  * option) any later version.
11  *
12  * Created:   21.01.1999 <mb@ichabod.han.de>
13  * Modified:  26.12.2000 Francis Devereux <francis@devereux.tc>
14  *            Added reiserfs 3.5.28 support.
15  *
16  */
17 
18 #include <string.h>
19 #include <errno.h>
20 #include "gpart.h"
21 #include "gm_rfs.h"
22 
23 static const char	rcsid[] = "$Id: gm_rfs.c,v 1.5 2001/02/07 18:08:08 mb Exp mb $";
24 
25 
rfs_init(disk_desc * d,g_module * m)26 int rfs_init(disk_desc *d,g_module *m)
27 {
28 	if ((d == 0) || (m == 0))
29 		return (0);
30 
31 	m->m_desc = "Reiser filesystem";
32 	return (REISERFS_FIRST_BLOCK * 1024 + SB_SIZE);
33 }
34 
35 
36 
rfs_term(disk_desc * d)37 int rfs_term(disk_desc *d)
38 {
39 	return (1);
40 }
41 
42 
43 
rfs_gfun(disk_desc * d,g_module * m)44 int rfs_gfun(disk_desc *d,g_module *m)
45 {
46 	struct reiserfs_super_block	*sb;
47 	dos_part_entry			*pt = &m->m_part;
48 	s64_t				size;
49 
50 	m->m_guess = GM_NO;
51 	sb = (struct reiserfs_super_block *)(d->d_sbuf + REISERFS_FIRST_BLOCK * 1024);
52 	if (strncmp(sb->s_magic,REISERFS_SUPER_MAGIC,12) == 0)
53 	{
54 		/*
55 		 * sanity checks.
56 		 */
57 
58 		if (sb->s_block_count < sb->s_free_blocks)
59 			return (1);
60 
61 		if (sb->s_block_count < REISERFS_MIN_BLOCK_AMOUNT)
62 			return (1);
63 
64 		if ((sb->s_state != REISERFS_VALID_FS) &&
65 		    (sb->s_state != REISERFS_ERROR_FS))
66 			return (1);
67 
68 		if (sb->s_oid_maxsize % 2) /* must be even */
69 			return (1);
70 
71 		if (sb->s_oid_maxsize < sb->s_oid_cursize)
72 			return (1);
73 
74 		if ((sb->s_blocksize != 4096) && (sb->s_blocksize != 8192))
75 			return (1);
76 
77 		/*
78 		 * ok.
79 		 */
80 
81 		m->m_guess = GM_YES;
82 		pt->p_start = d->d_nsb;
83 		size = sb->s_block_count; size *= sb->s_blocksize; size /= d->d_ssize;
84 		pt->p_size = (unsigned long)size;
85 		pt->p_typ = 0x83;
86 	}
87 	return (1);
88 }
89