24.01.2014 Views

Codice

Codice

Codice

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

240 volume VI os16<br />

Script e sorgenti del kernel 241<br />

«<br />

«<br />

910115 | for (m = 0; m < SB_MAP_ZONE_SIZE; m++) //<br />

910116 | { // Reset map in memory,<br />

910117 | sb->map_zone[m] = 0xFFFF; // before loading.<br />

910118 | } //<br />

910119 | size_map = sb->map_zone_blocks * 1024;<br />

910120 | size_read = dev_io ((pid_t) -1, sb->device, DEV_READ, start,<br />

910121 | sb->map_zone, size_map, NULL);<br />

910122 | if (size_read != size_map)<br />

910123 | {<br />

910124 | errset (EIO); // I/O error.<br />

910125 | return (NULL);<br />

910126 | }<br />

910127 | //<br />

910128 | // Check the inode that should mount the super block. If<br />

910129 | // ‘*inode_mnt’ is ‘NULL’, then it is meant to be the first mount of<br />

910130 | // the root file system. In such case, the inode must be loaded too,<br />

910131 | // and the value for ‘*inode_mnt’ must be modified.<br />

910132 | //<br />

910133 | if (*inode_mnt == NULL)<br />

910134 | {<br />

910135 | *inode_mnt = inode_get (device, 1);<br />

910136 | }<br />

910137 | //<br />

910138 | // Check for a valid value.<br />

910139 | //<br />

910140 | if (*inode_mnt == NULL)<br />

910141 | {<br />

910142 | //<br />

910143 | // This is bad!<br />

910144 | //<br />

910145 | errset (EUNKNOWN); // Unknown error.<br />

910146 | return (NULL);<br />

910147 | }<br />

910148 | //<br />

910149 | // A valid inode is available for the mount.<br />

910150 | //<br />

910151 | (*inode_mnt)->sb_attached = sb;<br />

910152 | //<br />

910153 | // Return the super block pointer.<br />

910154 | //<br />

910155 | return (sb);<br />

910156 |}<br />

104.4.49 kernel/fs/sb_reference.c<br />

Si veda la sezione 103.3.47.<br />

920001 |#include <br />

920002 |#include <br />

920003 |//----------------------------------------------------------------------<br />

920004 |sb_t *<br />

920005 |sb_reference (dev_t device)<br />

920006 |{<br />

920007 | int s; // Slot index.<br />

920008 | //<br />

920009 | // If device is zero, a reference to the whole table is returned.<br />

920010 | //<br />

920011 | if (device == 0)<br />

920012 | {<br />

920013 | return (sb_table);<br />

920014 | }<br />

920015 | //<br />

920016 | // If device is ((dev_t) -1), a reference to a free slot is<br />

920017 | // returned.<br />

920018 | //<br />

920019 | if (device == ((dev_t) -1))<br />

920020 | {<br />

920021 | for (s = 0; s < SB_MAX_SLOTS; s++)<br />

920022 | {<br />

920023 | if (sb_table[s].device == 0)<br />

920024 | {<br />

920025 | return (&sb_table[s]);<br />

920026 | }<br />

920027 | }<br />

920028 | return (NULL);<br />

920029 | }<br />

920030 | //<br />

920031 | // A device was selected: find the super block associated to it.<br />

920032 | //<br />

920033 | for (s = 0; s < SB_MAX_SLOTS; s++)<br />

920034 | {<br />

920035 | if (sb_table[s].device == device)<br />

920036 | {<br />

920037 | return (&sb_table[s]);<br />

920038 | }<br />

920039 | }<br />

920040 | //<br />

920041 | // The super block was not found.<br />

920042 | //<br />

920043 | return (NULL);<br />

920044 |}<br />

104.4.50 kernel/fs/sb_save.c<br />

Si veda la sezione 103.3.48.<br />

930001 |#include <br />

930002 |#include <br />

930003 |#include <br />

930004 |//----------------------------------------------------------------------<br />

930005 |int<br />

930006 |sb_save (sb_t *sb)<br />

930007 |{<br />

930008 | ssize_t size_written;<br />

930009 | addr_t start;<br />

930010 | size_t size_map;<br />

930011 | //<br />

930012 | // Check for valid argument.<br />

930013 | //<br />

930014 | if (sb == NULL)<br />

930015 | {<br />

930016 | errset (EINVAL); // Invalid argument.<br />

930017 | return (-1);<br />

930018 | }<br />

930019 | //<br />

930020 | // Check if the super block changed for some reason (only the<br />

930021 | // inode and the zone maps can change really).<br />

930022 | //<br />

930023 | if (!sb->changed)<br />

930024 | {<br />

930025 | //<br />

930026 | // Nothing to save.<br />

930027 | //<br />

930028 | return (0);<br />

930029 | }<br />

930030 | //<br />

930031 | // Something inside the super block changed: start the procedure to<br />

930032 | // save the inode map (recall that the super block header is not<br />

930033 | // saved, because it never changes).<br />

930034 | //<br />

930035 | start = 1024; // After boot block.<br />

930036 | start += 1024; // After super block.<br />

930037 | size_map = sb->map_inode_blocks * 1024;<br />

930038 | size_written = dev_io ((pid_t) -1, sb->device, DEV_WRITE, start,<br />

930039 | sb->map_inode, size_map, NULL);<br />

930040 | if (size_written != size_map)<br />

930041 | {<br />

930042 | //<br />

930043 | // Error writing the map.<br />

930044 | //<br />

930045 | errset (EIO); // I/O error.<br />

930046 | return (-1);<br />

930047 | }<br />

930048 | //<br />

930049 | // Start the procedure to save the zone map.<br />

930050 | //<br />

930051 | start = 1024; // After boot block.<br />

930052 | start += 1024; // After super block.<br />

930053 | start += (sb->map_inode_blocks * 1024); // After inode bit map.<br />

930054 | size_map = sb->map_zone_blocks * 1024;<br />

930055 | size_written = dev_io ((pid_t) -1, sb->device, DEV_WRITE, start,<br />

930056 | sb->map_zone, size_map, NULL);<br />

930057 | if (size_written != size_map)<br />

930058 | {<br />

930059 | //<br />

930060 | // Error writing the map.<br />

930061 | //<br />

930062 | errset (EIO); // I/O error.<br />

930063 | return (-1);<br />

930064 | }<br />

930065 | //<br />

930066 | // Super block saved.<br />

930067 | //<br />

930068 | sb->changed = 0;<br />

930069 | //<br />

930070 | return (0);<br />

930071 |}<br />

104.4.51 kernel/fs/sb_table.c<br />

Si veda la sezione 103.3.47.<br />

940001 |#include <br />

940002 |//----------------------------------------------------------------------<br />

940003 |sb_t sb_table[SB_MAX_SLOTS];<br />

104.4.52 kernel/fs/sb_zone_status.c<br />

Si veda la sezione 103.3.45.<br />

950001 |#include <br />

950002 |#include <br />

950003 |//----------------------------------------------------------------------<br />

950004 |int<br />

950005 |sb_zone_status (sb_t *sb, zno_t zone)<br />

950006 |{<br />

950007 | int map_element;<br />

950008 | int map_bit;<br />

950009 | int map_mask;<br />

950010 | //<br />

950011 | // Check arguments.<br />

950012 | //<br />

950013 | if (zone == 0 || sb == NULL)<br />

950014 | {<br />

950015 | errset (EINVAL); // Invalid argument.<br />

950016 | return (-1);<br />

950017 | }<br />

950018 | //<br />

950019 | // Calculate the map element, the map bit and the map mask.<br />

950020 | //<br />

950021 | map_element = zone / 16;<br />

950022 | map_bit = zone % 16;<br />

950023 | map_mask = 1 map_zone[map_element] & map_mask)<br />

950028 | {<br />

950029 | return (1); // True.<br />

950030 | }<br />

950031 | else<br />

950032 | {<br />

950033 | return (0); // False.<br />

950034 | }<br />

950035 |}<br />

104.4.53 kernel/fs/zone_alloc.c<br />

Si veda la sezione 103.3.51.<br />

960001 |#include <br />

960002 |#include <br />

960003 |#include <br />

960004 |//----------------------------------------------------------------------<br />

960005 |zno_t<br />

960006 |zone_alloc (sb_t *sb)<br />

960007 |{<br />

«<br />

«<br />

«

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!