Você está na página 1de 2

lseek , chmod and chown system calls

10.
6)
Lseek: The lseek call moves the file offset pointer to any point you specify. lseek doesn’t
7)
do any physical. I/O, but it determines the position in the file where the next I/O
4)
operation will take place. Here’s its syntax:
5) position = lseek(fd, offset, reference) ;
2) offset and reference arguments together control the location of the file’s offset
The
3)
pointer. Offset signifies the position (positive or negative) of this pointer relative to
1)
reference, which can take one of the three values:

SEEK_SET or 0 ----- Offset pointer set to beginning of file.


SEEK_CUR or 1 ----Offset pointer remains at current location.
SEEK_END or 2 ------Offset pointer set to end of file.

Example:
With some restrictions, offset can be a positive or negative integer, so it is represented
by a signed data type. For instance,
lseek ( fd, 10, SEEK_CUR)
Descriptor fd obtained from prior open moves the pointer forward by 10 characters
from its current position, and
lseek (fd, -10, SEEK_END)
Negative offset sets the pointer 10 characters before the end of file.

Change Owner (chown): Changing the owner or mode (access permissions) of a file
are operations on the inode, not on the file per se. The syntax of the calls is
chown(owner, group, pathname);
To change the owner of a file, the kernel converts the file name to. The process owner
must be superuser. The kernel then assigns the new owner and group to the file. After
the change of ownership, the old owner loses "owner" access rights to the file.
Example: Suppose there is a file called “/etc/pwd” , whose owner is PC. Now if you
want to change the ownership then following syntax can be used.
chown(DEPT, ‘/etc/pwd);
Now with the above command, ownership of file ‘/etc/pwd” is tranfered from PC to
DEPT.
Change Permission Modes (chmod): It changes the permissions specified in the
command line and leaves the other permissions unchanged. In this mode it uses the
following syntax:
Chmod (category, operation, permissions, pathname);
Following abbreviations are used by chmod.
Category Operation Permission
u- user ‘+’ - Assigns permission r – Read Permission
g- group ‘-‘ Removes Permission w - Write permission
o- others x - Execute Permission
a- all

Example:
1) Chmod u+x “abc.txt” --In this example the file abc.txt is assigned the execute
permission.
2) Chmod u-w “abc.txt” --In this example the file abc.txt is removed the write
permission)

Você também pode gostar