Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/util/openUp.c

1/*
2 * Copyright (c) 2001 Apple Computer, Inc. All rights reserved.
3 *
4 *
5 * The contents of this file constitute Original Code as defined in and
6 * are subject to the Apple Public Source License Version 1.1 (the
7 * "License"). You may not use this file except in compliance with the
8 * License. Please obtain a copy of the License at
9 * http://www.apple.com/publicsource and read it before using this file.
10 *
11 * This Original Code and all software distributed under the License are
12 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
13 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
14 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
16 * License for the specific language governing rights and limitations
17 * under the License.
18 *
19 *
20 * Shantonu Sen
21 * openUp.c - program to set the "first-open-window" field of a volume
22 *
23 * Get the directory ID for the first argument, and set it as word 2
24 * of the Finder Info fields for the volume it lives on
25 *
26 * cc -o openUp openUp.c
27 * Usage: openUp /Volumes/Foo/OpenMe/
28 *
29 */
30
31#include <stdio.h>
32#include <unistd.h>
33#include <stdlib.h>
34#include <sys/attr.h>
35#include <sys/stat.h>
36#include <sys/mount.h>
37#include <memory.h>
38
39struct directoryinfo {
40long unsigned length;
41uintptr_t dirid; // changed from: u_int32_t dirid;
42};
43
44struct volumeinfo {
45long unsigned length;
46uintptr_t finderinfo[8]; // changed from: u_int32_t finderinfo[8];
47};
48
49
50int main(int argc, char *argv[]) {
51char *path = NULL;
52struct attrlist alist;
53struct directoryinfo dirinfo;
54struct volumeinfo volinfo;
55struct statfs sfs;
56
57path = argv[1];
58
59bzero(&alist, sizeof(alist));
60alist.bitmapcount = 5;
61alist.commonattr = ATTR_CMN_OBJID;
62
63getattrlist(path, &alist, &dirinfo, sizeof(dirinfo), 0);
64
65printf("directory id: %lu\n", dirinfo.dirid);
66
67statfs(path, &sfs);
68
69printf("mountpoint: %s\n", sfs.f_mntonname);
70
71alist.commonattr = ATTR_CMN_FNDRINFO;
72alist.volattr = ATTR_VOL_INFO;
73
74getattrlist(sfs.f_mntonname, &alist, &volinfo, sizeof(volinfo), 0);
75volinfo.finderinfo[2] = dirinfo.dirid;
76setattrlist(sfs.f_mntonname, &alist, volinfo.finderinfo, sizeof(volinfo.finderinfo), 0);
77
78return EXIT_SUCCESS;
79}
80

Archive Download this file

Revision: 2045