Your IP : 216.73.216.40


Current Path : /var/www/html/bibhas.ghoshal/lab_files/
Upload File :
Current File : /var/www/html/bibhas.ghoshal/lab_files/System calls for files and directories in Linux.html

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="http://os.obs.utcluj.ro/OS/Lab/03.System%20Calls%20for%20File%20and%20Directory%20Manipulation%20in%20Linux_files/filelist.xml">
<title>System calls for files and directories in Linux</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Edit</o:Author>
  <o:LastAuthor>Adrian Colesa</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>630</o:TotalTime>
  <o:Created>2007-02-26T11:57:00Z</o:Created>
  <o:LastSaved>2007-02-26T11:57:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>3836</o:Words>
  <o:Characters>21866</o:Characters>
  <o:Company>home</o:Company>
  <o:Lines>182</o:Lines>
  <o:Paragraphs>51</o:Paragraphs>
  <o:CharactersWithSpaces>25651</o:CharactersWithSpaces>
  <o:Version>11.5606</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>0</w:DisplayVerticalDrawingGridEvery>
  <w:UseMarginsForDrawingGridOrigin/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:FootnoteLayoutLikeWW8/>
   <w:ShapeLayoutLikeWW8/>
   <w:AlignTablesRowByRow/>
   <w:ForgetLastTabAlignment/>
   <w:LayoutRawTableWidth/>
   <w:LayoutTableRowsApart/>
   <w:UseWord97LineBreakingRules/>
   <w:SelectEntireFieldWithStartOrEnd/>
   <w:UseWord2002TableStyleRules/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"MS Mincho";
	panose-1:2 2 6 9 4 2 5 8 3 4;
	mso-font-alt:"Arial Unicode MS";
	mso-font-charset:128;
	mso-generic-font-family:roman;
	mso-font-format:other;
	mso-font-pitch:fixed;
	mso-font-signature:1 134676480 16 0 131072 0;}
@font-face
	{font-family:"\@MS Mincho";
	panose-1:0 0 0 0 0 0 0 0 0 0;
	mso-font-charset:128;
	mso-generic-font-family:roman;
	mso-font-format:other;
	mso-font-pitch:fixed;
	mso-font-signature:1 134676480 16 0 131072 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"Times New Roman";}
h1
	{mso-style-next:Normal;
	margin-top:12.0pt;
	margin-right:0cm;
	margin-bottom:3.0pt;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	page-break-after:avoid;
	mso-outline-level:1;
	font-size:16.0pt;
	font-family:Arial;
	mso-font-kerning:16.0pt;}
h3
	{mso-style-next:Normal;
	margin-top:12.0pt;
	margin-right:0cm;
	margin-bottom:3.0pt;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	page-break-after:avoid;
	mso-outline-level:3;
	font-size:13.0pt;
	font-family:Arial;}
h5
	{mso-style-next:Normal;
	margin-top:12.0pt;
	margin-right:0cm;
	margin-bottom:3.0pt;
	margin-left:0cm;
	mso-pagination:widow-orphan;
	mso-outline-level:5;
	font-size:13.0pt;
	font-family:"Times New Roman";
	font-style:italic;}
p.MsoFooter, li.MsoFooter, div.MsoFooter
	{margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	mso-pagination:widow-orphan;
	tab-stops:center 8.0cm right 16.0cm;
	font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:"MS Mincho";
	mso-ansi-language:RO;}
p.Code, li.Code, div.Code
	{mso-style-name:Code;
	margin-top:0cm;
	margin-right:0cm;
	margin-bottom:0cm;
	margin-left:36.0pt;
	margin-bottom:.0001pt;
	text-align:justify;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Courier New";
	mso-fareast-font-family:"MS Mincho";
	mso-ansi-language:RO;
	mso-no-proof:yes;}
span.CodeChar
	{mso-style-name:"Code Char";
	font-family:"Courier New";
	mso-ascii-font-family:"Courier New";
	mso-fareast-font-family:"MS Mincho";
	mso-hansi-font-family:"Courier New";
	mso-bidi-font-family:"Courier New";
	mso-ansi-language:RO;
	mso-fareast-language:EN-US;
	mso-bidi-language:AR-SA;
	mso-no-proof:yes;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
@page Section1
	{size:612.0pt 792.0pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:36.0pt;
	mso-footer-margin:36.0pt;
	mso-paper-source:0;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:93015450;
	mso-list-template-ids:67698719;}
@list l0:level1
	{mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l0:level2
	{mso-level-text:"%1\.%2\.";
	mso-level-tab-stop:39.6pt;
	mso-level-number-position:left;
	margin-left:39.6pt;
	text-indent:-21.6pt;}
@list l0:level3
	{mso-level-text:"%1\.%2\.%3\.";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:61.2pt;
	text-indent:-25.2pt;}
@list l0:level4
	{mso-level-text:"%1\.%2\.%3\.%4\.";
	mso-level-tab-stop:90.0pt;
	mso-level-number-position:left;
	margin-left:86.4pt;
	text-indent:-32.4pt;}
@list l0:level5
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.";
	mso-level-tab-stop:126.0pt;
	mso-level-number-position:left;
	margin-left:111.6pt;
	text-indent:-39.6pt;}
@list l0:level6
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.";
	mso-level-tab-stop:144.0pt;
	mso-level-number-position:left;
	margin-left:136.8pt;
	text-indent:-46.8pt;}
@list l0:level7
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.";
	mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	margin-left:162.0pt;
	text-indent:-54.0pt;}
@list l0:level8
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.";
	mso-level-tab-stop:198.0pt;
	mso-level-number-position:left;
	margin-left:187.2pt;
	text-indent:-61.2pt;}
@list l0:level9
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9\.";
	mso-level-tab-stop:234.0pt;
	mso-level-number-position:left;
	margin-left:216.0pt;
	text-indent:-72.0pt;}
@list l1
	{mso-list-id:418402935;
	mso-list-template-ids:2005176900;}
@list l1:level1
	{mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:72.0pt;
	text-indent:-18.0pt;}
@list l1:level2
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:108.0pt;
	mso-level-number-position:left;
	margin-left:108.0pt;
	text-indent:-18.0pt;}
@list l1:level3
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:144.0pt;
	mso-level-number-position:right;
	margin-left:144.0pt;
	text-indent:-9.0pt;}
@list l1:level4
	{mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	margin-left:180.0pt;
	text-indent:-18.0pt;}
@list l1:level5
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:216.0pt;
	mso-level-number-position:left;
	margin-left:216.0pt;
	text-indent:-18.0pt;}
@list l1:level6
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:252.0pt;
	mso-level-number-position:right;
	margin-left:252.0pt;
	text-indent:-9.0pt;}
@list l1:level7
	{mso-level-tab-stop:288.0pt;
	mso-level-number-position:left;
	margin-left:288.0pt;
	text-indent:-18.0pt;}
@list l1:level8
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:324.0pt;
	mso-level-number-position:left;
	margin-left:324.0pt;
	text-indent:-18.0pt;}
@list l1:level9
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:360.0pt;
	mso-level-number-position:right;
	margin-left:360.0pt;
	text-indent:-9.0pt;}
@list l2
	{mso-list-id:1073283842;
	mso-list-template-ids:67698719;}
@list l2:level1
	{mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l2:level2
	{mso-level-text:"%1\.%2\.";
	mso-level-tab-stop:39.6pt;
	mso-level-number-position:left;
	margin-left:39.6pt;
	text-indent:-21.6pt;}
@list l2:level3
	{mso-level-text:"%1\.%2\.%3\.";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:61.2pt;
	text-indent:-25.2pt;}
@list l2:level4
	{mso-level-text:"%1\.%2\.%3\.%4\.";
	mso-level-tab-stop:90.0pt;
	mso-level-number-position:left;
	margin-left:86.4pt;
	text-indent:-32.4pt;}
@list l2:level5
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.";
	mso-level-tab-stop:126.0pt;
	mso-level-number-position:left;
	margin-left:111.6pt;
	text-indent:-39.6pt;}
@list l2:level6
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.";
	mso-level-tab-stop:144.0pt;
	mso-level-number-position:left;
	margin-left:136.8pt;
	text-indent:-46.8pt;}
@list l2:level7
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.";
	mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	margin-left:162.0pt;
	text-indent:-54.0pt;}
@list l2:level8
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.";
	mso-level-tab-stop:198.0pt;
	mso-level-number-position:left;
	margin-left:187.2pt;
	text-indent:-61.2pt;}
@list l2:level9
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9\.";
	mso-level-tab-stop:234.0pt;
	mso-level-number-position:left;
	margin-left:216.0pt;
	text-indent:-72.0pt;}
@list l3
	{mso-list-id:1117287398;
	mso-list-template-ids:67698719;}
@list l3:level1
	{mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l3:level2
	{mso-level-text:"%1\.%2\.";
	mso-level-tab-stop:39.6pt;
	mso-level-number-position:left;
	margin-left:39.6pt;
	text-indent:-21.6pt;}
@list l3:level3
	{mso-level-text:"%1\.%2\.%3\.";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:61.2pt;
	text-indent:-25.2pt;}
@list l3:level4
	{mso-level-text:"%1\.%2\.%3\.%4\.";
	mso-level-tab-stop:90.0pt;
	mso-level-number-position:left;
	margin-left:86.4pt;
	text-indent:-32.4pt;}
@list l3:level5
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.";
	mso-level-tab-stop:126.0pt;
	mso-level-number-position:left;
	margin-left:111.6pt;
	text-indent:-39.6pt;}
@list l3:level6
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.";
	mso-level-tab-stop:144.0pt;
	mso-level-number-position:left;
	margin-left:136.8pt;
	text-indent:-46.8pt;}
@list l3:level7
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.";
	mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	margin-left:162.0pt;
	text-indent:-54.0pt;}
@list l3:level8
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.";
	mso-level-tab-stop:198.0pt;
	mso-level-number-position:left;
	margin-left:187.2pt;
	text-indent:-61.2pt;}
@list l3:level9
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9\.";
	mso-level-tab-stop:234.0pt;
	mso-level-number-position:left;
	margin-left:216.0pt;
	text-indent:-72.0pt;}
@list l4
	{mso-list-id:1141650928;
	mso-list-template-ids:67698719;}
@list l4:level1
	{mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l4:level2
	{mso-level-text:"%1\.%2\.";
	mso-level-tab-stop:39.6pt;
	mso-level-number-position:left;
	margin-left:39.6pt;
	text-indent:-21.6pt;}
@list l4:level3
	{mso-level-text:"%1\.%2\.%3\.";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:61.2pt;
	text-indent:-25.2pt;}
@list l4:level4
	{mso-level-text:"%1\.%2\.%3\.%4\.";
	mso-level-tab-stop:90.0pt;
	mso-level-number-position:left;
	margin-left:86.4pt;
	text-indent:-32.4pt;}
@list l4:level5
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.";
	mso-level-tab-stop:126.0pt;
	mso-level-number-position:left;
	margin-left:111.6pt;
	text-indent:-39.6pt;}
@list l4:level6
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.";
	mso-level-tab-stop:144.0pt;
	mso-level-number-position:left;
	margin-left:136.8pt;
	text-indent:-46.8pt;}
@list l4:level7
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.";
	mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	margin-left:162.0pt;
	text-indent:-54.0pt;}
@list l4:level8
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.";
	mso-level-tab-stop:198.0pt;
	mso-level-number-position:left;
	margin-left:187.2pt;
	text-indent:-61.2pt;}
@list l4:level9
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9\.";
	mso-level-tab-stop:234.0pt;
	mso-level-number-position:left;
	margin-left:216.0pt;
	text-indent:-72.0pt;}
@list l5
	{mso-list-id:1407149203;
	mso-list-template-ids:-724518658;}
@list l5:level1
	{mso-level-tab-stop:36.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l5:level2
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l5:level3
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:108.0pt;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l5:level4
	{mso-level-tab-stop:144.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l5:level5
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l5:level6
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:216.0pt;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l5:level7
	{mso-level-tab-stop:252.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l5:level8
	{mso-level-number-format:alpha-lower;
	mso-level-tab-stop:288.0pt;
	mso-level-number-position:left;
	text-indent:-18.0pt;}
@list l5:level9
	{mso-level-number-format:roman-lower;
	mso-level-tab-stop:324.0pt;
	mso-level-number-position:right;
	text-indent:-9.0pt;}
@list l6
	{mso-list-id:1751923154;
	mso-list-template-ids:67698719;}
@list l6:level1
	{mso-level-tab-stop:18.0pt;
	mso-level-number-position:left;
	margin-left:18.0pt;
	text-indent:-18.0pt;}
@list l6:level2
	{mso-level-text:"%1\.%2\.";
	mso-level-tab-stop:39.6pt;
	mso-level-number-position:left;
	margin-left:39.6pt;
	text-indent:-21.6pt;}
@list l6:level3
	{mso-level-text:"%1\.%2\.%3\.";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:61.2pt;
	text-indent:-25.2pt;}
@list l6:level4
	{mso-level-text:"%1\.%2\.%3\.%4\.";
	mso-level-tab-stop:90.0pt;
	mso-level-number-position:left;
	margin-left:86.4pt;
	text-indent:-32.4pt;}
@list l6:level5
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.";
	mso-level-tab-stop:126.0pt;
	mso-level-number-position:left;
	margin-left:111.6pt;
	text-indent:-39.6pt;}
@list l6:level6
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.";
	mso-level-tab-stop:144.0pt;
	mso-level-number-position:left;
	margin-left:136.8pt;
	text-indent:-46.8pt;}
@list l6:level7
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.";
	mso-level-tab-stop:180.0pt;
	mso-level-number-position:left;
	margin-left:162.0pt;
	text-indent:-54.0pt;}
@list l6:level8
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.";
	mso-level-tab-stop:198.0pt;
	mso-level-number-position:left;
	margin-left:187.2pt;
	text-indent:-61.2pt;}
@list l6:level9
	{mso-level-text:"%1\.%2\.%3\.%4\.%5\.%6\.%7\.%8\.%9\.";
	mso-level-tab-stop:234.0pt;
	mso-level-number-position:left;
	margin-left:216.0pt;
	text-indent:-72.0pt;}
@list l7
	{mso-list-id:2039577859;
	mso-list-type:hybrid;
	mso-list-template-ids:-1092298346 67698711 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l7:level1
	{mso-level-number-format:alpha-lower;
	mso-level-text:"%1\)";
	mso-level-tab-stop:72.0pt;
	mso-level-number-position:left;
	margin-left:72.0pt;
	text-indent:-18.0pt;}
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
</head>

<body style="tab-interval:36.0pt" lang="EN-US">

<div class="Section1">

<p class="MsoNormal" style="text-align:center" align="center"><b style="mso-bidi-font-weight:
normal"><span style="font-size:16.0pt;font-family:Arial">System calls for working
with files and directories in Linux<o:p></o:p></span></b></p>

<p class="MsoNormal" style="text-align:center" align="center"><span style="font-size:16.0pt"><o:p>&nbsp;</o:p></span></p>

<h1 style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo4;
tab-stops:list 18.0pt"><!--[if !supportLists]--><span style="font-size:14.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:14.0pt">Theoretical Background <o:p></o:p></span></h1>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
following article presents the way to use the most common system calls in
order to make input-output operations on files, as well as operations to handle
files and directories in the Linux operating system.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h1 style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo4;
tab-stops:list 18.0pt"><!--[if !supportLists]--><span style="font-size:14.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:14.0pt">File descriptors<o:p></o:p></span></h1>

<p class="MsoNormal"><o:p>&nbsp;</o:p></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
operating system assigns internally to each opened file a descriptor or an
identifier (usually this is a positive integer). When opening or creating a new
file the system returns a file descriptor to the process that executed the
call. Each application has its own file descriptors. By convention, the first
three file descriptors are opened at the beginning of each process. The 0 file
descriptor identifies the standard input, 1 identifies the standard output and
2 the standard output for errors. The rest of the descriptors are used by the
processes when opening an ordinary, pipe or special file, or directories. There
are five system calls that generate file descriptors: <i style="mso-bidi-font-style:
normal">create</i>, <i style="mso-bidi-font-style:normal">open</i>, <i style="mso-bidi-font-style:normal">fcntl</i>, <i style="mso-bidi-font-style:
normal">dup</i> and <i style="mso-bidi-font-style:normal">pipe</i>. <o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h1 style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo4;
tab-stops:list 18.0pt"><!--[if !supportLists]--><span style="font-size:14.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:14.0pt">System calls when working with files<o:p></o:p></span></h1>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call OPEN<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">Opening
or creating a file can be done using the system call open. The syntax is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/types.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/stat.h&gt; <o:p></o:p></span></p>

<p class="Code" style="margin-bottom:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">#include &lt;fcntl.h&gt; <o:p></o:p></span></p>

<p class="Code"><b style="mso-bidi-font-weight:normal"><span style="mso-fareast-language:RO" lang="RO">int</span></b><span style="mso-fareast-language:
RO" lang="RO"> open(<b>const char</b> *path, <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:36.0pt;text-align:justify;text-indent:
36.0pt"><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;
mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span></span></b><b><span style="font-family:&quot;Courier New&quot;;mso-ansi-language:DE;mso-fareast-language:
RO" lang="DE">int</span></b><span style="font-family:&quot;Courier New&quot;;mso-ansi-language:
DE;mso-fareast-language:RO" lang="DE"> flags,... /* mode_t mod */);</span><span style="font-size:12.0pt;font-family:&quot;Courier New&quot;;mso-ansi-language:DE" lang="DE"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:
12.0pt;mso-ansi-language:DE" lang="DE"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">This
function returns the file descriptor or in case of an error -1. The number of
arguments that this function can have is two or three. The third argument is
used only when creating a new file. When we want to open an existing file only two
arguments are used. The function returns the smallest available file
descriptor. This can be used in the following system calls: <i style="mso-bidi-font-style:normal">read</i>, <i style="mso-bidi-font-style:
normal">write</i>, <i style="mso-bidi-font-style:normal">lseek</i> and <i style="mso-bidi-font-style:normal">close</i>. The effective UID or the
effective GID of the process that executes the call has to have read/write
rights, based on the value of the argument <i style="mso-bidi-font-style:normal">flags</i>.
The file pointer is places on the first byte in the file. The argument <i style="mso-bidi-font-style:normal">flags</i> is formed by a bitwise OR
operation made on the constants defined in the <i style="mso-bidi-font-style:
normal">fcntl.h</i> header. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_RDONLY<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Opens the file for reading. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_WRONLY<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Opens the file for writing. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_RDWR<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>The file is opened for reading and
writing.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_APPEND<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>It writes successively to the end of
the file.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_CREAT<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>The file is created in case it
didn\92t already exist.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_EXCL<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>If the file exists and O_CREAT is
positioned, calling <i style="mso-bidi-font-style:normal">open</i> will fail. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_NONBLOCK<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:35.45pt;text-align:justify"><span style="font-size:12.0pt">In the case of pipes and special files, this causes the
open system call and any other future I/O operations to never block. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_TRUNC<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>If the file exists all of its
content will be deleted. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">O_SYNC<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>It forces to write on the disk with
function <i style="mso-bidi-font-style:normal">write</i>. Though it slows down
all the system, it can be useful in critical situations.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
third argument, <i style="mso-bidi-font-style:normal">mod</i>, is a bitwise OR
made between a combination of two from the following list:<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">S_IRUSR, S_IWUSR,
S_IXUSR<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:36.0pt;text-align:justify;text-indent:
36.0pt"><span style="font-size:12.0pt;mso-fareast-language:RO">Owner: <i>read</i>,
<i>write</i>, <i>execute</i>. <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">S_IRGRP, S_IWGRP,
S_IXGRP <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:36.0pt;text-align:justify;text-indent:
36.0pt"><span style="font-size:12.0pt;mso-fareast-language:RO">Group: <i>read</i>,
<i>write</i>, <i>execute</i>.<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">S_IROTH, S_IWOTH,
S_IXOTH <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:36.0pt;text-align:justify;text-indent:
36.0pt"><span style="font-size:12.0pt;mso-fareast-language:RO">Others: <i>read</i>,
<i>write</i>, <i>execute.<o:p></o:p></i></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO;mso-bidi-font-style:italic"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO;mso-bidi-font-style:italic">The above define the access
rights for a file and they are defined in the <i>sys/stat.h</i> header. <o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt;mso-fareast-language:RO;
mso-bidi-font-style:italic"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call CREAT<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">A
new file can be created by:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/types.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/stat.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;fcntl.h&gt; <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><b><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO">int</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO;mso-bidi-font-weight:
bold"> creat(</span><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO">const char</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO;mso-bidi-font-weight:
bold"> *path, </span><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO">mode_t</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO;mso-bidi-font-weight:
bold"> mod)</span><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:
RO">;</span><span style="font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns the file descriptor or in case of an error it returns the
value -1. This call is equivalent with:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
font-family:&quot;Courier New&quot;"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
font-family:&quot;Courier New&quot;"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO">open(path, O_WRONLY |
O_CREAT | O_TRUNC, mod);</span><span style="font-size:12.0pt;font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
argument <i style="mso-bidi-font-style:normal">path</i> specifies the name of
the file, while <i style="mso-bidi-font-style:normal">mod</i> defines the
access rights. If the created file doesn\92t exist, a new i-node is allocated and
a link is made to this file from the directory it was created in. The owner of
the process that executes the call - given by the effective UID and the
effective GUID - must have writing permission in the directory. The open file
will have the access rights that were specified in the second argument (see <i style="mso-bidi-font-style:normal">umask</i>, too). The call returns the
smallest file descriptor available. The file is opened for writing and its
initial size is 0. The access time and the modification time are updated in the
i-node. If the file exists (permission to search the directory is needed), it
looses its contents and it will be opened for writing. The ownership and the access
permissions won\92t be modified. The second argument is ignored.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call READ<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">When
we want to read a certain number of bytes starting from the current position in
a file, we use the <i style="mso-bidi-font-style:normal">read</i> call. The
syntax is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;unistd.h&gt; <o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><b><span style="mso-fareast-language:
RO" lang="RO">ssize_t</span></b><span style="mso-fareast-language:RO" lang="RO"> read(<b>int</b>
fd, <b>void*</b> buf, <b>size_t</b> noct); <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns the number of bytes read, 0 for end of file (EOF) and -1 in
case an error occurred. It reads <i style="mso-bidi-font-style:normal">noct</i>
bytes from the open file referred by the <span class="GramE"><i style="mso-bidi-font-style:
normal">fd</i></span> descriptor and it puts it into a buffer <i style="mso-bidi-font-style:normal">buf</i>. The pointer (current position) is
incremented automatically after a reading that certain amount of bytes. The
process that executes a read operation waits until the system puts the data from
the disk into the buffer.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call WRITE<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">For
writing a certain number of bytes into a file starting from the current
position we use the <i style="mso-bidi-font-style:normal">write</i> call. Its
syntax is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;unistd.h&gt; <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO">ssize_t </span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO">write(<b>int </b>fd,<b> const
void* </b>buf, <b>size_t </b>noct);</span><span style="font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns the number of bytes written and the value -1 in case of an
error. It writes <i style="mso-bidi-font-style:normal">noct</i> bytes from the
buffer <i style="mso-bidi-font-style:normal">buf</i> into the file that has as
its descriptor <span class="GramE"><i style="mso-bidi-font-style:normal">fd</i></span>.
It is interesting to note that the actual writing onto the disk is delayed.
This is done at the initiative of the root, without informing the user when it
is done. If the process that did the call or an other process reads the data
that haven\92t been written on the disk yet, the system reads all this data out
from the cache buffers. The delayed writing is faster, but it has three
disadvantages: <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:72.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l7 level1 lfo7;tab-stops:list 72.0pt"><!--[if !supportLists]--><span style="font-size:12.0pt"><span style="mso-list:Ignore">a)<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">a disk error or a system error may cause loosing all
the data<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:72.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l7 level1 lfo7;tab-stops:list 72.0pt"><!--[if !supportLists]--><span style="font-size:12.0pt"><span style="mso-list:Ignore">b)<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">a process that had the initiative of a write operation
cannot be informed in case a writing error occurred <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:72.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l7 level1 lfo7;tab-stops:list 72.0pt"><!--[if !supportLists]--><span style="font-size:12.0pt"><span style="mso-list:Ignore">c)<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">the physical order of the write operations cannot be
controlled.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
eliminate these disadvantages, in some cases the O_SYNC is used. But as this
slows down the system and considering the reliability of today\92s systems it is
better to use the mechanism which includes using cache buffers. <o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call CLOSE<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">For
closing a file and thus eliminating the assigned descriptor we use the system
call <i style="mso-bidi-font-style:normal">close</i>. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;unistd.h&gt; <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO">int</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO;mso-bidi-font-weight:bold" lang="RO">
close(int fd);</span><span style="font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns 0 in case of success and -1 in case of an error. At the
termination of a process an open file is closed anyway.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.6.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call LSEEK<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
position a <u>pointer</u> (that points to the current position) in an absolute
or relative way can be done by calling the <i style="mso-bidi-font-style:normal">lseek</i>
function. Read and write operations are done relative to the current position
in the file. The syntax for <i style="mso-bidi-font-style:normal">lseek</i> is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/types.h&gt; <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;
margin-left:36.0pt;text-align:justify"><span style="font-family:&quot;Courier New&quot;;
mso-fareast-font-family:&quot;MS Mincho&quot;;mso-ansi-language:RO;mso-fareast-language:
RO;mso-no-proof:yes" lang="RO">#include &lt;unistd.h&gt; <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;
mso-fareast-font-family:&quot;MS Mincho&quot;;mso-ansi-language:RO;mso-fareast-language:
RO" lang="RO">off_t</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:
&quot;MS Mincho&quot;;mso-ansi-language:RO;mso-fareast-language:RO;mso-bidi-font-weight:
bold" lang="RO"> lseek(</span><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO">int </span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO;mso-bidi-font-weight:bold" lang="RO">fd, </span><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;
mso-fareast-font-family:&quot;MS Mincho&quot;;mso-ansi-language:RO;mso-fareast-language:
RO" lang="RO">off_t</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:
&quot;MS Mincho&quot;;mso-ansi-language:RO;mso-fareast-language:RO;mso-bidi-font-weight:
bold" lang="RO"> offset, </span><b style="mso-bidi-font-weight:normal"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO">int </span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO;mso-bidi-font-weight:bold" lang="RO">ref);</span><span style="font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns the displacement of the new current position from the beginning
of the file or -1 in case of an error. There isn\92t done any I/O operation and
the function doesn\92t send any commands to the disk controller. It <i style="mso-bidi-font-style:normal">ref</i> is set to SEEK_SET the positioning
is done relative to the beginning of the file (the first byte in the file is at
position 0). If <i style="mso-bidi-font-style:normal">ref</i> is SEEK_CUR the
positioning is done relative to the current position. If <i style="mso-bidi-font-style:
normal">ref</i> is SEEK_END then the positioning is done relative to the end of
the file. The system calls <i style="mso-bidi-font-style:normal">open</i>, <i style="mso-bidi-font-style:normal">creat</i>, <i style="mso-bidi-font-style:
normal">write</i> and <i style="mso-bidi-font-style:normal">read</i> execute an
<i style="mso-bidi-font-style:normal">lseek</i> by default. If a file was
opened using the symbolic constant O_APPEND then an <i style="mso-bidi-font-style:
normal">lseek</i> call is made to the end of the file before a write operation.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<b><span style="font-size:12.0pt;font-family:Arial;mso-fareast-font-family:
&quot;Times New Roman&quot;;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA"><br style="page-break-before:always" clear="all">
</span></b>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.7.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call LINK<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
link an existing file to another directory (or to the same directory) link can
be used. To make such a link in fact means to set a new name or a path to an
existing file. The <i style="mso-bidi-font-style:normal">link</i> system call creates a hard link. 
Creating symbolic links can be done using <i style="mso-bidi-font-style:normal">symlink</i> system call. 
The syntax of link is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="margin-bottom:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">#include &lt;unistd.h&gt; <o:p></o:p></span></p>

<p class="Code"><b style="mso-bidi-font-weight:normal"><span style="mso-fareast-language:RO" lang="RO">int</span></b><span style="mso-fareast-language:
RO" lang="RO"> link(<b style="mso-bidi-font-weight:normal">const char*</b> oldpath, <b style="mso-bidi-font-weight:normal">const char* </b>newpath); <o:p></o:p></span></p>

<p class="Code"><b style="mso-bidi-font-weight:normal"><span style="mso-fareast-language:RO" lang="RO">int</span></b><span style="mso-fareast-language:
RO" lang="RO"> symlink(<b style="mso-bidi-font-weight:normal">const char*</b> oldpath, <b style="mso-bidi-font-weight:normal">const char* </b>newpath); <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns 0 in case of success and -1 in case of an error. The argument <i style="mso-bidi-font-style:normal">oldpath</i> has to be a path to an existing
file. Only the root has the right to set a link to a directory.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.8.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call UNLINK<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
delete a link (a path) in a directory we can use the <i style="mso-bidi-font-style:
normal">unlink</i> system call. Its syntax is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>

<p class="Code" style="margin-bottom:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">#include &lt;unistd.h&gt; <o:p></o:p></span></p>

<p class="Code"><b style="mso-bidi-font-weight:normal"><span style="mso-fareast-language:RO" lang="RO">int</span></b><span style="mso-fareast-language:
RO" lang="RO"> unlink(<b style="mso-bidi-font-weight:normal">const char*</b> path); <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns 0 in case of success and -1 otherwise. The function decrements
the hard <span class="GramE">link counter</span> in the i-node and deletes the
appropriate directory entry for the file whose link was deleted. If the number of
links of a file becomes 0 then the space occupied by the file and its i-node
will be freed. Only the root can delete a directory. <o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.9.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System calls STAT, LSTAT and FSTAT<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">In
order to obtain more details about a file the following system calls can be
used: <i style="mso-bidi-font-style:normal">stat</i>, <i style="mso-bidi-font-style:
normal">lstat</i> or <i style="mso-bidi-font-style:normal">fstat</i>.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">#include &lt;sys/types.h&gt; </span></p>

<p class="Code"><span lang="RO">#include &lt;sys/stat.h&gt; </span></p>

<p class="Code" style="margin-top:3.0pt"><b style="mso-bidi-font-weight:normal"><span lang="RO">int</span></b><span lang="RO"> stat(<b>const char*</b> path, <b>struct
stat*</b> buf);</span></p>

<p class="Code" style="margin-top:3.0pt"><b style="mso-bidi-font-weight:normal"><span lang="RO">int</span></b><span lang="RO"> lstat(<b>const char*</b> path, <b>struct
stat*</b> buf); </span></p>

<p class="Code" style="margin-top:3.0pt"><b style="mso-bidi-font-weight:normal"><span lang="RO">int</span></b><span lang="RO"> fstat(<b style="mso-bidi-font-weight:normal">int</b>
df, <b>struct stat*</b> buf); </span></p>

<p class="MsoNormal" style="text-align:justify"><i style="mso-bidi-font-style:
normal"><o:p>&nbsp;</o:p></i></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">These
three functions return 0 in case of success and -1 in case of an error. The
first two gets as input parameter a name of a file and completes the structure
of the buffer with additional information read from its i-node. The <i style="mso-bidi-font-style:normal">fstat</i> function is similar, but it works
for files that were already opened and for which the file descriptor is known.
The difference between <i style="mso-bidi-font-style:normal">stat</i> and <i style="mso-bidi-font-style:normal">lstat</i> is that in case of a symbolic link,
function <i style="mso-bidi-font-style:normal">stat</i> returns information
about the linked (refered) file, while <i style="mso-bidi-font-style:normal">lstat</i>
returns information about the symbolic link file. The <i style="mso-bidi-font-style:normal">struct stat</i> structure is described in
the <i style="mso-bidi-font-style:normal">sys/stat.h</i> header and has the
following fields:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">struct stat { </span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">mode_t st_mode;<span style="mso-tab-count:1">&nbsp;&nbsp; </span>/* file type &amp; rights */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">ino_t st_ino;<span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp; </span>/* i-node */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">dev_t st_dev;<span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp; </span>/* <u>num&#259;r de dispozitiv (SF)</u> */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">nlink_t st_nlink; /* nr
of links */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">uid_t st_uid; <span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp; </span>/* owner ID */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">gid_t st_gid; <span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp; </span>/* group ID */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">off_t st_size; <span style="mso-tab-count:1">&nbsp;&nbsp; </span>/* ordinary file size */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">time_t st_atime; <span style="mso-tab-count:1"> </span>/* last time it was accessed */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">time_t st_mtime; <span style="mso-tab-count:1"> </span>/* last time it was modified */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">time_t st_ctime; <span style="mso-tab-count:1"> </span>/* last time settings were changed */</span></p>

<p class="Code" style="margin-left:72.0pt"><span lang="RO">dev_t st_rdev;<span style="mso-spacerun:yes">&nbsp;&nbsp; </span><span style="mso-tab-count:1"> </span>/* <u>nr.
dispozitiv */<o:p></o:p></u></span></p>

<p class="Code" style="margin-left:72.0pt"><u><span lang="RO"><span style="mso-tab-count:3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>/* pt. fi&#351;iere speciale /<o:p></o:p></span></u></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">long st_blksize; <span style="mso-tab-count:1"> </span>/* optimal size of the I/O block */</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">long st_blocks; <span style="mso-tab-count:1">&nbsp; </span>/* nr of 512 byte blocks allocated */</span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt">};<span style="font-size:12.0pt"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
Linux command that the most frequently uses this function is <i style="mso-bidi-font-style:normal">ls</i>. Type declarations for the members of
this structure can be found in the <i style="mso-bidi-font-style:normal">sys/stat.h</i>
header. The type and access rights for the file are encrypted in the <i style="mso-bidi-font-style:normal">st_mode</i> field and can be determined
using the following macros:<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><span style="mso-tab-count:
1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>

<div align="center">

<table class="MsoNormalTable" style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext" border="1" cellpadding="0" cellspacing="0">
 <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;page-break-inside:avoid">
  <td colspan="2" style="width:305.6pt;border:none;border-bottom:solid windowtext 1.0pt;
  mso-border-bottom-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="407">
  <h5>Table 1. Macros for obtaining the type of a file</h5>
  </td>
 </tr>
 <tr style="mso-yfti-irow:1">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  background:silver;padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <h3 style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:12.0pt">Macro<o:p></o:p></span></h3>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;background:silver;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoNormal"><b style="mso-bidi-font-weight:normal"><span style="font-size:12.0pt;font-family:Arial">Meaning <o:p></o:p></span></b></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:2">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISREG(st_mode)<o:p></o:p></span></p>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoFooter" style="tab-stops:36.0pt"><span lang="RO">Regular file.&nbsp;</span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:3">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISDIR(st_mode)<o:p></o:p></span></p>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoNormal"><span style="font-size:12.0pt">Directory file.<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:4">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISCHR(st_mode)<o:p></o:p></span></p>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoNormal"><span style="font-size:12.0pt">Special <u>device </u>of
  type character.&nbsp;<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:5">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISBLK(st_mode)<o:p></o:p></span></p>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoNormal"><span style="font-size:12.0pt">Special device of type block.&nbsp;<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:6">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISFIFO(st_mode)<o:p></o:p></span></p>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoNormal"><span style="font-size:12.0pt">Pipe file or FIFO.&nbsp;<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:7;mso-yfti-lastrow:yes">
  <td style="width:118.8pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="158">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISLNK(st_mode)<o:p></o:p></span></p>
  </td>
  <td style="width:186.8pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="249">
  <p class="MsoNormal"><span style="font-size:12.0pt">Symbolic link.&nbsp;<o:p></o:p></span></p>
  </td>
 </tr>
</tbody></table>

</div>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">Decrypting
the information contained in the <i style="mso-bidi-font-style:normal">st_mode</i>
field can be done by testing the result of a bitwise AND made between the <i style="mso-bidi-font-style:normal">st_mode</i> field and one of the constants
(bit mask): </span><span style="font-size:12.0pt;mso-ansi-language:
RO" lang="RO">S_IFIFO, S_IFCHR, S_IFBLK, S_IFDIR, S_IFREG, S_IFLNK, S_ISUID (<i>suid</i><span style="mso-bidi-font-style:italic"> bit set</span>), S_ISGID (<i>sgid</i><span style="mso-bidi-font-style:italic"> bit set</span>), S_ISVTX (<i>sticky</i><span style="mso-bidi-font-style:italic"> bit set</span>), S_IRUSR (read right for
the owner), S_IWUSR (write right for the owner), S_IWUSR (execution right for
the owner), etc.</span><span style="font-size:12.0pt"><o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 49.5pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.10.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call ACCESS<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">When
opening a file with system call <i style="mso-bidi-font-style:normal">open</i>
the root verifies the access rights in function of the UID and the effective
GID. There are some cases though when a process verifies these rights based
upon the real UID and GID. A situation when this can be useful is when a
process is executed with other access right using the <i style="mso-bidi-font-style:
normal">suid</i> or <i style="mso-bidi-font-style:normal">sgid</i> bit. Even
though a process may have root rights during execution, sometimes it is
necessary to test whether the real user can or cannot access the file. For this
we can use <i style="mso-bidi-font-style:normal">access</i> which allows
verifying the access rights of a file based on the real UID or GID. The syntax
for this system call is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">#include &lt;unistd.h&gt; </span></p>

<p class="Code" style="margin-top:3.0pt"><b style="mso-bidi-font-weight:normal"><span lang="RO">int</span></b><span lang="RO"> access(<b>const char*</b> path, <b style="mso-bidi-font-weight:normal">int</b> mod); </span></p>

<p class="Code"><span lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns 0 if the access right exists and -1 otherwise. The argument
mod is a bitwise AND between R_OK (permission to read), W_OK (permission to
write), X_OK (execution right), F_OK (the file exists).<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 49.5pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.11.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call UMASK<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
enhance the security in case of operations regarding the creation of files, the
Linux operating system offers a default mask to reset some access rights.
Encrypting this mask is made in a similar way to the encrypting of the access
rights in the i-node of a file. When creating a file those bits that are set to
1 in the mask invalidate the corresponding bits in the argument that specify
the access rights. The mask doesnot affect the system call <i style="mso-bidi-font-style:
normal">chmod</i>, so the processes can explicitly set their access rights independently
form the <i style="mso-bidi-font-style:normal">umask</i> mask. The syntax for
the call is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">#include &lt;sys/types.h&gt; </span></p>

<p class="Code"><span lang="RO">#include &lt;sys/stat.h&gt; </span></p>

<p class="Code" style="margin-top:3.0pt"><b><span lang="RO">mode_t</span></b><span lang="RO"> umask(<b>mode_t</b> mask); </span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns the value of the previous mask. The effect of the call is
shown below:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="font-size:12.0pt" lang="RO"><span style="mso-tab-count:
1">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span lang="RO">main() /* test umask */ </span></p>

<p class="Code"><span lang="RO">{ </span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">int fd; </span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">umask(022); </span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">if
((fd=creat("temp", 0666))==-1) </span></p>

<p class="Code" style="margin-left:72.0pt;text-indent:36.0pt"><span lang="RO">perror("creat");</span></p>

<p class="Code" style="text-indent:36.0pt"><span lang="RO">system("ls -l
temp"); </span></p>

<p class="Code"><span lang="RO">} </span></p>

<p class="MsoNormal" style="text-align:justify"><o:p>&nbsp;</o:p></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
result will be of the following form: <o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt;margin-right:0cm;margin-bottom:3.0pt;
margin-left:36.0pt"><span class="CodeChar"><span lang="RO">-rw-r--r-- temp </span></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">Note
that the write permission for the group and other users beside the owner was
automatically reset.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<b><span style="font-size:12.0pt;font-family:Arial;mso-fareast-font-family:
&quot;Times New Roman&quot;;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA"><br style="page-break-before:always" clear="all">
</span></b>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 49.5pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.12.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call CHMOD<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
modify the access rights for an existing file we use:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">#include &lt;sys/types.h&gt; </span></p>

<p class="Code"><span lang="RO">#include &lt;sys/stat.h&gt; </span></p>

<p class="Code" style="margin-top:3.0pt"><b style="mso-bidi-font-weight:normal"><span lang="RO">int</span></b><span lang="RO"> chmod(<b>const char*</b> path, <b>mode_t</b>
mod); </span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns 0 in case of a success and -1 otherwise. The <i style="mso-bidi-font-style:normal">chmod</i> call modifies the access rights of
the file specified by the <i style="mso-bidi-font-style:normal">path</i>
depending on the access rights specified by the <i style="mso-bidi-font-style:
normal">mod</i> argument. To be able to modify the access rights the effective
UID of the process has to be identical to the owner of the file or the process
must have root rights. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
<i style="mso-bidi-font-style:normal">mod</i> argument can be specified by one
of the symbolic constants defined in the <i style="mso-bidi-font-style:normal">sys/stat.h</i>
header. Their effect can be obtained by making a bitwise OR operation on them: <o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<table class="MsoNormalTable" style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext" border="1" cellpadding="0" cellspacing="0">
 <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;page-break-inside:avoid">
  <td colspan="2" style="width:379.25pt;border:none;border-bottom:solid windowtext 1.0pt;
  mso-border-bottom-alt:solid windowtext .75pt;padding:0cm 5.4pt 0cm 5.4pt" width="506">
  <p class="MsoNormal"><b>Table 2. <span style="mso-spacerun:yes">&nbsp;</span>Bit
  masks for testing the access rights of a file <o:p></o:p></b></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:1">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .75pt;mso-border-alt:solid windowtext .75pt;
  background:silver;padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><b><span style="font-size:12.0pt">Mode</span></b><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .75pt;mso-border-left-alt:solid windowtext .75pt;
  mso-border-alt:solid windowtext .75pt;background:silver;padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><b><span style="font-size:12.0pt">Description</span></b><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:2">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .75pt;mso-border-alt:solid windowtext .5pt;
  mso-border-top-alt:solid windowtext .75pt;padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISUID<o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .75pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .75pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><span style="font-size:12.0pt">Sets the suid bit.<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:3">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISGID<o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><span style="font-size:12.0pt">Sets the sgid bit.<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:4">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_ISVTX<o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><span style="font-size:12.0pt">Sets the sticky bit.<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:5">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_IRWXU&nbsp;<o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><span style="font-size:12.0pt">Read, write, execute rights
  for the owner obtained from: </span><span style="font-size:12.0pt;font-family:
  &quot;Courier New&quot;">S_IRUSR | S_IWUSR | S_IXUSR</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:6">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_IRWXG&nbsp;<o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><span style="font-size:12.0pt">Read, write, execute rights
  for the group obtained from: </span><span style="font-size:12.0pt;font-family:
  &quot;Courier New&quot;">S_IRGRP | S_IWGRP | S_IXGRP</span><span style="font-size:12.0pt">&nbsp;<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:7;mso-yfti-lastrow:yes">
  <td style="width:73.15pt;border:solid windowtext 1.0pt;border-top:
  none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" width="98">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">S_IRWXO<o:p></o:p></span></p>
  </td>
  <td style="width:306.1pt;border-top:none;border-left:none;
  border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" width="408">
  <p class="MsoNormal"><span style="font-size:12.0pt">Read, write, execute rights
  for others obtained from: </span><span style="font-size:12.0pt;font-family:
  &quot;Courier New&quot;">S_IROTH | S_IWOTH | S_IXOTH</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
 </tr>
</tbody></table>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 49.5pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.13.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call CHOWN<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">This
system call is used to modify the owner (UID) and the group (GID) that a
certain file belongs to. The syntax of the function is:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">#include &lt;sys/types.h&gt; </span></p>

<p class="Code"><span lang="RO">#include &lt;unistd.h&gt; </span></p>

<p class="Code" style="margin-top:3.0pt"><b><span lang="RO">int</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> chown(</span><b style="mso-bidi-font-weight:
normal"><span lang="RO">const char*</span></b><span style="mso-bidi-font-weight:
bold" lang="RO"> path, </span><b style="mso-bidi-font-weight:normal"><span lang="RO">uid_t</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> owner, </span><b style="mso-bidi-font-weight:
normal"><span lang="RO">gid_t</span></b><span style="mso-bidi-font-weight:
bold" lang="RO"> grp);</span><span lang="RO"> </span></p>

<p class="Code"><span lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
function returns 0 in case of success and -1 in case of an error. Calling this
function will change the owner and the group of the file specified by the argument
<i style="mso-bidi-font-style:normal">path</i> to the values specified by the
arguments <i style="mso-bidi-font-style:normal">owner</i> and <i style="mso-bidi-font-style:normal">grp</i>. None of the users can change the
owner of any file (even of his/her own files), except the root user, but they can change the GID for
their own files to that of any group they belong to. <o:p></o:p></span></p>

<b><span style="font-size:12.0pt;font-family:Arial;mso-fareast-font-family:
&quot;Times New Roman&quot;;mso-ansi-language:EN-US;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA"><br style="page-break-before:always" clear="all">
</span></b>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 49.5pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">3.14.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">System call UTIME<o:p></o:p></span></h3>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">There
are three members of the structure <i style="mso-bidi-font-style:normal">stat</i>
that refer to time. They are presented in the following table:<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<div align="center">

<table class="MsoNormalTable" style="border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt;
 mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh:.5pt solid windowtext;
 mso-border-insidev:.5pt solid windowtext" border="1" cellpadding="0" cellspacing="0">
 <tbody><tr style="mso-yfti-irow:0;mso-yfti-firstrow:yes;page-break-inside:avoid">
  <td colspan="3" style="width:362.85pt;border:none;
  border-bottom:solid windowtext 1.0pt;mso-border-bottom-alt:solid windowtext .75pt;
  padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="484">
  <p class="MsoNormal"><b>Table 3.<span style="mso-spacerun:yes">&nbsp; </span>Timing
  information associated with a file<o:p></o:p></b></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:1">
  <td style="width:64.85pt;border:solid windowtext 1.0pt;
  border-top:none;mso-border-top-alt:solid windowtext .75pt;mso-border-alt:
  solid windowtext .75pt;background:silver;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="86">
  <p class="MsoNormal"><b><span style="font-size:12.0pt">Field </span></b><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
  <td style="width:215.6pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .75pt;mso-border-left-alt:solid windowtext .75pt;
  mso-border-alt:solid windowtext .75pt;background:silver;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="287">
  <p class="MsoNormal"><b><span style="font-size:12.0pt">Description</span></b><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
  <td style="width:82.4pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .75pt;mso-border-left-alt:solid windowtext .75pt;
  mso-border-alt:solid windowtext .75pt;background:silver;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="110">
  <p class="MsoNormal"><b><span style="font-size:12.0pt">Operation</span></b><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:2">
  <td style="width:64.85pt;border:solid windowtext 1.0pt;
  border-top:none;mso-border-top-alt:solid windowtext .75pt;mso-border-alt:
  solid windowtext .5pt;mso-border-top-alt:solid windowtext .75pt;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="86">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">st_atime&nbsp;<o:p></o:p></span></p>
  </td>
  <td style="width:215.6pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .75pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .75pt;
  padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="287">
  <p class="MsoNormal"><span style="font-size:12.0pt">Last time the data in the file
  was accessed<o:p></o:p></span></p>
  </td>
  <td style="width:82.4pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .75pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;mso-border-top-alt:solid windowtext .75pt;
  padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="110">
  <p class="MsoNormal"><span style="font-size:12.0pt">Read<o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:3">
  <td style="width:64.85pt;border:solid windowtext 1.0pt;
  border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="86">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">st_mtime<o:p></o:p></span></p>
  </td>
  <td style="width:215.6pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="287">
  <p class="MsoNormal"><span style="font-size:12.0pt">Last time the data in the
  file was modified <o:p></o:p></span></p>
  </td>
  <td style="width:82.4pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="110">
  <p class="MsoNormal"><span style="font-size:12.0pt">Write <o:p></o:p></span></p>
  </td>
 </tr>
 <tr style="mso-yfti-irow:4;mso-yfti-lastrow:yes">
  <td style="width:64.85pt;border:solid windowtext 1.0pt;
  border-top:none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt;
  padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="86">
  <p class="MsoNormal"><span style="font-family:&quot;Courier New&quot;">st_ctime<o:p></o:p></span></p>
  </td>
  <td style="width:215.6pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="287">
  <p class="MsoNormal"><span style="font-size:12.0pt">Changing the settings for
  the <span style="mso-spacerun:yes">&nbsp;</span>i-node&nbsp;<o:p></o:p></span></p>
  </td>
  <td style="width:82.4pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt" valign="top" width="110">
  <p class="MsoNormal"><span style="font-size:12.0pt;color:black">chmod, chown</span><span style="font-size:12.0pt"><o:p></o:p></span></p>
  </td>
 </tr>
</tbody></table>

</div>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify;tab-stops:313.5pt"><span style="font-size:12.0pt">The difference between the time the file was last
modified and the change in the setting of the i-node is that the first one
refers to the time when the contents of the file were modified while the second
one refers to the time when the information in the i-node was last
modified.<span style="mso-spacerun:yes">&nbsp; </span>This is due to the fact that
the information in the i-node is kept separately from the contents of the file.
System calls that change the i-node are those ones which modify the access
rights of a file, change the UID, change the number of links, etc. The system
doesnot keep the time when the i-node was last accessed. This is why neither of
the system calls <i style="mso-bidi-font-style:normal">access</i> or <i style="mso-bidi-font-style:normal">stat</i> do not change these times. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;tab-stops:313.5pt"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify;tab-stops:313.5pt"><span style="font-size:12.0pt">The access time and last modification time of any kind
of files can be changed by calling one of the system call presented below:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;tab-stops:313.5pt"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="text-align:left" align="left"><span lang="RO">#include
&lt;sys/time.h&gt; </span></p>

<p class="Code" style="margin-top:3.0pt;text-align:left" align="left"><b><span lang="RO">int</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> utimes(</span><b style="mso-bidi-font-weight:normal"><span lang="RO">const char* </span></b><span style="mso-bidi-font-weight:bold" lang="RO">path,<br>
<span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><b style="mso-bidi-font-weight:
normal"><span lang="RO">const struct timeval*</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> times);<o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt;text-align:left" align="left"><b><span lang="RO">int</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> lutimes(</span><b style="mso-bidi-font-weight:normal"><span lang="RO">const char* </span></b><span style="mso-bidi-font-weight:bold" lang="RO">path, <br>
<span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><b style="mso-bidi-font-weight:
normal"><span lang="RO">const struct timeval*</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> times);</span><span lang="RO"> </span></p>

<p class="Code" style="margin-top:3.0pt;text-align:left" align="left"><b><span lang="RO">int</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> futimes(</span><b style="mso-bidi-font-weight:normal"><span lang="RO">int</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> fd, </span><b style="mso-bidi-font-weight:
normal"><span lang="RO">const struct timeval*</span></b><span style="mso-bidi-font-weight:bold" lang="RO"> times);</span></p>

<p class="MsoNormal" style="text-align:justify"><o:p>&nbsp;</o:p></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
functions return 0 in case of success and -1 otherwise. Only the owner of a
file or the root can change the times associated with a file. The parameter <i style="mso-bidi-font-style:normal">times</i> represents the address (pointer)
of a list of two <i style="mso-bidi-font-style:normal">timeval</i> structures,
corresponding to the access and modification time. The fields of the <i style="mso-bidi-font-style:normal">timeval</i> structure are: <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">struct timeval { </span></p>

<p class="Code"><span lang="RO">long tv_sec; /* seconds passed since 1.01.1970 */</span></p>

<p class="Code"><span lang="RO">suseconds_t tv_usec; <span style="mso-tab-count:
1">&nbsp;&nbsp; </span>/* microseconds */</span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt">}<span style="font-size:12.0pt"><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">To
obtain the current time in the form it is required by the <i style="mso-bidi-font-style:
normal">timeval</i> structure, we can use the <i style="mso-bidi-font-style:
normal">gettimeofday</i> function. For different conversions between the normal
format of a data and hour and the format specific to the <i style="mso-bidi-font-style:
normal">timeval</i> structure the function <i style="mso-bidi-font-style:normal">ctime</i>
can be used or any other functions belonging to the same family (for more
details see the textbook). <o:p></o:p></span></p>

<b><span style="font-size:14.0pt;font-family:Arial;mso-fareast-font-family:
&quot;Times New Roman&quot;;mso-font-kerning:16.0pt;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA"><br style="page-break-before:always" clear="all">
</span></b>

<h1 style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo4;
tab-stops:list 18.0pt"><!--[if !supportLists]--><span style="font-size:14.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:14.0pt">Functions for working with directories<o:p></o:p></span></h1>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">A
directory can be read as a file by anyone whoever has reading permissions for
it. Writing a directory as a file can only be done by the kernel. The structure
of the directory appears to the user as a succession of structures named
directory entries. A directory entry contains, among other information, the
name of the file and the i-node of this. For reading the directory entries one
after the other we can use the following functions:<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="mso-fareast-language:
RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/types.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;dirent.h&gt; <o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><b><span style="mso-fareast-language:
RO" lang="RO">DIR*</span></b><span style="mso-fareast-language:RO" lang="RO"> opendir(<b>const
char*</b> pathname);<o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><b><span style="mso-fareast-language:
RO" lang="RO">struct dirent*</span></b><span style="mso-fareast-language:RO" lang="RO">
readdir(<b>DIR*</b> dp); <o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><b><span style="mso-fareast-language:
RO" lang="RO">void</span></b><span style="mso-fareast-language:RO" lang="RO"> rewinddir(<b>DIR*
</b>dp); <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><b><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO">int</span></b><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO"> closedir(<b>DIR*</b>
dp);<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><span style="font-family:&quot;Courier New&quot;;mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO">The <i style="mso-bidi-font-style:normal">opendir</i>
function opens a directory. It returns a valid pointer if the opening was
successful and NULL otherwise. <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO">The <i style="mso-bidi-font-style:normal">readdir</i>
function, at every call, reads another directory entry from the current
directory. The first <i style="mso-bidi-font-style:normal">readdir</i> will
read the first directory entry; the second call will read the next entry and so
on. In case of a successful reading the function will return a valid pointer to
a structure of type <i style="mso-bidi-font-style:normal">dirent</i> and NULL
otherwise (in case it reached the end of the directory, for example). <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO">The <i style="mso-bidi-font-style:normal">rewinddir</i>
function repositions the file pointer to the first directory entry (the
beginning of the directory). <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO">The <i style="mso-bidi-font-style:normal">closedir</i>
function closes a previously opened directory. In case of an error it returns
the value -1.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO">The structure <i style="mso-bidi-font-style:normal">dirent</i>
is defined in the <i style="mso-bidi-font-style:normal">dirent.h</i> file. It
contains at least two elements:<o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">struct dirent { <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">ino_t d_fileno;<span style="mso-spacerun:yes">&nbsp; </span><span style="mso-tab-count:3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>// i-node nr.<span style="mso-spacerun:yes">&nbsp; </span><o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">char d_name[MAXNAMLEN + 1]; <span style="mso-tab-count:1">&nbsp; </span>// file
name<o:p></o:p></span></p>

<p class="MsoNormal" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO">}<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h1 style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo4;
tab-stops:list 18.0pt"><!--[if !supportLists]--><span style="font-size:14.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]--><span style="font-size:14.0pt">Examples<o:p></o:p></span></h1>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">5.1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">Example 1<o:p></o:p></span></h3>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">Write
a program that creates a file with a 4K bytes free space. Such files are called
files with holes.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/types.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/stat.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;fcntl.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;unistd.h&gt;<o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">char buf1[]="LAB "; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">char
buf2[]="OS Linux"; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">int main( void) <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">{ <span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">int fd; <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">if ((fd=creat("file.gol", 0666)) &lt; 0) </span><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">{<o:p></o:p></span></p>

<p class="Code" style="margin-left:72.0pt;text-indent:36.0pt"><span style="mso-fareast-language:RO" lang="RO">perror("Creation error"); <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit (1);<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">}<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">if (write(fd, buf1, sizeof(buf1)) &lt; 0) <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror("Writing
error"); <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(2);
<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">}<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">if (lseek(fd, 4096, SEEK_SET) &lt; 0) <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror("Positioning
error"); <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(3);
<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">}<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">if (write(fd, buf2, sizeof(buf2)) &lt; 0) <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror("Writing
error"); <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(2);
<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">}<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">}<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt">Trace the execution of the
program with the help of the following commands:<o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">ls -l <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:36.0pt;text-align:justify"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO;mso-no-proof:yes" lang="RO">stat file.gol<o:p></o:p></span></p>

<p class="MsoNormal" style="text-indent:36.0pt;tab-stops:150.0pt"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO">od -c file.gol<span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>

<p class="MsoNormal" style="text-indent:36.0pt;tab-stops:150.0pt"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="text-indent:36.0pt;tab-stops:150.0pt"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">5.2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">Example 2<o:p></o:p></span></h3>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">Write
a program that copies the contents of an existing file into another file. The
names of the two file should be read as an input from the command line. You may
presume that any of the commands <i style="mso-bidi-font-style:normal">read</i>
or <i style="mso-bidi-font-style:normal">write</i> may cause errors.<o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">#include
&lt;sys/types.h&gt;<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">#include
&lt;sys/uio.h&gt;<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">#include
&lt;unistd.h&gt;<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">#include
&lt;fcntl.h&gt;<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">#define
BUFSIZE 512 <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">int
main (int argc, char** argv)<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">{ <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO">int from, to, nr, nw, n; <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO">char buf[BUFSIZE];<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;</span><o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO">if ((from=open(argv[1], O_RDONLY)) &lt; 0) {<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror(Error
opening source file);<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(1);<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;</span><o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp; </span>if
((to=creat(argv[2], 0666)) &lt; 0) { <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror("Error
creating destination file");<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(2);<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}<span style="mso-spacerun:yes">&nbsp; </span><o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO">while((nr=read(from, buf, sizeof( buf))) != 0) { <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;</span>if (nr &lt; 0) { <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;</span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>perror("Error reading source file");<o:p></o:p></span></p>

<p class="Code" style="margin-left:72.0pt"><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(3);<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp; </span>} <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;</span>nw=0; <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;</span>do { <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if ((n=write(to, &amp;buf[nw],
nr-nw)) &lt; 0) {<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror("Error
writing destination file"); <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(4);<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;
</span>}<o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;</span>nw += n; <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span><span style="mso-tab-count:1">&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;</span>} while (nw &lt; nr); <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp; </span>} <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO"><span style="mso-spacerun:yes">&nbsp; </span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp; </span>close(from);
close(to); <o:p></o:p></span></p>

<p class="Code"><span style="mso-ansi-language:EN-US;mso-fareast-language:RO">}</span><span style="mso-fareast-language:RO" lang="RO"><o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<h3 style="margin-left:39.6pt;text-indent:-21.6pt;mso-list:l0 level2 lfo4;
tab-stops:list 39.6pt"><!--[if !supportLists]--><span style="font-size:12.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">5.3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]--><span style="font-size:12.0pt">Example 3<o:p></o:p></span></h3>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">Write
a program that displays the contents of a directory, specifying the type for
each of its files. The name for the directory should be an input parameter.<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">#include &lt;sys/types.h&gt;</span></p>

<p class="Code"><span lang="RO">#include &lt;sys/stat.h&gt;</span></p>

<p class="Code"><span lang="RO">#include &lt;dirent.h&gt;</span></p>

<p class="Code" style="margin-top:3.0pt"><span lang="RO">void listDir(char
*dirName)</span></p>

<p class="Code"><span lang="RO">{</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span>DIR* dir;</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span>struct
dirent *dirEntry;</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span>struct
stat inode;</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span>char
name[1000];</span></p>

<p class="Code" style="margin-top:3.0pt"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp; </span>dir = opendir(dirName);</span></p>

<p class="Code" style="text-indent:20.7pt"><span lang="RO">if (dir == 0) {</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>perror
("Eroare deschidere fisier");</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(1);</span></p>

<p class="Code" style="text-indent:20.7pt"><span lang="RO">}</span></p>

<p class="Code" style="margin-top:3.0pt;text-indent:20.7pt"><span lang="RO">while
((dirEntry=readdir(dir)) != 0) {</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>sprintf(name,"%s/%s",dirName,dirEntry-&gt;d_name);<span style="mso-spacerun:yes">&nbsp; </span></span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>lstat
(name, &amp;inode);</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;</span>// test the type of file</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if
(S_ISDIR(inode.st_mode))</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>printf("dir ");</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>else if
(S_ISREG(inode.st_mode))</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>printf
("fis ");</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp; </span>else</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>if (S_ISLNK(inode.st_mode))<span style="mso-tab-count:1"> </span></span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>printf ("lnk ");</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>else;</span></p>

<p class="Code" style="margin-top:3.0pt"><span lang="RO"><span style="mso-tab-count:
1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>printf(" %s\n", dirEntry-&gt;d_name);</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>}</span></p>

<p class="Code"><span lang="RO">}</span></p>

<p class="Code"><span lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span lang="RO">int main(int argc, char **argv)</span></p>

<p class="Code"><span lang="RO">{</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>if (argc
!= 2) {</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>printf
("UTILIZARE: %s nume_dir\n", argv[0]);</span></p>

<p class="Code"><span lang="RO"><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>exit(0);</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp; </span>}</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;
</span>printf(\94Continutul directorului este:</span><span style="mso-ansi-language:
EN-US">\n</span><span lang="RO">\94);</span></p>

<p class="Code"><span lang="RO"><span style="mso-spacerun:yes">&nbsp;&nbsp;&nbsp;
</span>listDir(argv[1]);</span></p>

<p class="Code"><span lang="RO">}</span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>


<!--
<h1 style="margin-left:18.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo4;
tab-stops:list 18.0pt"><!--[if !supportLists]-->
<!--
<span style="font-size:14.0pt;
mso-fareast-font-family:Arial"><span style="mso-list:Ignore">6.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:14.0pt">Problems<o:p></o:p></span></h1>

<p class="MsoNormal"><span style="font-size:12.0pt"><o:p>&nbsp;</o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt">


<!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Determine the size of a file using the <i style="mso-bidi-font-style:normal">lseek</i> command. Once you found out the
size, calculate the number of blocks assigned for the file. Compare these
results with the similar results obtained when using the function <i style="mso-bidi-font-style:normal">stat</i>.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Modify the 1<sup>st</sup> problem and see whether when
creating a file with large holes (hundreds of MB or GB) does the OS allocate
space on the HDD for the holes in the file, too, or not. For this you can use
the commands <i style="mso-bidi-font-style:normal">stat</i> and <span class="SpellE"><span class="GramE"><i style="mso-bidi-font-style:normal">df</i></span></span>.
Find out what value does a read operation return when reading from such a zone.
<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a C program that writes the lines of a file into
another file, but in the reverse order. The names of the files should be read
as input parameters.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--

<span style="font-size:12.0pt"><span style="mso-list:Ignore">4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--

<span style="font-size:12.0pt">Write a program that reads the characters located to
offset 0, 20, 40, 60 \85 in an existing text file and appends them to the end of
the file. Print out the size of the file before and after all append operations.
<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Using <span class="SpellE"><i style="mso-bidi-font-style:
normal">lseek</i></span> system call, find out if you can read from and write to
any position in a file opened for reading and writing with O_APPEND. Write a
program that when you launch N times in the background, writes the ID of the
current process in a file. Neither of the programs can continue their execution
until all the processes haven\92t written their ID in the file. In the end all
processes should print out the ID of the following process. Consider N as a
known value.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">6.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a program that would allow the user to insert a
string (read from the standard input) into a file from a certain position. The
program call should have the following format: </span><span style="font-family:
&quot;Courier New&quot;;mso-no-proof:yes">insert file offset string.</span><span style="font-size:12.0pt"><o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->


<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">7.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Consider the following program:<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/types.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;sys/stat.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">#include
&lt;fcntl.h&gt; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">void main( void) <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">{ <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">if (open("temp", O_RDWR) &lt; 0) <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO"><span style="mso-spacerun:yes">&nbsp;</span><span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun:yes">&nbsp; </span></span><span style="mso-ansi-language:EN-US;
mso-fareast-language:RO">{ </span><span style="mso-fareast-language:
RO" lang="RO">perror("open"); exit(1); }<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO"><o:p>&nbsp;</o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">if (unlink("temp") &lt; 0) <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO"><span style="mso-spacerun:yes">&nbsp; </span>{ perror("unlink");
exit(2); }<o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">printf("Unlink done!\n"); <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">sleep(15); <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">printf("END.\n"); <o:p></o:p></span></p>

<p class="Code" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO" lang="RO">exit(0); <o:p></o:p></span></p>

<p class="MsoNormal" style="text-indent:36.0pt"><span style="mso-fareast-language:
RO">}<span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt;
mso-fareast-language:RO">Assuming that the file <b style="mso-bidi-font-weight:
normal">temp</b> exists and that the program is launched in the background
explain the result of the following commands:<o:p></o:p></span></p>

<p class="Code" style="margin-top:3.0pt"><span style="mso-fareast-language:
RO" lang="RO">ls -l temp; df /home; a.out &amp; <o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">$ ls -l temp; df
/home; <span style="mso-tab-count:1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span># dup&#259; terminarea progr.
<o:p></o:p></span></p>

<p class="Code"><span style="mso-fareast-language:RO" lang="RO">$ df /home <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">What
conclusions can be made concerning the system call <i style="mso-bidi-font-style:
normal">unlink</i>?<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">8.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a C program that deletes a directory with all
its subfolders. The name of the directory should be read from the command line.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">9.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a program that deletes every 5<sup>th</sup> byte
from a file, but without using a temporary file or allocating a buffer in the
memory. For adjusting the size of the file you may use the <i style="mso-bidi-font-style:
normal">truncate</i> function.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">10.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a C program that finds a file in a file-tree
starting from a given directory. The name of the file for which we are
searching for, as well as the name of the starting directory should be read
from the command line. Optionally, the name of the file can be specified as a pattern
using the \91*\92 character.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->

<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">11.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a C program similar to the previous one, but
this time try to find a string in the files.<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->
<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">12.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]-->
<!--
<span style="font-size:12.0pt">Write a program having the name <i style="mso-bidi-font-style:
normal">move</i>, similar with the Linux command <i style="mso-bidi-font-style:
normal">mv</i>. The user should be able to call the program in any of the
following ways:<o:p></o:p></span></p>

<p class="MsoNormal" style="margin-top:3.0pt;margin-right:0cm;margin-bottom:0cm;
margin-left:36.0pt;margin-bottom:.0001pt;text-align:justify"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-no-proof:yes" lang="RO">move numeFisOld numeFisNew <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:36.0pt;text-align:justify"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:&quot;MS Mincho&quot;;
mso-ansi-language:RO;mso-no-proof:yes" lang="RO">move numeFis numeDir <o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
18.0pt"><span style="font-family:&quot;Courier New&quot;;mso-fareast-font-family:
&quot;MS Mincho&quot;;mso-ansi-language:RO" lang="RO">move numeDirOld numeDirNew</span><span style="font-family:&quot;Courier New&quot;"><o:p></o:p></span></p>

<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->
<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">13.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">Write a program that would allow traversing a
file-tree printing out the type, size and access rights for of the found files.
The name of the starting directory should be read from the command line. <i style="mso-bidi-font-style:normal">Observation: be attentive to the symbolic
links.</i> <span style="mso-spacerun:yes">&nbsp;</span><o:p></o:p></span></p>



<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->
<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">14.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">A binary file <i style="mso-bidi-font-style:normal">fil.bin</i>
contains integers. Calculate the arithmetic mean of each group of numbers that
are situated between two 0s in the file. Write these obtained values on
distinct lines in the file <i style="mso-bidi-font-style:normal">means.txt</i>.
The beginning and the end of the file plays the role of a 0, except the case
when the first and last element of the file is 0. <o:p></o:p></span></p>


<p class="MsoNormal" style="margin-left:18.0pt;text-align:justify;text-indent:
-18.0pt;mso-list:l6 level1 lfo6;tab-stops:list 18.0pt"><!--[if !supportLists]-->
<!--
<span style="font-size:12.0pt"><span style="mso-list:Ignore">15.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span></span><!--[endif]-->

<!--
<span style="font-size:12.0pt">A binary file <i style="mso-bidi-font-style:normal">fil.bin</i>
contains numbers and characters in the following way: 2 integers followed by a
character from the set {+,-,*<span class="GramE">,/</span>}. Write a C program
that reads a group of numbers and the attached character and performs the
operation on the two integers and then writes the result in a file <i style="mso-bidi-font-style:normal">res.txt</i> in the form: <o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify;text-indent:36.0pt"><span style="font-family:&quot;Courier New&quot;">nr1 operator nr2 = result<o:p></o:p></span></p>

<p class="MsoNormal" style="text-align:justify"><span style="font-size:12.0pt">The
result line should be appended to the end of the file. The number of groups in
the binary file should be specified in the command line as an input parameter. <o:p></o:p></span></p>

<p class="MsoNormal"><span style="font-size:12.0pt"><span style="mso-spacerun:yes">&nbsp;</span><o:p></o:p></span></p>

</div>
-->


</body></html>