Skip to content

Commit 4f3b4a0

Browse files
committed
Added contents to APUE chapter 4
1 parent d10a64f commit 4f3b4a0

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

docs/apue/ch4.md

+46
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,49 @@ Sticky Bit (`S_ISVTX`), or saved-text bit in the later versions of the UNIX Syst
8484
* On file: only on a minority of systems
8585
* On directory: `/tmp` and `/var/tmp`
8686

87+
### `chown`, `fchown`, `fchownat`, and `lchown` Functions
88+
89+
> [Functions](https://gist.github.com/shichao-an/233e97d9b3d15aca39b2)
90+
91+
* `lchown` and `fchownat` (with the `AT_SYMLINK_NOFOLLOW` flag set) change the owners of the symbolic link itself.
92+
* `fchown` operates on a open file, it can’t be used to change the ownership of a symbolic link.
93+
94+
Only the superuser can change the ownership of a file (FreeBSD 8.0, Linux 3.2.0, and Mac OS X 10.6.8)
95+
96+
When `_POSIX_CHOWN_RESTRICTED` is in effect, a non-superuser can’t change the user ID of your files; A nonsuperuser can change the group ID of files that he owns, but only to groups that he belongs to.
97+
98+
### File Size
99+
100+
The `st_size` member of the stat structure contains the size of the file in bytes. This field is meaningful only for regular files, directories, and symbolic links.
101+
102+
FreeBSD 8.0, Mac OS X 10.6.8, and Solaris 10 also define the file size for a pipe as the number of bytes that are available for reading from the pipe.
103+
104+
* For a regular file, a file size of 0 is allowed. We’ll get an end-of-file indication on the first read of the file.
105+
* For a directory, the file size is usually a multiple of a number, such as 16 or 512.
106+
* For a symbolic link, the file size is the number of bytes in the filename.
107+
108+
Most contemporary UNIX systems provide two fields:
109+
110+
* `st_blksize`: preferred block size for I/O for the file
111+
* `st_blocks`: actual number of 512-byte blocks that are allocated
112+
113+
Be aware that different versions of the UNIX System use units other than 512-byte blocks for `st_blocks`. Use of this value is **nonportable**.
114+
115+
### Holes in a File
116+
117+
```
118+
$ ls -l core
119+
-rw-r--r-- 1 sar 8483248 Nov 18 12:18 core
120+
$ du -s core
121+
272 core
122+
```
123+
124+
### File Truncation
125+
> [Functions](https://gist.github.com/shichao-an/df5f6cc1cd7871670b11)
126+
127+
These two functions truncate an existing file to *length* bytes. If the previous size of the file was greater than length, the data beyond length is no longer accessible. Otherwise, if the previous size was less than length, the file size will increase and the data between the old end of file and the new end of file will read as 0 (a hole is probably created in the file).
128+
129+
130+
### File Systems
131+
132+
Most UNIX file systems support **case-sensitive** filenames. On Mac OS X, however, the HFS file system is **case-preserving** with **case-insensitive** comparisons.

site/apue/ch4/index.html

+49-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@
179179

180180
<li><a href="#sticky-bit">Sticky Bit</a></li>
181181

182+
<li><a href="#chown-fchown-fchownat-and-lchown-functions">chown, fchown, fchownat, and lchown Functions</a></li>
183+
184+
<li><a href="#file-size">File Size</a></li>
185+
186+
<li><a href="#holes-in-a-file">Holes in a File</a></li>
187+
188+
<li><a href="#file-truncation">File Truncation</a></li>
189+
190+
<li><a href="#file-systems">File Systems</a></li>
191+
182192

183193
</ul>
184194
</div></div>
@@ -259,7 +269,45 @@ <h3 id="sticky-bit">Sticky Bit</h3>
259269
<ul>
260270
<li>On file: only on a minority of systems</li>
261271
<li>On directory: <code>/tmp</code> and <code>/var/tmp</code></li>
262-
</ul></div>
272+
</ul>
273+
<h3 id="chown-fchown-fchownat-and-lchown-functions"><code>chown</code>, <code>fchown</code>, <code>fchownat</code>, and <code>lchown</code> Functions</h3>
274+
<blockquote>
275+
<p><a href="https://gist.github.com/shichao-an/233e97d9b3d15aca39b2">Functions</a></p>
276+
</blockquote>
277+
<ul>
278+
<li><code>lchown</code> and <code>fchownat</code> (with the <code>AT_SYMLINK_NOFOLLOW</code> flag set) change the owners of the symbolic link itself.</li>
279+
<li><code>fchown</code> operates on a open file, it can’t be used to change the ownership of a symbolic link.</li>
280+
</ul>
281+
<p>Only the superuser can change the ownership of a file (FreeBSD 8.0, Linux 3.2.0, and Mac OS X 10.6.8)</p>
282+
<p>When <code>_POSIX_CHOWN_RESTRICTED</code> is in effect, a non-superuser can’t change the user ID of your files; A nonsuperuser can change the group ID of files that he owns, but only to groups that he belongs to.</p>
283+
<h3 id="file-size">File Size</h3>
284+
<p>The <code>st_size</code> member of the stat structure contains the size of the file in bytes. This field is meaningful only for regular files, directories, and symbolic links.</p>
285+
<p>FreeBSD 8.0, Mac OS X 10.6.8, and Solaris 10 also define the file size for a pipe as the number of bytes that are available for reading from the pipe.</p>
286+
<ul>
287+
<li>For a regular file, a file size of 0 is allowed. We’ll get an end-of-file indication on the first read of the file. </li>
288+
<li>For a directory, the file size is usually a multiple of a number, such as 16 or 512.</li>
289+
<li>For a symbolic link, the file size is the number of bytes in the filename.</li>
290+
</ul>
291+
<p>Most contemporary UNIX systems provide two fields:</p>
292+
<ul>
293+
<li><code>st_blksize</code>: preferred block size for I/O for the file</li>
294+
<li><code>st_blocks</code>: actual number of 512-byte blocks that are allocated</li>
295+
</ul>
296+
<p>Be aware that different versions of the UNIX System use units other than 512-byte blocks for <code>st_blocks</code>. Use of this value is <strong>nonportable</strong>.</p>
297+
<h3 id="holes-in-a-file">Holes in a File</h3>
298+
<pre><code>$ ls -l core
299+
-rw-r--r-- 1 sar 8483248 Nov 18 12:18 core
300+
$ du -s core
301+
272 core
302+
</code></pre>
303+
304+
<h3 id="file-truncation">File Truncation</h3>
305+
<blockquote>
306+
<p><a href="https://gist.github.com/shichao-an/df5f6cc1cd7871670b11">Functions</a></p>
307+
</blockquote>
308+
<p>These two functions truncate an existing file to <em>length</em> bytes. If the previous size of the file was greater than length, the data beyond length is no longer accessible. Otherwise, if the previous size was less than length, the file size will increase and the data between the old end of file and the new end of file will read as 0 (a hole is probably created in the file).</p>
309+
<h3 id="file-systems">File Systems</h3>
310+
<p>Most UNIX file systems support <strong>case-sensitive</strong> filenames. On Mac OS X, however, the HFS file system is <strong>case-preserving</strong> with <strong>case-insensitive</strong> comparisons.</p></div>
263311
</div>
264312

265313

0 commit comments

Comments
 (0)