From edfcb0288539a6db018ec873d38dcf029a4e1896 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sun, 24 Aug 2014 11:50:23 +0000 Subject: [PATCH] isofs: basic improvements - fix for "out of extents" panic; - return ENOENT when a file name does not exist; - inode count sanity check upon unmount. Change-Id: Icb97dbaf7c8aec463438f06b341defca357094b2 --- minix/fs/iso9660fs/inode.c | 14 ++++++++++++++ minix/fs/iso9660fs/mount.c | 3 +++ minix/fs/iso9660fs/path.c | 10 +++++++--- minix/fs/iso9660fs/proto.h | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/minix/fs/iso9660fs/inode.c b/minix/fs/iso9660fs/inode.c index 4b12c660c..1bcaf5f1e 100644 --- a/minix/fs/iso9660fs/inode.c +++ b/minix/fs/iso9660fs/inode.c @@ -212,6 +212,7 @@ void read_inode_iso9660(struct inode *i, /* Parse first extent. */ if (dir_rec->data_length_l > 0) { + assert(i->extent == NULL); i->extent = alloc_extent(); i->extent->location = dir_rec->loc_extent_l + dir_rec->ext_attr_rec_length; @@ -299,6 +300,7 @@ void read_inode_extents(struct inode *i, (memcmp(dir_rec->file_id, extent_rec->file_id, dir_rec->length_file_id) == 0)) { /* Add the extent at the end of the linked list. */ + assert(cur_extent->next == NULL); cur_extent->next = alloc_extent(); cur_extent->next->location = dir_rec->loc_extent_l + dir_rec->ext_attr_rec_length; @@ -388,3 +390,15 @@ int check_dir_record(const struct iso9660_dir_record *d, size_t offset) return OK; } + +int check_inodes(void) +{ + /* Check whether there are no more inodes in use. Called on unmount. */ + int i; + + for (i = 0; i < NR_INODE_RECORDS; i++) + if (inodes[i].i_count > 0) + return FALSE; + + return TRUE; +} diff --git a/minix/fs/iso9660fs/mount.c b/minix/fs/iso9660fs/mount.c index 9cbe06a70..5b9266f9b 100644 --- a/minix/fs/iso9660fs/mount.c +++ b/minix/fs/iso9660fs/mount.c @@ -60,4 +60,7 @@ void fs_unmount(void) release_vol_pri_desc(&v_pri); /* Release the super block */ bdev_close(fs_dev); + + if (check_inodes() == FALSE) + printf("ISOFS: unmounting with in-use inodes!\n"); } diff --git a/minix/fs/iso9660fs/path.c b/minix/fs/iso9660fs/path.c index df800fd21..04af43cdf 100644 --- a/minix/fs/iso9660fs/path.c +++ b/minix/fs/iso9660fs/path.c @@ -41,12 +41,16 @@ static int search_dir( r = read_inode(dir_tmp, ldir_ptr->extent, pos, &pos); if ((r != OK) || (pos >= ldir_ptr->i_stat.st_size)) { put_inode(dir_tmp); - return EINVAL; + return ENOENT; } + /* Temporary fix for extent spilling */ + put_inode(dir_tmp); + dir_tmp = alloc_inode(); + /* End of fix */ r = read_inode(dir_tmp, ldir_ptr->extent, pos, &pos); if ((r != OK) || (pos >= ldir_ptr->i_stat.st_size)) { put_inode(dir_tmp); - return EINVAL; + return ENOENT; } *numb = dir_tmp->i_stat.st_ino; put_inode(dir_tmp); @@ -60,7 +64,7 @@ static int search_dir( r = read_inode(dir_tmp, ldir_ptr->extent, pos, &pos); if ((r != OK) || (pos >= ldir_ptr->i_stat.st_size)) { put_inode(dir_tmp); - return EINVAL; + return ENOENT; } if ((strcmp(dir_tmp->i_name, string) == 0) || diff --git a/minix/fs/iso9660fs/proto.h b/minix/fs/iso9660fs/proto.h index 106c76490..051eb052f 100644 --- a/minix/fs/iso9660fs/proto.h +++ b/minix/fs/iso9660fs/proto.h @@ -28,6 +28,8 @@ void read_inode_susp(struct inode *i, const struct iso9660_dir_record *dir_rec, int check_dir_record(const struct iso9660_dir_record *d, size_t offset); +int check_inodes(void); + /* link.c */ ssize_t fs_rdlink(ino_t ino_nr, struct fsdriver_data *data, size_t bytes);