thank me later

Pathnames

Each file has a pathname, pointing to an inode.

A device ID is a pair of identifiers:

All inodes have a numeric id. This id is unique within the filesystem.

Each inode specifies the blocksize for input/output operations.

Stat

struct stat
{
    dev_t           st_dev;
    ino_t           st_ino;
    mode_t          st_mode;
    nlink_t         st_nlink;
    uid_t           st_uid;
    gid_t           st_uid;
    dev_t           st_rdev;
    off_t           st_size;
    blksize_t       st_blksize;
    blkcount_t      st_blocks;
    struct timespec st_atim;
    struct timespec st_mtim;
    struct timespec st_ctim;
}

Hard Links and Symbolic Links


#include <unistd.h>

int link(const char *oldpath, const char *newpath);

int symlink(const char *oldpath, const char *newpath);

Creates a new link to a file.

A hard link:

A symbolic link:

Some system calls in UNIX/Linux systems have a pathname as parameter.

A pathname is a strings that resolves to a file.

A component of a pathname is a sub-string delimited by '/'.

Recall also that:

Step 1: determine the starting lookup directory

1.1) Absolute pathnames

An absolute pathname is pathname starts with '/'.

The starting lookup directory is the root directory of the calling process.

1.2) Relative pathnames

A relative pathname is a pathname that does not start with '/'.

The starting lookup directory is the current working directory of the calling process.

Step 2: walk the path components

To walk the path, we start by declaring a current lookup directory.

We initialize the current lookup directory to the starting lookup directory.

Then, we iterate along the components of the pathname.

Unless the current component is the last component, we do the following.

If the current lookup directory is a symbolic link, we replace it with the resolution of the link.

Then if the current lookup directory contains the current component and the current component is a directory, we set the current lookup directory to the current component, otherwise we return an error.

When the current component is the last,