You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
«<br />
«<br />
«<br />
226 volume VI os16<br />
104.4.34 kernel/fs/path_chown.c<br />
Si veda la sezione 103.3.32.<br />
770001 |#include <br />
770002 |#include <br />
770003 |#include <br />
770004 |//----------------------------------------------------------------------<br />
770005 |int<br />
770006 |path_chown (pid_t pid, const char *path, uid_t uid, gid_t gid)<br />
770007 |{<br />
770008 | proc_t *ps;<br />
770009 | inode_t *inode;<br />
770010 | //<br />
770011 | // Get process.<br />
770012 | //<br />
770013 | ps = proc_reference (pid);<br />
770014 | //<br />
770015 | // Must be root, as the ability to change group is not considered.<br />
770016 | //<br />
770017 | if (ps->euid != 0)<br />
770018 | {<br />
770019 | errset (EPERM); // Operation not permitted.<br />
770020 | return (-1);<br />
770021 | }<br />
770022 | //<br />
770023 | // Try to load the file inode.<br />
770024 | //<br />
770025 | inode = path_inode (pid, path);<br />
770026 | if (inode == NULL)<br />
770027 | {<br />
770028 | //<br />
770029 | // Cannot access the file: it does not exists or permissions are<br />
770030 | // not sufficient. Variable ‘errno’ is set by function<br />
770031 | // ‘inode_directory()’.<br />
770032 | //<br />
770033 | return (-1);<br />
770034 | }<br />
770035 | //<br />
770036 | // Update the owner and group.<br />
770037 | //<br />
770038 | if (uid != -1)<br />
770039 | {<br />
770040 | inode->uid = uid;<br />
770041 | inode->changed = 1;<br />
770042 | }<br />
770043 | if (gid != -1)<br />
770044 | {<br />
770045 | inode->gid = gid;<br />
770046 | inode->changed = 1;<br />
770047 | }<br />
770048 | //<br />
770049 | // Save and release the inode.<br />
770050 | //<br />
770051 | inode_save (inode);<br />
770052 | inode_put (inode);<br />
770053 | //<br />
770054 | // Return.<br />
770055 | //<br />
770056 | return (0);<br />
770057 |}<br />
104.4.35 kernel/fs/path_device.c<br />
Si veda la sezione 103.3.33.<br />
780001 |#include <br />
780002 |#include <br />
780003 |#include <br />
780004 |//----------------------------------------------------------------------<br />
780005 |dev_t<br />
780006 |path_device (pid_t pid, const char *path)<br />
780007 |{<br />
780008 | proc_t *ps;<br />
780009 | inode_t *inode;<br />
780010 | dev_t device;<br />
780011 | //<br />
780012 | // Get process.<br />
780013 | //<br />
780014 | ps = proc_reference (pid);<br />
780015 | //<br />
780016 | inode = path_inode (pid, path);<br />
780017 | if (inode == NULL)<br />
780018 | {<br />
780019 | errset (errno);<br />
780020 | return ((dev_t) -1);<br />
780021 | }<br />
780022 | //<br />
780023 | if (!(S_ISBLK (inode->mode) || S_ISCHR (inode->mode)))<br />
780024 | {<br />
780025 | errset (ENODEV); // No such device.<br />
780026 | inode_put (inode);<br />
780027 | return ((dev_t) -1);<br />
780028 | }<br />
780029 | //<br />
780030 | device = inode->direct[0];<br />
780031 | inode_put (inode);<br />
780032 | return (device);<br />
780033 |}<br />
104.4.36 kernel/fs/path_fix.c<br />
Si veda la sezione 103.3.34.<br />
790001 |#include <br />
790002 |#include <br />
790003 |#include <br />
790004 |//----------------------------------------------------------------------<br />
790005 |int<br />
790006 |path_fix (char *path)<br />
790007 |{<br />
790008 | char new_path[PATH_MAX];<br />
790009 | char *token[PATH_MAX/4];<br />
790010 | int t; // Token index.<br />
790011 | int token_size; // Token array effective size.<br />
Script e sorgenti del kernel 227<br />
790012 | int comp; // String compare return value.<br />
790013 | size_t path_size; // Path string size.<br />
790014 | //<br />
790015 | // Initialize token search.<br />
790016 | //<br />
790017 | token[0] = strtok (path, "/");<br />
790018 | //<br />
790019 | // Scan tokens.<br />
790020 | //<br />
790021 | for (t = 0;<br />
790022 | t < PATH_MAX/4 && token[t] != NULL;<br />
790023 | t++, token[t] = strtok (NULL, "/"))<br />
790024 | {<br />
790025 | //<br />
790026 | // If current token is ‘.’, just ignore it.<br />
790027 | //<br />
790028 | comp = strcmp (token[t], ".");<br />
790029 | if (comp == 0)<br />
790030 | {<br />
790031 | t--;<br />
790032 | }<br />
790033 | //<br />
790034 | // If current token is ‘..’, remove previous token,<br />
790035 | // if there is one.<br />
790036 | //<br />
790037 | comp = strcmp (token[t], "..");<br />
790038 | if (comp == 0)<br />
790039 | {<br />
790040 | if (t > 0)<br />
790041 | {<br />
790042 | t -= 2;<br />
790043 | }<br />
790044 | else<br />
790045 | {<br />
790046 | t = -1;<br />
790047 | }<br />
790048 | }<br />
790049 | //<br />
790050 | // ‘t’ will be incremented and another token will be<br />
790051 | // found.<br />
790052 | //<br />
790053 | }<br />
790054 | //<br />
790055 | // Save the token array effective size.<br />
790056 | //<br />
790057 | token_size = t;<br />
790058 | //<br />
790059 | // Initialize the new path string.<br />
790060 | //<br />
790061 | new_path[0] = ’\0’;<br />
790062 | //<br />
790063 | // Build the new path string.<br />
790064 | //<br />
790065 | if (token_size > 0)<br />
790066 | {<br />
790067 | for (t = 0; t < token_size; t++)<br />
790068 | {<br />
790069 | path_size = strlen (new_path);<br />
790070 | strncat (new_path, "/", 2);<br />
790071 | strncat (new_path, token[t], PATH_MAX - path_size - 1);<br />
790072 | }<br />
790073 | }<br />
790074 | else<br />
790075 | {<br />
790076 | strncat (new_path, "/", 2);<br />
790077 | }<br />
790078 | //<br />
790079 | // Copy the new path into the original string.<br />
790080 | //<br />
790081 | strncpy (path, new_path, PATH_MAX);<br />
790082 | //<br />
790083 | // Return.<br />
790084 | //<br />
790085 | return (0);<br />
790086 |}<br />
104.4.37 kernel/fs/path_full.c<br />
Si veda la sezione 103.3.35.<br />
800001 |#include <br />
800002 |#include <br />
800003 |#include <br />
800004 |//----------------------------------------------------------------------<br />
800005 |int<br />
800006 |path_full (const char *path, const char *path_cwd, char *full_path)<br />
800007 |{<br />
800008 | unsigned int path_size;<br />
800009 | //<br />
800010 | // Check some arguments.<br />
800011 | //<br />
800012 | if (path == NULL || strlen (path) == 0 || full_path == NULL)<br />
800013 | {<br />
800014 | errset (EINVAL); // Invalid argument.<br />
800015 | return (-1);<br />
800016 | }<br />
800017 | //<br />
800018 | // The main path and the receiving one are right.<br />
800019 | // Now arrange to get a full path name.<br />
800020 | //<br />
800021 | if (path[0] == ’/’)<br />
800022 | {<br />
800023 | strncpy (full_path, path, PATH_MAX);<br />
800024 | full_path[PATH_MAX-1] = 0;<br />
800025 | }<br />
800026 | else<br />
800027 | {<br />
800028 | if (path_cwd == NULL || strlen (path_cwd) == 0)<br />
800029 | {<br />
800030 | errset (EINVAL); // Invalid argument.<br />
800031 | return (-1);<br />
800032 | }<br />
800033 | strncpy (full_path, path_cwd, PATH_MAX);<br />
800034 | path_size = strlen (full_path);<br />
800035 | strncat (full_path, "/", (PATH_MAX - path_size));<br />
800036 | path_size = strlen (full_path);<br />
«