Back to index

avfs  1.0.1
Functions
parsels.h File Reference
#include "avfs.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct lscacheav_new_lscache ()
int av_parse_ls (struct lscache *cache, const char *line, struct avstat *stbuf, char **filename, char **linkname)

Function Documentation

struct lscache* av_new_lscache ( ) [read]

Definition at line 49 of file parsels.c.

{
    struct lscache *cache;

    AV_NEW_OBJ(cache, free_lscache);

    cache->ugid = av_new_ugidcache();
    av_localtime(time(NULL), &cache->currtim);

    return cache;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int av_parse_ls ( struct lscache cache,
const char *  line,
struct avstat stbuf,
char **  filename,
char **  linkname 
)

Definition at line 411 of file parsels.c.

{
    struct columns colstruct;
    struct columns *col = &colstruct;
    int i;
    int saveidx, lnkidx;
    char *p_copy = NULL;
    const char *lineorig = line;

    *linkname = NULL;
    *filename = NULL;
    
    if (strncmp (line, "total", 5) == 0)
        return 0;

    if ((i = parse_filetype(*(line++))) == -1)
        goto error;
  
    stbuf->mode = i;
    if (*line == ' ')       /* Notwell 4 */
        line++;
    if (*line == '['){
        if (strlen (line) <= 8 || line [8] != ']')
            goto error;
        /* Should parse here the Notwell permissions :) */
        if (AV_ISDIR (stbuf->mode))
            stbuf->mode |= 755;
        else
            stbuf->mode |= 644;
        line += 9;
    } else {
        if ((i = parse_filemode(line)) == -1)
            goto error;
        stbuf->mode |= i;
        line += 9;
    
        /* This is for an extra ACL attribute (HP-UX) */
        if (*line == '+')
            line++;
    }

    p_copy = av_strdup(line);

    split_text (p_copy, col);

  
    stbuf->nlink = atol (INC_COL(col));
    if (stbuf->nlink <= 0)
        goto error;
  
    if (!is_num (col))
        stbuf->uid = av_finduid (cache->ugid, CURR_COL(col), -1);
    else
        stbuf->uid = (uid_t) atol (CURR_COL(col));
  
    /* Mhm, the ls -lg did not produce a group field */
    for (col->idx = 3; col->idx <= 5; col->idx++) 
        if (is_month(CURR_COL(col), NULL) || 
            is_week(CURR_COL(col)) || 
            is_dos_date(CURR_COL(col)) ||
            is_iso_date(CURR_COL(col)))
            break;

    saveidx = col->idx;
    col->idx = 2;

  
    if (saveidx == 6 || 
        (saveidx == 5 && !AV_ISCHR(stbuf->mode) && !AV_ISBLK(stbuf->mode)))
        goto error;

    if (!(saveidx == 3 || 
          (saveidx == 4 && (AV_ISCHR(stbuf->mode) || AV_ISBLK (stbuf->mode))))) {
        /* We have gid field */

        if (is_num (col))
            stbuf->gid = (gid_t) atol (INC_COL(col));
        else
            stbuf->gid = av_findgid (cache->ugid, INC_COL(col), -1);
    }
  
    /* This is device */
    if (AV_ISCHR (stbuf->mode) || AV_ISBLK (stbuf->mode)){
        int maj, min;
       
        if (!is_num (col) || sscanf(INC_COL(col), " %d,", &maj) != 1)
            goto error;
    
        if (!is_num (col) || sscanf(INC_COL(col), " %d", &min) != 1)
            goto error;
       
        stbuf->rdev = av_mkdev(maj, min);
        stbuf->size = 0;
    
    } else {
        /* Common file size */
        if (!is_num (col))
            goto error;
    
#ifdef HAVE_ATOLL
        stbuf->size = (avoff_t) atoll (INC_COL(col));
#else
        stbuf->size = (avoff_t) atol (INC_COL(col));
#endif
        stbuf->rdev = 0;
    }
  
    col->idx = saveidx;
  
    stbuf->mtime.nsec = 0;
    stbuf->mtime.sec = parse_filedate(col, &cache->currtim);
    if (stbuf->mtime.sec == -1)
        goto error;

    /* Use resulting time value */
    stbuf->atime = stbuf->ctime = stbuf->mtime;
    stbuf->dev = 0;
    stbuf->ino = 0;
    stbuf->blksize = 512;
    stbuf->blocks = AV_DIV(stbuf->size, 512);

    saveidx = col->idx;
    lnkidx = 0;

    for (col->idx ++; col->idx < col->num; col->idx++) 
        if (strcmp (CURR_COL(col), "->") == 0) {
            lnkidx = col->idx;
            break;
        }
  
    col->idx = saveidx;

    if (((AV_ISLNK (stbuf->mode) || 
          /* Maybe a hardlink? (in extfs) */
          (col->num == saveidx + 3 && stbuf->nlink > 1))) 
        && lnkidx){
        int p;
        int len;
        char *s;
  
        len = col->cptr[lnkidx] - col->cptr[col->idx] - 1;
        s = av_malloc(len + 1);
        strncpy(s, line + col->cptr[col->idx], len);
        s[len] = '\0';
        *filename = s;
    
        s = av_strdup (line + col->cptr[lnkidx + 1]);
        p = strlen (s);
        if (s [p-1] == '\r' || s [p-1] == '\n')
            s [p-1] = 0;
        if (s [p-2] == '\r' || s [p-2] == '\n')
            s [p-2] = 0;
    
        *linkname = s;

    } else {
        int p;
        char *s;
    
        s = av_strdup (line + col->cptr[col->idx]);
        p = strlen (s);
    
        if (p >= 1 && (s [p-1] == '\r' || s [p-1] == '\n'))
            s [p-1] = 0;
        if (p >= 2 && (s [p-2] == '\r' || s [p-2] == '\n'))
            s [p-2] = 0;
    
        *filename = s;
    }
    av_free (p_copy);
    return 1;
  
  error:
    av_free(p_copy);
    av_log(AVLOG_WARNING, "Could not parse %s", lineorig);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: