Fork me on GitHub

root/kernel/syscalls/rmdir.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_rmdir

   1 /*
   2  * fiwix/kernel/syscalls/rmdir.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/fs.h>
   9 #include <fiwix/stat.h>
  10 #include <fiwix/errno.h>
  11 
  12 #ifdef __DEBUG__
  13 #include <fiwix/stdio.h>
  14 #include <fiwix/process.h>
  15 #endif /*__DEBUG__ */
  16 
  17 int sys_rmdir(const char *dirname)
  18 {
  19         struct inode *i, *dir;
  20         char *tmp_dirname;
  21         int errno;
  22 
  23 #ifdef __DEBUG__
  24         printk("(pid %d) sys_rmdir(%s)\n", current->pid, dirname);
  25 #endif /*__DEBUG__ */
  26 
  27         if((errno = malloc_name(dirname, &tmp_dirname)) < 0) {
  28                 return errno;
  29         }
  30         if((errno = namei(tmp_dirname, &i, &dir, !FOLLOW_LINKS))) {
  31                 if(dir) {
  32                         iput(dir);
  33                 }
  34                 free_name(tmp_dirname);
  35                 return errno;
  36         }
  37         if(!S_ISDIR(i->i_mode)) {
  38                 iput(i);
  39                 iput(dir);
  40                 free_name(tmp_dirname);
  41                 return -ENOTDIR;
  42         }
  43         if(i == current->root || i->mount_point || i->count > 1) {
  44                 iput(i);
  45                 iput(dir);
  46                 free_name(tmp_dirname);
  47                 return -EBUSY;
  48         }
  49         if(IS_RDONLY_FS(i)) {
  50                 iput(i);
  51                 iput(dir);
  52                 free_name(tmp_dirname);
  53                 return -EROFS;
  54         }
  55         if(i == dir) {
  56                 iput(i);
  57                 iput(dir);
  58                 free_name(tmp_dirname);
  59                 return -EPERM;
  60         }
  61         if(check_permission(TO_EXEC | TO_WRITE, dir) < 0) {
  62                 iput(i);
  63                 iput(dir);
  64                 free_name(tmp_dirname);
  65                 return -EACCES;
  66         }
  67 
  68         /* check sticky permission bit */
  69         if(dir->i_mode & S_ISVTX) {
  70                 if(check_user_permission(i)) {
  71                         iput(i);
  72                         iput(dir);
  73                         free_name(tmp_dirname);
  74                         return -EPERM;
  75                 }
  76         }
  77 
  78         if(i->fsop && i->fsop->rmdir) {
  79                 errno = i->fsop->rmdir(dir, i);
  80         } else {
  81                 errno = -EPERM;
  82         }
  83         iput(i);
  84         iput(dir);
  85         free_name(tmp_dirname);
  86         return errno;
  87 }

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