Beispiel #1
0
    int statfs(

/*  SYNOPSIS */
    const char *path,
    struct statfs *buf)

/*  FUNCTION
        Gets information about mounted filesystem.

    INPUTS
        path - path to any file in the filesystem we want to know about
        buf - pointer to statfs structures where information about filesystem
            will be stored

    RESULT
        Information about filesystem is stored in statfs structure

    NOTES

    EXAMPLE

    BUGS
        f_flags, f_files, f_ffree and f_fsid.val are always set to 0
        f_mntfromname is set to an empty string

    SEE ALSO
    	
    INTERNALS

******************************************************************************/
{
    BPTR lock;
    LONG ioerr = 0;
    struct InfoData data;
    char *apath;
    
    if (path == NULL)
    {
	errno = EINVAL;
        return -1;
    }

    apath = __path_u2a(path);
    if (!apath) 
    {
	errno = EINVAL;
	return -1;
    }
    
    /* Get filesystem data from lock */
    if(((lock = Lock(apath, SHARED_LOCK))))
    {
	if(Info(lock, &data))
	{
	    /* Fill statfs structure */
	    buf->f_type = getnixfilesystemtype(data.id_DiskType);
	    buf->f_flags = 0;
	    buf->f_fsize = data.id_BytesPerBlock;
	    buf->f_bsize = data.id_BytesPerBlock;
	    buf->f_blocks = data.id_NumBlocks;
	    buf->f_bfree = data.id_NumBlocks - data.id_NumBlocksUsed;
	    buf->f_bavail = data.id_NumBlocks - data.id_NumBlocksUsed;
	    buf->f_files = 0;
	    buf->f_ffree = 0;
	    buf->f_fsid.val[0] = 0;
	    buf->f_fsid.val[1] = 0;
	    strncpy(buf->f_mntonname, __path_a2u(((struct DeviceList *)BADDR(data.id_VolumeNode))->dl_Name), MNAMELEN);
	    buf->f_mntfromname[0] = '\0';
	}
	else
	{
	    ioerr = IoErr();
	}
        UnLock(lock);
    }
    else
    {
	ioerr = IoErr();
    }
	
    if(ioerr != 0) {
	errno = IoErr2errno(ioerr);
	return -1;
    }

    return 0;
}
Beispiel #2
0
	char *dirname(

/*  SYNOPSIS */
	char *filename)

/*  FUNCTION
	Returns the string up to the latest '/'.
	
    INPUTS
	filename - Path which should be split

    RESULT
	Directory part of the path.
	
    NOTES

    EXAMPLE

    BUGS

    SEE ALSO
	basename()

    INTERNALS

******************************************************************************/
{
    char *uname;
    char *pos;

    if (!filename || *filename == '\0')
    {
	D(bug("dirname()=.\n")); 
        return ".";
    }

    uname = (char *)__path_a2u(filename);

    pos = uname;

    if (pos[0] == '/' && pos[1] == '\0')
    {
	D(bug("dirname(/)=/\n"));
        return uname;
    }

    D(bug("dirname(%s)=", filename));

    pos = uname + strlen(uname);
    while (pos[-1] == '/')
    {
        --pos;
	pos[0] = '\0';
    }
    while (--pos > uname)
    {
        if (pos[0] == '/')
        {
            pos[0] = '\0';
            break;
        }
    }

    if (pos == uname)
	uname = ".";

    D(bug("%s\n", uname));
    return uname;
}