xref: /OK3568_Linux_fs/kernel/include/linux/adfs_fs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _ADFS_FS_H
3*4882a593Smuzhiyun #define _ADFS_FS_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <uapi/linux/adfs_fs.h>
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun /*
8*4882a593Smuzhiyun  * Calculate the boot block checksum on an ADFS drive.  Note that this will
9*4882a593Smuzhiyun  * appear to be correct if the sector contains all zeros, so also check that
10*4882a593Smuzhiyun  * the disk size is non-zero!!!
11*4882a593Smuzhiyun  */
adfs_checkbblk(unsigned char * ptr)12*4882a593Smuzhiyun static inline int adfs_checkbblk(unsigned char *ptr)
13*4882a593Smuzhiyun {
14*4882a593Smuzhiyun 	unsigned int result = 0;
15*4882a593Smuzhiyun 	unsigned char *p = ptr + 511;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun 	do {
18*4882a593Smuzhiyun 	        result = (result & 0xff) + (result >> 8);
19*4882a593Smuzhiyun         	result = result + *--p;
20*4882a593Smuzhiyun 	} while (p != ptr);
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun 	return (result & 0xff) != ptr[511];
23*4882a593Smuzhiyun }
24*4882a593Smuzhiyun #endif
25