Re: [PATCH] blkid: add support for adfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Oct 11, 2009 at 04:45:15PM +0100, Richard Fearn wrote:
> Add support for adfs to blkid.

 Thanks, but:

> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.

 We use LGPL (see shlibs/blkid/COPYING.libblkid) for the library.
 Please, use linux kernel as inspiration rather than a source for
 copy & past :-)

> +#include <string.h>
> +#include "superblocks.h"
> +#include "adfs.h"

 Please, don't use the adfs.h header file -- we usually use .c file
 for all FS code.

> +static int probe_adfs(blkid_probe pr, const struct blkid_idmag *mag)
> +{
> +        unsigned char *as;
> +        uint8_t *dr;

 It would be much better to use struct adfs_discrecord (ADFS
 superblock) rather than dr[magic constants].
 
 See kernel include/linux/adfs_fs.h. But please, use stdint.h types
 rather than __uN kernel types.

> +        long int disc_size;
> +        unsigned char disc_name[11];
> +
> +        /* read superblock */
> +        as = blkid_probe_get_buffer(pr, BOOT_BLOCK_OFFSET,  
> BOOT_BLOCK_SIZE);
> +        if (!as)
> +                return NOT_ADFS;
> +
> +        /* verify boot block checksum */
> +        if (adfs_checkbblk(as))
> +                return NOT_ADFS;
> +
> +        dr = as + DISC_RECORD_OFFSET;
> +
> +        /* check log2secsize */
> +        if (dr[0] != 8 && dr[0] != 9 && dr[0] != 10)
> +                return NOT_ADFS;
> +
> +        /* check disc size is non-zero */
> +        disc_size = dr[16] + (dr[17] << 8) + (dr[18] << 16) + (dr[19]  
> << 24);

    if (le32_to_cpu(dr->disc_size_high) >> dr->log2secsize)

> +        if (disc_size == 0)
> +                return NOT_ADFS;
> +
> +        /* set label, if disc has a name */
> +        if (dr[22]) {
> +                disc_name[10] = '\0';
> +                strncpy(disc_name, dr + 22, 10);
> +                *strchrnul(disc_name, '\r') = '\0';
> +                blkid_probe_set_label(pr, disc_name, strlen(disc_name));
> +        }

    blkid_probe_set_label(pr, dr->disk_name, sizeof(dr->disc_name));

 should be enough, it will append \0 and remove tailing whitespace
 from the label.

> +
> +        return IS_ADFS;
> +}
> +
> +const struct blkid_idinfo adfs_idinfo = {
> +        .name = "adfs",
> +        .usage = BLKID_USAGE_FILESYSTEM,
> +        .probefunc = probe_adfs,
> +        .flags = BLKID_IDINFO_TOLERANT

 the 'tolerant' flag means that the filesystem can co-exist on the
 device with any other filesystem. I have doubts that this is true for
 ADFS.

> +++ b/shlibs/blkid/src/superblocks/adfs.h
[...]
> +static inline int adfs_checkbblk(unsigned char *ptr)
> +{
> +    unsigned int result = 0;
> +    unsigned char *p = ptr + 511;
> +
> +    do {
> +            result = (result & 0xff) + (result >> 8);
> +            result = result + *--p;
> +    } while (p != ptr);
> +
> +    return (result & 0xff) != ptr[511];
> +}

 I think you can move this code into probe_adfs().

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux