Sei sulla pagina 1di 21

SYSTEM CALLS

Group 9 - Stat, Dup, Dup2, Mount and Unmount


STAT SYSTEM CALL
Harsh Shah
• Stat system call is a system call in
Linux to check the status of a file
such as to check when the file was
accessed.
• The stat() system call actually returns
file attributes.
• The file attributes of an inode are
basically returned by Stat() function.
Syntax of Stat Function

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

st_dev: It is the ID of device in which we have our file residing currently.


st_rdev: This field describes that a particular file represents a particular device.
st_ino: It is the inode number or the serial number of the file. As it is an index number
so it should be unique for all files
st_size: st_size is the size of the file in bytes.
st_atime: It is the last time or the recent time at which the file was accessed.
st_ctime: It is the recent time at which the status or the permissions of the file was
changed.
st_mtime: It is the recent time at which the file was modified.
st_blksize: This field gives the preferred block size for I/O file system which may vary
from file to file.
st_blocks: This field tells the total number of blocks in multiples of 512 bytes.
st_nlink: This field tells the total number of hard links.
st_uid: This field indicates the user ID.
st_gid: This field indicates the group ID.
st_mode: It indicates the permissions on the file, tells the modes on a file. Following are
the flags that should be defined for st_mode field
DUP
Narendra
• The dup() system call creates a copy of the file
descriptor oldfd, using the lowest-numbered unused
file descriptor for the new descriptor.
• After a successful return, the old and new file
descriptors may be used interchangeably. They refer
to the same open file description and thus share file
offset and file status flags; for example, if the file offset
is modified by us on one of the file descriptors, the
offset is also changed for the other.
• The two file descriptors do not share file descriptor
flags (the close-on-exec flag). The close-on-exec flag
(FD_CLOEXEC) for the duplicate descriptor is off.
Syntax:

int dup(int fildes);

Field Description

int fildes The file descriptor that you are attempting to create an alias for.

dup returns the value of the new file descriptor that it has created (which will always be
return value the smallest available file descriptor). A negative return value means that an error
occured.
DUP-2
Sujit Shinde
• The dup2() system call performs the same task as
dup(), but instead of using the lowest-numbered
unused file descriptor, it uses the file descriptor
number specified in newfd.
• If the file descriptor newfd was previously open, it
is silently closed before being reused.
• The steps of closing and reusing the file descriptor
newfd are performed atomically.
Syntax:
int dup2(int fildes, int fildes2);

Field Description

int fildes The source file descriptor. This remains open after the call to dup2.

The destination file descriptor. This file descriptor will point to the same file as filedes after
int fildes2
this call returns.

dup2 returns the value of the second parameter (fildes2) upon success. A negative return
return value
value means that an error occured.
MOUNT
Vrund Shah
• Unix systems have a single directory tree.
• All accessible storage must have an associated
location in this single directory tree.
• This is unlike Windows where (in the most common
syntax for file paths) there is one directory tree per
storage component (drive).
• Mounting is the act of associating a storage device to
a particular location in the directory tree. For example,
when the system boots, a particular storage device
(commonly called the root partition) is associated with
the root of the directory tree, i.e., that storage device is
mounted on / (the root directory).
Syntax
• mount [-lhV]
• mount -a [-fFnrsvw] [-t vfstype] [-O optlist]
• mount [-fnrsvw] [-o option[,option]...]
device|dir
• mount [-fnrsvw] [-t vfstype] [-o options]
device|dir
Options
-V, --version
Output version.
-h, --help
Print a help message.
-v, --verbose
Verbose mode.
-a, --all
Mount all filesystems (of the given types) mentioned in fstab.
-F, --fork
(Used in conjunction with -a.) Fork off a new incarnation of mount for each
device.
-f, --fake
Causes everything to be done except for the actual system call; if it's not
obvious, this ''fakes'' mounting the filesystem.
-i, --internal-only
Don't call the /sbin/mount.<filesystem> helper even if it exists.
-l
Add the labels in the mount output..
-n, --no-mtab
Mount without writing in /etc/mtab. This is necessary for example when /etc is on a read-only
filesystem.
--no-canonicalize
Don't canonicalize paths. The mount command canonicalizes all paths (from command line
or fstab) and stores canonicalized paths to the /etc/mtab file.
-p, --pass-fd num
In case of a loop mount with encryption, read the passphrase from file descriptor num instead
of from the terminal.
-s
Tolerate sloppy mount options rather than failing. This will ignore mount options not supported
by a filesystem type. Not all filesystems support this option.
-r, --read-only
Mount the filesystem read-only. A synonym is -o ro.
-w, --rw
Mount the filesystem read/write. This is the default. A synonym is -o rw.
-L label
Mount the partition that has the specified label.
-U uuid
Mount the partition that has the specified uuid.
UNMOUNT
SHEFALI DSOUZA
• The umount command detaches the
specified file system(s) from the file hierarchy.
• A file system is specified by giving the
directory where it has been mounted.
• Giving the special device on which the file
system lives may also work, but is an obsolete
method, mainly because it will fail in case this
device was mounted on more than one
directory.
Syntax

umount [-hV]
umount -a [-dflnrv] [-t vfstype] [-O
options]
umount [-dflnrv] {dir|device}...
Options

a, --all
All of the file systems described in /etc/mtab are unmounted.
-A, --all-targets
Unmount all mountpoints in the current namespace for the specified filesystem.
-d, --detach-loop
When the unmounted device was a loop device, also free this loop device.
--fake
Causes everything to be done except for the actual system call; this 'fakes'
unmounting the filesystem.
-f, --force
Force unmount (in case of an unreachable NFS system)
-i, --internal-only
Do not call the /sbin/umount.<filesystem> helper even if it exists. By default
/sbin/umount.<filesystem> helper is called if one exists.
-n, --no-mtab
Unmount without writing in /etc/mtab.
-l, --lazy
Lazy unmount.
-O, --test-opts options,list
Indicate that the actions should only be taken on file systems with the
specified options in /etc/fstab. More than one option type may be
specified in a comma separated list. Each option can be prefixed
withno to specify options for which no action should be taken.
-R, --recursive
Recursively unmount each directory specified.
-r, --read-only
In case unmounting fails, try to remount read-only.
-t, --types vfstype,ext2,ext3
Indicate that the actions should only be taken on file systems of the
specified type.
-v, --verbose
Verbose mode.
-h, --help
Print help message and exit.
-V, --version
Print version and exit.

Potrebbero piacerti anche