core: New function: gf_dirent_for_namelen

Given the length of a name that needs to be stored in d_name, the
new function allocates enough space for a gf_dirent_t and
returns a ref.

Signed-off-by: Shehjar Tikoo <shehjart@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>

BUG: 597 (miscellaneous fixes for xlators to work well with NFS xlator)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=597
This commit is contained in:
Shehjar Tikoo 2010-02-25 15:37:48 +00:00 committed by Anand V. Avati
parent 9fe5c6d391
commit 508075b079
2 changed files with 20 additions and 0 deletions

View File

@ -49,6 +49,25 @@ gf_dirent_nb_size (gf_dirent_t *entries)
return (sizeof (struct gf_dirent_nb) + strlen (entries->d_name) + 1);
}
gf_dirent_t *
gf_dirent_for_namelen (int len)
{
gf_dirent_t *gf_dirent = NULL;
/* TODO: use mem-pool */
gf_dirent = CALLOC (len, sizeof(char));
if (!gf_dirent)
return NULL;
INIT_LIST_HEAD (&gf_dirent->list);
gf_dirent->d_off = 0;
gf_dirent->d_ino = -1;
gf_dirent->d_type = 0;
return gf_dirent;
}
gf_dirent_t *
gf_dirent_for_name (const char *name)

View File

@ -57,5 +57,6 @@ gf_dirent_t *gf_dirent_for_name (const char *name);
void gf_dirent_free (gf_dirent_t *entries);
int gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t size);
int gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t size);
gf_dirent_t * gf_dirent_for_namelen (int len);
#endif /* _GF_DIRENT_H */