changeset 320:40e9dd5ff084

build success
author menikon
date Thu, 06 Feb 2020 18:27:50 +0900
parents 71c7bd0d047e
children 98902fad1e2e
files src/impl/fs_impl.cbc src/impl/fs_impl.h src/impl/fs_impl_private.cbc src/interface/fs.dg
diffstat 4 files changed, 60 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/fs_impl.cbc	Thu Feb 06 17:21:04 2020 +0900
+++ b/src/impl/fs_impl.cbc	Thu Feb 06 18:27:50 2020 +0900
@@ -176,10 +176,23 @@
     goto readi_loopcheck(fs, tot, m, dst, off, n, next(...));
 }
 
-__code writeifs_impl(struct fs_impl* fs, struct inode* ip, char* src, uint off, uint n, __code next(...)) {
+__code writeifs_impl(struct fs_impl* fs, struct inode* ip, char* src, uint off, uint tot, uint n, __code next(int ret, ...)) {
+    if (ip->type == T_DEV) { 
+        goto writei_check_diskinode(fs, ip, src, n, next(...));
+    }
+    
+    if (off > ip->size || off + n < off) {
+        ret = -1;
+        goto next(ret, ...);
+    }
+    
+    if (off + n > MAXFILE * BSIZE) {
+        ret = -1;
+        goto next(ret, ...);
+    }
+    goto writei_loopcheck(fs, tot, m, src, off, n, next(...));
+}
 
-    goto next(...);
-}
 
 __code namecmpfs_impl(struct fs_impl* fs, const char* s, const char* t, __code next(int strncmp_val, ...)) {
     strncmp_val = strncmp(s, t, DIRSIZ);
--- a/src/impl/fs_impl.h	Thu Feb 06 17:21:04 2020 +0900
+++ b/src/impl/fs_impl.h	Thu Feb 06 18:27:50 2020 +0900
@@ -16,6 +16,7 @@
     uint m;
     char* dst;
     uint n;
+    char* src;
 
     __code allocinode(Type* fs_impl, uint dev, short type, __code next(...));
     __code allocinode_loop(Type* fs_impl, uint inum, uint dev, struct superblock* sb, struct buf* bp, struct dinode* dip, __code next(...));
@@ -30,6 +31,10 @@
     __code readi_loopcheck(struct fs_impl* fs_impl, uint tot, uint m, char* dst, uint off, uint n, __code next(...));
     __code readi_loop(struct fs_impl* fs_impl, struct inode *ip, struct buf* bp, uint tot, uint m, char* dst, uint off, uint n, __code next(...));
     __code readi_noloop(struct fs_impl* fs_impl, uint n, __code next(int ret, ...));
+    __code writei_check_diskinode(struct fs_impl* fs_impl,struct inode* ip, char* src, uint n, __code next(int ret, ...));
+    __code writei_loopcheck(struct fs_impl* fs_impl, uint tot, uint m, char* src, uint off, uint n, __code next(...));
+    __code writei_loop(struct fs_impl* fs_impl, struct inode* ip, struct buf* bp, uint tot, uint m, char* src, uint off, uint n, __code next(...));
+    __code writei_noloop(struct fs_impl* fs_impl, struct inode* ip, uint n, uint off, __code next(int ret, ...));
     __code dirlookup_loopcheck(Type* fs_impl, struct inode* dp, char* name, uint off, uint* poff, dirent* de, next(...));
     __code dirlookup_loop(struct fs_impl* fs_impl, struct inode* dp, char* name, uint off, uint* poff, dirent* de, __code next(...));
     __code dirlookup_noloop(struct fs_impl* fs_impl, __code next(int ret, ...));
--- a/src/impl/fs_impl_private.cbc	Thu Feb 06 17:21:04 2020 +0900
+++ b/src/impl/fs_impl_private.cbc	Thu Feb 06 18:27:50 2020 +0900
@@ -345,7 +345,44 @@
 __code readi_noloop(struct fs_impl* fs_impl, uint n, __code next(int ret, ...)){
     ret = n;
     goto next(ret, ...);
+}
 
+__code writei_check_diskinode(struct fs_impl* fs_impl,struct inode* ip, char* src, uint n, __code next(int ret, ...)){
+    if (ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write) {
+        ret = -1;
+        goto next(ret, ...);
+    }
+
+    ret = devsw[ip->major].write(ip, src, n);
+    goto next(ret, ...);
+}
+
+__code writei_loopcheck(struct fs_impl* fs_impl, uint tot, uint m, char* src, uint off, uint n, __code next(...)){
+    if(tot < n){
+        goto writei_loop(fs_impl, ip, bp, tot, m, src, off, n, next(...));
+    }
+    goto writei_noloop(fs_impl, next(...));
+}
+
+__code writei_loop(struct fs_impl* fs_impl, struct inode* ip, struct buf* bp, uint tot, uint m, char* src, uint off, uint n, __code next(...)){ //:skip
+    bp = bread(ip->dev, bmap(ip, off / BSIZE));
+    m = min(n - tot, BSIZE - off%BSIZE); 
+    memmove(bp->data + off % BSIZE, src, m);
+    log_write(bp);
+    brelse(bp);
+    tot += m;
+    off += m;
+    src += m;
+    goto writei_loopcheck(fs_impl, tot, m, src, off, n, next(...));
+}
+
+__code writei_noloop(struct fs_impl* fs_impl, struct inode* ip, uint n, uint off, __code next(int ret, ...)){
+    if (n > 0 && off > ip->size) {
+        ip->size = off;
+        iupdate(ip);
+    }
+    ret = n;
+    goto next(ret, ...);
 }
 typedef struct dirent dirent;
 __code dirlookup_loopcheck(struct fs_impl* fs_impl, struct inode* dp, char* name, uint off, uint* poff, dirent* de, __code next(...)){ //:skip
--- a/src/interface/fs.dg	Thu Feb 06 17:21:04 2020 +0900
+++ b/src/interface/fs.dg	Thu Feb 06 18:27:50 2020 +0900
@@ -31,8 +31,8 @@
     __code iput(Impl* fs, struct inode* ip, __code next(...));
     __code iunlockput(Impl* fs, struct inode* ip, __code next(...));
     __code stati(Impl* fs , struct inode* ip, struct stat* st, __code next(...));
-    __code readi(Impl* fs, struct inode* ip, char* dst, uint off, uint tot, uint n, __code next(...));
-    __code writei(Impl* fs, struct inode* ip, char* src, uint off, uint n, __code next(...));
+    __code readi(Impl* fs, struct inode* ip, char* dst, uint off, uint tot, uint n, __code next(int ret, ...));
+    __code writei(Impl* fs, struct inode* ip, char* src, uint off, uint tot, uint n, __code next(int ret, ...));
     __code namecmp(Impl* fs, const char* s, const char* t, __code next(int strncmp_val, ...));
     __code dirlookup(struct inode* dp, char* name, uint* poff, dirent* de, __code next(int ret, ...));
     __code dirlink(struct fs_impl* fs, struct inode* ip, struct dirent* de, struct inode* dp, char* name, uint off, uint inum, __code next(...));