Changeset 3d4fd2c in mainline for uspace/srv/fs/ext4fs/ext4fs_ops.c


Ignore:
Timestamp:
2011-11-22T16:56:09Z (12 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
82d7816
Parents:
bf66ef4
Message:

deleting regular files (directories is not debugged)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/ext4fs/ext4fs_ops.c

    rbf66ef4 r3d4fd2c  
    382382int ext4fs_destroy_node(fs_node_t *fn)
    383383{
     384        int rc;
     385
     386        bool has_children;
     387        rc = ext4fs_has_children(&has_children, fn);
     388        if (rc != EOK) {
     389                ext4fs_node_put(fn);
     390                return rc;
     391        }
     392
     393        if (has_children) {
     394                EXT4FS_DBG("destroying non-empty node");
     395                ext4fs_node_put(fn);
     396                return EINVAL;
     397        }
     398
     399        ext4fs_node_t *enode = EXT4FS_NODE(fn);
     400        ext4_filesystem_t *fs = enode->instance->filesystem;
     401        ext4_inode_ref_t *inode_ref = enode->inode_ref;
     402
     403        EXT4FS_DBG("destroying \%u", inode_ref->index);
     404
     405        rc = ext4_filesystem_truncate_inode(fs, inode_ref, 0);
     406        if (rc != EOK) {
     407                ext4fs_node_put(fn);
     408                return rc;
     409        }
     410
     411        rc = ext4_filesystem_free_inode(fs, inode_ref);
     412        if (rc != EOK) {
     413                ext4fs_node_put(fn);
     414                return rc;
     415        }
     416
     417        ext4fs_node_put(fn);
     418        return EOK;
     419
     420//      EXT4FS_DBG("not supported");
     421//
     422//      // TODO
     423//      return ENOTSUP;
     424}
     425
     426
     427int ext4fs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
     428{
    384429        EXT4FS_DBG("not supported");
    385430
     
    389434
    390435
    391 int ext4fs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
    392 {
    393         EXT4FS_DBG("not supported");
    394 
    395         // TODO
    396         return ENOTSUP;
    397 }
    398 
    399 
    400436int ext4fs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *name)
    401437{
     438        EXT4FS_DBG("unlinking \%s", name);
     439
    402440        int rc;
    403441
     
    430468        child_inode_ref->dirty = true;
    431469
     470//      EXT4FS_DBG("links count = \%u", lnk_count);
     471
    432472        // If directory - handle links from parent
    433473        if (lnk_count <= 1 && ext4fs_is_directory(cfn)) {
    434474
    435                 ext4_inode_ref_t *parent_inode_ref = EXT4FS_NODE(pfn)->inode_ref;
    436                 uint32_t parent_lnk_count = ext4_inode_get_links_count(
    437                                 parent_inode_ref->inode);
    438                 parent_lnk_count--;
    439                 ext4_inode_set_links_count(parent_inode_ref->inode, parent_lnk_count);
    440 
    441                 parent_inode_ref->dirty = true;
     475//              EXT4FS_DBG("directory will be removed, lnlk_count = \%u", lnk_count);
     476
     477                if (lnk_count) {
     478                        lnk_count = ext4_inode_get_links_count(child_inode_ref->inode);
     479                        lnk_count--;
     480                        ext4_inode_set_links_count(child_inode_ref->inode, lnk_count);
     481                }
     482
     483//              ext4_inode_ref_t *parent_inode_ref = EXT4FS_NODE(pfn)->inode_ref;
     484//              uint32_t parent_lnk_count = ext4_inode_get_links_count(
     485//                              parent_inode_ref->inode);
     486//
     487//              EXT4FS_DBG("directory will be removed, parent link count = \%u", parent_lnk_count);
     488//
     489//              parent_lnk_count--;
     490//              ext4_inode_set_links_count(parent_inode_ref->inode, parent_lnk_count);
     491//
     492//              parent_inode_ref->dirty = true;
    442493        }
    443494
     
    10211072ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t new_size)
    10221073{
     1074        int rc;
    10231075        fs_node_t *fn;
    1024         ext4fs_node_t *enode;
    1025         ext4_inode_ref_t *inode_ref;
    1026         ext4_filesystem_t* fs;
    1027         aoff64_t old_size;
    1028         aoff64_t size_diff;
    1029         int rc;
     1076//      aoff64_t old_size;
     1077//      aoff64_t size_diff;
    10301078
    10311079        rc = ext4fs_node_get(&fn, service_id, index);
     
    10341082        }
    10351083
    1036         enode = EXT4FS_NODE(fn);
    1037         inode_ref = enode->inode_ref;
    1038         fs = enode->instance->filesystem;
    1039 
    1040 
    1041         if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) {
    1042                 // Unable to truncate
    1043                 ext4fs_node_put(fn);
    1044                 return EINVAL;
    1045         }
    1046 
    1047         old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
    1048 
    1049         if (old_size == new_size) {
    1050                 ext4fs_node_put(fn);
    1051                 return EOK;
    1052         } else {
    1053 
    1054                 uint32_t block_size;
    1055                 uint32_t blocks_count, total_blocks;
    1056                 uint32_t i;
    1057 
    1058                 block_size  = ext4_superblock_get_block_size(fs->superblock);
    1059 
    1060                 if (old_size < new_size) {
    1061                         // Currently not supported to expand the file
    1062                         // TODO
    1063                         EXT4FS_DBG("trying to expand the file");
    1064                         return EINVAL;
    1065                 }
    1066 
    1067                 size_diff = old_size - new_size;
    1068                 blocks_count = size_diff / block_size;
    1069                 if (size_diff % block_size != 0) {
    1070                         blocks_count++;
    1071                 }
    1072 
    1073                 total_blocks = old_size / block_size;
    1074                 if (old_size % block_size != 0) {
    1075                         total_blocks++;
    1076                 }
    1077 
    1078                 inode_ref->dirty = true;
    1079 
    1080                 // starting from 1 because of logical blocks are numbered from 0
    1081                 for (i = 1; i <= blocks_count; ++i) {
    1082                         // TODO check retval
    1083                         // TODO decrement inode->blocks_count
    1084 
    1085                         ext4_filesystem_release_inode_block(fs, inode_ref, total_blocks - i);
    1086                 }
    1087 
    1088                 ext4_inode_set_size(inode_ref->inode, new_size);
    1089 
    1090         }
    1091 
     1084        ext4fs_node_t *enode = EXT4FS_NODE(fn);
     1085        ext4_inode_ref_t *inode_ref = enode->inode_ref;
     1086        ext4_filesystem_t *fs = enode->instance->filesystem;
     1087
     1088        rc = ext4_filesystem_truncate_inode(fs, inode_ref, new_size);
    10921089        ext4fs_node_put(fn);
    10931090
    1094         return EOK;
     1091        return rc;
     1092
     1093//      if (! ext4_inode_can_truncate(fs->superblock, inode_ref->inode)) {
     1094//              // Unable to truncate
     1095//              ext4fs_node_put(fn);
     1096//              return EINVAL;
     1097//      }
     1098//
     1099//      old_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
     1100//
     1101//      if (old_size == new_size) {
     1102//              ext4fs_node_put(fn);
     1103//              return EOK;
     1104//      } else {
     1105//
     1106//              uint32_t block_size;
     1107//              uint32_t blocks_count, total_blocks;
     1108//              uint32_t i;
     1109//
     1110//              block_size  = ext4_superblock_get_block_size(fs->superblock);
     1111//
     1112//              if (old_size < new_size) {
     1113//                      // Currently not supported to expand the file
     1114//                      // TODO
     1115//                      EXT4FS_DBG("trying to expand the file");
     1116//                      ext4fs_node_put(fn);
     1117//                      return EINVAL;
     1118//              }
     1119//
     1120//              size_diff = old_size - new_size;
     1121//              blocks_count = size_diff / block_size;
     1122//              if (size_diff % block_size != 0) {
     1123//                      blocks_count++;
     1124//              }
     1125//
     1126//              total_blocks = old_size / block_size;
     1127//              if (old_size % block_size != 0) {
     1128//                      total_blocks++;
     1129//              }
     1130//
     1131//              // starting from 1 because of logical blocks are numbered from 0
     1132//              for (i = 1; i <= blocks_count; ++i) {
     1133//                      // TODO check retval
     1134//                      // TODO decrement inode->blocks_count
     1135//
     1136//                      ext4_filesystem_release_inode_block(fs, inode_ref, total_blocks - i);
     1137//              }
     1138//
     1139//              ext4_inode_set_size(inode_ref->inode, new_size);
     1140//
     1141//              inode_ref->dirty = true;
     1142//
     1143//      }
     1144//
     1145//      ext4fs_node_put(fn);
     1146//
     1147//      return EOK;
    10951148}
    10961149
Note: See TracChangeset for help on using the changeset viewer.