How can I resize a fat32 file system in an LVM partition? [closed] - resize

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Simple enough: I have an LVM partition (e.g. /dev/mapper/foo-fat) that contains a Fat32 file system. Prior to reducing the size of this LVM partition (which I'll do with lvmreduce), I want to reduce the size of the Fat32 filesystem it contains.
It looks like parted should be able to do it, but I can't find the magic invocation to make it work.

Use fatresize (manpage) and then proceed with lvresize.
To avoid truncating the FS, you should first shrink the VFAT volume a few hundreds (to be safe) megabytes more than wanted, then resize the LVM container and finally grow the volume to fill the LVM partition.
Besides, this question does not belong to StackOverflow but to ServerFault.

No answers + deadline to meet = write it myself.
For future reference, it was only a few lines of code, using libparted. For readability, I've omitted error checking, etc. Caller is responsible for ensuring there's enough space in the partition for the new filesystem size.
#include <parted/parted.h>
int
resize_filesystem(const char *device, PedSector newsize)
{
PedDevice *dev = NULL;
PedGeometry *geom = NULL;
PedGeometry *new_geom = NULL;
PedFileSystem *fs = NULL;
int rc = 0;
dev = ped_device_get(device);
ped_device_open(dev);
geom = ped_geometry_new(dev, 0LL, dev->length);
fs = ped_file_system_open(geom);
new_geom = ped_geometry_new(dev, 0LL, newsize / dev->sector_size);
ped_file_system_resize(fs, new_geom, NULL);
ped_file_system_close(fs);
ped_geometry_destroy(geom);
ped_geometry_destroy(new_geom);
ped_device_close(dev);
return rc;
}

This appears to be what you want, http://www.gnu.org/software/parted/manual/html_chapter/parted_2.html#SEC25

Related

Why can you not specify var/val loops in Kotlin? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Why can't you specify a val or var type in for loop's in Kotlin. For example, I would like to be able to do
for (var i in 0...data.size - 1) {
for (j in 0..bytes.size - 1) {
bytes[j] = data[i++]//cant do i++ in current kotlin because "i" is val
}
//do stuff
}
But instead I have to do this
var i = 0
while (i < data.size) {
for (j in 0..bytes.size - 1) {
bytes[j] = data[i++]
}
//do stuff
}
Your example is slightly different from Java's typical for(int i=0;i<data.size;i++) example.
In the Kotlin version 'i' is actually an element of the range in which case i++ doesn't make sense. It just so happens that the range you have is a list of indexes.
The way you are using the Kotlin for loop is much closer to Java's foreach loop for(i : indexes).
I think that because Kotlin is a language that tries to make easy to respect most of the functional programming concepts, it prefers to prohibit that sort of behaviour. Also, a possible problem that your initial code could encount is an OutOfBoundException in the situation where the bytes array has more elements than the data array.

Calculus with Constants [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
An electric current, I, in amps, is given by
I=cos(wt)+√(8)sin(wt),
where w≠0 is a constant. What are the maximum and minimum values of I?
I have tried finding the derivative, but after that, I do not know how to solve for 0 because of the constant w.
Well David,you can convert this function into one trigonometric function by multiplying and dividing it by
√(1^2 + 8) i.e, 3. So your function becomes like this
I = 3*(1/3 cos(wt) + √8/3 sin(wt))
= 3* sin(wt + atan(1/√8))
Now, you can easily say its maximum value is
I = 3 amp
and minimum value is
I = 0 amp.

vb. net search about sentence and return the first word index [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
i was asked a question here but i forget to explain my problem well.. so my problem is that I have a huge string in arabic which i want to search about a sentences in it and if i found it return the first word index (word index not character) ..
for example:
Dim myString as String = "Fundamentally programs manipulate numbers and text. These are the building blocks of all programs. Programming languages let you use them in different ways, eg adding numbers, etc, or storing data on disk for later retrieval.. Fundamentally programs manipulate numbers and text."
so.. when i search about (programs manipulate) i want to return: 1 and 36 .. any suggestions by the best way ? if with linq i will appreciated .. thanx
You can use something similar to this.
class Program
{
public static void Main(string[] args)
{
var str = "Fundamentally programs manipulate numbers and text. These are the building blocks of all programs. Programming languages let you use them in different ways, eg adding numbers, etc, or storing data on disk for later retrieval.. Fundamentally programs manipulate numbers and text.";
foreach (var index in GetIndexes(str, "programs manipulate",' '))
{
Console.WriteLine(index);
}
Console.ReadKey();
}
public static IEnumerable<int> GetIndexes(string str, string search,params char[] delimiters)
{
var index = 0;
var words = str.Split(delimiters).ToList();
var searchwords = search.Split(delimiters);
while (words.Any())
{
if (words.Take(searchwords.Length).SequenceEqual(searchwords))
yield return index;
words.RemoveAt(0);
index += 1;
}
}
}

Need help creating a simple program to convert Mb to Kb in Visual Basic [Noob] [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Noob here who has taken a computing class and has just started learning Visual Basic using Visual Studio. My first task is to research online and create a simple console application that converts Megabytes to Kilobytes.
Module
Sub Main()
Dim Kb As Integer
Console.WriteLine("Enter Number of Megabytes")
Kb = Console.ReadLine / 1024
Console.WriteLine(Kb)
End Sub
End Module
This is far as I have come after looking around the internet, (yes, very noobish!) not exactly sure where I go from here or know if I am even doing it right.
It would be much appreciated if someone could help me out with some code. Thanks!
Well, 1MB is equals to 1024KB. So, multiply the input (in MB) by 1024.
Dim kb As Integer = 0
Console.WriteLine("Enter Number of Megabytes")
kb = Integer.Parse(Console.ReadLine()) * 1024
Console.WriteLine(kb.ToString())
Console.ReadLine()
In the good ol' days 1024 was the number to use. Today it is not so easy. For memory 1024 is still appropriate but for other things, e.g. disk size, it may not be. See:
http://physics.nist.gov/cuu/Units/prefixes.html
and
http://physics.nist.gov/cuu/Units/binary.html

How to calculate current velocity using Euler integration [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I want to know if I convert formula correctly. I'm not sure of that.
I know:
force = mass * acceleration
acceleration = (Velocity - previousVelocity) / deltaTime
acceleration = force / mass
So:
(Velocity - previousVelocity) / deltaTime = Force / Mass
If I know the force to apply , the mass , deltaTime and previousVelocity, to convert it in the new velocity for a euler integration? This formula is correct ?:
Velocity = (Force / mass * deltaTime) + previousVelocity
I feel like something is wrong or missing, I need the real formula.
thanks a lot!
What you've written is Forward Euler on dv/dt = f(t) (with m=1) ... i.e. v(n+1) = v(n) + f(n) * dt.