1 /* fsdef.c: filesystem index definition
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/module.h>
13 #include "fscache-int.h"
15 static uint16_t fscache_fsdef_netfs_get_key(const void *cookie_netfs_data,
16 void *buffer, uint16_t bufmax);
18 static uint16_t fscache_fsdef_netfs_get_aux(const void *cookie_netfs_data,
19 void *buffer, uint16_t bufmax);
21 static fscache_checkaux_t fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
25 struct fscache_cookie_def fscache_fsdef_netfs_def = {
26 .name = "FSDEF.netfs",
27 .type = FSCACHE_COOKIE_TYPE_INDEX,
28 .get_key = fscache_fsdef_netfs_get_key,
29 .get_aux = fscache_fsdef_netfs_get_aux,
30 .check_aux = fscache_fsdef_netfs_check_aux,
33 struct fscache_cookie fscache_fsdef_index = {
34 .usage = ATOMIC_INIT(1),
36 .sem = __RWSEM_INITIALIZER(fscache_fsdef_index.sem),
37 .backing_objects = HLIST_HEAD_INIT,
40 EXPORT_SYMBOL(fscache_fsdef_index);
42 /*****************************************************************************/
44 * get the key data for an FSDEF index record
46 static uint16_t fscache_fsdef_netfs_get_key(const void *cookie_netfs_data,
47 void *buffer, uint16_t bufmax)
49 const struct fscache_netfs *netfs = cookie_netfs_data;
52 _enter("{%s.%u},", netfs->name, netfs->version);
54 klen = strlen(netfs->name);
58 memcpy(buffer, netfs->name, klen);
62 /*****************************************************************************/
64 * get the auxilliary data for an FSDEF index record
66 static uint16_t fscache_fsdef_netfs_get_aux(const void *cookie_netfs_data,
67 void *buffer, uint16_t bufmax)
69 const struct fscache_netfs *netfs = cookie_netfs_data;
72 _enter("{%s.%u},", netfs->name, netfs->version);
74 dlen = sizeof(uint32_t);
78 memcpy(buffer, &netfs->version, dlen);
82 /*****************************************************************************/
84 * check that the version stored in the auxilliary data is correct
86 static fscache_checkaux_t fscache_fsdef_netfs_check_aux(void *cookie_netfs_data,
90 struct fscache_netfs *netfs = cookie_netfs_data;
93 _enter("{%s},,%hu", netfs->name, datalen);
95 if (datalen != sizeof(version)) {
96 _leave(" = OBSOLETE [dl=%d v=%d]",
97 datalen, sizeof(version));
98 return FSCACHE_CHECKAUX_OBSOLETE;
101 memcpy(&version, data, sizeof(version));
102 if (version != netfs->version) {
103 _leave(" = OBSOLETE [ver=%x net=%x]",
104 version, netfs->version);
105 return FSCACHE_CHECKAUX_OBSOLETE;
109 return FSCACHE_CHECKAUX_OKAY;