lib/vfs/direntry.c: vfs_s_inode_from_path() and vfs_s_get_path() now handle vfs_path_t

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-04-26 16:29:34 +03:00
parent 9a28ce8c8d
commit 9e4dc03e9e
2 changed files with 26 additions and 24 deletions

View File

@ -398,12 +398,15 @@ vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
*/ */
static char * static char *
vfs_s_get_path (struct vfs_class *me, const char *inname, struct vfs_s_super **archive, int flags) vfs_s_get_path (const vfs_path_t *vpath, struct vfs_s_super **archive, int flags)
{ {
char *buf, *retval; char *buf, *retval;
vfs_path_element_t *path_element;
buf = g_strdup (inname); path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
retval = g_strdup (vfs_s_get_path_mangle (me, buf, archive, flags));
buf = g_strdup (vpath->unparsed);
retval = g_strdup (vfs_s_get_path_mangle (path_element->class, buf, archive, flags));
g_free (buf); g_free (buf);
return retval; return retval;
} }
@ -413,22 +416,25 @@ vfs_s_get_path (struct vfs_class *me, const char *inname, struct vfs_s_super **a
/* ------------------------ readdir & friends ----------------------------- */ /* ------------------------ readdir & friends ----------------------------- */
static struct vfs_s_inode * static struct vfs_s_inode *
vfs_s_inode_from_path (struct vfs_class *me, const char *name, int flags) vfs_s_inode_from_path (const vfs_path_t *vpath, int flags)
{ {
struct vfs_s_super *super; struct vfs_s_super *super;
struct vfs_s_inode *ino; struct vfs_s_inode *ino;
char *q; char *q;
vfs_path_element_t *path_element;
if (!(q = vfs_s_get_path (me, name, &super, 0))) if (!(q = vfs_s_get_path (vpath, &super, 0)))
return NULL; return NULL;
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
ino = ino =
vfs_s_find_inode (me, super, q, vfs_s_find_inode (path_element->class, super, q,
flags & FL_FOLLOW ? LINK_FOLLOW : LINK_NO_FOLLOW, flags & ~FL_FOLLOW); flags & FL_FOLLOW ? LINK_FOLLOW : LINK_NO_FOLLOW, flags & ~FL_FOLLOW);
if ((!ino) && (!*q)) if ((!ino) && (!*q))
/* We are asking about / directory of ftp server: assume it exists */ /* We are asking about / directory of ftp server: assume it exists */
ino = ino =
vfs_s_find_inode (me, super, q, vfs_s_find_inode (path_element->class, super, q,
flags & FL_FOLLOW ? LINK_FOLLOW : flags & FL_FOLLOW ? LINK_FOLLOW :
LINK_NO_FOLLOW, FL_DIR | (flags & ~FL_FOLLOW)); LINK_NO_FOLLOW, FL_DIR | (flags & ~FL_FOLLOW));
g_free (q); g_free (q);
@ -445,7 +451,8 @@ vfs_s_opendir (const vfs_path_t * vpath)
vfs_path_element_t *path_element; vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1); path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
dir = vfs_s_inode_from_path (path_element->class, vpath->unparsed, FL_DIR | FL_FOLLOW);
dir = vfs_s_inode_from_path (vpath, FL_DIR | FL_FOLLOW);
if (dir == NULL) if (dir == NULL)
return NULL; return NULL;
if (!S_ISDIR (dir->st.st_mode)) if (!S_ISDIR (dir->st.st_mode))
@ -527,10 +534,8 @@ static int
vfs_s_internal_stat (const vfs_path_t * vpath, struct stat *buf, int flag) vfs_s_internal_stat (const vfs_path_t * vpath, struct stat *buf, int flag)
{ {
struct vfs_s_inode *ino; struct vfs_s_inode *ino;
vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1); ino = vfs_s_inode_from_path (vpath, flag);
ino = vfs_s_inode_from_path (path_element->class, vpath->unparsed, flag);
if (ino == NULL) if (ino == NULL)
return -1; return -1;
*buf = ino->st; *buf = ino->st;
@ -573,7 +578,7 @@ vfs_s_readlink (const vfs_path_t * vpath, char *buf, size_t size)
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1); path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
ino = vfs_s_inode_from_path (path_element->class, vpath->unparsed, 0); ino = vfs_s_inode_from_path (vpath, 0);
if (!ino) if (!ino)
return -1; return -1;
@ -828,7 +833,7 @@ vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
case VFS_SETCTL_STALE_DATA: case VFS_SETCTL_STALE_DATA:
{ {
struct vfs_s_inode *ino = struct vfs_s_inode *ino =
vfs_s_inode_from_path (path_element->class, vpath->unparsed, 0); vfs_s_inode_from_path (vpath, 0);
if (ino == NULL) if (ino == NULL)
return 0; return 0;
@ -859,11 +864,8 @@ vfs_s_getid (const vfs_path_t * vpath)
{ {
struct vfs_s_super *archive = NULL; struct vfs_s_super *archive = NULL;
char *p; char *p;
vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1); p = vfs_s_get_path (vpath, &archive, FL_NO_OPEN);
p = vfs_s_get_path (path_element->class, vpath->unparsed, &archive, FL_NO_OPEN);
if (p == NULL) if (p == NULL)
return NULL; return NULL;
g_free (p); g_free (p);
@ -1174,7 +1176,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1); path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
q = vfs_s_get_path (path_element->class, vpath->unparsed, &super, 0); q = vfs_s_get_path (vpath, &super, 0);
if (q == NULL) if (q == NULL)
return NULL; return NULL;
ino = vfs_s_find_inode (path_element->class, super, q, LINK_FOLLOW, FL_NONE); ino = vfs_s_find_inode (path_element->class, super, q, LINK_FOLLOW, FL_NONE);

View File

@ -105,18 +105,18 @@ vfs_path_from_str (const char *path_str)
vfs_path_t * vfs_path_t *
vfs_path_new (void) vfs_path_new (void)
{ {
vfs_path_t *path; vfs_path_t *vpath;
path = g_new0 (vfs_path_t, 1); vpath = g_new0 (vfs_path_t, 1);
path->path = g_ptr_array_new (); vpath->path = g_ptr_array_new ();
return path; return vpath;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
size_t size_t
vfs_path_length (const vfs_path_t * path) vfs_path_length (const vfs_path_t * vpath)
{ {
return path->path->len; return vpath->path->len;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */