You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
212 volume VI os16<br />
Script e sorgenti del kernel 213<br />
«<br />
610031 | NULL);<br />
610032 | if (size_read < sizeof (directory_t))<br />
610033 | {<br />
610034 | break;<br />
610035 | }<br />
610036 | //<br />
610037 | // Scan the directory portion just read.<br />
610038 | //<br />
610039 | dir = (directory_t *) buffer;<br />
610040 | //<br />
610041 | for (d = 0; d < size_read; d += (sizeof (directory_t)), dir++)<br />
610042 | {<br />
610043 | if (dir->ino != 0 &&<br />
610044 | strncmp (dir->name, ".", NAME_MAX) != 0 &&<br />
610045 | strncmp (dir->name, "..", NAME_MAX) != 0)<br />
610046 | {<br />
610047 | //<br />
610048 | // There is an item and the directory is not empty.<br />
610049 | //<br />
610050 | return (0); // false<br />
610051 | }<br />
610052 | }<br />
610053 | }<br />
610054 | //<br />
610055 | // Nothing was found; good!<br />
610056 | //<br />
610057 | return (1); // true<br />
610058 |}<br />
104.4.19 kernel/fs/inode_file_read.c<br />
Si veda la sezione 103.3.18.<br />
620001 |#include <br />
620002 |#include <br />
620003 |#include <br />
620004 |//----------------------------------------------------------------------<br />
620005 |ssize_t<br />
620006 |inode_file_read (inode_t *inode, off_t offset,<br />
620007 | void *buffer, size_t count, int *eof)<br />
620008 |{<br />
620009 | unsigned char *destination = (unsigned char *) buffer;<br />
620010 | unsigned char zone_buffer[SB_MAX_ZONE_SIZE];<br />
620011 | blkcnt_t blkcnt_read;<br />
620012 | off_t off_fzone; // File zone offset.<br />
620013 | off_t off_buffer; // Destination buffer offset.<br />
620014 | ssize_t size_read; // Byte transfer counter.<br />
620015 | zno_t fzone;<br />
620016 | off_t off_end;<br />
620017 | //<br />
620018 | // The inode pointer must be valid, and<br />
620019 | // the start byte must be positive.<br />
620020 | //<br />
620021 | if (inode == NULL || offset < 0)<br />
620022 | {<br />
620023 | errset (EINVAL); // Invalid argument.<br />
620024 | return ((ssize_t) -1);<br />
620025 | }<br />
620026 | //<br />
620027 | // Check if the start address is inside the file size. This is not<br />
620028 | // an error, but zero bytes are read and ‘*eof’ is set. Otherwise,<br />
620029 | // ‘*eof’ is reset.<br />
620030 | //<br />
620031 | if (offset >= inode->size)<br />
620032 | {<br />
620033 | (eof != NULL)? *eof = 1: 0;<br />
620034 | return (0);<br />
620035 | }<br />
620036 | else<br />
620037 | {<br />
620038 | (eof != NULL)? *eof = 0: 0;<br />
620039 | }<br />
620040 | //<br />
620041 | // Adjust, if necessary, the size of read, because it cannot be<br />
620042 | // larger than the actual file size. The variable ‘off_end’ is<br />
620043 | // used to calculate the position *after* the requested read.<br />
620044 | // Remember that the first file position is byte zero; so,<br />
620045 | // the byte index inside the file goes from zero to inode->size -1.<br />
620046 | //<br />
620047 | off_end = offset;<br />
620048 | off_end += count;<br />
620049 | if (off_end > inode->size)<br />
620050 | {<br />
620051 | count = (inode->size - offset);<br />
620052 | }<br />
620053 | //<br />
620054 | // Read the first file-zone inside the zone buffer.<br />
620055 | //<br />
620056 | fzone = offset / inode->sb->blksize;<br />
620057 | off_fzone = offset % inode->sb->blksize;<br />
620058 | blkcnt_read = inode_fzones_read (inode, fzone, zone_buffer,<br />
620059 | (blkcnt_t) 1);<br />
620060 | if (blkcnt_read sb->blksize && count > 0;<br />
620085 | off_fzone++, off_buffer++, size_read++,<br />
620086 | count--, offset++)<br />
620087 | {<br />
620088 | destination[off_buffer] = zone_buffer[off_fzone];<br />
620089 | }<br />
620090 | //<br />
620091 | // If not all the bytes are copied, read the next file-zone.<br />
620092 | //<br />
620093 | if (count)<br />
620094 | {<br />
620095 | //<br />
620096 | // Read another file-zone inside the zone buffer.<br />
620097 | // Again, the function ‘inode_fzones_read()’ might<br />
620098 | // return a null pointer, but the variable ‘errno’ tells if<br />
620099 | // it is really an error. For this reason, the variable<br />
620100 | // ‘errno’ must be reset before the read, and checked after<br />
620101 | // it.<br />
620102 | //<br />
620103 | fzone = offset / inode->sb->blksize;<br />
620104 | off_fzone = offset % inode->sb->blksize;<br />
620105 | blkcnt_read = inode_fzones_read (inode, fzone, zone_buffer,<br />
620106 | (blkcnt_t) 1);<br />
620107 | if (blkcnt_read 0; size_written += size_copied)<br />
630034 | {<br />
630035 | //<br />
630036 | // Read the next file-zone inside the zone buffer: the function<br />
630037 | // ‘inode_zone()’ is used to create automatically the zone, if<br />
630038 | // it does not exist.<br />
630039 | //<br />
630040 | fzone = offset / inode->sb->blksize;<br />
630041 | off_fzone = offset % inode->sb->blksize;<br />
630042 | zone = inode_zone (inode, fzone, 1);<br />
630043 | if (zone == 0)<br />
630044 | {<br />
630045 | //<br />
630046 | // Return previously written bytes. The variable ‘errno’ is<br />
630047 | // already set by ‘inode_zone()’.<br />
630048 | //<br />
630049 | return (size_written);<br />
630050 | }<br />
630051 | blkcnt_read = inode_fzones_read (inode, fzone, buffer_zone,<br />
630052 | (blkcnt_t) 1);<br />
630053 | if (blkcnt_read sb->blksize && count > 0;<br />
630069 | off_fzone++, off_source++, size_copied++, count--,<br />
630070 | offset++)<br />
630071 | {<br />
630072 | buffer_zone[off_fzone] = buffer_source[off_source];<br />
630073 | }<br />
630074 | //<br />
«