1*6a54128fSAndroid Build Coastguard Worker<!DOCTYPE Article PUBLIC "-//Davenport//DTD DocBook V3.0//EN"> 2*6a54128fSAndroid Build Coastguard Worker 3*6a54128fSAndroid Build Coastguard Worker<Article> 4*6a54128fSAndroid Build Coastguard Worker 5*6a54128fSAndroid Build Coastguard Worker<ArtHeader> 6*6a54128fSAndroid Build Coastguard Worker 7*6a54128fSAndroid Build Coastguard Worker<Title>EXT2ED - The Extended-2 filesystem editor - Design and implementation</Title> 8*6a54128fSAndroid Build Coastguard Worker<AUTHOR 9*6a54128fSAndroid Build Coastguard Worker> 10*6a54128fSAndroid Build Coastguard Worker<FirstName>Programmed by Gadi Oxman, with the guide of Avner Lottem</FirstName> 11*6a54128fSAndroid Build Coastguard Worker</AUTHOR 12*6a54128fSAndroid Build Coastguard Worker> 13*6a54128fSAndroid Build Coastguard Worker<PubDate>v0.1, August 3 1995</PubDate> 14*6a54128fSAndroid Build Coastguard Worker 15*6a54128fSAndroid Build Coastguard Worker</ArtHeader> 16*6a54128fSAndroid Build Coastguard Worker 17*6a54128fSAndroid Build Coastguard Worker<Sect1> 18*6a54128fSAndroid Build Coastguard Worker<Title>About EXT2ED documentation</Title> 19*6a54128fSAndroid Build Coastguard Worker 20*6a54128fSAndroid Build Coastguard Worker<Para> 21*6a54128fSAndroid Build Coastguard WorkerThe EXT2ED documentation consists of three parts: 22*6a54128fSAndroid Build Coastguard Worker 23*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 24*6a54128fSAndroid Build Coastguard Worker<ListItem> 25*6a54128fSAndroid Build Coastguard Worker 26*6a54128fSAndroid Build Coastguard Worker<Para> 27*6a54128fSAndroid Build Coastguard Worker The ext2 filesystem overview. 28*6a54128fSAndroid Build Coastguard Worker</Para> 29*6a54128fSAndroid Build Coastguard Worker</ListItem> 30*6a54128fSAndroid Build Coastguard Worker<ListItem> 31*6a54128fSAndroid Build Coastguard Worker 32*6a54128fSAndroid Build Coastguard Worker<Para> 33*6a54128fSAndroid Build Coastguard Worker The EXT2ED user's guide. 34*6a54128fSAndroid Build Coastguard Worker</Para> 35*6a54128fSAndroid Build Coastguard Worker</ListItem> 36*6a54128fSAndroid Build Coastguard Worker<ListItem> 37*6a54128fSAndroid Build Coastguard Worker 38*6a54128fSAndroid Build Coastguard Worker<Para> 39*6a54128fSAndroid Build Coastguard Worker The EXT2ED design and implementation. 40*6a54128fSAndroid Build Coastguard Worker</Para> 41*6a54128fSAndroid Build Coastguard Worker</ListItem> 42*6a54128fSAndroid Build Coastguard Worker 43*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 44*6a54128fSAndroid Build Coastguard Worker 45*6a54128fSAndroid Build Coastguard Worker</Para> 46*6a54128fSAndroid Build Coastguard Worker 47*6a54128fSAndroid Build Coastguard Worker<Para> 48*6a54128fSAndroid Build Coastguard WorkerThis document is not the user's guide. If you just intend to use EXT2ED, you 49*6a54128fSAndroid Build Coastguard Workermay not want to read it. 50*6a54128fSAndroid Build Coastguard Worker</Para> 51*6a54128fSAndroid Build Coastguard Worker 52*6a54128fSAndroid Build Coastguard Worker<Para> 53*6a54128fSAndroid Build Coastguard WorkerHowever, if you intend to browse and modify the source code, this document is 54*6a54128fSAndroid Build Coastguard Workerfor you. 55*6a54128fSAndroid Build Coastguard Worker</Para> 56*6a54128fSAndroid Build Coastguard Worker 57*6a54128fSAndroid Build Coastguard Worker<Para> 58*6a54128fSAndroid Build Coastguard WorkerIn any case, If you intend to read this article, I strongly suggest that you 59*6a54128fSAndroid Build Coastguard Workerwill be familiar with the material presented in the other two articles as well. 60*6a54128fSAndroid Build Coastguard Worker</Para> 61*6a54128fSAndroid Build Coastguard Worker 62*6a54128fSAndroid Build Coastguard Worker</Sect1> 63*6a54128fSAndroid Build Coastguard Worker 64*6a54128fSAndroid Build Coastguard Worker<Sect1> 65*6a54128fSAndroid Build Coastguard Worker<Title>Preface</Title> 66*6a54128fSAndroid Build Coastguard Worker 67*6a54128fSAndroid Build Coastguard Worker<Para> 68*6a54128fSAndroid Build Coastguard WorkerIn this document I will try to explain how EXT2ED is constructed. 69*6a54128fSAndroid Build Coastguard WorkerAt this time of writing, the initial version is finished and ready 70*6a54128fSAndroid Build Coastguard Workerfor distribution; It is fully functional. However, this was not always the 71*6a54128fSAndroid Build Coastguard Workercase. 72*6a54128fSAndroid Build Coastguard Worker</Para> 73*6a54128fSAndroid Build Coastguard Worker 74*6a54128fSAndroid Build Coastguard Worker<Para> 75*6a54128fSAndroid Build Coastguard WorkerAt first, I didn't know much about Unix, much less about Unix filesystems, 76*6a54128fSAndroid Build Coastguard Workerand even less about Linux and the extended-2 filesystem. While working 77*6a54128fSAndroid Build Coastguard Workeron this project, I gradually acquired knowledge about all of the above 78*6a54128fSAndroid Build Coastguard Workersubjects. I can think of two ways in which I could have made my project: 79*6a54128fSAndroid Build Coastguard Worker 80*6a54128fSAndroid Build Coastguard Worker<OrderedList> 81*6a54128fSAndroid Build Coastguard Worker<ListItem> 82*6a54128fSAndroid Build Coastguard Worker 83*6a54128fSAndroid Build Coastguard Worker<Para> 84*6a54128fSAndroid Build Coastguard Worker The "Engineer" way 85*6a54128fSAndroid Build Coastguard Worker 86*6a54128fSAndroid Build Coastguard WorkerLearn the subject thoroughly before I get to the programming itself. 87*6a54128fSAndroid Build Coastguard WorkerThen, I could easily see the entire picture and select the best 88*6a54128fSAndroid Build Coastguard Workercourse of action, taking all the factors into account. 89*6a54128fSAndroid Build Coastguard Worker</Para> 90*6a54128fSAndroid Build Coastguard Worker</ListItem> 91*6a54128fSAndroid Build Coastguard Worker<ListItem> 92*6a54128fSAndroid Build Coastguard Worker 93*6a54128fSAndroid Build Coastguard Worker<Para> 94*6a54128fSAndroid Build Coastguard Worker The "Explorer - Progressive" way. 95*6a54128fSAndroid Build Coastguard Worker 96*6a54128fSAndroid Build Coastguard WorkerJump immediately into the cold water - Start programming and 97*6a54128fSAndroid Build Coastguard Workerlearning the material in parallel. 98*6a54128fSAndroid Build Coastguard Worker</Para> 99*6a54128fSAndroid Build Coastguard Worker</ListItem> 100*6a54128fSAndroid Build Coastguard Worker 101*6a54128fSAndroid Build Coastguard Worker</OrderedList> 102*6a54128fSAndroid Build Coastguard Worker 103*6a54128fSAndroid Build Coastguard Worker</Para> 104*6a54128fSAndroid Build Coastguard Worker 105*6a54128fSAndroid Build Coastguard Worker<Para> 106*6a54128fSAndroid Build Coastguard WorkerI guess that the above dilemma is typical and appears all through science and 107*6a54128fSAndroid Build Coastguard Workertechnology. 108*6a54128fSAndroid Build Coastguard Worker</Para> 109*6a54128fSAndroid Build Coastguard Worker 110*6a54128fSAndroid Build Coastguard Worker<Para> 111*6a54128fSAndroid Build Coastguard WorkerHowever, I didn't have the luxury of choice when I started my project - 112*6a54128fSAndroid Build Coastguard WorkerLinux is a relatively new (and great!) operating system. The extended-2 113*6a54128fSAndroid Build Coastguard Workerfilesystem is even newer - Its first release lies somewhere in 1993 - Only 114*6a54128fSAndroid Build Coastguard Workerpassed two years until I started working on my project. 115*6a54128fSAndroid Build Coastguard Worker</Para> 116*6a54128fSAndroid Build Coastguard Worker 117*6a54128fSAndroid Build Coastguard Worker<Para> 118*6a54128fSAndroid Build Coastguard WorkerThe situation I found myself at the beginning was that I didn't have a fully 119*6a54128fSAndroid Build Coastguard Workerdetailed document which describes the ext2 filesystem. In fact, I didn't 120*6a54128fSAndroid Build Coastguard Workerhave any ext2 document at all. When I asked Avner about documentation, he 121*6a54128fSAndroid Build Coastguard Workersuggested two references: 122*6a54128fSAndroid Build Coastguard Worker 123*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 124*6a54128fSAndroid Build Coastguard Worker<ListItem> 125*6a54128fSAndroid Build Coastguard Worker 126*6a54128fSAndroid Build Coastguard Worker<Para> 127*6a54128fSAndroid Build Coastguard Worker A general Unix book - THE DESIGN OF THE UNIX OPERATING SYSTEM, by 128*6a54128fSAndroid Build Coastguard WorkerMaurice J. Bach. 129*6a54128fSAndroid Build Coastguard Worker</Para> 130*6a54128fSAndroid Build Coastguard Worker</ListItem> 131*6a54128fSAndroid Build Coastguard Worker<ListItem> 132*6a54128fSAndroid Build Coastguard Worker 133*6a54128fSAndroid Build Coastguard Worker<Para> 134*6a54128fSAndroid Build Coastguard Worker The kernel sources. 135*6a54128fSAndroid Build Coastguard Worker</Para> 136*6a54128fSAndroid Build Coastguard Worker</ListItem> 137*6a54128fSAndroid Build Coastguard Worker 138*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 139*6a54128fSAndroid Build Coastguard Worker 140*6a54128fSAndroid Build Coastguard WorkerI read the relevant parts of the book before I started my project - It is a 141*6a54128fSAndroid Build Coastguard Workerbit old now, but the principles are still the same. However, I needed 142*6a54128fSAndroid Build Coastguard Workermore than just the principles. 143*6a54128fSAndroid Build Coastguard Worker</Para> 144*6a54128fSAndroid Build Coastguard Worker 145*6a54128fSAndroid Build Coastguard Worker<Para> 146*6a54128fSAndroid Build Coastguard WorkerThe kernel sources are a rare bonus! You don't get everyday the full 147*6a54128fSAndroid Build Coastguard Workersources of the operating system. There is so much that can be learned from 148*6a54128fSAndroid Build Coastguard Workerthem, and it is the ultimate source - The exact answer how the kernel 149*6a54128fSAndroid Build Coastguard Workerworks is there, with all the fine details. At the first week I started to 150*6a54128fSAndroid Build Coastguard Workerlook at random at the relevant parts of the sources. However, it is difficult 151*6a54128fSAndroid Build Coastguard Workerto understand the global picture from direct reading of over one hundred 152*6a54128fSAndroid Build Coastguard Workerpage sources. Then, I started to do some programming. I didn't know 153*6a54128fSAndroid Build Coastguard Workeryet what I was looking for, and I started to work on the project like a kid 154*6a54128fSAndroid Build Coastguard Workerwho starts to build a large puzzle. 155*6a54128fSAndroid Build Coastguard Worker</Para> 156*6a54128fSAndroid Build Coastguard Worker 157*6a54128fSAndroid Build Coastguard Worker<Para> 158*6a54128fSAndroid Build Coastguard WorkerHowever, this was exactly the interesting part! It is frustrating to know 159*6a54128fSAndroid Build Coastguard Workerit all from advance - I think that the discovery itself, bit by bit, is the 160*6a54128fSAndroid Build Coastguard Workerkey to a true learning and understanding. 161*6a54128fSAndroid Build Coastguard Worker</Para> 162*6a54128fSAndroid Build Coastguard Worker 163*6a54128fSAndroid Build Coastguard Worker<Para> 164*6a54128fSAndroid Build Coastguard WorkerNow, in this document, I am trying to present the subject. Even though I 165*6a54128fSAndroid Build Coastguard Workerdeveloped EXT2ED progressively, I now can see the entire subject much 166*6a54128fSAndroid Build Coastguard Workerbrighter than I did before, and though I do have the option of presenting it 167*6a54128fSAndroid Build Coastguard Workeronly in the "engineer" way. However, I will not do that. 168*6a54128fSAndroid Build Coastguard Worker</Para> 169*6a54128fSAndroid Build Coastguard Worker 170*6a54128fSAndroid Build Coastguard Worker<Para> 171*6a54128fSAndroid Build Coastguard WorkerMy presentation will be mixed - Sometimes I will present a subject with an 172*6a54128fSAndroid Build Coastguard Workerincremental perspective, and sometimes from a "top down" view. I'll leave 173*6a54128fSAndroid Build Coastguard Workeryou to decide if my presentation choice was wise :-) 174*6a54128fSAndroid Build Coastguard Worker</Para> 175*6a54128fSAndroid Build Coastguard Worker 176*6a54128fSAndroid Build Coastguard Worker<Para> 177*6a54128fSAndroid Build Coastguard WorkerIn addition, you'll notice that the sections tend to get shorter as we get 178*6a54128fSAndroid Build Coastguard Workercloser to the end. The reason is simply that I started to feel that I was 179*6a54128fSAndroid Build Coastguard Workerrepeating myself so I decided to present only the new ideas. 180*6a54128fSAndroid Build Coastguard Worker</Para> 181*6a54128fSAndroid Build Coastguard Worker 182*6a54128fSAndroid Build Coastguard Worker</Sect1> 183*6a54128fSAndroid Build Coastguard Worker 184*6a54128fSAndroid Build Coastguard Worker<Sect1> 185*6a54128fSAndroid Build Coastguard Worker<Title>Getting started ...</Title> 186*6a54128fSAndroid Build Coastguard Worker 187*6a54128fSAndroid Build Coastguard Worker<Para> 188*6a54128fSAndroid Build Coastguard WorkerGetting started is almost always the most difficult task. Once you get 189*6a54128fSAndroid Build Coastguard Workerstarted, things start "running" ... 190*6a54128fSAndroid Build Coastguard Worker</Para> 191*6a54128fSAndroid Build Coastguard Worker 192*6a54128fSAndroid Build Coastguard Worker<Sect2> 193*6a54128fSAndroid Build Coastguard Worker<Title>Before the actual programming</Title> 194*6a54128fSAndroid Build Coastguard Worker 195*6a54128fSAndroid Build Coastguard Worker<Para> 196*6a54128fSAndroid Build Coastguard WorkerFrom mine talking with Avner, I understood that Linux, like any other Unix 197*6a54128fSAndroid Build Coastguard Workersystem, provides accesses to the entire disk as though it were a general 198*6a54128fSAndroid Build Coastguard Workerfile - Accessing the device. It is surely a nice idea. Avner suggested two 199*6a54128fSAndroid Build Coastguard Workerways of action: 200*6a54128fSAndroid Build Coastguard Worker 201*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 202*6a54128fSAndroid Build Coastguard Worker<ListItem> 203*6a54128fSAndroid Build Coastguard Worker 204*6a54128fSAndroid Build Coastguard Worker<Para> 205*6a54128fSAndroid Build Coastguard Worker Opening the device like a regular file in the user space. 206*6a54128fSAndroid Build Coastguard Worker</Para> 207*6a54128fSAndroid Build Coastguard Worker</ListItem> 208*6a54128fSAndroid Build Coastguard Worker<ListItem> 209*6a54128fSAndroid Build Coastguard Worker 210*6a54128fSAndroid Build Coastguard Worker<Para> 211*6a54128fSAndroid Build Coastguard Worker Constructing a device driver which will run in the kernel space and 212*6a54128fSAndroid Build Coastguard Workerprovide hooks for the user space program. The advantage is that it 213*6a54128fSAndroid Build Coastguard Workerwill be a part of the kernel, and would be able to use the ext2 214*6a54128fSAndroid Build Coastguard Workerkernel functions to do some of the work. 215*6a54128fSAndroid Build Coastguard Worker</Para> 216*6a54128fSAndroid Build Coastguard Worker</ListItem> 217*6a54128fSAndroid Build Coastguard Worker 218*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 219*6a54128fSAndroid Build Coastguard Worker 220*6a54128fSAndroid Build Coastguard WorkerI chose the first way. I think that the basic reason was simplicity - Learning 221*6a54128fSAndroid Build Coastguard Workerthe ext2 filesystem was complicated enough, and adding to it the task of 222*6a54128fSAndroid Build Coastguard Workerlearning how to program in the kernel space was too much. I still don't know 223*6a54128fSAndroid Build Coastguard Workerhow to program a device driver, and this is perhaps the bad part, but 224*6a54128fSAndroid Build Coastguard Workerconcerning the project in a back-perspective, I think that the first way is 225*6a54128fSAndroid Build Coastguard Workersuperior to the second; Ironically, because of the very reason I chose it - 226*6a54128fSAndroid Build Coastguard WorkerSimplicity. EXT2ED can now run entirely in the user space (which I think is 227*6a54128fSAndroid Build Coastguard Workera point in favor, because it doesn't require the user to recompile its 228*6a54128fSAndroid Build Coastguard Workerkernel), and the entire hard work is mine, which fitted nicely into the 229*6a54128fSAndroid Build Coastguard Workerlearning experience - I didn't use other code to do the job (aside from 230*6a54128fSAndroid Build Coastguard Workerlooking at the sources, of-course). 231*6a54128fSAndroid Build Coastguard Worker</Para> 232*6a54128fSAndroid Build Coastguard Worker 233*6a54128fSAndroid Build Coastguard Worker</Sect2> 234*6a54128fSAndroid Build Coastguard Worker 235*6a54128fSAndroid Build Coastguard Worker<Sect2> 236*6a54128fSAndroid Build Coastguard Worker<Title>Jumping into the cold water</Title> 237*6a54128fSAndroid Build Coastguard Worker 238*6a54128fSAndroid Build Coastguard Worker<Para> 239*6a54128fSAndroid Build Coastguard WorkerI didn't know almost anything of the structure of the ext2 filesystem. 240*6a54128fSAndroid Build Coastguard WorkerReading the sources was not enough - I needed to experiment. However, a tool 241*6a54128fSAndroid Build Coastguard Workerfor experiments in the ext2 filesystem was exactly my project! - Kind of a 242*6a54128fSAndroid Build Coastguard Workerparadox. 243*6a54128fSAndroid Build Coastguard Worker</Para> 244*6a54128fSAndroid Build Coastguard Worker 245*6a54128fSAndroid Build Coastguard Worker<Para> 246*6a54128fSAndroid Build Coastguard WorkerI started immediately with constructing a simple <Literal remap="tt">hex editor</Literal> - It would 247*6a54128fSAndroid Build Coastguard Workeropen the device as a regular file, provide means of moving inside the 248*6a54128fSAndroid Build Coastguard Workerfilesystem with a simple <Literal remap="tt">offset</Literal> method, and just show a 249*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt"> hex dump</Literal> of the contents at this point. Programming this was trivially 250*6a54128fSAndroid Build Coastguard Workersimple of-course. At this point, the user-interface didn't matter to me - I 251*6a54128fSAndroid Build Coastguard Workerwanted a fast way to interact. As a result, I chose a simple command line 252*6a54128fSAndroid Build Coastguard Workerparser. Of course, there where no windows at this point. 253*6a54128fSAndroid Build Coastguard Worker</Para> 254*6a54128fSAndroid Build Coastguard Worker 255*6a54128fSAndroid Build Coastguard Worker<Para> 256*6a54128fSAndroid Build Coastguard WorkerA hex editor is nice, but is not enough. It indeed enabled me to see each part 257*6a54128fSAndroid Build Coastguard Workerof the filesystem, but the format of the viewed data was difficult to 258*6a54128fSAndroid Build Coastguard Workeranalyze. I wanted to see the data in a more intuitive way. 259*6a54128fSAndroid Build Coastguard Worker</Para> 260*6a54128fSAndroid Build Coastguard Worker 261*6a54128fSAndroid Build Coastguard Worker<Para> 262*6a54128fSAndroid Build Coastguard WorkerAt this point of time, the most helpful file in the sources was the ext2 263*6a54128fSAndroid Build Coastguard Workermain include file - <Literal remap="tt">/usr/include/linux/ext2_fs.h</Literal>. Among its contents 264*6a54128fSAndroid Build Coastguard Workerthere were various structures which I assumed they are disk images - Appear 265*6a54128fSAndroid Build Coastguard Workerexactly like that on the disk. 266*6a54128fSAndroid Build Coastguard Worker</Para> 267*6a54128fSAndroid Build Coastguard Worker 268*6a54128fSAndroid Build Coastguard Worker<Para> 269*6a54128fSAndroid Build Coastguard WorkerI wanted a <Literal remap="tt">quick</Literal> way to get going. I didn't have the patience to learn 270*6a54128fSAndroid Build Coastguard Workereach of the structures use in the code. Rather, I wanted to see them in action, 271*6a54128fSAndroid Build Coastguard Workerso that I could explore the connections between them - Test my assumptions, 272*6a54128fSAndroid Build Coastguard Workerand reach other assumptions. 273*6a54128fSAndroid Build Coastguard Worker</Para> 274*6a54128fSAndroid Build Coastguard Worker 275*6a54128fSAndroid Build Coastguard Worker<Para> 276*6a54128fSAndroid Build Coastguard WorkerSo after the <Literal remap="tt">hex editor</Literal>, EXT2ED progressed into a tool which has some 277*6a54128fSAndroid Build Coastguard Workerelements of a compiler. I programmed EXT2ED to <Literal remap="tt">dynamically read the kernel 278*6a54128fSAndroid Build Coastguard Workerext2 main include file in run time</Literal>, and process the information. The goal 279*6a54128fSAndroid Build Coastguard Workerwas to <Literal remap="tt">imply a structure-definition on the current offset at the 280*6a54128fSAndroid Build Coastguard Workerfilesystem</Literal>. EXT2ED would then display the structure as a list of its 281*6a54128fSAndroid Build Coastguard Workervariables names and contents, instead of a meaningless hex dump. 282*6a54128fSAndroid Build Coastguard Worker</Para> 283*6a54128fSAndroid Build Coastguard Worker 284*6a54128fSAndroid Build Coastguard Worker<Para> 285*6a54128fSAndroid Build Coastguard WorkerThe format of the include file is not very complicated - The structures 286*6a54128fSAndroid Build Coastguard Workerare mostly <Literal remap="tt">flat</Literal> - Didn't contain a lot of recursive structure; Only a 287*6a54128fSAndroid Build Coastguard Workerglobal structure definition, and some variables. There were cases of 288*6a54128fSAndroid Build Coastguard Workerstructures inside structures, I treated them in a somewhat non-elegant way - I 289*6a54128fSAndroid Build Coastguard Workermade all the structures flat, and expanded the arrays. As a result, the parser 290*6a54128fSAndroid Build Coastguard Workerwas very simple. After all, this was not an exercise in compiling, and I 291*6a54128fSAndroid Build Coastguard Workerwanted to quickly get some results. 292*6a54128fSAndroid Build Coastguard Worker</Para> 293*6a54128fSAndroid Build Coastguard Worker 294*6a54128fSAndroid Build Coastguard Worker<Para> 295*6a54128fSAndroid Build Coastguard WorkerTo handle the task, I constructed the <Literal remap="tt">struct_descriptor</Literal> structure. 296*6a54128fSAndroid Build Coastguard WorkerEach <Literal remap="tt">struct_descriptor instance</Literal> contained information which is needed 297*6a54128fSAndroid Build Coastguard Workerin order to format a block of data according to the C structure contained in 298*6a54128fSAndroid Build Coastguard Workerthe kernel source. The information contained: 299*6a54128fSAndroid Build Coastguard Worker 300*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 301*6a54128fSAndroid Build Coastguard Worker<ListItem> 302*6a54128fSAndroid Build Coastguard Worker 303*6a54128fSAndroid Build Coastguard Worker<Para> 304*6a54128fSAndroid Build Coastguard Worker The descriptor name, used to reference to the structure in EXT2ED. 305*6a54128fSAndroid Build Coastguard Worker</Para> 306*6a54128fSAndroid Build Coastguard Worker</ListItem> 307*6a54128fSAndroid Build Coastguard Worker<ListItem> 308*6a54128fSAndroid Build Coastguard Worker 309*6a54128fSAndroid Build Coastguard Worker<Para> 310*6a54128fSAndroid Build Coastguard Worker The name of each variable. 311*6a54128fSAndroid Build Coastguard Worker</Para> 312*6a54128fSAndroid Build Coastguard Worker</ListItem> 313*6a54128fSAndroid Build Coastguard Worker<ListItem> 314*6a54128fSAndroid Build Coastguard Worker 315*6a54128fSAndroid Build Coastguard Worker<Para> 316*6a54128fSAndroid Build Coastguard Worker The relative offset of the each variable in the data block. 317*6a54128fSAndroid Build Coastguard Worker</Para> 318*6a54128fSAndroid Build Coastguard Worker</ListItem> 319*6a54128fSAndroid Build Coastguard Worker<ListItem> 320*6a54128fSAndroid Build Coastguard Worker 321*6a54128fSAndroid Build Coastguard Worker<Para> 322*6a54128fSAndroid Build Coastguard Worker The length, in bytes, of each variable. 323*6a54128fSAndroid Build Coastguard Worker</Para> 324*6a54128fSAndroid Build Coastguard Worker</ListItem> 325*6a54128fSAndroid Build Coastguard Worker 326*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 327*6a54128fSAndroid Build Coastguard Worker 328*6a54128fSAndroid Build Coastguard WorkerSince I didn't want to limit the number of structures, I chose a simple 329*6a54128fSAndroid Build Coastguard Workerdouble linked list to store the information. One variable contained the 330*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">current structure type</Literal> - A pointer to the relevant 331*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct_descriptor</Literal>. 332*6a54128fSAndroid Build Coastguard Worker</Para> 333*6a54128fSAndroid Build Coastguard Worker 334*6a54128fSAndroid Build Coastguard Worker<Para> 335*6a54128fSAndroid Build Coastguard WorkerNow EXT2ED contained basically three command line operations: 336*6a54128fSAndroid Build Coastguard Worker 337*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 338*6a54128fSAndroid Build Coastguard Worker<ListItem> 339*6a54128fSAndroid Build Coastguard Worker 340*6a54128fSAndroid Build Coastguard Worker<Para> 341*6a54128fSAndroid Build Coastguard Worker setdevice 342*6a54128fSAndroid Build Coastguard Worker 343*6a54128fSAndroid Build Coastguard WorkerUsed to open a device for reading only. Write access was postponed 344*6a54128fSAndroid Build Coastguard Workerto a very advanced state in the project, simply because I didn't 345*6a54128fSAndroid Build Coastguard Workerknow a thing of the filesystem structure, and I believed that 346*6a54128fSAndroid Build Coastguard Workermaking actual changes would do nothing but damage :-) 347*6a54128fSAndroid Build Coastguard Worker</Para> 348*6a54128fSAndroid Build Coastguard Worker</ListItem> 349*6a54128fSAndroid Build Coastguard Worker<ListItem> 350*6a54128fSAndroid Build Coastguard Worker 351*6a54128fSAndroid Build Coastguard Worker<Para> 352*6a54128fSAndroid Build Coastguard Worker setoffset 353*6a54128fSAndroid Build Coastguard Worker 354*6a54128fSAndroid Build Coastguard WorkerUsed to move in the device. 355*6a54128fSAndroid Build Coastguard Worker</Para> 356*6a54128fSAndroid Build Coastguard Worker</ListItem> 357*6a54128fSAndroid Build Coastguard Worker<ListItem> 358*6a54128fSAndroid Build Coastguard Worker 359*6a54128fSAndroid Build Coastguard Worker<Para> 360*6a54128fSAndroid Build Coastguard Worker settype 361*6a54128fSAndroid Build Coastguard Worker 362*6a54128fSAndroid Build Coastguard WorkerUsed to imply a structure definition on the current place. 363*6a54128fSAndroid Build Coastguard Worker</Para> 364*6a54128fSAndroid Build Coastguard Worker</ListItem> 365*6a54128fSAndroid Build Coastguard Worker<ListItem> 366*6a54128fSAndroid Build Coastguard Worker 367*6a54128fSAndroid Build Coastguard Worker<Para> 368*6a54128fSAndroid Build Coastguard Worker show 369*6a54128fSAndroid Build Coastguard Worker 370*6a54128fSAndroid Build Coastguard WorkerUsed to display the data. It displayed the data in a simple hex dump 371*6a54128fSAndroid Build Coastguard Workerif there was no type set, or in a nice formatted way - As a list of 372*6a54128fSAndroid Build Coastguard Workerthe variable contents, if there was. 373*6a54128fSAndroid Build Coastguard Worker</Para> 374*6a54128fSAndroid Build Coastguard Worker</ListItem> 375*6a54128fSAndroid Build Coastguard Worker 376*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 377*6a54128fSAndroid Build Coastguard Worker 378*6a54128fSAndroid Build Coastguard Worker</Para> 379*6a54128fSAndroid Build Coastguard Worker 380*6a54128fSAndroid Build Coastguard Worker<Para> 381*6a54128fSAndroid Build Coastguard WorkerCommand line analyzing was primitive back then - A simple switch, as far as 382*6a54128fSAndroid Build Coastguard WorkerI can remember - Nothing alike the current flow control, but it was enough 383*6a54128fSAndroid Build Coastguard Workerat the time. 384*6a54128fSAndroid Build Coastguard Worker</Para> 385*6a54128fSAndroid Build Coastguard Worker 386*6a54128fSAndroid Build Coastguard Worker<Para> 387*6a54128fSAndroid Build Coastguard WorkerAt the end, I had something to start working with. It knew to format many 388*6a54128fSAndroid Build Coastguard Workerstructures - None of which I understood - and provided me, without too much 389*6a54128fSAndroid Build Coastguard Workerwork, something to start with. 390*6a54128fSAndroid Build Coastguard Worker</Para> 391*6a54128fSAndroid Build Coastguard Worker 392*6a54128fSAndroid Build Coastguard Worker</Sect2> 393*6a54128fSAndroid Build Coastguard Worker 394*6a54128fSAndroid Build Coastguard Worker</Sect1> 395*6a54128fSAndroid Build Coastguard Worker 396*6a54128fSAndroid Build Coastguard Worker<Sect1> 397*6a54128fSAndroid Build Coastguard Worker<Title>Starting to explore</Title> 398*6a54128fSAndroid Build Coastguard Worker 399*6a54128fSAndroid Build Coastguard Worker<Para> 400*6a54128fSAndroid Build Coastguard WorkerWith the above tool in my pocket, I started to explore the ext2 filesystem 401*6a54128fSAndroid Build Coastguard Workerstructure. From the brief reading in Bach's book, I got familiar to some 402*6a54128fSAndroid Build Coastguard Workerbasic concepts - The <Literal remap="tt">superblock</Literal>, for example. It seems that the 403*6a54128fSAndroid Build Coastguard Workersuperblock is an important part of the filesystem. I decided to start 404*6a54128fSAndroid Build Coastguard Workerexploring with that. 405*6a54128fSAndroid Build Coastguard Worker</Para> 406*6a54128fSAndroid Build Coastguard Worker 407*6a54128fSAndroid Build Coastguard Worker<Para> 408*6a54128fSAndroid Build Coastguard WorkerI realized that the superblock should be at a fixed location in the 409*6a54128fSAndroid Build Coastguard Workerfilesystem - Probably near the beginning. There can be no other way - 410*6a54128fSAndroid Build Coastguard WorkerThe kernel should start at some place to find it. A brief looking in 411*6a54128fSAndroid Build Coastguard Workerthe kernel sources revealed that the superblock is signed by a special 412*6a54128fSAndroid Build Coastguard Workersignature - A <Literal remap="tt">magic number</Literal> - EXT2_SUPER_MAGIC (0xEF53 - EF probably 413*6a54128fSAndroid Build Coastguard Workerstands for Extended Filesystem). I quickly found the superblock at the 414*6a54128fSAndroid Build Coastguard Workerfixed offset 1024 in the filesystem - The <Literal remap="tt">s_magic</Literal> variable in the 415*6a54128fSAndroid Build Coastguard Workersuperblock was set exactly to the above value. 416*6a54128fSAndroid Build Coastguard Worker</Para> 417*6a54128fSAndroid Build Coastguard Worker 418*6a54128fSAndroid Build Coastguard Worker<Para> 419*6a54128fSAndroid Build Coastguard WorkerIt seems that starting with the <Literal remap="tt">superblock</Literal> was a good bet - Just from 420*6a54128fSAndroid Build Coastguard Workerthe list of variables, one can learn a lot. I didn't understand all of them 421*6a54128fSAndroid Build Coastguard Workerat the time, but it seemed that the following keywords were repeating themselves 422*6a54128fSAndroid Build Coastguard Workerin various variables: 423*6a54128fSAndroid Build Coastguard Worker 424*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 425*6a54128fSAndroid Build Coastguard Worker<ListItem> 426*6a54128fSAndroid Build Coastguard Worker 427*6a54128fSAndroid Build Coastguard Worker<Para> 428*6a54128fSAndroid Build Coastguard Worker block 429*6a54128fSAndroid Build Coastguard Worker</Para> 430*6a54128fSAndroid Build Coastguard Worker</ListItem> 431*6a54128fSAndroid Build Coastguard Worker<ListItem> 432*6a54128fSAndroid Build Coastguard Worker 433*6a54128fSAndroid Build Coastguard Worker<Para> 434*6a54128fSAndroid Build Coastguard Worker inode 435*6a54128fSAndroid Build Coastguard Worker</Para> 436*6a54128fSAndroid Build Coastguard Worker</ListItem> 437*6a54128fSAndroid Build Coastguard Worker<ListItem> 438*6a54128fSAndroid Build Coastguard Worker 439*6a54128fSAndroid Build Coastguard Worker<Para> 440*6a54128fSAndroid Build Coastguard Worker group 441*6a54128fSAndroid Build Coastguard Worker</Para> 442*6a54128fSAndroid Build Coastguard Worker</ListItem> 443*6a54128fSAndroid Build Coastguard Worker 444*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 445*6a54128fSAndroid Build Coastguard Worker 446*6a54128fSAndroid Build Coastguard WorkerAt this point, I started to explore the block groups. I will not detail here 447*6a54128fSAndroid Build Coastguard Workerthe technical design of the ext2 filesystem. I have written a special 448*6a54128fSAndroid Build Coastguard Workerarticle which explains just that, in the "engineering" way. Please refer to it 449*6a54128fSAndroid Build Coastguard Workerif you feel that you are lacking knowledge in the structure of the ext2 450*6a54128fSAndroid Build Coastguard Workerfilesystem. 451*6a54128fSAndroid Build Coastguard Worker</Para> 452*6a54128fSAndroid Build Coastguard Worker 453*6a54128fSAndroid Build Coastguard Worker<Para> 454*6a54128fSAndroid Build Coastguard WorkerI was exploring the filesystem in this way for some time, along with reading 455*6a54128fSAndroid Build Coastguard Workerthe sources. This lead naturally to the next step. 456*6a54128fSAndroid Build Coastguard Worker</Para> 457*6a54128fSAndroid Build Coastguard Worker 458*6a54128fSAndroid Build Coastguard Worker</Sect1> 459*6a54128fSAndroid Build Coastguard Worker 460*6a54128fSAndroid Build Coastguard Worker<Sect1> 461*6a54128fSAndroid Build Coastguard Worker<Title>Object specific commands</Title> 462*6a54128fSAndroid Build Coastguard Worker 463*6a54128fSAndroid Build Coastguard Worker<Para> 464*6a54128fSAndroid Build Coastguard WorkerWhat has become clear is that the above way of exploring is not powerful 465*6a54128fSAndroid Build Coastguard Workerenough - I found myself doing various calculations manually in order to pass 466*6a54128fSAndroid Build Coastguard Workerbetween related structures. I needed to replace some tasks with an automated 467*6a54128fSAndroid Build Coastguard Workerprocedure. 468*6a54128fSAndroid Build Coastguard Worker</Para> 469*6a54128fSAndroid Build Coastguard Worker 470*6a54128fSAndroid Build Coastguard Worker<Para> 471*6a54128fSAndroid Build Coastguard WorkerIn addition, it also became clear that (of-course) each key object in the 472*6a54128fSAndroid Build Coastguard Workerfilesystem has its special place in regard to the overall ext2 filesystem 473*6a54128fSAndroid Build Coastguard Workerdesign, and needs a <Literal remap="tt">fine tuned handling</Literal>. It is at this point that the 474*6a54128fSAndroid Build Coastguard Workerstructure definitions <Literal remap="tt">came to life</Literal> - They became <Literal remap="tt">object 475*6a54128fSAndroid Build Coastguard Workerdefinitions</Literal>, making EXT2ED <Literal remap="tt">object oriented</Literal>. 476*6a54128fSAndroid Build Coastguard Worker</Para> 477*6a54128fSAndroid Build Coastguard Worker 478*6a54128fSAndroid Build Coastguard Worker<Para> 479*6a54128fSAndroid Build Coastguard WorkerThe actual meaning of the breathtaking words above, is that each structure 480*6a54128fSAndroid Build Coastguard Workernow had a list of <Literal remap="tt">private commands</Literal>, which ended up in 481*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">calling special fine-tuned C functions</Literal>. This approach was 482*6a54128fSAndroid Build Coastguard Workerfound to be very powerful and is <Literal remap="tt">the heart of EXT2ED even now</Literal>. 483*6a54128fSAndroid Build Coastguard Worker</Para> 484*6a54128fSAndroid Build Coastguard Worker 485*6a54128fSAndroid Build Coastguard Worker<Para> 486*6a54128fSAndroid Build Coastguard WorkerIn order to implement the above concepts, I added the structure 487*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct_commands</Literal>. The role of this structure is to group together a 488*6a54128fSAndroid Build Coastguard Workergroup of commands, which can be later assigned to a specific type. Each 489*6a54128fSAndroid Build Coastguard Workerstructure had: 490*6a54128fSAndroid Build Coastguard Worker 491*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 492*6a54128fSAndroid Build Coastguard Worker<ListItem> 493*6a54128fSAndroid Build Coastguard Worker 494*6a54128fSAndroid Build Coastguard Worker<Para> 495*6a54128fSAndroid Build Coastguard Worker A list of command names. 496*6a54128fSAndroid Build Coastguard Worker</Para> 497*6a54128fSAndroid Build Coastguard Worker</ListItem> 498*6a54128fSAndroid Build Coastguard Worker<ListItem> 499*6a54128fSAndroid Build Coastguard Worker 500*6a54128fSAndroid Build Coastguard Worker<Para> 501*6a54128fSAndroid Build Coastguard Worker A list of pointers to functions, which binds each command to its 502*6a54128fSAndroid Build Coastguard Workerspecial fine-tuned C function. 503*6a54128fSAndroid Build Coastguard Worker</Para> 504*6a54128fSAndroid Build Coastguard Worker</ListItem> 505*6a54128fSAndroid Build Coastguard Worker 506*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 507*6a54128fSAndroid Build Coastguard Worker 508*6a54128fSAndroid Build Coastguard WorkerIn order to relate a list of commands to a type definition, each 509*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct_descriptor</Literal> structure (explained earlier) was added a private 510*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct_commands</Literal> structure. 511*6a54128fSAndroid Build Coastguard Worker</Para> 512*6a54128fSAndroid Build Coastguard Worker 513*6a54128fSAndroid Build Coastguard Worker<Para> 514*6a54128fSAndroid Build Coastguard WorkerFollows the current definitions of <Literal remap="tt">struct_descriptor</Literal> and of 515*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct_command</Literal>: 516*6a54128fSAndroid Build Coastguard Worker 517*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 518*6a54128fSAndroid Build Coastguard Workerstruct struct_descriptor { 519*6a54128fSAndroid Build Coastguard Worker unsigned long length; 520*6a54128fSAndroid Build Coastguard Worker unsigned char name [60]; 521*6a54128fSAndroid Build Coastguard Worker unsigned short fields_num; 522*6a54128fSAndroid Build Coastguard Worker unsigned char field_names [MAX_FIELDS][80]; 523*6a54128fSAndroid Build Coastguard Worker unsigned short field_lengths [MAX_FIELDS]; 524*6a54128fSAndroid Build Coastguard Worker unsigned short field_positions [MAX_FIELDS]; 525*6a54128fSAndroid Build Coastguard Worker struct struct_commands type_commands; 526*6a54128fSAndroid Build Coastguard Worker struct struct_descriptor *prev,*next; 527*6a54128fSAndroid Build Coastguard Worker}; 528*6a54128fSAndroid Build Coastguard Worker 529*6a54128fSAndroid Build Coastguard Workertypedef void (*PF) (char *); 530*6a54128fSAndroid Build Coastguard Worker 531*6a54128fSAndroid Build Coastguard Workerstruct struct_commands { 532*6a54128fSAndroid Build Coastguard Worker int last_command; 533*6a54128fSAndroid Build Coastguard Worker char *names [MAX_COMMANDS_NUM]; 534*6a54128fSAndroid Build Coastguard Worker char *descriptions [MAX_COMMANDS_NUM]; 535*6a54128fSAndroid Build Coastguard Worker PF callback [MAX_COMMANDS_NUM]; 536*6a54128fSAndroid Build Coastguard Worker}; 537*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 538*6a54128fSAndroid Build Coastguard Worker 539*6a54128fSAndroid Build Coastguard Worker 540*6a54128fSAndroid Build Coastguard Worker</Para> 541*6a54128fSAndroid Build Coastguard Worker 542*6a54128fSAndroid Build Coastguard Worker</Sect1> 543*6a54128fSAndroid Build Coastguard Worker 544*6a54128fSAndroid Build Coastguard Worker<Sect1 id="flow-control"> 545*6a54128fSAndroid Build Coastguard Worker<Title>Program flow control</Title> 546*6a54128fSAndroid Build Coastguard Worker 547*6a54128fSAndroid Build Coastguard Worker<Para> 548*6a54128fSAndroid Build Coastguard WorkerObviously the above approach lead to a major redesign of EXT2ED. The 549*6a54128fSAndroid Build Coastguard Workermain engine of the resulting design is basically the same even now. 550*6a54128fSAndroid Build Coastguard Worker</Para> 551*6a54128fSAndroid Build Coastguard Worker 552*6a54128fSAndroid Build Coastguard Worker<Para> 553*6a54128fSAndroid Build Coastguard WorkerI redesigned the program flow control. Up to now, I analyzed the user command 554*6a54128fSAndroid Build Coastguard Workerline with the simple switch method. Now I used the far superior callback 555*6a54128fSAndroid Build Coastguard Workermethod. 556*6a54128fSAndroid Build Coastguard Worker</Para> 557*6a54128fSAndroid Build Coastguard Worker 558*6a54128fSAndroid Build Coastguard Worker<Para> 559*6a54128fSAndroid Build Coastguard WorkerI divided the available user commands into two groups: 560*6a54128fSAndroid Build Coastguard Worker 561*6a54128fSAndroid Build Coastguard Worker<OrderedList> 562*6a54128fSAndroid Build Coastguard Worker<ListItem> 563*6a54128fSAndroid Build Coastguard Worker 564*6a54128fSAndroid Build Coastguard Worker<Para> 565*6a54128fSAndroid Build Coastguard Worker General commands. 566*6a54128fSAndroid Build Coastguard Worker</Para> 567*6a54128fSAndroid Build Coastguard Worker</ListItem> 568*6a54128fSAndroid Build Coastguard Worker<ListItem> 569*6a54128fSAndroid Build Coastguard Worker 570*6a54128fSAndroid Build Coastguard Worker<Para> 571*6a54128fSAndroid Build Coastguard Worker Type specific commands. 572*6a54128fSAndroid Build Coastguard Worker</Para> 573*6a54128fSAndroid Build Coastguard Worker</ListItem> 574*6a54128fSAndroid Build Coastguard Worker 575*6a54128fSAndroid Build Coastguard Worker</OrderedList> 576*6a54128fSAndroid Build Coastguard Worker 577*6a54128fSAndroid Build Coastguard WorkerAs a result, at each point in time, the user was able to enter a 578*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">general command</Literal>, selectable from a list of general commands which was 579*6a54128fSAndroid Build Coastguard Workeralways available, or a <Literal remap="tt">type specific command</Literal>, selectable from a list of 580*6a54128fSAndroid Build Coastguard Workercommands which <Literal remap="tt">changed in time</Literal> according to the current type that the 581*6a54128fSAndroid Build Coastguard Workeruser was editing. The special <Literal remap="tt">type specific command</Literal> "knew" how to 582*6a54128fSAndroid Build Coastguard Workerhandle the object in the best possible way - It was "fine tuned" for the 583*6a54128fSAndroid Build Coastguard Workerobject's place in the ext2 filesystem design. 584*6a54128fSAndroid Build Coastguard Worker</Para> 585*6a54128fSAndroid Build Coastguard Worker 586*6a54128fSAndroid Build Coastguard Worker<Para> 587*6a54128fSAndroid Build Coastguard WorkerIn order to implement the above idea, I constructed a global variable of 588*6a54128fSAndroid Build Coastguard Workertype <Literal remap="tt">struct_commands</Literal>, which contained the <Literal remap="tt">general commands</Literal>. 589*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">type specific commands</Literal> were accessible through the <Literal remap="tt">struct 590*6a54128fSAndroid Build Coastguard Workerdescriptors</Literal>, as explained earlier. 591*6a54128fSAndroid Build Coastguard Worker</Para> 592*6a54128fSAndroid Build Coastguard Worker 593*6a54128fSAndroid Build Coastguard Worker<Para> 594*6a54128fSAndroid Build Coastguard WorkerThe program flow was now done according to the following algorithm: 595*6a54128fSAndroid Build Coastguard Worker 596*6a54128fSAndroid Build Coastguard Worker<OrderedList> 597*6a54128fSAndroid Build Coastguard Worker<ListItem> 598*6a54128fSAndroid Build Coastguard Worker 599*6a54128fSAndroid Build Coastguard Worker<Para> 600*6a54128fSAndroid Build Coastguard Worker Ask the user for a command line. 601*6a54128fSAndroid Build Coastguard Worker</Para> 602*6a54128fSAndroid Build Coastguard Worker</ListItem> 603*6a54128fSAndroid Build Coastguard Worker<ListItem> 604*6a54128fSAndroid Build Coastguard Worker 605*6a54128fSAndroid Build Coastguard Worker<Para> 606*6a54128fSAndroid Build Coastguard Worker Analyze the user command - Separate it into <Literal remap="tt">command</Literal> and 607*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">arguments</Literal>. 608*6a54128fSAndroid Build Coastguard Worker</Para> 609*6a54128fSAndroid Build Coastguard Worker</ListItem> 610*6a54128fSAndroid Build Coastguard Worker<ListItem> 611*6a54128fSAndroid Build Coastguard Worker 612*6a54128fSAndroid Build Coastguard Worker<Para> 613*6a54128fSAndroid Build Coastguard Worker Trace the list of known objects to match the command name to a type. 614*6a54128fSAndroid Build Coastguard WorkerIf the type is found, call the callback function, with the arguments 615*6a54128fSAndroid Build Coastguard Workeras a parameter. Then go back to step (1). 616*6a54128fSAndroid Build Coastguard Worker</Para> 617*6a54128fSAndroid Build Coastguard Worker</ListItem> 618*6a54128fSAndroid Build Coastguard Worker<ListItem> 619*6a54128fSAndroid Build Coastguard Worker 620*6a54128fSAndroid Build Coastguard Worker<Para> 621*6a54128fSAndroid Build Coastguard Worker If the command is not type specific, try to find it in the general 622*6a54128fSAndroid Build Coastguard Workercommands, and call it if found. Go back to step (1). 623*6a54128fSAndroid Build Coastguard Worker</Para> 624*6a54128fSAndroid Build Coastguard Worker</ListItem> 625*6a54128fSAndroid Build Coastguard Worker<ListItem> 626*6a54128fSAndroid Build Coastguard Worker 627*6a54128fSAndroid Build Coastguard Worker<Para> 628*6a54128fSAndroid Build Coastguard Worker If the command is not found, issue a short error message, and return 629*6a54128fSAndroid Build Coastguard Workerto step (1). 630*6a54128fSAndroid Build Coastguard Worker</Para> 631*6a54128fSAndroid Build Coastguard Worker</ListItem> 632*6a54128fSAndroid Build Coastguard Worker 633*6a54128fSAndroid Build Coastguard Worker</OrderedList> 634*6a54128fSAndroid Build Coastguard Worker 635*6a54128fSAndroid Build Coastguard WorkerNote the <Literal remap="tt">order</Literal> of the above steps. In particular, note that a command 636*6a54128fSAndroid Build Coastguard Workeris first assumed to be a type-specific command and only if this fails, a 637*6a54128fSAndroid Build Coastguard Workergeneral command is searched. The "<Literal remap="tt">side-effect</Literal>" (main effect, actually) 638*6a54128fSAndroid Build Coastguard Workeris that when we have two commands with the <Literal remap="tt">same name</Literal> - One that is a 639*6a54128fSAndroid Build Coastguard Workertype specific command, and one that is a general command, the dispatching 640*6a54128fSAndroid Build Coastguard Workeralgorithm will call the <Literal remap="tt">type specific command</Literal>. This allows 641*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">overriding</Literal> of a command to provide <Literal remap="tt">fine-tuned</Literal> operation. 642*6a54128fSAndroid Build Coastguard WorkerFor example, the <Literal remap="tt">show</Literal> command is overridden nearly everywhere, 643*6a54128fSAndroid Build Coastguard Workerto accommodate for the different ways in which different objects are displayed, 644*6a54128fSAndroid Build Coastguard Workerin order to provide an intuitive fine-tuned display. 645*6a54128fSAndroid Build Coastguard Worker</Para> 646*6a54128fSAndroid Build Coastguard Worker 647*6a54128fSAndroid Build Coastguard Worker<Para> 648*6a54128fSAndroid Build Coastguard WorkerThe above is done in the <Literal remap="tt">dispatch</Literal> function, in <Literal remap="tt">main.c</Literal>. Since 649*6a54128fSAndroid Build Coastguard Workerit is a very important function in EXT2ED, and it is relatively short, I will 650*6a54128fSAndroid Build Coastguard Workerlist it entirely here. Note that a redesign was made since then - Another 651*6a54128fSAndroid Build Coastguard Workerlevel was added between the two described, but I'll elaborate more on this 652*6a54128fSAndroid Build Coastguard Workerlater. However, the basic structure follows the explanation described above. 653*6a54128fSAndroid Build Coastguard Worker 654*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 655*6a54128fSAndroid Build Coastguard Workerint dispatch (char *command_line) 656*6a54128fSAndroid Build Coastguard Worker 657*6a54128fSAndroid Build Coastguard Worker{ 658*6a54128fSAndroid Build Coastguard Worker int i,found=0; 659*6a54128fSAndroid Build Coastguard Worker char command [80]; 660*6a54128fSAndroid Build Coastguard Worker 661*6a54128fSAndroid Build Coastguard Worker parse_word (command_line,command); 662*6a54128fSAndroid Build Coastguard Worker 663*6a54128fSAndroid Build Coastguard Worker if (strcmp (command,"quit")==0) return (1); 664*6a54128fSAndroid Build Coastguard Worker 665*6a54128fSAndroid Build Coastguard Worker /* 1. Search for type specific commands FIRST - Allows overriding of a general command */ 666*6a54128fSAndroid Build Coastguard Worker 667*6a54128fSAndroid Build Coastguard Worker if (current_type != NULL) 668*6a54128fSAndroid Build Coastguard Worker for (i=0;i<=current_type->type_commands.last_command && !found;i++) { 669*6a54128fSAndroid Build Coastguard Worker if (strcmp (command,current_type->type_commands.names [i])==0) { 670*6a54128fSAndroid Build Coastguard Worker (*current_type->type_commands.callback [i]) (command_line); 671*6a54128fSAndroid Build Coastguard Worker found=1; 672*6a54128fSAndroid Build Coastguard Worker } 673*6a54128fSAndroid Build Coastguard Worker } 674*6a54128fSAndroid Build Coastguard Worker 675*6a54128fSAndroid Build Coastguard Worker /* 2. Now search for ext2 filesystem general commands */ 676*6a54128fSAndroid Build Coastguard Worker 677*6a54128fSAndroid Build Coastguard Worker if (!found) 678*6a54128fSAndroid Build Coastguard Worker for (i=0;i<=ext2_commands.last_command && !found;i++) { 679*6a54128fSAndroid Build Coastguard Worker if (strcmp (command,ext2_commands.names [i])==0) { 680*6a54128fSAndroid Build Coastguard Worker (*ext2_commands.callback [i]) (command_line); 681*6a54128fSAndroid Build Coastguard Worker found=1; 682*6a54128fSAndroid Build Coastguard Worker } 683*6a54128fSAndroid Build Coastguard Worker } 684*6a54128fSAndroid Build Coastguard Worker 685*6a54128fSAndroid Build Coastguard Worker 686*6a54128fSAndroid Build Coastguard Worker /* 3. If not found, search the general commands */ 687*6a54128fSAndroid Build Coastguard Worker 688*6a54128fSAndroid Build Coastguard Worker if (!found) 689*6a54128fSAndroid Build Coastguard Worker for (i=0;i<=general_commands.last_command && !found;i++) { 690*6a54128fSAndroid Build Coastguard Worker if (strcmp (command,general_commands.names [i])==0) { 691*6a54128fSAndroid Build Coastguard Worker (*general_commands.callback [i]) (command_line); 692*6a54128fSAndroid Build Coastguard Worker found=1; 693*6a54128fSAndroid Build Coastguard Worker } 694*6a54128fSAndroid Build Coastguard Worker } 695*6a54128fSAndroid Build Coastguard Worker 696*6a54128fSAndroid Build Coastguard Worker if (!found) { 697*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error: Unknown command\n"); 698*6a54128fSAndroid Build Coastguard Worker refresh_command_win (); 699*6a54128fSAndroid Build Coastguard Worker } 700*6a54128fSAndroid Build Coastguard Worker 701*6a54128fSAndroid Build Coastguard Worker return (0); 702*6a54128fSAndroid Build Coastguard Worker} 703*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 704*6a54128fSAndroid Build Coastguard Worker 705*6a54128fSAndroid Build Coastguard Worker</Para> 706*6a54128fSAndroid Build Coastguard Worker 707*6a54128fSAndroid Build Coastguard Worker</Sect1> 708*6a54128fSAndroid Build Coastguard Worker 709*6a54128fSAndroid Build Coastguard Worker<Sect1> 710*6a54128fSAndroid Build Coastguard Worker<Title>Source files in EXT2ED</Title> 711*6a54128fSAndroid Build Coastguard Worker 712*6a54128fSAndroid Build Coastguard Worker<Para> 713*6a54128fSAndroid Build Coastguard WorkerThe project was getting large enough to be split into several source 714*6a54128fSAndroid Build Coastguard Workerfiles. I split the source as much as I could into self-contained 715*6a54128fSAndroid Build Coastguard Workersource files. The source files consist of the following blocks: 716*6a54128fSAndroid Build Coastguard Worker 717*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 718*6a54128fSAndroid Build Coastguard Worker<ListItem> 719*6a54128fSAndroid Build Coastguard Worker 720*6a54128fSAndroid Build Coastguard Worker<Para> 721*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Main include file - ext2ed.h</Literal> 722*6a54128fSAndroid Build Coastguard Worker 723*6a54128fSAndroid Build Coastguard WorkerThis file contains the definitions of the various structures, 724*6a54128fSAndroid Build Coastguard Workervariables and functions used in EXT2ED. It is included by all source 725*6a54128fSAndroid Build Coastguard Workerfiles in EXT2ED. 726*6a54128fSAndroid Build Coastguard Worker 727*6a54128fSAndroid Build Coastguard Worker</Para> 728*6a54128fSAndroid Build Coastguard Worker</ListItem> 729*6a54128fSAndroid Build Coastguard Worker<ListItem> 730*6a54128fSAndroid Build Coastguard Worker 731*6a54128fSAndroid Build Coastguard Worker<Para> 732*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Main block - main.c</Literal> 733*6a54128fSAndroid Build Coastguard Worker 734*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">main.c</Literal> handles the upper level of the program flow control. 735*6a54128fSAndroid Build Coastguard WorkerIt contains the <Literal remap="tt">parser</Literal> and the <Literal remap="tt">dispatcher</Literal>. Its task is 736*6a54128fSAndroid Build Coastguard Workerto ask the user for a required action, and to pass control to other 737*6a54128fSAndroid Build Coastguard Workerlower level functions in order to do the actual job. 738*6a54128fSAndroid Build Coastguard Worker 739*6a54128fSAndroid Build Coastguard Worker</Para> 740*6a54128fSAndroid Build Coastguard Worker</ListItem> 741*6a54128fSAndroid Build Coastguard Worker<ListItem> 742*6a54128fSAndroid Build Coastguard Worker 743*6a54128fSAndroid Build Coastguard Worker<Para> 744*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Initialization - init.c</Literal> 745*6a54128fSAndroid Build Coastguard Worker 746*6a54128fSAndroid Build Coastguard WorkerThe init source is responsible for the various initialization 747*6a54128fSAndroid Build Coastguard Workeractions which need to be done through the program. For example, 748*6a54128fSAndroid Build Coastguard Workerauto detection of an ext2 filesystem when selecting a device and 749*6a54128fSAndroid Build Coastguard Workerinitialization of the filesystem-specific structures described 750*6a54128fSAndroid Build Coastguard Workerearlier. 751*6a54128fSAndroid Build Coastguard Worker 752*6a54128fSAndroid Build Coastguard Worker</Para> 753*6a54128fSAndroid Build Coastguard Worker</ListItem> 754*6a54128fSAndroid Build Coastguard Worker<ListItem> 755*6a54128fSAndroid Build Coastguard Worker 756*6a54128fSAndroid Build Coastguard Worker<Para> 757*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Disk activity - disk.c</Literal> 758*6a54128fSAndroid Build Coastguard Worker 759*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">disk.c</Literal> is handles the lower level interaction with the 760*6a54128fSAndroid Build Coastguard Workerdevice. All disk activity is passed through this file - The various 761*6a54128fSAndroid Build Coastguard Workerfunctions through the source code request disk actions from the 762*6a54128fSAndroid Build Coastguard Workerfunctions in this file. In this way, for example, we can easily block 763*6a54128fSAndroid Build Coastguard Workerthe write access to the device. 764*6a54128fSAndroid Build Coastguard Worker 765*6a54128fSAndroid Build Coastguard Worker</Para> 766*6a54128fSAndroid Build Coastguard Worker</ListItem> 767*6a54128fSAndroid Build Coastguard Worker<ListItem> 768*6a54128fSAndroid Build Coastguard Worker 769*6a54128fSAndroid Build Coastguard Worker<Para> 770*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Display output activity - win.c</Literal> 771*6a54128fSAndroid Build Coastguard Worker 772*6a54128fSAndroid Build Coastguard WorkerIn a similar way to <Literal remap="tt">disk.c</Literal>, the user-interface functions and 773*6a54128fSAndroid Build Coastguard Workermost of the interaction with the <Literal remap="tt">ncurses library</Literal> are done 774*6a54128fSAndroid Build Coastguard Workerhere. Nothing will be actually written to a specific window without 775*6a54128fSAndroid Build Coastguard Workercalling a function from this file. 776*6a54128fSAndroid Build Coastguard Worker 777*6a54128fSAndroid Build Coastguard Worker</Para> 778*6a54128fSAndroid Build Coastguard Worker</ListItem> 779*6a54128fSAndroid Build Coastguard Worker<ListItem> 780*6a54128fSAndroid Build Coastguard Worker 781*6a54128fSAndroid Build Coastguard Worker<Para> 782*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Commands available through dispatching - *_com.c </Literal> 783*6a54128fSAndroid Build Coastguard Worker 784*6a54128fSAndroid Build Coastguard WorkerThe above file name is generic - Each file which ends with 785*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">_com.c</Literal> contains a group of related commands which can be 786*6a54128fSAndroid Build Coastguard Workercalled through <Literal remap="tt">the dispatching function</Literal>. 787*6a54128fSAndroid Build Coastguard Worker 788*6a54128fSAndroid Build Coastguard WorkerEach object typically has its own file. A separate file is also 789*6a54128fSAndroid Build Coastguard Workeravailable for the general commands. 790*6a54128fSAndroid Build Coastguard Worker</Para> 791*6a54128fSAndroid Build Coastguard Worker</ListItem> 792*6a54128fSAndroid Build Coastguard Worker 793*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 794*6a54128fSAndroid Build Coastguard Worker 795*6a54128fSAndroid Build Coastguard WorkerThe entire list of source files available at this time is: 796*6a54128fSAndroid Build Coastguard Worker 797*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 798*6a54128fSAndroid Build Coastguard Worker<ListItem> 799*6a54128fSAndroid Build Coastguard Worker 800*6a54128fSAndroid Build Coastguard Worker<Para> 801*6a54128fSAndroid Build Coastguard Worker blockbitmap_com.c 802*6a54128fSAndroid Build Coastguard Worker</Para> 803*6a54128fSAndroid Build Coastguard Worker</ListItem> 804*6a54128fSAndroid Build Coastguard Worker<ListItem> 805*6a54128fSAndroid Build Coastguard Worker 806*6a54128fSAndroid Build Coastguard Worker<Para> 807*6a54128fSAndroid Build Coastguard Worker dir_com.c 808*6a54128fSAndroid Build Coastguard Worker</Para> 809*6a54128fSAndroid Build Coastguard Worker</ListItem> 810*6a54128fSAndroid Build Coastguard Worker<ListItem> 811*6a54128fSAndroid Build Coastguard Worker 812*6a54128fSAndroid Build Coastguard Worker<Para> 813*6a54128fSAndroid Build Coastguard Worker disk.c 814*6a54128fSAndroid Build Coastguard Worker</Para> 815*6a54128fSAndroid Build Coastguard Worker</ListItem> 816*6a54128fSAndroid Build Coastguard Worker<ListItem> 817*6a54128fSAndroid Build Coastguard Worker 818*6a54128fSAndroid Build Coastguard Worker<Para> 819*6a54128fSAndroid Build Coastguard Worker ext2_com.c 820*6a54128fSAndroid Build Coastguard Worker</Para> 821*6a54128fSAndroid Build Coastguard Worker</ListItem> 822*6a54128fSAndroid Build Coastguard Worker<ListItem> 823*6a54128fSAndroid Build Coastguard Worker 824*6a54128fSAndroid Build Coastguard Worker<Para> 825*6a54128fSAndroid Build Coastguard Worker file_com.c 826*6a54128fSAndroid Build Coastguard Worker</Para> 827*6a54128fSAndroid Build Coastguard Worker</ListItem> 828*6a54128fSAndroid Build Coastguard Worker<ListItem> 829*6a54128fSAndroid Build Coastguard Worker 830*6a54128fSAndroid Build Coastguard Worker<Para> 831*6a54128fSAndroid Build Coastguard Worker general_com.c 832*6a54128fSAndroid Build Coastguard Worker</Para> 833*6a54128fSAndroid Build Coastguard Worker</ListItem> 834*6a54128fSAndroid Build Coastguard Worker<ListItem> 835*6a54128fSAndroid Build Coastguard Worker 836*6a54128fSAndroid Build Coastguard Worker<Para> 837*6a54128fSAndroid Build Coastguard Worker group_com.c 838*6a54128fSAndroid Build Coastguard Worker</Para> 839*6a54128fSAndroid Build Coastguard Worker</ListItem> 840*6a54128fSAndroid Build Coastguard Worker<ListItem> 841*6a54128fSAndroid Build Coastguard Worker 842*6a54128fSAndroid Build Coastguard Worker<Para> 843*6a54128fSAndroid Build Coastguard Worker init.c 844*6a54128fSAndroid Build Coastguard Worker</Para> 845*6a54128fSAndroid Build Coastguard Worker</ListItem> 846*6a54128fSAndroid Build Coastguard Worker<ListItem> 847*6a54128fSAndroid Build Coastguard Worker 848*6a54128fSAndroid Build Coastguard Worker<Para> 849*6a54128fSAndroid Build Coastguard Worker inode_com.c 850*6a54128fSAndroid Build Coastguard Worker</Para> 851*6a54128fSAndroid Build Coastguard Worker</ListItem> 852*6a54128fSAndroid Build Coastguard Worker<ListItem> 853*6a54128fSAndroid Build Coastguard Worker 854*6a54128fSAndroid Build Coastguard Worker<Para> 855*6a54128fSAndroid Build Coastguard Worker inodebitmap_com.c 856*6a54128fSAndroid Build Coastguard Worker</Para> 857*6a54128fSAndroid Build Coastguard Worker</ListItem> 858*6a54128fSAndroid Build Coastguard Worker<ListItem> 859*6a54128fSAndroid Build Coastguard Worker 860*6a54128fSAndroid Build Coastguard Worker<Para> 861*6a54128fSAndroid Build Coastguard Worker main.c 862*6a54128fSAndroid Build Coastguard Worker</Para> 863*6a54128fSAndroid Build Coastguard Worker</ListItem> 864*6a54128fSAndroid Build Coastguard Worker<ListItem> 865*6a54128fSAndroid Build Coastguard Worker 866*6a54128fSAndroid Build Coastguard Worker<Para> 867*6a54128fSAndroid Build Coastguard Worker super_com.c 868*6a54128fSAndroid Build Coastguard Worker</Para> 869*6a54128fSAndroid Build Coastguard Worker</ListItem> 870*6a54128fSAndroid Build Coastguard Worker<ListItem> 871*6a54128fSAndroid Build Coastguard Worker 872*6a54128fSAndroid Build Coastguard Worker<Para> 873*6a54128fSAndroid Build Coastguard Worker win.c 874*6a54128fSAndroid Build Coastguard Worker</Para> 875*6a54128fSAndroid Build Coastguard Worker</ListItem> 876*6a54128fSAndroid Build Coastguard Worker 877*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 878*6a54128fSAndroid Build Coastguard Worker 879*6a54128fSAndroid Build Coastguard Worker</Para> 880*6a54128fSAndroid Build Coastguard Worker 881*6a54128fSAndroid Build Coastguard Worker</Sect1> 882*6a54128fSAndroid Build Coastguard Worker 883*6a54128fSAndroid Build Coastguard Worker<Sect1> 884*6a54128fSAndroid Build Coastguard Worker<Title>User interface</Title> 885*6a54128fSAndroid Build Coastguard Worker 886*6a54128fSAndroid Build Coastguard Worker<Para> 887*6a54128fSAndroid Build Coastguard WorkerThe user interface is text-based only and is based on the following 888*6a54128fSAndroid Build Coastguard Workerlibraries: 889*6a54128fSAndroid Build Coastguard Worker</Para> 890*6a54128fSAndroid Build Coastguard Worker 891*6a54128fSAndroid Build Coastguard Worker<Para> 892*6a54128fSAndroid Build Coastguard Worker 893*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 894*6a54128fSAndroid Build Coastguard Worker<ListItem> 895*6a54128fSAndroid Build Coastguard Worker 896*6a54128fSAndroid Build Coastguard Worker<Para> 897*6a54128fSAndroid Build Coastguard Worker The <Literal remap="tt">ncurses</Literal> library, developed by <Literal remap="tt">Zeyd Ben-Halim</Literal>. 898*6a54128fSAndroid Build Coastguard Worker</Para> 899*6a54128fSAndroid Build Coastguard Worker</ListItem> 900*6a54128fSAndroid Build Coastguard Worker<ListItem> 901*6a54128fSAndroid Build Coastguard Worker 902*6a54128fSAndroid Build Coastguard Worker<Para> 903*6a54128fSAndroid Build Coastguard Worker The <Literal remap="tt">GNU readline</Literal> library. 904*6a54128fSAndroid Build Coastguard Worker</Para> 905*6a54128fSAndroid Build Coastguard Worker</ListItem> 906*6a54128fSAndroid Build Coastguard Worker 907*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 908*6a54128fSAndroid Build Coastguard Worker 909*6a54128fSAndroid Build Coastguard Worker</Para> 910*6a54128fSAndroid Build Coastguard Worker 911*6a54128fSAndroid Build Coastguard Worker<Para> 912*6a54128fSAndroid Build Coastguard WorkerThe user interaction is command line based - The user enters a command 913*6a54128fSAndroid Build Coastguard Workerline, which consists of a <Literal remap="tt">command</Literal> and of <Literal remap="tt">arguments</Literal>. This fits 914*6a54128fSAndroid Build Coastguard Workernicely with the program flow control described earlier - The <Literal remap="tt">command</Literal> 915*6a54128fSAndroid Build Coastguard Workeris used by <Literal remap="tt">dispatch</Literal> to select the right function, and the 916*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">arguments</Literal> are interpreted by the function itself. 917*6a54128fSAndroid Build Coastguard Worker</Para> 918*6a54128fSAndroid Build Coastguard Worker 919*6a54128fSAndroid Build Coastguard Worker<Sect2> 920*6a54128fSAndroid Build Coastguard Worker<Title>The ncurses library</Title> 921*6a54128fSAndroid Build Coastguard Worker 922*6a54128fSAndroid Build Coastguard Worker<Para> 923*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">ncurses</Literal> library enables me to divide the screen into "windows". 924*6a54128fSAndroid Build Coastguard WorkerThe main advantage is that I treat the "window" in a virtual way, asking 925*6a54128fSAndroid Build Coastguard Workerthe ncurses library to "write to a window". However, the ncurses 926*6a54128fSAndroid Build Coastguard Workerlibrary internally buffers the requests, and nothing is actually passed to the 927*6a54128fSAndroid Build Coastguard Workerterminal until an explicit refresh is requested. When the refresh request is 928*6a54128fSAndroid Build Coastguard Workermade, ncurses compares the current terminal state (as known in the last time 929*6a54128fSAndroid Build Coastguard Workerthat a refresh was done) with the new to be shown state, and passes to the 930*6a54128fSAndroid Build Coastguard Workerterminal the minimal information required to update the display. As a 931*6a54128fSAndroid Build Coastguard Workerresult, the display output is optimized behind the scenes by the 932*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ncurses</Literal> library, while I can still treat it in a virtual way. 933*6a54128fSAndroid Build Coastguard Worker</Para> 934*6a54128fSAndroid Build Coastguard Worker 935*6a54128fSAndroid Build Coastguard Worker<Para> 936*6a54128fSAndroid Build Coastguard WorkerThere are two basic concepts in the <Literal remap="tt">ncurses</Literal> library: 937*6a54128fSAndroid Build Coastguard Worker 938*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 939*6a54128fSAndroid Build Coastguard Worker<ListItem> 940*6a54128fSAndroid Build Coastguard Worker 941*6a54128fSAndroid Build Coastguard Worker<Para> 942*6a54128fSAndroid Build Coastguard Worker A window. 943*6a54128fSAndroid Build Coastguard Worker</Para> 944*6a54128fSAndroid Build Coastguard Worker</ListItem> 945*6a54128fSAndroid Build Coastguard Worker<ListItem> 946*6a54128fSAndroid Build Coastguard Worker 947*6a54128fSAndroid Build Coastguard Worker<Para> 948*6a54128fSAndroid Build Coastguard Worker A pad. 949*6a54128fSAndroid Build Coastguard Worker</Para> 950*6a54128fSAndroid Build Coastguard Worker</ListItem> 951*6a54128fSAndroid Build Coastguard Worker 952*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 953*6a54128fSAndroid Build Coastguard Worker 954*6a54128fSAndroid Build Coastguard WorkerA window can be no bigger than the actual terminal size. A pad, however, is 955*6a54128fSAndroid Build Coastguard Workernot limited in its size. 956*6a54128fSAndroid Build Coastguard Worker</Para> 957*6a54128fSAndroid Build Coastguard Worker 958*6a54128fSAndroid Build Coastguard Worker<Para> 959*6a54128fSAndroid Build Coastguard WorkerThe user screen is divided by EXT2ED into three windows and one pad: 960*6a54128fSAndroid Build Coastguard Worker 961*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 962*6a54128fSAndroid Build Coastguard Worker<ListItem> 963*6a54128fSAndroid Build Coastguard Worker 964*6a54128fSAndroid Build Coastguard Worker<Para> 965*6a54128fSAndroid Build Coastguard Worker Title window. 966*6a54128fSAndroid Build Coastguard Worker</Para> 967*6a54128fSAndroid Build Coastguard Worker</ListItem> 968*6a54128fSAndroid Build Coastguard Worker<ListItem> 969*6a54128fSAndroid Build Coastguard Worker 970*6a54128fSAndroid Build Coastguard Worker<Para> 971*6a54128fSAndroid Build Coastguard Worker Status window. 972*6a54128fSAndroid Build Coastguard Worker</Para> 973*6a54128fSAndroid Build Coastguard Worker</ListItem> 974*6a54128fSAndroid Build Coastguard Worker<ListItem> 975*6a54128fSAndroid Build Coastguard Worker 976*6a54128fSAndroid Build Coastguard Worker<Para> 977*6a54128fSAndroid Build Coastguard Worker Main display pad. 978*6a54128fSAndroid Build Coastguard Worker</Para> 979*6a54128fSAndroid Build Coastguard Worker</ListItem> 980*6a54128fSAndroid Build Coastguard Worker<ListItem> 981*6a54128fSAndroid Build Coastguard Worker 982*6a54128fSAndroid Build Coastguard Worker<Para> 983*6a54128fSAndroid Build Coastguard Worker Command window. 984*6a54128fSAndroid Build Coastguard Worker</Para> 985*6a54128fSAndroid Build Coastguard Worker</ListItem> 986*6a54128fSAndroid Build Coastguard Worker 987*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 988*6a54128fSAndroid Build Coastguard Worker 989*6a54128fSAndroid Build Coastguard Worker</Para> 990*6a54128fSAndroid Build Coastguard Worker 991*6a54128fSAndroid Build Coastguard Worker<Para> 992*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">title window</Literal> is static - It just displays the current version 993*6a54128fSAndroid Build Coastguard Workerof EXT2ED. 994*6a54128fSAndroid Build Coastguard Worker</Para> 995*6a54128fSAndroid Build Coastguard Worker 996*6a54128fSAndroid Build Coastguard Worker<Para> 997*6a54128fSAndroid Build Coastguard WorkerThe user interaction is done in the <Literal remap="tt">command window</Literal>. The user enters a 998*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">command line</Literal>, feedback is usually displayed there, and then relevant 999*6a54128fSAndroid Build Coastguard Workerdata is usually displayed in the main display and in the status window. 1000*6a54128fSAndroid Build Coastguard Worker</Para> 1001*6a54128fSAndroid Build Coastguard Worker 1002*6a54128fSAndroid Build Coastguard Worker<Para> 1003*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">main display</Literal> is using a <Literal remap="tt">pad</Literal> instead of a window because 1004*6a54128fSAndroid Build Coastguard Workerthe amount of information which is written to it is not known in advance. 1005*6a54128fSAndroid Build Coastguard WorkerTherefor, the user treats the main display as a "window" into a bigger 1006*6a54128fSAndroid Build Coastguard Workerdisplay and can <Literal remap="tt">scroll vertically</Literal> using the <Literal remap="tt">pgdn</Literal> and <Literal remap="tt">pgup</Literal> 1007*6a54128fSAndroid Build Coastguard Workercommands. Although the <Literal remap="tt">pad</Literal> mechanism enables me to use horizontal 1008*6a54128fSAndroid Build Coastguard Workerscrolling, I have not utilized this. 1009*6a54128fSAndroid Build Coastguard Worker</Para> 1010*6a54128fSAndroid Build Coastguard Worker 1011*6a54128fSAndroid Build Coastguard Worker<Para> 1012*6a54128fSAndroid Build Coastguard WorkerWhen I need to show something to the user, I use the ncurses <Literal remap="tt">wprintw</Literal> 1013*6a54128fSAndroid Build Coastguard Workercommand. Then an explicit refresh command is required. As explained before, 1014*6a54128fSAndroid Build Coastguard Workerthe refresh commands is piped through <Literal remap="tt">win.c</Literal>. For example, to update 1015*6a54128fSAndroid Build Coastguard Workerthe command window, <Literal remap="tt">refresh_command_win ()</Literal> is used. 1016*6a54128fSAndroid Build Coastguard Worker</Para> 1017*6a54128fSAndroid Build Coastguard Worker 1018*6a54128fSAndroid Build Coastguard Worker</Sect2> 1019*6a54128fSAndroid Build Coastguard Worker 1020*6a54128fSAndroid Build Coastguard Worker<Sect2> 1021*6a54128fSAndroid Build Coastguard Worker<Title>The readline library</Title> 1022*6a54128fSAndroid Build Coastguard Worker 1023*6a54128fSAndroid Build Coastguard Worker<Para> 1024*6a54128fSAndroid Build Coastguard WorkerAvner suggested me to integrate the GNU <Literal remap="tt">readline</Literal> library in my project. 1025*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">readline</Literal> library is designed specifically for programs which use 1026*6a54128fSAndroid Build Coastguard Workercommand line interface. It provides a nice package of <Literal remap="tt">command line editing 1027*6a54128fSAndroid Build Coastguard Workertools</Literal> - Inserting, deleting words, and the whole package of editing tools 1028*6a54128fSAndroid Build Coastguard Workerwhich are normally available in the <Literal remap="tt">bash</Literal> shell (Refer to the readline 1029*6a54128fSAndroid Build Coastguard Workerdocumentation for details). In addition, I utilized the <Literal remap="tt">history</Literal> 1030*6a54128fSAndroid Build Coastguard Workerfeature of the readline library - The entered commands are saved in a 1031*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">command history</Literal>, and can be called later by whatever means that the 1032*6a54128fSAndroid Build Coastguard Workerreadline package provides. Command completion is also supported - When the 1033*6a54128fSAndroid Build Coastguard Workeruser enters a partial command name, EXT2ED will provide the readline library 1034*6a54128fSAndroid Build Coastguard Workerwith the possible completions. 1035*6a54128fSAndroid Build Coastguard Worker</Para> 1036*6a54128fSAndroid Build Coastguard Worker 1037*6a54128fSAndroid Build Coastguard Worker</Sect2> 1038*6a54128fSAndroid Build Coastguard Worker 1039*6a54128fSAndroid Build Coastguard Worker</Sect1> 1040*6a54128fSAndroid Build Coastguard Worker 1041*6a54128fSAndroid Build Coastguard Worker<Sect1> 1042*6a54128fSAndroid Build Coastguard Worker<Title>Possible support of other filesystems</Title> 1043*6a54128fSAndroid Build Coastguard Worker 1044*6a54128fSAndroid Build Coastguard Worker<Para> 1045*6a54128fSAndroid Build Coastguard WorkerThe entire ext2 layer is provided through specific objects. Given another 1046*6a54128fSAndroid Build Coastguard Workerset of objects, support of other filesystem can be provided using the same 1047*6a54128fSAndroid Build Coastguard Workerdispatching mechanism. In order to prepare the surface for this option, I 1048*6a54128fSAndroid Build Coastguard Workeradded yet another layer to the two-layer structure presented earlier. EXT2ED 1049*6a54128fSAndroid Build Coastguard Workercommands now consist of three layers: 1050*6a54128fSAndroid Build Coastguard Worker 1051*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1052*6a54128fSAndroid Build Coastguard Worker<ListItem> 1053*6a54128fSAndroid Build Coastguard Worker 1054*6a54128fSAndroid Build Coastguard Worker<Para> 1055*6a54128fSAndroid Build Coastguard Worker The general commands. 1056*6a54128fSAndroid Build Coastguard Worker</Para> 1057*6a54128fSAndroid Build Coastguard Worker</ListItem> 1058*6a54128fSAndroid Build Coastguard Worker<ListItem> 1059*6a54128fSAndroid Build Coastguard Worker 1060*6a54128fSAndroid Build Coastguard Worker<Para> 1061*6a54128fSAndroid Build Coastguard Worker The ext2 general commands. 1062*6a54128fSAndroid Build Coastguard Worker</Para> 1063*6a54128fSAndroid Build Coastguard Worker</ListItem> 1064*6a54128fSAndroid Build Coastguard Worker<ListItem> 1065*6a54128fSAndroid Build Coastguard Worker 1066*6a54128fSAndroid Build Coastguard Worker<Para> 1067*6a54128fSAndroid Build Coastguard Worker The ext2 object specific commands. 1068*6a54128fSAndroid Build Coastguard Worker</Para> 1069*6a54128fSAndroid Build Coastguard Worker</ListItem> 1070*6a54128fSAndroid Build Coastguard Worker 1071*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1072*6a54128fSAndroid Build Coastguard Worker 1073*6a54128fSAndroid Build Coastguard WorkerThe general commands are provided by the <Literal remap="tt">general_com.c</Literal> source file, 1074*6a54128fSAndroid Build Coastguard Workerand are always available. The two other levels are not present when EXT2ED 1075*6a54128fSAndroid Build Coastguard Workerloads - They are dynamically added by <Literal remap="tt">init.c</Literal> when EXT2ED detects an 1076*6a54128fSAndroid Build Coastguard Workerext2 filesystem on the device. 1077*6a54128fSAndroid Build Coastguard Worker</Para> 1078*6a54128fSAndroid Build Coastguard Worker 1079*6a54128fSAndroid Build Coastguard Worker<Para> 1080*6a54128fSAndroid Build Coastguard WorkerThe abstraction levels presented above helps to extend EXT2ED to fully 1081*6a54128fSAndroid Build Coastguard Workersupport a new filesystem, with its own specific type commands. 1082*6a54128fSAndroid Build Coastguard Worker</Para> 1083*6a54128fSAndroid Build Coastguard Worker 1084*6a54128fSAndroid Build Coastguard Worker<Para> 1085*6a54128fSAndroid Build Coastguard WorkerEven without any source code modification, the user is free to add structure 1086*6a54128fSAndroid Build Coastguard Workerdefinitions in a separate file (specified in the configuration file), 1087*6a54128fSAndroid Build Coastguard Workerwhich will be added to the list of available objects. The added objects will 1088*6a54128fSAndroid Build Coastguard Workerconsist only of variables, of-course, and will be used through the more 1089*6a54128fSAndroid Build Coastguard Workerprimitive <Literal remap="tt">setoffset</Literal> and <Literal remap="tt">settype</Literal> commands. 1090*6a54128fSAndroid Build Coastguard Worker</Para> 1091*6a54128fSAndroid Build Coastguard Worker 1092*6a54128fSAndroid Build Coastguard Worker</Sect1> 1093*6a54128fSAndroid Build Coastguard Worker 1094*6a54128fSAndroid Build Coastguard Worker<Sect1> 1095*6a54128fSAndroid Build Coastguard Worker<Title>On the implementation of the various commands</Title> 1096*6a54128fSAndroid Build Coastguard Worker 1097*6a54128fSAndroid Build Coastguard Worker<Para> 1098*6a54128fSAndroid Build Coastguard WorkerThis section points out some typical programming style that I used in many 1099*6a54128fSAndroid Build Coastguard Workerplaces at the code. 1100*6a54128fSAndroid Build Coastguard Worker</Para> 1101*6a54128fSAndroid Build Coastguard Worker 1102*6a54128fSAndroid Build Coastguard Worker<Sect2> 1103*6a54128fSAndroid Build Coastguard Worker<Title>The explicit use of the dispatch function</Title> 1104*6a54128fSAndroid Build Coastguard Worker 1105*6a54128fSAndroid Build Coastguard Worker<Para> 1106*6a54128fSAndroid Build Coastguard WorkerThe various commands are reached by the user through the <Literal remap="tt">dispatch</Literal> 1107*6a54128fSAndroid Build Coastguard Workerfunction. This is not surprising. The fact that can be surprising, at least in 1108*6a54128fSAndroid Build Coastguard Workera first look, is that <Literal remap="tt">you'll find the dispatch call in many of my 1109*6a54128fSAndroid Build Coastguard Workerown functions!</Literal>. 1110*6a54128fSAndroid Build Coastguard Worker</Para> 1111*6a54128fSAndroid Build Coastguard Worker 1112*6a54128fSAndroid Build Coastguard Worker<Para> 1113*6a54128fSAndroid Build Coastguard WorkerI am in fact using my own implemented functions to construct higher 1114*6a54128fSAndroid Build Coastguard Workerlevel operations. I am heavily using the fact that the dispatching mechanism 1115*6a54128fSAndroid Build Coastguard Workeris object oriented ant that the <Literal remap="tt">overriding</Literal> principle takes place and 1116*6a54128fSAndroid Build Coastguard Workerselects the proper function to call when several commands with the same name 1117*6a54128fSAndroid Build Coastguard Workerare accessible. 1118*6a54128fSAndroid Build Coastguard Worker</Para> 1119*6a54128fSAndroid Build Coastguard Worker 1120*6a54128fSAndroid Build Coastguard Worker<Para> 1121*6a54128fSAndroid Build Coastguard WorkerSometimes, however, I call the explicit command directly, without passing 1122*6a54128fSAndroid Build Coastguard Workerthrough <Literal remap="tt">dispatch</Literal>. This is typically done when I want to bypass the 1123*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">overriding</Literal> effect. 1124*6a54128fSAndroid Build Coastguard Worker</Para> 1125*6a54128fSAndroid Build Coastguard Worker 1126*6a54128fSAndroid Build Coastguard Worker<Para> 1127*6a54128fSAndroid Build Coastguard Worker 1128*6a54128fSAndroid Build Coastguard WorkerThis is used, for example, in the interaction between the global cd command 1129*6a54128fSAndroid Build Coastguard Workerand the dir object specific cd command. You will see there that in order 1130*6a54128fSAndroid Build Coastguard Workerto implement the "entire" cd command, the type specific cd command uses both 1131*6a54128fSAndroid Build Coastguard Workera dispatching mechanism to call itself recursively if a relative path is 1132*6a54128fSAndroid Build Coastguard Workerused, or a direct call of the general cd handling function if an explicit path 1133*6a54128fSAndroid Build Coastguard Workeris used. 1134*6a54128fSAndroid Build Coastguard Worker 1135*6a54128fSAndroid Build Coastguard Worker</Para> 1136*6a54128fSAndroid Build Coastguard Worker 1137*6a54128fSAndroid Build Coastguard Worker</Sect2> 1138*6a54128fSAndroid Build Coastguard Worker 1139*6a54128fSAndroid Build Coastguard Worker<Sect2> 1140*6a54128fSAndroid Build Coastguard Worker<Title>Passing information between handling functions</Title> 1141*6a54128fSAndroid Build Coastguard Worker 1142*6a54128fSAndroid Build Coastguard Worker<Para> 1143*6a54128fSAndroid Build Coastguard WorkerTypically, every source code file which handles one object type has a global 1144*6a54128fSAndroid Build Coastguard Workerstructure specifically designed for it which is used by most of the 1145*6a54128fSAndroid Build Coastguard Workerfunctions in that file. This is used to pass information between the various 1146*6a54128fSAndroid Build Coastguard Workerfunctions there, and to physically provide the link to other related 1147*6a54128fSAndroid Build Coastguard Workerobjects, typically for initialization use. 1148*6a54128fSAndroid Build Coastguard Worker</Para> 1149*6a54128fSAndroid Build Coastguard Worker 1150*6a54128fSAndroid Build Coastguard Worker<Para> 1151*6a54128fSAndroid Build Coastguard Worker 1152*6a54128fSAndroid Build Coastguard WorkerFor example, in order to edit a file, information about the 1153*6a54128fSAndroid Build Coastguard Workerinode is needed - The file command is available only when editing an 1154*6a54128fSAndroid Build Coastguard Workerinode. When the file command is issued, the handling function (found, 1155*6a54128fSAndroid Build Coastguard Workeraccording to the source division outlined above, in inode_com.c) will 1156*6a54128fSAndroid Build Coastguard Workerstore the necessary information about the inode in a specific structure 1157*6a54128fSAndroid Build Coastguard Workerof type struct_file_info which will be available for use by the file_com.c 1158*6a54128fSAndroid Build Coastguard Workerfunctions. Only then it will set the type to file. This is also the reason 1159*6a54128fSAndroid Build Coastguard Workerthat a direct asynchronous set of the object type to a file through a settype 1160*6a54128fSAndroid Build Coastguard Workercommand will fail - The above data structure will not be initialized 1161*6a54128fSAndroid Build Coastguard Workerproperly because the user never was at the inode of the file. 1162*6a54128fSAndroid Build Coastguard Worker 1163*6a54128fSAndroid Build Coastguard Worker</Para> 1164*6a54128fSAndroid Build Coastguard Worker 1165*6a54128fSAndroid Build Coastguard Worker</Sect2> 1166*6a54128fSAndroid Build Coastguard Worker 1167*6a54128fSAndroid Build Coastguard Worker<Sect2> 1168*6a54128fSAndroid Build Coastguard Worker<Title>A very simplified overview of a typical command handling function</Title> 1169*6a54128fSAndroid Build Coastguard Worker 1170*6a54128fSAndroid Build Coastguard Worker<Para> 1171*6a54128fSAndroid Build Coastguard WorkerThis is a very simplified overview. Detailed information will follow 1172*6a54128fSAndroid Build Coastguard Workerwhere appropriate. 1173*6a54128fSAndroid Build Coastguard Worker</Para> 1174*6a54128fSAndroid Build Coastguard Worker 1175*6a54128fSAndroid Build Coastguard Worker<Sect3> 1176*6a54128fSAndroid Build Coastguard Worker<Title>The prototype of a typical handling function</Title> 1177*6a54128fSAndroid Build Coastguard Worker 1178*6a54128fSAndroid Build Coastguard Worker<Para> 1179*6a54128fSAndroid Build Coastguard Worker 1180*6a54128fSAndroid Build Coastguard Worker<OrderedList> 1181*6a54128fSAndroid Build Coastguard Worker<ListItem> 1182*6a54128fSAndroid Build Coastguard Worker 1183*6a54128fSAndroid Build Coastguard Worker<Para> 1184*6a54128fSAndroid Build Coastguard Worker I chose a unified <Literal remap="tt">naming convention</Literal> for the various object 1185*6a54128fSAndroid Build Coastguard Workerspecific commands. It is perhaps best showed with an example: 1186*6a54128fSAndroid Build Coastguard Worker 1187*6a54128fSAndroid Build Coastguard WorkerThe prototype of the handling function of the command <Literal remap="tt">next</Literal> of 1188*6a54128fSAndroid Build Coastguard Workerthe type <Literal remap="tt">file</Literal> is: 1189*6a54128fSAndroid Build Coastguard Worker 1190*6a54128fSAndroid Build Coastguard Worker<Screen> 1191*6a54128fSAndroid Build Coastguard Worker extern void type_file___next (char *command_line); 1192*6a54128fSAndroid Build Coastguard Worker 1193*6a54128fSAndroid Build Coastguard Worker</Screen> 1194*6a54128fSAndroid Build Coastguard Worker 1195*6a54128fSAndroid Build Coastguard Worker 1196*6a54128fSAndroid Build Coastguard WorkerFor other types and commands, the words <Literal remap="tt">file</Literal> and <Literal remap="tt">next</Literal> 1197*6a54128fSAndroid Build Coastguard Workershould be replaced accordingly. 1198*6a54128fSAndroid Build Coastguard Worker 1199*6a54128fSAndroid Build Coastguard Worker</Para> 1200*6a54128fSAndroid Build Coastguard Worker</ListItem> 1201*6a54128fSAndroid Build Coastguard Worker<ListItem> 1202*6a54128fSAndroid Build Coastguard Worker 1203*6a54128fSAndroid Build Coastguard Worker<Para> 1204*6a54128fSAndroid Build Coastguard Worker The ext2 general commands syntax is similar. For example, the ext2 1205*6a54128fSAndroid Build Coastguard Workergeneral command <Literal remap="tt">super</Literal> results in calling: 1206*6a54128fSAndroid Build Coastguard Worker 1207*6a54128fSAndroid Build Coastguard Worker<Screen> 1208*6a54128fSAndroid Build Coastguard Worker extern void type_ext2___super (char *command_line); 1209*6a54128fSAndroid Build Coastguard Worker 1210*6a54128fSAndroid Build Coastguard Worker</Screen> 1211*6a54128fSAndroid Build Coastguard Worker 1212*6a54128fSAndroid Build Coastguard WorkerThose functions are available in <Literal remap="tt">ext2_com.c</Literal>. 1213*6a54128fSAndroid Build Coastguard Worker</Para> 1214*6a54128fSAndroid Build Coastguard Worker</ListItem> 1215*6a54128fSAndroid Build Coastguard Worker<ListItem> 1216*6a54128fSAndroid Build Coastguard Worker 1217*6a54128fSAndroid Build Coastguard Worker<Para> 1218*6a54128fSAndroid Build Coastguard Worker The general commands syntax is even simpler - The name of the 1219*6a54128fSAndroid Build Coastguard Workerhandling function is exactly the name of the commands. Those 1220*6a54128fSAndroid Build Coastguard Workerfunctions are available in <Literal remap="tt">general_com.c</Literal>. 1221*6a54128fSAndroid Build Coastguard Worker</Para> 1222*6a54128fSAndroid Build Coastguard Worker</ListItem> 1223*6a54128fSAndroid Build Coastguard Worker 1224*6a54128fSAndroid Build Coastguard Worker</OrderedList> 1225*6a54128fSAndroid Build Coastguard Worker 1226*6a54128fSAndroid Build Coastguard Worker</Para> 1227*6a54128fSAndroid Build Coastguard Worker 1228*6a54128fSAndroid Build Coastguard Worker</Sect3> 1229*6a54128fSAndroid Build Coastguard Worker 1230*6a54128fSAndroid Build Coastguard Worker<Sect3> 1231*6a54128fSAndroid Build Coastguard Worker<Title>"Typical" algorithm</Title> 1232*6a54128fSAndroid Build Coastguard Worker 1233*6a54128fSAndroid Build Coastguard Worker<Para> 1234*6a54128fSAndroid Build Coastguard WorkerThis section can't of-course provide meaningful information - Each 1235*6a54128fSAndroid Build Coastguard Workercommand is handled differently, but the following frame is typical: 1236*6a54128fSAndroid Build Coastguard Worker 1237*6a54128fSAndroid Build Coastguard Worker<OrderedList> 1238*6a54128fSAndroid Build Coastguard Worker<ListItem> 1239*6a54128fSAndroid Build Coastguard Worker 1240*6a54128fSAndroid Build Coastguard Worker<Para> 1241*6a54128fSAndroid Build Coastguard Worker Parse command line arguments and analyze them. Return with an error 1242*6a54128fSAndroid Build Coastguard Workermessage if the syntax is wrong. 1243*6a54128fSAndroid Build Coastguard Worker</Para> 1244*6a54128fSAndroid Build Coastguard Worker</ListItem> 1245*6a54128fSAndroid Build Coastguard Worker<ListItem> 1246*6a54128fSAndroid Build Coastguard Worker 1247*6a54128fSAndroid Build Coastguard Worker<Para> 1248*6a54128fSAndroid Build Coastguard Worker "Act accordingly", perhaps making use of the global variable available 1249*6a54128fSAndroid Build Coastguard Workerto this type. 1250*6a54128fSAndroid Build Coastguard Worker</Para> 1251*6a54128fSAndroid Build Coastguard Worker</ListItem> 1252*6a54128fSAndroid Build Coastguard Worker<ListItem> 1253*6a54128fSAndroid Build Coastguard Worker 1254*6a54128fSAndroid Build Coastguard Worker<Para> 1255*6a54128fSAndroid Build Coastguard Worker Use some <Literal remap="tt">dispatch / direct </Literal> calls in order to pass control to 1256*6a54128fSAndroid Build Coastguard Workerother lower-level user commands. 1257*6a54128fSAndroid Build Coastguard Worker</Para> 1258*6a54128fSAndroid Build Coastguard Worker</ListItem> 1259*6a54128fSAndroid Build Coastguard Worker<ListItem> 1260*6a54128fSAndroid Build Coastguard Worker 1261*6a54128fSAndroid Build Coastguard Worker<Para> 1262*6a54128fSAndroid Build Coastguard Worker Sometimes <Literal remap="tt">dispatch</Literal> to the object's <Literal remap="tt">show</Literal> command to 1263*6a54128fSAndroid Build Coastguard Workerdisplay the resulting data to the user. 1264*6a54128fSAndroid Build Coastguard Worker</Para> 1265*6a54128fSAndroid Build Coastguard Worker</ListItem> 1266*6a54128fSAndroid Build Coastguard Worker 1267*6a54128fSAndroid Build Coastguard Worker</OrderedList> 1268*6a54128fSAndroid Build Coastguard Worker 1269*6a54128fSAndroid Build Coastguard WorkerI told you it is meaningless :-) 1270*6a54128fSAndroid Build Coastguard Worker</Para> 1271*6a54128fSAndroid Build Coastguard Worker 1272*6a54128fSAndroid Build Coastguard Worker</Sect3> 1273*6a54128fSAndroid Build Coastguard Worker 1274*6a54128fSAndroid Build Coastguard Worker</Sect2> 1275*6a54128fSAndroid Build Coastguard Worker 1276*6a54128fSAndroid Build Coastguard Worker</Sect1> 1277*6a54128fSAndroid Build Coastguard Worker 1278*6a54128fSAndroid Build Coastguard Worker<Sect1> 1279*6a54128fSAndroid Build Coastguard Worker<Title>Initialization overview</Title> 1280*6a54128fSAndroid Build Coastguard Worker 1281*6a54128fSAndroid Build Coastguard Worker<Para> 1282*6a54128fSAndroid Build Coastguard WorkerIn this section I will discuss some aspects of the various initialization 1283*6a54128fSAndroid Build Coastguard Workerroutines available in the source file <Literal remap="tt">init.c</Literal>. 1284*6a54128fSAndroid Build Coastguard Worker</Para> 1285*6a54128fSAndroid Build Coastguard Worker 1286*6a54128fSAndroid Build Coastguard Worker<Sect2> 1287*6a54128fSAndroid Build Coastguard Worker<Title>Upon startup</Title> 1288*6a54128fSAndroid Build Coastguard Worker 1289*6a54128fSAndroid Build Coastguard Worker<Para> 1290*6a54128fSAndroid Build Coastguard WorkerFollows the function <Literal remap="tt">main</Literal>, appearing of-course in <Literal remap="tt">main.c</Literal>: 1291*6a54128fSAndroid Build Coastguard Worker 1292*6a54128fSAndroid Build Coastguard Worker 1293*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 1294*6a54128fSAndroid Build Coastguard Workerint main (void) 1295*6a54128fSAndroid Build Coastguard Worker 1296*6a54128fSAndroid Build Coastguard Worker{ 1297*6a54128fSAndroid Build Coastguard Worker if (!init ()) return (0); /* Perform some initial initialization */ 1298*6a54128fSAndroid Build Coastguard Worker /* Quit if failed */ 1299*6a54128fSAndroid Build Coastguard Worker 1300*6a54128fSAndroid Build Coastguard Worker parser (); /* Get and parse user commands */ 1301*6a54128fSAndroid Build Coastguard Worker 1302*6a54128fSAndroid Build Coastguard Worker prepare_to_close (); /* Do some cleanup */ 1303*6a54128fSAndroid Build Coastguard Worker printf ("Quitting ...\n"); 1304*6a54128fSAndroid Build Coastguard Worker return (1); /* And quit */ 1305*6a54128fSAndroid Build Coastguard Worker} 1306*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 1307*6a54128fSAndroid Build Coastguard Worker 1308*6a54128fSAndroid Build Coastguard Worker</Para> 1309*6a54128fSAndroid Build Coastguard Worker 1310*6a54128fSAndroid Build Coastguard Worker<Para> 1311*6a54128fSAndroid Build Coastguard WorkerThe two initialization functions, which are called by <Literal remap="tt">main</Literal>, are: 1312*6a54128fSAndroid Build Coastguard Worker 1313*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1314*6a54128fSAndroid Build Coastguard Worker<ListItem> 1315*6a54128fSAndroid Build Coastguard Worker 1316*6a54128fSAndroid Build Coastguard Worker<Para> 1317*6a54128fSAndroid Build Coastguard Worker init 1318*6a54128fSAndroid Build Coastguard Worker</Para> 1319*6a54128fSAndroid Build Coastguard Worker</ListItem> 1320*6a54128fSAndroid Build Coastguard Worker<ListItem> 1321*6a54128fSAndroid Build Coastguard Worker 1322*6a54128fSAndroid Build Coastguard Worker<Para> 1323*6a54128fSAndroid Build Coastguard Worker prepare_to_close 1324*6a54128fSAndroid Build Coastguard Worker</Para> 1325*6a54128fSAndroid Build Coastguard Worker</ListItem> 1326*6a54128fSAndroid Build Coastguard Worker 1327*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1328*6a54128fSAndroid Build Coastguard Worker 1329*6a54128fSAndroid Build Coastguard Worker</Para> 1330*6a54128fSAndroid Build Coastguard Worker 1331*6a54128fSAndroid Build Coastguard Worker<Sect3> 1332*6a54128fSAndroid Build Coastguard Worker<Title>The init function</Title> 1333*6a54128fSAndroid Build Coastguard Worker 1334*6a54128fSAndroid Build Coastguard Worker<Para> 1335*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">init</Literal> is called from <Literal remap="tt">main</Literal> upon startup. It initializes the 1336*6a54128fSAndroid Build Coastguard Workerfollowing tasks / subsystems: 1337*6a54128fSAndroid Build Coastguard Worker 1338*6a54128fSAndroid Build Coastguard Worker<OrderedList> 1339*6a54128fSAndroid Build Coastguard Worker<ListItem> 1340*6a54128fSAndroid Build Coastguard Worker 1341*6a54128fSAndroid Build Coastguard Worker<Para> 1342*6a54128fSAndroid Build Coastguard Worker Processing of the <Literal remap="tt">user configuration file</Literal>, by using the 1343*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">process_configuration_file</Literal> function. Failing to complete the 1344*6a54128fSAndroid Build Coastguard Workerconfiguration file processing is considered a <Literal remap="tt">fatal error</Literal>, 1345*6a54128fSAndroid Build Coastguard Workerand EXT2ED is aborted. I did it this way because the configuration 1346*6a54128fSAndroid Build Coastguard Workerfile has some sensitive user options like write access behavior, and 1347*6a54128fSAndroid Build Coastguard WorkerI wanted to be sure that the user is aware of them. 1348*6a54128fSAndroid Build Coastguard Worker</Para> 1349*6a54128fSAndroid Build Coastguard Worker</ListItem> 1350*6a54128fSAndroid Build Coastguard Worker<ListItem> 1351*6a54128fSAndroid Build Coastguard Worker 1352*6a54128fSAndroid Build Coastguard Worker<Para> 1353*6a54128fSAndroid Build Coastguard Worker Registration of the <Literal remap="tt">general commands</Literal> through the use of 1354*6a54128fSAndroid Build Coastguard Workerthe <Literal remap="tt">add_general_commands</Literal> function. 1355*6a54128fSAndroid Build Coastguard Worker</Para> 1356*6a54128fSAndroid Build Coastguard Worker</ListItem> 1357*6a54128fSAndroid Build Coastguard Worker<ListItem> 1358*6a54128fSAndroid Build Coastguard Worker 1359*6a54128fSAndroid Build Coastguard Worker<Para> 1360*6a54128fSAndroid Build Coastguard Worker Reset of the object memory rotating lifo structure. 1361*6a54128fSAndroid Build Coastguard Worker</Para> 1362*6a54128fSAndroid Build Coastguard Worker</ListItem> 1363*6a54128fSAndroid Build Coastguard Worker<ListItem> 1364*6a54128fSAndroid Build Coastguard Worker 1365*6a54128fSAndroid Build Coastguard Worker<Para> 1366*6a54128fSAndroid Build Coastguard Worker Reset of the device parameters and of the current type. 1367*6a54128fSAndroid Build Coastguard Worker</Para> 1368*6a54128fSAndroid Build Coastguard Worker</ListItem> 1369*6a54128fSAndroid Build Coastguard Worker<ListItem> 1370*6a54128fSAndroid Build Coastguard Worker 1371*6a54128fSAndroid Build Coastguard Worker<Para> 1372*6a54128fSAndroid Build Coastguard Worker Initialization of the windows subsystem - The interface between the 1373*6a54128fSAndroid Build Coastguard Workerncurses library and EXT2ED, through the use of the <Literal remap="tt">init_windows</Literal> 1374*6a54128fSAndroid Build Coastguard Workerfunction, available in <Literal remap="tt">win.c</Literal>. 1375*6a54128fSAndroid Build Coastguard Worker</Para> 1376*6a54128fSAndroid Build Coastguard Worker</ListItem> 1377*6a54128fSAndroid Build Coastguard Worker<ListItem> 1378*6a54128fSAndroid Build Coastguard Worker 1379*6a54128fSAndroid Build Coastguard Worker<Para> 1380*6a54128fSAndroid Build Coastguard Worker Initialization of the interface between the readline library and 1381*6a54128fSAndroid Build Coastguard WorkerEXT2ED, through <Literal remap="tt">init_readline</Literal>. 1382*6a54128fSAndroid Build Coastguard Worker</Para> 1383*6a54128fSAndroid Build Coastguard Worker</ListItem> 1384*6a54128fSAndroid Build Coastguard Worker<ListItem> 1385*6a54128fSAndroid Build Coastguard Worker 1386*6a54128fSAndroid Build Coastguard Worker<Para> 1387*6a54128fSAndroid Build Coastguard Worker Initialization of the <Literal remap="tt">signals</Literal> subsystem, through 1388*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">init_signals</Literal>. 1389*6a54128fSAndroid Build Coastguard Worker</Para> 1390*6a54128fSAndroid Build Coastguard Worker</ListItem> 1391*6a54128fSAndroid Build Coastguard Worker<ListItem> 1392*6a54128fSAndroid Build Coastguard Worker 1393*6a54128fSAndroid Build Coastguard Worker<Para> 1394*6a54128fSAndroid Build Coastguard Worker Disabling write access. Write access needs to be explicitly enabled 1395*6a54128fSAndroid Build Coastguard Workerusing a user command, to prevent accidental user mistakes. 1396*6a54128fSAndroid Build Coastguard Worker</Para> 1397*6a54128fSAndroid Build Coastguard Worker</ListItem> 1398*6a54128fSAndroid Build Coastguard Worker 1399*6a54128fSAndroid Build Coastguard Worker</OrderedList> 1400*6a54128fSAndroid Build Coastguard Worker 1401*6a54128fSAndroid Build Coastguard WorkerWhen <Literal remap="tt">init</Literal> is finished, it dispatches the <Literal remap="tt">help</Literal> command in order 1402*6a54128fSAndroid Build Coastguard Workerto show the available commands to the user. Note that the ext2 layer is still 1403*6a54128fSAndroid Build Coastguard Workernot added; It will be added if and when EXT2ED will detect an ext2 1404*6a54128fSAndroid Build Coastguard Workerfilesystem on a device. 1405*6a54128fSAndroid Build Coastguard Worker</Para> 1406*6a54128fSAndroid Build Coastguard Worker 1407*6a54128fSAndroid Build Coastguard Worker</Sect3> 1408*6a54128fSAndroid Build Coastguard Worker 1409*6a54128fSAndroid Build Coastguard Worker<Sect3> 1410*6a54128fSAndroid Build Coastguard Worker<Title>The prepare_to_close function</Title> 1411*6a54128fSAndroid Build Coastguard Worker 1412*6a54128fSAndroid Build Coastguard Worker<Para> 1413*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">prepare_to_close</Literal> function reverses some of the actions done 1414*6a54128fSAndroid Build Coastguard Workerearlier in EXT2ED and freeing the dynamically allocated memory. 1415*6a54128fSAndroid Build Coastguard WorkerSpecifically, it: 1416*6a54128fSAndroid Build Coastguard Worker 1417*6a54128fSAndroid Build Coastguard Worker<OrderedList> 1418*6a54128fSAndroid Build Coastguard Worker<ListItem> 1419*6a54128fSAndroid Build Coastguard Worker 1420*6a54128fSAndroid Build Coastguard Worker<Para> 1421*6a54128fSAndroid Build Coastguard Worker Closes the open device, if any. 1422*6a54128fSAndroid Build Coastguard Worker</Para> 1423*6a54128fSAndroid Build Coastguard Worker</ListItem> 1424*6a54128fSAndroid Build Coastguard Worker<ListItem> 1425*6a54128fSAndroid Build Coastguard Worker 1426*6a54128fSAndroid Build Coastguard Worker<Para> 1427*6a54128fSAndroid Build Coastguard Worker Removes the first level - Removing the general commands, through 1428*6a54128fSAndroid Build Coastguard Workerthe use of <Literal remap="tt">free_user_commands</Literal>, with a pointer to the 1429*6a54128fSAndroid Build Coastguard Workergeneral_commands structure as a parameter. 1430*6a54128fSAndroid Build Coastguard Worker</Para> 1431*6a54128fSAndroid Build Coastguard Worker</ListItem> 1432*6a54128fSAndroid Build Coastguard Worker<ListItem> 1433*6a54128fSAndroid Build Coastguard Worker 1434*6a54128fSAndroid Build Coastguard Worker<Para> 1435*6a54128fSAndroid Build Coastguard Worker Removes of the second level - Removing the ext2 ext2 general 1436*6a54128fSAndroid Build Coastguard Workercommands, in much the same way. 1437*6a54128fSAndroid Build Coastguard Worker</Para> 1438*6a54128fSAndroid Build Coastguard Worker</ListItem> 1439*6a54128fSAndroid Build Coastguard Worker<ListItem> 1440*6a54128fSAndroid Build Coastguard Worker 1441*6a54128fSAndroid Build Coastguard Worker<Para> 1442*6a54128fSAndroid Build Coastguard Worker Removes of the third level - Removing the objects and the object 1443*6a54128fSAndroid Build Coastguard Workerspecific commands, by using <Literal remap="tt">free_struct_descriptors</Literal>. 1444*6a54128fSAndroid Build Coastguard Worker</Para> 1445*6a54128fSAndroid Build Coastguard Worker</ListItem> 1446*6a54128fSAndroid Build Coastguard Worker<ListItem> 1447*6a54128fSAndroid Build Coastguard Worker 1448*6a54128fSAndroid Build Coastguard Worker<Para> 1449*6a54128fSAndroid Build Coastguard Worker Closes the window subsystem, and detaches EXT2ED from the ncurses 1450*6a54128fSAndroid Build Coastguard Workerlibrary, through the use of the <Literal remap="tt">close_windows</Literal> function, 1451*6a54128fSAndroid Build Coastguard Workeravailable in <Literal remap="tt">win.c</Literal>. 1452*6a54128fSAndroid Build Coastguard Worker</Para> 1453*6a54128fSAndroid Build Coastguard Worker</ListItem> 1454*6a54128fSAndroid Build Coastguard Worker 1455*6a54128fSAndroid Build Coastguard Worker</OrderedList> 1456*6a54128fSAndroid Build Coastguard Worker 1457*6a54128fSAndroid Build Coastguard Worker</Para> 1458*6a54128fSAndroid Build Coastguard Worker 1459*6a54128fSAndroid Build Coastguard Worker</Sect3> 1460*6a54128fSAndroid Build Coastguard Worker 1461*6a54128fSAndroid Build Coastguard Worker</Sect2> 1462*6a54128fSAndroid Build Coastguard Worker 1463*6a54128fSAndroid Build Coastguard Worker<Sect2> 1464*6a54128fSAndroid Build Coastguard Worker<Title>Registration of commands</Title> 1465*6a54128fSAndroid Build Coastguard Worker 1466*6a54128fSAndroid Build Coastguard Worker<Para> 1467*6a54128fSAndroid Build Coastguard WorkerAddition of a user command is done through the <Literal remap="tt">add_user_command</Literal> 1468*6a54128fSAndroid Build Coastguard Workerfunction. The prototype is: 1469*6a54128fSAndroid Build Coastguard Worker 1470*6a54128fSAndroid Build Coastguard Worker<Screen> 1471*6a54128fSAndroid Build Coastguard Workervoid add_user_command (struct struct_commands *ptr,char *name,char 1472*6a54128fSAndroid Build Coastguard Worker*description,PF callback); 1473*6a54128fSAndroid Build Coastguard Worker</Screen> 1474*6a54128fSAndroid Build Coastguard Worker 1475*6a54128fSAndroid Build Coastguard WorkerThe function receives a pointer to a structure of type 1476*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct_commands</Literal>, a desired name for the command which will be used by 1477*6a54128fSAndroid Build Coastguard Workerthe user to identify the command, a short description which is utilized by the 1478*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">help</Literal> subsystem, and a pointer to a C function which will be called if 1479*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">dispatch</Literal> decides that this command was requested. 1480*6a54128fSAndroid Build Coastguard Worker</Para> 1481*6a54128fSAndroid Build Coastguard Worker 1482*6a54128fSAndroid Build Coastguard Worker<Para> 1483*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">add_user_command</Literal> is a <Literal remap="tt">low level function</Literal> used in the three 1484*6a54128fSAndroid Build Coastguard Workerlevels to add user commands. For example, addition of the <Literal remap="tt">ext2 1485*6a54128fSAndroid Build Coastguard Workergeneral commands is done by:</Literal> 1486*6a54128fSAndroid Build Coastguard Worker 1487*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 1488*6a54128fSAndroid Build Coastguard Workervoid add_ext2_general_commands (void) 1489*6a54128fSAndroid Build Coastguard Worker 1490*6a54128fSAndroid Build Coastguard Worker{ 1491*6a54128fSAndroid Build Coastguard Worker add_user_command (&ext2_commands,"super","Moves to the superblock of the filesystem",type_ext2___super); 1492*6a54128fSAndroid Build Coastguard Worker add_user_command (&ext2_commands,"group","Moves to the first group descriptor",type_ext2___group); 1493*6a54128fSAndroid Build Coastguard Worker add_user_command (&ext2_commands,"cd","Moves to the directory specified",type_ext2___cd); 1494*6a54128fSAndroid Build Coastguard Worker} 1495*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 1496*6a54128fSAndroid Build Coastguard Worker 1497*6a54128fSAndroid Build Coastguard Worker</Para> 1498*6a54128fSAndroid Build Coastguard Worker 1499*6a54128fSAndroid Build Coastguard Worker</Sect2> 1500*6a54128fSAndroid Build Coastguard Worker 1501*6a54128fSAndroid Build Coastguard Worker<Sect2> 1502*6a54128fSAndroid Build Coastguard Worker<Title>Registration of objects</Title> 1503*6a54128fSAndroid Build Coastguard Worker 1504*6a54128fSAndroid Build Coastguard Worker<Para> 1505*6a54128fSAndroid Build Coastguard WorkerRegistration of objects is based, as explained earlier, on the "compilation" 1506*6a54128fSAndroid Build Coastguard Workerof an external user file, which has a syntax similar to the C language 1507*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">struct</Literal> keyword. The primitive parser I have implemented detects the 1508*6a54128fSAndroid Build Coastguard Workerdefinition of structures, and calls some lower level functions to actually 1509*6a54128fSAndroid Build Coastguard Workerregister the new detected object. The parser's prototype is: 1510*6a54128fSAndroid Build Coastguard Worker 1511*6a54128fSAndroid Build Coastguard Worker<Screen> 1512*6a54128fSAndroid Build Coastguard Workerint set_struct_descriptors (char *file_name) 1513*6a54128fSAndroid Build Coastguard Worker</Screen> 1514*6a54128fSAndroid Build Coastguard Worker 1515*6a54128fSAndroid Build Coastguard WorkerIt opens the given file name, and calls, when appropriate: 1516*6a54128fSAndroid Build Coastguard Worker 1517*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1518*6a54128fSAndroid Build Coastguard Worker<ListItem> 1519*6a54128fSAndroid Build Coastguard Worker 1520*6a54128fSAndroid Build Coastguard Worker<Para> 1521*6a54128fSAndroid Build Coastguard Worker add_new_descriptor 1522*6a54128fSAndroid Build Coastguard Worker</Para> 1523*6a54128fSAndroid Build Coastguard Worker</ListItem> 1524*6a54128fSAndroid Build Coastguard Worker<ListItem> 1525*6a54128fSAndroid Build Coastguard Worker 1526*6a54128fSAndroid Build Coastguard Worker<Para> 1527*6a54128fSAndroid Build Coastguard Worker add_new_variable 1528*6a54128fSAndroid Build Coastguard Worker</Para> 1529*6a54128fSAndroid Build Coastguard Worker</ListItem> 1530*6a54128fSAndroid Build Coastguard Worker 1531*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1532*6a54128fSAndroid Build Coastguard Worker 1533*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">add_new_descriptor</Literal> is a low level function which adds a new descriptor 1534*6a54128fSAndroid Build Coastguard Workerto the doubly linked list of the available objects. It will then call 1535*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">fill_type_commands</Literal>, which will add specific commands to the object, 1536*6a54128fSAndroid Build Coastguard Workerif the object is known. 1537*6a54128fSAndroid Build Coastguard Worker</Para> 1538*6a54128fSAndroid Build Coastguard Worker 1539*6a54128fSAndroid Build Coastguard Worker<Para> 1540*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">add_new_variable</Literal> will add a new variable of the requested length to the 1541*6a54128fSAndroid Build Coastguard Workerspecified descriptor. 1542*6a54128fSAndroid Build Coastguard Worker</Para> 1543*6a54128fSAndroid Build Coastguard Worker 1544*6a54128fSAndroid Build Coastguard Worker</Sect2> 1545*6a54128fSAndroid Build Coastguard Worker 1546*6a54128fSAndroid Build Coastguard Worker<Sect2> 1547*6a54128fSAndroid Build Coastguard Worker<Title>Initialization upon specification of a device</Title> 1548*6a54128fSAndroid Build Coastguard Worker 1549*6a54128fSAndroid Build Coastguard Worker<Para> 1550*6a54128fSAndroid Build Coastguard WorkerWhen the general command <Literal remap="tt">setdevice</Literal> is used to open a device, some 1551*6a54128fSAndroid Build Coastguard Workerinitialization sequence takes place, which is intended to determine two 1552*6a54128fSAndroid Build Coastguard Workerfactors: 1553*6a54128fSAndroid Build Coastguard Worker 1554*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1555*6a54128fSAndroid Build Coastguard Worker<ListItem> 1556*6a54128fSAndroid Build Coastguard Worker 1557*6a54128fSAndroid Build Coastguard Worker<Para> 1558*6a54128fSAndroid Build Coastguard Worker Are we dealing with an ext2 filesystem ? 1559*6a54128fSAndroid Build Coastguard Worker</Para> 1560*6a54128fSAndroid Build Coastguard Worker</ListItem> 1561*6a54128fSAndroid Build Coastguard Worker<ListItem> 1562*6a54128fSAndroid Build Coastguard Worker 1563*6a54128fSAndroid Build Coastguard Worker<Para> 1564*6a54128fSAndroid Build Coastguard Worker What are the basic filesystem parameters, such as its total size and 1565*6a54128fSAndroid Build Coastguard Workerits block size ? 1566*6a54128fSAndroid Build Coastguard Worker</Para> 1567*6a54128fSAndroid Build Coastguard Worker</ListItem> 1568*6a54128fSAndroid Build Coastguard Worker 1569*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1570*6a54128fSAndroid Build Coastguard Worker 1571*6a54128fSAndroid Build Coastguard WorkerThis questions are answered by the <Literal remap="tt">set_file_system_info</Literal>, possibly 1572*6a54128fSAndroid Build Coastguard Workerusing some <Literal remap="tt">help from the user</Literal>, through the configuration file. 1573*6a54128fSAndroid Build Coastguard WorkerThe answers are placed in the <Literal remap="tt">file_system_info</Literal> structure, which is of 1574*6a54128fSAndroid Build Coastguard Workertype <Literal remap="tt">struct_file_system_info</Literal>: 1575*6a54128fSAndroid Build Coastguard Worker 1576*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 1577*6a54128fSAndroid Build Coastguard Workerstruct struct_file_system_info { 1578*6a54128fSAndroid Build Coastguard Worker unsigned long file_system_size; 1579*6a54128fSAndroid Build Coastguard Worker unsigned long super_block_offset; 1580*6a54128fSAndroid Build Coastguard Worker unsigned long first_group_desc_offset; 1581*6a54128fSAndroid Build Coastguard Worker unsigned long groups_count; 1582*6a54128fSAndroid Build Coastguard Worker unsigned long inodes_per_block; 1583*6a54128fSAndroid Build Coastguard Worker unsigned long blocks_per_group; /* The name is misleading; beware */ 1584*6a54128fSAndroid Build Coastguard Worker unsigned long no_blocks_in_group; 1585*6a54128fSAndroid Build Coastguard Worker unsigned short block_size; 1586*6a54128fSAndroid Build Coastguard Worker struct ext2_super_block super_block; 1587*6a54128fSAndroid Build Coastguard Worker}; 1588*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 1589*6a54128fSAndroid Build Coastguard Worker 1590*6a54128fSAndroid Build Coastguard Worker</Para> 1591*6a54128fSAndroid Build Coastguard Worker 1592*6a54128fSAndroid Build Coastguard Worker<Para> 1593*6a54128fSAndroid Build Coastguard WorkerAutodetection of an ext2 filesystem is usually recommended. However, on a damaged 1594*6a54128fSAndroid Build Coastguard Workerfilesystem I can't assure a success. That's were the user comes in - He can 1595*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">override</Literal> the auto detection procedure and force an ext2 filesystem, by 1596*6a54128fSAndroid Build Coastguard Workerselecting the proper options in the configuration file. 1597*6a54128fSAndroid Build Coastguard Worker</Para> 1598*6a54128fSAndroid Build Coastguard Worker 1599*6a54128fSAndroid Build Coastguard Worker<Para> 1600*6a54128fSAndroid Build Coastguard WorkerIf auto detection succeeds, the second question above is automatically 1601*6a54128fSAndroid Build Coastguard Workeranswered - I get all the information I need from the filesystem itself. In 1602*6a54128fSAndroid Build Coastguard Workerany case, default parameters can be supplied in the configuration file and 1603*6a54128fSAndroid Build Coastguard Workerthe user can select the required behavior. 1604*6a54128fSAndroid Build Coastguard Worker</Para> 1605*6a54128fSAndroid Build Coastguard Worker 1606*6a54128fSAndroid Build Coastguard Worker<Para> 1607*6a54128fSAndroid Build Coastguard WorkerIf we decide to treat the filesystem as an ext2 filesystem, <Literal remap="tt">registration of 1608*6a54128fSAndroid Build Coastguard Workerthe ext2 specific objects</Literal> is done at this point, by calling the 1609*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">set_struct_descriptors</Literal> outlined earlier, with the name of the file 1610*6a54128fSAndroid Build Coastguard Workerwhich describes the ext2 objects, and is basically based on the ext2 sources 1611*6a54128fSAndroid Build Coastguard Workermain include file. At this point, EXT2ED can be fully used by the user. 1612*6a54128fSAndroid Build Coastguard Worker</Para> 1613*6a54128fSAndroid Build Coastguard Worker 1614*6a54128fSAndroid Build Coastguard Worker<Para> 1615*6a54128fSAndroid Build Coastguard WorkerIf we do not register the ext2 specific objects, the user can still provide 1616*6a54128fSAndroid Build Coastguard Workerobject definitions in a separate file, and will be able to use EXT2ED in a 1617*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">limited form</Literal>, but more sophisticated than a simple hex editor. 1618*6a54128fSAndroid Build Coastguard Worker</Para> 1619*6a54128fSAndroid Build Coastguard Worker 1620*6a54128fSAndroid Build Coastguard Worker</Sect2> 1621*6a54128fSAndroid Build Coastguard Worker 1622*6a54128fSAndroid Build Coastguard Worker</Sect1> 1623*6a54128fSAndroid Build Coastguard Worker 1624*6a54128fSAndroid Build Coastguard Worker<Sect1> 1625*6a54128fSAndroid Build Coastguard Worker<Title>main.c</Title> 1626*6a54128fSAndroid Build Coastguard Worker 1627*6a54128fSAndroid Build Coastguard Worker<Para> 1628*6a54128fSAndroid Build Coastguard WorkerAs described earlier, <Literal remap="tt">main.c</Literal> is used as a front-head to the entire 1629*6a54128fSAndroid Build Coastguard Workerprogram. <Literal remap="tt">main.c</Literal> contains the following elements: 1630*6a54128fSAndroid Build Coastguard Worker</Para> 1631*6a54128fSAndroid Build Coastguard Worker 1632*6a54128fSAndroid Build Coastguard Worker<Sect2> 1633*6a54128fSAndroid Build Coastguard Worker<Title>The main routine</Title> 1634*6a54128fSAndroid Build Coastguard Worker 1635*6a54128fSAndroid Build Coastguard Worker<Para> 1636*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">main</Literal> routine was displayed above. Its task is to pass control to 1637*6a54128fSAndroid Build Coastguard Workerthe initialization routines and to the parser. 1638*6a54128fSAndroid Build Coastguard Worker</Para> 1639*6a54128fSAndroid Build Coastguard Worker 1640*6a54128fSAndroid Build Coastguard Worker</Sect2> 1641*6a54128fSAndroid Build Coastguard Worker 1642*6a54128fSAndroid Build Coastguard Worker<Sect2> 1643*6a54128fSAndroid Build Coastguard Worker<Title>The parser</Title> 1644*6a54128fSAndroid Build Coastguard Worker 1645*6a54128fSAndroid Build Coastguard Worker<Para> 1646*6a54128fSAndroid Build Coastguard WorkerThe parser consists of the following functions: 1647*6a54128fSAndroid Build Coastguard Worker 1648*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1649*6a54128fSAndroid Build Coastguard Worker<ListItem> 1650*6a54128fSAndroid Build Coastguard Worker 1651*6a54128fSAndroid Build Coastguard Worker<Para> 1652*6a54128fSAndroid Build Coastguard Worker The <Literal remap="tt">parser</Literal> function, which reads the command line from the 1653*6a54128fSAndroid Build Coastguard Workeruser and saves it in readline's history buffer and in the internal 1654*6a54128fSAndroid Build Coastguard Workerlast-command buffer. 1655*6a54128fSAndroid Build Coastguard Worker</Para> 1656*6a54128fSAndroid Build Coastguard Worker</ListItem> 1657*6a54128fSAndroid Build Coastguard Worker<ListItem> 1658*6a54128fSAndroid Build Coastguard Worker 1659*6a54128fSAndroid Build Coastguard Worker<Para> 1660*6a54128fSAndroid Build Coastguard Worker The <Literal remap="tt">parse_word</Literal> function, which receives a string and parses 1661*6a54128fSAndroid Build Coastguard Workerthe first word from it, ignoring whitespaces, and returns a pointer 1662*6a54128fSAndroid Build Coastguard Workerto the rest of the string. 1663*6a54128fSAndroid Build Coastguard Worker</Para> 1664*6a54128fSAndroid Build Coastguard Worker</ListItem> 1665*6a54128fSAndroid Build Coastguard Worker<ListItem> 1666*6a54128fSAndroid Build Coastguard Worker 1667*6a54128fSAndroid Build Coastguard Worker<Para> 1668*6a54128fSAndroid Build Coastguard Worker The <Literal remap="tt">complete_command</Literal> function, which is used by the readline 1669*6a54128fSAndroid Build Coastguard Workerlibrary for command completion. It scans the available commands at 1670*6a54128fSAndroid Build Coastguard Workerthis point and determines the possible completions. 1671*6a54128fSAndroid Build Coastguard Worker</Para> 1672*6a54128fSAndroid Build Coastguard Worker</ListItem> 1673*6a54128fSAndroid Build Coastguard Worker 1674*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1675*6a54128fSAndroid Build Coastguard Worker 1676*6a54128fSAndroid Build Coastguard Worker</Para> 1677*6a54128fSAndroid Build Coastguard Worker 1678*6a54128fSAndroid Build Coastguard Worker</Sect2> 1679*6a54128fSAndroid Build Coastguard Worker 1680*6a54128fSAndroid Build Coastguard Worker<Sect2> 1681*6a54128fSAndroid Build Coastguard Worker<Title>The dispatcher</Title> 1682*6a54128fSAndroid Build Coastguard Worker 1683*6a54128fSAndroid Build Coastguard Worker<Para> 1684*6a54128fSAndroid Build Coastguard WorkerThe dispatcher was already explained in the flow control section - section 1685*6a54128fSAndroid Build Coastguard Worker<XRef LinkEnd="flow-control">. Its task is to pass control to the proper command 1686*6a54128fSAndroid Build Coastguard Workerhandling function, based on the command line's command. 1687*6a54128fSAndroid Build Coastguard Worker</Para> 1688*6a54128fSAndroid Build Coastguard Worker 1689*6a54128fSAndroid Build Coastguard Worker</Sect2> 1690*6a54128fSAndroid Build Coastguard Worker 1691*6a54128fSAndroid Build Coastguard Worker<Sect2> 1692*6a54128fSAndroid Build Coastguard Worker<Title>The self-sanity control</Title> 1693*6a54128fSAndroid Build Coastguard Worker 1694*6a54128fSAndroid Build Coastguard Worker<Para> 1695*6a54128fSAndroid Build Coastguard WorkerThis is not fully implemented. 1696*6a54128fSAndroid Build Coastguard Worker</Para> 1697*6a54128fSAndroid Build Coastguard Worker 1698*6a54128fSAndroid Build Coastguard Worker<Para> 1699*6a54128fSAndroid Build Coastguard WorkerThe general idea was to provide a control system which will supervise the 1700*6a54128fSAndroid Build Coastguard Workerinternal work of EXT2ED. Since I am pretty sure that bugs exist, I have 1701*6a54128fSAndroid Build Coastguard Workerdouble checked myself in a few instances, and issued an <Literal remap="tt">internal 1702*6a54128fSAndroid Build Coastguard Workererror</Literal> warning if I reached the conclusion that something is not logical. 1703*6a54128fSAndroid Build Coastguard WorkerThe internal error is reported by the function <Literal remap="tt">internal_error</Literal>, 1704*6a54128fSAndroid Build Coastguard Workeravailable in <Literal remap="tt">main.c</Literal>. 1705*6a54128fSAndroid Build Coastguard Worker</Para> 1706*6a54128fSAndroid Build Coastguard Worker 1707*6a54128fSAndroid Build Coastguard Worker<Para> 1708*6a54128fSAndroid Build Coastguard WorkerThe self sanity check is compiled only if the compile time option 1709*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">DEBUG</Literal> is selected. 1710*6a54128fSAndroid Build Coastguard Worker</Para> 1711*6a54128fSAndroid Build Coastguard Worker 1712*6a54128fSAndroid Build Coastguard Worker</Sect2> 1713*6a54128fSAndroid Build Coastguard Worker 1714*6a54128fSAndroid Build Coastguard Worker</Sect1> 1715*6a54128fSAndroid Build Coastguard Worker 1716*6a54128fSAndroid Build Coastguard Worker<Sect1> 1717*6a54128fSAndroid Build Coastguard Worker<Title>The windows interface</Title> 1718*6a54128fSAndroid Build Coastguard Worker 1719*6a54128fSAndroid Build Coastguard Worker<Para> 1720*6a54128fSAndroid Build Coastguard WorkerScreen handling and interfacing to the <Literal remap="tt">ncurses</Literal> library is done in 1721*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">win.c</Literal>. 1722*6a54128fSAndroid Build Coastguard Worker</Para> 1723*6a54128fSAndroid Build Coastguard Worker 1724*6a54128fSAndroid Build Coastguard Worker<Sect2> 1725*6a54128fSAndroid Build Coastguard Worker<Title>Initialization</Title> 1726*6a54128fSAndroid Build Coastguard Worker 1727*6a54128fSAndroid Build Coastguard Worker<Para> 1728*6a54128fSAndroid Build Coastguard WorkerOpening of the windows is done in <Literal remap="tt">init_windows</Literal>. In 1729*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">close_windows</Literal>, we just close our windows. The various window lengths 1730*6a54128fSAndroid Build Coastguard Workerwith an exception to the <Literal remap="tt">show pad</Literal> are defined in the main header file. 1731*6a54128fSAndroid Build Coastguard WorkerThe rest of the display will be used by the <Literal remap="tt">show pad</Literal>. 1732*6a54128fSAndroid Build Coastguard Worker</Para> 1733*6a54128fSAndroid Build Coastguard Worker 1734*6a54128fSAndroid Build Coastguard Worker</Sect2> 1735*6a54128fSAndroid Build Coastguard Worker 1736*6a54128fSAndroid Build Coastguard Worker<Sect2> 1737*6a54128fSAndroid Build Coastguard Worker<Title>Display output</Title> 1738*6a54128fSAndroid Build Coastguard Worker 1739*6a54128fSAndroid Build Coastguard Worker<Para> 1740*6a54128fSAndroid Build Coastguard WorkerEach actual refreshing of the terminal monitor is done by using the 1741*6a54128fSAndroid Build Coastguard Workerappropriate refresh function from this file: <Literal remap="tt">refresh_title_win</Literal>, 1742*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">refresh_show_win</Literal>, <Literal remap="tt">refresh_show_pad</Literal> and 1743*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">refresh_command_win</Literal>. 1744*6a54128fSAndroid Build Coastguard Worker</Para> 1745*6a54128fSAndroid Build Coastguard Worker 1746*6a54128fSAndroid Build Coastguard Worker<Para> 1747*6a54128fSAndroid Build Coastguard WorkerWith the exception of the <Literal remap="tt">show pad</Literal>, each function simply calls the 1748*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ncurses refresh command</Literal>. In order to provide to <Literal remap="tt">scrolling</Literal> in 1749*6a54128fSAndroid Build Coastguard Workerthe <Literal remap="tt">show pad</Literal>, some information about its status is constantly updated 1750*6a54128fSAndroid Build Coastguard Workerby the various functions which display output in it. <Literal remap="tt">refresh_show_pad</Literal> 1751*6a54128fSAndroid Build Coastguard Workerpasses this information to <Literal remap="tt">ncurses</Literal> so that the correct part of the pad 1752*6a54128fSAndroid Build Coastguard Workeris actually copied to the display. 1753*6a54128fSAndroid Build Coastguard Worker</Para> 1754*6a54128fSAndroid Build Coastguard Worker 1755*6a54128fSAndroid Build Coastguard Worker<Para> 1756*6a54128fSAndroid Build Coastguard WorkerThe above information is saved in a global variable of type <Literal remap="tt">struct 1757*6a54128fSAndroid Build Coastguard Workerstruct_pad_info</Literal>: 1758*6a54128fSAndroid Build Coastguard Worker</Para> 1759*6a54128fSAndroid Build Coastguard Worker 1760*6a54128fSAndroid Build Coastguard Worker<Para> 1761*6a54128fSAndroid Build Coastguard Worker 1762*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 1763*6a54128fSAndroid Build Coastguard Workerstruct struct_pad_info { 1764*6a54128fSAndroid Build Coastguard Worker int display_lines,display_cols; 1765*6a54128fSAndroid Build Coastguard Worker int line,col; 1766*6a54128fSAndroid Build Coastguard Worker int max_line,max_col; 1767*6a54128fSAndroid Build Coastguard Worker int disable_output; 1768*6a54128fSAndroid Build Coastguard Worker}; 1769*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 1770*6a54128fSAndroid Build Coastguard Worker 1771*6a54128fSAndroid Build Coastguard Worker</Para> 1772*6a54128fSAndroid Build Coastguard Worker 1773*6a54128fSAndroid Build Coastguard Worker</Sect2> 1774*6a54128fSAndroid Build Coastguard Worker 1775*6a54128fSAndroid Build Coastguard Worker<Sect2> 1776*6a54128fSAndroid Build Coastguard Worker<Title>Screen redraw</Title> 1777*6a54128fSAndroid Build Coastguard Worker 1778*6a54128fSAndroid Build Coastguard Worker<Para> 1779*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">redraw_all</Literal> function will just reopen the windows. This action is 1780*6a54128fSAndroid Build Coastguard Workernecessary if the display gets garbled from some reason. 1781*6a54128fSAndroid Build Coastguard Worker</Para> 1782*6a54128fSAndroid Build Coastguard Worker 1783*6a54128fSAndroid Build Coastguard Worker</Sect2> 1784*6a54128fSAndroid Build Coastguard Worker 1785*6a54128fSAndroid Build Coastguard Worker</Sect1> 1786*6a54128fSAndroid Build Coastguard Worker 1787*6a54128fSAndroid Build Coastguard Worker<Sect1> 1788*6a54128fSAndroid Build Coastguard Worker<Title>The disk interface</Title> 1789*6a54128fSAndroid Build Coastguard Worker 1790*6a54128fSAndroid Build Coastguard Worker<Para> 1791*6a54128fSAndroid Build Coastguard WorkerAll the disk activity with regard to the filesystem passes through the file 1792*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">disk.c</Literal>. This is done that way to provide additional levels of safety 1793*6a54128fSAndroid Build Coastguard Workerconcerning the disk access. This way, global decisions considering the disk 1794*6a54128fSAndroid Build Coastguard Workercan be easily accomplished. The benefits of this isolation will become even 1795*6a54128fSAndroid Build Coastguard Workerclearer in the next sections. 1796*6a54128fSAndroid Build Coastguard Worker</Para> 1797*6a54128fSAndroid Build Coastguard Worker 1798*6a54128fSAndroid Build Coastguard Worker<Sect2> 1799*6a54128fSAndroid Build Coastguard Worker<Title>Low level functions</Title> 1800*6a54128fSAndroid Build Coastguard Worker 1801*6a54128fSAndroid Build Coastguard Worker<Para> 1802*6a54128fSAndroid Build Coastguard WorkerRead requests are ultimately handled by <Literal remap="tt">low_read</Literal> and write requests 1803*6a54128fSAndroid Build Coastguard Workerare handled by <Literal remap="tt">low_write</Literal>. They just receive the length of the data 1804*6a54128fSAndroid Build Coastguard Workerblock, the offset in the filesystem and a pointer to the buffer and pass the 1805*6a54128fSAndroid Build Coastguard Workerrequest to the <Literal remap="tt">fread</Literal> or <Literal remap="tt">fwrite</Literal> standard library functions. 1806*6a54128fSAndroid Build Coastguard Worker</Para> 1807*6a54128fSAndroid Build Coastguard Worker 1808*6a54128fSAndroid Build Coastguard Worker</Sect2> 1809*6a54128fSAndroid Build Coastguard Worker 1810*6a54128fSAndroid Build Coastguard Worker<Sect2> 1811*6a54128fSAndroid Build Coastguard Worker<Title>Mounted filesystems</Title> 1812*6a54128fSAndroid Build Coastguard Worker 1813*6a54128fSAndroid Build Coastguard Worker<Para> 1814*6a54128fSAndroid Build Coastguard WorkerEXT2ED design assumes that the edited filesystem is not mounted. Even if 1815*6a54128fSAndroid Build Coastguard Workera <Literal remap="tt">reasonably simple</Literal> way to handle mounted filesystems exists, it is 1816*6a54128fSAndroid Build Coastguard Workerprobably <Literal remap="tt">too complicated</Literal> :-) 1817*6a54128fSAndroid Build Coastguard Worker</Para> 1818*6a54128fSAndroid Build Coastguard Worker 1819*6a54128fSAndroid Build Coastguard Worker<Para> 1820*6a54128fSAndroid Build Coastguard WorkerWrite access to a mounted filesystem will be denied. Read access can be 1821*6a54128fSAndroid Build Coastguard Workerallowed by using a configuration file option. The mount status is determined 1822*6a54128fSAndroid Build Coastguard Workerby reading the file /etc/mtab. 1823*6a54128fSAndroid Build Coastguard Worker</Para> 1824*6a54128fSAndroid Build Coastguard Worker 1825*6a54128fSAndroid Build Coastguard Worker</Sect2> 1826*6a54128fSAndroid Build Coastguard Worker 1827*6a54128fSAndroid Build Coastguard Worker<Sect2> 1828*6a54128fSAndroid Build Coastguard Worker<Title>Write access</Title> 1829*6a54128fSAndroid Build Coastguard Worker 1830*6a54128fSAndroid Build Coastguard Worker<Para> 1831*6a54128fSAndroid Build Coastguard WorkerWrite access is the most sensitive part in the program. This program is 1832*6a54128fSAndroid Build Coastguard Workerintended for <Literal remap="tt">editing filesystems</Literal>. It is obvious that a small mistake 1833*6a54128fSAndroid Build Coastguard Workerin this regard can make the filesystem not usable anymore. 1834*6a54128fSAndroid Build Coastguard Worker</Para> 1835*6a54128fSAndroid Build Coastguard Worker 1836*6a54128fSAndroid Build Coastguard Worker<Para> 1837*6a54128fSAndroid Build Coastguard WorkerThe following safety measures are added, of-course, to the general Unix 1838*6a54128fSAndroid Build Coastguard Workerpermission protection - The user can always disable write access on the 1839*6a54128fSAndroid Build Coastguard Workerdevice file itself. 1840*6a54128fSAndroid Build Coastguard Worker</Para> 1841*6a54128fSAndroid Build Coastguard Worker 1842*6a54128fSAndroid Build Coastguard Worker<Para> 1843*6a54128fSAndroid Build Coastguard WorkerConsidering the user, the following safety measures were taken: 1844*6a54128fSAndroid Build Coastguard Worker 1845*6a54128fSAndroid Build Coastguard Worker<OrderedList> 1846*6a54128fSAndroid Build Coastguard Worker<ListItem> 1847*6a54128fSAndroid Build Coastguard Worker 1848*6a54128fSAndroid Build Coastguard Worker<Para> 1849*6a54128fSAndroid Build Coastguard Worker The filesystem is <Literal remap="tt">never</Literal> opened with write-access enables. 1850*6a54128fSAndroid Build Coastguard WorkerRather, the user must explicitly request to enable write-access. 1851*6a54128fSAndroid Build Coastguard Worker</Para> 1852*6a54128fSAndroid Build Coastguard Worker</ListItem> 1853*6a54128fSAndroid Build Coastguard Worker<ListItem> 1854*6a54128fSAndroid Build Coastguard Worker 1855*6a54128fSAndroid Build Coastguard Worker<Para> 1856*6a54128fSAndroid Build Coastguard Worker The user can <Literal remap="tt">disable</Literal> write access entirely by using a 1857*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">configuration file option</Literal>. 1858*6a54128fSAndroid Build Coastguard Worker</Para> 1859*6a54128fSAndroid Build Coastguard Worker</ListItem> 1860*6a54128fSAndroid Build Coastguard Worker<ListItem> 1861*6a54128fSAndroid Build Coastguard Worker 1862*6a54128fSAndroid Build Coastguard Worker<Para> 1863*6a54128fSAndroid Build Coastguard Worker Changes are never done automatically - Whenever the user makes 1864*6a54128fSAndroid Build Coastguard Workerchanges, they are done in memory. An explicit <Literal remap="tt">writedata</Literal> 1865*6a54128fSAndroid Build Coastguard Workercommand should be issued to make the changes active in the disk. 1866*6a54128fSAndroid Build Coastguard Worker</Para> 1867*6a54128fSAndroid Build Coastguard Worker</ListItem> 1868*6a54128fSAndroid Build Coastguard Worker 1869*6a54128fSAndroid Build Coastguard Worker</OrderedList> 1870*6a54128fSAndroid Build Coastguard Worker 1871*6a54128fSAndroid Build Coastguard WorkerConsidering myself, I tried to protect against my bugs by: 1872*6a54128fSAndroid Build Coastguard Worker 1873*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1874*6a54128fSAndroid Build Coastguard Worker<ListItem> 1875*6a54128fSAndroid Build Coastguard Worker 1876*6a54128fSAndroid Build Coastguard Worker<Para> 1877*6a54128fSAndroid Build Coastguard Worker Opening the device in read-only mode until a write request is 1878*6a54128fSAndroid Build Coastguard Workerissued by the user. 1879*6a54128fSAndroid Build Coastguard Worker</Para> 1880*6a54128fSAndroid Build Coastguard Worker</ListItem> 1881*6a54128fSAndroid Build Coastguard Worker<ListItem> 1882*6a54128fSAndroid Build Coastguard Worker 1883*6a54128fSAndroid Build Coastguard Worker<Para> 1884*6a54128fSAndroid Build Coastguard Worker Limiting <Literal remap="tt">actual</Literal> filesystem access to two functions only - 1885*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">low_read</Literal> for reading, and <Literal remap="tt">low_write</Literal> for writing. Those 1886*6a54128fSAndroid Build Coastguard Workerfunctions were programmed carefully, and I added the self 1887*6a54128fSAndroid Build Coastguard Workersanity checks there. In addition, this is the only place in which I 1888*6a54128fSAndroid Build Coastguard Workerneed to check the user options described above - There can be no 1889*6a54128fSAndroid Build Coastguard Workerplace in which I can "forget" to check them. 1890*6a54128fSAndroid Build Coastguard Worker 1891*6a54128fSAndroid Build Coastguard WorkerNote that The disabling of write-access through the configuration file 1892*6a54128fSAndroid Build Coastguard Workeris double checked here only as a <Literal remap="tt">self-sanity</Literal> check - If 1893*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">DEBUG</Literal> is selected, since write enable should have been refused 1894*6a54128fSAndroid Build Coastguard Workerand write-access is always disabled at startup, hence finding 1895*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">here</Literal> that the user has write access disabled through the 1896*6a54128fSAndroid Build Coastguard Workerconfiguration file clearly indicates that I have a bug somewhere. 1897*6a54128fSAndroid Build Coastguard Worker</Para> 1898*6a54128fSAndroid Build Coastguard Worker</ListItem> 1899*6a54128fSAndroid Build Coastguard Worker 1900*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1901*6a54128fSAndroid Build Coastguard Worker 1902*6a54128fSAndroid Build Coastguard Worker</Para> 1903*6a54128fSAndroid Build Coastguard Worker 1904*6a54128fSAndroid Build Coastguard Worker<Para> 1905*6a54128fSAndroid Build Coastguard WorkerThe following safety measure can provide protection against <Literal remap="tt">both</Literal> user 1906*6a54128fSAndroid Build Coastguard Workermistakes and my own bugs: 1907*6a54128fSAndroid Build Coastguard Worker 1908*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 1909*6a54128fSAndroid Build Coastguard Worker<ListItem> 1910*6a54128fSAndroid Build Coastguard Worker 1911*6a54128fSAndroid Build Coastguard Worker<Para> 1912*6a54128fSAndroid Build Coastguard Worker I added a <Literal remap="tt">logging option</Literal>, which logs every actual write 1913*6a54128fSAndroid Build Coastguard Workeraccess to the disk in the lowest level - In <Literal remap="tt">low_write</Literal> itself. 1914*6a54128fSAndroid Build Coastguard Worker 1915*6a54128fSAndroid Build Coastguard WorkerThe logging has nothing to do with the current type and the various 1916*6a54128fSAndroid Build Coastguard Workerother higher level operations of EXT2ED - It is simply a hex dump of 1917*6a54128fSAndroid Build Coastguard Workerthe contents which will be overwritten; Both the original contents 1918*6a54128fSAndroid Build Coastguard Workerand the new written data. 1919*6a54128fSAndroid Build Coastguard Worker 1920*6a54128fSAndroid Build Coastguard WorkerIn that case, even if the user makes a mistake, the original data 1921*6a54128fSAndroid Build Coastguard Workercan be retrieved. 1922*6a54128fSAndroid Build Coastguard Worker 1923*6a54128fSAndroid Build Coastguard WorkerEven If I have a bug somewhere which causes incorrect data to be 1924*6a54128fSAndroid Build Coastguard Workerwritten to the disk, the logging option will still log exactly the 1925*6a54128fSAndroid Build Coastguard Workeroriginal contents at the place were data was incorrectly overwritten. 1926*6a54128fSAndroid Build Coastguard Worker(This assumes, of-course, that <Literal remap="tt">low-write</Literal> and the <Literal remap="tt">logging 1927*6a54128fSAndroid Build Coastguard Workeritself</Literal> work correctly. I have done my best to verify that this is 1928*6a54128fSAndroid Build Coastguard Workerindeed the case). 1929*6a54128fSAndroid Build Coastguard Worker 1930*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">logging</Literal> option is implemented in the <Literal remap="tt">log_changes</Literal> 1931*6a54128fSAndroid Build Coastguard Workerfunction. 1932*6a54128fSAndroid Build Coastguard Worker</Para> 1933*6a54128fSAndroid Build Coastguard Worker</ListItem> 1934*6a54128fSAndroid Build Coastguard Worker 1935*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 1936*6a54128fSAndroid Build Coastguard Worker 1937*6a54128fSAndroid Build Coastguard Worker</Para> 1938*6a54128fSAndroid Build Coastguard Worker 1939*6a54128fSAndroid Build Coastguard Worker</Sect2> 1940*6a54128fSAndroid Build Coastguard Worker 1941*6a54128fSAndroid Build Coastguard Worker<Sect2> 1942*6a54128fSAndroid Build Coastguard Worker<Title>Reading / Writing objects</Title> 1943*6a54128fSAndroid Build Coastguard Worker 1944*6a54128fSAndroid Build Coastguard Worker<Para> 1945*6a54128fSAndroid Build Coastguard WorkerUsually <Literal remap="tt">(not always)</Literal>, the current object data is available in the 1946*6a54128fSAndroid Build Coastguard Workerglobal variable <Literal remap="tt">type_data</Literal>, which is of the type: 1947*6a54128fSAndroid Build Coastguard Worker 1948*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 1949*6a54128fSAndroid Build Coastguard Workerstruct struct_type_data { 1950*6a54128fSAndroid Build Coastguard Worker long offset_in_block; 1951*6a54128fSAndroid Build Coastguard Worker 1952*6a54128fSAndroid Build Coastguard Worker union union_type_data { 1953*6a54128fSAndroid Build Coastguard Worker char buffer [EXT2_MAX_BLOCK_SIZE]; 1954*6a54128fSAndroid Build Coastguard Worker struct ext2_acl_header t_ext2_acl_header; 1955*6a54128fSAndroid Build Coastguard Worker struct ext2_acl_entry t_ext2_acl_entry; 1956*6a54128fSAndroid Build Coastguard Worker struct ext2_old_group_desc t_ext2_old_group_desc; 1957*6a54128fSAndroid Build Coastguard Worker struct ext2_group_desc t_ext2_group_desc; 1958*6a54128fSAndroid Build Coastguard Worker struct ext2_inode t_ext2_inode; 1959*6a54128fSAndroid Build Coastguard Worker struct ext2_super_block t_ext2_super_block; 1960*6a54128fSAndroid Build Coastguard Worker struct ext2_dir_entry t_ext2_dir_entry; 1961*6a54128fSAndroid Build Coastguard Worker } u; 1962*6a54128fSAndroid Build Coastguard Worker}; 1963*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 1964*6a54128fSAndroid Build Coastguard Worker 1965*6a54128fSAndroid Build Coastguard WorkerThe above union enables me, in the program, to treat the data as raw data or 1966*6a54128fSAndroid Build Coastguard Workeras a meaningful filesystem object. 1967*6a54128fSAndroid Build Coastguard Worker</Para> 1968*6a54128fSAndroid Build Coastguard Worker 1969*6a54128fSAndroid Build Coastguard Worker<Para> 1970*6a54128fSAndroid Build Coastguard WorkerThe reading and writing, if done to this global variable, are done through 1971*6a54128fSAndroid Build Coastguard Workerthe functions <Literal remap="tt">load_type_data</Literal> and <Literal remap="tt">write_type_data</Literal>, available in 1972*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">disk.c</Literal>. 1973*6a54128fSAndroid Build Coastguard Worker</Para> 1974*6a54128fSAndroid Build Coastguard Worker 1975*6a54128fSAndroid Build Coastguard Worker</Sect2> 1976*6a54128fSAndroid Build Coastguard Worker 1977*6a54128fSAndroid Build Coastguard Worker</Sect1> 1978*6a54128fSAndroid Build Coastguard Worker 1979*6a54128fSAndroid Build Coastguard Worker<Sect1> 1980*6a54128fSAndroid Build Coastguard Worker<Title>The general commands</Title> 1981*6a54128fSAndroid Build Coastguard Worker 1982*6a54128fSAndroid Build Coastguard Worker<Para> 1983*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">general commands</Literal> are handled in the file <Literal remap="tt">general_com.c</Literal>. 1984*6a54128fSAndroid Build Coastguard Worker</Para> 1985*6a54128fSAndroid Build Coastguard Worker 1986*6a54128fSAndroid Build Coastguard Worker<Sect2> 1987*6a54128fSAndroid Build Coastguard Worker<Title>The help system</Title> 1988*6a54128fSAndroid Build Coastguard Worker 1989*6a54128fSAndroid Build Coastguard Worker<Para> 1990*6a54128fSAndroid Build Coastguard WorkerThe help command is handled by the function <Literal remap="tt">help</Literal>. The algorithm is as 1991*6a54128fSAndroid Build Coastguard Workerfollows: 1992*6a54128fSAndroid Build Coastguard Worker</Para> 1993*6a54128fSAndroid Build Coastguard Worker 1994*6a54128fSAndroid Build Coastguard Worker<Para> 1995*6a54128fSAndroid Build Coastguard Worker 1996*6a54128fSAndroid Build Coastguard Worker<OrderedList> 1997*6a54128fSAndroid Build Coastguard Worker<ListItem> 1998*6a54128fSAndroid Build Coastguard Worker 1999*6a54128fSAndroid Build Coastguard Worker<Para> 2000*6a54128fSAndroid Build Coastguard Worker Check the command line arguments. If there is an argument, pass 2001*6a54128fSAndroid Build Coastguard Workercontrol to the <Literal remap="tt">detailed_help</Literal> function, in order to provide 2002*6a54128fSAndroid Build Coastguard Workerhelp on the specific command. 2003*6a54128fSAndroid Build Coastguard Worker</Para> 2004*6a54128fSAndroid Build Coastguard Worker</ListItem> 2005*6a54128fSAndroid Build Coastguard Worker<ListItem> 2006*6a54128fSAndroid Build Coastguard Worker 2007*6a54128fSAndroid Build Coastguard Worker<Para> 2008*6a54128fSAndroid Build Coastguard Worker If general help was requested, display a list of the available 2009*6a54128fSAndroid Build Coastguard Workercommands at this point. The three levels are displayed in reverse 2010*6a54128fSAndroid Build Coastguard Workerorder - First the commands which are specific to the current type 2011*6a54128fSAndroid Build Coastguard Worker(If a current type is defined), then the ext2 general commands (If 2012*6a54128fSAndroid Build Coastguard Workerwe decided that the filesystem should be treated like an ext2 2013*6a54128fSAndroid Build Coastguard Workerfilesystem), then the general commands. 2014*6a54128fSAndroid Build Coastguard Worker</Para> 2015*6a54128fSAndroid Build Coastguard Worker</ListItem> 2016*6a54128fSAndroid Build Coastguard Worker<ListItem> 2017*6a54128fSAndroid Build Coastguard Worker 2018*6a54128fSAndroid Build Coastguard Worker<Para> 2019*6a54128fSAndroid Build Coastguard Worker Display information about EXT2ED - Current version, general 2020*6a54128fSAndroid Build Coastguard Workerinformation about the project, etc. 2021*6a54128fSAndroid Build Coastguard Worker</Para> 2022*6a54128fSAndroid Build Coastguard Worker</ListItem> 2023*6a54128fSAndroid Build Coastguard Worker 2024*6a54128fSAndroid Build Coastguard Worker</OrderedList> 2025*6a54128fSAndroid Build Coastguard Worker 2026*6a54128fSAndroid Build Coastguard Worker</Para> 2027*6a54128fSAndroid Build Coastguard Worker 2028*6a54128fSAndroid Build Coastguard Worker</Sect2> 2029*6a54128fSAndroid Build Coastguard Worker 2030*6a54128fSAndroid Build Coastguard Worker<Sect2> 2031*6a54128fSAndroid Build Coastguard Worker<Title>The setdevice command</Title> 2032*6a54128fSAndroid Build Coastguard Worker 2033*6a54128fSAndroid Build Coastguard Worker<Para> 2034*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">setdevice</Literal> commands result in calling the <Literal remap="tt">set_device</Literal> 2035*6a54128fSAndroid Build Coastguard Workerfunction. The algorithm is: 2036*6a54128fSAndroid Build Coastguard Worker</Para> 2037*6a54128fSAndroid Build Coastguard Worker 2038*6a54128fSAndroid Build Coastguard Worker<Para> 2039*6a54128fSAndroid Build Coastguard Worker 2040*6a54128fSAndroid Build Coastguard Worker<OrderedList> 2041*6a54128fSAndroid Build Coastguard Worker<ListItem> 2042*6a54128fSAndroid Build Coastguard Worker 2043*6a54128fSAndroid Build Coastguard Worker<Para> 2044*6a54128fSAndroid Build Coastguard Worker Parse the command line argument. If it isn't available report the 2045*6a54128fSAndroid Build Coastguard Workererror and return. 2046*6a54128fSAndroid Build Coastguard Worker</Para> 2047*6a54128fSAndroid Build Coastguard Worker</ListItem> 2048*6a54128fSAndroid Build Coastguard Worker<ListItem> 2049*6a54128fSAndroid Build Coastguard Worker 2050*6a54128fSAndroid Build Coastguard Worker<Para> 2051*6a54128fSAndroid Build Coastguard Worker Close the current open device, if there is one. 2052*6a54128fSAndroid Build Coastguard Worker</Para> 2053*6a54128fSAndroid Build Coastguard Worker</ListItem> 2054*6a54128fSAndroid Build Coastguard Worker<ListItem> 2055*6a54128fSAndroid Build Coastguard Worker 2056*6a54128fSAndroid Build Coastguard Worker<Para> 2057*6a54128fSAndroid Build Coastguard Worker Open the new device in read-only mode. Update the global variables 2058*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">device_name</Literal> and <Literal remap="tt">device_handle</Literal>. 2059*6a54128fSAndroid Build Coastguard Worker</Para> 2060*6a54128fSAndroid Build Coastguard Worker</ListItem> 2061*6a54128fSAndroid Build Coastguard Worker<ListItem> 2062*6a54128fSAndroid Build Coastguard Worker 2063*6a54128fSAndroid Build Coastguard Worker<Para> 2064*6a54128fSAndroid Build Coastguard Worker Disable write access. 2065*6a54128fSAndroid Build Coastguard Worker</Para> 2066*6a54128fSAndroid Build Coastguard Worker</ListItem> 2067*6a54128fSAndroid Build Coastguard Worker<ListItem> 2068*6a54128fSAndroid Build Coastguard Worker 2069*6a54128fSAndroid Build Coastguard Worker<Para> 2070*6a54128fSAndroid Build Coastguard Worker Empty the object memory. 2071*6a54128fSAndroid Build Coastguard Worker</Para> 2072*6a54128fSAndroid Build Coastguard Worker</ListItem> 2073*6a54128fSAndroid Build Coastguard Worker<ListItem> 2074*6a54128fSAndroid Build Coastguard Worker 2075*6a54128fSAndroid Build Coastguard Worker<Para> 2076*6a54128fSAndroid Build Coastguard Worker Unregister the ext2 general commands, using 2077*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">free_user_commands</Literal>. 2078*6a54128fSAndroid Build Coastguard Worker</Para> 2079*6a54128fSAndroid Build Coastguard Worker</ListItem> 2080*6a54128fSAndroid Build Coastguard Worker<ListItem> 2081*6a54128fSAndroid Build Coastguard Worker 2082*6a54128fSAndroid Build Coastguard Worker<Para> 2083*6a54128fSAndroid Build Coastguard Worker Unregister the current objects, using <Literal remap="tt">free_struct_descriptors</Literal> 2084*6a54128fSAndroid Build Coastguard Worker</Para> 2085*6a54128fSAndroid Build Coastguard Worker</ListItem> 2086*6a54128fSAndroid Build Coastguard Worker<ListItem> 2087*6a54128fSAndroid Build Coastguard Worker 2088*6a54128fSAndroid Build Coastguard Worker<Para> 2089*6a54128fSAndroid Build Coastguard Worker Call <Literal remap="tt">set_file_system_info</Literal> to auto-detect an ext2 filesystem 2090*6a54128fSAndroid Build Coastguard Workerand set the basic filesystem values. 2091*6a54128fSAndroid Build Coastguard Worker</Para> 2092*6a54128fSAndroid Build Coastguard Worker</ListItem> 2093*6a54128fSAndroid Build Coastguard Worker<ListItem> 2094*6a54128fSAndroid Build Coastguard Worker 2095*6a54128fSAndroid Build Coastguard Worker<Para> 2096*6a54128fSAndroid Build Coastguard Worker Add the <Literal remap="tt">alternate descriptors</Literal>, supplied by the user. 2097*6a54128fSAndroid Build Coastguard Worker</Para> 2098*6a54128fSAndroid Build Coastguard Worker</ListItem> 2099*6a54128fSAndroid Build Coastguard Worker<ListItem> 2100*6a54128fSAndroid Build Coastguard Worker 2101*6a54128fSAndroid Build Coastguard Worker<Para> 2102*6a54128fSAndroid Build Coastguard Worker Set the device offset to the filesystem start by dispatching 2103*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">setoffset 0</Literal>. 2104*6a54128fSAndroid Build Coastguard Worker</Para> 2105*6a54128fSAndroid Build Coastguard Worker</ListItem> 2106*6a54128fSAndroid Build Coastguard Worker<ListItem> 2107*6a54128fSAndroid Build Coastguard Worker 2108*6a54128fSAndroid Build Coastguard Worker<Para> 2109*6a54128fSAndroid Build Coastguard Worker Show the new available commands by dispatching the <Literal remap="tt">help</Literal> 2110*6a54128fSAndroid Build Coastguard Workercommand. 2111*6a54128fSAndroid Build Coastguard Worker</Para> 2112*6a54128fSAndroid Build Coastguard Worker</ListItem> 2113*6a54128fSAndroid Build Coastguard Worker 2114*6a54128fSAndroid Build Coastguard Worker</OrderedList> 2115*6a54128fSAndroid Build Coastguard Worker 2116*6a54128fSAndroid Build Coastguard Worker</Para> 2117*6a54128fSAndroid Build Coastguard Worker 2118*6a54128fSAndroid Build Coastguard Worker</Sect2> 2119*6a54128fSAndroid Build Coastguard Worker 2120*6a54128fSAndroid Build Coastguard Worker<Sect2> 2121*6a54128fSAndroid Build Coastguard Worker<Title>Basic maneuvering</Title> 2122*6a54128fSAndroid Build Coastguard Worker 2123*6a54128fSAndroid Build Coastguard Worker<Para> 2124*6a54128fSAndroid Build Coastguard WorkerBasic maneuvering is done using the <Literal remap="tt">setoffset</Literal> and the <Literal remap="tt">settype</Literal> 2125*6a54128fSAndroid Build Coastguard Workeruser commands. 2126*6a54128fSAndroid Build Coastguard Worker</Para> 2127*6a54128fSAndroid Build Coastguard Worker 2128*6a54128fSAndroid Build Coastguard Worker<Para> 2129*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">set_offset</Literal> accepts some alternative forms of specifying the new 2130*6a54128fSAndroid Build Coastguard Workeroffset. They all ultimately lead to changing the <Literal remap="tt">device_offset</Literal> 2131*6a54128fSAndroid Build Coastguard Workerglobal variable and seeking to the new position. <Literal remap="tt">set_offset</Literal> also 2132*6a54128fSAndroid Build Coastguard Workercalls <Literal remap="tt">load_type_data</Literal> to read a block ahead of the new position into 2133*6a54128fSAndroid Build Coastguard Workerthe <Literal remap="tt">type_data</Literal> global variable. 2134*6a54128fSAndroid Build Coastguard Worker</Para> 2135*6a54128fSAndroid Build Coastguard Worker 2136*6a54128fSAndroid Build Coastguard Worker<Para> 2137*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">set_type</Literal> will point the global variable <Literal remap="tt">current_type</Literal> to the 2138*6a54128fSAndroid Build Coastguard Workercorrect entry in the double linked list of the known objects. If the 2139*6a54128fSAndroid Build Coastguard Workerrequested type is <Literal remap="tt">hex</Literal> or <Literal remap="tt">none</Literal>, <Literal remap="tt">current_type</Literal> will be 2140*6a54128fSAndroid Build Coastguard Workerinitialized to <Literal remap="tt">NULL</Literal>. <Literal remap="tt">set_type</Literal> will also dispatch <Literal remap="tt">show</Literal>, 2141*6a54128fSAndroid Build Coastguard Workerso that the object data will be re-formatted in the new format. 2142*6a54128fSAndroid Build Coastguard Worker</Para> 2143*6a54128fSAndroid Build Coastguard Worker 2144*6a54128fSAndroid Build Coastguard Worker<Para> 2145*6a54128fSAndroid Build Coastguard WorkerWhen editing an ext2 filesystem, it is not intended that those commands will 2146*6a54128fSAndroid Build Coastguard Workerbe used directly, and it is usually not required. My implementation of the 2147*6a54128fSAndroid Build Coastguard Workerext2 layer, on the other hand, uses this lower level commands on countless 2148*6a54128fSAndroid Build Coastguard Workeroccasions. 2149*6a54128fSAndroid Build Coastguard Worker</Para> 2150*6a54128fSAndroid Build Coastguard Worker 2151*6a54128fSAndroid Build Coastguard Worker</Sect2> 2152*6a54128fSAndroid Build Coastguard Worker 2153*6a54128fSAndroid Build Coastguard Worker<Sect2> 2154*6a54128fSAndroid Build Coastguard Worker<Title>The display functions</Title> 2155*6a54128fSAndroid Build Coastguard Worker 2156*6a54128fSAndroid Build Coastguard Worker<Para> 2157*6a54128fSAndroid Build Coastguard WorkerThe general command version of <Literal remap="tt">show</Literal> is handled by the <Literal remap="tt">show</Literal> 2158*6a54128fSAndroid Build Coastguard Workerfunction. This command is overridden by various objects to provide a display 2159*6a54128fSAndroid Build Coastguard Workerwhich is better suited to the object. 2160*6a54128fSAndroid Build Coastguard Worker</Para> 2161*6a54128fSAndroid Build Coastguard Worker 2162*6a54128fSAndroid Build Coastguard Worker<Para> 2163*6a54128fSAndroid Build Coastguard WorkerThe general show command will format the data in <Literal remap="tt">type_data</Literal> according 2164*6a54128fSAndroid Build Coastguard Workerto the structure definition of the current type and show it on the <Literal remap="tt">show 2165*6a54128fSAndroid Build Coastguard Workerpad</Literal>. If there is no current type, the data will be shown as a simple hex 2166*6a54128fSAndroid Build Coastguard Workerdump; Otherwise, the list of variables, along with their values will be shown. 2167*6a54128fSAndroid Build Coastguard Worker</Para> 2168*6a54128fSAndroid Build Coastguard Worker 2169*6a54128fSAndroid Build Coastguard Worker<Para> 2170*6a54128fSAndroid Build Coastguard WorkerA call to <Literal remap="tt">show_info</Literal> is also made - <Literal remap="tt">show_info</Literal> will provide 2171*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">general statistics</Literal> on the <Literal remap="tt">show_window</Literal>, such as the current 2172*6a54128fSAndroid Build Coastguard Workerblock, current type, current offset and current page. 2173*6a54128fSAndroid Build Coastguard Worker</Para> 2174*6a54128fSAndroid Build Coastguard Worker 2175*6a54128fSAndroid Build Coastguard Worker<Para> 2176*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">pgup</Literal> and <Literal remap="tt">pgdn</Literal> general commands just update the 2177*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">show_pad_info</Literal> global variable - We just increment 2178*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">show_pad_info.line</Literal> with the number of lines in the screen - 2179*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">show_pad_info.display_lines</Literal>, which was initialized in 2180*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">init_windows</Literal>. 2181*6a54128fSAndroid Build Coastguard Worker</Para> 2182*6a54128fSAndroid Build Coastguard Worker 2183*6a54128fSAndroid Build Coastguard Worker</Sect2> 2184*6a54128fSAndroid Build Coastguard Worker 2185*6a54128fSAndroid Build Coastguard Worker<Sect2> 2186*6a54128fSAndroid Build Coastguard Worker<Title>Changing data</Title> 2187*6a54128fSAndroid Build Coastguard Worker 2188*6a54128fSAndroid Build Coastguard Worker<Para> 2189*6a54128fSAndroid Build Coastguard WorkerData change is done in memory only. An update to the disk if followed by an 2190*6a54128fSAndroid Build Coastguard Workerexplicit <Literal remap="tt">writedata</Literal> command to the disk. The <Literal remap="tt">write_data</Literal> 2191*6a54128fSAndroid Build Coastguard Workerfunction simple calls the <Literal remap="tt">write_type_data</Literal> function, outlined earlier. 2192*6a54128fSAndroid Build Coastguard Worker</Para> 2193*6a54128fSAndroid Build Coastguard Worker 2194*6a54128fSAndroid Build Coastguard Worker<Para> 2195*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">set</Literal> command is used for changing the data. 2196*6a54128fSAndroid Build Coastguard Worker</Para> 2197*6a54128fSAndroid Build Coastguard Worker 2198*6a54128fSAndroid Build Coastguard Worker<Para> 2199*6a54128fSAndroid Build Coastguard WorkerIf there is no current type, control is passed to the <Literal remap="tt">hex_set</Literal> function, 2200*6a54128fSAndroid Build Coastguard Workerwhich treats the data as a block of bytes and uses the 2201*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">type_data.offset_in_block</Literal> variable to write the new text or hex string 2202*6a54128fSAndroid Build Coastguard Workerto the correct place in the block. 2203*6a54128fSAndroid Build Coastguard Worker</Para> 2204*6a54128fSAndroid Build Coastguard Worker 2205*6a54128fSAndroid Build Coastguard Worker<Para> 2206*6a54128fSAndroid Build Coastguard WorkerIf a current type is defined, the requested variable is searched in the 2207*6a54128fSAndroid Build Coastguard Workercurrent object, and the desired new valued is entered. 2208*6a54128fSAndroid Build Coastguard Worker</Para> 2209*6a54128fSAndroid Build Coastguard Worker 2210*6a54128fSAndroid Build Coastguard Worker<Para> 2211*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">enablewrite</Literal> commands just sets the global variable 2212*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">write_access</Literal> to <Literal remap="tt">1</Literal> and re-opens the filesystem in read-write 2213*6a54128fSAndroid Build Coastguard Workermode, if possible. 2214*6a54128fSAndroid Build Coastguard Worker</Para> 2215*6a54128fSAndroid Build Coastguard Worker 2216*6a54128fSAndroid Build Coastguard Worker<Para> 2217*6a54128fSAndroid Build Coastguard WorkerIf the current type is NULL, a hex-mode is assumed - The <Literal remap="tt">next</Literal> and 2218*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">prev</Literal> commands will just update <Literal remap="tt">type_data.offset_in_block</Literal>. 2219*6a54128fSAndroid Build Coastguard Worker</Para> 2220*6a54128fSAndroid Build Coastguard Worker 2221*6a54128fSAndroid Build Coastguard Worker<Para> 2222*6a54128fSAndroid Build Coastguard WorkerIf the current type is not NULL, the The <Literal remap="tt">next</Literal> and <Literal remap="tt">prev</Literal> command 2223*6a54128fSAndroid Build Coastguard Workerare usually overridden anyway. If they are not overridden, it will be assumed 2224*6a54128fSAndroid Build Coastguard Workerthat the user is editing an array of such objects, and they will just pass 2225*6a54128fSAndroid Build Coastguard Workerto the next / prev element by dispatching to <Literal remap="tt">setoffset</Literal> using the 2226*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">setoffset type + / - X</Literal> syntax. 2227*6a54128fSAndroid Build Coastguard Worker</Para> 2228*6a54128fSAndroid Build Coastguard Worker 2229*6a54128fSAndroid Build Coastguard Worker</Sect2> 2230*6a54128fSAndroid Build Coastguard Worker 2231*6a54128fSAndroid Build Coastguard Worker</Sect1> 2232*6a54128fSAndroid Build Coastguard Worker 2233*6a54128fSAndroid Build Coastguard Worker<Sect1> 2234*6a54128fSAndroid Build Coastguard Worker<Title>The ext2 general commands</Title> 2235*6a54128fSAndroid Build Coastguard Worker 2236*6a54128fSAndroid Build Coastguard Worker<Para> 2237*6a54128fSAndroid Build Coastguard WorkerThe ext2 general commands are contained in the <Literal remap="tt">ext2_general_commands</Literal> 2238*6a54128fSAndroid Build Coastguard Workerglobal variable (which is of type <Literal remap="tt">struct struct_commands</Literal>). 2239*6a54128fSAndroid Build Coastguard Worker</Para> 2240*6a54128fSAndroid Build Coastguard Worker 2241*6a54128fSAndroid Build Coastguard Worker<Para> 2242*6a54128fSAndroid Build Coastguard WorkerThe handling functions are implemented in the source file <Literal remap="tt">ext2_com.c</Literal>. 2243*6a54128fSAndroid Build Coastguard WorkerI will include the entire source code since it is relatively short. 2244*6a54128fSAndroid Build Coastguard Worker</Para> 2245*6a54128fSAndroid Build Coastguard Worker 2246*6a54128fSAndroid Build Coastguard Worker<Sect2> 2247*6a54128fSAndroid Build Coastguard Worker<Title>The super command</Title> 2248*6a54128fSAndroid Build Coastguard Worker 2249*6a54128fSAndroid Build Coastguard Worker<Para> 2250*6a54128fSAndroid Build Coastguard WorkerThe super command just "brings the user" to the main superblock and set the 2251*6a54128fSAndroid Build Coastguard Workertype to ext2_super_block. The implementation is trivial: 2252*6a54128fSAndroid Build Coastguard Worker</Para> 2253*6a54128fSAndroid Build Coastguard Worker 2254*6a54128fSAndroid Build Coastguard Worker<Para> 2255*6a54128fSAndroid Build Coastguard Worker 2256*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2257*6a54128fSAndroid Build Coastguard Workervoid type_ext2___super (char *command_line) 2258*6a54128fSAndroid Build Coastguard Worker 2259*6a54128fSAndroid Build Coastguard Worker{ 2260*6a54128fSAndroid Build Coastguard Worker char buffer [80]; 2261*6a54128fSAndroid Build Coastguard Worker 2262*6a54128fSAndroid Build Coastguard Worker super_info.copy_num=0; 2263*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"setoffset %ld",file_system_info.super_block_offset);dispatch (buffer); 2264*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"settype ext2_super_block");dispatch (buffer); 2265*6a54128fSAndroid Build Coastguard Worker} 2266*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2267*6a54128fSAndroid Build Coastguard Worker 2268*6a54128fSAndroid Build Coastguard WorkerIt involves only setting the <Literal remap="tt">copy_num</Literal> variable to indicate the main 2269*6a54128fSAndroid Build Coastguard Workercopy, dispatching a <Literal remap="tt">setoffset</Literal> command to reach the superblock, and 2270*6a54128fSAndroid Build Coastguard Workerdispatching a <Literal remap="tt">settype</Literal> to enable the superblock specific commands. 2271*6a54128fSAndroid Build Coastguard WorkerThis last command will also call the <Literal remap="tt">show</Literal> command of the 2272*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ext2_super_block</Literal> type, through dispatching at the general command 2273*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">settype</Literal>. 2274*6a54128fSAndroid Build Coastguard Worker</Para> 2275*6a54128fSAndroid Build Coastguard Worker 2276*6a54128fSAndroid Build Coastguard Worker</Sect2> 2277*6a54128fSAndroid Build Coastguard Worker 2278*6a54128fSAndroid Build Coastguard Worker<Sect2> 2279*6a54128fSAndroid Build Coastguard Worker<Title>The group command</Title> 2280*6a54128fSAndroid Build Coastguard Worker 2281*6a54128fSAndroid Build Coastguard Worker<Para> 2282*6a54128fSAndroid Build Coastguard WorkerThe group command will bring the user to the specified group descriptor in 2283*6a54128fSAndroid Build Coastguard Workerthe main copy of the group descriptors. The type will be set to 2284*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ext2_group_desc</Literal>: 2285*6a54128fSAndroid Build Coastguard Worker 2286*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2287*6a54128fSAndroid Build Coastguard Workervoid type_ext2___group (char *command_line) 2288*6a54128fSAndroid Build Coastguard Worker 2289*6a54128fSAndroid Build Coastguard Worker{ 2290*6a54128fSAndroid Build Coastguard Worker long group_num=0; 2291*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80]; 2292*6a54128fSAndroid Build Coastguard Worker 2293*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer); 2294*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) { 2295*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer); 2296*6a54128fSAndroid Build Coastguard Worker group_num=atol (buffer); 2297*6a54128fSAndroid Build Coastguard Worker } 2298*6a54128fSAndroid Build Coastguard Worker 2299*6a54128fSAndroid Build Coastguard Worker group_info.copy_num=0;group_info.group_num=0; 2300*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"setoffset %ld",file_system_info.first_group_desc_offset);dispatch (buffer); 2301*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"settype ext2_group_desc");dispatch (buffer); 2302*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"entry %ld",group_num);dispatch (buffer); 2303*6a54128fSAndroid Build Coastguard Worker} 2304*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2305*6a54128fSAndroid Build Coastguard Worker 2306*6a54128fSAndroid Build Coastguard WorkerThe implementation is as trivial as the <Literal remap="tt">super</Literal> implementation. Note 2307*6a54128fSAndroid Build Coastguard Workerthe use of the <Literal remap="tt">entry</Literal> command, which is a command of the 2308*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ext2_group_desc</Literal> object, to pass to the correct group descriptor. 2309*6a54128fSAndroid Build Coastguard Worker</Para> 2310*6a54128fSAndroid Build Coastguard Worker 2311*6a54128fSAndroid Build Coastguard Worker</Sect2> 2312*6a54128fSAndroid Build Coastguard Worker 2313*6a54128fSAndroid Build Coastguard Worker<Sect2> 2314*6a54128fSAndroid Build Coastguard Worker<Title>The cd command</Title> 2315*6a54128fSAndroid Build Coastguard Worker 2316*6a54128fSAndroid Build Coastguard Worker<Para> 2317*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">cd</Literal> command performs the usual cd function. The path to the global 2318*6a54128fSAndroid Build Coastguard Workercd command is a path from <Literal remap="tt">/</Literal>. 2319*6a54128fSAndroid Build Coastguard Worker</Para> 2320*6a54128fSAndroid Build Coastguard Worker 2321*6a54128fSAndroid Build Coastguard Worker<Para> 2322*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">This is one of the best examples of the power of the object oriented 2323*6a54128fSAndroid Build Coastguard Workerdesign and of the dispatching mechanism. The operation is complicated, yet the 2324*6a54128fSAndroid Build Coastguard Workerimplementation is surprisingly short!</Literal> 2325*6a54128fSAndroid Build Coastguard Worker</Para> 2326*6a54128fSAndroid Build Coastguard Worker 2327*6a54128fSAndroid Build Coastguard Worker<Para> 2328*6a54128fSAndroid Build Coastguard Worker 2329*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2330*6a54128fSAndroid Build Coastguard Workervoid type_ext2___cd (char *command_line) 2331*6a54128fSAndroid Build Coastguard Worker 2332*6a54128fSAndroid Build Coastguard Worker{ 2333*6a54128fSAndroid Build Coastguard Worker char temp [80],buffer [80],*ptr; 2334*6a54128fSAndroid Build Coastguard Worker 2335*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer); 2336*6a54128fSAndroid Build Coastguard Worker if (*ptr==0) { 2337*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - No argument specified\n"); 2338*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();return; 2339*6a54128fSAndroid Build Coastguard Worker } 2340*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer); 2341*6a54128fSAndroid Build Coastguard Worker 2342*6a54128fSAndroid Build Coastguard Worker if (buffer [0] != '/') { 2343*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Use a full pathname (begin with '/')\n"); 2344*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();return; 2345*6a54128fSAndroid Build Coastguard Worker } 2346*6a54128fSAndroid Build Coastguard Worker 2347*6a54128fSAndroid Build Coastguard Worker dispatch ("super");dispatch ("group");dispatch ("inode"); 2348*6a54128fSAndroid Build Coastguard Worker dispatch ("next");dispatch ("dir"); 2349*6a54128fSAndroid Build Coastguard Worker if (buffer [1] != 0) { 2350*6a54128fSAndroid Build Coastguard Worker sprintf (temp,"cd %s",buffer+1);dispatch (temp); 2351*6a54128fSAndroid Build Coastguard Worker } 2352*6a54128fSAndroid Build Coastguard Worker} 2353*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2354*6a54128fSAndroid Build Coastguard Worker 2355*6a54128fSAndroid Build Coastguard Worker</Para> 2356*6a54128fSAndroid Build Coastguard Worker 2357*6a54128fSAndroid Build Coastguard Worker<Para> 2358*6a54128fSAndroid Build Coastguard WorkerNote the number of the dispatch calls! 2359*6a54128fSAndroid Build Coastguard Worker</Para> 2360*6a54128fSAndroid Build Coastguard Worker 2361*6a54128fSAndroid Build Coastguard Worker<Para> 2362*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">super</Literal> is used to get to the superblock. <Literal remap="tt">group</Literal> to get to the 2363*6a54128fSAndroid Build Coastguard Workerfirst group descriptor. <Literal remap="tt">inode</Literal> brings us to the first inode - The bad 2364*6a54128fSAndroid Build Coastguard Workerblocks inode. A <Literal remap="tt">next</Literal> is command to pass to the root directory inode, 2365*6a54128fSAndroid Build Coastguard Workera <Literal remap="tt">dir</Literal> command "enters" the directory, and then we let the <Literal remap="tt">object 2366*6a54128fSAndroid Build Coastguard Workerspecific cd command</Literal> to take us from there (The object is <Literal remap="tt">dir</Literal>, so 2367*6a54128fSAndroid Build Coastguard Workerthat <Literal remap="tt">dispatch</Literal> will call the <Literal remap="tt">cd</Literal> command of the <Literal remap="tt">dir</Literal> type). 2368*6a54128fSAndroid Build Coastguard WorkerNote that a symbolic link following could bring us back to the root directory, 2369*6a54128fSAndroid Build Coastguard Workerthus the innocent calls above treats nicely such a recursive case! 2370*6a54128fSAndroid Build Coastguard Worker</Para> 2371*6a54128fSAndroid Build Coastguard Worker 2372*6a54128fSAndroid Build Coastguard Worker<Para> 2373*6a54128fSAndroid Build Coastguard WorkerI feel that the above is <Literal remap="tt">intuitive</Literal> - I was expressing myself "in the 2374*6a54128fSAndroid Build Coastguard Workerlanguage" of the ext2 filesystem - (Go to the inode, etc), and the code was 2375*6a54128fSAndroid Build Coastguard Workerwritten exactly in this spirit! 2376*6a54128fSAndroid Build Coastguard Worker</Para> 2377*6a54128fSAndroid Build Coastguard Worker 2378*6a54128fSAndroid Build Coastguard Worker<Para> 2379*6a54128fSAndroid Build Coastguard WorkerI can write more at this point, but I guess I am already a bit carried 2380*6a54128fSAndroid Build Coastguard Workeraway with the self compliments :-) 2381*6a54128fSAndroid Build Coastguard Worker</Para> 2382*6a54128fSAndroid Build Coastguard Worker 2383*6a54128fSAndroid Build Coastguard Worker</Sect2> 2384*6a54128fSAndroid Build Coastguard Worker 2385*6a54128fSAndroid Build Coastguard Worker</Sect1> 2386*6a54128fSAndroid Build Coastguard Worker 2387*6a54128fSAndroid Build Coastguard Worker<Sect1> 2388*6a54128fSAndroid Build Coastguard Worker<Title>The superblock</Title> 2389*6a54128fSAndroid Build Coastguard Worker 2390*6a54128fSAndroid Build Coastguard Worker<Para> 2391*6a54128fSAndroid Build Coastguard WorkerThis section details the handling of the superblock. 2392*6a54128fSAndroid Build Coastguard Worker</Para> 2393*6a54128fSAndroid Build Coastguard Worker 2394*6a54128fSAndroid Build Coastguard Worker<Sect2> 2395*6a54128fSAndroid Build Coastguard Worker<Title>The superblock variables</Title> 2396*6a54128fSAndroid Build Coastguard Worker 2397*6a54128fSAndroid Build Coastguard Worker<Para> 2398*6a54128fSAndroid Build Coastguard WorkerThe superblock object is <Literal remap="tt">ext2_super_block</Literal>. The definition is just 2399*6a54128fSAndroid Build Coastguard Workertaken from the kernel ext2 main include file - /usr/include/linux/ext2_fs.h. 2400*6a54128fSAndroid Build Coastguard Worker<FOOTNOTE> 2401*6a54128fSAndroid Build Coastguard Worker 2402*6a54128fSAndroid Build Coastguard Worker<Para> 2403*6a54128fSAndroid Build Coastguard WorkerThose lines of source are copyrighted by <Literal remap="tt">Remy Card</Literal> - The author of the 2404*6a54128fSAndroid Build Coastguard Workerext2 filesystem, and by <Literal remap="tt">Linus Torvalds</Literal> - The first author of the Linux 2405*6a54128fSAndroid Build Coastguard Workeroperating system. Please cross reference the section Acknowledgments for the 2406*6a54128fSAndroid Build Coastguard Workerfull copyright. 2407*6a54128fSAndroid Build Coastguard Worker</Para> 2408*6a54128fSAndroid Build Coastguard Worker 2409*6a54128fSAndroid Build Coastguard Worker</FOOTNOTE> 2410*6a54128fSAndroid Build Coastguard Worker 2411*6a54128fSAndroid Build Coastguard Worker 2412*6a54128fSAndroid Build Coastguard Worker 2413*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2414*6a54128fSAndroid Build Coastguard Workerstruct ext2_super_block { 2415*6a54128fSAndroid Build Coastguard Worker __u32 s_inodes_count; /* Inodes count */ 2416*6a54128fSAndroid Build Coastguard Worker __u32 s_blocks_count; /* Blocks count */ 2417*6a54128fSAndroid Build Coastguard Worker __u32 s_r_blocks_count; /* Reserved blocks count */ 2418*6a54128fSAndroid Build Coastguard Worker __u32 s_free_blocks_count; /* Free blocks count */ 2419*6a54128fSAndroid Build Coastguard Worker __u32 s_free_inodes_count; /* Free inodes count */ 2420*6a54128fSAndroid Build Coastguard Worker __u32 s_first_data_block; /* First Data Block */ 2421*6a54128fSAndroid Build Coastguard Worker __u32 s_log_block_size; /* Block size */ 2422*6a54128fSAndroid Build Coastguard Worker __s32 s_log_frag_size; /* Fragment size */ 2423*6a54128fSAndroid Build Coastguard Worker __u32 s_blocks_per_group; /* # Blocks per group */ 2424*6a54128fSAndroid Build Coastguard Worker __u32 s_frags_per_group; /* # Fragments per group */ 2425*6a54128fSAndroid Build Coastguard Worker __u32 s_inodes_per_group; /* # Inodes per group */ 2426*6a54128fSAndroid Build Coastguard Worker __u32 s_mtime; /* Mount time */ 2427*6a54128fSAndroid Build Coastguard Worker __u32 s_wtime; /* Write time */ 2428*6a54128fSAndroid Build Coastguard Worker __u16 s_mnt_count; /* Mount count */ 2429*6a54128fSAndroid Build Coastguard Worker __s16 s_max_mnt_count; /* Maximal mount count */ 2430*6a54128fSAndroid Build Coastguard Worker __u16 s_magic; /* Magic signature */ 2431*6a54128fSAndroid Build Coastguard Worker __u16 s_state; /* File system state */ 2432*6a54128fSAndroid Build Coastguard Worker __u16 s_errors; /* Behavior when detecting errors */ 2433*6a54128fSAndroid Build Coastguard Worker __u16 s_pad; 2434*6a54128fSAndroid Build Coastguard Worker __u32 s_lastcheck; /* time of last check */ 2435*6a54128fSAndroid Build Coastguard Worker __u32 s_checkinterval; /* max. time between checks */ 2436*6a54128fSAndroid Build Coastguard Worker __u32 s_creator_os; /* OS */ 2437*6a54128fSAndroid Build Coastguard Worker __u32 s_rev_level; /* Revision level */ 2438*6a54128fSAndroid Build Coastguard Worker __u16 s_def_resuid; /* Default uid for reserved blocks */ 2439*6a54128fSAndroid Build Coastguard Worker __u16 s_def_resgid; /* Default gid for reserved blocks */ 2440*6a54128fSAndroid Build Coastguard Worker __u32 s_reserved[0]; /* Padding to the end of the block */ 2441*6a54128fSAndroid Build Coastguard Worker __u32 s_reserved[1]; /* Padding to the end of the block */ 2442*6a54128fSAndroid Build Coastguard Worker . 2443*6a54128fSAndroid Build Coastguard Worker . 2444*6a54128fSAndroid Build Coastguard Worker . 2445*6a54128fSAndroid Build Coastguard Worker __u32 s_reserved[234]; /* Padding to the end of the block */ 2446*6a54128fSAndroid Build Coastguard Worker}; 2447*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2448*6a54128fSAndroid Build Coastguard Worker 2449*6a54128fSAndroid Build Coastguard Worker</Para> 2450*6a54128fSAndroid Build Coastguard Worker 2451*6a54128fSAndroid Build Coastguard Worker<Para> 2452*6a54128fSAndroid Build Coastguard WorkerNote that I <Literal remap="tt">expanded</Literal> the array due to my primitive parser 2453*6a54128fSAndroid Build Coastguard Workerimplementation. The various fields are described in the <Literal remap="tt">technical 2454*6a54128fSAndroid Build Coastguard Workerdocument</Literal>. 2455*6a54128fSAndroid Build Coastguard Worker</Para> 2456*6a54128fSAndroid Build Coastguard Worker 2457*6a54128fSAndroid Build Coastguard Worker</Sect2> 2458*6a54128fSAndroid Build Coastguard Worker 2459*6a54128fSAndroid Build Coastguard Worker<Sect2> 2460*6a54128fSAndroid Build Coastguard Worker<Title>The superblock commands</Title> 2461*6a54128fSAndroid Build Coastguard Worker 2462*6a54128fSAndroid Build Coastguard Worker<Para> 2463*6a54128fSAndroid Build Coastguard WorkerThis section explains the commands available in the <Literal remap="tt">ext2_super_block</Literal> 2464*6a54128fSAndroid Build Coastguard Workertype. They all appear in <Literal remap="tt">super_com.c</Literal> 2465*6a54128fSAndroid Build Coastguard Worker</Para> 2466*6a54128fSAndroid Build Coastguard Worker 2467*6a54128fSAndroid Build Coastguard Worker<Sect3> 2468*6a54128fSAndroid Build Coastguard Worker<Title>The show command</Title> 2469*6a54128fSAndroid Build Coastguard Worker 2470*6a54128fSAndroid Build Coastguard Worker<Para> 2471*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">show</Literal> command is overridden here in order to provide more 2472*6a54128fSAndroid Build Coastguard Workerinformation than just the list of variables. A <Literal remap="tt">show</Literal> command will end 2473*6a54128fSAndroid Build Coastguard Workerup in calling <Literal remap="tt">type_super_block___show</Literal>. 2474*6a54128fSAndroid Build Coastguard Worker</Para> 2475*6a54128fSAndroid Build Coastguard Worker 2476*6a54128fSAndroid Build Coastguard Worker<Para> 2477*6a54128fSAndroid Build Coastguard WorkerThe first thing that we do is calling the <Literal remap="tt">general show command</Literal> in 2478*6a54128fSAndroid Build Coastguard Workerorder to display the list of variables. 2479*6a54128fSAndroid Build Coastguard Worker</Para> 2480*6a54128fSAndroid Build Coastguard Worker 2481*6a54128fSAndroid Build Coastguard Worker<Para> 2482*6a54128fSAndroid Build Coastguard WorkerWe then add some interpretation to the various lines to make the data 2483*6a54128fSAndroid Build Coastguard Workersomewhat more intuitive (Expansion of the time variables and the creator 2484*6a54128fSAndroid Build Coastguard Workeroperating system code, for example). 2485*6a54128fSAndroid Build Coastguard Worker</Para> 2486*6a54128fSAndroid Build Coastguard Worker 2487*6a54128fSAndroid Build Coastguard Worker<Para> 2488*6a54128fSAndroid Build Coastguard WorkerWe also display the <Literal remap="tt">backup copy number</Literal> of the superblock in the status 2489*6a54128fSAndroid Build Coastguard Workerwindow. This copy number is saved in the <Literal remap="tt">super_info</Literal> global variable - 2490*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">super_info.copy_num</Literal>. Currently, this is the only variable there ... 2491*6a54128fSAndroid Build Coastguard Workerbut this type of internal variable saving is typical through my 2492*6a54128fSAndroid Build Coastguard Workerimplementation. 2493*6a54128fSAndroid Build Coastguard Worker</Para> 2494*6a54128fSAndroid Build Coastguard Worker 2495*6a54128fSAndroid Build Coastguard Worker</Sect3> 2496*6a54128fSAndroid Build Coastguard Worker 2497*6a54128fSAndroid Build Coastguard Worker<Sect3> 2498*6a54128fSAndroid Build Coastguard Worker<Title>The backup copies handling commands</Title> 2499*6a54128fSAndroid Build Coastguard Worker 2500*6a54128fSAndroid Build Coastguard Worker<Para> 2501*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">current copy number</Literal> is available in <Literal remap="tt">super_info.copy_num</Literal>. It 2502*6a54128fSAndroid Build Coastguard Workerwas initialized in the ext2 command <Literal remap="tt">super</Literal>, and is used by the various 2503*6a54128fSAndroid Build Coastguard Workersuperblock routines. 2504*6a54128fSAndroid Build Coastguard Worker</Para> 2505*6a54128fSAndroid Build Coastguard Worker 2506*6a54128fSAndroid Build Coastguard Worker<Para> 2507*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">gocopy</Literal> routine will pass to another copy of the superblock. The 2508*6a54128fSAndroid Build Coastguard Workernew device offset will be computed with the aid of the variables in the 2509*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">file_system_info</Literal> structure. Then the routine will <Literal remap="tt">dispatch</Literal> to 2510*6a54128fSAndroid Build Coastguard Workerthe <Literal remap="tt">setoffset</Literal> and the <Literal remap="tt">show</Literal> routines. 2511*6a54128fSAndroid Build Coastguard Worker</Para> 2512*6a54128fSAndroid Build Coastguard Worker 2513*6a54128fSAndroid Build Coastguard Worker<Para> 2514*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">setactivecopy</Literal> routine will just save the current superblock data 2515*6a54128fSAndroid Build Coastguard Workerin a temporary variable of type <Literal remap="tt">ext2_super_block</Literal>, and will dispatch 2516*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">gocopy 0</Literal> to pass to the main superblock. Then it will place the saved 2517*6a54128fSAndroid Build Coastguard Workerdata in place of the actual data. 2518*6a54128fSAndroid Build Coastguard Worker</Para> 2519*6a54128fSAndroid Build Coastguard Worker 2520*6a54128fSAndroid Build Coastguard Worker<Para> 2521*6a54128fSAndroid Build Coastguard WorkerThe above two commands can be used if the main superblock is corrupted. 2522*6a54128fSAndroid Build Coastguard Worker</Para> 2523*6a54128fSAndroid Build Coastguard Worker 2524*6a54128fSAndroid Build Coastguard Worker</Sect3> 2525*6a54128fSAndroid Build Coastguard Worker 2526*6a54128fSAndroid Build Coastguard Worker</Sect2> 2527*6a54128fSAndroid Build Coastguard Worker 2528*6a54128fSAndroid Build Coastguard Worker</Sect1> 2529*6a54128fSAndroid Build Coastguard Worker 2530*6a54128fSAndroid Build Coastguard Worker<Sect1> 2531*6a54128fSAndroid Build Coastguard Worker<Title>The group descriptors</Title> 2532*6a54128fSAndroid Build Coastguard Worker 2533*6a54128fSAndroid Build Coastguard Worker<Para> 2534*6a54128fSAndroid Build Coastguard WorkerThe group descriptors handling mechanism allows the user to take a tour in 2535*6a54128fSAndroid Build Coastguard Workerthe group descriptors table, stopping at each point, and examining the 2536*6a54128fSAndroid Build Coastguard Workerrelevant inode table, block allocation map or inode allocation map through 2537*6a54128fSAndroid Build Coastguard Workerdispatching to the relevant objects. 2538*6a54128fSAndroid Build Coastguard Worker</Para> 2539*6a54128fSAndroid Build Coastguard Worker 2540*6a54128fSAndroid Build Coastguard Worker<Para> 2541*6a54128fSAndroid Build Coastguard WorkerSome information about the group descriptors is available in the global 2542*6a54128fSAndroid Build Coastguard Workervariable <Literal remap="tt">group_info</Literal>, which is of type <Literal remap="tt">struct_group_info</Literal>: 2543*6a54128fSAndroid Build Coastguard Worker</Para> 2544*6a54128fSAndroid Build Coastguard Worker 2545*6a54128fSAndroid Build Coastguard Worker<Para> 2546*6a54128fSAndroid Build Coastguard Worker 2547*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2548*6a54128fSAndroid Build Coastguard Workerstruct struct_group_info { 2549*6a54128fSAndroid Build Coastguard Worker unsigned long copy_num; 2550*6a54128fSAndroid Build Coastguard Worker unsigned long group_num; 2551*6a54128fSAndroid Build Coastguard Worker}; 2552*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2553*6a54128fSAndroid Build Coastguard Worker 2554*6a54128fSAndroid Build Coastguard Worker</Para> 2555*6a54128fSAndroid Build Coastguard Worker 2556*6a54128fSAndroid Build Coastguard Worker<Para> 2557*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">group_num</Literal> is the index of the current descriptor in the table. 2558*6a54128fSAndroid Build Coastguard Worker</Para> 2559*6a54128fSAndroid Build Coastguard Worker 2560*6a54128fSAndroid Build Coastguard Worker<Para> 2561*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">copy_num</Literal> is the number of the current backup copy. 2562*6a54128fSAndroid Build Coastguard Worker</Para> 2563*6a54128fSAndroid Build Coastguard Worker 2564*6a54128fSAndroid Build Coastguard Worker<Sect2> 2565*6a54128fSAndroid Build Coastguard Worker<Title>The group descriptor's variables</Title> 2566*6a54128fSAndroid Build Coastguard Worker 2567*6a54128fSAndroid Build Coastguard Worker<Para> 2568*6a54128fSAndroid Build Coastguard Worker 2569*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2570*6a54128fSAndroid Build Coastguard Workerstruct ext2_group_desc 2571*6a54128fSAndroid Build Coastguard Worker{ 2572*6a54128fSAndroid Build Coastguard Worker __u32 bg_block_bitmap; /* Blocks bitmap block */ 2573*6a54128fSAndroid Build Coastguard Worker __u32 bg_inode_bitmap; /* Inodes bitmap block */ 2574*6a54128fSAndroid Build Coastguard Worker __u32 bg_inode_table; /* Inodes table block */ 2575*6a54128fSAndroid Build Coastguard Worker __u16 bg_free_blocks_count; /* Free blocks count */ 2576*6a54128fSAndroid Build Coastguard Worker __u16 bg_free_inodes_count; /* Free inodes count */ 2577*6a54128fSAndroid Build Coastguard Worker __u16 bg_used_dirs_count; /* Directories count */ 2578*6a54128fSAndroid Build Coastguard Worker __u16 bg_pad; 2579*6a54128fSAndroid Build Coastguard Worker __u32 bg_reserved[3]; 2580*6a54128fSAndroid Build Coastguard Worker}; 2581*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2582*6a54128fSAndroid Build Coastguard Worker 2583*6a54128fSAndroid Build Coastguard Worker</Para> 2584*6a54128fSAndroid Build Coastguard Worker 2585*6a54128fSAndroid Build Coastguard Worker<Para> 2586*6a54128fSAndroid Build Coastguard WorkerThe first three variables are used to provide the links to the 2587*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">blockbitmap, inodebitmap and inode</Literal> objects. 2588*6a54128fSAndroid Build Coastguard Worker</Para> 2589*6a54128fSAndroid Build Coastguard Worker 2590*6a54128fSAndroid Build Coastguard Worker</Sect2> 2591*6a54128fSAndroid Build Coastguard Worker 2592*6a54128fSAndroid Build Coastguard Worker<Sect2> 2593*6a54128fSAndroid Build Coastguard Worker<Title>Movement in the table</Title> 2594*6a54128fSAndroid Build Coastguard Worker 2595*6a54128fSAndroid Build Coastguard Worker<Para> 2596*6a54128fSAndroid Build Coastguard WorkerMovement in the group descriptors table is done using the <Literal remap="tt">next, prev and 2597*6a54128fSAndroid Build Coastguard Workerentry</Literal> commands. Note that the first two commands <Literal remap="tt">override</Literal> the 2598*6a54128fSAndroid Build Coastguard Workergeneral commands of the same name. The <Literal remap="tt">next and prev</Literal> command are just 2599*6a54128fSAndroid Build Coastguard Workercalling the <Literal remap="tt">entry</Literal> function to do the job. I will show <Literal remap="tt">next</Literal>, 2600*6a54128fSAndroid Build Coastguard Workerfor example: 2601*6a54128fSAndroid Build Coastguard Worker</Para> 2602*6a54128fSAndroid Build Coastguard Worker 2603*6a54128fSAndroid Build Coastguard Worker<Para> 2604*6a54128fSAndroid Build Coastguard Worker 2605*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2606*6a54128fSAndroid Build Coastguard Workervoid type_ext2_group_desc___next (char *command_line) 2607*6a54128fSAndroid Build Coastguard Worker 2608*6a54128fSAndroid Build Coastguard Worker{ 2609*6a54128fSAndroid Build Coastguard Worker long entry_offset=1; 2610*6a54128fSAndroid Build Coastguard Worker char *ptr,buffer [80]; 2611*6a54128fSAndroid Build Coastguard Worker 2612*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (command_line,buffer); 2613*6a54128fSAndroid Build Coastguard Worker if (*ptr!=0) { 2614*6a54128fSAndroid Build Coastguard Worker ptr=parse_word (ptr,buffer); 2615*6a54128fSAndroid Build Coastguard Worker entry_offset=atol (buffer); 2616*6a54128fSAndroid Build Coastguard Worker } 2617*6a54128fSAndroid Build Coastguard Worker 2618*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"entry %ld",group_info.group_num+entry_offset); 2619*6a54128fSAndroid Build Coastguard Worker dispatch (buffer); 2620*6a54128fSAndroid Build Coastguard Worker} 2621*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2622*6a54128fSAndroid Build Coastguard Worker 2623*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">entry</Literal> function is also simple - It just calculates the offset 2624*6a54128fSAndroid Build Coastguard Workerusing the information in <Literal remap="tt">group_info</Literal> and in <Literal remap="tt">file_system_info</Literal>, 2625*6a54128fSAndroid Build Coastguard Workerand uses the usual <Literal remap="tt">setoffset / show</Literal> pair. 2626*6a54128fSAndroid Build Coastguard Worker</Para> 2627*6a54128fSAndroid Build Coastguard Worker 2628*6a54128fSAndroid Build Coastguard Worker</Sect2> 2629*6a54128fSAndroid Build Coastguard Worker 2630*6a54128fSAndroid Build Coastguard Worker<Sect2> 2631*6a54128fSAndroid Build Coastguard Worker<Title>The show command</Title> 2632*6a54128fSAndroid Build Coastguard Worker 2633*6a54128fSAndroid Build Coastguard Worker<Para> 2634*6a54128fSAndroid Build Coastguard WorkerAs usual, the <Literal remap="tt">show</Literal> command is overridden. The implementation is 2635*6a54128fSAndroid Build Coastguard Workersimilar to the superblock's show implementation - We just call the general 2636*6a54128fSAndroid Build Coastguard Workershow command, and add some information in the status window - The contents of 2637*6a54128fSAndroid Build Coastguard Workerthe <Literal remap="tt">group_info</Literal> structure. 2638*6a54128fSAndroid Build Coastguard Worker</Para> 2639*6a54128fSAndroid Build Coastguard Worker 2640*6a54128fSAndroid Build Coastguard Worker</Sect2> 2641*6a54128fSAndroid Build Coastguard Worker 2642*6a54128fSAndroid Build Coastguard Worker<Sect2> 2643*6a54128fSAndroid Build Coastguard Worker<Title>Moving between backup copies</Title> 2644*6a54128fSAndroid Build Coastguard Worker 2645*6a54128fSAndroid Build Coastguard Worker<Para> 2646*6a54128fSAndroid Build Coastguard WorkerThis is done exactly like the superblock case. Please refer to explanation 2647*6a54128fSAndroid Build Coastguard Workerthere. 2648*6a54128fSAndroid Build Coastguard Worker</Para> 2649*6a54128fSAndroid Build Coastguard Worker 2650*6a54128fSAndroid Build Coastguard Worker</Sect2> 2651*6a54128fSAndroid Build Coastguard Worker 2652*6a54128fSAndroid Build Coastguard Worker<Sect2> 2653*6a54128fSAndroid Build Coastguard Worker<Title>Links to the available friends</Title> 2654*6a54128fSAndroid Build Coastguard Worker 2655*6a54128fSAndroid Build Coastguard Worker<Para> 2656*6a54128fSAndroid Build Coastguard WorkerFrom a group descriptor, one typically wants to reach an <Literal remap="tt">inode</Literal>, or 2657*6a54128fSAndroid Build Coastguard Workerone of the <Literal remap="tt">allocation bitmaps</Literal>. This is done using the <Literal remap="tt">inode, 2658*6a54128fSAndroid Build Coastguard Workerblockbitmap or inodebitmap</Literal> commands. The implementation is again trivial 2659*6a54128fSAndroid Build Coastguard Worker- Get the necessary information from the group descriptor, initialize the 2660*6a54128fSAndroid Build Coastguard Workerstructures of the next type, and issue the <Literal remap="tt">setoffset / settype</Literal> pair. 2661*6a54128fSAndroid Build Coastguard Worker</Para> 2662*6a54128fSAndroid Build Coastguard Worker 2663*6a54128fSAndroid Build Coastguard Worker<Para> 2664*6a54128fSAndroid Build Coastguard WorkerFor example, here is the implementation of the <Literal remap="tt">blockbitmap</Literal> command: 2665*6a54128fSAndroid Build Coastguard Worker</Para> 2666*6a54128fSAndroid Build Coastguard Worker 2667*6a54128fSAndroid Build Coastguard Worker<Para> 2668*6a54128fSAndroid Build Coastguard Worker 2669*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2670*6a54128fSAndroid Build Coastguard Workervoid type_ext2_group_desc___blockbitmap (char *command_line) 2671*6a54128fSAndroid Build Coastguard Worker 2672*6a54128fSAndroid Build Coastguard Worker{ 2673*6a54128fSAndroid Build Coastguard Worker long block_bitmap_offset; 2674*6a54128fSAndroid Build Coastguard Worker char buffer [80]; 2675*6a54128fSAndroid Build Coastguard Worker 2676*6a54128fSAndroid Build Coastguard Worker block_bitmap_info.entry_num=0; 2677*6a54128fSAndroid Build Coastguard Worker block_bitmap_info.group_num=group_info.group_num; 2678*6a54128fSAndroid Build Coastguard Worker 2679*6a54128fSAndroid Build Coastguard Worker block_bitmap_offset=type_data.u.t_ext2_group_desc.bg_block_bitmap; 2680*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"setoffset block %ld",block_bitmap_offset);dispatch (buffer); 2681*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"settype block_bitmap");dispatch (buffer); 2682*6a54128fSAndroid Build Coastguard Worker} 2683*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2684*6a54128fSAndroid Build Coastguard Worker 2685*6a54128fSAndroid Build Coastguard Worker</Para> 2686*6a54128fSAndroid Build Coastguard Worker 2687*6a54128fSAndroid Build Coastguard Worker</Sect2> 2688*6a54128fSAndroid Build Coastguard Worker 2689*6a54128fSAndroid Build Coastguard Worker</Sect1> 2690*6a54128fSAndroid Build Coastguard Worker 2691*6a54128fSAndroid Build Coastguard Worker<Sect1> 2692*6a54128fSAndroid Build Coastguard Worker<Title>The inode table</Title> 2693*6a54128fSAndroid Build Coastguard Worker 2694*6a54128fSAndroid Build Coastguard Worker<Para> 2695*6a54128fSAndroid Build Coastguard WorkerThe inode handling enables the user to move in the inode table, edit the 2696*6a54128fSAndroid Build Coastguard Workervarious attributes of the inode, and follow to the next stage - A file or a 2697*6a54128fSAndroid Build Coastguard Workerdirectory. 2698*6a54128fSAndroid Build Coastguard Worker</Para> 2699*6a54128fSAndroid Build Coastguard Worker 2700*6a54128fSAndroid Build Coastguard Worker<Sect2> 2701*6a54128fSAndroid Build Coastguard Worker<Title>The inode variables</Title> 2702*6a54128fSAndroid Build Coastguard Worker 2703*6a54128fSAndroid Build Coastguard Worker<Para> 2704*6a54128fSAndroid Build Coastguard Worker 2705*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2706*6a54128fSAndroid Build Coastguard Workerstruct ext2_inode { 2707*6a54128fSAndroid Build Coastguard Worker __u16 i_mode; /* File mode */ 2708*6a54128fSAndroid Build Coastguard Worker __u16 i_uid; /* Owner Uid */ 2709*6a54128fSAndroid Build Coastguard Worker __u32 i_size; /* Size in bytes */ 2710*6a54128fSAndroid Build Coastguard Worker __u32 i_atime; /* Access time */ 2711*6a54128fSAndroid Build Coastguard Worker __u32 i_ctime; /* Creation time */ 2712*6a54128fSAndroid Build Coastguard Worker __u32 i_mtime; /* Modification time */ 2713*6a54128fSAndroid Build Coastguard Worker __u32 i_dtime; /* Deletion Time */ 2714*6a54128fSAndroid Build Coastguard Worker __u16 i_gid; /* Group Id */ 2715*6a54128fSAndroid Build Coastguard Worker __u16 i_links_count; /* Links count */ 2716*6a54128fSAndroid Build Coastguard Worker __u32 i_blocks; /* Blocks count */ 2717*6a54128fSAndroid Build Coastguard Worker __u32 i_flags; /* File flags */ 2718*6a54128fSAndroid Build Coastguard Worker union { 2719*6a54128fSAndroid Build Coastguard Worker struct { 2720*6a54128fSAndroid Build Coastguard Worker __u32 l_i_reserved1; 2721*6a54128fSAndroid Build Coastguard Worker } linux1; 2722*6a54128fSAndroid Build Coastguard Worker struct { 2723*6a54128fSAndroid Build Coastguard Worker __u32 h_i_translator; 2724*6a54128fSAndroid Build Coastguard Worker } hurd1; 2725*6a54128fSAndroid Build Coastguard Worker } osd1; /* OS dependent 1 */ 2726*6a54128fSAndroid Build Coastguard Worker __u32 i_block[EXT2_N_BLOCKS]; /* Pointers to blocks */ 2727*6a54128fSAndroid Build Coastguard Worker __u32 i_version; /* File version (for NFS) */ 2728*6a54128fSAndroid Build Coastguard Worker __u32 i_file_acl; /* File ACL */ 2729*6a54128fSAndroid Build Coastguard Worker __u32 i_size_high; /* High 32bits of size */ 2730*6a54128fSAndroid Build Coastguard Worker __u32 i_faddr; /* Fragment address */ 2731*6a54128fSAndroid Build Coastguard Worker union { 2732*6a54128fSAndroid Build Coastguard Worker struct { 2733*6a54128fSAndroid Build Coastguard Worker __u8 l_i_frag; /* Fragment number */ 2734*6a54128fSAndroid Build Coastguard Worker __u8 l_i_fsize; /* Fragment size */ 2735*6a54128fSAndroid Build Coastguard Worker __u16 i_pad1; 2736*6a54128fSAndroid Build Coastguard Worker __u32 l_i_reserved2[2]; 2737*6a54128fSAndroid Build Coastguard Worker } linux2; 2738*6a54128fSAndroid Build Coastguard Worker struct { 2739*6a54128fSAndroid Build Coastguard Worker __u8 h_i_frag; /* Fragment number */ 2740*6a54128fSAndroid Build Coastguard Worker __u8 h_i_fsize; /* Fragment size */ 2741*6a54128fSAndroid Build Coastguard Worker __u16 h_i_mode_high; 2742*6a54128fSAndroid Build Coastguard Worker __u16 h_i_uid_high; 2743*6a54128fSAndroid Build Coastguard Worker __u16 h_i_gid_high; 2744*6a54128fSAndroid Build Coastguard Worker __u32 h_i_author; 2745*6a54128fSAndroid Build Coastguard Worker } hurd2; 2746*6a54128fSAndroid Build Coastguard Worker } osd2; /* OS dependent 2 */ 2747*6a54128fSAndroid Build Coastguard Worker}; 2748*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2749*6a54128fSAndroid Build Coastguard Worker 2750*6a54128fSAndroid Build Coastguard Worker</Para> 2751*6a54128fSAndroid Build Coastguard Worker 2752*6a54128fSAndroid Build Coastguard Worker<Para> 2753*6a54128fSAndroid Build Coastguard WorkerThe above is the original source code definition. We can see that the inode 2754*6a54128fSAndroid Build Coastguard Workersupports <Literal remap="tt">Operating systems specific structures</Literal>. In addition to the 2755*6a54128fSAndroid Build Coastguard Workerexpansion of the arrays, I have <Literal remap="tt">"flattened</Literal> the inode to support only 2756*6a54128fSAndroid Build Coastguard Workerthe <Literal remap="tt">Linux</Literal> declaration. It seemed that this one occasion of multiple 2757*6a54128fSAndroid Build Coastguard Workervariable aliases didn't justify the complication of generally supporting 2758*6a54128fSAndroid Build Coastguard Workeraliases. In any case, the above system specific variables are not used 2759*6a54128fSAndroid Build Coastguard Workerinternally by EXT2ED, and the user is free to change the definition in 2760*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ext2.descriptors</Literal> to accommodate for his needs. 2761*6a54128fSAndroid Build Coastguard Worker</Para> 2762*6a54128fSAndroid Build Coastguard Worker 2763*6a54128fSAndroid Build Coastguard Worker</Sect2> 2764*6a54128fSAndroid Build Coastguard Worker 2765*6a54128fSAndroid Build Coastguard Worker<Sect2> 2766*6a54128fSAndroid Build Coastguard Worker<Title>The handling functions</Title> 2767*6a54128fSAndroid Build Coastguard Worker 2768*6a54128fSAndroid Build Coastguard Worker<Para> 2769*6a54128fSAndroid Build Coastguard WorkerThe user interface to <Literal remap="tt">movement</Literal> is the usual <Literal remap="tt">next / prev / 2770*6a54128fSAndroid Build Coastguard Workerentry</Literal> interface. There is really nothing special in those functions - The 2771*6a54128fSAndroid Build Coastguard Workersize of the inode is fixed, the total number of inodes is known from the 2772*6a54128fSAndroid Build Coastguard Workersuperblock information, and the current entry can be figured up from the 2773*6a54128fSAndroid Build Coastguard Workerdevice offset and the inode table start offset, which is known from the 2774*6a54128fSAndroid Build Coastguard Workercorresponding group descriptor. Those functions are a bit older then some 2775*6a54128fSAndroid Build Coastguard Workerother implementations of <Literal remap="tt">next</Literal> and <Literal remap="tt">prev</Literal>, and they do not save 2776*6a54128fSAndroid Build Coastguard Workerinformation in a special structure. Rather, they recompute it when 2777*6a54128fSAndroid Build Coastguard Workernecessary. 2778*6a54128fSAndroid Build Coastguard Worker</Para> 2779*6a54128fSAndroid Build Coastguard Worker 2780*6a54128fSAndroid Build Coastguard Worker<Para> 2781*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">show</Literal> command is overridden here, and provides a lot of additional 2782*6a54128fSAndroid Build Coastguard Workerinformation about the inode - Its type, interpretation of the permissions, 2783*6a54128fSAndroid Build Coastguard Workerspecial ext2 attributes (Immutable file, for example), and a lot more. 2784*6a54128fSAndroid Build Coastguard WorkerAgain, the <Literal remap="tt">general show</Literal> is called first, and then the additional 2785*6a54128fSAndroid Build Coastguard Workerinformation is written. 2786*6a54128fSAndroid Build Coastguard Worker</Para> 2787*6a54128fSAndroid Build Coastguard Worker 2788*6a54128fSAndroid Build Coastguard Worker</Sect2> 2789*6a54128fSAndroid Build Coastguard Worker 2790*6a54128fSAndroid Build Coastguard Worker<Sect2> 2791*6a54128fSAndroid Build Coastguard Worker<Title>Accessing files and directories</Title> 2792*6a54128fSAndroid Build Coastguard Worker 2793*6a54128fSAndroid Build Coastguard Worker<Para> 2794*6a54128fSAndroid Build Coastguard WorkerFrom the inode, a <Literal remap="tt">file</Literal> or a <Literal remap="tt">directory</Literal> can typically be reached. 2795*6a54128fSAndroid Build Coastguard WorkerIn order to treat a file, for example, its inode needs to be constantly 2796*6a54128fSAndroid Build Coastguard Workeraccessed. To satisfy that need, when editing a file or a directory, the 2797*6a54128fSAndroid Build Coastguard Workerinode is still saved in memory - <Literal remap="tt">type_data</Literal> is not overwritten. 2798*6a54128fSAndroid Build Coastguard WorkerRather, the following takes place: 2799*6a54128fSAndroid Build Coastguard Worker 2800*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 2801*6a54128fSAndroid Build Coastguard Worker<ListItem> 2802*6a54128fSAndroid Build Coastguard Worker 2803*6a54128fSAndroid Build Coastguard Worker<Para> 2804*6a54128fSAndroid Build Coastguard Worker An internal global structure which is used by the types <Literal remap="tt">file</Literal> 2805*6a54128fSAndroid Build Coastguard Workerand <Literal remap="tt">dir</Literal> handling functions is initialized by calling the 2806*6a54128fSAndroid Build Coastguard Workerappropriate function. 2807*6a54128fSAndroid Build Coastguard Worker</Para> 2808*6a54128fSAndroid Build Coastguard Worker</ListItem> 2809*6a54128fSAndroid Build Coastguard Worker<ListItem> 2810*6a54128fSAndroid Build Coastguard Worker 2811*6a54128fSAndroid Build Coastguard Worker<Para> 2812*6a54128fSAndroid Build Coastguard Worker The type is changed accordingly. 2813*6a54128fSAndroid Build Coastguard Worker</Para> 2814*6a54128fSAndroid Build Coastguard Worker</ListItem> 2815*6a54128fSAndroid Build Coastguard Worker 2816*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 2817*6a54128fSAndroid Build Coastguard Worker 2818*6a54128fSAndroid Build Coastguard WorkerThe result is that a <Literal remap="tt">settype ext2_inode</Literal> is the only action necessary 2819*6a54128fSAndroid Build Coastguard Workerto return to the inode - We actually never left it. 2820*6a54128fSAndroid Build Coastguard Worker</Para> 2821*6a54128fSAndroid Build Coastguard Worker 2822*6a54128fSAndroid Build Coastguard Worker<Para> 2823*6a54128fSAndroid Build Coastguard WorkerFollows the implementation of the inode's <Literal remap="tt">file</Literal> command: 2824*6a54128fSAndroid Build Coastguard Worker</Para> 2825*6a54128fSAndroid Build Coastguard Worker 2826*6a54128fSAndroid Build Coastguard Worker<Para> 2827*6a54128fSAndroid Build Coastguard Worker 2828*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2829*6a54128fSAndroid Build Coastguard Workervoid type_ext2_inode___file (char *command_line) 2830*6a54128fSAndroid Build Coastguard Worker 2831*6a54128fSAndroid Build Coastguard Worker{ 2832*6a54128fSAndroid Build Coastguard Worker char buffer [80]; 2833*6a54128fSAndroid Build Coastguard Worker 2834*6a54128fSAndroid Build Coastguard Worker if (!S_ISREG (type_data.u.t_ext2_inode.i_mode)) { 2835*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Inode type is not file\n"); 2836*6a54128fSAndroid Build Coastguard Worker refresh_command_win (); return; 2837*6a54128fSAndroid Build Coastguard Worker } 2838*6a54128fSAndroid Build Coastguard Worker 2839*6a54128fSAndroid Build Coastguard Worker if (!init_file_info ()) { 2840*6a54128fSAndroid Build Coastguard Worker wprintw (command_win,"Error - Unable to show file\n"); 2841*6a54128fSAndroid Build Coastguard Worker refresh_command_win ();return; 2842*6a54128fSAndroid Build Coastguard Worker } 2843*6a54128fSAndroid Build Coastguard Worker 2844*6a54128fSAndroid Build Coastguard Worker sprintf (buffer,"settype file");dispatch (buffer); 2845*6a54128fSAndroid Build Coastguard Worker} 2846*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2847*6a54128fSAndroid Build Coastguard Worker 2848*6a54128fSAndroid Build Coastguard Worker</Para> 2849*6a54128fSAndroid Build Coastguard Worker 2850*6a54128fSAndroid Build Coastguard Worker<Para> 2851*6a54128fSAndroid Build Coastguard WorkerAs we can see - We just call <Literal remap="tt">init_file_info</Literal> to get the necessary 2852*6a54128fSAndroid Build Coastguard Workerinformation from the inode, and set the type to <Literal remap="tt">file</Literal>. The next call 2853*6a54128fSAndroid Build Coastguard Workerto <Literal remap="tt">show</Literal>, will dispatch to the <Literal remap="tt">file's show</Literal> implementation. 2854*6a54128fSAndroid Build Coastguard Worker</Para> 2855*6a54128fSAndroid Build Coastguard Worker 2856*6a54128fSAndroid Build Coastguard Worker</Sect2> 2857*6a54128fSAndroid Build Coastguard Worker 2858*6a54128fSAndroid Build Coastguard Worker</Sect1> 2859*6a54128fSAndroid Build Coastguard Worker 2860*6a54128fSAndroid Build Coastguard Worker<Sect1> 2861*6a54128fSAndroid Build Coastguard Worker<Title>Viewing a file</Title> 2862*6a54128fSAndroid Build Coastguard Worker 2863*6a54128fSAndroid Build Coastguard Worker<Para> 2864*6a54128fSAndroid Build Coastguard WorkerThere isn't an ext2 kernel structure which corresponds to a file - A file is 2865*6a54128fSAndroid Build Coastguard Workerjust a series of blocks which are determined by its inode. As explained in 2866*6a54128fSAndroid Build Coastguard Workerthe last section, the inode is never actually left - The type is changed to 2867*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">file</Literal> - A type which contains no variables, and a special structure is 2868*6a54128fSAndroid Build Coastguard Workerinitialized: 2869*6a54128fSAndroid Build Coastguard Worker</Para> 2870*6a54128fSAndroid Build Coastguard Worker 2871*6a54128fSAndroid Build Coastguard Worker<Para> 2872*6a54128fSAndroid Build Coastguard Worker 2873*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2874*6a54128fSAndroid Build Coastguard Workerstruct struct_file_info { 2875*6a54128fSAndroid Build Coastguard Worker 2876*6a54128fSAndroid Build Coastguard Worker struct ext2_inodes *inode_ptr; 2877*6a54128fSAndroid Build Coastguard Worker 2878*6a54128fSAndroid Build Coastguard Worker long inode_offset; 2879*6a54128fSAndroid Build Coastguard Worker long global_block_num,global_block_offset; 2880*6a54128fSAndroid Build Coastguard Worker long block_num,blocks_count; 2881*6a54128fSAndroid Build Coastguard Worker long file_offset,file_length; 2882*6a54128fSAndroid Build Coastguard Worker long level; 2883*6a54128fSAndroid Build Coastguard Worker unsigned char buffer [EXT2_MAX_BLOCK_SIZE]; 2884*6a54128fSAndroid Build Coastguard Worker long offset_in_block; 2885*6a54128fSAndroid Build Coastguard Worker 2886*6a54128fSAndroid Build Coastguard Worker int display; 2887*6a54128fSAndroid Build Coastguard Worker /* The following is used if the file is a directory */ 2888*6a54128fSAndroid Build Coastguard Worker 2889*6a54128fSAndroid Build Coastguard Worker long dir_entry_num,dir_entries_count; 2890*6a54128fSAndroid Build Coastguard Worker long dir_entry_offset; 2891*6a54128fSAndroid Build Coastguard Worker}; 2892*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2893*6a54128fSAndroid Build Coastguard Worker 2894*6a54128fSAndroid Build Coastguard Worker</Para> 2895*6a54128fSAndroid Build Coastguard Worker 2896*6a54128fSAndroid Build Coastguard Worker<Para> 2897*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">inode_ptr</Literal> will just point to the inode in <Literal remap="tt">type_data</Literal>, which 2898*6a54128fSAndroid Build Coastguard Workeris not overwritten while the user is editing the file, as the 2899*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">setoffset</Literal> command is not internally used. The <Literal remap="tt">buffer</Literal> 2900*6a54128fSAndroid Build Coastguard Workerwill contain the current viewed block of the file. The other variables 2901*6a54128fSAndroid Build Coastguard Workercontain information about the current place in the file. For example, 2902*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">global_block_num</Literal> just contains the current block number. 2903*6a54128fSAndroid Build Coastguard Worker</Para> 2904*6a54128fSAndroid Build Coastguard Worker 2905*6a54128fSAndroid Build Coastguard Worker<Para> 2906*6a54128fSAndroid Build Coastguard WorkerThe general idea is that the above data structure will provide the file 2907*6a54128fSAndroid Build Coastguard Workerhandling functions all the accurate information which is needed to accomplish 2908*6a54128fSAndroid Build Coastguard Workertheir task. 2909*6a54128fSAndroid Build Coastguard Worker</Para> 2910*6a54128fSAndroid Build Coastguard Worker 2911*6a54128fSAndroid Build Coastguard Worker<Para> 2912*6a54128fSAndroid Build Coastguard WorkerThe global structure of the above type, <Literal remap="tt">file_info</Literal>, is initialized by 2913*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">init_file_info</Literal> in <Literal remap="tt">file_com.c</Literal>, which is called by the 2914*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">type_ext2_inode___file</Literal> function when the user requests to watch the 2915*6a54128fSAndroid Build Coastguard Workerfile. <Literal remap="tt">It is updated as necessary to provide accurate information as long as 2916*6a54128fSAndroid Build Coastguard Workerthe file is edited.</Literal> 2917*6a54128fSAndroid Build Coastguard Worker</Para> 2918*6a54128fSAndroid Build Coastguard Worker 2919*6a54128fSAndroid Build Coastguard Worker<Sect2> 2920*6a54128fSAndroid Build Coastguard Worker<Title>Returning to the file's inode</Title> 2921*6a54128fSAndroid Build Coastguard Worker 2922*6a54128fSAndroid Build Coastguard Worker<Para> 2923*6a54128fSAndroid Build Coastguard WorkerConcerning the method I used to handle files, the above task is trivial: 2924*6a54128fSAndroid Build Coastguard Worker 2925*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2926*6a54128fSAndroid Build Coastguard Workervoid type_file___inode (char *command_line) 2927*6a54128fSAndroid Build Coastguard Worker 2928*6a54128fSAndroid Build Coastguard Worker{ 2929*6a54128fSAndroid Build Coastguard Worker dispatch ("settype ext2_inode"); 2930*6a54128fSAndroid Build Coastguard Worker} 2931*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2932*6a54128fSAndroid Build Coastguard Worker 2933*6a54128fSAndroid Build Coastguard Worker</Para> 2934*6a54128fSAndroid Build Coastguard Worker 2935*6a54128fSAndroid Build Coastguard Worker</Sect2> 2936*6a54128fSAndroid Build Coastguard Worker 2937*6a54128fSAndroid Build Coastguard Worker<Sect2> 2938*6a54128fSAndroid Build Coastguard Worker<Title>File movement</Title> 2939*6a54128fSAndroid Build Coastguard Worker 2940*6a54128fSAndroid Build Coastguard Worker<Para> 2941*6a54128fSAndroid Build Coastguard WorkerEXT2ED keeps track of the current position in the file. Movement inside the 2942*6a54128fSAndroid Build Coastguard Workercurrent block is done using <Literal remap="tt">next, prev and offset</Literal> - They just change 2943*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">file_info.offset_in_block</Literal>. 2944*6a54128fSAndroid Build Coastguard Worker</Para> 2945*6a54128fSAndroid Build Coastguard Worker 2946*6a54128fSAndroid Build Coastguard Worker<Para> 2947*6a54128fSAndroid Build Coastguard WorkerMovement between blocks is done using <Literal remap="tt">nextblock, prevblock and block</Literal>. 2948*6a54128fSAndroid Build Coastguard WorkerTo accomplish this, the direct blocks, indirect blocks, etc, need to be 2949*6a54128fSAndroid Build Coastguard Workertraced. This is done by <Literal remap="tt">file_block_to_global_block</Literal>, which accepts a 2950*6a54128fSAndroid Build Coastguard Workerfile's internal block number, and converts it to the actual filesystem block 2951*6a54128fSAndroid Build Coastguard Workernumber. 2952*6a54128fSAndroid Build Coastguard Worker</Para> 2953*6a54128fSAndroid Build Coastguard Worker 2954*6a54128fSAndroid Build Coastguard Worker<Para> 2955*6a54128fSAndroid Build Coastguard Worker 2956*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 2957*6a54128fSAndroid Build Coastguard Workerlong file_block_to_global_block (long file_block,struct struct_file_info *file_info_ptr) 2958*6a54128fSAndroid Build Coastguard Worker 2959*6a54128fSAndroid Build Coastguard Worker{ 2960*6a54128fSAndroid Build Coastguard Worker long last_direct,last_indirect,last_dindirect; 2961*6a54128fSAndroid Build Coastguard Worker long f_indirect,s_indirect; 2962*6a54128fSAndroid Build Coastguard Worker 2963*6a54128fSAndroid Build Coastguard Worker last_direct=EXT2_NDIR_BLOCKS-1; 2964*6a54128fSAndroid Build Coastguard Worker last_indirect=last_direct+file_system_info.block_size/4; 2965*6a54128fSAndroid Build Coastguard Worker last_dindirect=last_indirect+(file_system_info.block_size/4) \ 2966*6a54128fSAndroid Build Coastguard Worker *(file_system_info.block_size/4); 2967*6a54128fSAndroid Build Coastguard Worker 2968*6a54128fSAndroid Build Coastguard Worker if (file_block <= last_direct) { 2969*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=0; 2970*6a54128fSAndroid Build Coastguard Worker return (file_info_ptr->inode_ptr->i_block [file_block]); 2971*6a54128fSAndroid Build Coastguard Worker } 2972*6a54128fSAndroid Build Coastguard Worker 2973*6a54128fSAndroid Build Coastguard Worker if (file_block <= last_indirect) { 2974*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=1; 2975*6a54128fSAndroid Build Coastguard Worker file_block=file_block-last_direct-1; 2976*6a54128fSAndroid Build Coastguard Worker return (return_indirect (file_info_ptr->inode_ptr-> \ 2977*6a54128fSAndroid Build Coastguard Worker i_block [EXT2_IND_BLOCK],file_block)); 2978*6a54128fSAndroid Build Coastguard Worker } 2979*6a54128fSAndroid Build Coastguard Worker 2980*6a54128fSAndroid Build Coastguard Worker if (file_block <= last_dindirect) { 2981*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=2; 2982*6a54128fSAndroid Build Coastguard Worker file_block=file_block-last_indirect-1; 2983*6a54128fSAndroid Build Coastguard Worker return (return_dindirect (file_info_ptr->inode_ptr-> \ 2984*6a54128fSAndroid Build Coastguard Worker i_block [EXT2_DIND_BLOCK],file_block)); 2985*6a54128fSAndroid Build Coastguard Worker } 2986*6a54128fSAndroid Build Coastguard Worker 2987*6a54128fSAndroid Build Coastguard Worker file_info_ptr->level=3; 2988*6a54128fSAndroid Build Coastguard Worker file_block=file_block-last_dindirect-1; 2989*6a54128fSAndroid Build Coastguard Worker return (return_tindirect (file_info_ptr->inode_ptr-> \ 2990*6a54128fSAndroid Build Coastguard Worker i_block [EXT2_TIND_BLOCK],file_block)); 2991*6a54128fSAndroid Build Coastguard Worker} 2992*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 2993*6a54128fSAndroid Build Coastguard Worker 2994*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">last_direct, last_indirect, etc</Literal>, contain the last internal block number 2995*6a54128fSAndroid Build Coastguard Workerwhich is accessed by this method - If the requested block is smaller then 2996*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">last_direct</Literal>, for example, it is a direct block. 2997*6a54128fSAndroid Build Coastguard Worker</Para> 2998*6a54128fSAndroid Build Coastguard Worker 2999*6a54128fSAndroid Build Coastguard Worker<Para> 3000*6a54128fSAndroid Build Coastguard WorkerIf the block is a direct block, its number is just taken from the inode. 3001*6a54128fSAndroid Build Coastguard WorkerA non-direct block is handled by <Literal remap="tt">return_indirect, return_dindirect and 3002*6a54128fSAndroid Build Coastguard Workerreturn_tindirect</Literal>, which correspond to indirect, double-indirect and 3003*6a54128fSAndroid Build Coastguard Workertriple-indirect. Each of the above functions is constructed using the lower 3004*6a54128fSAndroid Build Coastguard Workerlevel functions. For example, <Literal remap="tt">return_dindirect</Literal> is constructed as 3005*6a54128fSAndroid Build Coastguard Workerfollows: 3006*6a54128fSAndroid Build Coastguard Worker</Para> 3007*6a54128fSAndroid Build Coastguard Worker 3008*6a54128fSAndroid Build Coastguard Worker<Para> 3009*6a54128fSAndroid Build Coastguard Worker 3010*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 3011*6a54128fSAndroid Build Coastguard Workerlong return_dindirect (long table_block,long block_num) 3012*6a54128fSAndroid Build Coastguard Worker 3013*6a54128fSAndroid Build Coastguard Worker{ 3014*6a54128fSAndroid Build Coastguard Worker long f_indirect; 3015*6a54128fSAndroid Build Coastguard Worker 3016*6a54128fSAndroid Build Coastguard Worker f_indirect=block_num/(file_system_info.block_size/4); 3017*6a54128fSAndroid Build Coastguard Worker f_indirect=return_indirect (table_block,f_indirect); 3018*6a54128fSAndroid Build Coastguard Worker return (return_indirect (f_indirect,block_num%(file_system_info.block_size/4))); 3019*6a54128fSAndroid Build Coastguard Worker} 3020*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 3021*6a54128fSAndroid Build Coastguard Worker 3022*6a54128fSAndroid Build Coastguard Worker</Para> 3023*6a54128fSAndroid Build Coastguard Worker 3024*6a54128fSAndroid Build Coastguard Worker</Sect2> 3025*6a54128fSAndroid Build Coastguard Worker 3026*6a54128fSAndroid Build Coastguard Worker<Sect2> 3027*6a54128fSAndroid Build Coastguard Worker<Title>Object memory</Title> 3028*6a54128fSAndroid Build Coastguard Worker 3029*6a54128fSAndroid Build Coastguard Worker<Para> 3030*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">remember</Literal> command is overridden here and in the <Literal remap="tt">dir</Literal> type - 3031*6a54128fSAndroid Build Coastguard WorkerWe just remember the inode of the file. It is just simpler to implement, and 3032*6a54128fSAndroid Build Coastguard Workerdoesn't seem like a big limitation. 3033*6a54128fSAndroid Build Coastguard Worker</Para> 3034*6a54128fSAndroid Build Coastguard Worker 3035*6a54128fSAndroid Build Coastguard Worker</Sect2> 3036*6a54128fSAndroid Build Coastguard Worker 3037*6a54128fSAndroid Build Coastguard Worker<Sect2> 3038*6a54128fSAndroid Build Coastguard Worker<Title>Changing data</Title> 3039*6a54128fSAndroid Build Coastguard Worker 3040*6a54128fSAndroid Build Coastguard Worker<Para> 3041*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">set</Literal> command is overridden, and provides the same functionality 3042*6a54128fSAndroid Build Coastguard Workerlike the usage of the <Literal remap="tt">general set</Literal> command with no type declared. The 3043*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">writedata</Literal> is overridden so that we'll write the edited block 3044*6a54128fSAndroid Build Coastguard Worker(file_info.buffer) and not <Literal remap="tt">type_data</Literal> (Which contains the inode). 3045*6a54128fSAndroid Build Coastguard Worker</Para> 3046*6a54128fSAndroid Build Coastguard Worker 3047*6a54128fSAndroid Build Coastguard Worker</Sect2> 3048*6a54128fSAndroid Build Coastguard Worker 3049*6a54128fSAndroid Build Coastguard Worker</Sect1> 3050*6a54128fSAndroid Build Coastguard Worker 3051*6a54128fSAndroid Build Coastguard Worker<Sect1> 3052*6a54128fSAndroid Build Coastguard Worker<Title>Directories</Title> 3053*6a54128fSAndroid Build Coastguard Worker 3054*6a54128fSAndroid Build Coastguard Worker<Para> 3055*6a54128fSAndroid Build Coastguard WorkerA directory is just a file which is formatted according to a special format. 3056*6a54128fSAndroid Build Coastguard WorkerAs such, EXT2ED handles directories and files quite alike. Specifically, the 3057*6a54128fSAndroid Build Coastguard Workersame variable of type <Literal remap="tt">struct_file_info</Literal> which is used in the 3058*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">file</Literal>, is used here. 3059*6a54128fSAndroid Build Coastguard Worker</Para> 3060*6a54128fSAndroid Build Coastguard Worker 3061*6a54128fSAndroid Build Coastguard Worker<Para> 3062*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">dir</Literal> type uses all the variables in the above structure, as 3063*6a54128fSAndroid Build Coastguard Workeropposed to the <Literal remap="tt">file</Literal> type, which didn't use the last ones. 3064*6a54128fSAndroid Build Coastguard Worker</Para> 3065*6a54128fSAndroid Build Coastguard Worker 3066*6a54128fSAndroid Build Coastguard Worker<Sect2> 3067*6a54128fSAndroid Build Coastguard Worker<Title>The search_dir_entries function</Title> 3068*6a54128fSAndroid Build Coastguard Worker 3069*6a54128fSAndroid Build Coastguard Worker<Para> 3070*6a54128fSAndroid Build Coastguard WorkerThe entire situation is similar to that which was described in the 3071*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">file</Literal> type, with one main change: 3072*6a54128fSAndroid Build Coastguard Worker</Para> 3073*6a54128fSAndroid Build Coastguard Worker 3074*6a54128fSAndroid Build Coastguard Worker<Para> 3075*6a54128fSAndroid Build Coastguard WorkerThe main function in <Literal remap="tt">dir_com.c</Literal> is <Literal remap="tt">search_dir_entries</Literal>. This 3076*6a54128fSAndroid Build Coastguard Workerfunction will <Literal remap="tt">"run"</Literal> on the entire entries in the directory, and will 3077*6a54128fSAndroid Build Coastguard Workercall a client's function each time. The client's function is supplied as an 3078*6a54128fSAndroid Build Coastguard Workerargument, and will check the current entry for a match, based on its own 3079*6a54128fSAndroid Build Coastguard Workercriterion. It will then signal <Literal remap="tt">search_dir_entries</Literal> whether to 3080*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ABORT</Literal> the search, whether it <Literal remap="tt">FOUND</Literal> the entry it was looking 3081*6a54128fSAndroid Build Coastguard Workerfor, or that the entry is still not found, and we should <Literal remap="tt">CONTINUE</Literal> 3082*6a54128fSAndroid Build Coastguard Workersearching. Follows the declaration: 3083*6a54128fSAndroid Build Coastguard Worker 3084*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 3085*6a54128fSAndroid Build Coastguard Workerstruct struct_file_info search_dir_entries \ 3086*6a54128fSAndroid Build Coastguard Worker (int (*action) (struct struct_file_info *info),int *status) 3087*6a54128fSAndroid Build Coastguard Worker 3088*6a54128fSAndroid Build Coastguard Worker/* 3089*6a54128fSAndroid Build Coastguard Worker This routine runs on all directory entries in the current directory. 3090*6a54128fSAndroid Build Coastguard Worker For each entry, action is called. The return code of action is one of 3091*6a54128fSAndroid Build Coastguard Worker the following: 3092*6a54128fSAndroid Build Coastguard Worker 3093*6a54128fSAndroid Build Coastguard Worker ABORT - Current dir entry is returned. 3094*6a54128fSAndroid Build Coastguard Worker CONTINUE - Continue searching. 3095*6a54128fSAndroid Build Coastguard Worker FOUND - Current dir entry is returned. 3096*6a54128fSAndroid Build Coastguard Worker 3097*6a54128fSAndroid Build Coastguard Worker If the last entry is reached, it is returned, along with an ABORT status. 3098*6a54128fSAndroid Build Coastguard Worker 3099*6a54128fSAndroid Build Coastguard Worker status is updated to the returned code of action. 3100*6a54128fSAndroid Build Coastguard Worker*/ 3101*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 3102*6a54128fSAndroid Build Coastguard Worker 3103*6a54128fSAndroid Build Coastguard Worker</Para> 3104*6a54128fSAndroid Build Coastguard Worker 3105*6a54128fSAndroid Build Coastguard Worker<Para> 3106*6a54128fSAndroid Build Coastguard WorkerWith the above tool in hand, many operations are simple to perform - Here is 3107*6a54128fSAndroid Build Coastguard Workerthe way I counted the entries in the current directory: 3108*6a54128fSAndroid Build Coastguard Worker</Para> 3109*6a54128fSAndroid Build Coastguard Worker 3110*6a54128fSAndroid Build Coastguard Worker<Para> 3111*6a54128fSAndroid Build Coastguard Worker 3112*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 3113*6a54128fSAndroid Build Coastguard Workerlong count_dir_entries (void) 3114*6a54128fSAndroid Build Coastguard Worker 3115*6a54128fSAndroid Build Coastguard Worker{ 3116*6a54128fSAndroid Build Coastguard Worker int status; 3117*6a54128fSAndroid Build Coastguard Worker 3118*6a54128fSAndroid Build Coastguard Worker return (search_dir_entries (&action_count,&status).dir_entry_num); 3119*6a54128fSAndroid Build Coastguard Worker} 3120*6a54128fSAndroid Build Coastguard Worker 3121*6a54128fSAndroid Build Coastguard Workerint action_count (struct struct_file_info *info) 3122*6a54128fSAndroid Build Coastguard Worker 3123*6a54128fSAndroid Build Coastguard Worker{ 3124*6a54128fSAndroid Build Coastguard Worker return (CONTINUE); 3125*6a54128fSAndroid Build Coastguard Worker} 3126*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 3127*6a54128fSAndroid Build Coastguard Worker 3128*6a54128fSAndroid Build Coastguard WorkerIt will just <Literal remap="tt">CONTINUE</Literal> until the last entry. The returned structure 3129*6a54128fSAndroid Build Coastguard Worker(of type <Literal remap="tt">struct_file_info</Literal>) will have its number in the 3130*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">dir_entry_num</Literal> field, and this is exactly the required number! 3131*6a54128fSAndroid Build Coastguard Worker</Para> 3132*6a54128fSAndroid Build Coastguard Worker 3133*6a54128fSAndroid Build Coastguard Worker</Sect2> 3134*6a54128fSAndroid Build Coastguard Worker 3135*6a54128fSAndroid Build Coastguard Worker<Sect2> 3136*6a54128fSAndroid Build Coastguard Worker<Title>The cd command</Title> 3137*6a54128fSAndroid Build Coastguard Worker 3138*6a54128fSAndroid Build Coastguard Worker<Para> 3139*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">cd</Literal> command accepts a relative path, and moves there ... 3140*6a54128fSAndroid Build Coastguard WorkerThe implementation is of-course a bit more complicated: 3141*6a54128fSAndroid Build Coastguard Worker 3142*6a54128fSAndroid Build Coastguard Worker<OrderedList> 3143*6a54128fSAndroid Build Coastguard Worker<ListItem> 3144*6a54128fSAndroid Build Coastguard Worker 3145*6a54128fSAndroid Build Coastguard Worker<Para> 3146*6a54128fSAndroid Build Coastguard Worker The path is checked that it is not an absolute path (from <Literal remap="tt">/</Literal>). 3147*6a54128fSAndroid Build Coastguard WorkerIf it is, we let the <Literal remap="tt">general cd</Literal> to do the job by calling 3148*6a54128fSAndroid Build Coastguard Workerdirectly <Literal remap="tt">type_ext2___cd</Literal>. 3149*6a54128fSAndroid Build Coastguard Worker</Para> 3150*6a54128fSAndroid Build Coastguard Worker</ListItem> 3151*6a54128fSAndroid Build Coastguard Worker<ListItem> 3152*6a54128fSAndroid Build Coastguard Worker 3153*6a54128fSAndroid Build Coastguard Worker<Para> 3154*6a54128fSAndroid Build Coastguard Worker The path is divided into the nearest path and the rest of the path. 3155*6a54128fSAndroid Build Coastguard WorkerFor example, cd 1/2/3/4 is divided into <Literal remap="tt">1</Literal> and into 3156*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">2/3/4</Literal>. 3157*6a54128fSAndroid Build Coastguard Worker</Para> 3158*6a54128fSAndroid Build Coastguard Worker</ListItem> 3159*6a54128fSAndroid Build Coastguard Worker<ListItem> 3160*6a54128fSAndroid Build Coastguard Worker 3161*6a54128fSAndroid Build Coastguard Worker<Para> 3162*6a54128fSAndroid Build Coastguard Worker It is the first part of the path that we need to search for in the 3163*6a54128fSAndroid Build Coastguard Workercurrent directory. We search for it using <Literal remap="tt">search_dir_entries</Literal>, 3164*6a54128fSAndroid Build Coastguard Workerwhich accepts the <Literal remap="tt">action_name</Literal> function as the user defined 3165*6a54128fSAndroid Build Coastguard Workerfunction. 3166*6a54128fSAndroid Build Coastguard Worker</Para> 3167*6a54128fSAndroid Build Coastguard Worker</ListItem> 3168*6a54128fSAndroid Build Coastguard Worker<ListItem> 3169*6a54128fSAndroid Build Coastguard Worker 3170*6a54128fSAndroid Build Coastguard Worker<Para> 3171*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">search_dir_entries</Literal> will scan the entire entries and will call 3172*6a54128fSAndroid Build Coastguard Workerour <Literal remap="tt">action_name</Literal> function for each entry. In 3173*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">action_name</Literal>, the required name will be checked against the 3174*6a54128fSAndroid Build Coastguard Workername of the current entry, and <Literal remap="tt">FOUND</Literal> will be returned when a 3175*6a54128fSAndroid Build Coastguard Workermatch occurs. 3176*6a54128fSAndroid Build Coastguard Worker</Para> 3177*6a54128fSAndroid Build Coastguard Worker</ListItem> 3178*6a54128fSAndroid Build Coastguard Worker<ListItem> 3179*6a54128fSAndroid Build Coastguard Worker 3180*6a54128fSAndroid Build Coastguard Worker<Para> 3181*6a54128fSAndroid Build Coastguard Worker If the required entry is found, we dispatch a <Literal remap="tt">remember</Literal> 3182*6a54128fSAndroid Build Coastguard Workercommand to insert the current <Literal remap="tt">inode</Literal> into the object memory. 3183*6a54128fSAndroid Build Coastguard WorkerThis is required to easily support <Literal remap="tt">symbolic links</Literal> - If we 3184*6a54128fSAndroid Build Coastguard Workerfind later that the inode pointed by the entry is actually a 3185*6a54128fSAndroid Build Coastguard Workersymbolic link, we'll need to return to this point, and the above 3186*6a54128fSAndroid Build Coastguard Workerinode doesn't have (and can't have, because of <Literal remap="tt">hard links</Literal>) the 3187*6a54128fSAndroid Build Coastguard Workerinformation necessary to "move back". 3188*6a54128fSAndroid Build Coastguard Worker</Para> 3189*6a54128fSAndroid Build Coastguard Worker</ListItem> 3190*6a54128fSAndroid Build Coastguard Worker<ListItem> 3191*6a54128fSAndroid Build Coastguard Worker 3192*6a54128fSAndroid Build Coastguard Worker<Para> 3193*6a54128fSAndroid Build Coastguard Worker We then dispatch a <Literal remap="tt">followinode</Literal> command to reach the inode 3194*6a54128fSAndroid Build Coastguard Workerpointed by the required entry. This command will automatically 3195*6a54128fSAndroid Build Coastguard Workerchange the type to <Literal remap="tt">ext2_inode</Literal> - We are now at an inode, and 3196*6a54128fSAndroid Build Coastguard Workerall the inode commands are available. 3197*6a54128fSAndroid Build Coastguard Worker</Para> 3198*6a54128fSAndroid Build Coastguard Worker</ListItem> 3199*6a54128fSAndroid Build Coastguard Worker<ListItem> 3200*6a54128fSAndroid Build Coastguard Worker 3201*6a54128fSAndroid Build Coastguard Worker<Para> 3202*6a54128fSAndroid Build Coastguard Worker We check the inode's type to see if it is a directory. If it is, we 3203*6a54128fSAndroid Build Coastguard Workerdispatch a <Literal remap="tt">dir</Literal> command to "enter the directory", and 3204*6a54128fSAndroid Build Coastguard Workerrecursively call ourself (The type is <Literal remap="tt">dir</Literal> again) by 3205*6a54128fSAndroid Build Coastguard Workerdispatching a <Literal remap="tt">cd</Literal> command, with the rest of the path as an 3206*6a54128fSAndroid Build Coastguard Workerargument. 3207*6a54128fSAndroid Build Coastguard Worker</Para> 3208*6a54128fSAndroid Build Coastguard Worker</ListItem> 3209*6a54128fSAndroid Build Coastguard Worker<ListItem> 3210*6a54128fSAndroid Build Coastguard Worker 3211*6a54128fSAndroid Build Coastguard Worker<Para> 3212*6a54128fSAndroid Build Coastguard Worker If the inode's type is a symbolic link (only fast symbolic link were 3213*6a54128fSAndroid Build Coastguard Workermeanwhile implemented. I guess this is typically the case.), we note 3214*6a54128fSAndroid Build Coastguard Workerthe path it is pointing at, the saved inode is recalled, we dispatch 3215*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">dir</Literal> to get back to the original directory, and we call 3216*6a54128fSAndroid Build Coastguard Workerourself again with the <Literal remap="tt">link path/rest of the path</Literal> argument. 3217*6a54128fSAndroid Build Coastguard Worker</Para> 3218*6a54128fSAndroid Build Coastguard Worker</ListItem> 3219*6a54128fSAndroid Build Coastguard Worker<ListItem> 3220*6a54128fSAndroid Build Coastguard Worker 3221*6a54128fSAndroid Build Coastguard Worker<Para> 3222*6a54128fSAndroid Build Coastguard Worker In any other case, we just stop at the resulting inode. 3223*6a54128fSAndroid Build Coastguard Worker</Para> 3224*6a54128fSAndroid Build Coastguard Worker</ListItem> 3225*6a54128fSAndroid Build Coastguard Worker 3226*6a54128fSAndroid Build Coastguard Worker</OrderedList> 3227*6a54128fSAndroid Build Coastguard Worker 3228*6a54128fSAndroid Build Coastguard Worker</Para> 3229*6a54128fSAndroid Build Coastguard Worker 3230*6a54128fSAndroid Build Coastguard Worker</Sect2> 3231*6a54128fSAndroid Build Coastguard Worker 3232*6a54128fSAndroid Build Coastguard Worker</Sect1> 3233*6a54128fSAndroid Build Coastguard Worker 3234*6a54128fSAndroid Build Coastguard Worker<Sect1> 3235*6a54128fSAndroid Build Coastguard Worker<Title>The block and inode allocation bitmaps</Title> 3236*6a54128fSAndroid Build Coastguard Worker 3237*6a54128fSAndroid Build Coastguard Worker<Para> 3238*6a54128fSAndroid Build Coastguard WorkerThe block allocation bitmap is reached by the corresponding group descriptor. 3239*6a54128fSAndroid Build Coastguard WorkerThe group descriptor handling functions will save the necessary information 3240*6a54128fSAndroid Build Coastguard Workerinto a structure of the <Literal remap="tt">struct_block_bitmap_info</Literal> type: 3241*6a54128fSAndroid Build Coastguard Worker</Para> 3242*6a54128fSAndroid Build Coastguard Worker 3243*6a54128fSAndroid Build Coastguard Worker<Para> 3244*6a54128fSAndroid Build Coastguard Worker 3245*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 3246*6a54128fSAndroid Build Coastguard Workerstruct struct_block_bitmap_info { 3247*6a54128fSAndroid Build Coastguard Worker unsigned long entry_num; 3248*6a54128fSAndroid Build Coastguard Worker unsigned long group_num; 3249*6a54128fSAndroid Build Coastguard Worker}; 3250*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 3251*6a54128fSAndroid Build Coastguard Worker 3252*6a54128fSAndroid Build Coastguard Worker</Para> 3253*6a54128fSAndroid Build Coastguard Worker 3254*6a54128fSAndroid Build Coastguard Worker<Para> 3255*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">show</Literal> command is overridden, and will show the block as a series of 3256*6a54128fSAndroid Build Coastguard Workerbits, each bit corresponding to a block. The main variable is the 3257*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">entry_num</Literal> variable, declared above, which is just the current block 3258*6a54128fSAndroid Build Coastguard Workernumber in this block group. The current entry is highlighted, and the 3259*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">next, prev and entry</Literal> commands just change the above variable. 3260*6a54128fSAndroid Build Coastguard Worker</Para> 3261*6a54128fSAndroid Build Coastguard Worker 3262*6a54128fSAndroid Build Coastguard Worker<Para> 3263*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">allocate and deallocate</Literal> change the specified bits. Nothing 3264*6a54128fSAndroid Build Coastguard Workerspecial about them - They just contain code which converts between bit and 3265*6a54128fSAndroid Build Coastguard Workerbyte locations. 3266*6a54128fSAndroid Build Coastguard Worker</Para> 3267*6a54128fSAndroid Build Coastguard Worker 3268*6a54128fSAndroid Build Coastguard Worker<Para> 3269*6a54128fSAndroid Build Coastguard WorkerThe <Literal remap="tt">inode allocation bitmap</Literal> is treated in much the same fashion, with 3270*6a54128fSAndroid Build Coastguard Workerthe same commands available. 3271*6a54128fSAndroid Build Coastguard Worker</Para> 3272*6a54128fSAndroid Build Coastguard Worker 3273*6a54128fSAndroid Build Coastguard Worker</Sect1> 3274*6a54128fSAndroid Build Coastguard Worker 3275*6a54128fSAndroid Build Coastguard Worker<Sect1> 3276*6a54128fSAndroid Build Coastguard Worker<Title>Filesystem size limitation</Title> 3277*6a54128fSAndroid Build Coastguard Worker 3278*6a54128fSAndroid Build Coastguard Worker<Para> 3279*6a54128fSAndroid Build Coastguard WorkerWhile an ext2 filesystem has a size limit of <Literal remap="tt">4 TB</Literal>, EXT2ED currently 3280*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">can't</Literal> handle filesystems which are <Literal remap="tt">bigger than 2 GB</Literal>. 3281*6a54128fSAndroid Build Coastguard Worker</Para> 3282*6a54128fSAndroid Build Coastguard Worker 3283*6a54128fSAndroid Build Coastguard Worker<Para> 3284*6a54128fSAndroid Build Coastguard WorkerThis limitation results from my usage of <Literal remap="tt">32 bit long variables</Literal> and 3285*6a54128fSAndroid Build Coastguard Workerof the <Literal remap="tt">fseek</Literal> filesystem call, which can't seek up to 4 TB. 3286*6a54128fSAndroid Build Coastguard Worker</Para> 3287*6a54128fSAndroid Build Coastguard Worker 3288*6a54128fSAndroid Build Coastguard Worker<Para> 3289*6a54128fSAndroid Build Coastguard WorkerBy looking in the <Literal remap="tt">ext2 library</Literal> source code by <Literal remap="tt">Theodore Ts'o</Literal>, 3290*6a54128fSAndroid Build Coastguard WorkerI discovered the <Literal remap="tt">llseek</Literal> system call which can seek to a 3291*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">64 bit unsigned long long</Literal> offset. Correcting the situation is not 3292*6a54128fSAndroid Build Coastguard Workerdifficult in concept - I need to change long into unsigned long long where 3293*6a54128fSAndroid Build Coastguard Workerappropriate and modify <Literal remap="tt">disk.c</Literal> to use the llseek system call. 3294*6a54128fSAndroid Build Coastguard Worker</Para> 3295*6a54128fSAndroid Build Coastguard Worker 3296*6a54128fSAndroid Build Coastguard Worker<Para> 3297*6a54128fSAndroid Build Coastguard WorkerHowever, fixing the above limitation involves making changes in many places 3298*6a54128fSAndroid Build Coastguard Workerin the code and will obviously make the entire code less stable. For that 3299*6a54128fSAndroid Build Coastguard Workerreason, I chose to release EXT2ED as it is now and to postpone the above fix 3300*6a54128fSAndroid Build Coastguard Workerto the next release. 3301*6a54128fSAndroid Build Coastguard Worker</Para> 3302*6a54128fSAndroid Build Coastguard Worker 3303*6a54128fSAndroid Build Coastguard Worker</Sect1> 3304*6a54128fSAndroid Build Coastguard Worker 3305*6a54128fSAndroid Build Coastguard Worker<Sect1> 3306*6a54128fSAndroid Build Coastguard Worker<Title>Conclusion</Title> 3307*6a54128fSAndroid Build Coastguard Worker 3308*6a54128fSAndroid Build Coastguard Worker<Para> 3309*6a54128fSAndroid Build Coastguard WorkerHad I known in advance the structure of the ext2 filesystem, I feel that 3310*6a54128fSAndroid Build Coastguard Workerthe resulting design would have been quite different from the presented 3311*6a54128fSAndroid Build Coastguard Workerdesign above. 3312*6a54128fSAndroid Build Coastguard Worker</Para> 3313*6a54128fSAndroid Build Coastguard Worker 3314*6a54128fSAndroid Build Coastguard Worker<Para> 3315*6a54128fSAndroid Build Coastguard WorkerEXT2ED has now two levels of abstraction - A <Literal remap="tt">general</Literal> filesystem, and an 3316*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ext2</Literal> filesystem, and the surface is more or less prepared for additions 3317*6a54128fSAndroid Build Coastguard Workerof other filesystems. Had I approached the design in the "engineering" way, 3318*6a54128fSAndroid Build Coastguard WorkerI guess that the first level above would not have existed. 3319*6a54128fSAndroid Build Coastguard Worker</Para> 3320*6a54128fSAndroid Build Coastguard Worker 3321*6a54128fSAndroid Build Coastguard Worker</Sect1> 3322*6a54128fSAndroid Build Coastguard Worker 3323*6a54128fSAndroid Build Coastguard Worker<Sect1> 3324*6a54128fSAndroid Build Coastguard Worker<Title>Copyright</Title> 3325*6a54128fSAndroid Build Coastguard Worker 3326*6a54128fSAndroid Build Coastguard Worker<Para> 3327*6a54128fSAndroid Build Coastguard WorkerEXT2ED is Copyright (C) 1995 Gadi Oxman. 3328*6a54128fSAndroid Build Coastguard Worker</Para> 3329*6a54128fSAndroid Build Coastguard Worker 3330*6a54128fSAndroid Build Coastguard Worker<Para> 3331*6a54128fSAndroid Build Coastguard WorkerEXT2ED is hereby placed under the GPL - Gnu Public License. You are free and 3332*6a54128fSAndroid Build Coastguard Workerwelcome to copy, view and modify the sources. My only wish is that my 3333*6a54128fSAndroid Build Coastguard Workercopyright presented above will be left and that a list of the bug fixes, 3334*6a54128fSAndroid Build Coastguard Workeradded features, etc, will be provided. 3335*6a54128fSAndroid Build Coastguard Worker</Para> 3336*6a54128fSAndroid Build Coastguard Worker 3337*6a54128fSAndroid Build Coastguard Worker<Para> 3338*6a54128fSAndroid Build Coastguard WorkerThe entire EXT2ED project is based, of-course, on the kernel sources. The 3339*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">ext2.descriptors</Literal> distributed with EXT2ED is a slightly modified 3340*6a54128fSAndroid Build Coastguard Workerversion of the main ext2 include file, /usr/include/linux/ext2_fs.h. Follows 3341*6a54128fSAndroid Build Coastguard Workerthe original copyright: 3342*6a54128fSAndroid Build Coastguard Worker</Para> 3343*6a54128fSAndroid Build Coastguard Worker 3344*6a54128fSAndroid Build Coastguard Worker<Para> 3345*6a54128fSAndroid Build Coastguard Worker 3346*6a54128fSAndroid Build Coastguard Worker<ProgramListing> 3347*6a54128fSAndroid Build Coastguard Worker/* 3348*6a54128fSAndroid Build Coastguard Worker * linux/include/linux/ext2_fs.h 3349*6a54128fSAndroid Build Coastguard Worker * 3350*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 1992, 1993, 1994, 1995 3351*6a54128fSAndroid Build Coastguard Worker * Remy Card ([email protected]) 3352*6a54128fSAndroid Build Coastguard Worker * Laboratoire MASI - Institut Blaise Pascal 3353*6a54128fSAndroid Build Coastguard Worker * Universite Pierre et Marie Curie (Paris VI) 3354*6a54128fSAndroid Build Coastguard Worker * 3355*6a54128fSAndroid Build Coastguard Worker * from 3356*6a54128fSAndroid Build Coastguard Worker * 3357*6a54128fSAndroid Build Coastguard Worker * linux/include/linux/minix_fs.h 3358*6a54128fSAndroid Build Coastguard Worker * 3359*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 1991, 1992 Linus Torvalds 3360*6a54128fSAndroid Build Coastguard Worker */ 3361*6a54128fSAndroid Build Coastguard Worker 3362*6a54128fSAndroid Build Coastguard Worker</ProgramListing> 3363*6a54128fSAndroid Build Coastguard Worker 3364*6a54128fSAndroid Build Coastguard Worker</Para> 3365*6a54128fSAndroid Build Coastguard Worker 3366*6a54128fSAndroid Build Coastguard Worker</Sect1> 3367*6a54128fSAndroid Build Coastguard Worker 3368*6a54128fSAndroid Build Coastguard Worker<Sect1> 3369*6a54128fSAndroid Build Coastguard Worker<Title>Acknowledgments</Title> 3370*6a54128fSAndroid Build Coastguard Worker 3371*6a54128fSAndroid Build Coastguard Worker<Para> 3372*6a54128fSAndroid Build Coastguard WorkerEXT2ED was constructed as a student project in the software 3373*6a54128fSAndroid Build Coastguard Workerlaboratory of the faculty of electrical-engineering in the 3374*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">Technion - Israel's institute of technology</Literal>. 3375*6a54128fSAndroid Build Coastguard Worker</Para> 3376*6a54128fSAndroid Build Coastguard Worker 3377*6a54128fSAndroid Build Coastguard Worker<Para> 3378*6a54128fSAndroid Build Coastguard WorkerAt first, I would like to thank <Literal remap="tt">Avner Lottem</Literal> and <Literal remap="tt">Doctor Ilana 3379*6a54128fSAndroid Build Coastguard WorkerDavid</Literal> for their interest and assistance in this project. 3380*6a54128fSAndroid Build Coastguard Worker</Para> 3381*6a54128fSAndroid Build Coastguard Worker 3382*6a54128fSAndroid Build Coastguard Worker<Para> 3383*6a54128fSAndroid Build Coastguard WorkerI would also like to thank the following people, who were involved in the 3384*6a54128fSAndroid Build Coastguard Workerdesign and implementation of the ext2 filesystem kernel code and support 3385*6a54128fSAndroid Build Coastguard Workerutilities: 3386*6a54128fSAndroid Build Coastguard Worker 3387*6a54128fSAndroid Build Coastguard Worker<ItemizedList> 3388*6a54128fSAndroid Build Coastguard Worker<ListItem> 3389*6a54128fSAndroid Build Coastguard Worker 3390*6a54128fSAndroid Build Coastguard Worker<Para> 3391*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Remy Card</Literal> 3392*6a54128fSAndroid Build Coastguard Worker 3393*6a54128fSAndroid Build Coastguard WorkerWho designed, implemented and maintains the ext2 filesystem kernel 3394*6a54128fSAndroid Build Coastguard Workercode, and some of the ext2 utilities. <Literal remap="tt">Remy Card</Literal> is also the 3395*6a54128fSAndroid Build Coastguard Workerauthor of several helpful slides concerning the ext2 filesystem. 3396*6a54128fSAndroid Build Coastguard WorkerSpecifically, he is the author of <Literal remap="tt">File Management in the Linux 3397*6a54128fSAndroid Build Coastguard WorkerKernel</Literal> and of <Literal remap="tt">The Second Extended File System - Current 3398*6a54128fSAndroid Build Coastguard WorkerState, Future Development</Literal>. 3399*6a54128fSAndroid Build Coastguard Worker 3400*6a54128fSAndroid Build Coastguard Worker</Para> 3401*6a54128fSAndroid Build Coastguard Worker</ListItem> 3402*6a54128fSAndroid Build Coastguard Worker<ListItem> 3403*6a54128fSAndroid Build Coastguard Worker 3404*6a54128fSAndroid Build Coastguard Worker<Para> 3405*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Wayne Davison</Literal> 3406*6a54128fSAndroid Build Coastguard Worker 3407*6a54128fSAndroid Build Coastguard WorkerWho designed the ext2 filesystem. 3408*6a54128fSAndroid Build Coastguard Worker</Para> 3409*6a54128fSAndroid Build Coastguard Worker</ListItem> 3410*6a54128fSAndroid Build Coastguard Worker<ListItem> 3411*6a54128fSAndroid Build Coastguard Worker 3412*6a54128fSAndroid Build Coastguard Worker<Para> 3413*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Stephen Tweedie</Literal> 3414*6a54128fSAndroid Build Coastguard Worker 3415*6a54128fSAndroid Build Coastguard WorkerWho helped designing the ext2 filesystem kernel code and wrote the 3416*6a54128fSAndroid Build Coastguard Workerslides <Literal remap="tt">Optimizations in File Systems</Literal>. 3417*6a54128fSAndroid Build Coastguard Worker</Para> 3418*6a54128fSAndroid Build Coastguard Worker</ListItem> 3419*6a54128fSAndroid Build Coastguard Worker<ListItem> 3420*6a54128fSAndroid Build Coastguard Worker 3421*6a54128fSAndroid Build Coastguard Worker<Para> 3422*6a54128fSAndroid Build Coastguard Worker <Literal remap="tt">Theodore Ts'o</Literal> 3423*6a54128fSAndroid Build Coastguard Worker 3424*6a54128fSAndroid Build Coastguard WorkerWho is the author of several ext2 utilities and of the ext2 library 3425*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">libext2fs</Literal> (which I didn't use, simply because I didn't know 3426*6a54128fSAndroid Build Coastguard Workerit exists when I started to work on my project). 3427*6a54128fSAndroid Build Coastguard Worker</Para> 3428*6a54128fSAndroid Build Coastguard Worker</ListItem> 3429*6a54128fSAndroid Build Coastguard Worker 3430*6a54128fSAndroid Build Coastguard Worker</ItemizedList> 3431*6a54128fSAndroid Build Coastguard Worker 3432*6a54128fSAndroid Build Coastguard Worker</Para> 3433*6a54128fSAndroid Build Coastguard Worker 3434*6a54128fSAndroid Build Coastguard Worker<Para> 3435*6a54128fSAndroid Build Coastguard WorkerLastly, I would like to thank, of-course, <Literal remap="tt">Linus Torvalds</Literal> and the 3436*6a54128fSAndroid Build Coastguard Worker<Literal remap="tt">Linux community</Literal> for providing all of us with such a great operating 3437*6a54128fSAndroid Build Coastguard Workersystem. 3438*6a54128fSAndroid Build Coastguard Worker</Para> 3439*6a54128fSAndroid Build Coastguard Worker 3440*6a54128fSAndroid Build Coastguard Worker<Para> 3441*6a54128fSAndroid Build Coastguard WorkerPlease contact me in a case of bug report, suggestions, or just about 3442*6a54128fSAndroid Build Coastguard Workeranything concerning EXT2ED. 3443*6a54128fSAndroid Build Coastguard Worker</Para> 3444*6a54128fSAndroid Build Coastguard Worker 3445*6a54128fSAndroid Build Coastguard Worker<Para> 3446*6a54128fSAndroid Build Coastguard WorkerEnjoy, 3447*6a54128fSAndroid Build Coastguard Worker</Para> 3448*6a54128fSAndroid Build Coastguard Worker 3449*6a54128fSAndroid Build Coastguard Worker<Para> 3450*6a54128fSAndroid Build Coastguard WorkerGadi Oxman <[email protected]> 3451*6a54128fSAndroid Build Coastguard Worker</Para> 3452*6a54128fSAndroid Build Coastguard Worker 3453*6a54128fSAndroid Build Coastguard Worker<Para> 3454*6a54128fSAndroid Build Coastguard WorkerHaifa, August 95 3455*6a54128fSAndroid Build Coastguard Worker</Para> 3456*6a54128fSAndroid Build Coastguard Worker 3457*6a54128fSAndroid Build Coastguard Worker</Sect1> 3458*6a54128fSAndroid Build Coastguard Worker 3459*6a54128fSAndroid Build Coastguard Worker</Article> 3460