示例#1
17
// we can only get md5 of an object containing 1 range
// XXX: move code to separate thread
gboolean cache_mng_get_md5 (CacheMng *cmng, fuse_ino_t ino, gchar **md5str)
{
    struct _CacheEntry *entry;
    unsigned char digest[MD5_DIGEST_LENGTH];
    MD5_CTX md5ctx;
    ssize_t bytes;
    unsigned char data[1024];
    char path[PATH_MAX];
    size_t i;
    gchar *out;
    FILE *in;

    entry = g_hash_table_lookup (cmng->h_entries, GUINT_TO_POINTER (ino));
    if (!entry)
        return FALSE;
    
    if (range_count (entry->avail_range) != 1) {
        LOG_debug (CMNG_LOG, INO_H"Entry contains more than 1 range, can't take MD5 sum of such object !", INO_T (ino));
        return FALSE;
    }

    cache_mng_file_name (cmng, path, sizeof (path), ino);
    in = fopen (path, "rb");
    if (in == NULL) {
        LOG_debug (CMNG_LOG, INO_H"Can't open file for reading: %s", INO_T (ino), path);
        return FALSE;
    }

    MD5_Init (&md5ctx);
    while ((bytes = fread (data, 1, 1024, in)) != 0)
        MD5_Update (&md5ctx, data, bytes);
    MD5_Final (digest, &md5ctx);
    fclose (in);

    out = g_malloc (33);
    for (i = 0; i < 16; ++i)
        sprintf (&out[i*2], "%02x", (unsigned int)digest[i]);

    *md5str = out;

    return TRUE;
}
示例#2
0
unsigned long
cml_node_get_range_count(const cml_node *mn)
{
    return (mn->range == 0 ? 0 : range_count(mn->range));
}