-
Notifications
You must be signed in to change notification settings - Fork 2
/
Disk.java
862 lines (736 loc) · 28.2 KB
/
Disk.java
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
package TermProject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.Collections;
import java.util.Vector;
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Collections;
import java.util.Scanner;
/*
1. 문현균
2. 박민근
3. 박민근
4. 문현균
5. 손진우
6. 유승화
7. 유승화
8. 손진우
9. 이인홍
10. 이인홍
*/
class Console{
private SuperBlock sb;
private int select;
private int num;
private int size1,size2;
private int count;
private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
private Disk disk;
Console(SuperBlock sb){
this.sb = sb;
select = -1;
count = 0;
}
public void start(){
while(select != 0){
System.out.println("\n\nFile System Management\n"
+ "0. Quit\t"
+ "1. Make disk\t"
+ "2. Format disk\t"
+ "3. Umount disk\t"
+ "4. Empty space in disk\t"
+ "5. Read file\t"
+ "6. Write file\t"
+ "7. Create file\t"
+ "8. Read file by parallel\t"
+ "9. Delete file\t"
+ "10. Defragment\t"
+ "11. Show disk list\t"
+ "12. Show File list");
try{
System.out.print("Choose menu: ");
select = Integer.parseInt(in.readLine());
if(select > 12 || select < 0){
System.out.println("Out of boundary");
continue;
}
}catch(Exception e){
e.printStackTrace();
}
switch(select){
case 0: System.out.println("System Quit"); break; // 종료
case 1: //초기화
try{
System.out.println("Decide disk number of blocks: ");
size1 = Integer.parseInt(in.readLine());
System.out.println("Decide disk blockSize: ");
size2 = Integer.parseInt(in.readLine());
if(size1 <= 0 || size2 <= 0){
System.out.println("size must be bigger than 0");
break;
}
}catch(Exception e){
e.printStackTrace();
}
disk = new Disk(size1,size2);
sb.diskVector.add(disk);
System.out.println("Disk"+disk.id+" is added successfully\n");
break;
case 2: //format disk
disk = chooseDisk();
if(disk == null){
break;
}
//disk.formatDisk();
System.out.println("Disk got formated successfully");
break;
case 3: //unmount disk
disk = chooseDisk();
if(disk == null){
break;
}
//sb.unmountDisk(disk);
System.out.println("Disk got unmounted successfully");
break;
case 4: //엠티스페이스
disk = chooseDisk();
if(disk == null){
break;
}
System.out.println("Empty space in the disk: " + disk.getFreespace());
break;
case 5: //리드
disk = chooseDisk();
if(disk == null){
break;
}/*
getInodeId(chooseDisk());*/
//----------------------------------------------------------------------------------
int[] buffer;
//Scanner scan = new Scanner(System.in);
int index = 0; // 시작점
int size = 0; // 크기
try {
System.out.println("Enter the index :");
index = Integer.parseInt(in.readLine());
System.out.println("Enter the size :");
size = Integer.parseInt(in.readLine());
} catch (NumberFormatException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// index = scan.nextInt();
// size = scan.nextInt();
buffer = new int[size];
System.out.println("Index and size values are entered.");
buffer = disk.readDisk(index, size);
//return 받은 결과물 출력
if(buffer != null)
{
for(int k=0; k < buffer.length; k++)
{
System.out.println(buffer[k] + " ");
}
}
else
{
System.out.println("Buffer is null");
}
//scan close 시 에러 발생...
//scan.close();
break;
// ---------------------------------------------------------------------
case 6: //라이트
disk = chooseDisk();
if(disk == null){
break;
}
Integer inodeID = getInodeId(disk);
if (inodeID < 0)
continue;
disk.write(inodeID, Disk.scanInput());
break;
case 7: //크리에이트
disk = chooseDisk();
if(disk == null){
break;
}
try {
System.out.print("Enter owner: ");
String _owner = in.readLine();
System.out.print("Enter readOnly permission(0, 1): ");
boolean _readOnly = in.readLine().equals("1");
disk.create(_owner, _readOnly, Disk.scanInput());
} catch (IOException e) {
e.printStackTrace();
System.out.println("File create fail");
}
break;
case 8: //페러럴 리드
disk = chooseDisk();
if(disk == null){
break;
}
int threadNum = 0;
try {
System.out.println("Enter the number of thread you want to create :");
threadNum = Integer.parseInt(in.readLine());
}
catch (NumberFormatException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
for(int i=0; i<threadNum; i++)
{
new Thread("" + i)
{
public void run()
{
int[] buffer;
int index; // 시작점
int size; // 크기
for (int i = 0; i < disk.iNodeIDVector.size(); i++) //조건 맞는 Disk inodeIDVector에서 찾는 루프
{
index = Global.getINODE(disk.iNodeIDVector.get(i)).startPoint;
size = Global.getINODE(disk.iNodeIDVector.get(i)).size;
buffer = new int[size];
for(int j = 0; j < size; j++)
{
buffer[j] = disk.blocks[(j + index) / disk.getBlockSize()][(j + index) % disk.getBlockSize()];
System.out.println("Thread " + getName() + " value : " + buffer[j] + " ");
}
}
}
}.start();
}
break;
case 9: // 딜리트
disk = chooseDisk();
if(disk == null){
break;
}
disk.delete(getInodeId(disk));
break;
case 10: //디프레그먼트
disk = chooseDisk();
if(disk == null){
break;
}
disk.defragment();
break;
case 11: //Show List
System.out.println("Disk id List");
sb.diskVector.forEach(disk1 -> {System.out.print(disk1.id + "\t");});
System.out.println();
break;
case 12: //Show List
disk = chooseDisk();
if(disk == null){
break;
}
for (Integer integer : disk.iNodeIDVector) {
INODE tempINODE = Global.getINODE(integer);
System.out.println("ID: " + tempINODE.id + "\towner: " + tempINODE.owner + "\treadonly: "
+ tempINODE.readOnly + "\tdiskID: " + tempINODE.diskID
+ "\tstartPoint: " + tempINODE.startPoint + "\tsize: " + tempINODE.size);
}
break;
}
}
}
private Disk chooseDisk(){
System.out.println("\nChoose a disk");
for(int i = 0; i< sb.diskVector.size(); i++){
System.out.print(i+ ". Disk" + sb.diskVector.elementAt(i).id + "\t");
}
System.out.println();
try{
System.out.print("Choose menu: ");
num = Integer.parseInt(in.readLine());
if(num >= sb.diskVector.size() || num < 0){
System.out.println("Wrong number");
return null;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
return sb.diskVector.elementAt(num);
}
private Integer getInodeId(Disk disk){
System.out.println("Choose a file");
if (disk.iNodeIDVector.isEmpty()) {
System.out.println("There is no file");
return -1;
}
for(int i = 0; i< disk.iNodeIDVector.size(); i++){
System.out.print(i+ ". FILE" + disk.iNodeIDVector.elementAt(i) + "\t");
}
System.out.println();
try{
System.out.print("Choose menu: ");
num = Integer.parseInt(in.readLine());
if(num >= disk.iNodeIDVector.size() || num < 0){
System.out.println("Wrong number");
return -1;
}
}catch(Exception e){
e.printStackTrace();
return -1;
}
return disk.iNodeIDVector.elementAt(num);
}
}
//전역변수 처럼 사용하기 위함.
class Global {
public static int diskID = 0;
public static int iNodeID = 0;
public static Vector<INODE> iNodeVector = new Vector<>();
public static INODE getINODE(Integer id)
{
for (int i = 0; i < iNodeVector.size(); i++)
{
if (Integer.compare(iNodeVector.get(i).id, id) == 0)
return iNodeVector.get(i);
}
return null;
}
}
//id, startpoint, size 포함
class INODE
{
public final Integer id;
public Integer diskID; //default null
public String owner; //default null
public int startPoint; //default -1
public int size; //default 0
public boolean readOnly; //default false
INODE()
{
id = new Integer(Global.iNodeID++);
startPoint = -1;
Global.iNodeVector.add(this);
}
}
class SuperBlock
{
Vector<Disk> diskVector;
SuperBlock()
{
diskVector = new Vector<>();
}
public Disk getDisk(Integer id)
{
for (int i = 0; i < diskVector.size(); i++)
{
if (Integer.compare(diskVector.get(i).id, id) == 0)
return diskVector.get(i);
}
return null;
}
}
public class Disk extends Thread
{
public final Integer id;
Vector<Integer> iNodeIDVector;
int[][] blocks;
//0. Thread - Run
public void run()
{
System.out.println(Thread.currentThread().getName());
Scanner scan = new Scanner(System.in);
int index; // 시작점
int size; // 크기
System.out.println("Thread :: Enter the index and size :");
index = scan.nextInt();
size = scan.nextInt();
if(this.readDisk(index, size) != null)
{
for(int i=0; i<this.readDisk(index, size).length; i++)
{
System.out.println(this.readDisk(index, size)[i]);
}
}
scan.close();
}
//1. Initialize
Disk(int numBlocks, int blockSize) {
id = new Integer(Global.diskID++);
iNodeIDVector = new Vector<>();
blocks = new int[numBlocks][blockSize];
}
void temp_initial() // 임시 값 부여
{
int k = 0;
for(int i=0; i<this.getNumBlocks();i++) // i : 0 ~ 11
{
for(int j=0; j<this.getBlockSize(); j++)
{
blocks[i][j] = k;
k++;
}
}
}
int getNumBlocks() {
return blocks == null ? 0 : blocks.length;
}
int getBlockSize() {
return getNumBlocks() > 0 ? blocks[0].length : 0;
}
//4. Empty space
int getFreespace() {
return getNumBlocks()*getBlockSize()
- iNodeIDVector.stream().map(i -> Global.getINODE(i).size).mapToInt(i -> i).sum();
}
//5. Read disk
int[] readDisk (int index, int size)
{
int[] buffer = new int[size];
for (int i = 0; i < this.iNodeIDVector.size(); i++) //조건 맞는 Disk inodeIDVector에서 찾는 루프
{
//입력받은 인덱스 값이 StartPoint 와 SP + Size 사이일 경우
if(Global.getINODE(this.iNodeIDVector.get(i)).startPoint + Global.getINODE(this.iNodeIDVector.get(i)).size >= index && Global.getINODE(this.iNodeIDVector.get(i)).startPoint <= index)
{
// 입력받은 인덱스 + 크기 <= StartPoint + Size
if(Global.getINODE(this.iNodeIDVector.get(i)).startPoint + Global.getINODE(this.iNodeIDVector.get(i)).size >= index + size)
{
for(int j = 0; j < size; j++)
{
buffer[j] = this.blocks[(j + index) / this.getBlockSize()][(j + index) % this.getBlockSize()];
}
return buffer;
}
}
}
System.out.println("Error : Out of range");
return null;
}
int getSizeByID(int fileID){
return Global.getINODE(fileID).size;
}
int findStartPoint(int inputSize){
//Set keys = fileMap.keySet();
//List list = new ArrayList(keys);
//Collections.sort(list);
// sorted ID Vector
Vector<Integer> spVector = new Vector(iNodeIDVector.size());
//Vector<Integer> sizeVector = new Vector(iNodeIDVector.size());
HashMap<Integer, Integer> spIDMap = new HashMap();
// sorted start point vector
for (int i = 0; i < iNodeIDVector.size(); i++){
spVector.add(Global.getINODE(iNodeIDVector.elementAt(i)).startPoint);
spIDMap.put(spVector.elementAt(i), iNodeIDVector.elementAt(i));
}
Collections.sort(spVector);
/*
// sorted size vector
for (int i = 0; i < iNodeIDVector.size(); i++){
for (int j = 0; j < iNodeIDVector.size(); i++){
if(spVector.elementAt(j) == Global.iNodeVector.elementAt(j).startPoint){
sizeVector.add(Global.iNodeVector.elementAt(j).size);
break;
}
}
}
*/
int beginning = 0;
int end = getBlockSize() * getNumBlocks();
if (spVector.size() == 0 && end > inputSize ) return 0;
else {
for (int i = 0; i < spVector.size(); i ++){
if (i == 0){
if (inputSize <= spVector.elementAt(i) - beginning)
return beginning;
}
if (i == spVector.size() - 1){
if(inputSize <= end - (spVector.elementAt(i) + getSizeByID(spIDMap.get(spVector.elementAt(i))))) // ë - (ìì + ì¬ì´ì¦)
return (spVector.elementAt(i) + getSizeByID(spIDMap.get(spVector.elementAt(i))));
}
if (i > 0) {
if( inputSize <= spVector.elementAt(i) - (spVector.elementAt(i-1) + getSizeByID(spIDMap.get(spVector.elementAt(i-1))))) // íì¬ íì¼ ìì - ( ì´ì íì¼ ìì + ì´ì íì¼ ì¬ì´ì¦ )
return (spVector.elementAt(i-1) + getSizeByID(spIDMap.get(spVector.elementAt(i-1))));
}
}
}
return -1;
}
void assignBuffer(int startPoint, int inputSize, String[] elem){
// From start point, write
for (int i = startPoint, bufferIdx = 0; i < startPoint + inputSize; i++, bufferIdx++){
int row = i / getBlockSize();
int col = i % getBlockSize();
blocks[row][col] = Integer.parseInt(elem[bufferIdx]);
}
}
void assignBuffer(int startPoint, int inputSize, int[] elem){
// From start point, write
for (int i = startPoint, bufferIdx = 0; i < startPoint + inputSize; i++, bufferIdx++){
int row = i / getBlockSize();
int col = i % getBlockSize();
blocks[row][col] = elem[bufferIdx];
}
}
int[] copy(int startPoint, int size){
int[] arr = new int[size];
for(int i = 0; i < size; i++){
int row = i / getBlockSize();
int col = i % getBlockSize();
arr[i] = blocks[row][col];
}
return arr;
}
void create(String _owner, boolean _readOnly, String[] elem){
int inputSize = elem.length;
// Find start point
int startPoint = findStartPoint(inputSize);
if (startPoint == -1 ) {
System.out.println("Cannot find start point, too big file or defragment is needed");
return;
}
assignBuffer(startPoint, inputSize, elem);
// Create new INODE
INODE create = new INODE();
create.diskID = id;
create.startPoint = startPoint;
create.size = inputSize;
create.owner = _owner;
create.readOnly = _readOnly;
iNodeIDVector.add(create.id);
System.out.println("File created successfully");
}
void write(int fileID, String[] elem){
if (fileID < 0)
return;
if (Global.getINODE(fileID).readOnly) {
System.out.println("This file is readOnly");
return;
}
int fileStartPoint = Global.getINODE(fileID).startPoint;
int fileSize = Global.getINODE(fileID).size;
int inputSize = elem.length;
// sorted Vectors
Vector<Integer> spVector = new Vector(iNodeIDVector.size());
// sorted start point vector
for (int i = 0; i < iNodeIDVector.size(); i++){
spVector.add(Global.getINODE(iNodeIDVector.elementAt(i)).startPoint);
}
Collections.sort(spVector);
// Find index in spVector
int idx = 0; // idx_in_SpVector
for (int i = 0; i < spVector.size(); i++){
if (fileStartPoint == spVector.elementAt(i)){
idx = i;
break;
}
}
// Find free space to append
int space = 0;
if (fileStartPoint == spVector.elementAt(spVector.size() - 1)){
space = getBlockSize() * getNumBlocks() - (fileStartPoint + fileSize);
}
else {
space = spVector.elementAt(idx+1) - (fileStartPoint + fileSize);
}
// Assign buffer on disk
if(space < inputSize) {
int newStartPoint = findStartPoint(fileSize + inputSize);
if (newStartPoint == -1 ){
System.out.println("cannot write anymore");
return;
}
else{
int[] copy = copy(fileStartPoint, fileSize);
assignBuffer(newStartPoint, fileSize, copy);
assignBuffer(newStartPoint + fileSize, inputSize, elem);
Global.getINODE(fileID).startPoint = newStartPoint;
}
}
else{
assignBuffer(fileStartPoint + fileSize, inputSize, elem);
}
int newSize = fileSize + inputSize;
Global.getINODE(fileID).size = newSize;
System.out.println("File written successfully");
}
public static String[] scanInput(){
// Get Inputs ( divided by space )
System.out.print("Enter numbers(separated by space): ");
Scanner scan = new Scanner(System.in);
String inputs;
inputs = scan.nextLine();
String elem[] = inputs.split(" "); // Inputs as string array
return elem;
}
void delete(Integer iNodeID) {
if (iNodeID < 0) {
return;
}
if (Global.getINODE(iNodeID).readOnly) {
System.out.println("This file is readOnly");
return;
}
Global.iNodeVector.remove(Global.getINODE(iNodeID));
iNodeIDVector.remove(iNodeIDVector.indexOf(iNodeID));
System.out.println("File deleted Sucssesfully");
}
void defragment() {
Vector<Integer> temp = new Vector<>();
Vector<INODE> sortedvecter = new Vector<>();
for(int i=0; i<Global.iNodeVector.size(); i++) {
if(Global.iNodeVector.get(i).diskID == this.id) {
temp.add(Global.iNodeVector.get(i).startPoint);
}
}
Collections.sort(temp);
for(int i=0; i<temp.size(); i++) {
for(int j=0; j<Global.iNodeVector.size(); j++) {
if(Global.iNodeVector.get(j).startPoint == temp.get(i)) {
sortedvecter.add(Global.iNodeVector.get(j));
}
}
}
for(int i=0; i<sortedvecter.size(); i++) {
if(i==0) {
if(sortedvecter.get(i).startPoint != 0) {
sortedvecter.get(i).startPoint = 0;
}
}
else {
if(sortedvecter.get(i-1).startPoint+sortedvecter.get(i-1).size != sortedvecter.get(i).startPoint) {
sortedvecter.get(i).startPoint = sortedvecter.get(i-1).startPoint+sortedvecter.get(i-1).size;
}
}
}
for(int i=0; i<sortedvecter.size(); i++) {
for(int j=0; j<Global.iNodeVector.size(); j++) {
if(Global.iNodeVector.get(j).id == sortedvecter.get(i).id) {
for(int k=0; k<sortedvecter.get(i).size; k++) {
int point1 = temp.get(i) + k;
int point2 = Global.iNodeVector.get(j).startPoint + k;
int row1 = point1 / getBlockSize();
int col1 = point1 % getBlockSize();
int row2 = point2 / getBlockSize();
int col2 = point2 % getBlockSize();
blocks[row2][col2] = blocks[row1][col1];
}
}
}
}
System.out.println("Defragment Sucssesfully");
}
public static void main(String[] args) {
Console c = new Console(new SuperBlock());
c.start();
/*
Disk disk1 = new Disk(100, 100);
Disk disk2 = new Disk(100, 100);
String[] elem = scanInput();
disk1.create(elem);
//disk2.create(elem);
disk1.write(0, scanInput());
System.out.println("-------INODE ID---------");
for (int i = 0; i < Global.iNodeVector.size(); i++){
System.out.print(Global.iNodeVector.elementAt(i).id);
System.out.println(" ");
}
System.out.println(disk1.getFreespace());
SuperBlock sb = new SuperBlock();
System.out.println(Thread.currentThread().getName());
for(int i=0; i<3; i++)
{
new Thread("" + i)
{
public void run()
{
int[] buffer;
Scanner scan = new Scanner(System.in);
int disk_index; // 디스크 인덱스
int index; // 시작점
int size; // 크기
disk_index = 0;
index = 3;
size = 5;
buffer = new int[size];
System.out.println("Index and size values are entered.");
buffer = sb.diskVector.elementAt(disk_index).readDisk(index, size);
//return 받은 결과물 출력
if(buffer != null)
{
for(int k=0; k < buffer.length; k++)
{
System.out.println("Thread " + getName() + " value : " + buffer[k] + " ");
}
}
scan.close();
}
}.start();
}
*/
/*public static void main(String[] args)
{
SuperBlock sb = new SuperBlock(); // 슈퍼블록 할당
// 디스크 생성
Disk disk1 = new Disk(3, 4); // NumBlock * BlockSize
Disk disk2 = new Disk(4, 5); //
// diskVector에 disk 1, 2 삽입
sb.diskVector.add(disk1);
sb.diskVector.elementAt(0).temp_initial(); // 값 확인 위한 임시값 대입
sb.diskVector.add(disk2);
sb.diskVector.elementAt(1).temp_initial(); // 값 확인 위한 임시값 대입
// 새 iNode 생성
INODE iNode1 = new INODE();
INODE iNode2 = new INODE();
// iNode 삽입
sb.diskVector.elementAt(0).iNodeIDVector.add(iNode1.id);
sb.diskVector.elementAt(1).iNodeIDVector.add(iNode2.id);
// create 대체
//파일1 에 대한 inode1
iNode1.startPoint = 3;
iNode1.size = 9;
//파일2 에 대한 inode2
iNode2.startPoint = 6;
iNode2.size = 3;
for(int i=0; i<sb.diskVector.size(); i++)
{
System.out.println(sb.diskVector.get(i).getFreespace());
}
// iNode의 정보를 바꾸었을때 sb에서 iNode의 id를 가지고 온 후 Global에서 조회
iNode1.owner = "iNode1 Owner";
//iNode2.owner = "iNode2 Owner";
for (int i = 0; i < sb.diskVector.firstElement().iNodeIDVector.size(); i++)
{
System.out.println(Global.getINODE(sb.diskVector.elementAt(i).iNodeIDVector.get(i)).startPoint + " " + Global.getINODE(sb.diskVector.elementAt(i).iNodeIDVector.get(i)).size);
}*/
//5. Read
/* int[] buffer;
Scanner scan = new Scanner(System.in);
int disk_index; // 디스크 인덱스
int index; // 시작점
int size; // 크기
System.out.println("Enter the disk index you want to read : ");
disk_index = scan.nextInt();
System.out.println("Enter the index and size :");
index = scan.nextInt();
size = scan.nextInt();
buffer = new int[size];
System.out.println("Index and size values are entered.");
buffer = sb.diskVector.elementAt(disk_index).readDisk(index, size);
//return 받은 결과물 출력
if(buffer != null)
{
for(int k=0; k < buffer.length; k++)
{
System.out.println(buffer[k] + " ");
}
}
scan.close();
/* System.out.println(Thread.currentThread().getName());
disk1.start();
disk1.start();*/
}
}