Directory

# the Directory API

# Data structures

    /* entry types */

    #define ST_DIR     2
    #define ST_FILE   -3

    struct Entry{
        int type;              /* type of the entry */
        char *name;            /* name */
        SECTNUM sector;        /* sector pointer */
        char *comment;         /* optional comment */
        unsigned long size;    /* file size, 0 for a directory */
        long access;           /* RWEDAPSH access rights */

        int year, month, day;  /* date */
        int hour, min, sec;    /* hour */
    }

    /* general purpose list used to stored directory entries */
    struct List{
        void *content;         /* Filled with struct Entry* type */
        struct List *subdir;   /* If the cell content is a dir, its entries list */
                               /*  is stored here, else filled with NULL   */
        struct List *next;     /* Next cell */
    }

adfGetDirEnt()

## Syntax

struct List* adfGetDirEnt(struct Volume* vol, SECTNUM dir )
equivalent to
struct List* adfGetRDirEnt(struct Volume* vol, SECTNUM dir, FALSE )

## Description

Returns a linked list which contains the entries of one directory.

## Return values

The list, NULL in case of error.

## Examples

    struct List *list, *cell;
    struct Entry *entry;

    /* saves the head of the list */
    cell = list = adfGetDirEnt(vol,vol->curDirPtr);

    /* while cell->next is NULL, the last cell */
    while(cell) {
        entry = (struct Entry*)cell->content;
        printf("%s %ld\n", entry->name, entry->sector);
        cell = cell->next;
    }

    /* frees the list and the content */
    adfFreeDirList(list);

adfGetRDirEnt()

## Syntax

struct List* adfGetRDirEnt(struct Volume* vol, SECTNUM dir, BOOL recursive )

## Description

Returns a linked list which contains the entries of one directory.

## Return values

The list, NULL in case of error.

## Examples

    #define TRUE 1

    int main()
    {

    struct List *list, *cell;
    struct Entry *entry;

    ...

    /* saves the head of the list */
    cell = list = adfGetRDirEnt(vol,vol->curDirPtr,TRUE);

    /* prints the tree */
    printTree(cell);

    /* frees the list and the content */
    adfFreeDirList(list);

    ...

    }

    /* print the directories tree. recursive */
    printTree(struct List* tree)
    {
        while(tree) {
            entry = (struct Entry*)cell->content;
            printf("%s %ld\n", entry->name, entry->sector);
            if (tree->subdir!=NULL)
                printTree(tree->subdir)
            tree = tree->next;
        }
    }

adfChangeDir()

## Syntax

RETCODE adfChangeDir(struct Volume* vol, char *dirName)

## Description

Change the current working directory to the new one (dirName).

## Return values

RC_OK, something different in case of error.

adfParentDir()

## Syntax

RETCODE adfParentDir(struct Volume* vol)

## Description

Change the current working directory to its parent directory. If the current directory is the root of the filesystem ('/'), nothing happens.

## Return values

RC_OK, something different in case of error.

adfCreateDir()

## Syntax

RETCODE adfCreateDir(struct Volume* vol, SECTNUM parent, char* dirName)

## Description

Creates a new directory (dirName) into the specified directory (parent).

## Return values

RC_OK, something different in case of error.

adfRemoveEntry()

## Syntax

RETCODE adfRemoveEntry(struct Volume *vol, SECTNUM parent, char *name)

## Description

Removes a entry (a file or an empty directory) from one directory (parent).

## Return values

RC_OK, something different in case of error.

adfFreeDirList()

## Syntax

void adfFreeDirList(struct List* list)

## Description

Frees a linked list or a tree of directory entries.

adfAccess2String()

## Syntax

char* adfAccess2String(long access)

## Description

Converts the access rights from long to char*.

## Return values

A C string which represents the access rights.

adfRenameEntry()

## Syntax

RETCODE adfRenameEntry(struct Volume* vol, SECTNUM oldDir, char* old, SECTNUM newDir, char* new)

## Description

Changes the name of the entry old located in the oldDir into the name new, located into the newDir directory.

printEntry()

## Syntax

void printEntry(struct Entry* entry)

## Description

Do no use this function (not an adf one), but you can use its code to learn how to display a directory entry (in adf_dir.c).