-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch
2197 lines (2162 loc) · 72 KB
/
patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -ruNp minix_src_clean/include/minix/callnr.h immediate_files/include/minix/callnr.h
--- minix_src_clean/include/minix/callnr.h 2013-02-15 03:18:13.000000000 -0800
+++ immediate_files/include/minix/callnr.h 2013-06-08 22:45:07.040643107 -0700
@@ -55,6 +55,7 @@
#define IOCTL 54
#define FCNTL 55
#define FS_READY 57
+#define LSR 58 //lsr added
#define EXEC 59
#define UMASK 60
#define CHROOT 61
diff -ruNp minix_src_clean/include/minix/const.h immediate_files/include/minix/const.h
--- minix_src_clean/include/minix/const.h 2013-02-15 03:18:13.000000000 -0800
+++ immediate_files/include/minix/const.h 2013-06-08 22:31:05.340948620 -0700
@@ -114,6 +114,7 @@
#define I_UNIX_SOCKET 0140000 /* unix domain socket */
#define I_SYMBOLIC_LINK 0120000 /* file is a symbolic link */
#define I_REGULAR 0100000 /* regular file, not dir or special */
+#define I_IMMEDIATE 0110000 /* immediate file, for proj3 [modify]*/
#define I_BLOCK_SPECIAL 0060000 /* block special file */
#define I_DIRECTORY 0040000 /* file is a directory */
#define I_CHAR_SPECIAL 0020000 /* character special file */
diff -ruNp minix_src_clean/include/minix/vfsif.h immediate_files/include/minix/vfsif.h
--- minix_src_clean/include/minix/vfsif.h 2013-02-15 03:18:13.000000000 -0800
+++ immediate_files/include/minix/vfsif.h 2013-06-08 22:45:48.676906133 -0700
@@ -124,6 +124,7 @@ typedef struct {
#define REQ_RDLINK (VFS_BASE + 30)
#define REQ_GETDENTS (VFS_BASE + 31)
#define REQ_STATVFS (VFS_BASE + 32)
+#define REQ_LISTBLOCKNUM (VFS_BASE)
#define NREQS 33
diff -ruNp minix_src_clean/include/unistd.h immediate_files/include/unistd.h
--- minix_src_clean/include/unistd.h 2013-02-15 03:18:13.000000000 -0800
+++ immediate_files/include/unistd.h 2013-06-08 22:46:47.623940319 -0700
@@ -146,6 +146,9 @@ __aconst char *ttyname(int);
int unlink(const char *);
ssize_t write(int, const void *, size_t);
+//lsr
+void lsr(char * path);
+
/*
* IEEE Std 1003.2-92, adopted in X/Open Portability Guide Issue 4 and later
diff -ruNp minix_src_clean/lib/libc/sys-minix/lsr.c immediate_files/lib/libc/sys-minix/lsr.c
--- minix_src_clean/lib/libc/sys-minix/lsr.c 1969-12-31 16:00:00.000000000 -0800
+++ immediate_files/lib/libc/sys-minix/lsr.c 2013-06-08 22:54:24.513948689 -0700
@@ -0,0 +1,15 @@
+#include <sys/cdefs.h>
+#include "namespace.h"
+#include <lib.h>
+
+#include <unistd.h>
+#include <stdio.h>
+
+
+void lsr(char * path)
+{
+ //printf("LSR begin\n");
+ message m;
+ _loadname(path, &m);
+ return(_syscall(VFS_PROC_NR, LSR, &m));
+}
diff -ruNp minix_src_clean/lib/libc/sys-minix/Makefile.inc immediate_files/lib/libc/sys-minix/Makefile.inc
--- minix_src_clean/lib/libc/sys-minix/Makefile.inc 2013-02-15 03:18:14.000000000 -0800
+++ immediate_files/lib/libc/sys-minix/Makefile.inc 2013-06-08 22:56:17.690314286 -0700
@@ -19,6 +19,6 @@ SRCS+= accept.c access.c bind.c brk.c s
_exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c init.c
# Minix specific syscalls.
-SRCS+= cprofile.c lseek64.c sprofile.c _mcontext.c
+SRCS+= cprofile.c lseek64.c sprofile.c _mcontext.c lsr.c
.include "${ARCHDIR}/sys-minix/Makefile.inc"
diff -ruNp minix_src_clean/servers/mfs/inode.c immediate_files/servers/mfs/inode.c
--- minix_src_clean/servers/mfs/inode.c 2013-02-15 03:18:14.000000000 -0800
+++ immediate_files/servers/mfs/inode.c 2013-06-08 22:31:05.352969752 -0700
@@ -288,8 +288,9 @@ struct inode *alloc_inode(dev_t dev, mod
/* No inode table slots available. Free the inode just allocated. */
free_bit(sp, IMAP, b);
} else {
- /* An inode slot is available. Put the inode just allocated into it. */
- rip->i_mode = bits; /* set up RWX bits */
+ /* An inode slot is available. Put the inode just allocated into it. */ //[modify]
+ rip->i_mode = ((bits & I_TYPE) == I_REGULAR ? bits | I_IMMEDIATE : bits); /* set up RWX bits */
+ //printf("*** alloc_inode() - mode bits: 0%6o\n", rip->i_mode);
rip->i_nlinks = NO_LINK; /* initial no links */
rip->i_uid = caller_uid; /* file's uid is owner's */
rip->i_gid = caller_gid; /* ditto group id */
diff -ruNp minix_src_clean/servers/mfs/link.c immediate_files/servers/mfs/link.c
--- minix_src_clean/servers/mfs/link.c 2013-02-15 03:18:14.000000000 -0800
+++ immediate_files/servers/mfs/link.c 2013-06-08 23:48:36.666952622 -0700
@@ -535,15 +535,72 @@ off_t newsize; /* inode must become th
return(EINVAL);
if (newsize > rip->i_sp->s_max_size) /* don't let inode grow too big */
return(EFBIG);
-
+
+
/* Free the actual space if truncating. */
if (newsize < rip->i_size) {
- if ((r = freesp_inode(rip, newsize, rip->i_size)) != OK)
- return(r);
+
+ if ((rip->i_mode & I_TYPE) == I_IMMEDIATE){// [modify]
+ // do nothing
+ //printf("*** truncate_inode() called on immedate file inode\n");
+ }
+ else if ((r = freesp_inode(rip, newsize, rip->i_size)) != OK)
+ return(r);
+
+ if(newsize == 0) rip->i_mode = I_IMMEDIATE | (rip->i_mode & ALL_MODES);
}
/* Clear the rest of the last zone if expanding. */
- if (newsize > rip->i_size) clear_zone(rip, rip->i_size, 0);
+ else if (newsize > rip->i_size)
+ { // if it is immediate
+ if((rip->i_mode & I_TYPE) == I_IMMEDIATE)
+ { // if we need to change it to an immediate file
+ if(newsize > 32){
+ char izone_data[32];
+ register int i;
+ register struct buf *bp;
+
+ for(i = 0; i < rip->i_size; i++)
+ {
+ izone_data[i] = *(((char *)rip->i_zone) + i);
+ }
+
+ rip->i_update = ATIME | CTIME | MTIME;
+ IN_MARKDIRTY(rip);
+ for (i = 0; i < V2_NR_TZONES; i++)
+ { rip->i_zone[i] = NO_ZONE; }
+
+ if ((bp = new_block(rip, (off_t) 0)) == NULL)
+ panic("bp caused error in truncate_inode immediate growth");
+
+ /* copy data to b_data */
+ for(i = 0; i < rip->i_size; i++)
+ {
+ b_data(bp)[i] = izone_data[i];
+ }
+
+ MARKDIRTY(bp);
+ put_block(bp, PARTIAL_DATA_BLOCK);
+ rip->i_mode = (I_REGULAR | (rip->i_mode & ALL_MODES));
+
+ clear_zone(rip, rip->i_size, 0);
+ }
+ else { /* it gets bigger, but we don't need to convert to immediate yet */
+ /* add null char for every spot in izone */
+ for(r = rip->i_size; r < newsize; r++)
+ {
+ ((char*)rip->i_zone)[r] = '\0';
+ }
+ }
+ }
+ else /* it is not an immediate file, so truncate normally */
+ {
+ clear_zone(rip, rip->i_size, 0);
+ }
+
+ } // end "if (newsize > rip->i_size)"
+
+ // end [modify]
/* Next correct the inode size. */
rip->i_size = newsize;
diff -ruNp minix_src_clean/servers/mfs/link.c~ immediate_files/servers/mfs/link.c~
--- minix_src_clean/servers/mfs/link.c~ 1969-12-31 16:00:00.000000000 -0800
+++ immediate_files/servers/mfs/link.c~ 2013-06-08 23:48:11.170913703 -0700
@@ -0,0 +1,763 @@
+#include "fs.h"
+#include <sys/stat.h>
+#include <string.h>
+#include <minix/com.h>
+#include "buf.h"
+#include "inode.h"
+#include "super.h"
+#include <minix/vfsif.h>
+
+#define SAME 1000
+
+
+static int freesp_inode(struct inode *rip, off_t st, off_t end);
+static int remove_dir(struct inode *rldirp, struct inode *rip, char
+ dir_name[MFS_NAME_MAX]);
+static int unlink_file(struct inode *dirp, struct inode *rip, char
+ file_name[MFS_NAME_MAX]);
+static off_t nextblock(off_t pos, int zone_size);
+static void zerozone_half(struct inode *rip, off_t pos, int half, int
+ zone_size);
+static void zerozone_range(struct inode *rip, off_t pos, off_t len);
+
+/* Args to zerozone_half() */
+#define FIRST_HALF 0
+#define LAST_HALF 1
+
+
+/*===========================================================================*
+ * fs_link *
+ *===========================================================================*/
+int fs_link()
+{
+/* Perform the link(name1, name2) system call. */
+
+ struct inode *ip, *rip;
+ register int r;
+ char string[MFS_NAME_MAX];
+ struct inode *new_ip;
+ phys_bytes len;
+
+ len = min( (unsigned) fs_m_in.REQ_PATH_LEN, sizeof(string));
+ /* Copy the link name's last component */
+ r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
+ (vir_bytes) 0, (vir_bytes) string, (size_t) len);
+ if (r != OK) return r;
+ NUL(string, len, sizeof(string));
+
+ /* Temporarily open the file. */
+ if( (rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
+ return(EINVAL);
+
+ /* Check to see if the file has maximum number of links already. */
+ r = OK;
+ if(rip->i_nlinks >= LINK_MAX)
+ r = EMLINK;
+
+ /* Only super_user may link to directories. */
+ if(r == OK)
+ if( (rip->i_mode & I_TYPE) == I_DIRECTORY && caller_uid != SU_UID)
+ r = EPERM;
+
+ /* If error with 'name', return the inode. */
+ if (r != OK) {
+ put_inode(rip);
+ return(r);
+ }
+
+ /* Temporarily open the last dir */
+ if( (ip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_DIR_INO)) == NULL) {
+ put_inode(rip);
+ return(EINVAL);
+ }
+
+ if (ip->i_nlinks == NO_LINK) { /* Dir does not actually exist */
+ put_inode(rip);
+ put_inode(ip);
+ return(ENOENT);
+ }
+
+ /* If 'name2' exists in full (even if no space) set 'r' to error. */
+ if((new_ip = advance(ip, string, IGN_PERM)) == NULL) {
+ r = err_code;
+ if(r == ENOENT)
+ r = OK;
+ } else {
+ put_inode(new_ip);
+ r = EEXIST;
+ }
+
+ /* Try to link. */
+ if(r == OK)
+ r = search_dir(ip, string, &rip->i_num, ENTER, IGN_PERM);
+
+ /* If success, register the linking. */
+ if(r == OK) {
+ rip->i_nlinks++;
+ rip->i_update |= CTIME;
+ IN_MARKDIRTY(rip);
+ }
+
+ /* Done. Release both inodes. */
+ put_inode(rip);
+ put_inode(ip);
+ return(r);
+}
+
+
+/*===========================================================================*
+ * fs_unlink *
+ *===========================================================================*/
+int fs_unlink()
+{
+/* Perform the unlink(name) or rmdir(name) system call. The code for these two
+ * is almost the same. They differ only in some condition testing. Unlink()
+ * may be used by the superuser to do dangerous things; rmdir() may not.
+ */
+ register struct inode *rip;
+ struct inode *rldirp;
+ int r;
+ char string[MFS_NAME_MAX];
+ phys_bytes len;
+
+ /* Copy the last component */
+ len = min( (unsigned) fs_m_in.REQ_PATH_LEN, sizeof(string));
+ r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
+ (vir_bytes) 0, (vir_bytes) string, (size_t) len);
+ if (r != OK) return r;
+ NUL(string, len, sizeof(string));
+
+ /* Temporarily open the dir. */
+ if( (rldirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
+ return(EINVAL);
+
+ /* The last directory exists. Does the file also exist? */
+ rip = advance(rldirp, string, IGN_PERM);
+ r = err_code;
+
+ /* If error, return inode. */
+ if(r != OK) {
+ /* Mount point? */
+ if (r == EENTERMOUNT || r == ELEAVEMOUNT) {
+ put_inode(rip);
+ r = EBUSY;
+ }
+ put_inode(rldirp);
+ return(r);
+ }
+
+ if(rip->i_sp->s_rd_only) {
+ r = EROFS;
+ } else if(fs_m_in.m_type == REQ_UNLINK) {
+ /* Now test if the call is allowed, separately for unlink() and rmdir(). */
+ /* Only the su may unlink directories, but the su can unlink any
+ * dir.*/
+ if( (rip->i_mode & I_TYPE) == I_DIRECTORY) r = EPERM;
+
+ /* Actually try to unlink the file; fails if parent is mode 0 etc. */
+ if (r == OK) r = unlink_file(rldirp, rip, string);
+ } else {
+ r = remove_dir(rldirp, rip, string); /* call is RMDIR */
+ }
+
+ /* If unlink was possible, it has been done, otherwise it has not. */
+ put_inode(rip);
+ put_inode(rldirp);
+ return(r);
+}
+
+
+/*===========================================================================*
+ * fs_rdlink *
+ *===========================================================================*/
+int fs_rdlink()
+{
+ block_t b; /* block containing link text */
+ struct buf *bp; /* buffer containing link text */
+ register struct inode *rip; /* target inode */
+ register int r; /* return value */
+ size_t copylen;
+
+ copylen = min( (size_t) fs_m_in.REQ_MEM_SIZE, UMAX_FILE_POS);
+
+ /* Temporarily open the file. */
+ if( (rip = get_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
+ return(EINVAL);
+
+ if(!S_ISLNK(rip->i_mode))
+ r = EACCES;
+ else if ((b = read_map(rip, (off_t) 0)) == NO_BLOCK)
+ r = EIO;
+ else {
+ /* Passed all checks */
+ /* We can safely cast to unsigned, because copylen is guaranteed to be
+ below max file size */
+ copylen = min( copylen, (unsigned) rip->i_size);
+ bp = get_block(rip->i_dev, b, NORMAL);
+ r = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_GRANT,
+ (vir_bytes) 0, (vir_bytes) b_data(bp),
+ (size_t) copylen);
+ put_block(bp, DIRECTORY_BLOCK);
+ if (r == OK)
+ fs_m_out.RES_NBYTES = copylen;
+ }
+
+ put_inode(rip);
+ return(r);
+}
+
+
+/*===========================================================================*
+ * remove_dir *
+ *===========================================================================*/
+static int remove_dir(rldirp, rip, dir_name)
+struct inode *rldirp; /* parent directory */
+struct inode *rip; /* directory to be removed */
+char dir_name[MFS_NAME_MAX]; /* name of directory to be removed */
+{
+ /* A directory file has to be removed. Five conditions have to met:
+ * - The file must be a directory
+ * - The directory must be empty (except for . and ..)
+ * - The final component of the path must not be . or ..
+ * - The directory must not be the root of a mounted file system (VFS)
+ * - The directory must not be anybody's root/working directory (VFS)
+ */
+ int r;
+
+ /* search_dir checks that rip is a directory too. */
+ if ((r = search_dir(rip, "", NULL, IS_EMPTY, IGN_PERM)) != OK)
+ return(r);
+
+ if (strcmp(dir_name, ".") == 0 || strcmp(dir_name, "..") == 0)return(EINVAL);
+ if (rip->i_num == ROOT_INODE) return(EBUSY); /* can't remove 'root' */
+
+ /* Actually try to unlink the file; fails if parent is mode 0 etc. */
+ if ((r = unlink_file(rldirp, rip, dir_name)) != OK) return r;
+
+ /* Unlink . and .. from the dir. The super user can link and unlink any dir,
+ * so don't make too many assumptions about them.
+ */
+ (void) unlink_file(rip, NULL, dot1);
+ (void) unlink_file(rip, NULL, dot2);
+ return(OK);
+}
+
+
+/*===========================================================================*
+ * unlink_file *
+ *===========================================================================*/
+static int unlink_file(dirp, rip, file_name)
+struct inode *dirp; /* parent directory of file */
+struct inode *rip; /* inode of file, may be NULL too. */
+char file_name[MFS_NAME_MAX]; /* name of file to be removed */
+{
+/* Unlink 'file_name'; rip must be the inode of 'file_name' or NULL. */
+
+ ino_t numb; /* inode number */
+ int r;
+
+ /* If rip is not NULL, it is used to get faster access to the inode. */
+ if (rip == NULL) {
+ /* Search for file in directory and try to get its inode. */
+ err_code = search_dir(dirp, file_name, &numb, LOOK_UP, IGN_PERM);
+ if (err_code == OK) rip = get_inode(dirp->i_dev, (int) numb);
+ if (err_code != OK || rip == NULL) return(err_code);
+ } else {
+ dup_inode(rip); /* inode will be returned with put_inode */
+ }
+
+ r = search_dir(dirp, file_name, NULL, DELETE, IGN_PERM);
+
+ if (r == OK) {
+ rip->i_nlinks--; /* entry deleted from parent's dir */
+ rip->i_update |= CTIME;
+ IN_MARKDIRTY(rip);
+ }
+
+ put_inode(rip);
+ return(r);
+}
+
+
+/*===========================================================================*
+ * fs_rename *
+ *===========================================================================*/
+int fs_rename()
+{
+/* Perform the rename(name1, name2) system call. */
+ struct inode *old_dirp, *old_ip; /* ptrs to old dir, file inodes */
+ struct inode *new_dirp, *new_ip; /* ptrs to new dir, file inodes */
+ struct inode *new_superdirp, *next_new_superdirp;
+ int r = OK; /* error flag; initially no error */
+ int odir, ndir; /* TRUE iff {old|new} file is dir */
+ int same_pdir; /* TRUE iff parent dirs are the same */
+ char old_name[MFS_NAME_MAX], new_name[MFS_NAME_MAX];
+ ino_t numb;
+ phys_bytes len;
+
+ /* Copy the last component of the old name */
+ len = min( (unsigned) fs_m_in.REQ_REN_LEN_OLD, sizeof(old_name));
+ r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_REN_GRANT_OLD,
+ (vir_bytes) 0, (vir_bytes) old_name, (size_t) len);
+ if (r != OK) return r;
+ NUL(old_name, len, sizeof(old_name));
+
+ /* Copy the last component of the new name */
+ len = min( (unsigned) fs_m_in.REQ_REN_LEN_NEW, sizeof(new_name));
+ r = sys_safecopyfrom(VFS_PROC_NR, (cp_grant_id_t) fs_m_in.REQ_REN_GRANT_NEW,
+ (vir_bytes) 0, (vir_bytes) new_name, (size_t) len);
+ if (r != OK) return r;
+ NUL(new_name, len, sizeof(new_name));
+
+ /* Get old dir inode */
+ if( (old_dirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_REN_OLD_DIR)) == NULL)
+ return(err_code);
+
+ old_ip = advance(old_dirp, old_name, IGN_PERM);
+ r = err_code;
+
+ if (r == EENTERMOUNT || r == ELEAVEMOUNT) {
+ put_inode(old_ip);
+ old_ip = NULL;
+ if (r == EENTERMOUNT) r = EXDEV; /* should this fail at all? */
+ else if (r == ELEAVEMOUNT) r = EINVAL; /* rename on dot-dot */
+ }
+
+ if (old_ip == NULL) {
+ put_inode(old_dirp);
+ return(r);
+ }
+
+ /* Get new dir inode */
+ if( (new_dirp = get_inode(fs_dev, (ino_t) fs_m_in.REQ_REN_NEW_DIR)) == NULL) {
+ put_inode(old_ip);
+ put_inode(old_dirp);
+ return(err_code);
+ } else {
+ if (new_dirp->i_nlinks == NO_LINK) { /* Dir does not actually exist */
+ put_inode(old_ip);
+ put_inode(old_dirp);
+ put_inode(new_dirp);
+ return(ENOENT);
+ }
+ }
+
+ new_ip = advance(new_dirp, new_name, IGN_PERM); /* not required to exist */
+
+ /* However, if the check failed because the file does exist, don't continue.
+ * Note that ELEAVEMOUNT is covered by the dot-dot check later. */
+ if(err_code == EENTERMOUNT) {
+ put_inode(new_ip);
+ new_ip = NULL;
+ r = EBUSY;
+ }
+
+ odir = ((old_ip->i_mode & I_TYPE) == I_DIRECTORY); /* TRUE iff dir */
+
+ /* If it is ok, check for a variety of possible errors. */
+ if(r == OK) {
+ same_pdir = (old_dirp == new_dirp);
+
+ /* The old inode must not be a superdirectory of the new last dir. */
+ if (odir && !same_pdir) {
+ dup_inode(new_superdirp = new_dirp);
+ while (TRUE) { /* may hang in a file system loop */
+ if (new_superdirp == old_ip) {
+ put_inode(new_superdirp);
+ r = EINVAL;
+ break;
+ }
+ next_new_superdirp = advance(new_superdirp, dot2,
+ IGN_PERM);
+
+ put_inode(new_superdirp);
+ if(next_new_superdirp == new_superdirp) {
+ put_inode(new_superdirp);
+ break;
+ }
+ if(err_code == ELEAVEMOUNT) {
+ /* imitate that we are back at the root,
+ * cross device checked already on VFS */
+ put_inode(next_new_superdirp);
+ err_code = OK;
+ break;
+ }
+ new_superdirp = next_new_superdirp;
+ if(new_superdirp == NULL) {
+ /* Missing ".." entry. Assume the worst. */
+ r = EINVAL;
+ break;
+ }
+ }
+ }
+
+ /* The old or new name must not be . or .. */
+ if(strcmp(old_name, ".") == 0 || strcmp(old_name, "..") == 0 ||
+ strcmp(new_name, ".") == 0 || strcmp(new_name, "..") == 0) {
+ r = EINVAL;
+ }
+ /* Both parent directories must be on the same device.
+ if(old_dirp->i_dev != new_dirp->i_dev) r = EXDEV; */
+
+ /* Some tests apply only if the new path exists. */
+ if(new_ip == NULL) {
+ /* don't rename a file with a file system mounted on it.
+ if (old_ip->i_dev != old_dirp->i_dev) r = EXDEV;*/
+ if (odir && new_dirp->i_nlinks >= LINK_MAX &&
+ !same_pdir && r == OK) {
+ r = EMLINK;
+ }
+ } else {
+ if(old_ip == new_ip) r = SAME; /* old=new */
+
+ ndir = ((new_ip->i_mode & I_TYPE) == I_DIRECTORY);/* dir ? */
+ if(odir == TRUE && ndir == FALSE) r = ENOTDIR;
+ if(odir == FALSE && ndir == TRUE) r = EISDIR;
+ }
+ }
+
+ /* If a process has another root directory than the system root, we might
+ * "accidently" be moving it's working directory to a place where it's
+ * root directory isn't a super directory of it anymore. This can make
+ * the function chroot useless. If chroot will be used often we should
+ * probably check for it here. */
+
+ /* The rename will probably work. Only two things can go wrong now:
+ * 1. being unable to remove the new file. (when new file already exists)
+ * 2. being unable to make the new directory entry. (new file doesn't exists)
+ * [directory has to grow by one block and cannot because the disk
+ * is completely full].
+ */
+ if(r == OK) {
+ if(new_ip != NULL) {
+ /* There is already an entry for 'new'. Try to remove it. */
+ if(odir)
+ r = remove_dir(new_dirp, new_ip, new_name);
+ else
+ r = unlink_file(new_dirp, new_ip, new_name);
+ }
+ /* if r is OK, the rename will succeed, while there is now an
+ * unused entry in the new parent directory. */
+ }
+
+ if(r == OK) {
+ /* If the new name will be in the same parent directory as the old
+ * one, first remove the old name to free an entry for the new name,
+ * otherwise first try to create the new name entry to make sure
+ * the rename will succeed.
+ */
+ numb = old_ip->i_num; /* inode number of old file */
+
+ if(same_pdir) {
+ r = search_dir(old_dirp, old_name, NULL, DELETE, IGN_PERM);
+ /* shouldn't go wrong. */
+ if(r == OK)
+ (void) search_dir(old_dirp, new_name, &numb, ENTER,
+ IGN_PERM);
+ } else {
+ r = search_dir(new_dirp, new_name, &numb, ENTER, IGN_PERM);
+ if(r == OK)
+ (void) search_dir(old_dirp, old_name, NULL, DELETE,
+ IGN_PERM);
+ }
+ }
+ /* If r is OK, the ctime and mtime of old_dirp and new_dirp have been marked
+ * for update in search_dir. */
+
+ if(r == OK && odir && !same_pdir) {
+ /* Update the .. entry in the directory (still points to old_dirp).*/
+ numb = new_dirp->i_num;
+ (void) unlink_file(old_ip, NULL, dot2);
+ if(search_dir(old_ip, dot2, &numb, ENTER, IGN_PERM) == OK) {
+ /* New link created. */
+ new_dirp->i_nlinks++;
+ IN_MARKDIRTY(new_dirp);
+ }
+ }
+
+ /* Release the inodes. */
+ put_inode(old_dirp);
+ put_inode(old_ip);
+ put_inode(new_dirp);
+ put_inode(new_ip);
+ return(r == SAME ? OK : r);
+}
+
+
+/*===========================================================================*
+ * fs_ftrunc *
+ *===========================================================================*/
+int fs_ftrunc(void)
+{
+ struct inode *rip;
+ off_t start, end;
+ int r;
+
+ if( (rip = find_inode(fs_dev, (ino_t) fs_m_in.REQ_INODE_NR)) == NULL)
+ return(EINVAL);
+
+ if(rip->i_sp->s_rd_only) {
+ r = EROFS;
+ } else {
+ start = fs_m_in.REQ_TRC_START_LO;
+ end = fs_m_in.REQ_TRC_END_LO;
+
+ if (end == 0)
+ r = truncate_inode(rip, start);
+ else
+ r = freesp_inode(rip, start, end);
+ }
+
+ return(r);
+}
+
+
+/*===========================================================================*
+ * truncate_inode *
+ *===========================================================================*/
+int truncate_inode(rip, newsize)
+register struct inode *rip; /* pointer to inode to be truncated */
+off_t newsize; /* inode must become this size */
+{
+/* Set inode to a certain size, freeing any zones no longer referenced
+ * and updating the size in the inode. If the inode is extended, the
+ * extra space is a hole that reads as zeroes.
+ *
+ * Nothing special has to happen to file pointers if inode is opened in
+ * O_APPEND mode, as this is different per fd and is checked when
+ * writing is done.
+ */
+ int r;
+ mode_t file_type;
+
+ file_type = rip->i_mode & I_TYPE; /* check to see if file is special */
+ if (file_type == I_CHAR_SPECIAL || file_type == I_BLOCK_SPECIAL)
+ return(EINVAL);
+ if (newsize > rip->i_sp->s_max_size) /* don't let inode grow too big */
+ return(EFBIG);
+
+
+ /* Free the actual space if truncating. */
+ if (newsize < rip->i_size) {
+
+ if ((rip->i_mode & I_TYPE) == I_IMMEDIATE){// [modify]
+ // do nothing
+ //printf("*** truncate_inode() called on immedate file inode\n");
+ }
+ else if ((r = freesp_inode(rip, newsize, rip->i_size)) != OK)
+ return(r);
+
+ if(newsize == 0) rip->i_mode = I_IMMEDIATE | (rip->i_mode & ALL_MODES);
+ }
+
+ /* Clear the rest of the last zone if expanding. */
+ else if (newsize > rip->i_size)
+ { // if it is immediate
+ if((rip->i_mode & I_TYPE) == I_IMMEDIATE)
+ { // if we need to change it to an immediate file
+ if(newsize > 32){
+ char izone_data[32];
+ register int i;
+ register struct buf *bp;
+
+ for(i = 0; i < rip->i_size; i++)
+ {
+ izone_data[i] = *(((char *)rip->i_zone) + i);
+ }
+
+ rip->i_update = ATIME | CTIME | MTIME;
+ IN_MARKDIRTY(rip);
+ for (i = 0; i < V2_NR_TZONES; i++)
+ { rip->i_zone[i] = NO_ZONE; }
+
+ if ((bp = new_block(rip, (off_t) 0)) == NULL)
+ panic("bp caused error in truncate_inode immediate growth");
+
+ /* copy data to b_data */
+ for(i = 0; i < rip->i_size; i++)
+ {
+ b_data(bp)[i] = izone_data[i];
+ }
+
+ MARKDIRTY(bp);
+ put_block(bp, PARTIAL_DATA_BLOCK);
+ rip->i_mode = (I_REGULAR | (rip->i_mode & ALL_MODES));
+
+ clear_zone(rip, rip->i_size, 0);
+ }
+ else { /* it gets bigger, but we don't need to convert to immediate yet */
+ /* add null char for every spot in izone */
+ for(r = rip->i_size; r < newsize; r++)
+ {
+ ((char*)rip->i_zone)[r] = '\0';
+ }
+ }
+ }
+ else /* it is not an immediate file, so truncate normally */
+ {
+ clear_zone(rip, rip->i_size, 0);
+ }
+
+ } // end "if (newsize > rip->i_size)"
+
+ // end [modify]
+
+ /* Next correct the inode size. */
+ rip->i_size = newsize;
+ rip->i_update |= CTIME | MTIME;
+ IN_MARKDIRTY(rip);
+
+ return(OK);
+}
+
+
+/*===========================================================================*
+ * freesp_inode *
+ *===========================================================================*/
+static int freesp_inode(rip, start, end)
+register struct inode *rip; /* pointer to inode to be partly freed */
+off_t start, end; /* range of bytes to free (end uninclusive) */
+{
+/* Cut an arbitrary hole in an inode. The caller is responsible for checking
+ * the reasonableness of the inode type of rip. The reason is this is that
+ * this function can be called for different reasons, for which different
+ * sets of inode types are reasonable. Adjusting the final size of the inode
+ * is to be done by the caller too, if wished.
+ *
+ * Consumers of this function currently are truncate_inode() (used to
+ * free indirect and data blocks for any type of inode, but also to
+ * implement the ftruncate() and truncate() system calls) and the F_FREESP
+ * fcntl().
+ */
+ off_t p, e;
+ int zone_size, r;
+ int zero_last, zero_first;
+
+ if(end > rip->i_size) /* freeing beyond end makes no sense */
+ end = rip->i_size;
+ if(end <= start) /* end is uninclusive, so start<end */
+ return(EINVAL);
+
+ zone_size = rip->i_sp->s_block_size << rip->i_sp->s_log_zone_size;
+
+ /* If freeing doesn't cross a zone boundary, then we may only zero
+ * a range of the zone, unless we are freeing up that entire zone.
+ */
+ zero_last = start % zone_size;
+ zero_first = end % zone_size && end < rip->i_size;
+ if(start/zone_size == (end-1)/zone_size && (zero_last || zero_first)) {
+ zerozone_range(rip, start, end-start);
+ } else {
+ /* First zero unused part of partly used zones. */
+ if(zero_last)
+ zerozone_half(rip, start, LAST_HALF, zone_size);
+ if(zero_first)
+ zerozone_half(rip, end, FIRST_HALF, zone_size);
+
+ /* Now completely free the completely unused zones.
+ * write_map() will free unused (double) indirect
+ * blocks too. Converting the range to zone numbers avoids
+ * overflow on p when doing e.g. 'p += zone_size'.
+ */
+ e = end/zone_size;
+ if(end == rip->i_size && (end % zone_size)) e++;
+ for(p = nextblock(start, zone_size)/zone_size; p < e; p ++) {
+ if((r = write_map(rip, p*zone_size, NO_ZONE, WMAP_FREE)) != OK)
+ return(r);
+ }
+
+ }
+
+ rip->i_update |= CTIME | MTIME;
+ IN_MARKDIRTY(rip);
+
+ return(OK);
+}
+
+
+/*===========================================================================*
+ * nextblock *
+ *===========================================================================*/
+static off_t nextblock(pos, zone_size)
+off_t pos;
+int zone_size;
+{
+/* Return the first position in the next block after position 'pos'
+ * (unless this is the first position in the current block).
+ * This can be done in one expression, but that can overflow pos.
+ */
+ off_t p;
+ p = (pos/zone_size)*zone_size;
+ if((pos % zone_size)) p += zone_size; /* Round up. */
+ return(p);
+}
+
+
+/*===========================================================================*
+ * zerozone_half *
+ *===========================================================================*/
+static void zerozone_half(rip, pos, half, zone_size)
+struct inode *rip;
+off_t pos;
+int half;
+int zone_size;
+{
+/* Zero the upper or lower 'half' of a zone that holds position 'pos'.
+ * half can be FIRST_HALF or LAST_HALF.
+ *
+ * FIRST_HALF: 0..pos-1 will be zeroed
+ * LAST_HALF: pos..zone_size-1 will be zeroed
+ */
+ off_t offset, len;
+
+ /* Offset of zeroing boundary. */
+ offset = pos % zone_size;
+
+ if(half == LAST_HALF) {
+ len = zone_size - offset;
+ } else {
+ len = offset;
+ pos -= offset;
+ }
+
+ zerozone_range(rip, pos, len);
+}
+
+
+/*===========================================================================*
+ * zerozone_range *
+ *===========================================================================*/
+static void zerozone_range(rip, pos, len)
+struct inode *rip;
+off_t pos;
+off_t len;
+{
+/* Zero an arbitrary byte range in a zone, possibly spanning multiple blocks.
+ */
+ block_t b;
+ struct buf *bp;
+ off_t offset;
+ unsigned short block_size;
+ size_t bytes;
+
+ block_size = rip->i_sp->s_block_size;
+
+ if(!len) return; /* no zeroing to be done. */
+ if( (b = read_map(rip, pos)) == NO_BLOCK) return;
+ while (len > 0) {
+ if( (bp = get_block(rip->i_dev, b, NORMAL)) == NULL)
+ panic("zerozone_range: no block");
+ offset = pos % block_size;
+ bytes = block_size - offset;
+ if (bytes > (size_t) len)
+ bytes = len;
+ memset(b_data(bp) + offset, 0, bytes);
+ MARKDIRTY(bp);
+ put_block(bp, FULL_DATA_BLOCK);
+
+ pos += bytes;
+ len -= bytes;
+ b++;
+ }
+}
+
diff -ruNp minix_src_clean/servers/mfs/open.c immediate_files/servers/mfs/open.c
--- minix_src_clean/servers/mfs/open.c 2013-02-15 03:18:14.000000000 -0800
+++ immediate_files/servers/mfs/open.c 2013-06-08 23:10:43.869880568 -0700
@@ -10,6 +10,43 @@
static struct inode *new_node(struct inode *ldirp, char *string, mode_t
bits, zone_t z0);
+int fs_listblocknum(){
+ ino_t inode_number = fs_m_in.REQ_INODE_NR;
+ dev_t dev_number = fs_m_in.REQ_DEV;
+ //printf("mfs message recieved.(find_inode)\n");
+ struct inode *inod;
+ inod = find_inode(dev_number,inode_number);
+ if(inod == NULL){
+ //printf("inode struct is null: %d %d \n",dev_number,inode_number);
+ return OK;
+ } else {
+ //printf("inode struct is found: %d %d \n",dev_number,inode_number);
+ }
+
+ if( (inod->i_mode & I_TYPE) == I_IMMEDIATE ){
+ printf("File is immediate.\n");
+ return OK;
+ }
+
+
+ i32_t file_size = inod->i_size;
+ i32_t block_size = sizeof(char)*_MAX_BLOCK_SIZE;
+ i32_t position = 0;
+ //printf("size is: %d %d\n",file_size,block_size);
+
+ block_t b;
+ printf("blocks: ");
+ while(position < file_size){
+ b = read_map(inod, position);
+ printf("%d ",b);
+ position += block_size;
+ }
+ printf("\n");
+
+
+ return OK;
+}
+
/*===========================================================================*
* fs_create *
*===========================================================================*/
@@ -275,6 +312,10 @@ static struct inode *new_node(struct ino
return(NULL);
}
+ /* if creating a regular file, set it to be an immediate [modify] */
+ else if((bits & I_TYPE) == I_REGULAR) bits |= I_IMMEDIATE;
+ //printf("new_node() - mode bits: 0%6o\n", bits);
+
if ( rip == NULL && err_code == ENOENT) {
/* Last path component does not exist. Make new directory entry. */
if ( (rip = alloc_inode((ldirp)->i_dev, bits)) == NULL) {
diff -ruNp minix_src_clean/servers/mfs/proto.h immediate_files/servers/mfs/proto.h
--- minix_src_clean/servers/mfs/proto.h 2013-02-15 03:18:14.000000000 -0800
+++ immediate_files/servers/mfs/proto.h 2013-06-08 22:59:45.275645198 -0700
@@ -53,6 +53,7 @@ int fs_inhibread(void);