XINU
Functions
lftruncate.c File Reference
#include <xinu.h>
Include dependency graph for lftruncate.c:

Go to the source code of this file.

Functions

status lftruncate (struct lflcblk *lfptr)
 

Function Documentation

◆ lftruncate()

status lftruncate ( struct lflcblk lfptr)

Definition at line 10 of file lftruncate.c.

References lfiblk::ib_dba, lfiblk::ib_next, lfiblk::ib_offset, ldentry::ld_ilist, ldentry::ld_size, LF_BLKSIZ, Lf_data, lfdata::lf_dir, lfdata::lf_dirdirty, LF_DNULL, lfdata::lf_dskdev, LF_IBLEN, LF_INULL, lflcblk::lfbyte, lfdir::lfd_ifree, lflcblk::lfdbdirty, lfdbfree(), lflcblk::lfdblock, lflcblk::lfdirptr, lflcblk::lfdnum, lfflush(), lflcblk::lfibdirty, lfibget(), lfibput(), lflcblk::lfinum, lflcblk::lfpos, OK, and TRUE.

Referenced by lflcontrol().

13 {
14  struct ldentry *ldptr; /* Pointer to file's dir. entry */
15  struct lfiblk iblock; /* Buffer for one index block */
16  ibid32 ifree; /* Start of index blk free list */
17  ibid32 firstib; /* First index blk of the file */
18  ibid32 nextib; /* Walks down list of the */
19  /* file's index blocks */
20  dbid32 nextdb; /* Next data block to free */
21  int32 i; /* Moves through data blocks in */
22  /* a given index block */
23 
24  ldptr = lfptr->lfdirptr; /* Get pointer to dir. entry */
25  if (ldptr->ld_size == 0) { /* File is already empty */
26  return OK;
27  }
28 
29  /* Clean up the open local file first */
30 
31  if ( (lfptr->lfibdirty) || (lfptr->lfdbdirty) ) {
32  lfflush(lfptr);
33  }
34  lfptr->lfpos = 0;
35  lfptr->lfinum = LF_INULL;
36  lfptr->lfdnum = LF_DNULL;
37  lfptr->lfbyte = &lfptr->lfdblock[LF_BLKSIZ];
38 
39  /* Obtain ID of first index block on free list */
40 
41  ifree = Lf_data.lf_dir.lfd_ifree;
42 
43  /* Record file's first i-block and clear directory entry */
44 
45  firstib = ldptr->ld_ilist;
46  ldptr->ld_ilist = LF_INULL;
47  ldptr->ld_size = 0;
49 
50  /* Walk along index block list, disposing of each data block */
51  /* and clearing the corresponding pointer. A note on loop */
52  /* termination: last pointer is set to ifree below. */
53 
54  for (nextib=firstib; nextib!=ifree; nextib=iblock.ib_next) {
55 
56  /* Obtain a copy of current index block from disk */
57 
58  lfibget(Lf_data.lf_dskdev, nextib, &iblock);
59 
60  /* Free each data block in the index block */
61 
62  for (i=0; i<LF_IBLEN; i++) { /* For each d-block */
63 
64  /* Free the data block */
65 
66  nextdb = iblock.ib_dba[i];
67  if (nextdb != LF_DNULL) {
68  lfdbfree(Lf_data.lf_dskdev, nextdb);
69  }
70 
71  /* Clear entry in i-block for this d-block */
72 
73  iblock.ib_dba[i] = LF_DNULL;
74  }
75 
76  /* Clear offset (just to make debugging easier) */
77 
78  iblock.ib_offset = 0;
79 
80  /* For the last index block on the list, make it point */
81  /* to the current free list */
82 
83  if (iblock.ib_next == LF_INULL) {
84  iblock.ib_next = ifree;
85  }
86 
87  /* Write cleared i-block back to disk */
88 
89  lfibput(Lf_data.lf_dskdev, nextib, &iblock);
90  }
91 
92  /* Last index block on the file list now points to first node */
93  /* on the current free list. Once we make the free list */
94  /* point to the first index block on the file list, the */
95  /* entire set of index blocks will be on the free list */
96 
97  Lf_data.lf_dir.lfd_ifree = firstib;
98 
99  /* Indicate that directory has changed and return */
100 
102 
103  return OK;
104 }
int32 dbid32
データブロックID(ファイルシステムで使用する)
Definition: kernel.h:42
char * lfbyte
Definition: lfilesys.h:161
struct ldentry * lfdirptr
Definition: lfilesys.h:147
int32 ibid32
ブロックIDのインデックス(ファイルシステムで使用する)
Definition: kernel.h:40
ibid32 ld_ilist
Definition: lfilesys.h:99
struct lfdata Lf_data
Definition: lfsinit.c:5
ibid32 lfd_ifree
Definition: lfilesys.h:121
did32 lf_dskdev
Definition: lfilesys.h:131
#define OK
処理が成功した場合
Definition: kernel.h:77
#define LF_IBLEN
Definition: lfilesys.h:57
void lfibget(did32, ibid32, struct lfiblk *)
Definition: lfibget.c:10
#define LF_INULL
Definition: lfilesys.h:55
status lfdbfree(did32, dbid32)
Definition: lfdbfree.c:10
ibid32 lfinum
Definition: lfilesys.h:153
#define LF_BLKSIZ
Definition: lfilesys.h:48
struct lfdir lf_dir
Definition: lfilesys.h:134
#define TRUE
Boolean True(1)
Definition: kernel.h:65
dbid32 lfdnum
Definition: lfilesys.h:157
uint32 ld_size
Definition: lfilesys.h:98
bool8 lfdbdirty
Definition: lfilesys.h:166
bool8 lf_dirdirty
Definition: lfilesys.h:137
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define LF_DNULL
Definition: lfilesys.h:56
bool8 lfibdirty
Definition: lfilesys.h:165
uint32 lfpos
Definition: lfilesys.h:150
char lfdblock[LF_BLKSIZ]
Definition: lfilesys.h:159
status lfflush(struct lflcblk *)
Definition: lfflush.c:10
status lfibput(did32, ibid32, struct lfiblk *)
Definition: lfibput.c:10
Here is the call graph for this function:
Here is the caller graph for this function: