Fork me on GitHub

root/kernel/syscalls/mkdir.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_mkdir

   1 /*
   2  * fiwix/kernel/syscalls/mkdir.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/types.h>
   9 #include <fiwix/fs.h>
  10 #include <fiwix/stat.h>
  11 #include <fiwix/errno.h>
  12 #include <fiwix/string.h>
  13 
  14 #ifdef __DEBUG__
  15 #include <fiwix/stdio.h>
  16 #include <fiwix/process.h>
  17 #endif /*__DEBUG__ */
  18 
  19 int sys_mkdir(const char *dirname, __mode_t mode)
  20 {
  21         struct inode *i, *dir;
  22         char *tmp_dirname, *basename;
  23         int errno;
  24 
  25 #ifdef __DEBUG__
  26         printk("(pid %d) sys_mkdir('%s', %o)\n", current->pid, dirname, mode);
  27 #endif /*__DEBUG__ */
  28 
  29         if((errno = malloc_name(dirname, &tmp_dirname)) < 0) {
  30                 return errno;
  31         }
  32         basename = remove_trailing_slash(tmp_dirname);
  33         if((errno = namei(basename, &i, &dir, !FOLLOW_LINKS))) {
  34                 if(!dir) {
  35                         free_name(tmp_dirname);
  36                         return errno;
  37                 }
  38         }
  39         if(!errno) {
  40                 iput(i);
  41                 iput(dir);
  42                 free_name(tmp_dirname);
  43                 return -EEXIST;
  44         }
  45         if(IS_RDONLY_FS(dir)) {
  46                 iput(dir);
  47                 free_name(tmp_dirname);
  48                 return -EROFS;
  49         }
  50 
  51         if(check_permission(TO_EXEC | TO_WRITE, dir) < 0) {
  52                 iput(dir);
  53                 free_name(tmp_dirname);
  54                 return -EACCES;
  55         }
  56 
  57         basename = get_basename(basename);
  58         if(dir->fsop && dir->fsop->mkdir) {
  59                 errno = dir->fsop->mkdir(dir, basename, mode);
  60         } else {
  61                 errno = -EPERM;
  62         }
  63         iput(dir);
  64         free_name(tmp_dirname);
  65         return errno;
  66 }

/* [previous][next][first][last][top][bottom][index][help] */